From ea65577360618fce960aa1d4ebefeae6b6a3ecf4 Mon Sep 17 00:00:00 2001 From: Lionel Gauthier <lionel.gauthier@eurecom.fr> Date: Fri, 5 Jun 2015 14:03:50 +0000 Subject: [PATCH] git-svn-id: http://svn.eurecom.fr/openair4G/trunk@7535 818b1a75-f10b-46b9-bf7c-635c3b92a50f --- openair-cn/SGI/COPYING | 674 ----------------------- openair-cn/SGI/Makefile.am | 64 --- openair-cn/SGI/sgi.h | 301 ---------- openair-cn/SGI/sgi_egress.c | 427 --------------- openair-cn/SGI/sgi_nf.c | 362 ------------ openair-cn/SGI/sgi_pcap.c | 99 ---- openair-cn/SGI/sgi_socket.c | 1035 ----------------------------------- openair-cn/SGI/sgi_task.c | 361 ------------ openair-cn/SGI/sgi_util.c | 304 ---------- 9 files changed, 3627 deletions(-) delete mode 100644 openair-cn/SGI/COPYING delete mode 100644 openair-cn/SGI/Makefile.am delete mode 100755 openair-cn/SGI/sgi.h delete mode 100755 openair-cn/SGI/sgi_egress.c delete mode 100755 openair-cn/SGI/sgi_nf.c delete mode 100755 openair-cn/SGI/sgi_pcap.c delete mode 100644 openair-cn/SGI/sgi_socket.c delete mode 100644 openair-cn/SGI/sgi_task.c delete mode 100755 openair-cn/SGI/sgi_util.c diff --git a/openair-cn/SGI/COPYING b/openair-cn/SGI/COPYING deleted file mode 100644 index 94a9ed024d3..00000000000 --- a/openair-cn/SGI/COPYING +++ /dev/null @@ -1,674 +0,0 @@ - GNU GENERAL PUBLIC LICENSE - Version 3, 29 June 2007 - - Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/> - Everyone is permitted to copy and distribute verbatim copies - of this license document, but changing it is not allowed. - - Preamble - - The GNU General Public License is a free, copyleft license for -software and other kinds of works. - - The licenses for most software and other practical works are designed -to take away your freedom to share and change the works. By contrast, -the GNU General Public License is intended to guarantee your freedom to -share and change all versions of a program--to make sure it remains free -software for all its users. We, the Free Software Foundation, use the -GNU General Public License for most of our software; it applies also to -any other work released this way by its authors. You can apply it to -your programs, too. - - When we speak of free software, we are referring to freedom, not -price. Our General Public Licenses are designed to make sure that you -have the freedom to distribute copies of free software (and charge for -them if you wish), that you receive source code or can get it if you -want it, that you can change the software or use pieces of it in new -free programs, and that you know you can do these things. - - To protect your rights, we need to prevent others from denying you -these rights or asking you to surrender the rights. Therefore, you have -certain responsibilities if you distribute copies of the software, or if -you modify it: responsibilities to respect the freedom of others. - - For example, if you distribute copies of such a program, whether -gratis or for a fee, you must pass on to the recipients the same -freedoms that you received. You must make sure that they, too, receive -or can get the source code. And you must show them these terms so they -know their rights. - - Developers that use the GNU GPL protect your rights with two steps: -(1) assert copyright on the software, and (2) offer you this License -giving you legal permission to copy, distribute and/or modify it. - - For the developers' and authors' protection, the GPL clearly explains -that there is no warranty for this free software. For both users' and -authors' sake, the GPL requires that modified versions be marked as -changed, so that their problems will not be attributed erroneously to -authors of previous versions. - - Some devices are designed to deny users access to install or run -modified versions of the software inside them, although the manufacturer -can do so. This is fundamentally incompatible with the aim of -protecting users' freedom to change the software. The systematic -pattern of such abuse occurs in the area of products for individuals to -use, which is precisely where it is most unacceptable. Therefore, we -have designed this version of the GPL to prohibit the practice for those -products. If such problems arise substantially in other domains, we -stand ready to extend this provision to those domains in future versions -of the GPL, as needed to protect the freedom of users. - - Finally, every program is threatened constantly by software patents. -States should not allow patents to restrict development and use of -software on general-purpose computers, but in those that do, we wish to -avoid the special danger that patents applied to a free program could -make it effectively proprietary. To prevent this, the GPL assures that -patents cannot be used to render the program non-free. - - The precise terms and conditions for copying, distribution and -modification follow. - - TERMS AND CONDITIONS - - 0. Definitions. - - "This License" refers to version 3 of the GNU General Public License. - - "Copyright" also means copyright-like laws that apply to other kinds of -works, such as semiconductor masks. - - "The Program" refers to any copyrightable work licensed under this -License. Each licensee is addressed as "you". "Licensees" and -"recipients" may be individuals or organizations. - - To "modify" a work means to copy from or adapt all or part of the work -in a fashion requiring copyright permission, other than the making of an -exact copy. The resulting work is called a "modified version" of the -earlier work or a work "based on" the earlier work. - - A "covered work" means either the unmodified Program or a work based -on the Program. - - To "propagate" a work means to do anything with it that, without -permission, would make you directly or secondarily liable for -infringement under applicable copyright law, except executing it on a -computer or modifying a private copy. Propagation includes copying, -distribution (with or without modification), making available to the -public, and in some countries other activities as well. - - To "convey" a work means any kind of propagation that enables other -parties to make or receive copies. Mere interaction with a user through -a computer network, with no transfer of a copy, is not conveying. - - An interactive user interface displays "Appropriate Legal Notices" -to the extent that it includes a convenient and prominently visible -feature that (1) displays an appropriate copyright notice, and (2) -tells the user that there is no warranty for the work (except to the -extent that warranties are provided), that licensees may convey the -work under this License, and how to view a copy of this License. If -the interface presents a list of user commands or options, such as a -menu, a prominent item in the list meets this criterion. - - 1. Source Code. - - The "source code" for a work means the preferred form of the work -for making modifications to it. "Object code" means any non-source -form of a work. - - A "Standard Interface" means an interface that either is an official -standard defined by a recognized standards body, or, in the case of -interfaces specified for a particular programming language, one that -is widely used among developers working in that language. - - The "System Libraries" of an executable work include anything, other -than the work as a whole, that (a) is included in the normal form of -packaging a Major Component, but which is not part of that Major -Component, and (b) serves only to enable use of the work with that -Major Component, or to implement a Standard Interface for which an -implementation is available to the public in source code form. A -"Major Component", in this context, means a major essential component -(kernel, window system, and so on) of the specific operating system -(if any) on which the executable work runs, or a compiler used to -produce the work, or an object code interpreter used to run it. - - The "Corresponding Source" for a work in object code form means all -the source code needed to generate, install, and (for an executable -work) run the object code and to modify the work, including scripts to -control those activities. However, it does not include the work's -System Libraries, or general-purpose tools or generally available free -programs which are used unmodified in performing those activities but -which are not part of the work. For example, Corresponding Source -includes interface definition files associated with source files for -the work, and the source code for shared libraries and dynamically -linked subprograms that the work is specifically designed to require, -such as by intimate data communication or control flow between those -subprograms and other parts of the work. - - The Corresponding Source need not include anything that users -can regenerate automatically from other parts of the Corresponding -Source. - - The Corresponding Source for a work in source code form is that -same work. - - 2. Basic Permissions. - - All rights granted under this License are granted for the term of -copyright on the Program, and are irrevocable provided the stated -conditions are met. This License explicitly affirms your unlimited -permission to run the unmodified Program. The output from running a -covered work is covered by this License only if the output, given its -content, constitutes a covered work. This License acknowledges your -rights of fair use or other equivalent, as provided by copyright law. - - You may make, run and propagate covered works that you do not -convey, without conditions so long as your license otherwise remains -in force. You may convey covered works to others for the sole purpose -of having them make modifications exclusively for you, or provide you -with facilities for running those works, provided that you comply with -the terms of this License in conveying all material for which you do -not control copyright. Those thus making or running the covered works -for you must do so exclusively on your behalf, under your direction -and control, on terms that prohibit them from making any copies of -your copyrighted material outside their relationship with you. - - Conveying under any other circumstances is permitted solely under -the conditions stated below. Sublicensing is not allowed; section 10 -makes it unnecessary. - - 3. Protecting Users' Legal Rights From Anti-Circumvention Law. - - No covered work shall be deemed part of an effective technological -measure under any applicable law fulfilling obligations under article -11 of the WIPO copyright treaty adopted on 20 December 1996, or -similar laws prohibiting or restricting circumvention of such -measures. - - When you convey a covered work, you waive any legal power to forbid -circumvention of technological measures to the extent such circumvention -is effected by exercising rights under this License with respect to -the covered work, and you disclaim any intention to limit operation or -modification of the work as a means of enforcing, against the work's -users, your or third parties' legal rights to forbid circumvention of -technological measures. - - 4. Conveying Verbatim Copies. - - You may convey verbatim copies of the Program's source code as you -receive it, in any medium, provided that you conspicuously and -appropriately publish on each copy an appropriate copyright notice; -keep intact all notices stating that this License and any -non-permissive terms added in accord with section 7 apply to the code; -keep intact all notices of the absence of any warranty; and give all -recipients a copy of this License along with the Program. - - You may charge any price or no price for each copy that you convey, -and you may offer support or warranty protection for a fee. - - 5. Conveying Modified Source Versions. - - You may convey a work based on the Program, or the modifications to -produce it from the Program, in the form of source code under the -terms of section 4, provided that you also meet all of these conditions: - - a) The work must carry prominent notices stating that you modified - it, and giving a relevant date. - - b) The work must carry prominent notices stating that it is - released under this License and any conditions added under section - 7. This requirement modifies the requirement in section 4 to - "keep intact all notices". - - c) You must license the entire work, as a whole, under this - License to anyone who comes into possession of a copy. This - License will therefore apply, along with any applicable section 7 - additional terms, to the whole of the work, and all its parts, - regardless of how they are packaged. This License gives no - permission to license the work in any other way, but it does not - invalidate such permission if you have separately received it. - - d) If the work has interactive user interfaces, each must display - Appropriate Legal Notices; however, if the Program has interactive - interfaces that do not display Appropriate Legal Notices, your - work need not make them do so. - - A compilation of a covered work with other separate and independent -works, which are not by their nature extensions of the covered work, -and which are not combined with it such as to form a larger program, -in or on a volume of a storage or distribution medium, is called an -"aggregate" if the compilation and its resulting copyright are not -used to limit the access or legal rights of the compilation's users -beyond what the individual works permit. Inclusion of a covered work -in an aggregate does not cause this License to apply to the other -parts of the aggregate. - - 6. Conveying Non-Source Forms. - - You may convey a covered work in object code form under the terms -of sections 4 and 5, provided that you also convey the -machine-readable Corresponding Source under the terms of this License, -in one of these ways: - - a) Convey the object code in, or embodied in, a physical product - (including a physical distribution medium), accompanied by the - Corresponding Source fixed on a durable physical medium - customarily used for software interchange. - - b) Convey the object code in, or embodied in, a physical product - (including a physical distribution medium), accompanied by a - written offer, valid for at least three years and valid for as - long as you offer spare parts or customer support for that product - model, to give anyone who possesses the object code either (1) a - copy of the Corresponding Source for all the software in the - product that is covered by this License, on a durable physical - medium customarily used for software interchange, for a price no - more than your reasonable cost of physically performing this - conveying of source, or (2) access to copy the - Corresponding Source from a network server at no charge. - - c) Convey individual copies of the object code with a copy of the - written offer to provide the Corresponding Source. This - alternative is allowed only occasionally and noncommercially, and - only if you received the object code with such an offer, in accord - with subsection 6b. - - d) Convey the object code by offering access from a designated - place (gratis or for a charge), and offer equivalent access to the - Corresponding Source in the same way through the same place at no - further charge. You need not require recipients to copy the - Corresponding Source along with the object code. If the place to - copy the object code is a network server, the Corresponding Source - may be on a different server (operated by you or a third party) - that supports equivalent copying facilities, provided you maintain - clear directions next to the object code saying where to find the - Corresponding Source. Regardless of what server hosts the - Corresponding Source, you remain obligated to ensure that it is - available for as long as needed to satisfy these requirements. - - e) Convey the object code using peer-to-peer transmission, provided - you inform other peers where the object code and Corresponding - Source of the work are being offered to the general public at no - charge under subsection 6d. - - A separable portion of the object code, whose source code is excluded -from the Corresponding Source as a System Library, need not be -included in conveying the object code work. - - A "User Product" is either (1) a "consumer product", which means any -tangible personal property which is normally used for personal, family, -or household purposes, or (2) anything designed or sold for incorporation -into a dwelling. In determining whether a product is a consumer product, -doubtful cases shall be resolved in favor of coverage. For a particular -product received by a particular user, "normally used" refers to a -typical or common use of that class of product, regardless of the status -of the particular user or of the way in which the particular user -actually uses, or expects or is expected to use, the product. A product -is a consumer product regardless of whether the product has substantial -commercial, industrial or non-consumer uses, unless such uses represent -the only significant mode of use of the product. - - "Installation Information" for a User Product means any methods, -procedures, authorization keys, or other information required to install -and execute modified versions of a covered work in that User Product from -a modified version of its Corresponding Source. The information must -suffice to ensure that the continued functioning of the modified object -code is in no case prevented or interfered with solely because -modification has been made. - - If you convey an object code work under this section in, or with, or -specifically for use in, a User Product, and the conveying occurs as -part of a transaction in which the right of possession and use of the -User Product is transferred to the recipient in perpetuity or for a -fixed term (regardless of how the transaction is characterized), the -Corresponding Source conveyed under this section must be accompanied -by the Installation Information. But this requirement does not apply -if neither you nor any third party retains the ability to install -modified object code on the User Product (for example, the work has -been installed in ROM). - - The requirement to provide Installation Information does not include a -requirement to continue to provide support service, warranty, or updates -for a work that has been modified or installed by the recipient, or for -the User Product in which it has been modified or installed. Access to a -network may be denied when the modification itself materially and -adversely affects the operation of the network or violates the rules and -protocols for communication across the network. - - Corresponding Source conveyed, and Installation Information provided, -in accord with this section must be in a format that is publicly -documented (and with an implementation available to the public in -source code form), and must require no special password or key for -unpacking, reading or copying. - - 7. Additional Terms. - - "Additional permissions" are terms that supplement the terms of this -License by making exceptions from one or more of its conditions. -Additional permissions that are applicable to the entire Program shall -be treated as though they were included in this License, to the extent -that they are valid under applicable law. If additional permissions -apply only to part of the Program, that part may be used separately -under those permissions, but the entire Program remains governed by -this License without regard to the additional permissions. - - When you convey a copy of a covered work, you may at your option -remove any additional permissions from that copy, or from any part of -it. (Additional permissions may be written to require their own -removal in certain cases when you modify the work.) You may place -additional permissions on material, added by you to a covered work, -for which you have or can give appropriate copyright permission. - - Notwithstanding any other provision of this License, for material you -add to a covered work, you may (if authorized by the copyright holders of -that material) supplement the terms of this License with terms: - - a) Disclaiming warranty or limiting liability differently from the - terms of sections 15 and 16 of this License; or - - b) Requiring preservation of specified reasonable legal notices or - author attributions in that material or in the Appropriate Legal - Notices displayed by works containing it; or - - c) Prohibiting misrepresentation of the origin of that material, or - requiring that modified versions of such material be marked in - reasonable ways as different from the original version; or - - d) Limiting the use for publicity purposes of names of licensors or - authors of the material; or - - e) Declining to grant rights under trademark law for use of some - trade names, trademarks, or service marks; or - - f) Requiring indemnification of licensors and authors of that - material by anyone who conveys the material (or modified versions of - it) with contractual assumptions of liability to the recipient, for - any liability that these contractual assumptions directly impose on - those licensors and authors. - - All other non-permissive additional terms are considered "further -restrictions" within the meaning of section 10. If the Program as you -received it, or any part of it, contains a notice stating that it is -governed by this License along with a term that is a further -restriction, you may remove that term. If a license document contains -a further restriction but permits relicensing or conveying under this -License, you may add to a covered work material governed by the terms -of that license document, provided that the further restriction does -not survive such relicensing or conveying. - - If you add terms to a covered work in accord with this section, you -must place, in the relevant source files, a statement of the -additional terms that apply to those files, or a notice indicating -where to find the applicable terms. - - Additional terms, permissive or non-permissive, may be stated in the -form of a separately written license, or stated as exceptions; -the above requirements apply either way. - - 8. Termination. - - You may not propagate or modify a covered work except as expressly -provided under this License. Any attempt otherwise to propagate or -modify it is void, and will automatically terminate your rights under -this License (including any patent licenses granted under the third -paragraph of section 11). - - However, if you cease all violation of this License, then your -license from a particular copyright holder is reinstated (a) -provisionally, unless and until the copyright holder explicitly and -finally terminates your license, and (b) permanently, if the copyright -holder fails to notify you of the violation by some reasonable means -prior to 60 days after the cessation. - - Moreover, your license from a particular copyright holder is -reinstated permanently if the copyright holder notifies you of the -violation by some reasonable means, this is the first time you have -received notice of violation of this License (for any work) from that -copyright holder, and you cure the violation prior to 30 days after -your receipt of the notice. - - Termination of your rights under this section does not terminate the -licenses of parties who have received copies or rights from you under -this License. If your rights have been terminated and not permanently -reinstated, you do not qualify to receive new licenses for the same -material under section 10. - - 9. Acceptance Not Required for Having Copies. - - You are not required to accept this License in order to receive or -run a copy of the Program. Ancillary propagation of a covered work -occurring solely as a consequence of using peer-to-peer transmission -to receive a copy likewise does not require acceptance. However, -nothing other than this License grants you permission to propagate or -modify any covered work. These actions infringe copyright if you do -not accept this License. Therefore, by modifying or propagating a -covered work, you indicate your acceptance of this License to do so. - - 10. Automatic Licensing of Downstream Recipients. - - Each time you convey a covered work, the recipient automatically -receives a license from the original licensors, to run, modify and -propagate that work, subject to this License. You are not responsible -for enforcing compliance by third parties with this License. - - An "entity transaction" is a transaction transferring control of an -organization, or substantially all assets of one, or subdividing an -organization, or merging organizations. If propagation of a covered -work results from an entity transaction, each party to that -transaction who receives a copy of the work also receives whatever -licenses to the work the party's predecessor in interest had or could -give under the previous paragraph, plus a right to possession of the -Corresponding Source of the work from the predecessor in interest, if -the predecessor has it or can get it with reasonable efforts. - - You may not impose any further restrictions on the exercise of the -rights granted or affirmed under this License. For example, you may -not impose a license fee, royalty, or other charge for exercise of -rights granted under this License, and you may not initiate litigation -(including a cross-claim or counterclaim in a lawsuit) alleging that -any patent claim is infringed by making, using, selling, offering for -sale, or importing the Program or any portion of it. - - 11. Patents. - - A "contributor" is a copyright holder who authorizes use under this -License of the Program or a work on which the Program is based. The -work thus licensed is called the contributor's "contributor version". - - A contributor's "essential patent claims" are all patent claims -owned or controlled by the contributor, whether already acquired or -hereafter acquired, that would be infringed by some manner, permitted -by this License, of making, using, or selling its contributor version, -but do not include claims that would be infringed only as a -consequence of further modification of the contributor version. For -purposes of this definition, "control" includes the right to grant -patent sublicenses in a manner consistent with the requirements of -this License. - - Each contributor grants you a non-exclusive, worldwide, royalty-free -patent license under the contributor's essential patent claims, to -make, use, sell, offer for sale, import and otherwise run, modify and -propagate the contents of its contributor version. - - In the following three paragraphs, a "patent license" is any express -agreement or commitment, however denominated, not to enforce a patent -(such as an express permission to practice a patent or covenant not to -sue for patent infringement). To "grant" such a patent license to a -party means to make such an agreement or commitment not to enforce a -patent against the party. - - If you convey a covered work, knowingly relying on a patent license, -and the Corresponding Source of the work is not available for anyone -to copy, free of charge and under the terms of this License, through a -publicly available network server or other readily accessible means, -then you must either (1) cause the Corresponding Source to be so -available, or (2) arrange to deprive yourself of the benefit of the -patent license for this particular work, or (3) arrange, in a manner -consistent with the requirements of this License, to extend the patent -license to downstream recipients. "Knowingly relying" means you have -actual knowledge that, but for the patent license, your conveying the -covered work in a country, or your recipient's use of the covered work -in a country, would infringe one or more identifiable patents in that -country that you have reason to believe are valid. - - If, pursuant to or in connection with a single transaction or -arrangement, you convey, or propagate by procuring conveyance of, a -covered work, and grant a patent license to some of the parties -receiving the covered work authorizing them to use, propagate, modify -or convey a specific copy of the covered work, then the patent license -you grant is automatically extended to all recipients of the covered -work and works based on it. - - A patent license is "discriminatory" if it does not include within -the scope of its coverage, prohibits the exercise of, or is -conditioned on the non-exercise of one or more of the rights that are -specifically granted under this License. You may not convey a covered -work if you are a party to an arrangement with a third party that is -in the business of distributing software, under which you make payment -to the third party based on the extent of your activity of conveying -the work, and under which the third party grants, to any of the -parties who would receive the covered work from you, a discriminatory -patent license (a) in connection with copies of the covered work -conveyed by you (or copies made from those copies), or (b) primarily -for and in connection with specific products or compilations that -contain the covered work, unless you entered into that arrangement, -or that patent license was granted, prior to 28 March 2007. - - Nothing in this License shall be construed as excluding or limiting -any implied license or other defenses to infringement that may -otherwise be available to you under applicable patent law. - - 12. No Surrender of Others' Freedom. - - If conditions are imposed on you (whether by court order, agreement or -otherwise) that contradict the conditions of this License, they do not -excuse you from the conditions of this License. If you cannot convey a -covered work so as to satisfy simultaneously your obligations under this -License and any other pertinent obligations, then as a consequence you may -not convey it at all. For example, if you agree to terms that obligate you -to collect a royalty for further conveying from those to whom you convey -the Program, the only way you could satisfy both those terms and this -License would be to refrain entirely from conveying the Program. - - 13. Use with the GNU Affero General Public License. - - Notwithstanding any other provision of this License, you have -permission to link or combine any covered work with a work licensed -under version 3 of the GNU Affero General Public License into a single -combined work, and to convey the resulting work. The terms of this -License will continue to apply to the part which is the covered work, -but the special requirements of the GNU Affero General Public License, -section 13, concerning interaction through a network will apply to the -combination as such. - - 14. Revised Versions of this License. - - The Free Software Foundation may publish revised and/or new versions of -the GNU General Public License from time to time. Such new versions will -be similar in spirit to the present version, but may differ in detail to -address new problems or concerns. - - Each version is given a distinguishing version number. If the -Program specifies that a certain numbered version of the GNU General -Public License "or any later version" applies to it, you have the -option of following the terms and conditions either of that numbered -version or of any later version published by the Free Software -Foundation. If the Program does not specify a version number of the -GNU General Public License, you may choose any version ever published -by the Free Software Foundation. - - If the Program specifies that a proxy can decide which future -versions of the GNU General Public License can be used, that proxy's -public statement of acceptance of a version permanently authorizes you -to choose that version for the Program. - - Later license versions may give you additional or different -permissions. However, no additional obligations are imposed on any -author or copyright holder as a result of your choosing to follow a -later version. - - 15. Disclaimer of Warranty. - - THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY -APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT -HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY -OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, -THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR -PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM -IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF -ALL NECESSARY SERVICING, REPAIR OR CORRECTION. - - 16. Limitation of Liability. - - IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING -WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS -THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY -GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE -USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF -DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD -PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), -EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF -SUCH DAMAGES. - - 17. Interpretation of Sections 15 and 16. - - If the disclaimer of warranty and limitation of liability provided -above cannot be given local legal effect according to their terms, -reviewing courts shall apply local law that most closely approximates -an absolute waiver of all civil liability in connection with the -Program, unless a warranty or assumption of liability accompanies a -copy of the Program in return for a fee. - - END OF TERMS AND CONDITIONS - - How to Apply These Terms to Your New Programs - - If you develop a new program, and you want it to be of the greatest -possible use to the public, the best way to achieve this is to make it -free software which everyone can redistribute and change under these terms. - - To do so, attach the following notices to the program. It is safest -to attach them to the start of each source file to most effectively -state the exclusion of warranty; and each file should have at least -the "copyright" line and a pointer to where the full notice is found. - - <one line to give the program's name and a brief idea of what it does.> - Copyright (C) <year> <name of author> - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see <http://www.gnu.org/licenses/>. - -Also add information on how to contact you by electronic and paper mail. - - If the program does terminal interaction, make it output a short -notice like this when it starts in an interactive mode: - - <program> Copyright (C) <year> <name of author> - This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. - This is free software, and you are welcome to redistribute it - under certain conditions; type `show c' for details. - -The hypothetical commands `show w' and `show c' should show the appropriate -parts of the General Public License. Of course, your program's commands -might be different; for a GUI interface, you would use an "about box". - - You should also get your employer (if you work as a programmer) or school, -if any, to sign a "copyright disclaimer" for the program, if necessary. -For more information on this, and how to apply and follow the GNU GPL, see -<http://www.gnu.org/licenses/>. - - The GNU General Public License does not permit incorporating your program -into proprietary programs. If your program is a subroutine library, you -may consider it more useful to permit linking proprietary applications with -the library. If this is what you want to do, use the GNU Lesser General -Public License instead of this License. But first, please read -<http://www.gnu.org/philosophy/why-not-lgpl.html>. diff --git a/openair-cn/SGI/Makefile.am b/openair-cn/SGI/Makefile.am deleted file mode 100644 index 9a386ed1d55..00000000000 --- a/openair-cn/SGI/Makefile.am +++ /dev/null @@ -1,64 +0,0 @@ -################################################################################ -# OpenAirInterface -# Copyright(c) 1999 - 2014 Eurecom -# -# OpenAirInterface is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# -# OpenAirInterface is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with OpenAirInterface.The full GNU General Public License is -# included in this distribution in the file called "COPYING". If not, -# see <http://www.gnu.org/licenses/>. -# -# Contact Information -# OpenAirInterface Admin: openair_admin@eurecom.fr -# OpenAirInterface Tech : openair_tech@eurecom.fr -# OpenAirInterface Dev : openair4g-devel@eurecom.fr -# -# Address : Eurecom, Compus SophiaTech 450, route des chappes, 06451 Biot, France. -# -################################################################################ -AM_CFLAGS = @ADD_CFLAGS@ \ - -I$(top_srcdir)/COMMON \ - -I$(top_srcdir)/SGW-LITE \ - -I$(top_srcdir)/UTILS \ - -I$(top_srcdir)/UTILS/HASHTABLE \ - -I$(top_srcdir)/NAS/EURECOM-NAS/src/api/network \ - -I$(top_srcdir)/NAS/EURECOM-NAS/src/include \ - -I$(top_srcdir)/NAS/EURECOM-NAS/src/ies \ - -I$(top_srcdir)/NAS/EURECOM-NAS/src/emm/msg \ - -I$(top_srcdir)/NAS/EURECOM-NAS/src/esm/msg \ - -I$(top_srcdir)/NAS/EURECOM-NAS/src/util \ - -I$(top_srcdir)/GTPV1-U \ - -I$(top_srcdir)/INTERTASK_INTERFACE - -noinst_LTLIBRARIES = libsgi.la -libsgi_la_LDFLAGS = -all-static -libsgi_la_SOURCES = \ - sgi_task.c sgi.h \ - sgi_socket.c \ - sgi_egress.c \ - sgi_util.c - -if ENABLE_USE_PCAP_FOR_SGI - libsgi_la_SOURCES += sgi_pcap.c \ - /usr/lib/libpcap.a - -endif - - -if ENABLE_USE_NETFILTER_FOR_SGI - libsgi_la_SOURCES += sgi_nf.c \ - /usr/lib/libnetfilter_queue.a \ - /usr/lib/libnfnetlink.la -endif - - diff --git a/openair-cn/SGI/sgi.h b/openair-cn/SGI/sgi.h deleted file mode 100755 index c0e4ebda499..00000000000 --- a/openair-cn/SGI/sgi.h +++ /dev/null @@ -1,301 +0,0 @@ -/******************************************************************************* - OpenAirInterface - Copyright(c) 1999 - 2014 Eurecom - - OpenAirInterface is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - - OpenAirInterface is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with OpenAirInterface.The full GNU General Public License is - included in this distribution in the file called "COPYING". If not, - see <http://www.gnu.org/licenses/>. - - Contact Information - OpenAirInterface Admin: openair_admin@eurecom.fr - OpenAirInterface Tech : openair_tech@eurecom.fr - OpenAirInterface Dev : openair4g-devel@eurecom.fr - - Address : Eurecom, Compus SophiaTech 450, route des chappes, 06451 Biot, France. - - *******************************************************************************/ -/*! \file sgi.h -* \brief -* \author Lionel Gauthier -* \company Eurecom -* \email: lionel.gauthier@eurecom.fr -*/ -#ifndef SGI_H_ -#define SGI_H_ - -#include <net/ethernet.h> -#include <netinet/in.h> -#include <pthread.h> -#include <stdio.h> - -#ifdef ENABLE_USE_NETFILTER_FOR_SGI -#warning "ENABLE_USE_NETFILTER_FOR_SGI" -#define SGI_SOCKET_RAW 1 -#define SGI_SOCKET_BIND_TO_IF 1 -#undef SGI_MARKING -#undef SGI_PACKET_RX_RING -#undef SGI_SOCKET_UDP -#else -#warning "DISABLE_USE_NETFILTER_FOR_SGI" -//#define SGI_SOCKET_RAW 1 -#undef SGI_SOCKET_RAW -#define SGI_SOCKET_DGRAM 1 -#define SGI_SOCKET_BIND_TO_IF 1 -#undef SGI_PACKET_RX_RING -#undef SGI_MARKING -#undef SGI_SOCKET_UDP -#endif - -#ifdef ENABLE_USE_PCAP_FOR_SGI -#include <pcap.h> -#endif - -//#define SGI_TEST -// Packets include a ethernet header if SGI_PF_PACKET is defined -#define SGI_PF_PACKET - -#include "common_types.h" -#include "hashtable.h" -#include "obj_hashtable.h" -#include "sgw_lite_ie_defs.h" -#include "ip_forward_messages_types.h" - -# define SGI_IF_DEBUG(x, args...) -# define SGI_IF_ERROR(x, args...) -# define SGI_IF_WARNING(x, args...) -//----------------------------------------------------------------------------- -#ifndef SGI_IF_DEBUG -# define SGI_IF_DEBUG(x, args...) do { fprintf(stdout, "[SGI_IF][D]"x, ##args); } \ - while(0) -#endif -#ifndef SGI_IF_ERROR -# define SGI_IF_ERROR(x, args...) do { fprintf(stderr, "[SGI_IF][E]"x, ##args); } \ - while(0) -#endif -#ifndef SGI_IF_WARNING -# define SGI_IF_WARNING(x, args...) do { fprintf(stderr, "[SGI_IF][W]"x, ##args); } \ - while(0) -#endif - -// refer to 3GPP TS 23.203 V10.6.0 (2012-03) page 33 -//#define MAX_DEFINED_QCI 0 -#define MAX_DEFINED_QCI 9 -#define SGI_MIN_EPS_BEARER_ID 5 -#define SGI_MAX_SERVED_USERS_PER_PGW 1024 -#define SGI_MAX_EPS_BEARERS_PER_USER 11 -#define MAX_DEFINED_IPV6_ADDRESSES_PER_UE 16 - - -#define NIP6ADDR(addr) \ - ntohs((addr)->s6_addr16[0]), \ - ntohs((addr)->s6_addr16[1]), \ - ntohs((addr)->s6_addr16[2]), \ - ntohs((addr)->s6_addr16[3]), \ - ntohs((addr)->s6_addr16[4]), \ - ntohs((addr)->s6_addr16[5]), \ - ntohs((addr)->s6_addr16[6]), \ - ntohs((addr)->s6_addr16[7]) - -#define NIPADDR(addr) \ - (uint8_t)(addr & 0x000000FF), \ - (uint8_t)((addr & 0x0000FF00) >> 8), \ - (uint8_t)((addr & 0x00FF0000) >> 16), \ - (uint8_t)((addr & 0xFF000000) >> 24) - -#define NMACADDR(addr) \ - (uint8_t)(addr[0]), \ - (uint8_t)(addr[1]), \ - (uint8_t)(addr[2]), \ - (uint8_t)(addr[3]), \ - (uint8_t)(addr[4]), \ - (uint8_t)(addr[5]) -#ifdef VLAN8021Q -typedef struct vlan_tag_s { - uint16_t vlan_tpid; /* ETH_P_8021Q */ - uint16_t vlan_tci; /* VLAN TCI */ -} vlan_tag_t __attribute__ ((__packed__)); - -typedef struct ether_header_8021q_s { - u_int8_t ether_dhost[ETH_ALEN]; /* destination eth addr */ - u_int8_t ether_shost[ETH_ALEN]; /* source ether addr */ - vlan_tag_t ether_vlan8021q; - u_int16_t ether_type; /* packet type ID field */ -} ether_header_8021q_t __attribute__ ((__packed__)); -#endif - -typedef struct arphdr_s { - __be16 ar_hrd; /* format of hardware address */ - __be16 ar_pro; /* format of protocol address */ - unsigned char ar_hln; /* length of hardware address */ - unsigned char ar_pln; /* length of protocol address */ - __be16 ar_op; /* ARP opcode (command) */ - /* - * Ethernet looks like this : This bit is variable sized however... - */ - unsigned char ar_sha[ETH_ALEN]; /* sender hardware address */ - unsigned char ar_sip[4]; /* sender IP address */ - unsigned char ar_tha[ETH_ALEN]; /* target hardware address */ - unsigned char ar_tip[4]; /* target IP address */ - -} arphdr_t; - -typedef struct sgi_teid_mapping_s { - int is_outgoing_ipv4_packet_seen; - int is_outgoing_ipv6_packet_seen; - Teid_t enb_S1U_teid; ///< dest tunnel identifier - qci_t qci; - ebi_t eps_bearer_id; ///< EPS bearer identifier - char hw_addrlen; -#ifdef SGI_UE_ETHER_TRAFFIC - char ue_mac_addr[8]; -#endif - struct in6_addr in6_addr_captured[MAX_DEFINED_IPV6_ADDRESSES_PER_UE]; - struct in_addr in_add_captured; -} sgi_teid_mapping_t; - - -// Main goal is to do an association IP address <-> MAC address -// may be usefull for netfilter that does not capture MAC address -// if not set on certain hook points (table,path). -typedef struct sgi_addr_mapping_s { - int is_outgoing_packet_seen; - ebi_t eps_bearer_id; ///< EPS default bearer identifier, (really ?) - Teid_t enb_S1U_teid; ///< dest tunnel identifier, for default bearer - Teid_t sgw_S1U_teid; ///< dest tunnel identifier, for default bearer -#ifdef SGI_UE_ETHER_TRAFFIC - char ue_mac_addr[ETH_ALEN]; -#endif -} sgi_addr_mapping_t; - - - - -typedef struct sgi_data_s { - int sd[SGI_MAX_EPS_BEARERS_PER_USER]; - unsigned int if_index[SGI_MAX_EPS_BEARERS_PER_USER]; - int sd6; - char *interface_name; - int interface_name_len; - int interface_index; -#ifndef SGI_UE_ETHER_TRAFFIC - char interface_hw_address[ETH_ALEN]; -#ifdef VLAN8021Q - struct ether_header_8021q_s eh; -#else - struct ether_header eh; -#endif -#endif - uint32_t ipv4_addr; - hash_table_t *teid_mapping; - hash_table_t *addr_v4_mapping; - obj_hash_table_t *addr_v6_mapping; - pthread_t capture_on_sgi_if_thread; - pthread_mutex_t thread_started_mutex; - int thread_started; - - void *sock_mmap_ring; - struct iovec *malloc_ring; - - int hw_address_of_router_captured; - uint32_t local_addr_v4_4_hw_address_router_capture; - uint32_t ipv4_addr_of_router; - char hss_associated; - - -#ifdef ENABLE_USE_PCAP_FOR_SGI - //brief PCAP descriptor for capturing packets on SGI interface. - pcap_t * pcap_descr; -#endif -#define SGI_BUFFER_RECV_LEN 3000 - unsigned char recv_buffer[sizeof(struct ether_header) + SGI_BUFFER_RECV_LEN][SGI_MAX_EPS_BEARERS_PER_USER]; - -} sgi_data_t; - - -typedef struct sgi_read_thread_args_s { - sgi_data_t *sgi_data; - int socket_index; -} sgi_read_thread_args_t; -//----------------------------------------------------------------------------- - -#include "mme_config.h" - - -#define SGI_MAX_EPS_BEARERS (SGI_MAX_SERVED_USERS_PER_PGW*SGI_MAX_EPS_BEARERS_PER_USER) - - - -//----------------------------------------------------------------------------- -// sgi_task.c -//----------------------------------------------------------------------------- -#include "spgw_config.h" -int sgi_init(const pgw_config_t *pgw_config_p); -char* sgi_status_2_str(SGIStatus_t statusP); - -//----------------------------------------------------------------------------- -// sgi_nf.c -//----------------------------------------------------------------------------- -#ifdef ENABLE_USE_NETFILTER_FOR_SGI -void* sgi_nf_fw_2_gtpv1u_thread(void *args_p); -#endif - -//----------------------------------------------------------------------------- -// sgi_pcap.c -//----------------------------------------------------------------------------- -#ifdef ENABLE_USE_PCAP_FOR_SGI -# define SGI_PCAPMAXBYTES2CAPTURE 65535 -# define SGI_PCAPTIMEDELAYKERNEL2USERSPACE 1000 - -/*! \fn void* sgi_pcap_loop(void*) -* \brief -* \param[in] devname The name of the device (ex "eth1") that will be listened for capturing packets. -* \param[in] iif The interface identifier that will be listened for capturing packets. -*/ -void* sgi_pcap_fw_2_gtpv1u_thread(void*); -#endif -//----------------------------------------------------------------------------- -// sgi_util.c -//----------------------------------------------------------------------------- -void sgi_print_hex_octets(unsigned char* dataP, unsigned long sizeP); -char* sgi_status_2_str (SGIStatus_t statusP); -char* sgi_arpopcode_2_str (unsigned short int opcodeP); -unsigned short in_cksum(unsigned short *addr, int len); -void sgi_send_arp_request(sgi_data_t *sgi_dataP, char* dst_ip_addrP); - -//----------------------------------------------------------------------------- -// sgi_socket.c -//----------------------------------------------------------------------------- -int sgi_create_sockets(sgi_data_t *sgi_data_p); -int sgi_send_data(uint8_t *buffer, uint32_t length, sgi_data_t *sgi_dataP, Teid_t originating_sgw_S1u_teidP); -int sgi_dgram_send_data(uint8_t *buffer_pP, uint32_t length, sgi_data_t *sgi_data_pP, Teid_t originating_sgw_S1u_teidP); - -#ifdef SGI_TEST -unsigned short in_cksum(unsigned short *addr, int len); -void sgi_test_send_ping(sgi_data_t *sgi_dataP, uint32_t markP, uint64_t src_mac_addrP, uint64_t dst_mac_addrP, char* src_ip_addrP, char* dst_ip_addrP); -#endif -#ifdef ENABLE_USE_RAW_SOCKET_FOR_SGI -void sgi_sock_raw_cleanup_handler(void *args_p); -void* sgi_sock_raw_fw_2_gtpv1u_thread(void* args_p); -#endif - -//----------------------------------------------------------------------------- -// sgi_egress.c -//----------------------------------------------------------------------------- -void sgi_forward_ip_packet(sgi_data_t *sgi_dataP, struct ether_header *ehP, int packet_sizeP, sgi_addr_mapping_t *addr_mappingP); -#ifdef ENABLE_USE_RAW_SOCKET_FOR_SGI -void sgi_process_raw_packet(sgi_data_t *sgi_dataP, unsigned char* dataP, int packet_sizeP); -#endif -void sgi_process_dgram_packet(sgi_data_t *sgi_dataP, unsigned char* dataP, int packet_sizeP); -#endif /* SGI_H_ */ diff --git a/openair-cn/SGI/sgi_egress.c b/openair-cn/SGI/sgi_egress.c deleted file mode 100755 index 526c088bdd1..00000000000 --- a/openair-cn/SGI/sgi_egress.c +++ /dev/null @@ -1,427 +0,0 @@ -/******************************************************************************* - OpenAirInterface - Copyright(c) 1999 - 2014 Eurecom - - OpenAirInterface is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - - OpenAirInterface is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with OpenAirInterface.The full GNU General Public License is - included in this distribution in the file called "COPYING". If not, - see <http://www.gnu.org/licenses/>. - - Contact Information - OpenAirInterface Admin: openair_admin@eurecom.fr - OpenAirInterface Tech : openair_tech@eurecom.fr - OpenAirInterface Dev : openair4g-devel@eurecom.fr - - Address : Eurecom, Compus SophiaTech 450, route des chappes, 06451 Biot, France. - - *******************************************************************************/ -/*! \file sgi_egress.c -* \brief -* \author Lionel Gauthier -* \company Eurecom -* \email: lionel.gauthier@eurecom.fr -*/ -#include <sys/socket.h> -#include <netinet/in.h> -#include <arpa/inet.h> -#include <string.h> - - -#include "sgi.h" -#include "gtpv1u.h" -#include "intertask_interface.h" -#include "assertions.h" - -#include <netinet/ip6.h> -#include <netinet/ip.h> -#include <net/if_arp.h> - - -struct ipv6hdr { - __u8 priority:4, - version:4; - __u8 flow_lbl[3]; - - __be16 payload_len; - __u8 nexthdr; - __u8 hop_limit; - - struct in6_addr saddr; - struct in6_addr daddr; -}; - -#ifdef ENABLE_USE_RAW_SOCKET_FOR_SGI - -#ifdef SGI_UE_ETHER_TRAFFIC -void sgi_process_raw_packet(sgi_data_t *sgi_data_pP, unsigned char* data_pP, int packet_sizeP) -{ - Gtpv1uTunnelDataReq *gtpv1u_tunnel_data_req_p = NULL; - MessageDef *message_p = NULL; - unsigned char *message_payload_p = NULL ; - struct ether_header *eh_p = (struct ether_header *) data_pP; - struct arphdr *arph_p = NULL; - struct iphdr *iph_p = NULL; - struct ipv6hdr *ip6h_p = NULL; - //struct arphdr *rarph = NULL; - //unsigned char *rarp_ptr = NULL; - //unsigned char *sha = NULL; /* Sender hardware address. */ - //unsigned char *tha = NULL; /* Target hardware address. */ - sgi_addr_mapping_t *addr_mapping_p = NULL; - //__be32 sip, tip; /* Sender, target IP address. */ - struct in6_addr dest6_addr; - u_int32_t dest4_addr; - struct in_addr in_dest_addr; - - - switch (htons(eh_p->ether_type)) { - - //******************* - case ETHERTYPE_IP: - //******************* - iph_p = (struct iphdr *) (data_pP + sizeof(struct ether_header)); - dest4_addr = iph_p->daddr; - - if (hashtable_get(sgi_data_pP->addr_v4_mapping, dest4_addr, (void**)&addr_mapping_p) == HASH_TABLE_OK) { - memcpy(eh_p->ether_dhost, addr_mapping_p->ue_mac_addr, ETH_ALEN); - //SGI_IF_DEBUG("--------------------------------------------------------------\n%s :\n", __FUNCTION__); - //sgi_print_hex_octets(data_pP, packet_sizeP); - - } else { - if (sgi_data_pP->ipv4_addr == dest4_addr) { - //SGI_IF_DEBUG("%s Dropping incoming egress IPV4 packet not UE IP flow\n", __FUNCTION__); - return; - } else { - in_dest_addr.s_addr = dest4_addr; - //SGI_IF_WARNING("%s Dropping incoming egress IPV4 packet, IPV4 dest %s not found \n", __FUNCTION__, inet_ntoa(in_dest_addr)); - return; - } - } - - break; - - - //******************* - case ETHERTYPE_IPV6: - //******************* - ip6h_p = (struct ipv6hdr *) (data_pP + sizeof(struct ether_header)); - memcpy(dest6_addr.__in6_u.__u6_addr8, ip6h_p->daddr.__in6_u.__u6_addr8, 16); - - if (obj_hashtable_get(sgi_data_pP->addr_v6_mapping, (void*)&dest6_addr, sizeof(struct in6_addr), (void**)&addr_mapping_p) == HASH_TABLE_OK) { - memcpy(eh_p->ether_dhost, addr_mapping_p->ue_mac_addr, ETH_ALEN); - //SGI_IF_DEBUG("--------------------------------------------------------------\n%s :\n", __FUNCTION__); - //sgi_print_hex_octets(data_pP, packet_sizeP); - } else { - //SGI_IF_WARNING("%s Dropping incoming egress IPV6 packet, IPV6 dest %X:%X:%X:%X:%X:%X:%X:%X not found \n", __FUNCTION__, NIP6ADDR(&dest6_addr)); - return; - } - - break; - - - //******************* - case ETHERTYPE_REVARP: - //******************* - SGI_IF_ERROR("%s UNHANDLED ETHERTYPE_REVARP of incoming egress packet\n", __FUNCTION__); - return; - break; - - - //******************* - case ETHERTYPE_ARP: - //******************* - SGI_IF_DEBUG("%s HANDLED ETHERTYPE_ARP of incoming egress packet\n", __FUNCTION__); - arph_p = (struct arphdr *) (data_pP + sizeof(struct ether_header)); -#ifdef SGI_UE_ETHER_TRAFFIC - // The entry should be here but all signalling tied with RRC procedures not finished so - // a data packet can arrive before the MODIFY_BEARER REQUEST - // get " unsigned char __ar_tip[4]; /* Target IP address. */" (from /usr/include/net/if_apr.h line 68) - memcpy(&dest4_addr, &((unsigned char*)(&arph_p[1]))[ETH_ALEN*2+4], 4); - SGI_IF_DEBUG("%s ARP OPCODE %s TARGET IP %d.%d.%d.%d\n", __FUNCTION__, sgi_arpopcode_2_str(ntohl(arph_p->ar_op)), NIPADDR(dest4_addr)); - - if (hashtable_get(sgi_data_pP->addr_v4_mapping, dest4_addr, (void**)&addr_mapping_p) == HASH_TABLE_OK) { - memcpy(eh_p->ether_dhost, addr_mapping_p->ue_mac_addr, ETH_ALEN); - } else { - if (sgi_data_pP->ipv4_addr == dest4_addr) { - //SGI_IF_DEBUG("%s Dropping incoming egress IPV4 packet not UE IP flow\n", __FUNCTION__); - return; - } else { - in_dest_addr.s_addr = dest4_addr; - //SGI_IF_WARNING("%s Dropping incoming egress IPV4 packet, IPV4 dest %s not found \n", __FUNCTION__, inet_ntoa(in_dest_addr)); - return; - } - } - -#else -#endif - break; - // rarph = (struct arphdr *)(data_pP + sizeof(struct ether_header)); - // - // // If it's not Ethernet, delete it. - // if (rarph->ar_pro != htons(ETH_P_IP)) { - // SGI_IF_ERROR("%s ARP PACKET PROTOCOL OG INCOMING PACKET IS NOT ETHERNET\n",__FUNCTION__); - // break; - // } - // rarp_ptr = (unsigned char *) (rarph + 1); - // sha = rarp_ptr; - // rarp_ptr += ETH_ALEN; - // memcpy(&sip, rarp_ptr, 4); - // rarp_ptr += 4; - // tha = rarp_ptr; - // rarp_ptr += ETH_ALEN; - // memcpy(&tip, rarp_ptr, 4); - // SGI_IF_DEBUG("%s ARP DEST IP transport IP = %d.%d.%d.%d\n",__FUNCTION__, NIPADDR(tip)); - // // TO DO IF NECESSARY - // break; - // - - default: - SGI_IF_ERROR("%s UNHANDLED ether type %d of incoming egress packet\n", __FUNCTION__, eh_p->ether_type); - return; - } - - message_p = itti_alloc_new_message(TASK_FW_IP, GTPV1U_TUNNEL_DATA_REQ); - - if (message_p == NULL) { - SGI_IF_ERROR("%s OUT OF MEMORY DROP EGRESS PACKET\n", __FUNCTION__); - return; - } - - message_payload_p = itti_malloc(TASK_FW_IP, TASK_GTPV1_U, packet_sizeP); - - if (message_payload_p == NULL) { - SGI_IF_ERROR("%s OUT OF MEMORY DROP EGRESS PACKET\n", __FUNCTION__); - return; - } - - memcpy(message_payload_p, data_pP, packet_sizeP); - - gtpv1u_tunnel_data_req_p = &message_p->ittiMsg.gtpv1uTunnelDataReq; - //LG HACK gtpv1u_tunnel_data_req_p->S1u_enb_teid = addr_mapping_p->enb_S1U_teid; -#warning forced S1u_enb_teid to 1 for testing, waiting for MODIFY_BEARER REQUEST - gtpv1u_tunnel_data_req_p->S1u_enb_teid = 1; - gtpv1u_tunnel_data_req_p->local_S1u_teid = addr_mapping_p->sgw_S1U_teid; - gtpv1u_tunnel_data_req_p->length = packet_sizeP; - gtpv1u_tunnel_data_req_p->buffer = message_payload_p; - SGI_IF_DEBUG("%s ETHER send GTPV1U_TUNNEL_DATA_REQ to GTPV1U S1u_enb_teid %u local_S1u_teid %u size %u\n", __FUNCTION__, gtpv1u_tunnel_data_req_p->S1u_enb_teid, - gtpv1u_tunnel_data_req_p->local_S1u_teid, packet_sizeP); - - itti_send_msg_to_task(TASK_GTPV1_U, INSTANCE_DEFAULT, message_p); - -} -#else -void sgi_process_raw_packet(sgi_data_t *sgi_data_pP, unsigned char* data_pP, int packet_sizeP) -{ - Gtpv1uTunnelDataReq *gtpv1u_tunnel_data_req_p = NULL; - MessageDef *message_p = NULL; - unsigned char *message_payload_p = NULL ; - struct ether_header *eh_p = (struct ether_header *) data_pP; - struct arphdr *arph_p = NULL; - struct iphdr *iph_p = NULL; - struct ipv6hdr *ip6h_p = NULL; - sgi_addr_mapping_t *addr_mapping_p = NULL; - struct in6_addr dest6_addr; - u_int32_t dest4_addr; - u_int32_t src4_addr; - struct in_addr in_dest_addr; - - - switch (htons(eh_p->ether_type)) { - //sgi_print_hex_octets(data_pP, packet_sizeP); - - //******************* - case ETHERTYPE_IP: - //******************* - iph_p = (struct iphdr *) (data_pP + sizeof(struct ether_header)); - dest4_addr = iph_p->daddr; - - if (hashtable_get(sgi_data_pP->addr_v4_mapping, dest4_addr, (void**)&addr_mapping_p) != HASH_TABLE_OK) { - if (sgi_data_pP->ipv4_addr == dest4_addr) { - //SGI_IF_DEBUG("%s Dropping incoming egress IPV4 packet not UE IP flow\n", __FUNCTION__); - return; - } else { - in_dest_addr.s_addr = dest4_addr; - //SGI_IF_WARNING("%s Dropping incoming egress IPV4 packet, IPV4 dest %s not found \n", __FUNCTION__, inet_ntoa(in_dest_addr)); - return; - } - } - - break; - - - //******************* - case ETHERTYPE_IPV6: - //******************* - ip6h_p = (struct ipv6hdr *) (data_pP + sizeof(struct ether_header)); - memcpy(dest6_addr.__in6_u.__u6_addr8, ip6h_p->daddr.__in6_u.__u6_addr8, 16); - - if (obj_hashtable_get(sgi_data_pP->addr_v6_mapping, (void*)&dest6_addr, sizeof(struct in6_addr), (void**)&addr_mapping_p) != HASH_TABLE_OK) { - SGI_IF_WARNING("%s Dropping incoming egress IPV6 packet, IPV6 dest %X:%X:%X:%X:%X:%X:%X:%X not found \n", __FUNCTION__, NIP6ADDR(&dest6_addr)); - return; - } - - break; - - - //******************* - case ETHERTYPE_REVARP: - //******************* - SGI_IF_ERROR("%s UNHANDLED ETHERTYPE_REVARP of incoming egress packet\n", __FUNCTION__); - return; - break; - - - //******************* - case ETHERTYPE_ARP: - //******************* - SGI_IF_DEBUG("%s HANDLED ETHERTYPE_ARP of incoming egress packet\n", __FUNCTION__); - arph_p = (struct arphdr *) (data_pP + sizeof(struct ether_header)); - // The entry should be here but all signalling tied with RRC procedures not finished so - // a data packet can arrive before the MODIFY_BEARER REQUEST - // get " unsigned char __ar_tip[4]; /* Target IP address. */" (from /usr/include/net/if_apr.h line 68) - memcpy(&dest4_addr, &((unsigned char*)(&arph_p[1]))[ETH_ALEN*2+4], 4); - SGI_IF_DEBUG("%s ARP OPCODE %s TARGET IP %d.%d.%d.%d\n", __FUNCTION__, sgi_arpopcode_2_str(ntohl(arph_p->ar_op)), NIPADDR(dest4_addr)); - - if (hashtable_get(sgi_data_pP->addr_v4_mapping, dest4_addr, (void**)&addr_mapping_p) != HASH_TABLE_OK) { - if (sgi_data_pP->ipv4_addr == dest4_addr) { - SGI_IF_DEBUG("%s Dropping incoming egress IPV4 packet not UE IP flow\n", __FUNCTION__); - return; - } else { - if (sgi_data_pP->hw_address_of_router_captured) { - in_dest_addr.s_addr = dest4_addr; - SGI_IF_WARNING("%s Dropping incoming egress IPV4 packet, IPV4 dest %s not found \n", __FUNCTION__, inet_ntoa(in_dest_addr)); - } else { - // may be a response to our ARP request to router - if (htons(arph_p->ar_op) == ARPOP_REPLY) { - memcpy(&src4_addr, &((unsigned char*)(&arph_p[1]))[ETH_ALEN], 4); - SGI_IF_DEBUG("%s FOR ROUTER HW ADDRESS COMPARING: %d - %d %d - %d\n", - __FUNCTION__, - sgi_data_pP->local_addr_v4_4_hw_address_router_capture, - dest4_addr, - sgi_data_pP->ipv4_addr_of_router, - src4_addr); - - if ((sgi_data_pP->local_addr_v4_4_hw_address_router_capture == dest4_addr) && (sgi_data_pP->ipv4_addr_of_router == src4_addr)) { - sgi_data_pP->hw_address_of_router_captured = 1; - sgi_data_pP->eh.ether_dhost[0] = ((unsigned char*)(&arph_p[1]))[0]; - sgi_data_pP->eh.ether_dhost[1] = ((unsigned char*)(&arph_p[1]))[1]; - sgi_data_pP->eh.ether_dhost[2] = ((unsigned char*)(&arph_p[1]))[2]; - sgi_data_pP->eh.ether_dhost[3] = ((unsigned char*)(&arph_p[1]))[3]; - sgi_data_pP->eh.ether_dhost[4] = ((unsigned char*)(&arph_p[1]))[4]; - sgi_data_pP->eh.ether_dhost[5] = ((unsigned char*)(&arph_p[1]))[5]; - SGI_IF_DEBUG("%s FOUND ROUTER HW ADDRESS: %02x:%02x:%02x:%02x:%02x:%02x\n", __FUNCTION__, NMACADDR(sgi_data_pP->eh.ether_dhost)); - } - } - } - - return; - } - } - - break; - - default: - //SGI_IF_ERROR("%s UNHANDLED ether type %d of incoming egress packet\n", __FUNCTION__, eh_p->ether_type); - return; - } - - //SGI_IF_DEBUG("--------------------------------------------------------------\n%s :\n", __FUNCTION__); - //sgi_print_hex_octets(data_pP+sizeof(sgi_data_pP->eh), packet_sizeP - sizeof(sgi_data_pP->eh)); - - message_p = itti_alloc_new_message(TASK_FW_IP, GTPV1U_TUNNEL_DATA_REQ); - - if (message_p == NULL) { - SGI_IF_ERROR("%s OUT OF MEMORY DROP EGRESS PACKET\n", __FUNCTION__); - return; - } - - AssertFatal((packet_sizeP - sizeof(sgi_data_pP->eh)) > 20, "BAD IP PACKET SIZE"); - message_payload_p = itti_malloc(TASK_FW_IP, TASK_GTPV1_U, packet_sizeP - sizeof(sgi_data_pP->eh) + GTPU_HEADER_OVERHEAD_MAX); - - if (message_payload_p == NULL) { - SGI_IF_ERROR("%s OUT OF MEMORY DROP EGRESS PACKET\n", __FUNCTION__); - return; - } - - memcpy(message_payload_p + GTPU_HEADER_OVERHEAD_MAX, data_pP+sizeof(sgi_data_pP->eh), packet_sizeP - sizeof(sgi_data_pP->eh)); - - gtpv1u_tunnel_data_req_p = &message_p->ittiMsg.gtpv1uTunnelDataReq; - gtpv1u_tunnel_data_req_p->S1u_enb_teid = addr_mapping_p->enb_S1U_teid; - //#warning forced S1u_enb_teid to 1 for testing, waiting for MODIFY_BEARER REQUEST - // gtpv1u_tunnel_data_req_p->S1u_enb_teid = 1; - gtpv1u_tunnel_data_req_p->local_S1u_teid = addr_mapping_p->sgw_S1U_teid; - gtpv1u_tunnel_data_req_p->length = packet_sizeP - sizeof(sgi_data_pP->eh); - gtpv1u_tunnel_data_req_p->offset = GTPU_HEADER_OVERHEAD_MAX; - gtpv1u_tunnel_data_req_p->buffer = message_payload_p; - SGI_IF_DEBUG("%s send GTPV1U_TUNNEL_DATA_REQ to GTPV1U S1u_enb_teid %u local_S1u_teid %u size %u\n", - __FUNCTION__, - gtpv1u_tunnel_data_req_p->S1u_enb_teid, - gtpv1u_tunnel_data_req_p->local_S1u_teid, - gtpv1u_tunnel_data_req_p->length); - - itti_send_msg_to_task(TASK_GTPV1_U, INSTANCE_DEFAULT, message_p); - -} -#endif -#endif -void sgi_process_dgram_packet(sgi_data_t *sgi_data_pP, unsigned char* data_pP, int packet_sizeP) -{ - Gtpv1uTunnelDataReq *gtpv1u_tunnel_data_req_p = NULL; - MessageDef *message_p = NULL; - unsigned char *message_payload_p = NULL ; - struct arphdr *arph_p = NULL; - struct iphdr *iph_p = NULL; - struct ipv6hdr *ip6h_p = NULL; - sgi_addr_mapping_t *addr_mapping_p = NULL; - struct in6_addr dest6_addr; - u_int32_t dest4_addr; - u_int32_t src4_addr; - struct in_addr in_dest_addr; - - sgi_print_hex_octets(data_pP, packet_sizeP); - - return; - message_p = itti_alloc_new_message(TASK_FW_IP, GTPV1U_TUNNEL_DATA_REQ); - - if (message_p == NULL) { - SGI_IF_ERROR("%s OUT OF MEMORY DROP EGRESS PACKET\n", __FUNCTION__); - return; - } - - AssertFatal(packet_sizeP > 20, "BAD IP PACKET SIZE"); - message_payload_p = itti_malloc(TASK_FW_IP, TASK_GTPV1_U, packet_sizeP + GTPU_HEADER_OVERHEAD_MAX); - - if (message_payload_p == NULL) { - SGI_IF_ERROR("%s OUT OF MEMORY DROP EGRESS PACKET\n", __FUNCTION__); - return; - } - - memcpy(message_payload_p + GTPU_HEADER_OVERHEAD_MAX, data_pP, packet_sizeP); - - gtpv1u_tunnel_data_req_p = &message_p->ittiMsg.gtpv1uTunnelDataReq; - gtpv1u_tunnel_data_req_p->S1u_enb_teid = addr_mapping_p->enb_S1U_teid; - //#warning forced S1u_enb_teid to 1 for testing, waiting for MODIFY_BEARER REQUEST - // gtpv1u_tunnel_data_req_p->S1u_enb_teid = 1; - gtpv1u_tunnel_data_req_p->local_S1u_teid = addr_mapping_p->sgw_S1U_teid; - gtpv1u_tunnel_data_req_p->length = packet_sizeP ; - gtpv1u_tunnel_data_req_p->offset = GTPU_HEADER_OVERHEAD_MAX; - gtpv1u_tunnel_data_req_p->buffer = message_payload_p; - SGI_IF_DEBUG("%s send GTPV1U_TUNNEL_DATA_REQ to GTPV1U S1u_enb_teid %u local_S1u_teid %u size %u\n", - __FUNCTION__, - gtpv1u_tunnel_data_req_p->S1u_enb_teid, - gtpv1u_tunnel_data_req_p->local_S1u_teid, - gtpv1u_tunnel_data_req_p->length); - - itti_send_msg_to_task(TASK_GTPV1_U, INSTANCE_DEFAULT, message_p); - -} diff --git a/openair-cn/SGI/sgi_nf.c b/openair-cn/SGI/sgi_nf.c deleted file mode 100755 index c81dcf64d68..00000000000 --- a/openair-cn/SGI/sgi_nf.c +++ /dev/null @@ -1,362 +0,0 @@ -/******************************************************************************* - OpenAirInterface - Copyright(c) 1999 - 2014 Eurecom - - OpenAirInterface is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - - OpenAirInterface is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with OpenAirInterface.The full GNU General Public License is - included in this distribution in the file called "COPYING". If not, - see <http://www.gnu.org/licenses/>. - - Contact Information - OpenAirInterface Admin: openair_admin@eurecom.fr - OpenAirInterface Tech : openair_tech@eurecom.fr - OpenAirInterface Dev : openair4g-devel@eurecom.fr - - Address : Eurecom, Compus SophiaTech 450, route des chappes, 06451 Biot, France. - - *******************************************************************************/ -/*! \file sgi_nf.c -* \brief -* \author Lionel Gauthier -* \company Eurecom -* \email: lionel.gauthier@eurecom.fr -*/ -#include <stdio.h> -#include <string.h> - -#include <netinet/in.h> -#include <linux/netfilter.h> /* Defines verdicts (NF_ACCEPT, etc) */ -#include <libnfnetlink/libnfnetlink.h> -#include <libnetfilter_queue/libnetfilter_queue.h> -#include <libnetfilter_queue/linux_nfnetlink_queue.h> - -#include "mme_config.h" -#include "intertask_interface.h" -#include "sgi.h" -//----------------------------------------------------------------------------- -struct nfq_handle { - struct nfnl_handle *nfnlh; - struct nfnl_subsys_handle *nfnlssh; - struct nfq_q_handle *qh_list; -}; - -struct nfq_q_handle { - struct nfq_q_handle *next; - struct nfq_handle *h; - u_int16_t id; - - nfq_callback *cb; - void *data; -}; - -struct nfq_data { - struct nfattr **data; -}; - - -enum { - NFQ_XML_HW = (1 << 0), NFQ_XML_MARK = (1 << 1), NFQ_XML_DEV = (1 << 2), NFQ_XML_PHYSDEV = (1 << 3), - NFQ_XML_PAYLOAD = (1 << 4), NFQ_XML_TIME = (1 << 5), NFQ_XML_ALL = ~0U -}; -//------------------------------------------------------ -#define SNPRINTF_FAILURE(ret, rem, offset, len) \ -do { \ - if (ret < 0) \ - return ret; \ - len += ret; \ - if (ret > rem) \ - ret = rem; \ - offset += ret; \ - rem -= ret; \ -} while (0) - -//------------------------------------------------------ -static int nfq_snprintf(char *buf, size_t rem, struct nfq_data *tb, int flags) -//------------------------------------------------------ -{ - struct nfqnl_msg_packet_hdr *ph; - struct nfqnl_msg_packet_hw *hwph; - u_int32_t mark, ifi; - int size, offset = 0, len = 0, ret; - unsigned char *data; - - size = snprintf(buf + offset, rem, "<pkt>"); - SNPRINTF_FAILURE(size, rem, offset, len); - - - - ph = nfq_get_msg_packet_hdr(tb); - - if (ph) { - size = snprintf(buf + offset, rem, - "<hook> %u <id>%u", - ph->hook, ntohl(ph->packet_id)); - SNPRINTF_FAILURE(size, rem, offset, len); - - hwph = nfq_get_packet_hw(tb); - - if (hwph && (flags & NFQ_XML_HW)) { - int i, hlen = ntohs(hwph->hw_addrlen); - - size = snprintf(buf + offset, rem, "<hw><proto>%04x" - "</proto>", - ntohs(ph->hw_protocol)); - SNPRINTF_FAILURE(size, rem, offset, len); - - size = snprintf(buf + offset, rem, "<src>"); - SNPRINTF_FAILURE(size, rem, offset, len); - - for (i=0; i<hlen; i++) { - size = snprintf(buf + offset, rem, "%02x", - hwph->hw_addr[i]); - SNPRINTF_FAILURE(size, rem, offset, len); - } - - size = snprintf(buf + offset, rem, "</src></hw>"); - SNPRINTF_FAILURE(size, rem, offset, len); - } else if (flags & NFQ_XML_HW) { - size = snprintf(buf + offset, rem, "<hw><proto>%04x" - "</proto></hw>", - ntohs(ph->hw_protocol)); - SNPRINTF_FAILURE(size, rem, offset, len); - } - } - - mark = nfq_get_nfmark(tb); - - if (mark && (flags & NFQ_XML_MARK)) { - size = snprintf(buf + offset, rem, "<mark>%u</mark>", mark); - SNPRINTF_FAILURE(size, rem, offset, len); - } - - ifi = nfq_get_indev(tb); - - if (ifi && (flags & NFQ_XML_DEV)) { - size = snprintf(buf + offset, rem, "<indev>%u</indev>", ifi); - SNPRINTF_FAILURE(size, rem, offset, len); - } - - ifi = nfq_get_outdev(tb); - - if (ifi && (flags & NFQ_XML_DEV)) { - size = snprintf(buf + offset, rem, "<outdev>%u</outdev>", ifi); - SNPRINTF_FAILURE(size, rem, offset, len); - } - - ifi = nfq_get_physindev(tb); - - if (ifi && (flags & NFQ_XML_PHYSDEV)) { - size = snprintf(buf + offset, rem, - "<physindev>%u</physindev>", ifi); - SNPRINTF_FAILURE(size, rem, offset, len); - } - - ifi = nfq_get_physoutdev(tb); - - if (ifi && (flags & NFQ_XML_PHYSDEV)) { - size = snprintf(buf + offset, rem, - "<physoutdev>%u</physoutdev>", ifi); - SNPRINTF_FAILURE(size, rem, offset, len); - } - - ret = nfq_get_payload(tb, &data); - - if (ret >= 0 && (flags & NFQ_XML_PAYLOAD)) { - int i; - - size = snprintf(buf + offset, rem, "<payload>"); - SNPRINTF_FAILURE(size, rem, offset, len); - - for (i=0; i<ret; i++) { - size = snprintf(buf + offset, rem, "%02x", - data[i] & 0xff); - SNPRINTF_FAILURE(size, rem, offset, len); - } - - size = snprintf(buf + offset, rem, "</payload>"); - SNPRINTF_FAILURE(size, rem, offset, len); - } - - size = snprintf(buf + offset, rem, "</pkt>"); - SNPRINTF_FAILURE(size, rem, offset, len); - - return len; -} -//------------------------------------------------------ -static int sgi_nfqueue_callback(struct nfq_q_handle *myQueue, struct nfgenmsg *msg, - struct nfq_data *pkt, void *cbData) -//----------------------------------------------------------------------------- -{ - uint32_t id = 0; - struct nfqnl_msg_packet_hdr *header; - struct nfqnl_msg_packet_hw *macAddr; - MessageDef *message_p; - Gtpv1uTunnelDataReq *data_req_p; - Teid_t local_teid; - u_int32_t verdict; - - if ((header = nfq_get_msg_packet_hdr(pkt))) { - id = ntohl(header->packet_id); - SGI_IF_DEBUG("packet_id %u hw_protocol %u hook %u\n", ntohl(header->packet_id), ntohs(header->hw_protocol), header->hook); - } - - // The HW address is only fetchable at certain hook points - // LG Warning HW address is src address - macAddr = nfq_get_packet_hw(pkt); - - if (macAddr) { - SGI_IF_DEBUG("MAC len %u addr %02X:%02X:%02X:%02X:%02X:%02X\n", - ntohs(macAddr->hw_addrlen), - macAddr->hw_addr[0], - macAddr->hw_addr[1], - macAddr->hw_addr[2], - macAddr->hw_addr[3], - macAddr->hw_addr[4], - macAddr->hw_addr[5]); - } else { - SGI_IF_DEBUG("No MAC addr\n"); - } - - /*timeval tv; - if (!nfq_get_timestamp(pkt, &tv)) { - cout << "; tstamp " << tv.tv_sec << "." << tv.tv_usec; - } else { - cout << "; no tstamp"; - }*/ - - //cout << "; mark " << nfq_get_nfmark(pkt); - // Print the payload; in copy meta mode, only headers will be included; - // in copy packet mode, whole packet will be returned. - char *pktData; - int len = nfq_get_payload(pkt, &pktData); - - // Note that you can also get the physical devices - SGI_IF_DEBUG("pkt id %d recvd: indev %d outdev %d mark %d len %d\n", - id, - nfq_get_indev(pkt), - nfq_get_outdev(pkt), - nfq_get_nfmark(pkt), - len); - - - //sgi_print_hex_octets((unsigned char *)pktData, len); - - message_p = itti_alloc_new_message(TASK_FW_IP, GTPV1U_TUNNEL_DATA_REQ); - - if (message_p == NULL) { - return -1; - } - - data_req_p = &message_p->ittiMsg.gtpv1uTunnelDataReq; - data_req_p->buffer = malloc(sizeof(uint8_t) * len); - - if (data_req_p->buffer == NULL) { - SGI_IF_ERROR("Failed to allocate new buffer\n"); - itti_free(ITTI_MSG_ORIGIN_ID(message_p), message_p); - message_p = NULL; - return -1; - } else { - // MAY BE TO BE CHANGED - local_teid = nfq_get_nfmark(pkt); - - // if packet is marked, it is a packet going into a EPS bearer - //if (local_teid != 0) { - if (1) { - data_req_p->local_S1u_teid = local_teid; - - memcpy(data_req_p->buffer, pktData, len); - data_req_p->length = len; - - if (itti_send_msg_to_task(TASK_GTPV1_U, INSTANCE_DEFAULT, message_p) < 0) { - SGI_IF_ERROR("Failed to send message to task\n"); - itti_free(ITTI_MSG_ORIGIN_ID(message_p), message_p); - message_p = NULL; - } - - verdict = NF_STOLEN; - return nfq_set_verdict(myQueue, id, verdict, 0, NULL); - } else { - verdict = NF_ACCEPT; - return nfq_set_verdict(myQueue, id, verdict, len, pktData); - } - } - - return 0; - // end sgi_nfqueue_callback -} -//----------------------------------------------------------------------------- -void* sgi_nf_fw_2_gtpv1u_thread(void *args_p) -//----------------------------------------------------------------------------- -{ - struct nfq_handle *nfqHandle; - struct nfq_q_handle *myQueue; - struct nfnl_handle *netlinkHandle; - int fd, res; - volatile sgi_data_t *sgi_data_p; - - sgi_data_p = (sgi_data_t*)args_p; - - SGI_IF_DEBUG("RX thread on netfilter queue started, operating on Device %s iif %d\n", sgi_data_p->interface_name, sgi_data_p->interface_index); - - // Get a queue connection handle from the module - if (!(nfqHandle = nfq_open())) { - SGI_IF_ERROR("Error in nfq_open()"); - exit(-1); - } - - // Unbind the handler from processing any IP packets - // Not totally sure why this is done, or if it's necessary... - if (nfq_unbind_pf(nfqHandle, PF_INET) < 0) { - SGI_IF_ERROR("Error in nfq_unbind_pf()"); - exit(-1); - } - - // Bind this handler to process IP packets... - if (nfq_bind_pf(nfqHandle, PF_INET) < 0) { - SGI_IF_ERROR("Error in nfq_bind_pf()"); - exit(-1); - } - - // Install a callback on queue 1 - if (!(myQueue = nfq_create_queue(nfqHandle, 1, &sgi_nfqueue_callback, NULL))) { - SGI_IF_ERROR("Error in nfq_create_queue()"); - exit(-1); - } - - // Turn on packet copy mode - if (nfq_set_mode(myQueue, NFQNL_COPY_PACKET, 0xffff) < 0) { - SGI_IF_ERROR("Could not set packet copy mode"); - exit(-1); - } - - netlinkHandle = nfq_nfnlh(nfqHandle); - fd = nfnl_fd(netlinkHandle); - - SGI_IF_DEBUG("Waiting for egress packets\n"); - sgi_data_p->thread_started = 1; - - while ((res = recv(fd, &sgi_data_p->recv_buffer[sizeof(struct ether_header)], SGI_BUFFER_RECV_LEN, 0)) && res >= 0) { - // a callback mechanism is used - // rather than just handling it directly here, but that - // seems to be the convention... - nfq_handle_packet(nfqHandle, &sgi_data_p->recv_buffer[sizeof(struct ether_header)], res); - // end while receiving traffic - } - - nfq_destroy_queue(myQueue); - - nfq_close(nfqHandle); - - return NULL; -} diff --git a/openair-cn/SGI/sgi_pcap.c b/openair-cn/SGI/sgi_pcap.c deleted file mode 100755 index b81d743562b..00000000000 --- a/openair-cn/SGI/sgi_pcap.c +++ /dev/null @@ -1,99 +0,0 @@ -/******************************************************************************* - OpenAirInterface - Copyright(c) 1999 - 2014 Eurecom - - OpenAirInterface is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - - OpenAirInterface is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with OpenAirInterface.The full GNU General Public License is - included in this distribution in the file called "COPYING". If not, - see <http://www.gnu.org/licenses/>. - - Contact Information - OpenAirInterface Admin: openair_admin@eurecom.fr - OpenAirInterface Tech : openair_tech@eurecom.fr - OpenAirInterface Dev : openair4g-devel@eurecom.fr - - Address : Eurecom, Compus SophiaTech 450, route des chappes, 06451 Biot, France. - - *******************************************************************************/ -/*! \file sgi_pcap.c -* \brief -* \author Lionel Gauthier -* \company Eurecom -* \email: lionel.gauthier@eurecom.fr -*/ -#include <string.h> -#include "sgi.h" - - -//--------------------------------------------------------------------------------------------------------------------- -void* sgi_pcap_fw_2_gtpv1u_thread(void* args_p) -{ - bpf_u_int32 netaddr = 0, mask = 0; // To store network address and netmask - struct bpf_program filter; // Place to store the BPF filter program - char errbuf[PCAP_ERRBUF_SIZE]; // Error buffer - struct pcap_pkthdr pkthdr; // Packet information (timestamp, size...) - const unsigned char *packet = NULL; // Received raw data - char filter_string[] = ""; - sgi_data_t *sgi_data_p; - - sgi_data_p = (sgi_data_t*)args_p; - - SGI_IF_DEBUG("[PCAP] Device is %s and iif is %d\n", sgi_data_p->interface_name, sgi_data_p->interface_index); - - memset(errbuf, 0, PCAP_ERRBUF_SIZE); - - sgi_data_p->pcap_descr = pcap_open_live(sgi_data_p->interface_name, SGI_PCAPMAXBYTES2CAPTURE, 0, SGI_PCAPTIMEDELAYKERNEL2USERSPACE, errbuf); - - if (sgi_data_p->pcap_descr == NULL) - SGI_IF_ERROR("Error %s", errbuf); - else if (*errbuf) - SGI_IF_WARNING("Warning %s\n", errbuf); - - // Look up info from the capture device - if (pcap_lookupnet(sgi_data_p->interface_name, &netaddr, &mask, errbuf) == -1) { - SGI_IF_ERROR("Can't get netmask for device %s\n", sgi_data_p->interface_name); - netaddr = 0; - mask = 0; - pthread_exit(NULL); - } - - // Compiles the filter expression into a BPF filter program - if (pcap_compile(sgi_data_p->pcap_descr, &filter, filter_string, 0, mask) == -1) { - SGI_IF_ERROR("Couldn't parse filter : %s\n", pcap_geterr(sgi_data_p->pcap_descr)); - pthread_exit(NULL); - } - - // Load the filter program into the packet capture device - if (pcap_setfilter(sgi_data_p->pcap_descr, &filter) == -1) { - SGI_IF_ERROR("Couldn't install filter: %s\n", pcap_geterr(sgi_data_p->pcap_descr)); - pthread_exit(NULL); - } - - pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL); - sgi_data_p->thread_started = 1; - - while (1) { - packet = pcap_next(sgi_data_p->pcap_descr, &pkthdr); // Get one packet - - if ( ( pkthdr.len > 0 ) && ( packet != NULL ) ) { - sgi_print_hex_octets(packet, pkthdr.len); - - if (packet[54] == 0x85) { // case ROUTER SOLICITATION WITH ETHERNET HEADER - } - } - } - - pthread_exit(NULL); -} - diff --git a/openair-cn/SGI/sgi_socket.c b/openair-cn/SGI/sgi_socket.c deleted file mode 100644 index a73fcbd9d26..00000000000 --- a/openair-cn/SGI/sgi_socket.c +++ /dev/null @@ -1,1035 +0,0 @@ -/******************************************************************************* - OpenAirInterface - Copyright(c) 1999 - 2014 Eurecom - - OpenAirInterface is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - - OpenAirInterface is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with OpenAirInterface.The full GNU General Public License is - included in this distribution in the file called "COPYING". If not, - see <http://www.gnu.org/licenses/>. - - Contact Information - OpenAirInterface Admin: openair_admin@eurecom.fr - OpenAirInterface Tech : openair_tech@eurecom.fr - OpenAirInterface Dev : openair4g-devel@eurecom.fr - - Address : Eurecom, Compus SophiaTech 450, route des chappes, 06451 Biot, France. - - *******************************************************************************/ -/*! \file sgi_socket.c -* \brief -* \author Lionel Gauthier -* \company Eurecom -* \email: lionel.gauthier@eurecom.fr -*/ -#include <pthread.h> -#include <stdio.h> -#include <string.h> -#include <unistd.h> -#include <errno.h> -#include <assert.h> -#include <fcntl.h> -#include <stdlib.h> - -#include <sys/ioctl.h> -#include <sys/types.h> -#include <sys/socket.h> -#include <sys/mman.h> //mmap - -#include <asm/types.h> -#include <net/if.h> -#include <net/ethernet.h> -#include <linux/if_ether.h> -#include <net/if_arp.h> -#include <linux/if_packet.h> -#include <netinet/in.h> -#include <poll.h> -#include <arpa/inet.h> -#ifndef SGI_UE_ETHER_TRAFFIC -#include <sys/uio.h> -#endif - - -#include <netinet/ip6.h> -#include <netinet/ip.h> -#include "sgi.h" -#include "intertask_interface.h" - - -//static char sgi_command_buffer[256]; - -#define HW_ADDRESS "%02x:%02x:%02x:%02x:%02x:%02x" -#define HW_ADDRESS_FORMAT(iFR) \ - (uint8_t)(iFR)[0], \ - (uint8_t)(iFR)[1], \ - (uint8_t)(iFR)[2], \ - (uint8_t)(iFR)[3], \ - (uint8_t)(iFR)[4], \ - (uint8_t)(iFR)[5] - -#define IPV4_ADDR "%u.%u.%u.%u" -#define IPV4_ADDR_FORMAT(aDDRESS) \ - (uint8_t)((aDDRESS) & 0x000000ff), \ - (uint8_t)(((aDDRESS) & 0x0000ff00) >> 8 ), \ - (uint8_t)(((aDDRESS) & 0x00ff0000) >> 16), \ - (uint8_t)(((aDDRESS) & 0xff000000) >> 24) - -struct ipv6hdr { - __u8 priority:4, - version:4; - __u8 flow_lbl[3]; - - __be16 payload_len; - __u8 nexthdr; - __u8 hop_limit; - - struct in6_addr saddr; - struct in6_addr daddr; -}; - - -/// The number of frames in the ring -// This number is not set in stone. Nor are block_size, block_nr or frame_size -#define CONF_RING_FRAMES 128 - -/// Offset of data from start of frame -#define PKT_OFFSET (TPACKET_ALIGN(sizeof(struct tpacket_hdr)) + \ - TPACKET_ALIGN(sizeof(struct sockaddr_ll))) - -int sgi_create_vlan_interface(char *interface_nameP, int vlan_idP) -{ - char vlan_interface_name[IFNAMSIZ]; - char command_line[256]; - int ret = 0; - - ret = sprintf(vlan_interface_name, "%s.%d", interface_nameP, vlan_idP); - - if (ret > 0) { - ret = sprintf(command_line, "ifconfig %s down > /dev/null 2>&1", vlan_interface_name); - - if (ret > 0) ret = system(command_line); - else return -1; - - ret = sprintf(command_line, "vconfig rem %s > /dev/null 2>&1", vlan_interface_name); - - if (ret > 0) ret = system(command_line); - else return -1; - - ret = sprintf(command_line, "vconfig add %s %d", interface_nameP, vlan_idP); - - if (ret > 0) ret = system(command_line); - else return -1; - - ret = sprintf(command_line, "ifconfig %s up", vlan_interface_name); - - if (ret > 0) ret = system(command_line); - else return -1; - - ret = sprintf(command_line, "sync"); - - if (ret > 0) ret = system(command_line); - else return -1; - - //ret = sprintf(command_line, "ip -4 addr add 10.0.%d.2/24 dev %s", vlan_idP+200, vlan_interface_name); - //if (ret > 0) ret = system(command_line); else return -1; - return 0; - } else { - return -1; - } -} - - -int sgi_create_sockets(sgi_data_t *sgi_data_p) -{ -#ifdef SGI_SOCKET_BIND_TO_IF - struct sockaddr_ll socket_address; - char if_name[16]; -#endif -#ifdef SGI_MARKING - int value = 0; - const int *val_p=&value; -#endif -#ifdef SGI_PACKET_RX_RING - struct tpacket_req tp; -#endif - uint32_t i = 0; -#ifndef SGI_UE_ETHER_TRAFFIC - FILE *fp = NULL; - char filename[128]; - int rc = 0; - char *router_mac_addr = NULL; - int b = 0; - char addr_mac_byte[16]; -#endif - - if (sgi_data_p == NULL) { - return -1; - } - - SGI_IF_DEBUG("Creating sockets for sgi on interface %s\n", sgi_data_p->interface_name); - - // qci = 0 is for the default bearers QOS, Non-GBR - /* Create a RAW IP socket and request for all internet IP traffic */ - // work - for (i = 0; i < SGI_MAX_EPS_BEARERS_PER_USER; i++) { - - sgi_create_vlan_interface(sgi_data_p->interface_name,i+SGI_MIN_EPS_BEARER_ID); - - // works also -#if defined SGI_SOCKET_RAW - sgi_data_p->sd[i] = socket(PF_PACKET, SOCK_RAW, htons(IPPROTO_RAW)); -#else -#if defined SGI_SOCKET_DGRAM - SGI_IF_DEBUG("Created socket PF_PACKET/SOCK_DGRAM/ETH_P_ALL\n",strerror(errno), errno); - sgi_data_p->sd[i] = socket(PF_PACKET, SOCK_DGRAM, htons(ETH_P_ALL)); -#endif -#endif - //sgi_data_p->sd[i] = socket(AF_INET, SOCK_RAW, ETH_P_IP); - //sgi_data_p->sd[i] = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_IP)); - - if (sgi_data_p->sd[i] < 0) { - SGI_IF_ERROR("Error during socket creation (%s:%d)\n",strerror(errno), errno); - goto error; - } - - /* socket options, tell the kernel we provide the IP structure - int one = 1; - const int *val = &one; - if(setsockopt(sgi_data_p->sd[i], IPPROTO_IP, IP_HDRINCL, val, sizeof(one)) < 0) - { - SGI_IF_ERROR("Error during socket setsockopt IP_HDRINCL (%s:%d)\n", strerror(errno), errno); - goto error; - }*/ - - -#ifdef SGI_MARKING - // setting socket option to use MARK value - //value = rab_id + SGI_MIN_EPS_BEARER_ID; - value = 5; - - if (setsockopt (sgi_data_p->sd[i], SOL_SOCKET, SO_MARK, val_p, sizeof (value)) < 0) { - SGI_IF_ERROR("error notifying kernel about MARK"); - goto error; - } - - SGI_IF_DEBUG("Created socket %d for rab_id %d (for any UE context)\n", sgi_data_p->sd[i], value); -#endif - -#ifdef SGI_PACKET_RX_RING - // tell kernel to export data through mmap()ped ring - tp.tp_block_size = CONF_RING_FRAMES * getpagesize(); - tp.tp_block_nr = 1; - tp.tp_frame_size = getpagesize(); - tp.tp_frame_nr = CONF_RING_FRAMES; - - if (setsockopt(sgi_data_p->sd[i], SOL_PACKET, PACKET_RX_RING, (void*) &tp, sizeof(tp))) { - SGI_IF_ERROR("setsockopt() ring\n"); - goto error; - } - - // open ring - sgi_data_p->sock_mmap_ring = mmap(0, tp.tp_block_size * tp.tp_block_nr, PROT_READ | PROT_WRITE, MAP_SHARED, sgi_data_p->sd[i], 0); - - if (!sgi_data_p->sock_mmap_ring) { - SGI_IF_ERROR("Failed to mmap socket (%s:%d)\n", strerror(errno), errno); - goto error; - } - - /* Setup our ringbuffer */ - sgi_data_p->malloc_ring = malloc(tp.tp_frame_nr * sizeof(struct iovec)); - - for(i=0; i<tp.tp_frame_nr; i++) { - sgi_data_p->malloc_ring[i].iov_base=(void *)((long)sgi_data_p->sock_mmap_ring)+(i*tp.tp_frame_size); - sgi_data_p->malloc_ring[i].iov_len=tp.tp_frame_size; - } - -#endif - -#ifdef SGI_SOCKET_BIND_TO_IF - sprintf(if_name, "%s.%d",sgi_data_p->interface_name,i+SGI_MIN_EPS_BEARER_ID); - - memset(&socket_address, 0, sizeof(struct sockaddr_ll)); - socket_address.sll_family = AF_PACKET; //always PF_PACKET - - //socket_address.sll_addr = ;// Filled when we want to tx - //socket_address.sll_halen = ;// Filled when we want to tx - //socket_address.sll_family ;// Filled when we want to tx - - //socket_address.sll_hatype = ;// Filled when packet received - //socket_address.sll_pkttype = ;// Filled when packet received - sgi_data_p->if_index[i] = if_nametoindex(if_name); - socket_address.sll_ifindex = sgi_data_p->if_index[i]; - //LG 2014-11-07socket_address.sll_protocol = htons(ETH_P_IP);/* Protocol phy level */ - socket_address.sll_protocol = htons(ETH_P_ALL); - - // Now we can bind the socket to send the IP traffic - if (bind(sgi_data_p->sd[i], (struct sockaddr *)&socket_address, sizeof(struct sockaddr_ll)) < 0) { - SGI_IF_ERROR("Bind socket to %s (%s:%d)\n", if_name, strerror(errno), errno); - goto error; - } else { - SGI_IF_DEBUG("Bind EPS bearer ID %d socket %d to %s\n", - i+SGI_MIN_EPS_BEARER_ID, sgi_data_p->sd[i], if_name); - } - -#endif - - } - -#ifndef SGI_SOCKET_DGRAM - - if (sprintf(filename, "/sys/class/net/%s/address", sgi_data_p->interface_name) <= 0 ) { - SGI_IF_ERROR("Build of file name /sys/class/net/sgi_if_name/address Failed (%s:%d)\n", strerror(errno), errno); - goto error; - } - - fp = fopen(filename, "r"); - - if (fp) { - rc = fscanf(fp, "%hhx:%hhx:%hhx:%hhx:%hhx:%hhx", - &sgi_data_p->interface_hw_address[0], - &sgi_data_p->interface_hw_address[1], - &sgi_data_p->interface_hw_address[2], - &sgi_data_p->interface_hw_address[3], - &sgi_data_p->interface_hw_address[4], - &sgi_data_p->interface_hw_address[5]); - fclose(fp); - - if (rc <= 0) { - SGI_IF_ERROR("ERROR reading %s\n" ,filename); - goto error; - } - } else { - SGI_IF_ERROR("Correct /sys/class/net/sgi_if_name file not found\n"); - goto error; - } - - memcpy((void*)(&sgi_data_p->eh.ether_shost[0]), (void*)(&sgi_data_p->interface_hw_address[0]), ETH_ALEN); - router_mac_addr = getenv("MAC_ROUTER"); - - if (router_mac_addr == NULL) { - SGI_IF_ERROR("ERROR getting ENV variable MAC_ROUTER, should be set by start script\n"); - goto error; - } - - for (b = 0 ; b < 6; b++) { - strncpy(addr_mac_byte, router_mac_addr+2*b, 2); - addr_mac_byte[2] = '\0'; - // we can do (unsigned int*) because x86 processors are little-endian - // (done for suppressing a warning) - rc = sscanf ((const char*)addr_mac_byte, "%02x", (uint32_t*)&i); - - if (rc < 1) { - SGI_IF_ERROR("Error in converting string MAC_ROUTER address %s in char array\n", router_mac_addr); - goto error; - } - - sgi_data_p->eh.ether_dhost[b] = (i & 0x000000FF); - } - - SGI_IF_DEBUG("Found MAC address for ROUTER : %02x:%02x:%02x:%02x:%02x:%02x\n", - NMACADDR(sgi_data_p->eh.ether_dhost)); - -#ifdef VLAN8021Q - sgi_data_p->eh.ether_vlan8021q.vlan_tpid = htons(0x8100); - sgi_data_p->eh.ether_vlan8021q.vlan_tci = htons(0x7000 | 0x0000 | 0x0000); -#endif - SGI_IF_DEBUG("Found MAC address for SGI IF %s: %02x:%02x:%02x:%02x:%02x:%02x\n", - sgi_data_p->interface_name, NMACADDR(sgi_data_p->eh.ether_shost)); - -#endif - return 0; -error: - SGI_IF_ERROR("ERROR (%s)\n", strerror(errno)); - - for (i=0; i<SGI_MAX_EPS_BEARERS_PER_USER; i++) { - if (sgi_data_p->sd[i] > 0) { - close(sgi_data_p->sd[i]); - } - - sgi_data_p->sd[i] = -1; - } - - return -1; -} -#ifdef SGI_UE_ETHER_TRAFFIC -int sgi_send_data(uint8_t *buffer_pP, uint32_t length, sgi_data_t *sgi_data_pP, Teid_t originating_sgw_S1u_teidP) -{ - struct ether_header *eh_p = (struct ether_header *) buffer_pP; - struct iphdr *iph_p = NULL; - struct arphdr *arph_p = NULL; - struct ipv6hdr *ip6h_p = NULL; - sgi_teid_mapping_t *mapping_p = NULL; - sgi_addr_mapping_t *addr_mapping_p = NULL; - hashtable_rc_t hash_rc; - struct in6_addr src6_addr; /* source address */ - struct in6_addr *src6_addr_p; /* source address */ - u_int32_t src4_addr; - - if (buffer_pP == NULL) { - SGI_IF_ERROR("sgi_send_data: received bad parameter\n"); - return -1; - } - - // get IP version of this packet - switch (htons(eh_p->ether_type)) { - - //******************* - case ETHERTYPE_IP: - //******************* - iph_p = (struct iphdr *) (buffer_pP + sizeof(struct ether_header)); - // The entry should be here but all signalling tied with RRC procedures not finished so - // a data packet can arrive before the MODIFY_BEARER REQUEST - src4_addr = iph_p->saddr; - - if (hashtable_get(sgi_data_pP->addr_v4_mapping, src4_addr, (void**)&addr_mapping_p) != HASH_TABLE_OK) { - hash_rc = hashtable_get(sgi_data_pP->teid_mapping, originating_sgw_S1u_teidP, (void**)&mapping_p); - - if (hash_rc == HASH_TABLE_KEY_NOT_EXISTS) { - SGI_IF_ERROR("%s Error unknown context SGW teid %d\n", __FUNCTION__, originating_sgw_S1u_teidP); - return -1; - } else { - if (mapping_p->is_outgoing_ipv4_packet_seen == 0) { - mapping_p->hw_addrlen = ETH_ALEN; // TO DO - memcpy(mapping_p->ue_mac_addr, eh_p->ether_shost, ETH_ALEN); - mapping_p->is_outgoing_ipv4_packet_seen = 1; - mapping_p->in_add_captured.s_addr = src4_addr; - - addr_mapping_p = calloc(1, sizeof(sgi_addr_mapping_t)); - memcpy(addr_mapping_p->ue_mac_addr, eh_p->ether_shost, ETH_ALEN); - addr_mapping_p->is_outgoing_packet_seen = 1; - addr_mapping_p->enb_S1U_teid = mapping_p->enb_S1U_teid; - addr_mapping_p->sgw_S1U_teid = originating_sgw_S1u_teidP; - hashtable_insert(sgi_data_pP->addr_v4_mapping, src4_addr, (void*)addr_mapping_p); - SGI_IF_DEBUG("%s ASSOCIATED %d.%d.%d.%d to MAC %02x:%02x:%02x:%02x:%02x:%02x teid %d\n", - __FUNCTION__, NIPADDR(src4_addr), NMACADDR(eh_p->ether_shost), originating_sgw_S1u_teidP); - } else { - SGI_IF_ERROR("Error IPv4 address already registered for teid %d\n", originating_sgw_S1u_teidP); - return -1; - } - } - - } else { - hash_rc = hashtable_get(sgi_data_pP->teid_mapping, originating_sgw_S1u_teidP, (void**)&mapping_p); - } - - break; - - //******************* - case ETHERTYPE_ARP: - //******************* - arph_p = (struct arphdr *) (buffer_pP + sizeof(struct ether_header)); - // The entry should be here but all signalling tied with RRC procedures not finished so - // a data packet can arrive before the MODIFY_BEARER REQUEST - memcpy(&src4_addr, &((unsigned char*)(&arph_p[1]))[ETH_ALEN], 4); - SGI_IF_ERROR("%s ARP OPCODE %s TARGET IP %d.%d.%d.%d\n", __FUNCTION__, sgi_arpopcode_2_str(ntohl(arph_p->ar_op)), NIPADDR(src4_addr)); - - if (hashtable_get(sgi_data_pP->addr_v4_mapping, src4_addr, (void**)&addr_mapping_p) != HASH_TABLE_OK) { - hash_rc = hashtable_get(sgi_data_pP->teid_mapping, originating_sgw_S1u_teidP, (void**)&mapping_p); - - if (hash_rc == HASH_TABLE_KEY_NOT_EXISTS) { - SGI_IF_ERROR("%s Error unknown context SGW teid %d\n", __FUNCTION__, originating_sgw_S1u_teidP); - return -1; - } else { - if (mapping_p->is_outgoing_ipv4_packet_seen == 0) { - mapping_p->hw_addrlen = ETH_ALEN; // TO DO - memcpy(mapping_p->ue_mac_addr, eh_p->ether_shost, ETH_ALEN); - mapping_p->is_outgoing_ipv4_packet_seen = 1; - mapping_p->in_add_captured.s_addr = src4_addr; - - addr_mapping_p = calloc(1, sizeof(sgi_addr_mapping_t)); - memcpy(addr_mapping_p->ue_mac_addr, eh_p->ether_shost, ETH_ALEN); - addr_mapping_p->is_outgoing_packet_seen = 1; - addr_mapping_p->enb_S1U_teid = mapping_p->enb_S1U_teid; - addr_mapping_p->sgw_S1U_teid = originating_sgw_S1u_teidP; - hashtable_insert(sgi_data_pP->addr_v4_mapping, src4_addr, (void*)addr_mapping_p); - SGI_IF_DEBUG("%s ASSOCIATED %d.%d.%d.%d to MAC %02x:%02x:%02x:%02x:%02x:%02x teid %d\n", - __FUNCTION__, NIPADDR(src4_addr), NMACADDR(eh_p->ether_shost), originating_sgw_S1u_teidP); - } else { - SGI_IF_ERROR("Error IPv4 address already registered for teid %d\n", originating_sgw_S1u_teidP); - return -1; - } - } - - } else { - hash_rc = hashtable_get(sgi_data_pP->teid_mapping, originating_sgw_S1u_teidP, (void**)&mapping_p); - } - - break; - - - //******************* - case ETHERTYPE_IPV6: - ip6h_p = (struct ipv6hdr *) (buffer_pP + sizeof(struct ether_header)); - - if (obj_hashtable_get(sgi_data_pP->addr_v6_mapping, &src6_addr, sizeof(struct in6_addr), (void**)&addr_mapping_p) != HASH_TABLE_OK) { - hash_rc = hashtable_get(sgi_data_pP->teid_mapping, originating_sgw_S1u_teidP, (void**)&mapping_p); - - if (hash_rc == HASH_TABLE_KEY_NOT_EXISTS) { - SGI_IF_ERROR("%s Error unknown context SGW teid %d\n", __FUNCTION__, originating_sgw_S1u_teidP); - return -1; - } else { - - if (mapping_p->is_outgoing_ipv6_packet_seen < MAX_DEFINED_IPV6_ADDRESSES_PER_UE) { - mapping_p->hw_addrlen = ETH_ALEN; - memcpy(mapping_p->ue_mac_addr, eh_p->ether_shost, ETH_ALEN); - - memcpy(&mapping_p->in6_addr_captured[mapping_p->is_outgoing_ipv6_packet_seen].s6_addr, src6_addr.s6_addr, 16); - mapping_p->is_outgoing_ipv6_packet_seen +=1; - - addr_mapping_p = calloc(1, sizeof(sgi_addr_mapping_t)); - memcpy(addr_mapping_p->ue_mac_addr, eh_p->ether_shost, ETH_ALEN); - addr_mapping_p->is_outgoing_packet_seen = 1; - addr_mapping_p->enb_S1U_teid = mapping_p->enb_S1U_teid; - addr_mapping_p->sgw_S1U_teid = originating_sgw_S1u_teidP; - - src6_addr_p = malloc(sizeof(struct in6_addr)); - - if (src6_addr_p == NULL) { - return -1; - } - - memcpy(src6_addr_p->s6_addr, ip6h_p->saddr.s6_addr, 16); - obj_hashtable_insert(sgi_data_pP->addr_v6_mapping, src6_addr_p,sizeof(struct in6_addr), (void*)addr_mapping_p); - } else { - SGI_IF_ERROR("Error TOO MANY IPv6 address already registered for teid %d\n", originating_sgw_S1u_teidP); - return -1; - } - } - - } else { - hash_rc = hashtable_get(sgi_data_pP->teid_mapping, originating_sgw_S1u_teidP, (void**)&mapping_p); - } - - break; - - default: - SGI_IF_WARNING("%s UNHANDLED ETHERTYPE: %X\n", __FUNCTION__, htons(eh_p->ether_type)); - break; - } - - assert(mapping_p != NULL); - - if (send(sgi_data_pP->sd[mapping_p->eps_bearer_id - SGI_MIN_EPS_BEARER_ID], (void *)buffer_pP, length, 0) < 0) { - SGI_IF_ERROR("Error during send to socket %d bearer id %d : (%s:%d)\n", - sgi_data_pP->sd[mapping_p->eps_bearer_id - SGI_MIN_EPS_BEARER_ID], - mapping_p->eps_bearer_id, - strerror(errno), - errno); - return -1; - } - - return 0; -} -#else -int sgi_send_data(uint8_t *buffer_pP, uint32_t length, sgi_data_t *sgi_data_pP, Teid_t originating_sgw_S1u_teidP) -{ - struct iphdr *iph_p = (struct iphdr *) buffer_pP; - struct ipv6hdr *ip6h_p = (struct ipv6hdr *) buffer_pP; - sgi_teid_mapping_t *mapping_p = NULL; - sgi_addr_mapping_t *addr_mapping_p = NULL; - hashtable_rc_t hash_rc; - struct in6_addr src6_addr; /* source address */ - struct in6_addr *src6_addr_p; /* source address */ - u_int32_t src4_addr; - struct iovec iov[2]; - - if (buffer_pP == NULL) { - SGI_IF_ERROR("sgi_send_data: received bad parameter\n"); - return -1; - } - - // get IP version of this packet - switch (iph_p->version) { - - //******************* - case 4: - //******************* - // The entry should be here but all signalling tied with RRC procedures not finished so - // a data packet can arrive before the MODIFY_BEARER REQUEST - sgi_data_pP->eh.ether_type = htons(ETHERTYPE_IP); - src4_addr = iph_p->saddr; - - if (hashtable_get(sgi_data_pP->addr_v4_mapping, src4_addr, (void**)&addr_mapping_p) != HASH_TABLE_OK) { - hash_rc = hashtable_get(sgi_data_pP->teid_mapping, originating_sgw_S1u_teidP, (void**)&mapping_p); - - if (hash_rc == HASH_TABLE_KEY_NOT_EXISTS) { - SGI_IF_ERROR("%s Error unknown context SGW teid %d\n", __FUNCTION__, originating_sgw_S1u_teidP); - return -1; - } else { - if (mapping_p->is_outgoing_ipv4_packet_seen == 0) { - mapping_p->hw_addrlen = ETH_ALEN; // TO DO - mapping_p->is_outgoing_ipv4_packet_seen = 1; - mapping_p->in_add_captured.s_addr = src4_addr; - - addr_mapping_p = calloc(1, sizeof(sgi_addr_mapping_t)); - addr_mapping_p->is_outgoing_packet_seen = 1; - addr_mapping_p->enb_S1U_teid = mapping_p->enb_S1U_teid; - addr_mapping_p->sgw_S1U_teid = originating_sgw_S1u_teidP; - hashtable_insert(sgi_data_pP->addr_v4_mapping, src4_addr, (void*)addr_mapping_p); - SGI_IF_DEBUG("%s ASSOCIATED %d.%d.%d.%d to teid %d\n", - __FUNCTION__, NIPADDR(src4_addr), originating_sgw_S1u_teidP); - } else { - SGI_IF_ERROR("Error IPv4 address already registered for teid %d\n", originating_sgw_S1u_teidP); - return -1; - } - } - - } else { - hash_rc = hashtable_get(sgi_data_pP->teid_mapping, originating_sgw_S1u_teidP, (void**)&mapping_p); - } - - break; - - - - //******************* - case 6: - sgi_data_pP->eh.ether_type = htons(ETHERTYPE_IPV6); - - if (obj_hashtable_get(sgi_data_pP->addr_v6_mapping, &src6_addr, sizeof(struct in6_addr), (void**)&addr_mapping_p) != HASH_TABLE_OK) { - hash_rc = hashtable_get(sgi_data_pP->teid_mapping, originating_sgw_S1u_teidP, (void**)&mapping_p); - - if (hash_rc == HASH_TABLE_KEY_NOT_EXISTS) { - SGI_IF_ERROR("%s Error unknown context SGW teid %d\n", __FUNCTION__, originating_sgw_S1u_teidP); - return -1; - } else { - - if (mapping_p->is_outgoing_ipv6_packet_seen < MAX_DEFINED_IPV6_ADDRESSES_PER_UE) { - mapping_p->hw_addrlen = 0; - - memcpy(&mapping_p->in6_addr_captured[mapping_p->is_outgoing_ipv6_packet_seen].s6_addr, src6_addr.s6_addr, 16); - mapping_p->is_outgoing_ipv6_packet_seen +=1; - - addr_mapping_p = calloc(1, sizeof(sgi_addr_mapping_t)); - addr_mapping_p->is_outgoing_packet_seen = 1; - addr_mapping_p->enb_S1U_teid = mapping_p->enb_S1U_teid; - addr_mapping_p->sgw_S1U_teid = originating_sgw_S1u_teidP; - - src6_addr_p = malloc(sizeof(struct in6_addr)); - - if (src6_addr_p == NULL) { - return -1; - } - - memcpy(src6_addr_p->s6_addr, ip6h_p->saddr.s6_addr, 16); - obj_hashtable_insert(sgi_data_pP->addr_v6_mapping, src6_addr_p,sizeof(struct in6_addr), (void*)addr_mapping_p); - } else { - SGI_IF_ERROR("Error TOO MANY IPv6 address already registered for teid %d\n", originating_sgw_S1u_teidP); - return -1; - } - } - - } else { - hash_rc = hashtable_get(sgi_data_pP->teid_mapping, originating_sgw_S1u_teidP, (void**)&mapping_p); - } - - break; - - default: - SGI_IF_WARNING("%s UNHANDLED IP VERSION: %X\n", __FUNCTION__, iph_p->version); - break; - } - - assert(mapping_p != NULL); - iov[0].iov_base = &sgi_data_pP->eh; - iov[0].iov_len = sizeof(sgi_data_pP->eh); - iov[1].iov_base = (void *)buffer_pP; - iov[1].iov_len = length; -#ifdef VLAN8021Q - sgi_data_pP->eh.ether_vlan8021q.vlan_tci = htons(0x7000 | 0x0000 | mapping_p->eps_bearer_id); -#endif - - //sgi_print_hex_octets(iov[0].iov_base, iov[0].iov_len); - //sgi_print_hex_octets(iov[1].iov_base, iov[1].iov_len); - if (writev(sgi_data_pP->sd[mapping_p->eps_bearer_id - SGI_MIN_EPS_BEARER_ID], (const struct iovec *)iov, 2) < 0) { - SGI_IF_ERROR("Error during writev to socket %d bearer id %d : (%s:%d)\n", - sgi_data_pP->sd[mapping_p->eps_bearer_id - SGI_MIN_EPS_BEARER_ID], - mapping_p->eps_bearer_id, - strerror(errno), - errno); - return -1; - } - - /* if (send(sgi_data_pP->sd[mapping_p->eps_bearer_id - SGI_MIN_EPS_BEARER_ID], (void *)buffer_pP, length, 0) < 0) { - SGI_IF_ERROR("Error during send to socket %d bearer id %d : (%s:%d)\n", - sgi_data_pP->sd[mapping_p->eps_bearer_id - SGI_MIN_EPS_BEARER_ID], - mapping_p->eps_bearer_id, - strerror(errno), - errno); - return -1; - } - */ - return 0; -} - -#endif -int sgi_dgram_send_data(uint8_t *buffer_pP, uint32_t length, sgi_data_t *sgi_data_pP, Teid_t originating_sgw_S1u_teidP) -{ - struct iphdr *iph_p = (struct iphdr *) buffer_pP; - struct ipv6hdr *ip6h_p = (struct ipv6hdr *) buffer_pP; - sgi_teid_mapping_t *mapping_p = NULL; - sgi_addr_mapping_t *addr_mapping_p = NULL; - hashtable_rc_t hash_rc; - struct in6_addr src6_addr; /* source address */ - struct in6_addr *src6_addr_p; /* source address */ - u_int32_t src4_addr; - - struct sockaddr_ll device; - - if (buffer_pP == NULL) { - SGI_IF_ERROR("sgi_send_data: received bad parameter\n"); - return -1; - } - - // get IP version of this packet - switch (iph_p->version) { - - //******************* - case 4: - //******************* - // The entry should be here but all signalling tied with RRC procedures not finished so - // a data packet can arrive before the MODIFY_BEARER REQUEST - sgi_data_pP->eh.ether_type = htons(ETHERTYPE_IP); - src4_addr = iph_p->saddr; - - if (hashtable_get(sgi_data_pP->addr_v4_mapping, src4_addr, (void**)&addr_mapping_p) != HASH_TABLE_OK) { - hash_rc = hashtable_get(sgi_data_pP->teid_mapping, originating_sgw_S1u_teidP, (void**)&mapping_p); - - if (hash_rc == HASH_TABLE_KEY_NOT_EXISTS) { - SGI_IF_ERROR("%s Error unknown context SGW teid %d\n", __FUNCTION__, originating_sgw_S1u_teidP); - return -1; - } else { - if (mapping_p->is_outgoing_ipv4_packet_seen == 0) { - mapping_p->hw_addrlen = 0; // TO DO - mapping_p->is_outgoing_ipv4_packet_seen = 1; - mapping_p->in_add_captured.s_addr = src4_addr; - - addr_mapping_p = calloc(1, sizeof(sgi_addr_mapping_t)); - addr_mapping_p->is_outgoing_packet_seen = 1; - addr_mapping_p->enb_S1U_teid = mapping_p->enb_S1U_teid; - addr_mapping_p->sgw_S1U_teid = originating_sgw_S1u_teidP; - hashtable_insert(sgi_data_pP->addr_v4_mapping, src4_addr, (void*)addr_mapping_p); - SGI_IF_DEBUG("%s ASSOCIATED %d.%d.%d.%d to teid %d\n", - __FUNCTION__, NIPADDR(src4_addr), originating_sgw_S1u_teidP); - } else { - SGI_IF_ERROR("Error IPv4 address already registered for teid %d\n", originating_sgw_S1u_teidP); - return -1; - } - } - } else { - hash_rc = hashtable_get(sgi_data_pP->teid_mapping, originating_sgw_S1u_teidP, (void**)&mapping_p); - } - - break; - - - - //******************* - case 6: - sgi_data_pP->eh.ether_type = htons(ETHERTYPE_IPV6); - - if (obj_hashtable_get(sgi_data_pP->addr_v6_mapping, &src6_addr, sizeof(struct in6_addr), (void**)&addr_mapping_p) != HASH_TABLE_OK) { - hash_rc = hashtable_get(sgi_data_pP->teid_mapping, originating_sgw_S1u_teidP, (void**)&mapping_p); - - if (hash_rc == HASH_TABLE_KEY_NOT_EXISTS) { - SGI_IF_ERROR("%s Error unknown context SGW teid %d\n", __FUNCTION__, originating_sgw_S1u_teidP); - return -1; - } else { - - if (mapping_p->is_outgoing_ipv6_packet_seen < MAX_DEFINED_IPV6_ADDRESSES_PER_UE) { - mapping_p->hw_addrlen = 0; - - memcpy(&mapping_p->in6_addr_captured[mapping_p->is_outgoing_ipv6_packet_seen].s6_addr, src6_addr.s6_addr, 16); - mapping_p->is_outgoing_ipv6_packet_seen +=1; - - addr_mapping_p = calloc(1, sizeof(sgi_addr_mapping_t)); - addr_mapping_p->is_outgoing_packet_seen = 1; - addr_mapping_p->enb_S1U_teid = mapping_p->enb_S1U_teid; - addr_mapping_p->sgw_S1U_teid = originating_sgw_S1u_teidP; - - src6_addr_p = malloc(sizeof(struct in6_addr)); - - if (src6_addr_p == NULL) { - return -1; - } - - memcpy(src6_addr_p->s6_addr, ip6h_p->saddr.s6_addr, 16); - obj_hashtable_insert(sgi_data_pP->addr_v6_mapping, src6_addr_p,sizeof(struct in6_addr), (void*)addr_mapping_p); - } else { - SGI_IF_ERROR("Error TOO MANY IPv6 address already registered for teid %d\n", originating_sgw_S1u_teidP); - return -1; - } - } - - } else { - hash_rc = hashtable_get(sgi_data_pP->teid_mapping, originating_sgw_S1u_teidP, (void**)&mapping_p); - } - - break; - - default: - SGI_IF_WARNING("%s UNHANDLED IP VERSION: %X\n", __FUNCTION__, iph_p->version); - break; - } - - memset(&device, 0, sizeof(device)); - device.sll_family = AF_PACKET; - device.sll_protocol = htons(ETH_P_ALL); - device.sll_ifindex = sgi_data_pP->if_index[mapping_p->eps_bearer_id - SGI_MIN_EPS_BEARER_ID]; - - - if (sendto(sgi_data_pP->sd[mapping_p->eps_bearer_id - SGI_MIN_EPS_BEARER_ID], - buffer_pP, - length, - 0, - (struct sockaddr *) &device, - sizeof (device)) < 0) { - SGI_IF_ERROR("%d Error during send to socket %d bearer id %d : (%s:%d)\n", - __LINE__, - sgi_data_pP->sd[mapping_p->eps_bearer_id - SGI_MIN_EPS_BEARER_ID], - mapping_p->eps_bearer_id, - strerror(errno), - errno); - return -1; - } - - - return 0; -} - -#ifdef SGI_TEST -#include <stdio.h> -#include <sys/types.h> -#include <sys/socket.h> -#include <netdb.h> -#include <netinet/in.h> -#include <netinet/in_systm.h> -#include <netinet/ether.h> -#include <netinet/ip.h> -#include <netinet/ip_icmp.h> -#include <string.h> -#include <arpa/inet.h> -#include <sys/socket.h> - -#define SGI_TEST_BUFF_LEN 500 -unsigned char sgi_test_tx_buffer[SGI_TEST_BUFF_LEN]; - - -void sgi_test_send_ping(sgi_data_t *sgi_dataP, uint32_t markP, uint64_t src_mac_addrP, uint64_t dst_mac_addrP, char* src_ip_addrP, char* dst_ip_addrP) -{ -#ifdef SGI_PF_PACKET - struct ether_header *eh = (struct ether_header *) sgi_test_tx_buffer; - struct iphdr *iph = (struct iphdr *) (sgi_test_tx_buffer + sizeof(struct ether_header)); - struct icmphdr *icmp = (struct icmphdr *) (sgi_test_tx_buffer + sizeof(struct ether_header) + sizeof(struct iphdr)); -#else - struct iphdr *iph = (struct iphdr *) sgi_test_tx_buffer; - struct icmphdr *icmp = (struct icmphdr *) (sgi_test_tx_buffer + sizeof(struct iphdr)); -#endif - struct hostent *hp, *hp2; - struct in_addr ip_dst; - struct in_addr ip_src; - - - -#ifdef SGI_PF_PACKET - eh->ether_shost[0] = (u_int8_t)((src_mac_addrP & 0x0000FF0000000000) >> 40); - eh->ether_shost[1] = (u_int8_t)((src_mac_addrP & 0x000000FF00000000) >> 32); - eh->ether_shost[2] = (u_int8_t)((src_mac_addrP & 0x00000000FF000000) >> 24); - eh->ether_shost[3] = (u_int8_t)((src_mac_addrP & 0x0000000000FF0000) >> 16); - eh->ether_shost[4] = (u_int8_t)((src_mac_addrP & 0x000000000000FF00) >> 8); - eh->ether_shost[5] = (u_int8_t) (src_mac_addrP & 0x00000000000000FF); - - eh->ether_dhost[0] = (u_int8_t)((dst_mac_addrP & 0x0000FF0000000000) >> 40); - eh->ether_dhost[1] = (u_int8_t)((dst_mac_addrP & 0x000000FF00000000) >> 32); - eh->ether_dhost[2] = (u_int8_t)((dst_mac_addrP & 0x00000000FF000000) >> 24); - eh->ether_dhost[3] = (u_int8_t)((dst_mac_addrP & 0x0000000000FF0000) >> 16); - eh->ether_dhost[4] = (u_int8_t)((dst_mac_addrP & 0x000000000000FF00) >> 8); - eh->ether_dhost[5] = (u_int8_t) (dst_mac_addrP & 0x00000000000000FF); - eh->ether_type = htons(ETH_P_IP); -#endif - - if ((hp = gethostbyname(dst_ip_addrP)) == NULL) { - SGI_IF_DEBUG("gethostbyname() is OK.\n"); - - if ((ip_dst.s_addr = inet_addr(dst_ip_addrP)) == -1) { - fprintf(stderr, "%s: Can't resolve, unknown host.\n", dst_ip_addrP); - exit(1); - } - } else - bcopy(hp->h_addr_list[0], &ip_dst.s_addr, hp->h_length); - - /* The following source address just redundant for target to collect */ - if ((hp2 = gethostbyname(src_ip_addrP)) == NULL) { - SGI_IF_DEBUG("gethostbyname() is OK.\n"); - - if ((ip_src.s_addr = inet_addr(src_ip_addrP)) == -1) { - fprintf(stderr, "%s: Can't resolve, unknown host\n", src_ip_addrP); - exit(1); - } - } else - bcopy(hp2->h_addr_list[0], &ip_src.s_addr, hp->h_length); - - printf("Sending to %08X from spoofed %08X\n", ip_dst.s_addr, ip_src.s_addr); - /* Ip structure, check the ip.h */ - iph->version = 4; - iph->ihl = sizeof *iph >> 2; - iph->tos = 0; - iph->tot_len = htons(SGI_TEST_BUFF_LEN-sizeof(struct ether_header)); - iph->id = htons(4321); - iph->frag_off = htons(0); - iph->ttl = 255; - iph->protocol = IPPROTO_ICMP; - iph->check = htons(0); - iph->saddr = ip_src.s_addr; - iph->daddr = ip_dst.s_addr; - - icmp->type = ICMP_ECHO; - icmp->code = 0; - icmp->un.echo.id = 1000; - icmp->un.echo.sequence = 10; - /* Header checksum */ - icmp->checksum = 0; - - icmp-> checksum = in_cksum((unsigned short *)icmp, sizeof(struct icmphdr)); - iph->check = in_cksum((unsigned short *)iph, sizeof(struct iphdr)); - - /* sending time */ - if (send(sgi_dataP->sd[0], sgi_test_tx_buffer, SGI_TEST_BUFF_LEN, 0) < 0) { - SGI_IF_ERROR("sendto() error (%s:%d)\n", strerror(errno), errno); - } else - SGI_IF_DEBUG("sendto() is OK.\n"); -} - -#endif - -#ifdef ENABLE_USE_RAW_SOCKET_FOR_SGI - -void sgi_sock_raw_cleanup_handler(void *args_p) -{ - sgi_data_t *sgi_data_p; - int socket_index; - - sgi_data_p = ((sgi_read_thread_args_t*)args_p)->sgi_data; - socket_index = ((sgi_read_thread_args_t*)args_p)->socket_index; - - SGI_IF_DEBUG("Called %s\n", __FUNCTION__); -#ifdef SGI_PACKET_RX_RING - free(sgi_data_p->malloc_ring); - sgi_data_p->malloc_ring = NULL; - - if (munmap(sgi_data_p->sock_mmap_ring, CONF_RING_FRAMES * getpagesize())) { - SGI_IF_ERROR("munmap\n"); - } else { - sgi_data_p->sock_mmap_ring = NULL; - } - -#endif - - if (sgi_data_p->sd[socket_index] > 0) { - close(sgi_data_p->sd[socket_index]); - SGI_IF_DEBUG("Closed soket %d\n", sgi_data_p->sd[socket_index]); - } - - sgi_data_p->sd[socket_index] = -1; - - free(args_p); -} - -void* sgi_sock_raw_fw_2_gtpv1u_thread(void* args_p) -{ - sgi_data_t *sgi_data_p; - int socket_index; -#ifdef SGI_PACKET_RX_RING - struct pollfd pfd; - int i; - pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; - char *names[]= { - "<", /* incoming */ - "B", /* broadcast */ - "M", /* multicast */ - "P", /* promisc */ - ">", /* outgoing */ - }; -#else - int num_bytes; -#endif - sgi_data_p = ((sgi_read_thread_args_t*)args_p)->sgi_data; - socket_index = ((sgi_read_thread_args_t*)args_p)->socket_index; - - SGI_IF_DEBUG("RX thread on raw socket started, operating on Device %s.%d\n", sgi_data_p->interface_name, socket_index+SGI_MIN_EPS_BEARER_ID); - - - pthread_cleanup_push(sgi_sock_raw_cleanup_handler, args_p); - - pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL); - - pthread_mutex_lock (&sgi_data_p->thread_started_mutex); - sgi_data_p->thread_started += 1; - pthread_mutex_unlock (&sgi_data_p->thread_started_mutex); - -#ifdef SGI_PACKET_RX_RING - i = 0; - - while (1) { - while(*(unsigned long*)sgi_data_p->malloc_ring[i].iov_base) { - struct tpacket_hdr *h=sgi_data_p->malloc_ring[i].iov_base; - struct sockaddr_ll *sll=(void *)h + TPACKET_ALIGN(sizeof(*h)); - unsigned char *bp=(unsigned char *)h + h->tp_mac; - - SGI_IF_DEBUG("%u.%.6u: if%u %s %u bytes\n", - h->tp_sec, h->tp_usec, - sll->sll_ifindex, - names[sll->sll_pkttype], - h->tp_len); - - sgi_process_raw_packet(sgi_data_p, bp, h->tp_len); - pthread_mutex_lock(&mutex); /* memory barrier */ - /* tell the kernel this packet is done with */ - h->tp_status=0; - pthread_mutex_unlock(&mutex); /* memory barrier */ - - i=(i==CONF_RING_FRAMES-1) ? 0 : i+1; - } - - /* Sleep when nothings happen */ - pfd.fd=sgi_data_p->sd; - pfd.events=POLLIN|POLLERR; - pfd.revents=0; - poll(&pfd, 1, -1); - } - -#else - - while (1) { - num_bytes = recvfrom(sgi_data_p->sd[socket_index], &sgi_data_p->recv_buffer[0][socket_index], SGI_BUFFER_RECV_LEN, 0, NULL, NULL); - - if (num_bytes > 0) { - SGI_IF_DEBUG("recvfrom bearer id %d %d bytes\n", socket_index + SGI_MIN_EPS_BEARER_ID, num_bytes); -#ifdef SGI_SOCKET_RAW - sgi_process_raw_packet(sgi_data_p, &sgi_data_p->recv_buffer[0][socket_index], num_bytes); -#else -#ifdef SGI_SOCKET_DGRAM - sgi_process_dgram_packet(sgi_data_p, &sgi_data_p->recv_buffer[0][socket_index], num_bytes); -#endif -#endif - } else { - SGI_IF_DEBUG("recvfrom bearer id %d %d (%s:%d)\n", socket_index + SGI_MIN_EPS_BEARER_ID, num_bytes, strerror(errno), errno); - } - } - -#endif - pthread_cleanup_pop(0); - pthread_exit(NULL); -} -#endif - diff --git a/openair-cn/SGI/sgi_task.c b/openair-cn/SGI/sgi_task.c deleted file mode 100644 index aa7e99eef5f..00000000000 --- a/openair-cn/SGI/sgi_task.c +++ /dev/null @@ -1,361 +0,0 @@ -/******************************************************************************* - OpenAirInterface - Copyright(c) 1999 - 2014 Eurecom - - OpenAirInterface is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - - OpenAirInterface is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with OpenAirInterface.The full GNU General Public License is - included in this distribution in the file called "COPYING". If not, - see <http://www.gnu.org/licenses/>. - - Contact Information - OpenAirInterface Admin: openair_admin@eurecom.fr - OpenAirInterface Tech : openair_tech@eurecom.fr - OpenAirInterface Dev : openair4g-devel@eurecom.fr - - Address : Eurecom, Compus SophiaTech 450, route des chappes, 06451 Biot, France. - - *******************************************************************************/ -/*! \file sgi_task.c -* \brief -* \author Lionel Gauthier -* \company Eurecom -* \email: lionel.gauthier@eurecom.fr -*/ - -#include <pthread.h> -#include <stdio.h> -#include <string.h> -#include <unistd.h> -#include <errno.h> -#include <assert.h> -#include <stdlib.h> -#include <unistd.h> - -#include <time.h> -#include <net/if.h> - -//----------------------------------------------------------------------------- -#include "assertions.h" -#include "mme_config.h" -#include "intertask_interface.h" -#include "sgi.h" - -//----------------------------------------------------------------------------- -static void* sgi_task_thread(void *args_p); -static int sgi_create_endpoint_request(sgi_data_t *sgi_dataP, SGICreateEndpointReq *req_p); -static int sgi_update_endpoint_request(sgi_data_t *sgi_dataP, SGIUpdateEndpointReq *req_p); -static int sgi_init_phase2(sgi_data_t *sgi_data_pP); -//----------------------------------------------------------------------------- -static pthread_t fw_2_sgi_task_thread; -//----------------------------------------------------------------------------- -static void* sgi_task_thread(void *args_p) -//----------------------------------------------------------------------------- -{ - sgi_data_t *sgi_data_p; - - if (args_p == NULL) { - return NULL; - } - - itti_mark_task_ready(TASK_FW_IP); - - sgi_data_p = (sgi_data_t *)args_p; - - - while(1) { - /* Trying to fetch a message from the message queue. - * If the queue is empty, this function will block till a - * message is sent to the task. - */ - MessageDef *received_message_p; - itti_receive_msg(TASK_FW_IP, &received_message_p); - - DevAssert(received_message_p != NULL); - - if (sgi_data_p->hss_associated) { - switch (ITTI_MSG_ID(received_message_p)) { - case GTPV1U_TUNNEL_DATA_IND: { - /* We received data from GTPV1_U incoming from an UE. - * Forward it host adapter. - */ - Gtpv1uTunnelDataInd *data_ind_p; - data_ind_p = &received_message_p->ittiMsg.gtpv1uTunnelDataInd; -#ifdef SGI_SOCKET_RAW - sgi_send_data(&data_ind_p->buffer[data_ind_p->offset], data_ind_p->length, sgi_data_p, data_ind_p->local_S1u_teid); -#else -#ifdef SGI_SOCKET_DGRAM - sgi_dgram_send_data(&data_ind_p->buffer[data_ind_p->offset], data_ind_p->length, sgi_data_p, data_ind_p->local_S1u_teid); -#endif -#endif - /* Buffer is no longer needed, free it */ - itti_free(ITTI_MSG_ORIGIN_ID(received_message_p), data_ind_p->buffer); - } - break; - - case SGI_CREATE_ENDPOINT_REQUEST: { - SGICreateEndpointReq *req_p; - req_p = &received_message_p->ittiMsg.sgiCreateEndpointReq; - sgi_create_endpoint_request(sgi_data_p, req_p); - } - break; - - case SGI_UPDATE_ENDPOINT_REQUEST: { - SGIUpdateEndpointReq *req_p; - req_p = &received_message_p->ittiMsg.sgiUpdateEndpointReq; - sgi_update_endpoint_request(sgi_data_p, req_p); - } - break; - - default: { - SGI_IF_ERROR("Unkwnon message ID %d:%s\n", - ITTI_MSG_ID(received_message_p), ITTI_MSG_NAME(received_message_p)); - } - break; - } - } else { - switch (ITTI_MSG_ID(received_message_p)) { - case ACTIVATE_MESSAGE: { - sgi_data_p->hss_associated = 1; -#if !defined(ENABLE_USE_GTPU_IN_KERNEL) - SGI_IF_DEBUG("HSS ASSOCIATED, CAN START VLANS (bug in freediameter)"); - sgi_init_phase2(sgi_data_p); -#endif - } - break; - - default: { - SGI_IF_ERROR("Unkwnon or ignored message ID %d:%s\n", - ITTI_MSG_ID(received_message_p), ITTI_MSG_NAME(received_message_p)); - } - break; - } - } - - itti_free(ITTI_MSG_ORIGIN_ID(received_message_p), received_message_p); - received_message_p = NULL; - } - - return NULL; -} - - -//------------------------------------------------------ -static int sgi_create_endpoint_request(sgi_data_t *sgi_dataP, SGICreateEndpointReq *req_p) -//------------------------------------------------------ -{ - SGICreateEndpointResp *sgi_create_endpoint_resp_p; - MessageDef *message_p; - sgi_teid_mapping_t *mapping; - - SGI_IF_DEBUG("Rx IP_FW_CREATE_SGI_ENDPOINT_REQUEST, Context: S-GW S11 teid %u, S-GW S1U teid %u EPS bearer id %u\n", - req_p->context_teid, req_p->sgw_S1u_teid, req_p->eps_bearer_id); - - message_p = itti_alloc_new_message(TASK_FW_IP, SGI_CREATE_ENDPOINT_RESPONSE); - - if (message_p == NULL) { - return -1; - } - - sgi_create_endpoint_resp_p = &message_p->ittiMsg.sgiCreateEndpointResp; - sgi_create_endpoint_resp_p->context_teid = req_p->context_teid; - sgi_create_endpoint_resp_p->sgw_S1u_teid = req_p->sgw_S1u_teid; - sgi_create_endpoint_resp_p->eps_bearer_id = req_p->eps_bearer_id; - sgi_create_endpoint_resp_p->pdn_type = req_p->pdn_type; - sgi_create_endpoint_resp_p->paa = req_p->paa; - sgi_create_endpoint_resp_p->status = SGI_STATUS_OK; - - if (hashtable_is_key_exists(sgi_dataP->teid_mapping, req_p->sgw_S1u_teid) == HASH_TABLE_OK) { - SGI_IF_ERROR("SGI_STATUS_ERROR_CONTEXT_ALREADY_EXIST Context: S11 teid %u\n", req_p->context_teid); - sgi_create_endpoint_resp_p->status = SGI_STATUS_ERROR_CONTEXT_ALREADY_EXIST; - } else { - mapping = malloc(sizeof(sgi_teid_mapping_t)); - - if (mapping == NULL) { - sgi_create_endpoint_resp_p->status = SGI_STATUS_ERROR_NO_MEMORY_AVAILABLE; - } else { - memset(mapping, 0 , sizeof(sgi_teid_mapping_t)); - - mapping->eps_bearer_id = req_p->eps_bearer_id; - mapping->enb_S1U_teid = -1; - - if (hashtable_insert(sgi_dataP->teid_mapping, req_p->sgw_S1u_teid, mapping) != 0) { - SGI_IF_ERROR("SGI_STATUS_ERROR_SYSTEM_FAILURE Context: S11 teid %u\n", req_p->context_teid); - sgi_create_endpoint_resp_p->status = SGI_STATUS_ERROR_SYSTEM_FAILURE; - free(mapping); - } else { - SGI_IF_ERROR("SGI_STATUS_OK Context: S11 teid %u\n", req_p->context_teid); - sgi_create_endpoint_resp_p->status = SGI_STATUS_OK; - } - } - } - - return itti_send_msg_to_task(TASK_SPGW_APP, INSTANCE_DEFAULT, message_p); -} - -//------------------------------------------------------ -static int sgi_update_endpoint_request(sgi_data_t *sgi_dataP, SGIUpdateEndpointReq *req_p) -//------------------------------------------------------ -{ - SGIUpdateEndpointResp *sgi_update_endpoint_resp_p = NULL; - MessageDef *message_p = NULL; - sgi_teid_mapping_t *mapping = NULL; - - SGI_IF_DEBUG("Rx IP_FW_UPDATE_SGI_ENDPOINT_REQUEST, Context: S-GW S11 teid %u, S-GW S1U teid %u EPS bearer id %u\n", - req_p->context_teid, req_p->sgw_S1u_teid, req_p->eps_bearer_id); - - message_p = itti_alloc_new_message(TASK_FW_IP, SGI_UPDATE_ENDPOINT_RESPONSE); - - if (message_p == NULL) { - return -1; - } - - sgi_update_endpoint_resp_p = &message_p->ittiMsg.sgiUpdateEndpointResp; - sgi_update_endpoint_resp_p->context_teid = req_p->context_teid; - sgi_update_endpoint_resp_p->sgw_S1u_teid = req_p->sgw_S1u_teid; - sgi_update_endpoint_resp_p->eps_bearer_id = req_p->eps_bearer_id; - sgi_update_endpoint_resp_p->enb_S1u_teid = req_p->enb_S1u_teid; - sgi_update_endpoint_resp_p->status = SGI_STATUS_OK; - - if (hashtable_get(sgi_dataP->teid_mapping, req_p->sgw_S1u_teid, (void**)&mapping) == HASH_TABLE_OK) { - mapping->enb_S1U_teid = req_p->enb_S1u_teid; - } else { - SGI_IF_ERROR("SGI_STATUS_ERROR_CONTEXT_NOT_FOUND Context: S11 teid %u\n", req_p->context_teid); - sgi_update_endpoint_resp_p->status = SGI_STATUS_ERROR_CONTEXT_NOT_FOUND; - } - - return itti_send_msg_to_task(TASK_SPGW_APP, INSTANCE_DEFAULT, message_p); -} - -//----------------------------------------------------------------------------- -int sgi_init(const pgw_config_t *pgw_config_p) -//----------------------------------------------------------------------------- -{ - - volatile sgi_data_t *sgi_data_p; - int len; - int i; - - SGI_IF_DEBUG("Initializing FW_IP task interface\n"); - - sgi_data_p = malloc(sizeof(sgi_data_t)); - memset((void *)sgi_data_p, 0, sizeof(sgi_data_t)); - - for (i=0; i < SGI_MAX_EPS_BEARERS_PER_USER; i++) { - sgi_data_p->sd[i] = -1; - } - - sgi_data_p->thread_started = 0; - pthread_mutex_init (&sgi_data_p->thread_started_mutex, NULL); - - sgi_data_p->teid_mapping = hashtable_create (SGI_MAX_EPS_BEARERS, NULL, NULL); - - if (sgi_data_p->teid_mapping == NULL) { - SGI_IF_ERROR("Failed to create SGI hashtable teid_mapping\n"); - return -1; - } - - sgi_data_p->addr_v4_mapping = hashtable_create (SGI_MAX_SERVED_USERS_PER_PGW, NULL, NULL); - - if (sgi_data_p->addr_v4_mapping == NULL) { - SGI_IF_ERROR("Failed to create SGI hashtable addr_v4_mapping\n"); - return -1; - } - - sgi_data_p->addr_v6_mapping = obj_hashtable_create (SGI_MAX_SERVED_USERS_PER_PGW, NULL, NULL, NULL); - - if (sgi_data_p->addr_v6_mapping == NULL) { - SGI_IF_ERROR("Failed to create SGI hashtable addr_v6_mapping\n"); - return -1; - } - - - len = strlen(pgw_config_p->ipv4.pgw_interface_name_for_SGI); - sgi_data_p->interface_name = calloc(len + 1, sizeof(char)); - memcpy(sgi_data_p->interface_name, pgw_config_p->ipv4.pgw_interface_name_for_SGI, len); - sgi_data_p->interface_name[len] = '\0'; - sgi_data_p->ipv4_addr = pgw_config_p->ipv4.pgw_ipv4_address_for_SGI; - - - if (pthread_create(&fw_2_sgi_task_thread, NULL, &sgi_task_thread, (void *)sgi_data_p) < 0) { - SGI_IF_ERROR("sgi_task_thread pthread_create: %s", strerror(errno)); - return -1; - } - - return 0; -} - -int sgi_init_phase2(sgi_data_t *sgi_data_pP) -{ - int i; - - if (strcmp(sgi_data_pP->interface_name, PGW_CONFIG_STRING_INTERFACE_DISABLED) != 0) { - sgi_data_pP->interface_index = if_nametoindex(sgi_data_pP->interface_name); - - if (sgi_create_sockets(sgi_data_pP) < 0) { - SGI_IF_ERROR("Could not create socket, leaving thread %s\n", __FUNCTION__); - free(sgi_data_pP); - return -1; - } - } else { - SGI_IF_WARNING("SGI interface disabled by config file\n"); - } - - - if (strcmp(sgi_data_pP->interface_name, PGW_CONFIG_STRING_INTERFACE_DISABLED) != 0) { -#ifdef ENABLE_USE_PCAP_FOR_SGI - - if (pthread_create(&sgi_data_pP->capture_on_sgi_if_thread, NULL, &sgi_pcap_fw_2_gtpv1u_thread, (void *)sgi_data_pP) < 0) { - SGI_IF_ERROR("sgi_pcap_fw_2_gtpv1u_thread pthread_create: %s", strerror(errno)); - return -1; - } - -#endif -#ifdef ENABLE_USE_NETFILTER_FOR_SGI - - if (pthread_create(&sgi_data_pP->capture_on_sgi_if_thread, NULL, &sgi_nf_fw_2_gtpv1u_thread, (void *)sgi_data_pP) < 0) { - SGI_IF_ERROR("sgi_nf_fw_2_gtpv1u_thread pthread_create: %s", strerror(errno)); - return -1; - } - -#endif - //#if 0 -#ifdef ENABLE_USE_RAW_SOCKET_FOR_SGI - - for (i=0; i < SGI_MAX_EPS_BEARERS_PER_USER; i++) { - sgi_read_thread_args_t *args_p = malloc(sizeof(sgi_read_thread_args_t)); - args_p->sgi_data = sgi_data_pP; - args_p->socket_index = i; - - if (pthread_create(&sgi_data_pP->capture_on_sgi_if_thread, NULL, &sgi_sock_raw_fw_2_gtpv1u_thread, (void *)args_p) < 0) { - SGI_IF_ERROR("sgi_sock_raw_fw_2_gtpv1u_thread pthread_create: %s", strerror(errno)); - return -1; - } - } - -#endif - //#endif - } - - while (sgi_data_pP->thread_started != SGI_MAX_EPS_BEARERS_PER_USER ) { - usleep(1000); - } - - /*SGI_IF_DEBUG("ARP RESOLVING ROUTER...\n"); - while (sgi_data_p->hw_address_of_router_captured == 0) { - sgi_send_arp_request(sgi_data_p, "router.eur"); - sleep(2); - }*/ - SGI_IF_DEBUG("Initializing FW_IP task interface: DONE\n"); - return 0; -} diff --git a/openair-cn/SGI/sgi_util.c b/openair-cn/SGI/sgi_util.c deleted file mode 100755 index 879b451e505..00000000000 --- a/openair-cn/SGI/sgi_util.c +++ /dev/null @@ -1,304 +0,0 @@ -/******************************************************************************* - OpenAirInterface - Copyright(c) 1999 - 2014 Eurecom - - OpenAirInterface is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - - OpenAirInterface is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with OpenAirInterface.The full GNU General Public License is - included in this distribution in the file called "COPYING". If not, - see <http://www.gnu.org/licenses/>. - - Contact Information - OpenAirInterface Admin: openair_admin@eurecom.fr - OpenAirInterface Tech : openair_tech@eurecom.fr - OpenAirInterface Dev : openair4g-devel@eurecom.fr - - Address : Eurecom, Compus SophiaTech 450, route des chappes, 06451 Biot, France. - - *******************************************************************************/ -/*! \file sgi_util.c -* \brief -* \author Lionel Gauthier -* \company Eurecom -* \email: lionel.gauthier@eurecom.fr -*/ -#include <stdio.h> -#include <errno.h> -#include <string.h> -#include <netdb.h> -#include <sys/socket.h> -#include <arpa/inet.h> -#include <net/if_arp.h> -#include <netinet/in.h> -#include <net/if.h> -#include <sys/ioctl.h> -#include <sys/time.h> -#include "sgi.h" - -#define FW_2_PRINT_BUFFER_LEN 10000 -static char fw_2_print_buffer[FW_2_PRINT_BUFFER_LEN]; -//----------------------------------------------------------------------------- -void sgi_print_hex_octets(unsigned char* dataP, unsigned long sizeP) -//----------------------------------------------------------------------------- -{ - unsigned long octet_index = 0; - unsigned long buffer_marker = 0; - unsigned char aindex; - struct timeval tv; - struct timezone tz; - char timeofday[64]; - unsigned int h,m,s; - - if (dataP == NULL) { - return; - } - - gettimeofday(&tv, &tz); - h = (tv.tv_sec/3600) % 24; - m = (tv.tv_sec / 60) % 60; - s = tv.tv_sec % 60; - snprintf(timeofday, 64, "%02d:%02d:%02d.%06d", h,m,s,tv.tv_usec); - - SGI_IF_DEBUG("%s------+-------------------------------------------------+\n",timeofday); - SGI_IF_DEBUG("%s | 0 1 2 3 4 5 6 7 8 9 a b c d e f |\n",timeofday); - SGI_IF_DEBUG("%s------+-------------------------------------------------+\n",timeofday); - - for (octet_index = 0; octet_index < sizeP; octet_index++) { - if ((octet_index % 16) == 0) { - if (octet_index != 0) { - buffer_marker+=snprintf(&fw_2_print_buffer[buffer_marker], FW_2_PRINT_BUFFER_LEN - buffer_marker, " |\n"); - SGI_IF_DEBUG("%s%s",timeofday, fw_2_print_buffer); - buffer_marker = 0; - } - - buffer_marker+=snprintf(&fw_2_print_buffer[buffer_marker], FW_2_PRINT_BUFFER_LEN - buffer_marker, " %04ld |", octet_index); - } - - /* - * Print every single octet in hexadecimal form - */ - buffer_marker+=snprintf(&fw_2_print_buffer[buffer_marker], FW_2_PRINT_BUFFER_LEN - buffer_marker, " %02x", dataP[octet_index]); - /* - * Align newline and pipes according to the octets in groups of 2 - */ - } - - /* - * Append enough spaces and put final pipe - */ - for (aindex = octet_index; aindex < 16; ++aindex) - buffer_marker+=snprintf(&fw_2_print_buffer[buffer_marker], FW_2_PRINT_BUFFER_LEN - buffer_marker, " "); - - //SGI_IF_DEBUG(" "); - buffer_marker+=snprintf(&fw_2_print_buffer[buffer_marker], FW_2_PRINT_BUFFER_LEN - buffer_marker, " |\n"); - SGI_IF_DEBUG("%s%s",timeofday,fw_2_print_buffer); -} - -//----------------------------------------------------------------------------- -char* sgi_status_2_str(SGIStatus_t statusP) -//----------------------------------------------------------------------------- -{ - switch (statusP) { - case SGI_STATUS_OK: - return "SGI_STATUS_OK"; - break; - - case SGI_STATUS_ERROR_CONTEXT_ALREADY_EXIST: - return "SGI_STATUS_ERROR_CONTEXT_ALREADY_EXIST"; - break; - - case SGI_STATUS_ERROR_CONTEXT_NOT_FOUND: - return "SGI_STATUS_ERROR_CONTEXT_NOT_FOUND"; - break; - - case SGI_STATUS_ERROR_INVALID_MESSAGE_FORMAT: - return "SGI_STATUS_ERROR_INVALID_MESSAGE_FORMAT"; - break; - - case SGI_STATUS_ERROR_SERVICE_NOT_SUPPORTED: - return "SGI_STATUS_ERROR_SERVICE_NOT_SUPPORTED"; - break; - - case SGI_STATUS_ERROR_SYSTEM_FAILURE: - return "SGI_STATUS_ERROR_SYSTEM_FAILURE"; - break; - - case SGI_STATUS_ERROR_NO_RESOURCES_AVAILABLE: - return "SGI_STATUS_ERROR_NO_RESOURCES_AVAILABLE"; - break; - - case SGI_STATUS_ERROR_NO_MEMORY_AVAILABLE: - return "SGI_STATUS_ERROR_NO_MEMORY_AVAILABLE"; - break; - - default: - return "UNKNOWN_SGI_STATUS"; - } -} - -//----------------------------------------------------------------------------- -char* sgi_arpopcode_2_str(unsigned short int opcodeP) -//----------------------------------------------------------------------------- -{ - switch (opcodeP) { - case ARPOP_REQUEST: - return "ARPOP_REQUEST"; - break; - - case ARPOP_REPLY: - return "ARPOP_REPLY"; - break; - - case ARPOP_RREQUEST: - return "ARPOP_RREQUEST"; - break; - - case ARPOP_RREPLY: - return "ARPOP_RREPLY"; - break; - - case ARPOP_InREQUEST: - return "ARPOP_InREQUEST"; - break; - - case ARPOP_InREPLY: - return "ARPOP_InREPLY"; - break; - - case ARPOP_NAK: - return "ARPOP_NAK"; - break; - - default: - return "UNKNOWN_ARP_OPCODE"; - } -} -//----------------------------------------------------------------------------- -unsigned short in_cksum(unsigned short *addr, int len) -//----------------------------------------------------------------------------- -{ - register int sum = 0; - u_short answer = 0; - register u_short *w = addr; - register int nleft = len; - - /* - * Our algorithm is simple, using a 32 bit accumulator (sum), we add - * sequential 16 bit words to it, and at the end, fold back all the - * carry bits from the top 16 bits into the lower 16 bits. - */ - while (nleft > 1) { - sum += *w++; - nleft -= 2; - } - - /* mop up an odd byte, if necessary */ - if (nleft == 1) { - *(u_char *) (&answer) = *(u_char *) w; - sum += answer; - } - - /* add back carry outs from top 16 bits to low 16 bits */ - sum = (sum >> 16) + (sum & 0xffff); /* add hi 16 to low 16 */ - sum += (sum >> 16); /* add carry */ - answer = ~sum; /* truncate to 16 bits */ - return (answer); -} -//----------------------------------------------------------------------------- -void sgi_send_arp_request(sgi_data_t *sgi_dataP, char* dst_ip_addrP) -//----------------------------------------------------------------------------- -{ - char buffer[100]; // ARP request is 60 bytes including ethernet - struct arphdr_s *arph = (struct arphdr_s *)(buffer); - struct hostent *hp = NULL; - uint32_t i; - struct in_addr ip_dst; - struct ifreq ifr; - struct iovec iov[2]; - - sgi_dataP->eh.ether_dhost[0] = (u_int8_t)(0xFF); - sgi_dataP->eh.ether_dhost[1] = (u_int8_t)(0xFF); - sgi_dataP->eh.ether_dhost[2] = (u_int8_t)(0xFF); - sgi_dataP->eh.ether_dhost[3] = (u_int8_t)(0xFF); - sgi_dataP->eh.ether_dhost[4] = (u_int8_t)(0xFF); - sgi_dataP->eh.ether_dhost[5] = (u_int8_t)(0xFF); - - // get IP address of the default virtual interface - ifr.ifr_addr.sa_family = AF_INET; - sprintf(ifr.ifr_name, "%s.%d",sgi_dataP->interface_name,SGI_MIN_EPS_BEARER_ID); - - if (ioctl(sgi_dataP->sd[0], SIOCGIFADDR, &ifr) != 0) { - SGI_IF_ERROR("Error during IP ADDRESS RETRIEVAL ON SGI INTERFACE (%s:%d)\n",strerror(errno), errno); - exit (-1); - } - - if ((hp = gethostbyname(dst_ip_addrP)) == NULL) { - SGI_IF_DEBUG("gethostbyname() is OK.\n"); - - if ((ip_dst.s_addr = inet_addr(dst_ip_addrP)) == -1) { - SGI_IF_ERROR("%s: Can't resolve, unknown host.\n", dst_ip_addrP); - exit(1); - } - } else - bcopy(hp->h_addr_list[0], &ip_dst.s_addr, hp->h_length); - - arph->ar_hrd = htons(ARPHRD_ETHER); - arph->ar_pro = htons(ETH_P_IP); - arph->ar_hln = ETH_ALEN; - arph->ar_pln = 4; - arph->ar_op = htons(ARPOP_REQUEST); - - // sources - memcpy(arph->ar_sha, sgi_dataP->eh.ether_shost, ETH_ALEN); - - i = ((struct sockaddr_in *)&ifr.ifr_addr)->sin_addr.s_addr; - arph->ar_sip[3] = i >> 24; - arph->ar_sip[2] = (i & 0x00FF0000) >> 16; - arph->ar_sip[1] = (i & 0x0000FF00) >> 8; - arph->ar_sip[0] = (i & 0x000000FF); - - // destinations - memset(arph->ar_tha, 0, ETH_ALEN); - - i = ip_dst.s_addr; - arph->ar_tip[3] = i >> 24; - arph->ar_tip[2] = (i & 0x00FF0000) >> 16; - arph->ar_tip[1] = (i & 0x0000FF00) >> 8; - arph->ar_tip[0] = (i & 0x000000FF); - // save ip address of router for comparing with ARP REPLY - sgi_dataP->ipv4_addr_of_router = ip_dst.s_addr; - - iov[0].iov_base = &sgi_dataP->eh; - iov[0].iov_len = sizeof(sgi_dataP->eh); - iov[1].iov_base = (void *)buffer; - iov[1].iov_len = sizeof (struct arphdr) + ETH_ALEN*2 + 4*2; -#ifdef VLAN8021Q - sgi_data_p->eh.ether_vlan8021q.vlan_tpid = htons(0x8100); - sgi_dataP->eh.ether_vlan8021q.vlan_tci = htons(0x7000 | 0x0000 | SGI_MIN_EPS_BEARER_ID); -#endif - sgi_dataP->eh.ether_type = htons(ETH_P_ARP); - - sgi_print_hex_octets(iov[0].iov_base, iov[0].iov_len); - sgi_print_hex_octets(iov[1].iov_base, iov[1].iov_len); - - if (writev(sgi_dataP->sd[0], (const struct iovec *)&iov, 2) < 0) { - SGI_IF_ERROR("Error during send ARP to socket %d bearer id %d : (%s:%d)\n", - sgi_dataP->sd[0], - SGI_MIN_EPS_BEARER_ID, - strerror(errno), - errno); - exit(1); - } - -} - -- GitLab