From 7c0bdb5f8479e80114f3138e1a1ccca409310c8a Mon Sep 17 00:00:00 2001 From: duxbbo Date: Mon, 25 Jul 2022 03:56:08 +0000 Subject: [PATCH] mv files && add patches for linux 5.10 Signed-off-by: duxbbo --- LICENSE | 2 +- apply_newip.sh | 46 ++ code/common/LICENSE | 29 ++ code/{net/newip => common}/nip_addr.c | 2 +- .../{include/uapi/linux => common}/nip_addr.h | 17 - code/{net/newip => common}/nip_checksum.c | 1 - code/{net/newip => common}/nip_checksum.h | 2 +- code/{net/newip => common}/nip_hdr.h | 32 +- code/{net/newip => common}/nip_hdr_decap.c | 5 +- code/{net/newip => common}/nip_hdr_encap.c | 61 ++- code/include/linux/nip_addr.h | 32 -- code/{ => linux}/include/net/nip_addrconf.h | 1 - code/{ => linux}/net/newip/af_ninet.c | 1 - code/{ => linux}/net/newip/datagram.c | 0 code/{ => linux}/net/newip/nip_addrconf.c | 1 - .../{ => linux}/net/newip/nip_addrconf_core.c | 0 code/{ => linux}/net/newip/tcp_nip.c | 1 - code/{ => linux}/net/newip/tcp_nip_input.c | 16 +- code/{ => linux}/net/newip/tcp_nip_output.c | 61 ++- code/{ => linux}/net/newip/udp.c | 1 - patches/linux-5.10/newip.patch | 486 ++++++++++++++++++ 21 files changed, 707 insertions(+), 90 deletions(-) create mode 100644 apply_newip.sh create mode 100644 code/common/LICENSE rename code/{net/newip => common}/nip_addr.c (99%) rename code/{include/uapi/linux => common}/nip_addr.h (85%) rename code/{net/newip => common}/nip_checksum.c (99%) rename code/{net/newip => common}/nip_checksum.h (98%) rename code/{net/newip => common}/nip_hdr.h (90%) rename code/{net/newip => common}/nip_hdr_decap.c (98%) rename code/{net/newip => common}/nip_hdr_encap.c (77%) delete mode 100644 code/include/linux/nip_addr.h rename code/{ => linux}/include/net/nip_addrconf.h (98%) rename code/{ => linux}/net/newip/af_ninet.c (99%) rename code/{ => linux}/net/newip/datagram.c (100%) rename code/{ => linux}/net/newip/nip_addrconf.c (99%) rename code/{ => linux}/net/newip/nip_addrconf_core.c (100%) rename code/{ => linux}/net/newip/tcp_nip.c (99%) rename code/{ => linux}/net/newip/tcp_nip_input.c (99%) rename code/{ => linux}/net/newip/tcp_nip_output.c (96%) rename code/{ => linux}/net/newip/udp.c (99%) create mode 100644 patches/linux-5.10/newip.patch diff --git a/LICENSE b/LICENSE index 0f69df1..827cfd2 100644 --- a/LICENSE +++ b/LICENSE @@ -20,7 +20,7 @@ Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA Alternatively, -b) The BSD2 License, (https://opensource.org/licenses/BSD-3-Clause) +b) 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: diff --git a/apply_newip.sh b/apply_newip.sh new file mode 100644 index 0000000..d1c564c --- /dev/null +++ b/apply_newip.sh @@ -0,0 +1,46 @@ +#!/bin/bash +# +# Copyright (c) 2022 Huawei Device Co., Ltd. +# +# NewIP is dual licensed: you can use it either under the terms of +# the GPL, or the BSD license, at your option. +# See the LICENSE file in directory / of this repository for complete details. +# + +set -e + +OHOS_SOURCE_ROOT=$1 +KERNEL_BUILD_ROOT=$2 +PRODUCT_NAME=$3 +KERNEL_VERSION=$4 + +PATCH_FILE=$OHOS_SOURCE_ROOT/foundation/communication/sfc/newip/patches/$KERNEL_VERSION/newip.patch +PRODUCT_SWITCH=$OHOS_SOURCE_ROOT/foundation/communication/sfc/newip/patches/$PRODUCT_NAME.flag +function main() +{ + if [ ! -f $PATCH_FILE ]; then + echo "newip not supportted!kernel=$KERNEL_VERSION!" + return; + fi + if [ ! -f $PRODUCT_SWITCH ]; then + echo "newip not supportted!product=$PRODUCT_NAME!" + return; + fi + + + cd $KERNEL_BUILD_ROOT + echo "patch for newip..." + patch -p1 < $PATCH_FILE + + cp -R $OHOS_SOURCE_ROOT/foundation/communication/sfc/newip/code/linux/net/newip net/ + cp -arfL $OHOS_SOURCE_ROOT/foundation/communication/sfc/newip/code/linux/include/* include/ + + cp -arfL $OHOS_SOURCE_ROOT/foundation/communication/sfc/newip/code/common/*.h net/newip/ + cp -arfL $OHOS_SOURCE_ROOT/foundation/communication/sfc/newip/code/common/*.c net/newip/ + ln -s -f $KERNEL_BUILD_ROOT/net/newip/nip_addr.h $KERNEL_BUILD_ROOT/include/uapi/linux/nip_addr.h + ln -s -f $KERNEL_BUILD_ROOT/net/newip/nip_addr.h $KERNEL_BUILD_ROOT/include/linux/nip_addr.h + + cd - +} + +main diff --git a/code/common/LICENSE b/code/common/LICENSE new file mode 100644 index 0000000..d83b446 --- /dev/null +++ b/code/common/LICENSE @@ -0,0 +1,29 @@ +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/net/newip/nip_addr.c b/code/common/nip_addr.c similarity index 99% rename from code/net/newip/nip_addr.c rename to code/common/nip_addr.c index fb41473..fd07814 100644 --- a/code/net/newip/nip_addr.c +++ b/code/common/nip_addr.c @@ -24,7 +24,7 @@ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include +#include "nip_addr.h" /* This is similar to 0.0.0.0 in IPv4. Does not appear as a real address, * just a constant used by the native for special processing diff --git a/code/include/uapi/linux/nip_addr.h b/code/common/nip_addr.h similarity index 85% rename from code/include/uapi/linux/nip_addr.h rename to code/common/nip_addr.h index b58a088..a22411e 100644 --- a/code/include/uapi/linux/nip_addr.h +++ b/code/common/nip_addr.h @@ -97,23 +97,6 @@ struct nip_addr { }; #pragma pack() -#define POD_SOCKADDR_SIZE 10 - -struct sockaddr_nin { - unsigned short sin_family; /* AF_NINET */ - unsigned short sin_port; /* Transport layer port, big-endian */ - struct nip_addr sin_addr; /* NIP address */ - - /* Pad to size of struct sockaddr - * We don't neet to use this field - * Due to the flexible size of nip_addr, we consider the extreme situation: - * the size of nip_addr is 2 bytes, so we need to add 10 bytes to make sure - * it has the same size as struct sockaddr. And it won't have trouble if you - * increase the length of nip_addr. - */ - unsigned char sin_zero[POD_SOCKADDR_SIZE]; -}; - extern const struct nip_addr nip_any_addr; extern const struct nip_addr nip_broadcast_addr_arp; diff --git a/code/net/newip/nip_checksum.c b/code/common/nip_checksum.c similarity index 99% rename from code/net/newip/nip_checksum.c rename to code/common/nip_checksum.c index 437e52b..fdd1d18 100644 --- a/code/net/newip/nip_checksum.c +++ b/code/common/nip_checksum.c @@ -24,7 +24,6 @@ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include #include "nip_hdr.h" #include "nip_checksum.h" diff --git a/code/net/newip/nip_checksum.h b/code/common/nip_checksum.h similarity index 98% rename from code/net/newip/nip_checksum.h rename to code/common/nip_checksum.h index 97a359f..3dd28f4 100644 --- a/code/net/newip/nip_checksum.h +++ b/code/common/nip_checksum.h @@ -27,7 +27,7 @@ #ifndef _NIP_CHECKSUM_H #define _NIP_CHECKSUM_H -#include +#include "nip_addr.h" struct nip_pseudo_header { struct nip_addr saddr; /* Source address, network order.(big end) */ diff --git a/code/net/newip/nip_hdr.h b/code/common/nip_hdr.h similarity index 90% rename from code/net/newip/nip_hdr.h rename to code/common/nip_hdr.h index 1622c5d..3c8ecb3 100644 --- a/code/net/newip/nip_hdr.h +++ b/code/common/nip_hdr.h @@ -27,21 +27,26 @@ #ifndef _NEWIP_HDR_H #define _NEWIP_HDR_H -#include +#include "nip_addr.h" /* Ethernet head 14B, +2B byte alignment, +66 to avoid * HMAC driver SKB space expansion caused by Coredum problem */ +/* This parameter is used only to apply for the length of the packet buffer, + * but not to determine the actual packet header length + */ #define NIP_ETH_HDR_BASE_LEN 14 #define NIP_ETH_HDR_LEN (NIP_ETH_HDR_BASE_LEN + 2 + 66) /* bitmap1 + bitmap2 + TTL + total len + nexthd + daddr + saddr - * 1B 1B 1B 2B 1B 7B 7B = 20B - * NIP_HDR_MAX 可以从50 修改成 20 + * 1B 1B 1B 2B 1B 9B 9B = 24B * V4 TCP 1448 * NIP TCP 1430 + 30 = 1460 */ -#define NIP_HDR_MAX 8 // 50 -> 8 +/* This interface is only used to define the buffer length. + * To calculate the packet header length, use the "get_nip_hdr_len" func + */ +#define NIP_HDR_MAX 24 #define NIP_UDP_HDR_LEN 8 #define NIP_MIN_MTU (NIP_HDR_MAX + NIP_UDP_HDR_LEN) #define NIP_BYTE_ALIGNMENT 2 @@ -99,6 +104,13 @@ #define NIP_ARP_DEFAULT_TTL 64 #define IPPROTO_NIP_ICMP 0xB1 +enum NIP_HDR_TYPE { + NIP_HDR_UDP = 0, + NIP_HDR_COMM = 1, + + NIP_HDR_TYPE_MAX, +}; + enum NIP_HDR_DECAP_ERR { NIP_HDR_BITMAP_INVALID = 1, NIP_HDR_BITMAP_NUM_OUT_RANGE = 2, @@ -195,7 +207,9 @@ struct nip_pkt_seg_info { unsigned int usr_data_len; /* Length of user data read this time */ }; -void nip_calc_pkt_frag_num(unsigned int mtu, unsigned int usr_data_len, +void nip_calc_pkt_frag_num(unsigned int mtu, + unsigned int nip_hdr_len, + unsigned int usr_data_len, struct nip_pkt_seg_info *seg_info); void nip_hdr_udp_encap(struct nip_hdr_encap *head); @@ -209,6 +223,14 @@ void nip_update_total_len(struct nip_hdr_encap *head, unsigned short total_len); /* Note: a function call requires its own byte order conversion.(niph->total_len) */ int nip_hdr_parse(unsigned char *buf, unsigned int buf_len, struct nip_hdr_decap *niph); +/* The length of the packet header is obtained according to the packet type, + * source ADDRESS, and destination address. + * If the packet does not carry the source address or destination address, fill in the blank + */ +int get_nip_hdr_len(enum NIP_HDR_TYPE hdr_type, + const struct nip_addr *saddr, + const struct nip_addr *daddr); + struct udp_hdr { unsigned short sport; unsigned short dport; diff --git a/code/net/newip/nip_hdr_decap.c b/code/common/nip_hdr_decap.c similarity index 98% rename from code/net/newip/nip_hdr_decap.c rename to code/common/nip_hdr_decap.c index bf8743b..10b00c9 100644 --- a/code/net/newip/nip_hdr_decap.c +++ b/code/common/nip_hdr_decap.c @@ -253,15 +253,16 @@ static int nip_hdr_check(struct nip_hdr_decap *niph) * 1.niph->total_len is network order.(big end), need change to host order * 2.niph->saddr/daddr is network order.(big end) */ -int nip_hdr_parse(unsigned char *buf, unsigned int buf_len, struct nip_hdr_decap *niph) +int nip_hdr_parse(unsigned char *rcv_buf, unsigned int buf_len, struct nip_hdr_decap *niph) { int i = 0; int len; int ret; + unsigned char *buf = rcv_buf; unsigned char bitmap[BITMAP_MAX] = {0}; int num = _get_nip_hdr_bitmap(buf, bitmap, BITMAP_MAX); - if (num <= 0) + if (num <= 0 || !rcv_buf) return num; niph->hdr_real_len = num * sizeof(bitmap[0]); diff --git a/code/net/newip/nip_hdr_encap.c b/code/common/nip_hdr_encap.c similarity index 77% rename from code/net/newip/nip_hdr_encap.c rename to code/common/nip_hdr_encap.c index 4a034da..0928eed 100644 --- a/code/net/newip/nip_hdr_encap.c +++ b/code/common/nip_hdr_encap.c @@ -30,10 +30,12 @@ #define FMT_FACTORY_NUM_MAX 1 #define ENCAP_FACTORY_NUM_MAX 1 -void nip_calc_pkt_frag_num(unsigned int mtu, unsigned int usr_data_len, +void nip_calc_pkt_frag_num(unsigned int mtu, + unsigned int nip_hdr_len, + unsigned int usr_data_len, struct nip_pkt_seg_info *seg_info) { - unsigned int mid_usr_pkt_len = (mtu - NIP_HDR_MAX - NIP_UDP_HDR_LEN) & + unsigned int mid_usr_pkt_len = (mtu - nip_hdr_len - NIP_UDP_HDR_LEN) & INTEGER_MULTIPLE_OF_8; unsigned int mid_pkt_num = usr_data_len / mid_usr_pkt_len; unsigned int last_usr_pkt_len = 0; @@ -99,6 +101,8 @@ void nip_update_total_len(struct nip_hdr_encap *head, unsigned short total_len) *head->total_len_pos = total_len; } +#define BITMAP1_OFFSET 1 +#define BITMAP2_OFFSET 2 static inline void _nip_hdr_encap_udp_bitmap(struct nip_hdr_encap *head) { /* bitmap(1B) + ttl(1B) + total_len(2B) + nexthdr(1B) + daddr(xB) + saddr(xB) */ @@ -109,11 +113,11 @@ static inline void _nip_hdr_encap_udp_bitmap(struct nip_hdr_encap *head) if (((head->daddr.bitlen / NIP_ADDR_BIT_LEN_8) + (head->saddr.bitlen / NIP_ADDR_BIT_LEN_8)) % NIP_BYTE_ALIGNMENT != 0) { head->hdr_buf[0] = NIP_UDP_BITMAP_1; - head->hdr_buf_pos = 1; + head->hdr_buf_pos = BITMAP1_OFFSET; } else { head->hdr_buf[0] = NIP_UDP_BITMAP_1_INC_2; head->hdr_buf[1] = NIP_NODATA_BITMAP_2; - head->hdr_buf_pos = 2; + head->hdr_buf_pos = BITMAP2_OFFSET; } } @@ -127,11 +131,11 @@ static inline void _nip_hdr_encap_comm_bitmap(struct nip_hdr_encap *head) if (((head->daddr.bitlen / NIP_ADDR_BIT_LEN_8) + (head->saddr.bitlen / NIP_ADDR_BIT_LEN_8)) % NIP_BYTE_ALIGNMENT != 0) { head->hdr_buf[0] = NIP_NORMAL_BITMAP_1; - head->hdr_buf_pos = 1; + head->hdr_buf_pos = BITMAP1_OFFSET; } else { head->hdr_buf[0] = NIP_NORMAL_BITMAP_1_INC_2; head->hdr_buf[1] = NIP_NODATA_BITMAP_2; - head->hdr_buf_pos = 2; + head->hdr_buf_pos = BITMAP2_OFFSET; } } @@ -173,3 +177,48 @@ void nip_hdr_comm_encap(struct nip_hdr_encap *head) _nip_hdr_saddr_encap(head); } +#if (NEWIP_BYTE_ALIGNMENT_ENABLE == 1) // include bitmap2 +#define NIP_COMM_HDR_LEN_NOINCLUDE_ADDR 6 // include total len +#define NIP_UDP_HDR_LEN_NOINCLUDE_ADDR 4 // not include total len +#else +#define NIP_COMM_HDR_LEN_NOINCLUDE_ADDR 5 // include total len +#define NIP_UDP_HDR_LEN_NOINCLUDE_ADDR 3 // not include total len +#endif +/* bitmap1 + bitmap2 + TTL + total len + nexthd + daddr + saddr + * 1B 1B 1B 2B 1B 7B 7B = 20B + * NIP_HDR_MAX 20 + * V4 TCP 1448 + * NIP TCP 1430 + 30 = 1460 + */ +/* The length of the packet header is obtained according to the packet type, + * source ADDRESS, and destination address. + * If the packet does not carry the source address or destination address, fill in the blank + */ +int get_nip_hdr_len(enum NIP_HDR_TYPE hdr_type, + const struct nip_addr *saddr, + const struct nip_addr *daddr) +{ + int saddr_len = 0; + int daddr_len = 0; + enum NIP_HDR_TYPE base_len = hdr_type == NIP_HDR_UDP ? + NIP_UDP_HDR_LEN_NOINCLUDE_ADDR : + NIP_COMM_HDR_LEN_NOINCLUDE_ADDR; + + if (hdr_type >= NIP_HDR_TYPE_MAX) + return 0; + + if (saddr) { + saddr_len = get_nip_addr_len(saddr); + if (saddr_len == 0) + return 0; + } + + if (daddr) { + daddr_len = get_nip_addr_len(daddr); + if (daddr_len == 0) + return 0; + } + + return base_len + saddr_len + daddr_len; +} + diff --git a/code/include/linux/nip_addr.h b/code/include/linux/nip_addr.h deleted file mode 100644 index c43d217..0000000 --- a/code/include/linux/nip_addr.h +++ /dev/null @@ -1,32 +0,0 @@ -/* SPDX-License-Identifier: BSD-2-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. - * - * 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. - */ -#ifndef _NIP_ADDR_H -#define _NIP_ADDR_H - -#include - -#endif /* _NIP_ADDR_H */ diff --git a/code/include/net/nip_addrconf.h b/code/linux/include/net/nip_addrconf.h similarity index 98% rename from code/include/net/nip_addrconf.h rename to code/linux/include/net/nip_addrconf.h index d38487d..9268601 100644 --- a/code/include/net/nip_addrconf.h +++ b/code/linux/include/net/nip_addrconf.h @@ -10,7 +10,6 @@ #include #include -#include #include #include #include diff --git a/code/net/newip/af_ninet.c b/code/linux/net/newip/af_ninet.c similarity index 99% rename from code/net/newip/af_ninet.c rename to code/linux/net/newip/af_ninet.c index cda24d1..9c52264 100644 --- a/code/net/newip/af_ninet.c +++ b/code/linux/net/newip/af_ninet.c @@ -37,7 +37,6 @@ #include #include #include -#include #include #include diff --git a/code/net/newip/datagram.c b/code/linux/net/newip/datagram.c similarity index 100% rename from code/net/newip/datagram.c rename to code/linux/net/newip/datagram.c diff --git a/code/net/newip/nip_addrconf.c b/code/linux/net/newip/nip_addrconf.c similarity index 99% rename from code/net/newip/nip_addrconf.c rename to code/linux/net/newip/nip_addrconf.c index f8ac0fe..46db1b1 100644 --- a/code/net/newip/nip_addrconf.c +++ b/code/linux/net/newip/nip_addrconf.c @@ -14,7 +14,6 @@ #include #include -#include #include #include #include diff --git a/code/net/newip/nip_addrconf_core.c b/code/linux/net/newip/nip_addrconf_core.c similarity index 100% rename from code/net/newip/nip_addrconf_core.c rename to code/linux/net/newip/nip_addrconf_core.c diff --git a/code/net/newip/tcp_nip.c b/code/linux/net/newip/tcp_nip.c similarity index 99% rename from code/net/newip/tcp_nip.c rename to code/linux/net/newip/tcp_nip.c index 8c27852..669a795 100644 --- a/code/net/newip/tcp_nip.c +++ b/code/linux/net/newip/tcp_nip.c @@ -59,7 +59,6 @@ #include #include #include -#include #include #include #include diff --git a/code/net/newip/tcp_nip_input.c b/code/linux/net/newip/tcp_nip_input.c similarity index 99% rename from code/net/newip/tcp_nip_input.c rename to code/linux/net/newip/tcp_nip_input.c index d37d1d6..c8d1d8f 100644 --- a/code/net/newip/tcp_nip_input.c +++ b/code/linux/net/newip/tcp_nip_input.c @@ -890,7 +890,7 @@ static void tcp_nip_ack_probe(struct sock *sk) #define DUP_ACK 0 #define NOR_ACK 1 #define ACK_DEF 2 -static void tcp_nip_ack_retrans(struct sock *sk, u32 ack, int ack_type) +static void tcp_nip_ack_retrans(struct sock *sk, u32 ack, int ack_type, u32 retrans_num) { int skb_index = 0; struct tcp_sock *tp = tcp_sk(sk); @@ -927,7 +927,7 @@ static void tcp_nip_ack_retrans(struct sock *sk, u32 ack, int ack_type) if (TCP_SKB_CB(skb)->seq != tp->ack_retrans_seq) continue; - if (skb_index < g_ack_retrans_num) { + if (skb_index < retrans_num) { tcp_nip_retransmit_skb(sk, skb, 1); skb_index++; tp->ack_retrans_num++; @@ -945,7 +945,7 @@ static void tcp_nip_ack_retrans(struct sock *sk, u32 ack, int ack_type) #define DUP_ACK_RETRANS_START_NUM 3 #define DIVIDEND_UP 3 #define DIVIDEND_DOWN 5 -static void tcp_nip_dup_ack_retrans(struct sock *sk, u32 ack) +static void tcp_nip_dup_ack_retrans(struct sock *sk, u32 ack, u32 retrans_num) { struct tcp_sock *tp = tcp_sk(sk); @@ -973,12 +973,12 @@ static void tcp_nip_dup_ack_retrans(struct sock *sk, u32 ack) tp->ack_retrans_seq = ack; tp->ack_retrans_num = 0; - tcp_nip_ack_retrans(sk, ack, DUP_ACK); + tcp_nip_ack_retrans(sk, ack, DUP_ACK, retrans_num); } } } -static void tcp_nip_nor_ack_retrans(struct sock *sk, u32 ack) +static void tcp_nip_nor_ack_retrans(struct sock *sk, u32 ack, u32 retrans_num) { struct tcp_sock *tp = tcp_sk(sk); @@ -999,7 +999,7 @@ static void tcp_nip_nor_ack_retrans(struct sock *sk, u32 ack) return; } - tcp_nip_ack_retrans(sk, ack, NOR_ACK); + tcp_nip_ack_retrans(sk, ack, NOR_ACK, retrans_num); } tp->sacked_out = 0; @@ -1110,12 +1110,12 @@ static int tcp_nip_ack(struct sock *sk, const struct sk_buff *skb, int flag) tcp_nip_clean_rtx_queue(sk, &skb_snd_tstamp); tcp_nip_ack_calc_ssthresh(sk, ack, icsk_rto_last, skb_snd_tstamp); - tcp_nip_nor_ack_retrans(sk, ack); + tcp_nip_nor_ack_retrans(sk, ack, g_ack_retrans_num); return 1; } // ack == tp->snd_una - tcp_nip_dup_ack_retrans(sk, ack); + tcp_nip_dup_ack_retrans(sk, ack, g_dup_ack_retrans_num); return 1; } diff --git a/code/net/newip/tcp_nip_output.c b/code/linux/net/newip/tcp_nip_output.c similarity index 96% rename from code/net/newip/tcp_nip_output.c rename to code/linux/net/newip/tcp_nip_output.c index c9030b4..1687722 100644 --- a/code/net/newip/tcp_nip_output.c +++ b/code/linux/net/newip/tcp_nip_output.c @@ -58,9 +58,11 @@ static inline int __tcp_nip_mtu_to_mss(struct sock *sk, int pmtu) const struct tcp_sock *tp = tcp_sk(sk); const struct inet_connection_sock *icsk = inet_csk(sk); int mss_now; + int nip_hdr_len = get_nip_hdr_len(NIP_HDR_COMM, &sk->sk_nip_rcv_saddr, &sk->sk_nip_daddr); /* Calculate base mss without TCP options: It is MMS_S - sizeof(tcphdr) of rfc1122 */ - mss_now = pmtu - NIP_HDR_MAX - sizeof(struct tcphdr); + nip_hdr_len = nip_hdr_len == 0 ? NIP_HDR_MAX : nip_hdr_len; + mss_now = pmtu - nip_hdr_len - sizeof(struct tcphdr); /* IPv6 adds a frag_hdr in case RTAX_FEATURE_ALLFRAG is set */ if (icsk->icsk_af_ops->net_frag_header_len) { @@ -96,11 +98,11 @@ 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; - mtu = mss + - tp->tcp_header_len + - icsk->icsk_ext_hdr_len + - NIP_HDR_MAX; /* 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); @@ -342,6 +344,9 @@ static __u16 tcp_nip_advertise_mss(struct sock *sk) struct tcp_sock *tp = tcp_sk(sk); const struct dst_entry *dst = __sk_dst_get(sk); int mss = tp->advmss; + int nip_hdr_len; + int nip_mss; + u32 mtu; if (dst) { unsigned int metric = dst_metric_advmss(dst); @@ -350,6 +355,17 @@ static __u16 tcp_nip_advertise_mss(struct sock *sk) mss = metric; tp->advmss = mss; } + + mtu = dst_mtu(dst); + 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; + nip_mss = mtu - nip_hdr_len - sizeof(struct tcphdr); + + if (nip_mss > mss) { + mss = nip_mss; + tp->advmss = mss; + } } return (__u16)mss; @@ -699,6 +715,34 @@ static unsigned int tcp_nip_synack_options(struct request_sock *req, return MAX_TCP_OPTION_SPACE - remaining; } +static int get_nip_mss(const struct sock *sk, struct dst_entry *dst, struct request_sock *req) +{ + struct inet_request_sock *ireq = inet_rsk(req); + struct tcp_sock *tp = tcp_sk(sk); + u16 user_mss; + int mss; + int nip_hdr_len; + int nip_mss; + u32 mtu; + + mss = dst_metric_advmss(dst); + user_mss = READ_ONCE(tp->rx_opt.user_mss); + if (user_mss && user_mss < mss) + mss = user_mss; + + mtu = dst_mtu(dst); + nip_hdr_len = get_nip_hdr_len(NIP_HDR_COMM, &ireq->ir_nip_loc_addr, &ireq->ir_nip_rmt_addr); + nip_hdr_len = nip_hdr_len == 0 ? NIP_HDR_MAX : nip_hdr_len; + nip_mss = mtu - nip_hdr_len - sizeof(struct tcphdr); + + if (nip_mss > mss) { + mss = nip_mss; + tp->advmss = mss; + } + + return mss; +} + /* Function * The SYN + ACK segment is constructed based on the current transport control block, * routing information, and request information. @@ -715,13 +759,11 @@ struct sk_buff *tcp_nip_make_synack(const struct sock *sk, struct dst_entry *dst enum tcp_synack_type synack_type) { struct inet_request_sock *ireq = inet_rsk(req); - const struct tcp_sock *tp = tcp_sk(sk); struct tcp_md5sig_key *md5 = NULL; struct tcp_nip_out_options opts; struct sk_buff *skb; int tcp_header_size; struct tcphdr *th; - u16 user_mss; int mss; unsigned short check = 0; @@ -746,10 +788,7 @@ struct sk_buff *tcp_nip_make_synack(const struct sock *sk, struct dst_entry *dst /* set skb priority from sk */ skb->priority = sk->sk_priority; - mss = dst_metric_advmss(dst); - user_mss = READ_ONCE(tp->rx_opt.user_mss); - if (user_mss && user_mss < mss) - mss = user_mss; + mss = get_nip_mss(sk, dst, req); /* Clear the options and set the associated timestamp */ memset(&opts, 0, sizeof(opts)); diff --git a/code/net/newip/udp.c b/code/linux/net/newip/udp.c similarity index 99% rename from code/net/newip/udp.c rename to code/linux/net/newip/udp.c index f8114a1..abfcca6 100644 --- a/code/net/newip/udp.c +++ b/code/linux/net/newip/udp.c @@ -19,7 +19,6 @@ #include #include #include -#include #include #include #include diff --git a/patches/linux-5.10/newip.patch b/patches/linux-5.10/newip.patch new file mode 100644 index 0000000..cc39bc4 --- /dev/null +++ b/patches/linux-5.10/newip.patch @@ -0,0 +1,486 @@ +diff -Naur old/include/linux/netdevice.h new/include/linux/netdevice.h +--- old/include/linux/netdevice.h 2022-07-23 18:52:45.626073631 +0800 ++++ new/include/linux/netdevice.h 2022-07-23 18:52:45.666073630 +0800 +@@ -2016,6 +2016,9 @@ + struct dn_dev __rcu *dn_ptr; + #endif + struct inet6_dev __rcu *ip6_ptr; ++#if IS_ENABLED(CONFIG_NEWIP) ++ struct ninet_dev __rcu *nip_ptr; /* NIP */ ++#endif + #if IS_ENABLED(CONFIG_AX25) + void *ax25_ptr; + #endif +diff -Naur old/include/linux/socket.h new/include/linux/socket.h +--- old/include/linux/socket.h 2022-07-23 18:52:45.636073630 +0800 ++++ new/include/linux/socket.h 2022-07-23 18:52:45.666073630 +0800 +@@ -223,8 +223,8 @@ + * reuses AF_INET address family + */ + #define AF_XDP 44 /* XDP sockets */ +- +-#define AF_MAX 45 /* For now.. */ ++#define AF_NINET 45 /* NIP */ ++#define AF_MAX 46 /* For now.. */ + + /* Protocol families, same as address families. */ + #define PF_UNSPEC AF_UNSPEC +@@ -274,6 +274,7 @@ + #define PF_QIPCRTR AF_QIPCRTR + #define PF_SMC AF_SMC + #define PF_XDP AF_XDP ++#define PF_NINET AF_NINET /* NIP */ + #define PF_MAX AF_MAX + + /* Maximum queue length specifiable by listen. */ +diff -Naur old/include/linux/tcp.h new/include/linux/tcp.h +--- old/include/linux/tcp.h 2022-07-23 18:52:45.636073630 +0800 ++++ new/include/linux/tcp.h 2022-07-23 18:52:45.666073630 +0800 +@@ -317,6 +317,9 @@ + + /* OOO segments go in this rbtree. Socket lock must be held. */ + struct rb_root out_of_order_queue; ++#ifdef CONFIG_NEWIP ++ struct sk_buff *nip_out_of_order_queue; /* NIP */ ++#endif + struct sk_buff *ooo_last_skb; /* cache rb_last(out_of_order_queue) */ + + /* SACKs data, these 2 need to be together (see tcp_options_write) */ +@@ -412,6 +415,17 @@ + */ + struct request_sock __rcu *fastopen_rsk; + struct saved_syn *saved_syn; ++ ++#ifdef CONFIG_NEWIP ++/* newip tcp retrans */ ++ u32 ack_retrans_num; ++ u32 ack_retrans_seq; ++ u32 nip_ssthresh; ++ u32 nip_ssthresh_reset; ++ bool nip_keepalive_enable; ++ u32 idle_ka_probes_out; ++ u32 nip_keepalive_timeout_scale; ++#endif + }; + + enum tsq_enum { +@@ -423,6 +437,10 @@ + TCP_MTU_REDUCED_DEFERRED, /* tcp_v{4|6}_err() could not call + * tcp_v{4|6}_mtu_reduced() + */ ++#ifdef CONFIG_NEWIP ++ TCP_NIP_WRITE_TIMER_DEFERRED, /* NIP */ ++ TCP_NIP_DELACK_TIMER_DEFERRED, /* NIP */ ++#endif + }; + + enum tsq_flags { +diff -Naur old/include/net/dst.h new/include/net/dst.h +--- old/include/net/dst.h 2022-07-23 18:52:45.636073630 +0800 ++++ new/include/net/dst.h 2022-07-23 18:52:45.676073630 +0800 +@@ -35,6 +35,8 @@ + int (*output)(struct net *net, struct sock *sk, struct sk_buff *skb); + + unsigned short flags; ++ ++#define DST_HOST 0x0001 /* NIP */ + #define DST_NOXFRM 0x0002 + #define DST_NOPOLICY 0x0004 + #define DST_NOCOUNT 0x0008 +diff -Naur old/include/net/inet_hashtables.h new/include/net/inet_hashtables.h +--- old/include/net/inet_hashtables.h 2022-07-23 18:52:45.636073630 +0800 ++++ new/include/net/inet_hashtables.h 2022-07-23 18:52:45.676073630 +0800 +@@ -83,6 +83,9 @@ + #if IS_ENABLED(CONFIG_IPV6) + struct in6_addr fast_v6_rcv_saddr; + #endif ++#if IS_ENABLED(CONFIG_NEWIP) ++ struct nip_addr fast_nip_rcv_saddr; ++#endif + __be32 fast_rcv_saddr; + unsigned short fast_sk_family; + bool fast_ipv6_only; +@@ -402,6 +405,13 @@ + const struct in6_addr *laddr, const u16 lport, + const struct in6_addr *faddr, const __be16 fport); + ++#ifdef CONFIG_NEWIP ++/* NIP */ ++u32 ninet_ehashfn(const struct net *net, ++ const struct nip_addr *laddr, const u16 lport, ++ const struct nip_addr *faddr, const __be16 fport); ++#endif ++ + static inline void sk_daddr_set(struct sock *sk, __be32 addr) + { + sk->sk_daddr = addr; /* alias of inet_daddr */ +diff -Naur old/include/net/inet_sock.h new/include/net/inet_sock.h +--- old/include/net/inet_sock.h 2022-07-23 18:52:45.636073630 +0800 ++++ new/include/net/inet_sock.h 2022-07-23 18:52:45.676073630 +0800 +@@ -73,6 +73,10 @@ + #define ir_rmt_port req.__req_common.skc_dport + #define ir_v6_rmt_addr req.__req_common.skc_v6_daddr + #define ir_v6_loc_addr req.__req_common.skc_v6_rcv_saddr ++ ++#define ir_nip_rmt_addr req.__req_common.nip_daddr /* NIP */ ++#define ir_nip_loc_addr req.__req_common.nip_rcv_saddr /* NIP */ ++ + #define ir_iif req.__req_common.skc_bound_dev_if + #define ir_cookie req.__req_common.skc_cookie + #define ireq_net req.__req_common.skc_net +@@ -97,6 +101,12 @@ + struct sk_buff *pktopts; + }; + #endif ++#if IS_ENABLED(CONFIG_NEWIP) ++ /* NIP */ ++ struct { ++ struct sk_buff *nip_pktopts; ++ }; ++#endif + }; + }; + +diff -Naur old/include/net/neighbour.h new/include/net/neighbour.h +--- old/include/net/neighbour.h 2022-07-23 18:52:45.636073630 +0800 ++++ new/include/net/neighbour.h 2022-07-23 18:52:45.676073630 +0800 +@@ -232,6 +232,9 @@ + NEIGH_ARP_TABLE = 0, + NEIGH_ND_TABLE = 1, + NEIGH_DN_TABLE = 2, ++#ifdef CONFIG_NEWIP ++ NEIGH_NND_TABLE = 3, /* NIP */ ++#endif + NEIGH_NR_TABLES, + NEIGH_LINK_TABLE = NEIGH_NR_TABLES /* Pseudo table for neigh_xmit */ + }; +diff -Naur old/include/net/net_namespace.h new/include/net/net_namespace.h +--- old/include/net/net_namespace.h 2022-07-23 18:52:45.636073630 +0800 ++++ new/include/net/net_namespace.h 2022-07-23 18:52:45.676073630 +0800 +@@ -38,6 +38,9 @@ + #include + #include + #include ++#ifdef CONFIG_NEWIP ++#include ++#endif + + struct user_namespace; + struct proc_dir_entry; +@@ -127,6 +130,9 @@ + #if IS_ENABLED(CONFIG_IPV6) + struct netns_ipv6 ipv6; + #endif ++#if IS_ENABLED(CONFIG_NEWIP) ++ struct netns_newip newip; /* NIP */ ++#endif + #if IS_ENABLED(CONFIG_IEEE802154_6LOWPAN) + struct netns_ieee802154_lowpan ieee802154_lowpan; + #endif +diff -Naur old/include/net/secure_seq.h new/include/net/secure_seq.h +--- old/include/net/secure_seq.h 2022-07-23 18:52:45.636073630 +0800 ++++ new/include/net/secure_seq.h 2022-07-23 18:52:45.676073630 +0800 +@@ -19,4 +19,11 @@ + u64 secure_dccpv6_sequence_number(__be32 *saddr, __be32 *daddr, + __be16 sport, __be16 dport); + ++#ifdef CONFIG_NEWIP ++/* NIP */ ++u64 secure_newip_port_ephemeral(const __be32 *saddr, const __be32 *daddr, ++ __be16 dport); ++__u32 secure_tcp_nip_sequence_number(const __be32 *saddr, const __be32 *daddr, ++ __be16 sport, __be16 dport); ++#endif + #endif /* _NET_SECURE_SEQ */ +diff -Naur old/include/net/sock.h new/include/net/sock.h +--- old/include/net/sock.h 2022-07-23 18:52:45.646073630 +0800 ++++ new/include/net/sock.h 2022-07-23 18:52:45.676073630 +0800 +@@ -68,6 +68,9 @@ + #include + #include + #include ++#ifdef CONFIG_NEWIP ++#include ++#endif + + /* + * This structure really needs to be cleaned up. +@@ -202,6 +205,11 @@ + struct in6_addr skc_v6_rcv_saddr; + #endif + ++#if IS_ENABLED(CONFIG_NEWIP) ++ struct nip_addr nip_daddr; /* NIP */ ++ struct nip_addr nip_rcv_saddr; /* NIP */ ++#endif ++ + atomic64_t skc_cookie; + + /* following fields are padding to force +@@ -379,6 +387,8 @@ + #define sk_net __sk_common.skc_net + #define sk_v6_daddr __sk_common.skc_v6_daddr + #define sk_v6_rcv_saddr __sk_common.skc_v6_rcv_saddr ++#define sk_nip_daddr __sk_common.nip_daddr /* NIP */ ++#define sk_nip_rcv_saddr __sk_common.nip_rcv_saddr /* NIP */ + #define sk_cookie __sk_common.skc_cookie + #define sk_incoming_cpu __sk_common.skc_incoming_cpu + #define sk_flags __sk_common.skc_flags +diff -Naur old/include/net/tcp.h new/include/net/tcp.h +--- old/include/net/tcp.h 2022-07-23 18:52:45.646073630 +0800 ++++ new/include/net/tcp.h 2022-07-23 18:52:45.676073630 +0800 +@@ -40,7 +40,9 @@ + #include + #include + #include +- ++#ifdef CONFIG_NEWIP ++#include /* NIP */ ++#endif + #include + #include + #include +@@ -869,6 +871,9 @@ + #if IS_ENABLED(CONFIG_IPV6) + struct inet6_skb_parm h6; + #endif ++#if IS_ENABLED(CONFIG_NEWIP) ++ struct ninet_skb_parm hnip; /* NIP */ ++#endif + } header; /* For incoming skbs */ + struct { + __u32 flags; +diff -Naur old/include/uapi/linux/if_ether.h new/include/uapi/linux/if_ether.h +--- old/include/uapi/linux/if_ether.h 2022-07-23 18:52:45.646073630 +0800 ++++ new/include/uapi/linux/if_ether.h 2022-07-23 18:52:45.676073630 +0800 +@@ -72,6 +72,7 @@ + #define ETH_P_ERSPAN 0x88BE /* ERSPAN type II */ + #define ETH_P_IPX 0x8137 /* IPX over DIX */ + #define ETH_P_IPV6 0x86DD /* IPv6 over bluebook */ ++#define ETH_P_NEWIP 0xEADD /* NIP */ + #define ETH_P_PAUSE 0x8808 /* IEEE Pause frames. See 802.3 31B */ + #define ETH_P_SLOW 0x8809 /* Slow Protocol. See 802.3ad 43B */ + #define ETH_P_WCCP 0x883E /* Web-cache coordination protocol +diff -Naur old/net/Kconfig new/net/Kconfig +--- old/net/Kconfig 2022-07-23 18:52:45.656073630 +0800 ++++ new/net/Kconfig 2022-07-23 18:52:45.676073630 +0800 +@@ -93,6 +93,7 @@ + if INET + source "net/ipv4/Kconfig" + source "net/ipv6/Kconfig" ++source "net/newip/Kconfig" + source "net/netlabel/Kconfig" + source "net/mptcp/Kconfig" + +diff -Naur old/net/Makefile new/net/Makefile +--- old/net/Makefile 2022-07-23 18:52:45.656073630 +0800 ++++ new/net/Makefile 2022-07-23 18:52:45.676073630 +0800 +@@ -20,6 +20,7 @@ + obj-$(CONFIG_XFRM) += xfrm/ + obj-$(CONFIG_UNIX_SCM) += unix/ + obj-$(CONFIG_NET) += ipv6/ ++obj-$(CONFIG_NET) += newip/ + obj-$(CONFIG_BPFILTER) += bpfilter/ + obj-$(CONFIG_PACKET) += packet/ + obj-$(CONFIG_NET_KEY) += key/ +diff -Naur old/net/core/neighbour.c new/net/core/neighbour.c +--- old/net/core/neighbour.c 2022-07-23 18:52:45.646073630 +0800 ++++ new/net/core/neighbour.c 2022-07-23 18:52:45.676073630 +0800 +@@ -1779,6 +1779,11 @@ + case AF_DECnet: + tbl = neigh_tables[NEIGH_DN_TABLE]; + break; ++#ifdef CONFIG_NEWIP ++ case AF_NINET: /* NIP */ ++ tbl = neigh_tables[NEIGH_NND_TABLE]; ++ break; ++#endif + } + + return tbl; +diff -Naur old/net/core/secure_seq.c new/net/core/secure_seq.c +--- old/net/core/secure_seq.c 2022-07-23 18:52:45.646073630 +0800 ++++ new/net/core/secure_seq.c 2022-07-23 18:52:45.676073630 +0800 +@@ -151,6 +151,51 @@ + EXPORT_SYMBOL_GPL(secure_ipv4_port_ephemeral); + #endif + ++#ifdef CONFIG_NEWIP ++/* NIP */ ++__u32 secure_tcp_nip_sequence_number(const __be32 *saddr, const __be32 *daddr, ++ __be16 sport, __be16 dport) ++{ ++ const struct { ++ struct nip_addr saddr; ++ struct nip_addr daddr; ++ __be16 sport; ++ __be16 dport; ++ } __aligned(SIPHASH_ALIGNMENT) combined = { ++ .saddr = *(struct nip_addr *)saddr, ++ .daddr = *(struct nip_addr *)daddr, ++ .sport = sport, ++ .dport = dport, ++ }; ++ u32 hash; ++ ++ net_secret_init(); ++ hash = siphash(&combined, offsetofend(typeof(combined), dport), ++ &net_secret); ++ return seq_scale(hash); ++} ++EXPORT_SYMBOL_GPL(secure_tcp_nip_sequence_number); ++ ++/* NIP */ ++u64 secure_newip_port_ephemeral(const __be32 *saddr, const __be32 *daddr, ++ __be16 dport) ++{ ++ const struct { ++ struct nip_addr saddr; ++ struct nip_addr daddr; ++ __be16 dport; ++ } __aligned(SIPHASH_ALIGNMENT) combined = { ++ .saddr = *(struct nip_addr *)saddr, ++ .daddr = *(struct nip_addr *)daddr, ++ .dport = dport, ++ }; ++ net_secret_init(); ++ return siphash(&combined, offsetofend(typeof(combined), dport), ++ &net_secret); ++} ++EXPORT_SYMBOL_GPL(secure_newip_port_ephemeral); ++#endif ++ + #if IS_ENABLED(CONFIG_IP_DCCP) + u64 secure_dccp_sequence_number(__be32 saddr, __be32 daddr, + __be16 sport, __be16 dport) +diff -Naur old/net/ipv4/inet_connection_sock.c new/net/ipv4/inet_connection_sock.c +--- old/net/ipv4/inet_connection_sock.c 2022-07-23 18:52:45.646073630 +0800 ++++ new/net/ipv4/inet_connection_sock.c 2022-07-23 18:52:45.676073630 +0800 +@@ -22,7 +22,34 @@ + #include + #include + #include ++#if IS_ENABLED(CONFIG_NEWIP) ++#include ++#include ++#endif + ++#if IS_ENABLED(CONFIG_NEWIP) ++/* 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 ++ */ ++static 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)); ++} ++#endif + #if IS_ENABLED(CONFIG_IPV6) + /* match_sk*_wildcard == true: IPV6_ADDR_ANY equals to any IPv6 addresses + * if IPv6 only, and any IPv4 addresses +@@ -102,6 +129,16 @@ + match_wildcard, + match_wildcard); + #endif ++ ++#if IS_ENABLED(CONFIG_NEWIP) ++ if (sk->sk_family == AF_NINET) ++ return nip_rcv_saddr_equal(&sk->sk_nip_rcv_saddr, ++ &sk2->sk_nip_rcv_saddr, ++ sk2->sk_family == AF_NINET, ++ match_wildcard, ++ match_wildcard); ++#endif ++ + return ipv4_rcv_saddr_equal(sk->sk_rcv_saddr, sk2->sk_rcv_saddr, + ipv6_only_sock(sk2), match_wildcard, + match_wildcard); +@@ -292,6 +329,13 @@ + tb->fast_ipv6_only, + ipv6_only_sock(sk), true, false); + #endif ++#if IS_ENABLED(CONFIG_NEWIP) ++ if (tb->fast_sk_family == AF_NINET) ++ return nip_rcv_saddr_equal(&tb->fast_nip_rcv_saddr, ++ &sk->sk_nip_rcv_saddr, ++ sk->sk_family == AF_NINET, ++ true, false); ++#endif + return ipv4_rcv_saddr_equal(tb->fast_rcv_saddr, sk->sk_rcv_saddr, + ipv6_only_sock(sk), true, false); + } +@@ -313,6 +357,9 @@ + #if IS_ENABLED(CONFIG_IPV6) + tb->fast_v6_rcv_saddr = sk->sk_v6_rcv_saddr; + #endif ++#if IS_ENABLED(CONFIG_NEWIP) ++ tb->fast_nip_rcv_saddr = sk->sk_nip_rcv_saddr; ++#endif + } else { + tb->fastreuseport = 0; + } +@@ -340,6 +387,9 @@ + #if IS_ENABLED(CONFIG_IPV6) + tb->fast_v6_rcv_saddr = sk->sk_v6_rcv_saddr; + #endif ++#if IS_ENABLED(CONFIG_NEWIP) ++ tb->fast_nip_rcv_saddr = sk->sk_nip_rcv_saddr; ++#endif + } + } else { + tb->fastreuseport = 0; +diff -Naur old/net/ipv4/inet_hashtables.c new/net/ipv4/inet_hashtables.c +--- old/net/ipv4/inet_hashtables.c 2022-07-23 18:52:45.656073630 +0800 ++++ new/net/ipv4/inet_hashtables.c 2022-07-23 18:52:45.676073630 +0800 +@@ -52,6 +52,15 @@ + &sk->sk_v6_rcv_saddr, sk->sk_num, + &sk->sk_v6_daddr, sk->sk_dport); + #endif ++ ++#if IS_ENABLED(CONFIG_NEWIP) ++ /* NIP */ ++ if (sk->sk_family == AF_NINET) ++ return ninet_ehashfn(sock_net(sk), ++ &sk->sk_nip_rcv_saddr, sk->sk_num, ++ &sk->sk_nip_daddr, sk->sk_dport); ++#endif ++ + return inet_ehashfn(sock_net(sk), + sk->sk_rcv_saddr, sk->sk_num, + sk->sk_daddr, sk->sk_dport); +diff -Naur old/security/selinux/hooks.c new/security/selinux/hooks.c +--- old/security/selinux/hooks.c 2022-07-23 18:52:45.656073630 +0800 ++++ new/security/selinux/hooks.c 2022-07-23 18:52:45.676073630 +0800 +@@ -1271,7 +1271,7 @@ + return SECCLASS_SMC_SOCKET; + case PF_XDP: + return SECCLASS_XDP_SOCKET; +-#if PF_MAX > 45 ++#if PF_MAX > 46 + #error New address family defined, please update this function. + #endif + } +diff -Naur old/security/selinux/include/classmap.h new/security/selinux/include/classmap.h +--- old/security/selinux/include/classmap.h 2022-07-23 18:52:45.656073630 +0800 ++++ new/security/selinux/include/classmap.h 2022-07-23 18:52:45.676073630 +0800 +@@ -253,6 +253,6 @@ + { NULL } + }; + +-#if PF_MAX > 45 ++#if PF_MAX > 46 + #error New address family defined, please update secclass_map. + #endif -- Gitee