diff --git a/LICENSE b/LICENSE index 04199a45c8a87865a975360c8b630ef708e97b97..c639838f9ae0356f5728dd364b6494650b0020f3 100644 --- a/LICENSE +++ b/LICENSE @@ -1,11 +1,9 @@ -NewIP - New IP Stack +NewIP - New IP protocol stack Copyright (c) 2022 Huawei Device Co., Ltd. All rights reserved. -NewIP is dual licensed: you can use it under the terms of the GPL V2 and the BSD2 license. - The code/linux/ subdirectorie is licensed under the GPL V2 License. -The code/ommon/ subdirectorie is licensed under 2-Clause BSD License. -The examples/ subdirectorie is licensed under 2-Clause BSD License. +The code/ommon/ subdirectorie is licensed under 3-Clause BSD License. +The examples/ subdirectorie is licensed under 3-Clause BSD License. a) GNU General Public License version 2, (https://opensource.org/licenses/GPL-2.0) This library is free software; you can redistribute it and/or @@ -23,8 +21,7 @@ License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -And, -b) The BSD2 License, (https://opensource.org/licenses/BSD-2-Clause) +b) The 3-Clause BSD License, (https://opensource.org/licenses/BSD-3-Clause) Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: @@ -36,6 +33,9 @@ conditions are met: copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. +3. Neither the name of the copyright holder nor the names of its + contributors may be used to endorse or promote products derived + from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, diff --git a/OAT.xml b/OAT.xml index 0ed7809d475eed5c83412b424581009f77e05a11..d986074b4de57ab8d7fd0a383f45d891ad9b227c 100644 --- a/OAT.xml +++ b/OAT.xml @@ -57,20 +57,21 @@ Note:If the text contains special characters, please escape them according to th - - - - - - - - - - - - - - + + + + + + + + + + + + + + + diff --git a/README.OpenSource b/README.OpenSource new file mode 100644 index 0000000000000000000000000000000000000000..5d105dacb0c3313298571615382a303c58da66a4 --- /dev/null +++ b/README.OpenSource @@ -0,0 +1,11 @@ +[ + { + "Name": "linux-5.10", + "License": "GPL-2.0+", + "License File": "COPYING", + "Version Number": "5.10.93", + "Owner": "tanyanying@huawei.com", + "Upstream URL": "https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/log/?h=linux-5.10.y", + "Description": "linux kernel 5.10" + } +] diff --git a/README_zh.md b/README_zh.md index a1d8be2ce9bfad8f21dd459286d1b78b6b58a22f..59ef5e53cdf6fa6398307f8a51d4c4c52fc1caa4 100644 --- a/README_zh.md +++ b/README_zh.md @@ -47,7 +47,8 @@ NewIP内核协议栈主要代码目录结构如下: │ │ └── uapi │ └── net │ └── newip # NewIP 功能代码 -└── figures # ReadMe 内嵌图例 +├── figures # ReadMe 内嵌图例 +└── tools # NewIP 配套工具 ``` ## 编译构建 diff --git a/apply_newip.sh b/apply_newip.sh index bf1cfc2e091c9ff585ad2dea20dbe4f487dccaf2..a415b96be943c3ba40807a3dcc57378c5a89c7cd 100644 --- a/apply_newip.sh +++ b/apply_newip.sh @@ -18,39 +18,39 @@ function main() { cd $KERNEL_BUILD_ROOT - ln -s -f $NEWIP_SOURCE_ROOT/code/linux/include/linux/newip_route.h $KERNEL_BUILD_ROOT/include/linux/newip_route.h - ln -s -f $NEWIP_SOURCE_ROOT/code/linux/include/linux/nip.h $KERNEL_BUILD_ROOT/include/linux/nip.h - ln -s -f $NEWIP_SOURCE_ROOT/code/linux/include/linux/nip_icmp.h $KERNEL_BUILD_ROOT/include/linux/nip_icmp.h + ln -s -f $NEWIP_SOURCE_ROOT/src/linux/include/linux/newip_route.h $KERNEL_BUILD_ROOT/include/linux/newip_route.h + ln -s -f $NEWIP_SOURCE_ROOT/src/linux/include/linux/nip.h $KERNEL_BUILD_ROOT/include/linux/nip.h + ln -s -f $NEWIP_SOURCE_ROOT/src/linux/include/linux/nip_icmp.h $KERNEL_BUILD_ROOT/include/linux/nip_icmp.h - ln -s -f $NEWIP_SOURCE_ROOT/code/linux/include/net/netns/nip.h $KERNEL_BUILD_ROOT/include/net/netns/nip.h - ln -s -f $NEWIP_SOURCE_ROOT/code/linux/include/net/flow_nip.h $KERNEL_BUILD_ROOT/include/net/flow_nip.h - ln -s -f $NEWIP_SOURCE_ROOT/code/linux/include/net/if_ninet.h $KERNEL_BUILD_ROOT/include/net/if_ninet.h - ln -s -f $NEWIP_SOURCE_ROOT/code/linux/include/net/ninet_connection_sock.h $KERNEL_BUILD_ROOT/include/net/ninet_connection_sock.h - ln -s -f $NEWIP_SOURCE_ROOT/code/linux/include/net/ninet_hashtables.h $KERNEL_BUILD_ROOT/include/net/ninet_hashtables.h - ln -s -f $NEWIP_SOURCE_ROOT/code/linux/include/net/nip.h $KERNEL_BUILD_ROOT/include/net/nip.h - ln -s -f $NEWIP_SOURCE_ROOT/code/linux/include/net/nip_addrconf.h $KERNEL_BUILD_ROOT/include/net/nip_addrconf.h - ln -s -f $NEWIP_SOURCE_ROOT/code/linux/include/net/nip_fib.h $KERNEL_BUILD_ROOT/include/net/nip_fib.h - ln -s -f $NEWIP_SOURCE_ROOT/code/linux/include/net/nip_route.h $KERNEL_BUILD_ROOT/include/net/nip_route.h - ln -s -f $NEWIP_SOURCE_ROOT/code/linux/include/net/nip_udp.h $KERNEL_BUILD_ROOT/include/net/nip_udp.h - ln -s -f $NEWIP_SOURCE_ROOT/code/linux/include/net/nndisc.h $KERNEL_BUILD_ROOT/include/net/nndisc.h - ln -s -f $NEWIP_SOURCE_ROOT/code/linux/include/net/tcp_nip.h $KERNEL_BUILD_ROOT/include/net/tcp_nip.h - ln -s -f $NEWIP_SOURCE_ROOT/code/linux/include/net/transp_nip.h $KERNEL_BUILD_ROOT/include/net/transp_nip.h + ln -s -f $NEWIP_SOURCE_ROOT/src/linux/include/net/netns/nip.h $KERNEL_BUILD_ROOT/include/net/netns/nip.h + ln -s -f $NEWIP_SOURCE_ROOT/src/linux/include/net/flow_nip.h $KERNEL_BUILD_ROOT/include/net/flow_nip.h + ln -s -f $NEWIP_SOURCE_ROOT/src/linux/include/net/if_ninet.h $KERNEL_BUILD_ROOT/include/net/if_ninet.h + ln -s -f $NEWIP_SOURCE_ROOT/src/linux/include/net/ninet_connection_sock.h $KERNEL_BUILD_ROOT/include/net/ninet_connection_sock.h + ln -s -f $NEWIP_SOURCE_ROOT/src/linux/include/net/ninet_hashtables.h $KERNEL_BUILD_ROOT/include/net/ninet_hashtables.h + ln -s -f $NEWIP_SOURCE_ROOT/src/linux/include/net/nip.h $KERNEL_BUILD_ROOT/include/net/nip.h + ln -s -f $NEWIP_SOURCE_ROOT/src/linux/include/net/nip_addrconf.h $KERNEL_BUILD_ROOT/include/net/nip_addrconf.h + ln -s -f $NEWIP_SOURCE_ROOT/src/linux/include/net/nip_fib.h $KERNEL_BUILD_ROOT/include/net/nip_fib.h + ln -s -f $NEWIP_SOURCE_ROOT/src/linux/include/net/nip_route.h $KERNEL_BUILD_ROOT/include/net/nip_route.h + ln -s -f $NEWIP_SOURCE_ROOT/src/linux/include/net/nip_udp.h $KERNEL_BUILD_ROOT/include/net/nip_udp.h + ln -s -f $NEWIP_SOURCE_ROOT/src/linux/include/net/nndisc.h $KERNEL_BUILD_ROOT/include/net/nndisc.h + ln -s -f $NEWIP_SOURCE_ROOT/src/linux/include/net/tcp_nip.h $KERNEL_BUILD_ROOT/include/net/tcp_nip.h + ln -s -f $NEWIP_SOURCE_ROOT/src/linux/include/net/transp_nip.h $KERNEL_BUILD_ROOT/include/net/transp_nip.h - ln -s -f $NEWIP_SOURCE_ROOT/code/linux/include/uapi/linux/newip_route.h $KERNEL_BUILD_ROOT/include/uapi/linux/newip_route.h - ln -s -f $NEWIP_SOURCE_ROOT/code/linux/include/uapi/linux/nip.h $KERNEL_BUILD_ROOT/include/uapi/linux/nip.h - ln -s -f $NEWIP_SOURCE_ROOT/code/linux/include/uapi/linux/nip_icmp.h $KERNEL_BUILD_ROOT/include/uapi/linux/nip_icmp.h + ln -s -f $NEWIP_SOURCE_ROOT/src/linux/include/uapi/linux/newip_route.h $KERNEL_BUILD_ROOT/include/uapi/linux/newip_route.h + ln -s -f $NEWIP_SOURCE_ROOT/src/linux/include/uapi/linux/nip.h $KERNEL_BUILD_ROOT/include/uapi/linux/nip.h + ln -s -f $NEWIP_SOURCE_ROOT/src/linux/include/uapi/linux/nip_icmp.h $KERNEL_BUILD_ROOT/include/uapi/linux/nip_icmp.h - ln -s -f $NEWIP_SOURCE_ROOT/code/linux/include/trace/hooks/nip_hooks.h $KERNEL_BUILD_ROOT/include/trace/hooks/nip_hooks.h + ln -s -f $NEWIP_SOURCE_ROOT/src/linux/include/trace/hooks/nip_hooks.h $KERNEL_BUILD_ROOT/include/trace/hooks/nip_hooks.h - ln -s -f $NEWIP_SOURCE_ROOT/code/linux/net/newip $KERNEL_BUILD_ROOT/net - ln -s -f $NEWIP_SOURCE_ROOT/code/common/nip_addr.c $KERNEL_BUILD_ROOT/net/newip/nip_addr.c - ln -s -f $NEWIP_SOURCE_ROOT/code/common/nip_addr.h $KERNEL_BUILD_ROOT/net/newip/nip_addr.h - ln -s -f $NEWIP_SOURCE_ROOT/code/common/nip_addr.h $KERNEL_BUILD_ROOT/include/uapi/linux/nip_addr.h - ln -s -f $NEWIP_SOURCE_ROOT/code/common/nip_checksum.c $KERNEL_BUILD_ROOT/net/newip/nip_checksum.c - ln -s -f $NEWIP_SOURCE_ROOT/code/common/nip_checksum.h $KERNEL_BUILD_ROOT/net/newip/nip_checksum.h - ln -s -f $NEWIP_SOURCE_ROOT/code/common/nip_hdr_decap.c $KERNEL_BUILD_ROOT/net/newip/nip_hdr_decap.c - ln -s -f $NEWIP_SOURCE_ROOT/code/common/nip_hdr_encap.c $KERNEL_BUILD_ROOT/net/newip/nip_hdr_encap.c - ln -s -f $NEWIP_SOURCE_ROOT/code/common/nip_hdr.h $KERNEL_BUILD_ROOT/net/newip/nip_hdr.h + ln -s -f $NEWIP_SOURCE_ROOT/src/linux/net/newip $KERNEL_BUILD_ROOT/net + ln -s -f $NEWIP_SOURCE_ROOT/src/common/nip_addr.c $KERNEL_BUILD_ROOT/net/newip/nip_addr.c + ln -s -f $NEWIP_SOURCE_ROOT/src/common/nip_addr.h $KERNEL_BUILD_ROOT/net/newip/nip_addr.h + ln -s -f $NEWIP_SOURCE_ROOT/src/common/nip_addr.h $KERNEL_BUILD_ROOT/include/uapi/linux/nip_addr.h + ln -s -f $NEWIP_SOURCE_ROOT/src/common/nip_checksum.c $KERNEL_BUILD_ROOT/net/newip/nip_checksum.c + ln -s -f $NEWIP_SOURCE_ROOT/src/common/nip_checksum.h $KERNEL_BUILD_ROOT/net/newip/nip_checksum.h + ln -s -f $NEWIP_SOURCE_ROOT/src/common/nip_hdr_decap.c $KERNEL_BUILD_ROOT/net/newip/nip_hdr_decap.c + ln -s -f $NEWIP_SOURCE_ROOT/src/common/nip_hdr_encap.c $KERNEL_BUILD_ROOT/net/newip/nip_hdr_encap.c + ln -s -f $NEWIP_SOURCE_ROOT/src/common/nip_hdr.h $KERNEL_BUILD_ROOT/net/newip/nip_hdr.h cd - } diff --git a/code/common/LICENSE b/code/common/LICENSE deleted file mode 100644 index d83b4463c4113647df63c7082244b8daf60097dc..0000000000000000000000000000000000000000 --- a/code/common/LICENSE +++ /dev/null @@ -1,29 +0,0 @@ -NewIP common -Copyright (c) 2022 Huawei Device Co., Ltd. All rights reserved. - -The BSD2 License, (https://opensource.org/licenses/BSD-2-Clause) -Redistribution and use in source and binary forms, with or -without modification, are permitted provided that the following -conditions are met: - -1. Redistributions of source code must retain the above - copyright notice, this list of conditions and the following - disclaimer. -2. Redistributions in binary form must reproduce the above - copyright notice, this list of conditions and the following - disclaimer in the documentation and/or other materials - provided with the distribution. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND -CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, -INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR -CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT -NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; -LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN -CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR -OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, -EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/code/linux/LICENSE b/code/linux/LICENSE deleted file mode 100644 index ff0812fd89cc41fc1b1ed6732a621057d30ed2ad..0000000000000000000000000000000000000000 --- a/code/linux/LICENSE +++ /dev/null @@ -1,359 +0,0 @@ -Valid-License-Identifier: GPL-2.0 -Valid-License-Identifier: GPL-2.0-only -Valid-License-Identifier: GPL-2.0+ -Valid-License-Identifier: GPL-2.0-or-later -SPDX-URL: https://spdx.org/licenses/GPL-2.0.html -Usage-Guide: - To use this license in source code, put one of the following SPDX - tag/value pairs into a comment according to the placement - guidelines in the licensing rules documentation. - For 'GNU General Public License (GPL) version 2 only' use: - SPDX-License-Identifier: GPL-2.0 - or - SPDX-License-Identifier: GPL-2.0-only - For 'GNU General Public License (GPL) version 2 or any later version' use: - SPDX-License-Identifier: GPL-2.0+ - or - SPDX-License-Identifier: GPL-2.0-or-later -License-Text: - - GNU GENERAL PUBLIC LICENSE - Version 2, June 1991 - - Copyright (C) 1989, 1991 Free Software Foundation, Inc. - 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - Everyone is permitted to copy and distribute verbatim copies - of this license document, but changing it is not allowed. - - Preamble - - The licenses for most software are designed to take away your -freedom to share and change it. By contrast, the GNU General Public -License is intended to guarantee your freedom to share and change free -software--to make sure the software is free for all its users. This -General Public License applies to most of the Free Software -Foundation's software and to any other program whose authors commit to -using it. (Some other Free Software Foundation software is covered by -the GNU Library General Public License instead.) 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 -this service 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 make restrictions that forbid -anyone to deny you these rights or to ask you to surrender the rights. -These restrictions translate to certain responsibilities for you if you -distribute copies of the software, or if you modify it. - - For example, if you distribute copies of such a program, whether -gratis or for a fee, you must give the recipients all the rights that -you have. 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. - - We protect your rights with two steps: (1) copyright the software, and -(2) offer you this license which gives you legal permission to copy, -distribute and/or modify the software. - - Also, for each author's protection and ours, we want to make certain -that everyone understands that there is no warranty for this free -software. If the software is modified by someone else and passed on, we -want its recipients to know that what they have is not the original, so -that any problems introduced by others will not reflect on the original -authors' reputations. - - Finally, any free program is threatened constantly by software -patents. We wish to avoid the danger that redistributors of a free -program will individually obtain patent licenses, in effect making the -program proprietary. To prevent this, we have made it clear that any -patent must be licensed for everyone's free use or not licensed at all. - - The precise terms and conditions for copying, distribution and -modification follow. - - GNU GENERAL PUBLIC LICENSE - TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION - - 0. This License applies to any program or other work which contains -a notice placed by the copyright holder saying it may be distributed -under the terms of this General Public License. The "Program", below, -refers to any such program or work, and a "work based on the Program" -means either the Program or any derivative work under copyright law: -that is to say, a work containing the Program or a portion of it, -either verbatim or with modifications and/or translated into another -language. (Hereinafter, translation is included without limitation in -the term "modification".) Each licensee is addressed as "you". - -Activities other than copying, distribution and modification are not -covered by this License; they are outside its scope. The act of -running the Program is not restricted, and the output from the Program -is covered only if its contents constitute a work based on the -Program (independent of having been made by running the Program). -Whether that is true depends on what the Program does. - - 1. You may copy and distribute 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 and disclaimer of warranty; keep intact all the -notices that refer to this License and to the absence of any warranty; -and give any other recipients of the Program a copy of this License -along with the Program. - -You may charge a fee for the physical act of transferring a copy, and -you may at your option offer warranty protection in exchange for a fee. - - 2. You may modify your copy or copies of the Program or any portion -of it, thus forming a work based on the Program, and copy and -distribute such modifications or work under the terms of Section 1 -above, provided that you also meet all of these conditions: - - a) You must cause the modified files to carry prominent notices - stating that you changed the files and the date of any change. - - b) You must cause any work that you distribute or publish, that in - whole or in part contains or is derived from the Program or any - part thereof, to be licensed as a whole at no charge to all third - parties under the terms of this License. - - c) If the modified program normally reads commands interactively - when run, you must cause it, when started running for such - interactive use in the most ordinary way, to print or display an - announcement including an appropriate copyright notice and a - notice that there is no warranty (or else, saying that you provide - a warranty) and that users may redistribute the program under - these conditions, and telling the user how to view a copy of this - License. (Exception: if the Program itself is interactive but - does not normally print such an announcement, your work based on - the Program is not required to print an announcement.) - -These requirements apply to the modified work as a whole. If -identifiable sections of that work are not derived from the Program, -and can be reasonably considered independent and separate works in -themselves, then this License, and its terms, do not apply to those -sections when you distribute them as separate works. But when you -distribute the same sections as part of a whole which is a work based -on the Program, the distribution of the whole must be on the terms of -this License, whose permissions for other licensees extend to the -entire whole, and thus to each and every part regardless of who wrote it. - -Thus, it is not the intent of this section to claim rights or contest -your rights to work written entirely by you; rather, the intent is to -exercise the right to control the distribution of derivative or -collective works based on the Program. - -In addition, mere aggregation of another work not based on the Program -with the Program (or with a work based on the Program) on a volume of -a storage or distribution medium does not bring the other work under -the scope of this License. - - 3. You may copy and distribute the Program (or a work based on it, -under Section 2) in object code or executable form under the terms of -Sections 1 and 2 above provided that you also do one of the following: - - a) Accompany it with the complete corresponding machine-readable - source code, which must be distributed under the terms of Sections - 1 and 2 above on a medium customarily used for software interchange; or, - - b) Accompany it with a written offer, valid for at least three - years, to give any third party, for a charge no more than your - cost of physically performing source distribution, a complete - machine-readable copy of the corresponding source code, to be - distributed under the terms of Sections 1 and 2 above on a medium - customarily used for software interchange; or, - - c) Accompany it with the information you received as to the offer - to distribute corresponding source code. (This alternative is - allowed only for noncommercial distribution and only if you - received the program in object code or executable form with such - an offer, in accord with Subsection b above.) - -The source code for a work means the preferred form of the work for -making modifications to it. For an executable work, complete source -code means all the source code for all modules it contains, plus any -associated interface definition files, plus the scripts used to -control compilation and installation of the executable. However, as a -special exception, the source code distributed need not include -anything that is normally distributed (in either source or binary -form) with the major components (compiler, kernel, and so on) of the -operating system on which the executable runs, unless that component -itself accompanies the executable. - -If distribution of executable or object code is made by offering -access to copy from a designated place, then offering equivalent -access to copy the source code from the same place counts as -distribution of the source code, even though third parties are not -compelled to copy the source along with the object code. - - 4. You may not copy, modify, sublicense, or distribute the Program -except as expressly provided under this License. Any attempt -otherwise to copy, modify, sublicense or distribute the Program is -void, and will automatically terminate your rights under this License. -However, parties who have received copies, or rights, from you under -this License will not have their licenses terminated so long as such -parties remain in full compliance. - - 5. You are not required to accept this License, since you have not -signed it. However, nothing else grants you permission to modify or -distribute the Program or its derivative works. These actions are -prohibited by law if you do not accept this License. Therefore, by -modifying or distributing the Program (or any work based on the -Program), you indicate your acceptance of this License to do so, and -all its terms and conditions for copying, distributing or modifying -the Program or works based on it. - - 6. Each time you redistribute the Program (or any work based on the -Program), the recipient automatically receives a license from the -original licensor to copy, distribute or modify the Program subject to -these terms and conditions. You may not impose any further -restrictions on the recipients' exercise of the rights granted herein. -You are not responsible for enforcing compliance by third parties to -this License. - - 7. If, as a consequence of a court judgment or allegation of patent -infringement or for any other reason (not limited to patent issues), -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 -distribute so as to satisfy simultaneously your obligations under this -License and any other pertinent obligations, then as a consequence you -may not distribute the Program at all. For example, if a patent -license would not permit royalty-free redistribution of the Program by -all those who receive copies directly or indirectly through you, then -the only way you could satisfy both it and this License would be to -refrain entirely from distribution of the Program. - -If any portion of this section is held invalid or unenforceable under -any particular circumstance, the balance of the section is intended to -apply and the section as a whole is intended to apply in other -circumstances. - -It is not the purpose of this section to induce you to infringe any -patents or other property right claims or to contest validity of any -such claims; this section has the sole purpose of protecting the -integrity of the free software distribution system, which is -implemented by public license practices. Many people have made -generous contributions to the wide range of software distributed -through that system in reliance on consistent application of that -system; it is up to the author/donor to decide if he or she is willing -to distribute software through any other system and a licensee cannot -impose that choice. - -This section is intended to make thoroughly clear what is believed to -be a consequence of the rest of this License. - - 8. If the distribution and/or use of the Program is restricted in -certain countries either by patents or by copyrighted interfaces, the -original copyright holder who places the Program under this License -may add an explicit geographical distribution limitation excluding -those countries, so that distribution is permitted only in or among -countries not thus excluded. In such case, this License incorporates -the limitation as if written in the body of this License. - - 9. The Free Software Foundation may publish revised and/or new versions -of the 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 a version number of this License which applies to it and "any -later version", you have the option of following the terms and conditions -either of that version or of any later version published by the Free -Software Foundation. If the Program does not specify a version number of -this License, you may choose any version ever published by the Free Software -Foundation. - - 10. If you wish to incorporate parts of the Program into other free -programs whose distribution conditions are different, write to the author -to ask for permission. For software which is copyrighted by the Free -Software Foundation, write to the Free Software Foundation; we sometimes -make exceptions for this. Our decision will be guided by the two goals -of preserving the free status of all derivatives of our free software and -of promoting the sharing and reuse of software generally. - - NO WARRANTY - - 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, 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. - - 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING -WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR -REDISTRIBUTE 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. - - 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 -convey the exclusion of warranty; and each file should have at least -the "copyright" line and a pointer to where the full notice is found. - - - Copyright (C) - - 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 2 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, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - - -Also add information on how to contact you by electronic and paper mail. - -If the program is interactive, make it output a short notice like this -when it starts in an interactive mode: - - Gnomovision version 69, Copyright (C) year name of author - Gnomovision 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, the commands you use may -be called something other than `show w' and `show c'; they could even be -mouse-clicks or menu items--whatever suits your program. - -You should also get your employer (if you work as a programmer) or your -school, if any, to sign a "copyright disclaimer" for the program, if -necessary. Here is a sample; alter the names: - - Yoyodyne, Inc., hereby disclaims all copyright interest in the program - `Gnomovision' (which makes passes at compilers) written by James Hacker. - - , 1 April 1989 - Ty Coon, President of Vice - -This 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 Library General -Public License instead of this License. diff --git a/code/linux/net/newip/datagram.c b/code/linux/net/newip/datagram.c deleted file mode 100644 index e4e6709ba29d9bb4d3a7fe4c07c737bc7e68253c..0000000000000000000000000000000000000000 --- a/code/linux/net/newip/datagram.c +++ /dev/null @@ -1,26 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-or-later -/* - * Copyright (c) 2022 Huawei Device Co., Ltd. - * - * NewIP common UDP code - * Linux NewIP INET implementation - * - * Adapted from linux/net/ipv6/datagram.c - */ -#include -#include -#include -#include -#include - -int nip_datagram_connect(struct sock *sk, struct sockaddr *uaddr, int addr_len) -{ - int res = 0; - return res; -} - -void nip_datagram_release_cb(struct sock *sk) -{ - ; -} - diff --git a/examples/Makefile b/examples/Makefile index 395233059debfa57ec929cb02b4796a87fb75864..b67dfdb83f93b0f6870c99ed6e5ec3b8fb6b4806 100644 --- a/examples/Makefile +++ b/examples/Makefile @@ -1,4 +1,4 @@ -# SPDX-License-Identifier: BSD-2-Clause +# SPDX-License-Identifier: BSD-3-Clause # # Copyright (c) 2022 Huawei Device Co., Ltd. # @@ -8,7 +8,7 @@ CC=gcc # CC = arm-linux-gnueabi-gcc CFLAGS=-pthread -static -g -UT_LIST = nip_addr_cfg_demo nip_route_cfg_demo nip_tcp_server_demo nip_tcp_client_demo nip_udp_server_demo nip_udp_client_demo +UT_LIST = nip_addr_cfg_demo nip_route_cfg_demo nip_tcp_server_demo nip_tcp_client_demo nip_udp_server_demo nip_udp_client_demo get_af_ninet check_nip_enable nip_addr nip_route all: $(UT_LIST) @@ -46,3 +46,15 @@ nip_udp_server_demo: nip_udp_server_demo.c $(NIP_LIB) nip_udp_client_demo: nip_udp_client_demo.c $(NIP_LIB) $(CC) $(CFLAGS) -o nip_udp_client_demo nip_udp_client_demo.c $(NIP_DEF_LIB) + +get_af_ninet: get_af_ninet.c + $(CC) $(CFLAGS) -o get_af_ninet get_af_ninet.c + +check_nip_enable: check_nip_enable.c + $(CC) $(CFLAGS) -o check_nip_enable check_nip_enable.c + +nip_addr: nip_addr.c $(NIP_LIB) + $(CC) $(CFLAGS) -o nip_addr nip_addr.c $(NIP_DEF_LIB) + +nip_route: nip_route.c $(NIP_LIB) + $(CC) $(CFLAGS) -o nip_route nip_route.c $(NIP_DEF_LIB) \ No newline at end of file diff --git a/examples/check_nip_enable.c b/examples/check_nip_enable.c new file mode 100644 index 0000000000000000000000000000000000000000..3f96b3054a0c057fe80fe5cd969f85c4516289df --- /dev/null +++ b/examples/check_nip_enable.c @@ -0,0 +1,78 @@ +// SPDX-License-Identifier: BSD-3-Clause +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above + * copyright notice, this list of conditions and the following + * disclaimer. + * 2. Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials + * provided with the distribution. + * 3. Neither the name of the copyright holder nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#include +#include +#include +#include +#include + +#define NIP_DISABLE_PATH ("/sys/module/newip/parameters/disable") +#define NIP_DISABLE_LENTH (5) +#define NIP_ENABLE_INVALID (0xFF) + +int g_nip_enable = NIP_ENABLE_INVALID; + +void _check_nip_enable(void) +{ + char tmp[NIP_DISABLE_LENTH]; + FILE *fn = fopen(NIP_DISABLE_PATH, "r"); + + if (!fn) { + printf("fail to open %s.\n\n", NIP_DISABLE_PATH); + return; + } + + if (fgets(tmp, NIP_DISABLE_LENTH, fn) == NULL) { + printf("fail to gets %s.\n\n", NIP_DISABLE_PATH); + fclose(fn); + return; + } + + fclose(fn); + g_nip_enable = atoi(tmp) ? 0 : 1; +} + +int check_nip_enable(void) +{ + if (g_nip_enable == NIP_ENABLE_INVALID) + _check_nip_enable(); + + return g_nip_enable; +} + +int main(int argc, char **argv) +{ + int af_ninet = check_nip_enable(); + + printf("nip_enable=%d\n\n", g_nip_enable); + return 0; +} + diff --git a/examples/get_af_ninet.c b/examples/get_af_ninet.c new file mode 100644 index 0000000000000000000000000000000000000000..d245f2d86512740bf03a98febb7fe0f6c2337703 --- /dev/null +++ b/examples/get_af_ninet.c @@ -0,0 +1,77 @@ +// SPDX-License-Identifier: BSD-3-Clause +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above + * copyright notice, this list of conditions and the following + * disclaimer. + * 2. Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials + * provided with the distribution. + * 3. Neither the name of the copyright holder nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#include +#include +#include +#include +#include + +#define AF_NINET_PATH ("/sys/module/newip/parameters/af_ninet") +#define AF_NINET_LENTH (5) + +int g_af_ninet; + +void _get_af_ninet(void) +{ + char tmp[AF_NINET_LENTH]; + FILE *fn = fopen(AF_NINET_PATH, "r"); + + if (!fn) { + printf("fail to open %s.\n\n", AF_NINET_PATH); + return; + } + + if (fgets(tmp, AF_NINET_LENTH, fn) == NULL) { + printf("fail to gets %s.\n\n", AF_NINET_PATH); + fclose(fn); + return; + } + + fclose(fn); + g_af_ninet = atoi(tmp); +} + +int get_af_ninet(void) +{ + if (g_af_ninet == 0) + _get_af_ninet(); + + return g_af_ninet; +} + +int main(int argc, char **argv) +{ + int af_ninet = get_af_ninet(); + + printf("af_ninet=%d\n\n", g_af_ninet); + return 0; +} + diff --git a/examples/newip_route.h b/examples/newip_route.h index b1f6118de6e4871678b291b65bd8dc5c4e38c7aa..37b136bac944c47f42566e14eea649fa6d064b77 100644 --- a/examples/newip_route.h +++ b/examples/newip_route.h @@ -1,16 +1,20 @@ -/* SPDX-License-Identifier: BSD-2-Clause */ +/* SPDX-License-Identifier: BSD-3-Clause */ /* * Copyright (c) 2022 Huawei Device Co., Ltd. * * Redistribution and use in source and binary forms, with or without modification, * are permitted provided that the following conditions are met: * - * 1. Redistributions of source code must retain the above copyright notice, this list of - * conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list - * of conditions and the following disclaimer in the documentation and/or other materials + * 1. Redistributions of source code must retain the above + * copyright notice, this list of conditions and the following + * disclaimer. + * 2. Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials * provided with the distribution. + * 3. Neither the name of the copyright holder nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, diff --git a/examples/nip.h b/examples/nip.h index 2dff0395384805a9ca01b45ab09995d33309817c..06d5da91a76fa176ac9617c1ed4fe3dc3f607a70 100644 --- a/examples/nip.h +++ b/examples/nip.h @@ -1,16 +1,20 @@ -/* SPDX-License-Identifier: BSD-2-Clause */ +/* SPDX-License-Identifier: BSD-3-Clause */ /* * Copyright (c) 2022 Huawei Device Co., Ltd. * * Redistribution and use in source and binary forms, with or without modification, * are permitted provided that the following conditions are met: * - * 1. Redistributions of source code must retain the above copyright notice, this list of - * conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list - * of conditions and the following disclaimer in the documentation and/or other materials + * 1. Redistributions of source code must retain the above + * copyright notice, this list of conditions and the following + * disclaimer. + * 2. Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials * provided with the distribution. + * 3. Neither the name of the copyright holder nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, @@ -41,6 +45,20 @@ #define NIP_ADDR_BIT_LEN_40 40 #define NIP_ADDR_BIT_LEN_MAX 64 +enum nip_addr_check_value { + ADDR_FIRST_DC = 0xDC, + ADDR_FIRST_F0 = 0xF0, + ADDR_FIRST_F1, + ADDR_FIRST_F2, + ADDR_FIRST_F3, + ADDR_FIRST_FE = 0xFE, + ADDR_FIRST_FF = 0xFF, + ADDR_SECOND_MIN_DD = 0xDD, + ADDR_SECOND_MIN_F1 = 0x14, /* f1 14 00 */ + ADDR_THIRD_MIN_F2 = 0x01, /* f2 00 01 00 00 */ + ADDR_THIRD_MIN_F3 = 0x01, /* F3 0001 0000 0000 */ +}; + enum nip_8bit_addr_index { NIP_8BIT_ADDR_INDEX_0 = 0, NIP_8BIT_ADDR_INDEX_1 = 1, diff --git a/examples/nip_addr.c b/examples/nip_addr.c new file mode 100644 index 0000000000000000000000000000000000000000..b6aa8a56b29d1c3bf75aeb3b324f16f5665a4bc7 --- /dev/null +++ b/examples/nip_addr.c @@ -0,0 +1,137 @@ +// SPDX-License-Identifier: BSD-3-Clause +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above + * copyright notice, this list of conditions and the following + * disclaimer. + * 2. Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials + * provided with the distribution. + * 3. Neither the name of the copyright holder nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#include +#include +#include +#include +#include +#include +#include + +#include "nip_uapi.h" +#include "nip_lib.h" + +/* get ifindex based on the device name + * struct ifreq ifr; + * struct nip_ifreq ifrn; + * ioctl(fd, SIOGIFINDEX, &ifr); + * ifr.ifr_ifindex; ===> ifindex + */ +int32_t nip_add_addr(int32_t ifindex, struct nip_addr *addr, int opt) +{ + int fd, ret; + struct nip_ifreq ifrn; + + fd = socket(AF_NINET, SOCK_DGRAM, 0); + if (fd < 0) + return -1; + + memset(&ifrn, 0, sizeof(ifrn)); + ifrn.ifrn_addr = *addr; + ifrn.ifrn_ifindex = ifindex; + + ret = ioctl(fd, opt, &ifrn); + if (ret < 0 && errno != EEXIST) { // ignore File Exists error + printf("cfg newip addr fail, ifindex=%d, opt=%u, ret=%d.\n", ifindex, opt, ret); + close(fd); + return -1; + } + + close(fd); + return 0; +} + +void cmd_help(void) +{ + /* nip_addr wlan0 add 01 (在wlan0上配置地址01) */ + /* nip_addr wlan0 del 01 (在wlan0上删除地址01) */ + printf("[cmd example] nip_addr { add | del } \n"); +} + +int main(int argc, char **argv_input) +{ + int ret; + int opt; + int ifindex = 0; + char **argv = argv_input; + char cmd[ARRAY_LEN]; + char dev[ARRAY_LEN]; + struct nip_addr addr = {0}; + + if (argc != DEMO_INPUT_3) { + printf("unsupport addr cfg input, argc=%u.\n", argc); + cmd_help(); + return -1; + } + + /* 配置参数1解析: */ + argv++; + memset(dev, 0, ARRAY_LEN); + ret = sscanf(*argv, "%s", dev); + if (strncmp(dev, "wlan", NAME_WLAN_LEN) && strncmp(dev, "eth", NAME_ETH_LEN)) { + printf("unsupport addr cfg cmd-1, cmd=%s.\n", dev); + cmd_help(); + return -1; + } + ret = nip_get_ifindex(dev, &ifindex); + if (ret != 0) + return -1; + + /* 配置参数2解析: { add | del } */ + argv++; + memset(cmd, 0, ARRAY_LEN); + ret = sscanf(*argv, "%s", cmd); + if (!strncmp(cmd, "add", NAME_WLAN_LEN)) { + opt = SIOCSIFADDR; + } else if (!strncmp(cmd, "del", NAME_WLAN_LEN)) { + opt = SIOCDIFADDR; + } else { + printf("unsupport addr cfg cmd-2, cmd=%s.\n", cmd); + cmd_help(); + return -1; + } + + /* 配置参数3解析: */ + argv++; + if (nip_get_addr(argv, &addr)) { + printf("unsupport addr cfg cmd-3.\n"); + cmd_help(); + return 1; + } + + ret = nip_add_addr(ifindex, &addr, opt); + if (ret != 0) + return -1; + + printf("%s (ifindex=%u) cfg addr success.\n", dev, ifindex); + return 0; +} + diff --git a/examples/nip_addr_cfg_demo.c b/examples/nip_addr_cfg_demo.c index 7d2c3106c86a1b69f3455e1461a646b0852bca4e..7915b70cf1d7499e4de84900904c2a9adf1c99ae 100644 --- a/examples/nip_addr_cfg_demo.c +++ b/examples/nip_addr_cfg_demo.c @@ -1,16 +1,20 @@ -// SPDX-License-Identifier: BSD-2-Clause +// SPDX-License-Identifier: BSD-3-Clause /* * Copyright (c) 2022 Huawei Device Co., Ltd. * * Redistribution and use in source and binary forms, with or without modification, * are permitted provided that the following conditions are met: * - * 1. Redistributions of source code must retain the above copyright notice, this list of - * conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list - * of conditions and the following disclaimer in the documentation and/or other materials + * 1. Redistributions of source code must retain the above + * copyright notice, this list of conditions and the following + * disclaimer. + * 2. Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials * provided with the distribution. + * 3. Neither the name of the copyright holder nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, diff --git a/examples/nip_lib.c b/examples/nip_lib.c index b6a8c7dd23e7a96f0c443de7fbb10558410f0fc2..8699228c4183761995e1ce8b9206ceea040979bb 100644 --- a/examples/nip_lib.c +++ b/examples/nip_lib.c @@ -1,16 +1,20 @@ -// SPDX-License-Identifier: BSD-2-Clause +// SPDX-License-Identifier: BSD-3-Clause /* * Copyright (c) 2022 Huawei Device Co., Ltd. * * Redistribution and use in source and binary forms, with or without modification, * are permitted provided that the following conditions are met: * - * 1. Redistributions of source code must retain the above copyright notice, this list of - * conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list - * of conditions and the following disclaimer in the documentation and/or other materials + * 1. Redistributions of source code must retain the above + * copyright notice, this list of conditions and the following + * disclaimer. + * 2. Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials * provided with the distribution. + * 3. Neither the name of the copyright holder nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, @@ -35,6 +39,10 @@ #include "nip_uapi.h" #include "nip_lib.h" +#define ADDR_STR_LEN 2 +#define STR_FMT_1 55 +#define STR_FMT_2 87 + int32_t nip_get_ifindex(const char *ifname, int *ifindex) { int fd; @@ -59,3 +67,83 @@ int32_t nip_get_ifindex(const char *ifname, int *ifindex) return 0; } +int nip_addr_fmt(char *addr, struct nip_addr *sap, int addrlen_input) +{ + unsigned char first_byte; + int addrlen, i; + + memset(sap, 0, sizeof(struct nip_addr)); + for (i = 0; i < INDEX_MAX; i++) { + /* 0 ~ 9 = 48 ~ 57, '0'构造成 0 = 48 - 48 */ + if (addr[i] >= '0' && addr[i] <= '9') + addr[i] = addr[i] - '0'; + /* A ~ F = 65 ~ 70, 'A'构造成 10 = 65 - 55 */ + else if (addr[i] >= 'A' && addr[i] <= 'F') + addr[i] = addr[i] - STR_FMT_1; + /* a ~ f = 97 ~ 102, 'a'构造成 10 = 97 - 87 */ + else if (addr[i] >= 'a' && addr[i] <= 'f') + addr[i] = addr[i] - STR_FMT_2; + else if (addr[i] == 0) + break; + + printf("Newip addr error: uaddr[%u]=%c.\n", i, addr[i]); + return 1; + } + + first_byte = addr[0] << NIP_ADDR_LEN_4; + first_byte += addr[1]; + if (first_byte >= 0x00 && first_byte <= ADDR_FIRST_DC) + addrlen = NIP_ADDR_LEN_1; + else if ((first_byte > ADDR_FIRST_DC && first_byte <= ADDR_FIRST_F0) || + (first_byte == ADDR_FIRST_FF)) + addrlen = NIP_ADDR_LEN_2; + else if (first_byte == ADDR_FIRST_F1) + addrlen = NIP_ADDR_LEN_3; + else if (first_byte == ADDR_FIRST_F2) + addrlen = NIP_ADDR_LEN_5; + else if (first_byte == ADDR_FIRST_F3) + addrlen = NIP_ADDR_LEN_7; + else if (first_byte == ADDR_FIRST_FE) + addrlen = NIP_ADDR_LEN_8; + else + addrlen = 0; + + if (addrlen_input != addrlen) { + printf("Newip addr error, first_byte=0x%x.\n", first_byte); + return 1; + } + + sap->bitlen = addrlen * NIP_ADDR_LEN_8; + printf("*************************************************\n"); + printf("Newip addr len=%u\n", addrlen); + for (i = 0; i < addrlen; i++) { + sap->nip_addr_field8[i] = addr[i * INDEX_2] << INDEX_4; + sap->nip_addr_field8[i] += addr[i * INDEX_2 + 1]; + printf("%02x ", sap->nip_addr_field8[i]); + } + printf("\n*************************************************\n\n"); + + return 0; +} + +int nip_get_addr(char **args, struct nip_addr *addr) +{ + int ret; + char *sp = *args; + int addrlen_input = 0; + __u8 addr[INDEX_MAX] = {0}; + + while (*sp != '\0') { + addrlen_input += 1; + sp++; + } + + if (addrlen_input % ADDR_STR_LEN != 0) { + printf("NewIP addr str-len invalid, addrlen_input=%u.\n", addrlen_input); + return -1; + } + + ret = sscanf(*args, "%s", addr); + return nip_addr_fmt(addr, addr, addrlen_input / ADDR_STR_LEN); +} + diff --git a/examples/nip_lib.h b/examples/nip_lib.h index 3a38b93cf48488a9195a3627e93847177c6f74bd..a32dfe70d5297fe40cfcb299f79520ee9d7163fb 100644 --- a/examples/nip_lib.h +++ b/examples/nip_lib.h @@ -1,16 +1,20 @@ -/* SPDX-License-Identifier: BSD-2-Clause */ +/* SPDX-License-Identifier: BSD-3-Clause */ /* * Copyright (c) 2022 Huawei Device Co., Ltd. * * Redistribution and use in source and binary forms, with or without modification, * are permitted provided that the following conditions are met: * - * 1. Redistributions of source code must retain the above copyright notice, this list of - * conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list - * of conditions and the following disclaimer in the documentation and/or other materials + * 1. Redistributions of source code must retain the above + * copyright notice, this list of conditions and the following + * disclaimer. + * 2. Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials * provided with the distribution. + * 3. Neither the name of the copyright holder nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, @@ -31,6 +35,9 @@ #define AF_NINET 45 #define DEMO_INPUT_1 2 /* The DEMO program contains one parameter */ +#define DEMO_INPUT_2 3 +#define DEMO_INPUT_3 4 +#define DEMO_INPUT_4 5 /* Eth0 and wlan0 are optional. Change the value based on the actual interface */ #define NIC_NAME "eth0" @@ -44,6 +51,11 @@ #define TCP_SERVER_PORT 5556 /* TCP Server Port */ #define UDP_SERVER_PORT 9090 /* UDP Server Port */ +#define NAME_WLAN_LEN 4 +#define NAME_ETH_LEN 3 +#define ARRAY_LEN 255 + int nip_get_ifindex(const char *ifname, int *ifindex); +int nip_get_addr(char **args, struct nip_addr *addr); #endif /* _NIP_LIB_H */ diff --git a/examples/nip_route.c b/examples/nip_route.c new file mode 100644 index 0000000000000000000000000000000000000000..46b9d01cb41bc8cf84b6edf3cef152f1e699176c --- /dev/null +++ b/examples/nip_route.c @@ -0,0 +1,172 @@ +// SPDX-License-Identifier: BSD-3-Clause +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above + * copyright notice, this list of conditions and the following + * disclaimer. + * 2. Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials + * provided with the distribution. + * 3. Neither the name of the copyright holder nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#include +#include +#include +#include +#include +#include +#include +#include + +#include "nip_uapi.h" +#include "nip_lib.h" +#include "newip_route.h" + +/* get ifindex based on the device name + * struct ifreq ifr; + * struct nip_ifreq ifrn; + * ioctl(fd, SIOGIFINDEX, &ifr); + * ifr.ifr_ifindex; ===> ifindex + */ +int nip_route_add(int ifindex, struct nip_addr *dst_addr, struct nip_addr *gateway_addr, + uint8_t gateway_flag, int opt) +{ + int fd, ret; + struct nip_rtmsg rt; + + fd = socket(AF_NINET, SOCK_DGRAM, 0); + if (fd < 0) + return -1; + + memset(&rt, 0, sizeof(rt)); + rt.rtmsg_ifindex = ifindex; + rt.rtmsg_flags = RTF_UP; + rt.rtmsg_dst = *dst_addr; + + if (gateway_flag) { + rt.rtmsg_gateway = *gateway_addr; + rt.rtmsg_flags |= RTF_GATEWAY; + } + + ret = ioctl(fd, opt, &rt); + if (ret < 0 && errno != EEXIST) { // ignore File Exists error + close(fd); + return -1; + } + + close(fd); + return 0; +} + +void cmd_help(void) +{ + /* nip_route add 02 wlan0 (配置目的地址02设备路由,出口是wlan0) + * nip_route add 02 wlan0 03 (配置目的地址02设备路由,出口是wlan0,网关地址是03) + * nip_route add ff09 wlan0 03 (配置广播默认路由, 出口是wlan0,网关地址是03) + */ + printf("\n[cmd example]\n"); + printf("nip_route { add | del } \n"); + printf("nip_route { add | del } \n"); +} + +int main(int argc, char **argv_input) +{ + int ret; + int opt; + int ifindex = 0; + uint8_t dst_addr_len; + uint8_t gateway_addr_len; + uint8_t gateway_flag = 0; + char **argv = argv_input; + char cmd[ARRAY_LEN]; + char dev[ARRAY_LEN]; + struct nip_addr dst_addr = {0}; + struct nip_addr gateway_addr = {0}; + + if (argc != DEMO_INPUT_3 && argc != DEMO_INPUT_4) { + printf("unsupport route cfg input, argc=%u.\n", argc); + cmd_help(); + return -1; + } + + /* 配置参数1解析: { add | del } */ + argv++; + memset(cmd, 0, ARRAY_LEN); + ret = sscanf(*argv, "%s", cmd); + if (!strncmp(cmd, "add", NAME_WLAN_LEN)) { + opt = SIOCADDRT; + } else if (!strncmp(cmd, "del", NAME_WLAN_LEN)) { + opt = SIOCDELRT; + } else { + printf("unsupport route cfg cmd-1, cmd=%s.\n", cmd); + cmd_help(); + return -1; + } + + /* 配置参数2解析: */ + argv++; + if (nip_get_addr(argv, &dst_addr)) { + printf("unsupport route cfg cmd-2.\n"); + cmd_help(); + return 1; + } + + /* 配置参数3解析: */ + argv++; + memset(dev, 0, ARRAY_LEN); + ret = sscanf(*argv, "%s", dev); + if (strncmp(dev, "wlan", NAME_WLAN_LEN) && strncmp(dev, "eth", NAME_ETH_LEN)) { + printf("unsupport route cfg cmd-3, cmd=%s.\n", dev); + cmd_help(); + return -1; + } + ret = nip_get_ifindex(dev, &ifindex); + if (ret != 0) + return -1; + + /* 配置参数4解析: */ + if (argc == DEMO_INPUT_4) { + argv++; + if (nip_get_addr(argv, &gateway_addr)) { + printf("unsupport route cfg cmd-4.\n"); + cmd_help(); + return 1; + } + gateway_flag = 1; + } + + ret = nip_get_ifindex(dev, &ifindex); + if (ret != 0) { + printf("get %s ifindex fail, ret=%d.\n", dev, ret); + return -1; + } + + ret = nip_route_add(ifindex, &dst_addr, &gateway_addr, gateway_flag, opt); + if (ret != 0) { + printf("get %s ifindex fail, ret=%d.\n", dev, ret); + return -1; + } + + printf("%s (ifindex=%u) cfg route success.\n", dev, ifindex); + return 0; +} + diff --git a/examples/nip_route_cfg_demo.c b/examples/nip_route_cfg_demo.c index 5ed1bd1547e90490cd7015267c5a0e4f8031aec3..8a0d4b613a1d3cc03b7aec60953257bffbe6202d 100644 --- a/examples/nip_route_cfg_demo.c +++ b/examples/nip_route_cfg_demo.c @@ -1,16 +1,20 @@ -// SPDX-License-Identifier: BSD-2-Clause +// SPDX-License-Identifier: BSD-3-Clause /* * Copyright (c) 2022 Huawei Device Co., Ltd. * * Redistribution and use in source and binary forms, with or without modification, * are permitted provided that the following conditions are met: * - * 1. Redistributions of source code must retain the above copyright notice, this list of - * conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list - * of conditions and the following disclaimer in the documentation and/or other materials + * 1. Redistributions of source code must retain the above + * copyright notice, this list of conditions and the following + * disclaimer. + * 2. Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials * provided with the distribution. + * 3. Neither the name of the copyright holder nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, diff --git a/examples/nip_tcp_client_demo.c b/examples/nip_tcp_client_demo.c index 5344e2bbd28053ee59ad49cfe40cdebac02df5fa..7a83be9fd47bfb62edb233de6c8dd2331bbcb15c 100644 --- a/examples/nip_tcp_client_demo.c +++ b/examples/nip_tcp_client_demo.c @@ -1,16 +1,20 @@ -// SPDX-License-Identifier: BSD-2-Clause +// SPDX-License-Identifier: BSD-3-Clause /* * Copyright (c) 2022 Huawei Device Co., Ltd. * * Redistribution and use in source and binary forms, with or without modification, * are permitted provided that the following conditions are met: * - * 1. Redistributions of source code must retain the above copyright notice, this list of - * conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list - * of conditions and the following disclaimer in the documentation and/or other materials + * 1. Redistributions of source code must retain the above + * copyright notice, this list of conditions and the following + * disclaimer. + * 2. Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials * provided with the distribution. + * 3. Neither the name of the copyright holder nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, diff --git a/examples/nip_tcp_server_demo.c b/examples/nip_tcp_server_demo.c index f0ef1961a8bcdf336cf57294353e84f339f7a3cd..b692e3afae4850d0c921ed66e7e09eebd8fceaca 100644 --- a/examples/nip_tcp_server_demo.c +++ b/examples/nip_tcp_server_demo.c @@ -1,16 +1,20 @@ -// SPDX-License-Identifier: BSD-2-Clause +// SPDX-License-Identifier: BSD-3-Clause /* * Copyright (c) 2022 Huawei Device Co., Ltd. * * Redistribution and use in source and binary forms, with or without modification, * are permitted provided that the following conditions are met: * - * 1. Redistributions of source code must retain the above copyright notice, this list of - * conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list - * of conditions and the following disclaimer in the documentation and/or other materials + * 1. Redistributions of source code must retain the above + * copyright notice, this list of conditions and the following + * disclaimer. + * 2. Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials * provided with the distribution. + * 3. Neither the name of the copyright holder nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, diff --git a/examples/nip_udp_client_demo.c b/examples/nip_udp_client_demo.c index 7bd6d30a4c5fa5e6c1379a647e55b81b7b40349c..74f1634ea99a874851aa78c9e0158c53e7f6c638 100644 --- a/examples/nip_udp_client_demo.c +++ b/examples/nip_udp_client_demo.c @@ -1,16 +1,20 @@ -// SPDX-License-Identifier: BSD-2-Clause +// SPDX-License-Identifier: BSD-3-Clause /* * Copyright (c) 2022 Huawei Device Co., Ltd. * * Redistribution and use in source and binary forms, with or without modification, * are permitted provided that the following conditions are met: * - * 1. Redistributions of source code must retain the above copyright notice, this list of - * conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list - * of conditions and the following disclaimer in the documentation and/or other materials + * 1. Redistributions of source code must retain the above + * copyright notice, this list of conditions and the following + * disclaimer. + * 2. Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials * provided with the distribution. + * 3. Neither the name of the copyright holder nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, diff --git a/examples/nip_udp_server_demo.c b/examples/nip_udp_server_demo.c index 612b3e8e3f8cec4dfbd1eb7da344611fa7f761c5..07fc327dc9b5b7f6c3e690a1fe14c32ec57fbf97 100644 --- a/examples/nip_udp_server_demo.c +++ b/examples/nip_udp_server_demo.c @@ -1,16 +1,20 @@ -// SPDX-License-Identifier: BSD-2-Clause +// SPDX-License-Identifier: BSD-3-Clause /* * Copyright (c) 2022 Huawei Device Co., Ltd. * * Redistribution and use in source and binary forms, with or without modification, * are permitted provided that the following conditions are met: * - * 1. Redistributions of source code must retain the above copyright notice, this list of - * conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list - * of conditions and the following disclaimer in the documentation and/or other materials + * 1. Redistributions of source code must retain the above + * copyright notice, this list of conditions and the following + * disclaimer. + * 2. Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials * provided with the distribution. + * 3. Neither the name of the copyright holder nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, diff --git a/figures/image-20220901152539801.png b/figures/image-20220901152539801.png index 7a26e08dde2035080fd492ab6d2738b9e1a1eef1..4adcdeffc67754f3a7da8527c67eca22ddd9bbb4 100644 Binary files a/figures/image-20220901152539801.png and b/figures/image-20220901152539801.png differ diff --git a/code/common/nip_addr.c b/src/common/nip_addr.c similarity index 95% rename from code/common/nip_addr.c rename to src/common/nip_addr.c index ff1a1d293f17838a505651fd60893805f0d5e399..cc5d2b3f42db7d56504fb5dde8036fea57cbd153 100644 --- a/code/common/nip_addr.c +++ b/src/common/nip_addr.c @@ -1,16 +1,20 @@ -// SPDX-License-Identifier: BSD-2-Clause +// SPDX-License-Identifier: BSD-3-Clause /* * Copyright (c) 2022 Huawei Device Co., Ltd. * * Redistribution and use in source and binary forms, with or without modification, * are permitted provided that the following conditions are met: * - * 1. Redistributions of source code must retain the above copyright notice, this list of - * conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list - * of conditions and the following disclaimer in the documentation and/or other materials + * 1. Redistributions of source code must retain the above + * copyright notice, this list of conditions and the following + * disclaimer. + * 2. Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials * provided with the distribution. + * 3. Neither the name of the copyright holder nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, diff --git a/code/common/nip_addr.h b/src/common/nip_addr.h similarity index 86% rename from code/common/nip_addr.h rename to src/common/nip_addr.h index a9139b13010377843e8d934bddbd2923302306f9..905ff82c9b80e5b5f77a47d3b8cb1f21a0b26082 100644 --- a/code/common/nip_addr.h +++ b/src/common/nip_addr.h @@ -1,16 +1,20 @@ -/* SPDX-License-Identifier: BSD-2-Clause */ +/* SPDX-License-Identifier: BSD-3-Clause */ /* * Copyright (c) 2022 Huawei Device Co., Ltd. * * Redistribution and use in source and binary forms, with or without modification, * are permitted provided that the following conditions are met: * - * 1. Redistributions of source code must retain the above copyright notice, this list of - * conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list - * of conditions and the following disclaimer in the documentation and/or other materials + * 1. Redistributions of source code must retain the above + * copyright notice, this list of conditions and the following + * disclaimer. + * 2. Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials * provided with the distribution. + * 3. Neither the name of the copyright holder nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, diff --git a/code/common/nip_checksum.c b/src/common/nip_checksum.c similarity index 85% rename from code/common/nip_checksum.c rename to src/common/nip_checksum.c index fdd1d18c654171ce1961fd9889f8825dcf21c4c4..b99d527a671ff783c65a7544e0816c8a596ba8e5 100644 --- a/code/common/nip_checksum.c +++ b/src/common/nip_checksum.c @@ -1,16 +1,20 @@ -// SPDX-License-Identifier: BSD-2-Clause +// SPDX-License-Identifier: BSD-3-Clause /* * Copyright (c) 2022 Huawei Device Co., Ltd. * * Redistribution and use in source and binary forms, with or without modification, * are permitted provided that the following conditions are met: * - * 1. Redistributions of source code must retain the above copyright notice, this list of - * conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list - * of conditions and the following disclaimer in the documentation and/or other materials + * 1. Redistributions of source code must retain the above + * copyright notice, this list of conditions and the following + * disclaimer. + * 2. Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials * provided with the distribution. + * 3. Neither the name of the copyright holder nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, diff --git a/code/common/nip_checksum.h b/src/common/nip_checksum.h similarity index 77% rename from code/common/nip_checksum.h rename to src/common/nip_checksum.h index 3dd28f4be2de30f912ca801f72590b10d111f12b..c86b07a652133d105ca6878f8c3dca41837b99cd 100644 --- a/code/common/nip_checksum.h +++ b/src/common/nip_checksum.h @@ -1,16 +1,20 @@ -/* SPDX-License-Identifier: BSD-2-Clause */ +/* SPDX-License-Identifier: BSD-3-Clause */ /* * Copyright (c) 2022 Huawei Device Co., Ltd. * * Redistribution and use in source and binary forms, with or without modification, * are permitted provided that the following conditions are met: * - * 1. Redistributions of source code must retain the above copyright notice, this list of - * conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list - * of conditions and the following disclaimer in the documentation and/or other materials + * 1. Redistributions of source code must retain the above + * copyright notice, this list of conditions and the following + * disclaimer. + * 2. Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials * provided with the distribution. + * 3. Neither the name of the copyright holder nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, diff --git a/code/common/nip_hdr.h b/src/common/nip_hdr.h similarity index 94% rename from code/common/nip_hdr.h rename to src/common/nip_hdr.h index 3c8ecb389313db743a8114b78ebdfb9dbe399154..6b2855b3f788d0d2de40906754a6ea0af403945c 100644 --- a/code/common/nip_hdr.h +++ b/src/common/nip_hdr.h @@ -1,16 +1,20 @@ -/* SPDX-License-Identifier: BSD-2-Clause */ +/* SPDX-License-Identifier: BSD-3-Clause */ /* * Copyright (c) 2022 Huawei Device Co., Ltd. * * Redistribution and use in source and binary forms, with or without modification, * are permitted provided that the following conditions are met: * - * 1. Redistributions of source code must retain the above copyright notice, this list of - * conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list - * of conditions and the following disclaimer in the documentation and/or other materials + * 1. Redistributions of source code must retain the above + * copyright notice, this list of conditions and the following + * disclaimer. + * 2. Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials * provided with the distribution. + * 3. Neither the name of the copyright holder nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, diff --git a/code/common/nip_hdr_decap.c b/src/common/nip_hdr_decap.c similarity index 92% rename from code/common/nip_hdr_decap.c rename to src/common/nip_hdr_decap.c index 10b00c90a1bbbd62ee12b205ce839f47f652c5bc..02f93eccee06838515deb4ef874495da42ff6d7e 100644 --- a/code/common/nip_hdr_decap.c +++ b/src/common/nip_hdr_decap.c @@ -1,16 +1,20 @@ -// SPDX-License-Identifier: BSD-2-Clause +// SPDX-License-Identifier: BSD-3-Clause /* * Copyright (c) 2022 Huawei Device Co., Ltd. * * Redistribution and use in source and binary forms, with or without modification, * are permitted provided that the following conditions are met: * - * 1. Redistributions of source code must retain the above copyright notice, this list of - * conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list - * of conditions and the following disclaimer in the documentation and/or other materials + * 1. Redistributions of source code must retain the above + * copyright notice, this list of conditions and the following + * disclaimer. + * 2. Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials * provided with the distribution. + * 3. Neither the name of the copyright holder nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, diff --git a/code/common/nip_hdr_encap.c b/src/common/nip_hdr_encap.c similarity index 92% rename from code/common/nip_hdr_encap.c rename to src/common/nip_hdr_encap.c index 0928eed4331728836947029b051c6e0bfb2e9eaf..ff5c83620ea33ccd4e367f2f51966479e801afcb 100644 --- a/code/common/nip_hdr_encap.c +++ b/src/common/nip_hdr_encap.c @@ -1,16 +1,20 @@ -// SPDX-License-Identifier: BSD-2-Clause +// SPDX-License-Identifier: BSD-3-Clause /* * Copyright (c) 2022 Huawei Device Co., Ltd. * * Redistribution and use in source and binary forms, with or without modification, * are permitted provided that the following conditions are met: * - * 1. Redistributions of source code must retain the above copyright notice, this list of - * conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list - * of conditions and the following disclaimer in the documentation and/or other materials + * 1. Redistributions of source code must retain the above + * copyright notice, this list of conditions and the following + * disclaimer. + * 2. Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials * provided with the distribution. + * 3. Neither the name of the copyright holder nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, diff --git a/code/linux/include/linux/newip_route.h b/src/linux/include/linux/newip_route.h similarity index 100% rename from code/linux/include/linux/newip_route.h rename to src/linux/include/linux/newip_route.h diff --git a/code/linux/include/linux/nip.h b/src/linux/include/linux/nip.h similarity index 100% rename from code/linux/include/linux/nip.h rename to src/linux/include/linux/nip.h diff --git a/code/linux/include/linux/nip_icmp.h b/src/linux/include/linux/nip_icmp.h similarity index 100% rename from code/linux/include/linux/nip_icmp.h rename to src/linux/include/linux/nip_icmp.h diff --git a/code/linux/include/net/flow_nip.h b/src/linux/include/net/flow_nip.h similarity index 100% rename from code/linux/include/net/flow_nip.h rename to src/linux/include/net/flow_nip.h diff --git a/code/linux/include/net/if_ninet.h b/src/linux/include/net/if_ninet.h similarity index 100% rename from code/linux/include/net/if_ninet.h rename to src/linux/include/net/if_ninet.h diff --git a/code/linux/include/net/netns/nip.h b/src/linux/include/net/netns/nip.h similarity index 100% rename from code/linux/include/net/netns/nip.h rename to src/linux/include/net/netns/nip.h diff --git a/code/linux/include/net/ninet_connection_sock.h b/src/linux/include/net/ninet_connection_sock.h similarity index 86% rename from code/linux/include/net/ninet_connection_sock.h rename to src/linux/include/net/ninet_connection_sock.h index 1c13485ba677aa39ef6de86f180eaedb6599f8fc..31dc6066df8a1eff5408983ae0993fc0f22ecb52 100644 --- a/code/linux/include/net/ninet_connection_sock.h +++ b/src/linux/include/net/ninet_connection_sock.h @@ -20,8 +20,6 @@ struct sk_buff; struct sock; struct sockaddr; -int ninet_csk_bind_conflict(const struct sock *sk, - const struct inet_bind_bucket *tb, bool relax); int ninet_csk_xmit(struct sock *sk, struct sk_buff *skb, struct flowi *fl); void ninet_csk_reqsk_queue_hash_add(struct sock *sk, struct request_sock *req, unsigned long timeout); diff --git a/code/linux/include/net/ninet_hashtables.h b/src/linux/include/net/ninet_hashtables.h similarity index 100% rename from code/linux/include/net/ninet_hashtables.h rename to src/linux/include/net/ninet_hashtables.h diff --git a/code/linux/include/net/nip.h b/src/linux/include/net/nip.h similarity index 83% rename from code/linux/include/net/nip.h rename to src/linux/include/net/nip.h index ecc146971f5a9e7534cee7e5f9adb873a28e0d2e..b51ce6f7089d5b49173e236519905ddff7443f76 100644 --- a/code/linux/include/net/nip.h +++ b/src/linux/include/net/nip.h @@ -47,14 +47,6 @@ struct ninet_protocol { #define NIPCB(skb) ((struct ninet_skb_parm *)&(TCP_SKB_CB(skb)->header.hnip)) extern const struct ninet_protocol __rcu *ninet_protos[MAX_INET_PROTOS]; - -int ninet_add_protocol(const struct ninet_protocol *prot, - unsigned char protocol); -int ninet_del_protocol(const struct ninet_protocol *prot, - unsigned char protocol); -int ninet_register_protosw(struct inet_protosw *p); -void ninet_unregister_protosw(struct inet_protosw *p); - extern const struct proto_ops ninet_dgram_ops; extern const struct proto_ops ninet_stream_ops; extern struct neigh_table nnd_tbl; @@ -90,15 +82,10 @@ static inline u32 nip_addr_hash(const struct nip_addr *a) int nip_send_skb(struct sk_buff *skb); void ninet_destroy_sock(struct sock *sk); -int nip_datagram_connect(struct sock *sk, struct sockaddr *addr, int addr_len); -int nip_datagram_connect_v6_only(struct sock *sk, struct sockaddr *addr, - int addr_len); +int nip_datagram_connect_v6_only(struct sock *sk, struct sockaddr *addr, int addr_len); int nip_datagram_dst_update(struct sock *sk, bool fix_sk_saddr); -void nip_datagram_release_cb(struct sock *sk); -int ninet_add_protocol(const struct ninet_protocol *prot, - unsigned char protocol); -int ninet_eld_protocol(const struct ninet_protocol *prot, - unsigned char protocol); +int ninet_add_protocol(const struct ninet_protocol *prot, unsigned char protocol); +int ninet_del_protocol(const struct ninet_protocol *prot, unsigned char protocol); int ninet_register_protosw(struct inet_protosw *p); void ninet_unregister_protosw(struct inet_protosw *p); int nip_input(struct sk_buff *skb); @@ -132,12 +119,6 @@ int nip_getsockopt(struct sock *sk, int level, /* functions defined in nip_addrconf.c */ int nip_addrconf_get_ifaddr(struct net *net, unsigned int cmd, void __user *arg); -bool nip_rcv_saddr_equal(const struct nip_addr *sk1_rcv_saddr, - const struct nip_addr *sk2_rcv_saddr, - bool sk2_isnewip, - bool match_sk1_wildcard, - bool match_sk2_wildcard); - void nip_dbg(const char *fmt, ...); #define DEBUG(format, ...) nip_dbg(format, ##__VA_ARGS__) diff --git a/code/linux/include/net/nip_addrconf.h b/src/linux/include/net/nip_addrconf.h similarity index 100% rename from code/linux/include/net/nip_addrconf.h rename to src/linux/include/net/nip_addrconf.h diff --git a/code/linux/include/net/nip_fib.h b/src/linux/include/net/nip_fib.h similarity index 100% rename from code/linux/include/net/nip_fib.h rename to src/linux/include/net/nip_fib.h diff --git a/code/linux/include/net/nip_route.h b/src/linux/include/net/nip_route.h similarity index 100% rename from code/linux/include/net/nip_route.h rename to src/linux/include/net/nip_route.h diff --git a/code/linux/include/net/nip_udp.h b/src/linux/include/net/nip_udp.h similarity index 100% rename from code/linux/include/net/nip_udp.h rename to src/linux/include/net/nip_udp.h diff --git a/code/linux/include/net/nndisc.h b/src/linux/include/net/nndisc.h similarity index 100% rename from code/linux/include/net/nndisc.h rename to src/linux/include/net/nndisc.h diff --git a/code/linux/include/net/tcp_nip.h b/src/linux/include/net/tcp_nip.h similarity index 100% rename from code/linux/include/net/tcp_nip.h rename to src/linux/include/net/tcp_nip.h diff --git a/code/linux/include/net/transp_nip.h b/src/linux/include/net/transp_nip.h similarity index 73% rename from code/linux/include/net/transp_nip.h rename to src/linux/include/net/transp_nip.h index 2688e55f5f7799e5ed816cb117e878f247985961..35fe52c298aa33a1567bd8f121c322bc41234ab2 100644 --- a/code/linux/include/net/transp_nip.h +++ b/src/linux/include/net/transp_nip.h @@ -26,11 +26,4 @@ void nip_dgram_sock_seq_show(struct seq_file *seq, struct sock *sp, __u16 srcp, void ninet_destroy_sock(struct sock *sk); -#define NEWIP_SEQ_DGRAM_HEADER \ - " s1 " \ - "local_address " \ - "remote_address " \ - "st tx_queue rc_queue tr tm->when retrnsmt" \ - " uid timeout inode ref pointer drops\n" - #endif diff --git a/code/linux/include/trace/hooks/nip_hooks.h b/src/linux/include/trace/hooks/nip_hooks.h similarity index 100% rename from code/linux/include/trace/hooks/nip_hooks.h rename to src/linux/include/trace/hooks/nip_hooks.h diff --git a/code/linux/include/uapi/linux/newip_route.h b/src/linux/include/uapi/linux/newip_route.h similarity index 100% rename from code/linux/include/uapi/linux/newip_route.h rename to src/linux/include/uapi/linux/newip_route.h diff --git a/code/linux/include/uapi/linux/nip.h b/src/linux/include/uapi/linux/nip.h similarity index 100% rename from code/linux/include/uapi/linux/nip.h rename to src/linux/include/uapi/linux/nip.h diff --git a/code/linux/include/uapi/linux/nip_icmp.h b/src/linux/include/uapi/linux/nip_icmp.h similarity index 100% rename from code/linux/include/uapi/linux/nip_icmp.h rename to src/linux/include/uapi/linux/nip_icmp.h diff --git a/code/linux/net/newip/Kconfig b/src/linux/net/newip/Kconfig similarity index 100% rename from code/linux/net/newip/Kconfig rename to src/linux/net/newip/Kconfig diff --git a/code/linux/net/newip/Makefile b/src/linux/net/newip/Makefile similarity index 70% rename from code/linux/net/newip/Makefile rename to src/linux/net/newip/Makefile index 5cf03070cc2e4f393adc8a742a8f4e312769341d..18ae012ac936b38eca2ed0af4cea3386391e16d9 100644 --- a/code/linux/net/newip/Makefile +++ b/src/linux/net/newip/Makefile @@ -7,7 +7,7 @@ obj-$(CONFIG_NEWIP) += newip.o -newip-objs := nip_addr.o nip_hdr_encap.o nip_hdr_decap.o nip_checksum.o af_ninet.o nip_input.o udp.o protocol.o nip_output.o datagram.o nip_addrconf.o nip_addrconf_core.o route.o nip_fib.o nip_fib_rules.o nndisc.o icmp.o tcp_nip_parameter.o +newip-objs := nip_addr.o nip_hdr_encap.o nip_hdr_decap.o nip_checksum.o af_ninet.o nip_input.o udp.o protocol.o nip_output.o nip_addrconf.o nip_addrconf_core.o route.o nip_fib.o nip_fib_rules.o nndisc.o icmp.o tcp_nip_parameter.o newip-objs += tcp_nip.o ninet_connection_sock.o ninet_hashtables.o tcp_nip_output.o tcp_nip_input.o tcp_nip_timer.o nip_sockglue.o ifeq ($(CONFIG_NEWIP_HOOKS), y) diff --git a/code/linux/net/newip/af_ninet.c b/src/linux/net/newip/af_ninet.c similarity index 98% rename from code/linux/net/newip/af_ninet.c rename to src/linux/net/newip/af_ninet.c index 3d8dbddc3fa62ff69f081499d777c5e9b8872f1b..867f4d2e010098fe13e3b3da9f2803058ba4696e 100644 --- a/code/linux/net/newip/af_ninet.c +++ b/src/linux/net/newip/af_ninet.c @@ -7,6 +7,8 @@ * * Based on linux/net/ipv6/af_inet6.c */ +#define pr_fmt(fmt) "NIP AF-NIET: " fmt + #include #include #include @@ -61,8 +63,7 @@ atomic_t g_nip_socket_number = ATOMIC_INIT(0); static int disable_nip_mod; module_param_named(disable, disable_nip_mod, int, 0444); -MODULE_PARM_DESC(disable, - "Disable NewIP module such that it is non_functional"); +MODULE_PARM_DESC(disable, "Disable NewIP module such that it is non_functional"); bool newip_mod_enabled(void) { @@ -667,9 +668,8 @@ static int __init ninet_init(void) for (r = &inetsw_nip[0]; r < &inetsw_nip[SOCK_MAX]; ++r) INIT_LIST_HEAD(r); - if (disable_nip_mod) { - DEBUG("Loaded, but adminstratively disabled,"); - DEBUG("reboot required to enable"); + if (!newip_mod_enabled()) { + DEBUG("Loaded, but administratively disabled, reboot required to enable"); goto out; } @@ -748,8 +748,10 @@ out: return err; nip_packet_fail: -udp_fail: + tcp_nip_exit(); tcp_fail: + nip_udp_exit(); +udp_fail: nip_addrconf_cleanup(); nip_addr_fail: nip_route_cleanup(); diff --git a/code/linux/net/newip/hooks/Kconfig b/src/linux/net/newip/hooks/Kconfig similarity index 100% rename from code/linux/net/newip/hooks/Kconfig rename to src/linux/net/newip/hooks/Kconfig diff --git a/code/linux/net/newip/hooks/Makefile b/src/linux/net/newip/hooks/Makefile similarity index 100% rename from code/linux/net/newip/hooks/Makefile rename to src/linux/net/newip/hooks/Makefile diff --git a/code/linux/net/newip/hooks/nip_hooks.c b/src/linux/net/newip/hooks/nip_hooks.c similarity index 100% rename from code/linux/net/newip/hooks/nip_hooks.c rename to src/linux/net/newip/hooks/nip_hooks.c diff --git a/code/linux/net/newip/icmp.c b/src/linux/net/newip/icmp.c similarity index 88% rename from code/linux/net/newip/icmp.c rename to src/linux/net/newip/icmp.c index 11c3ff7089c044a796af8d7e9aabc2cd3af1690d..c376a0e56c1bf8d3a2b382bd2947a3fb58676dcb 100644 --- a/code/linux/net/newip/icmp.c +++ b/src/linux/net/newip/icmp.c @@ -46,16 +46,8 @@ int nip_icmp_rcv(struct sk_buff *skb) return ret; } -static void nip_icmp_err(struct sk_buff *skb, - struct ninet_skb_parm *opt, - u8 type, uint8_t code, - int offset, __be32 info) -{ -} - static const struct ninet_protocol nip_icmp_protocol = { .handler = nip_icmp_rcv, - .err_handler = nip_icmp_err, .flags = 0, }; diff --git a/code/linux/net/newip/ninet_connection_sock.c b/src/linux/net/newip/ninet_connection_sock.c similarity index 89% rename from code/linux/net/newip/ninet_connection_sock.c rename to src/linux/net/newip/ninet_connection_sock.c index cfff906187f1180d4f2dda118c6d09a8571a7a45..7d92e4faee22621d1aa523af7d82111c635db2a9 100644 --- a/code/linux/net/newip/ninet_connection_sock.c +++ b/src/linux/net/newip/ninet_connection_sock.c @@ -88,15 +88,3 @@ void ninet_csk_reqsk_queue_hash_add(struct sock *sk, struct request_sock *req, inet_csk_reqsk_queue_added(sk); } -/* Function - * Check whether the socket conflicts with the linked list. If no, 0 is returned - * Parameter - * sk: The transport control block to listen - * tb: bind bucket, sock list for storing bind - */ -int ninet_csk_bind_conflict(const struct sock *sk, - const struct inet_bind_bucket *tb, bool relax) -{ - return 0; -} - diff --git a/code/linux/net/newip/ninet_hashtables.c b/src/linux/net/newip/ninet_hashtables.c similarity index 100% rename from code/linux/net/newip/ninet_hashtables.c rename to src/linux/net/newip/ninet_hashtables.c diff --git a/code/linux/net/newip/nip_addrconf.c b/src/linux/net/newip/nip_addrconf.c similarity index 93% rename from code/linux/net/newip/nip_addrconf.c rename to src/linux/net/newip/nip_addrconf.c index db671bff79bdfd14461bc5bfa0e72219f7434d6f..e1ee256b2e0935f7f349951bbddc4dc934047b64 100644 --- a/code/linux/net/newip/nip_addrconf.c +++ b/src/linux/net/newip/nip_addrconf.c @@ -58,28 +58,6 @@ static struct nip_devconf newip_devconf_dflt __read_mostly = { .ignore_routes_with_linkdown = 0, }; -/* only match New IP sock - * match_sk*_wildcard == true: NIP_ADDR_ANY equals to any New IP addresses - * - * match_sk*_wildcard == false: addresses must be exactly the same, i.e. - * NIP_ADDR_ANY only equals to NIP_ADDR_ANY - */ -bool nip_rcv_saddr_equal(const struct nip_addr *sk1_rcv_saddr, - const struct nip_addr *sk2_rcv_saddr, - bool sk2_isnewip, - bool match_sk1_wildcard, - bool match_sk2_wildcard) -{ - if (!sk2_isnewip) - return false; - if (nip_addr_eq(sk1_rcv_saddr, sk2_rcv_saddr)) - return true; - return (match_sk1_wildcard && - nip_addr_eq(sk1_rcv_saddr, &nip_any_addr)) || - (match_sk2_wildcard && - nip_addr_eq(sk2_rcv_saddr, &nip_any_addr)); -} - /* Check if link is ready: is it up and is a valid qdisc available */ static inline bool nip_addrconf_link_ready(const struct net_device *dev) { @@ -484,37 +462,6 @@ static bool nip_chk_same_addr(struct net *net, const struct nip_addr *addr, return false; } -int __nip_get_lladdr(struct ninet_dev *idev, struct nip_addr *addr, u32 banned_flags) -{ - struct ninet_ifaddr *ifp; - int err = -EADDRNOTAVAIL; - - list_for_each_entry_reverse(ifp, &idev->addr_list, if_list) { - if (!(ifp->flags & banned_flags)) { - *addr = ifp->addr; - err = 0; - break; - } - } - return err; -} - -int nip_get_lladdr(struct net_device *dev, struct nip_addr *addr, u32 banned_flags) -{ - struct ninet_dev *idev; - int err = -EADDRNOTAVAIL; - - rcu_read_lock(); - idev = __nin_dev_get(dev); - if (idev) { - read_lock_bh(&idev->lock); - err = __nip_get_lladdr(idev, addr, banned_flags); - read_unlock_bh(&idev->lock); - } - rcu_read_unlock(); - return err; -} - static int __nip_get_firstaddr(struct ninet_dev *idev, struct nip_addr *addr) { struct ninet_ifaddr *ifp; diff --git a/code/linux/net/newip/nip_addrconf_core.c b/src/linux/net/newip/nip_addrconf_core.c similarity index 82% rename from code/linux/net/newip/nip_addrconf_core.c rename to src/linux/net/newip/nip_addrconf_core.c index 12d104dde28a2b834dca8c9c66a150fdef00047e..34e9867470a8228995ef09ef9efc5ad25878dfea 100644 --- a/code/linux/net/newip/nip_addrconf_core.c +++ b/src/linux/net/newip/nip_addrconf_core.c @@ -26,10 +26,7 @@ void nin_dev_finish_destroy(struct ninet_dev *idev) WARN_ON(!list_empty(&idev->addr_list)); dev_put(dev); - if (!idev->dead) { - DEBUG(KERN_WARNING "Freeing alive ninet device.\n"); - return; - } - call_rcu(&idev->rcu, nin_dev_finish_destroy_rcu); + if (idev->dead) + call_rcu(&idev->rcu, nin_dev_finish_destroy_rcu); } diff --git a/code/linux/net/newip/nip_fib.c b/src/linux/net/newip/nip_fib.c similarity index 100% rename from code/linux/net/newip/nip_fib.c rename to src/linux/net/newip/nip_fib.c diff --git a/code/linux/net/newip/nip_fib_rules.c b/src/linux/net/newip/nip_fib_rules.c similarity index 100% rename from code/linux/net/newip/nip_fib_rules.c rename to src/linux/net/newip/nip_fib_rules.c diff --git a/code/linux/net/newip/nip_hooks_register.c b/src/linux/net/newip/nip_hooks_register.c similarity index 100% rename from code/linux/net/newip/nip_hooks_register.c rename to src/linux/net/newip/nip_hooks_register.c diff --git a/code/linux/net/newip/nip_hooks_register.h b/src/linux/net/newip/nip_hooks_register.h similarity index 100% rename from code/linux/net/newip/nip_hooks_register.h rename to src/linux/net/newip/nip_hooks_register.h diff --git a/code/linux/net/newip/nip_input.c b/src/linux/net/newip/nip_input.c similarity index 100% rename from code/linux/net/newip/nip_input.c rename to src/linux/net/newip/nip_input.c diff --git a/code/linux/net/newip/nip_output.c b/src/linux/net/newip/nip_output.c similarity index 100% rename from code/linux/net/newip/nip_output.c rename to src/linux/net/newip/nip_output.c diff --git a/code/linux/net/newip/nip_sockglue.c b/src/linux/net/newip/nip_sockglue.c similarity index 100% rename from code/linux/net/newip/nip_sockglue.c rename to src/linux/net/newip/nip_sockglue.c diff --git a/code/linux/net/newip/nndisc.c b/src/linux/net/newip/nndisc.c similarity index 100% rename from code/linux/net/newip/nndisc.c rename to src/linux/net/newip/nndisc.c diff --git a/code/linux/net/newip/protocol.c b/src/linux/net/newip/protocol.c similarity index 100% rename from code/linux/net/newip/protocol.c rename to src/linux/net/newip/protocol.c diff --git a/code/linux/net/newip/route.c b/src/linux/net/newip/route.c similarity index 100% rename from code/linux/net/newip/route.c rename to src/linux/net/newip/route.c diff --git a/code/linux/net/newip/tcp_nip.c b/src/linux/net/newip/tcp_nip.c similarity index 100% rename from code/linux/net/newip/tcp_nip.c rename to src/linux/net/newip/tcp_nip.c diff --git a/code/linux/net/newip/tcp_nip_input.c b/src/linux/net/newip/tcp_nip_input.c similarity index 100% rename from code/linux/net/newip/tcp_nip_input.c rename to src/linux/net/newip/tcp_nip_input.c diff --git a/code/linux/net/newip/tcp_nip_output.c b/src/linux/net/newip/tcp_nip_output.c similarity index 96% rename from code/linux/net/newip/tcp_nip_output.c rename to src/linux/net/newip/tcp_nip_output.c index d3fe24dc07a238743ef2167d5a1f4a8b43f4d3e1..045f29010a6b0fa07f33d874760be4e613c843ef 100644 --- a/code/linux/net/newip/tcp_nip_output.c +++ b/src/linux/net/newip/tcp_nip_output.c @@ -92,27 +92,6 @@ int tcp_nip_mtu_to_mss(struct sock *sk, int pmtu) (tcp_sk(sk)->tcp_header_len - sizeof(struct tcphdr)); } -/* Inverse of above */ -int tcp_nip_mss_to_mtu(struct sock *sk, int mss) -{ - const struct tcp_sock *tp = tcp_sk(sk); - const struct inet_connection_sock *icsk = inet_csk(sk); - int mtu; - int nip_hdr_len = get_nip_hdr_len(NIP_HDR_COMM, &sk->sk_nip_rcv_saddr, &sk->sk_nip_daddr); - - nip_hdr_len = nip_hdr_len == 0 ? NIP_HDR_MAX : nip_hdr_len; - mtu = mss + tp->tcp_header_len + icsk->icsk_ext_hdr_len + nip_hdr_len; - - /* IPv6 adds a frag_hdr in case RTAX_FEATURE_ALLFRAG is set */ - if (icsk->icsk_af_ops->net_frag_header_len) { - const struct dst_entry *dst = __sk_dst_get(sk); - - if (dst && dst_allfrag(dst)) - mtu += icsk->icsk_af_ops->net_frag_header_len; - } - return mtu; -} - static inline void tcp_advance_send_head(struct sock *sk, const struct sk_buff *skb) { if (tcp_skb_is_last(sk, skb)) @@ -197,22 +176,6 @@ u32 __nip_tcp_select_window(struct sock *sk) DEBUG("%s wscale(%u) win change [%u to %u], [allowed|free]space=[%u, %u], mss=%u", __func__, tp->rx_opt.rcv_wscale, free_space, window, allowed_space, free_space, mss); - } else { - window = tp->rcv_wnd; - /* Get the largest window that is a nice multiple of mss. - * Window clamp already applied above. - * If our current window offering is within 1 mss of the - * free space we just keep it. This prevents the divide - * and multiply from happening most of the time. - * We also don't do any window rounding when the free space - * is too small. - */ - if (window <= free_space - mss || window > free_space) - window = rounddown(free_space, mss); - else if (mss == full_space && - free_space > window + (full_space >> 1)) - window = free_space; - DEBUG("%s win change [%u to %u]", __func__, tp->rcv_wnd, window); } return window; } diff --git a/code/linux/net/newip/tcp_nip_parameter.c b/src/linux/net/newip/tcp_nip_parameter.c similarity index 100% rename from code/linux/net/newip/tcp_nip_parameter.c rename to src/linux/net/newip/tcp_nip_parameter.c diff --git a/code/linux/net/newip/tcp_nip_parameter.h b/src/linux/net/newip/tcp_nip_parameter.h similarity index 100% rename from code/linux/net/newip/tcp_nip_parameter.h rename to src/linux/net/newip/tcp_nip_parameter.h diff --git a/code/linux/net/newip/tcp_nip_timer.c b/src/linux/net/newip/tcp_nip_timer.c similarity index 100% rename from code/linux/net/newip/tcp_nip_timer.c rename to src/linux/net/newip/tcp_nip_timer.c diff --git a/code/linux/net/newip/udp.c b/src/linux/net/newip/udp.c similarity index 98% rename from code/linux/net/newip/udp.c rename to src/linux/net/newip/udp.c index abfcca62538ddd74807f425631de0dca3301c605..c36b6a168ff2199456354cd5211bb52466ea2de3 100644 --- a/code/linux/net/newip/udp.c +++ b/src/linux/net/newip/udp.c @@ -430,25 +430,11 @@ static const struct ninet_protocol nip_udp_protocol = { .flags = 0, }; -int udp_stub_hash(struct sock *sk) -{ - return 0; -} - -void udp_stub_unhash(struct sock *sk) -{ -} - -void udp_stub_rehash(struct sock *sk) -{ -} - /* Newip Udp related operations */ struct proto nip_udp_prot = { .name = "nip_udp", .owner = THIS_MODULE, .close = udp_lib_close, - .connect = nip_datagram_connect, .disconnect = udp_disconnect, .ioctl = udp_ioctl, .init = udp_init_sock, @@ -458,10 +444,8 @@ struct proto nip_udp_prot = { .sendmsg = nip_udp_output, .recvmsg = nip_udp_recvmsg, .backlog_rcv = __nip_udp_queue_rcv_skb, - .release_cb = nip_datagram_release_cb, .hash = udp_lib_hash, .unhash = udp_lib_unhash, - .rehash = udp_stub_rehash, .get_port = nip_udp_get_port, .memory_allocated = &udp_memory_allocated, .sysctl_mem = sysctl_udp_mem, diff --git a/tools/wireshark_cfg_for_newip.lua b/tools/wireshark_cfg_for_newip.lua new file mode 100644 index 0000000000000000000000000000000000000000..47a9602c21690be40963e02116b9e8cbfccec928 --- /dev/null +++ b/tools/wireshark_cfg_for_newip.lua @@ -0,0 +1,313 @@ +require "bit32" +--[[ +SPDX-License-Identifier: GPL-2.0-or-later +Copyright (c) 2022 Huawei Device Co., Ltd. +Function : wireshark lua configure for NewIP protocol stack +Author : yangyanjun +Edit Date : 2022/5/27 +--]] + +do -- lua begin + +--协议名称为NewIP,在Packet Details窗格显示为NewIP +-- create a new protocol +local nip_proto_name = "NewIP" +local nip_proto_desc = "NewIP Protocol" +local nip_proto_obj = Proto(nip_proto_name, nip_proto_desc) + +--[[ +NewIP协议字段定义 + ProtoField 参数: + para1 [必选] - 字段的缩写名称(过滤器中使用的字符串) + para2 [可选] - 字段的实际名称(出现在树中的字符串) + para3 [可选] - 字段类型 +--]] +local _ttl = ProtoField.uint8 (nip_proto_name .. ".ttl", "ttl", base.DEC) +local _total_len = ProtoField.uint16(nip_proto_name .. ".total_len", "total_len", base.DEC) +local _nexthdr = ProtoField.uint8 (nip_proto_name .. ".nexthdr", "nexthdr", base.DEC) +local _daddr = ProtoField.bytes (nip_proto_name .. ".daddr", "daddr", base.SPACE) +local _saddr = ProtoField.bytes (nip_proto_name .. ".saddr", "saddr", base.SPACE) +local _hdr_len = ProtoField.uint8 (nip_proto_name .. ".hdr_len", "hdr_len", base.DEC) +local _trans_data = ProtoField.bytes (nip_proto_name .. ".trans_data", "trans_data", base.SPACE) + +-- 将字段添加都协议中 +nip_proto_obj.fields = { + _ttl, + _total_len, + _nexthdr, + _daddr, + _saddr, + _hdr_len, + _trans_data +} +--获取 _trans_data 解析器 +local _unknown_data_dis = Dissector.get("data") + +--定义 bitmap1 子菜单 +-- create a new protocol +local bitmap1_name = "bitmap1" +local bitmap1_desc = "bitmap1" +local bitmap1_obj = Proto(bitmap1_name, bitmap1_desc) + +--[[ +bitmap1 子菜单字段定义 + ProtoField 参数: + para1 [必选] - 字段的缩写名称(过滤器中使用的字符串) + para2 [可选] - 字段的实际名称(出现在树中的字符串) + para3 [可选] - 字段类型 +--]] +local _bitmap1 = ProtoField.uint8(bitmap1_name .. ".bitmap1", "bitmap1", base.HEX) +local _nip_valid = ProtoField.uint8(bitmap1_name .. ".nip_valid", "nip_valid", base.DEC) +local _include_ttl = ProtoField.uint8(bitmap1_name .. ".include_ttl", "include_ttl", base.DEC) +local _include_total_len = ProtoField.uint8(bitmap1_name .. ".include_total_len", "include_total_len", base.DEC) +local _include_nexthdr = ProtoField.uint8(bitmap1_name .. ".include_nexthdr", "include_nexthdr", base.DEC) +local _include_daddr = ProtoField.uint8(bitmap1_name .. ".include_daddr", "include_daddr", base.DEC) +local _include_saddr = ProtoField.uint8(bitmap1_name .. ".include_saddr", "include_saddr", base.DEC) +local _include_bitmap2 = ProtoField.uint8(bitmap1_name .. ".include_bitmap2", "include_bitmap2", base.DEC) + +-- 将字段添加都协议中 +bitmap1_obj.fields = { + _bitmap1, _nip_valid, _include_ttl, _include_total_len, _include_nexthdr, _include_daddr, _include_saddr, _include_bitmap2 +} + +--定义 bitmap2 子菜单 +-- create a new protocol +local bitmap2_name = "bitmap2" +local bitmap2_desc = "bitmap2" +local bitmap2_obj = Proto(bitmap2_name, bitmap2_desc) + +--[[ +bitmap2 子菜单字段定义 + ProtoField 参数: + para1 [必选] - 字段的缩写名称(过滤器中使用的字符串) + para2 [可选] - 字段的实际名称(出现在树中的字符串) + para3 [可选] - 字段类型 +--]] +local _bitmap2 = ProtoField.uint8(bitmap2_name .. ".bitmap2", "bitmap2", base.HEX) +local _include_hdr_len = ProtoField.uint8(bitmap2_name .. ".include_hdr_len", "include_hdr_len", base.DEC) + +-- 将字段添加都协议中 +bitmap2_obj.fields = { + _bitmap2, _include_hdr_len +} + +--定义 nd icmp 子菜单 +-- create a new protocol +local nd_icmp_name = "nd_icmp" +local nd_icmp_desc = "nd_icmp" +local nd_icmp_obj = Proto(nd_icmp_name, nd_icmp_desc) + +--[[ +nd_icmp 子菜单字段定义 + ProtoField 参数: + para1 [必选] - 字段的缩写名称(过滤器中使用的字符串) + para2 [可选] - 字段的实际名称(出现在树中的字符串) + para3 [可选] - 字段类型 +--]] +local _type = ProtoField.uint8 (nd_icmp_name .. ".type", "type", base.DEC) +local _code = ProtoField.uint8 (nd_icmp_name .. ".code", "code", base.DEC) +local _checksum = ProtoField.uint16(nd_icmp_name .. ".checksum", "checksum", base.HEX) +local _rs_daddr = ProtoField.bytes (nd_icmp_name .. ".rs_daddr", "rs_daddr", base.SPACE) +local _mac_len = ProtoField.uint8 (nd_icmp_name .. ".mac_len", "mac_len", base.DEC) +local _mac = ProtoField.bytes (nd_icmp_name .. ".mac", "mac", base.SPACE) + +-- 将字段添加都协议中 +nd_icmp_obj.fields = { + _type, _code, _checksum, _rs_daddr, _mac_len, _mac +} + +--[[ + 下面定义 newip 解析器的主函数 + 第一个参数是 tvb 类型,表示的是需要此解析器解析的数据 + 第二个参数是 pinfo 类型,是协议解析树上的信息,包括 UI 上的显示 + 第三个参数是 treeitem 类型,表示上一级解析树 +--]] +function nip_dissector(tvb, pinfo, treeitem) + --设置一些 UI 上面的信息 + pinfo.cols.protocol:set(nip_proto_name) + pinfo.cols.info:set(nip_proto_desc) + + local offset = 0 + local tvb_len = tvb:len() + local nexthdr = 0 + + -- 在上一级解析树上创建 nip 的根节点 + local nip_tree = treeitem:add(nip_proto_obj, tvb:range(tvb_len)) + + local bitmap1 = tvb(offset, 1) --表示从报文缓冲区0开始取1个字节 + local bitmap1_val = tvb(offset, 1):uint() + local nip_valid = bit.band(bit.rshift(bitmap1_val, 7), 0x00000001) --右移 7 位 与 0x01 相与,获取 nip_valid 位 + local include_ttl = bit.band(bit.rshift(bitmap1_val, 6), 0x00000001) --右移 6 位 与 0x01 相与,获取 include_ttl 位 + local include_total_len = bit.band(bit.rshift(bitmap1_val, 5), 0x00000001) --右移 5 位 与 0x01 相与,获取 include_total_len 位 + local include_nexthdr = bit.band(bit.rshift(bitmap1_val, 4), 0x00000001) --右移 4 位 与 0x01 相与,获取 include_nexthdr 位 + local include_daddr = bit.band(bit.rshift(bitmap1_val, 2), 0x00000001) --右移 2 位 与 0x01 相与,获取 include_daddr 位 + local include_saddr = bit.band(bit.rshift(bitmap1_val, 1), 0x00000001) --右移 1 位 与 0x01 相与,获取 include_saddr 位 + local include_bitmap2 = bit.band(bitmap1_val, 0x00000001) --获取 include_bitmap2 位 + offset = offset + 1 --_bitmap1 占用1字节 + + --nip报头无效(0表示有效) + if nip_valid ~= 0 then + return false + else + --bitmap1子菜单 + local bitmap1_tree = nip_tree:add(bitmap1_obj, tvb:range(tvb_len)) + bitmap1_tree:add(_bitmap1, bitmap1) + bitmap1_tree:add(_nip_valid, nip_valid) + + if include_ttl then + bitmap1_tree:add(_include_ttl, include_ttl) + end + + if include_total_len then + bitmap1_tree:add(_include_total_len, include_total_len) + end + + if include_nexthdr then + bitmap1_tree:add(_include_nexthdr, include_nexthdr) + end + + if include_daddr then + bitmap1_tree:add(_include_daddr, include_daddr) + end + + if include_saddr then + bitmap1_tree:add(_include_saddr, include_saddr) + end + + if include_bitmap2 then + bitmap1_tree:add(_include_bitmap2, include_bitmap2) + end + end + + if include_bitmap2 ~= 0 then + --bitmap2子菜单 + local bitmap2_tree = nip_tree:add(bitmap2_obj, tvb:range(tvb_len)) + local bitmap2 = tvb(offset, 1) + local bitmap2_val = tvb(offset, 1):uint() + local include_hdr_len = bit.band(bit.rshift(bitmap2_val, 7), 0x00000001) --右移 7 位 与 0x01 相与,获取 include_hdr_len 位 + offset = offset + 1 --_bitmap2 占用1字节 + + bitmap2_tree:add(_bitmap2, bitmap2) + + if include_hdr_len then + bitmap2_tree:add(_include_hdr_len, include_hdr_len) + end + end + + if include_ttl then + nip_tree:add(_ttl, tvb(offset, 1)) + offset = offset + 1 --_ttl 占用1字节 + end + + if include_total_len then + nip_tree:add(_total_len, tvb(offset, 2)) + offset = offset + 2 --_total_len 占用2字节 + end + + if include_nexthdr then + nexthdr = tvb(offset, 1):uint() + nip_tree:add(_nexthdr, tvb(offset, 1)) + offset = offset + 1 --_nexthdr 占用1字节 + end + + if include_daddr then + local first_addr = tvb(offset, 1):uint() + local addr_len = get_nip_addr_len (first_addr) + if addr_len == 0 then + return false + end + nip_tree:add(_daddr, tvb(offset, addr_len)) + offset = offset + addr_len --_daddr 占用 addr_len 字节 + end + + if include_saddr then + local first_addr = tvb(offset, 1):uint() + local addr_len = get_nip_addr_len (first_addr) + if addr_len == 0 then + return false + end + nip_tree:add(_saddr, tvb(offset, addr_len)) + offset = offset + addr_len --_daddr 占用 addr_len 字节 + end + + if include_hdr_len then + nip_tree:add(_hdr_len, tvb(offset, 1)) + offset = offset + 1 --_hdr_len 占用1字节 + end + + --根据next header 确定上层协议 + local trans_data = tvb(offset, tvb_len - offset) + if (nexthdr == 177) then + local nd_icmp_tree = nip_tree:add(nd_icmp_obj, tvb:range(tvb_len)) + local type = tvb(offset, 1):uint() + nd_icmp_tree:add(_type, tvb(offset, 1)) + offset = offset + 1 + nd_icmp_tree:add(_code, tvb(offset, 1)) + offset = offset + 1 + nd_icmp_tree:add(_checksum, tvb(offset, 1)) + offset = offset + 1 + if type == 1 then + nd_icmp_tree:add(_rs_daddr, tvb(offset, 1)) + offset = offset + 1 + pinfo.cols.protocol = "ND request based NewIP" + else + nd_icmp_tree:add(_mac_len, tvb(offset, 1)) + offset = offset + 1 + nd_icmp_tree:add(_mac, tvb(offset, 6)) + offset = offset + 6 + pinfo.cols.protocol = "ND response based NewIP" + end + elseif (nexthdr == 6) then + Dissector.get("tcp"):call(trans_data:tvb(), pinfo, treeitem) + pinfo.cols.protocol = "TCP based NewIP" + elseif (nexthdr == 17) then + Dissector.get("udp"):call(trans_data:tvb(), pinfo, treeitem) + pinfo.cols.protocol = "UDP based NewIP" + else + nip_tree:add(_trans_data, trans_data) + end +end + +--[[ + 下面定义 NewIP 解析器的主函数,这个函数由 wireshark调用 + 第一个参数是 Tvb 类型,表示的是需要此解析器解析的数据 + 第二个参数是 Pinfo 类型,是协议解析树上的信息,包括 UI 上的显示 + 第三个参数是 TreeItem 类型,表示上一级解析树 +--]] +function nip_proto_obj.dissector(tvb, pinfo, treeitem) + if nip_dissector(tvb, pinfo, treeitem) then + --valid NewIP diagram + else + --不是NewIP协议(其他未知协议)时,直接输出报文数据 + _unknown_data_dis:call(tvb, pinfo, treeitem) + end + +end + + +--向 wireshark 注册协议插件被调用的条件 +local ipn_encap_table = DissectorTable.get("ethertype") +ipn_encap_table:add(0xEADD, nip_proto_obj) + +--NewIP地址长度计算 +function get_nip_addr_len (first_addr) + if first_addr <= 0xDC then + return 1 + elseif first_addr >= 0xDD and first_addr <= 0xF0 then + return 2 + elseif first_addr == 0xF1 then + return 3 + elseif first_addr == 0xF2 then + return 5 + elseif first_addr == 0xF3 then + return 7 + elseif first_addr == 0xFE then + return 8 + elseif first_addr == 0xFF then + return 2 + else + return 0 + end +end + +end -- lua end