diff --git a/apply_newip.sh b/apply_newip.sh index 4c7e3a9a248ecaf80614fd20965e5e4527c4103a..f3ae8fd9c71ab82b7783209793ff3faa13062aad 100644 --- a/apply_newip.sh +++ b/apply_newip.sh @@ -2,8 +2,7 @@ # # 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. +# you can use it under the terms of the GPL V2 and the BSD2 license. # See the LICENSE file in directory / of this repository for complete details. # diff --git a/code/common/nip_addr.c b/code/common/nip_addr.c index fd07814ed944318717f3040d4525a5899a491570..ff1a1d293f17838a505651fd60893805f0d5e399 100644 --- a/code/common/nip_addr.c +++ b/code/common/nip_addr.c @@ -41,10 +41,30 @@ const struct nip_addr nip_broadcast_addr_arp = { .nip_addr_field8[1] = 0x04, }; +enum addr_check_ret { + NOT_CURRENT_ADDR = -1, + CURRENT_ADDR_VALID = 0, + ADDR_2BYTE_INVALID = 1, + ADDR_3BYTE_INVALID = 2, + ADDR_5BYTE_INVALID = 3, + ADDR_7BYTE_INVALID = 4, + ADDR_BITLEN_INVALID = 5, + NIP_ADDR_UNKNOWN, +}; + +#define NIP_TRUE 1 +#define NIP_FALSE 0 + /* Short address range: * 【1-byte】0 ~ 220 * 00 ~ DC - * + */ +static inline int is_1byte_addr_flag(unsigned char first_byte) +{ + return first_byte <= ADDR_FIRST_DC ? NIP_TRUE : NIP_FALSE; +} + +/* Short address range: * 【2-byte】221 ~ 5119 * DD/DE/.../F0 is a 2-byte address descriptor followed by the address value * DDDD ~ DDFF : 221 ~ 255 @@ -52,23 +72,189 @@ const struct nip_addr nip_broadcast_addr_arp = { * DF00 ~ DFFF : 512 ~ 767 * ... * F000 ~ F0FF : 4864 ~ 5119 - * + */ +static inline int is_2byte_addr_flag(unsigned char first_byte) +{ + return (first_byte > ADDR_FIRST_DC) && (first_byte <= ADDR_FIRST_F0) ? + NIP_TRUE : NIP_FALSE; +} + +/* Short address range: * 【3-byte】5120 ~ 65535 * F1 is a 3-byte address descriptor followed by the address value * F1 1400 ~ F1 FFFF - * + */ +static inline int is_3byte_addr_flag(unsigned char first_byte) +{ + return first_byte == ADDR_FIRST_F1 ? NIP_TRUE : NIP_FALSE; +} + +/* Short address range: * 【5-byte】65536 ~ 4,294,967,295 * F2 is a 5-byte address descriptor followed by the address value * F2 0001 0000 ~ F2 FFFF FFFF - * + */ +static inline int is_5byte_addr_flag(unsigned char first_byte) +{ + return first_byte == ADDR_FIRST_F2 ? NIP_TRUE : NIP_FALSE; +} + +/* Short address range: * 【7-byte】4,294,967,296 ~ 281,474,976,710,655 * F3 is a 7-byte address descriptor followed by the address value * F3 0001 0000 0000 ~ F3 FFFF FFFF FFFF - * - * 【9-byte】281,474,976,710,656 ~ xxxx - * F4 is a 9-byte address descriptor followed by the address value - * F4 0001 0000 0000 0000 ~ F4 FFFF FFFF FFFF FFFF - * + */ +static inline int is_7byte_addr_flag(unsigned char first_byte) +{ + return first_byte == ADDR_FIRST_F3 ? NIP_TRUE : NIP_FALSE; +} + +/* Short address range: + * 【8-byte】 + * F4 is a 8-byte address descriptor followed by the address value + * F400 0000 0000 0000 ~ F4FF FFFF FFFF FFFF + */ +static inline int is_8byte_addr_flag(unsigned char first_byte) +{ + return first_byte == ADDR_FIRST_FE ? NIP_TRUE : NIP_FALSE; +} + +/* Short address range: + * 【public addr】 + * 0xFF00 - The loopback address + * 0xFF01 - Public address for access authentication + * 0xFF02 - Public address of access authentication + * 0xFF03 - The neighbor found a public address + * 0xFF04 - Address resolution (ARP) + * 0xFF05 - DHCP public address + * 0xFF06 - Public address for minimalist access authentication + * 0xFF07 - Self-organizing protocol public address + * 0xFF08 - The IEEE EUI - 64 addresses + * 0xFF09 - any_addr + */ +static inline int is_public_addr_flag(unsigned char first_byte) +{ + return first_byte == ADDR_FIRST_FF ? NIP_TRUE : NIP_FALSE; +} + +/* Short address range: + * 【1-byte】0 ~ 220 + * 00 ~ DC + */ +static int nip_addr_1byte_check(unsigned char first_byte, unsigned char second_byte, + unsigned char third_byte, int addr_len) +{ + int ret = NOT_CURRENT_ADDR; + + if (is_1byte_addr_flag(first_byte) && addr_len == NIP_ADDR_LEN_1) + ret = CURRENT_ADDR_VALID; + + return ret; +} + +/* Short address range: + * 【2-byte】221 ~ 5119 + * DD/DE/.../F0 is a 2-byte address descriptor followed by the address value + * DDDD ~ DDFF : 221 ~ 255 + * DE00 ~ DEFF : 256 ~ 511 + * DF00 ~ DFFF : 512 ~ 767 + * ... + * F000 ~ F0FF : 4864 ~ 5119 + */ +static int nip_addr_2byte_check(unsigned char first_byte, unsigned char second_byte, + unsigned char third_byte, int addr_len) +{ + int ret = NOT_CURRENT_ADDR; + + if (is_2byte_addr_flag(first_byte) && addr_len == NIP_ADDR_LEN_2) { + if (first_byte > ADDR_FIRST_DC + 1 || + second_byte >= ADDR_SECOND_MIN_DD) + ret = CURRENT_ADDR_VALID; + else + ret = ADDR_2BYTE_INVALID; + } + + return ret; +} + +/* Short address range: + * 【3-byte】5120 ~ 65535 + * F1 is a 3-byte address descriptor followed by the address value + * F1 1400 ~ F1 FFFF + */ +static int nip_addr_3byte_check(unsigned char first_byte, unsigned char second_byte, + unsigned char third_byte, int addr_len) +{ + int ret = NOT_CURRENT_ADDR; + + if (is_3byte_addr_flag(first_byte) && addr_len == NIP_ADDR_LEN_3) { + if (second_byte >= ADDR_SECOND_MIN_F1) + ret = CURRENT_ADDR_VALID; + else + ret = ADDR_3BYTE_INVALID; + } + + return ret; +} + +/* Short address range: + * 【5-byte】65536 ~ 4,294,967,295 + * F2 is a 5-byte address descriptor followed by the address value + * F2 0001 0000 ~ F2 FFFF FFFF + */ +static int nip_addr_5byte_check(unsigned char first_byte, unsigned char second_byte, + unsigned char third_byte, int addr_len) +{ + int ret = NOT_CURRENT_ADDR; + + if (is_5byte_addr_flag(first_byte) && addr_len == NIP_ADDR_LEN_5) { + if (second_byte > 0 || third_byte >= ADDR_THIRD_MIN_F2) + ret = CURRENT_ADDR_VALID; + else + ret = ADDR_5BYTE_INVALID; + } + + return ret; +} + +/* Short address range: + * 【7-byte】4,294,967,296 ~ 281,474,976,710,655 + * F3 is a 7-byte address descriptor followed by the address value + * F3 0001 0000 0000 ~ F3 FFFF FFFF FFFF + */ +static int nip_addr_7byte_check(unsigned char first_byte, unsigned char second_byte, + unsigned char third_byte, int addr_len) +{ + int ret = NOT_CURRENT_ADDR; + + if (is_7byte_addr_flag(first_byte) && addr_len == NIP_ADDR_LEN_7) { + if (second_byte > 0 || third_byte >= ADDR_THIRD_MIN_F3) + ret = CURRENT_ADDR_VALID; + else + ret = ADDR_7BYTE_INVALID; + } + + return ret; +} + +/* Short address range: + * 【8-byte】 + * F4 is a 8-byte address descriptor followed by the address value + * F400 0000 0000 0000 ~ F4FF FFFF FFFF FFFF + */ +static int nip_addr_8byte_check(unsigned char first_byte, unsigned char second_byte, + unsigned char third_byte, int addr_len) +{ + int ret = NOT_CURRENT_ADDR; + + if (is_8byte_addr_flag(first_byte) && addr_len == NIP_ADDR_LEN_8) + ret = CURRENT_ADDR_VALID; + + return ret; +} + +/* Short address range: + * 【public addr】 * 0xFF00 - The loopback address * 0xFF01 - Public address for access authentication * 0xFF02 - Public address of access authentication @@ -80,10 +266,44 @@ const struct nip_addr nip_broadcast_addr_arp = { * 0xFF08 - The IEEE EUI - 64 addresses * 0xFF09 - any_addr */ +static int nip_addr_public_check(unsigned char first_byte, unsigned char second_byte, + unsigned char third_byte, int addr_len) +{ + int ret = NOT_CURRENT_ADDR; + + if (is_public_addr_flag(first_byte) && addr_len == NIP_ADDR_LEN_2) + ret = CURRENT_ADDR_VALID; + + return ret; +} + +static int nip_addr_unknown(unsigned char first_byte, unsigned char second_byte, + unsigned char third_byte, int addr_len) +{ + return NIP_ADDR_UNKNOWN; +} + +#define CHECK_FUN_MAX 8 +static int (*nip_addr_check_fun[CHECK_FUN_MAX])(unsigned char first_byte, + unsigned char second_byte, + unsigned char third_byte, + int addr_len) = { + nip_addr_1byte_check, + nip_addr_2byte_check, + nip_addr_3byte_check, + nip_addr_5byte_check, + nip_addr_7byte_check, + nip_addr_8byte_check, + nip_addr_public_check, + nip_addr_unknown, +}; + int nip_addr_invalid(const struct nip_addr *addr) { + int i; + int addr_len; + int ret = NIP_ADDR_UNKNOWN; unsigned char first_byte, second_byte, third_byte; - int addr_len, i, err; first_byte = addr->nip_addr_field8[NIP_8BIT_ADDR_INDEX_0]; second_byte = addr->nip_addr_field8[NIP_8BIT_ADDR_INDEX_1]; @@ -92,44 +312,21 @@ int nip_addr_invalid(const struct nip_addr *addr) /* The value of the field after the effective length of the short address should be 0 */ for (i = addr_len; i < NIP_8BIT_ADDR_INDEX_MAX; i++) { - if (addr->nip_addr_field8[i] > 0x00) { - /* newip bitlen error */ - err = 1; - return err; - } + if (addr->nip_addr_field8[i] > 0x00) + return ADDR_BITLEN_INVALID; } - if (first_byte <= ADDR_FIRST_DC && addr_len == NIP_ADDR_LEN_1) { - err = 0; - } else if (first_byte <= ADDR_FIRST_F0 && addr_len == NIP_ADDR_LEN_2) { - if (first_byte > ADDR_FIRST_DC + 1 || - second_byte >= ADDR_SECOND_MIN_DD) { - err = 0; - } else { - /* addr2 is not valid */ - err = 1; - } - } else if (first_byte == ADDR_FIRST_F1 && addr_len == NIP_ADDR_LEN_3) { - if (second_byte >= ADDR_SECOND_MIN_F1) { - err = 0; - } else { - /* addr3 is not valid */ - err = 1; - } - } else if (first_byte == ADDR_FIRST_F2 && addr_len == NIP_ADDR_LEN_5) { - if (second_byte > 0 || third_byte >= ADDR_THIRD_MIN_F2) { - err = 0; - } else { - /* addr5 is not valid */ - err = 1; - } - } else if (first_byte == ADDR_FIRST_FF && addr_len == NIP_ADDR_LEN_2) { - err = 0; - } else { - /* addr check fail */ - err = 1; + for (i = 0; i < CHECK_FUN_MAX; i++) { + ret = nip_addr_check_fun[i](first_byte, second_byte, third_byte, addr_len); + if (ret == CURRENT_ADDR_VALID) + return ret; + else if (ret == NOT_CURRENT_ADDR) + continue; + else + return ret; } - return err; + + return ret; } /* 0xFF00 - The loopback address @@ -145,8 +342,8 @@ int nip_addr_invalid(const struct nip_addr *addr) */ int nip_addr_public(const struct nip_addr *addr) { - if (addr->bitlen == NIP_ADDR_BIT_LEN_16 && - addr->nip_addr_field8[NIP_8BIT_ADDR_INDEX_0] == ADDR_FIRST_FF) + if (is_public_addr_flag(addr->nip_addr_field8[NIP_8BIT_ADDR_INDEX_0]) && + addr->bitlen == NIP_ADDR_BIT_LEN_16) return 1; else return 0; @@ -168,102 +365,62 @@ int nip_addr_any(const struct nip_addr *ad) int get_nip_addr_len(const struct nip_addr *addr) { int len = 0; + unsigned char first_byte = addr->nip_addr_field8[0]; - if (addr->nip_addr_field8[0] <= ADDR_FIRST_DC) + if (is_1byte_addr_flag(first_byte)) len = NIP_ADDR_LEN_1; - else if ((addr->nip_addr_field8[0] > ADDR_FIRST_DC && - addr->nip_addr_field8[0] <= ADDR_FIRST_F0) || - addr->nip_addr_field8[0] == ADDR_FIRST_FF) + else if (is_2byte_addr_flag(first_byte) || is_public_addr_flag(first_byte)) len = NIP_ADDR_LEN_2; - else if (addr->nip_addr_field8[0] == ADDR_FIRST_F1) + else if (is_3byte_addr_flag(first_byte)) len = NIP_ADDR_LEN_3; - else if (addr->nip_addr_field8[0] == ADDR_FIRST_F2) + else if (is_5byte_addr_flag(first_byte)) len = NIP_ADDR_LEN_5; - else - return 0; + else if (is_7byte_addr_flag(first_byte)) + len = NIP_ADDR_LEN_7; + else if (is_8byte_addr_flag(first_byte)) + len = NIP_ADDR_LEN_8; + return len; } unsigned char *build_nip_addr(const struct nip_addr *addr, unsigned char *buf) { - unsigned char *p = buf; int i; + unsigned char *p = buf; + int addr_len = get_nip_addr_len(addr); - if (addr->nip_addr_field8[0] <= ADDR_FIRST_DC) { - *p = addr->nip_addr_field8[0]; - } else if (((addr->nip_addr_field8[0] > ADDR_FIRST_DC) && - (addr->nip_addr_field8[0] <= ADDR_FIRST_F0)) || - (addr->nip_addr_field8[0] == ADDR_FIRST_FF)) { - *p = addr->nip_addr_field8[0]; - p++; - *p = addr->nip_addr_field8[NIP_8BIT_ADDR_INDEX_1]; - } else if (addr->nip_addr_field8[0] == ADDR_FIRST_F1) { - for (i = 0; i < NIP_ADDR_LEN_2; i++) { - *p = addr->nip_addr_field8[i]; - p++; - } - *p = addr->nip_addr_field8[NIP_8BIT_ADDR_INDEX_2]; - } else if (addr->nip_addr_field8[0] == ADDR_FIRST_F2) { - for (i = 0; i < NIP_ADDR_LEN_4; i++) { - *p = addr->nip_addr_field8[i]; - p++; - } - *p = addr->nip_addr_field8[NIP_8BIT_ADDR_INDEX_4]; - } else { + if (addr_len == 0) return 0; + + for (i = 0; i < addr_len; i++) { + *p = addr->nip_addr_field8[i]; + p++; } - return ++p; + return p; } unsigned char *decode_nip_addr(unsigned char *buf, struct nip_addr *addr) { - unsigned char *p = buf; int i; + int ret; + int addr_len; + unsigned char *p = buf; - if (*p <= ADDR_FIRST_DC) { - addr->nip_addr_field8[0] = *p; - p++; - addr->bitlen = NIP_ADDR_BIT_LEN_8; - } else if (*p > ADDR_FIRST_DC && *p <= ADDR_FIRST_F0) { - if (*p > ADDR_FIRST_DC + 1 || *(p + 1) >= ADDR_SECOND_MIN_DD) { - addr->nip_addr_field8[0] = *p; - p++; - addr->nip_addr_field8[1] = *p; - p++; - addr->bitlen = NIP_ADDR_BIT_LEN_16; - } else { - return 0; - } - } else if (*p == ADDR_FIRST_F1) { - if (*(p + 1) >= ADDR_SECOND_MIN_F1) { - for (i = 0; i < NIP_ADDR_LEN_3; i++) { - addr->nip_addr_field8[i] = *p; - p++; - } - addr->bitlen = NIP_ADDR_BIT_LEN_24; - } else { - return 0; - } - } else if (*p == ADDR_FIRST_F2) { - if (*(p + 1) > 0 || *(p + 2) >= ADDR_THIRD_MIN_F2) { /* 偏移2 */ - for (i = 0; i < NIP_ADDR_LEN_5; i++) { - addr->nip_addr_field8[i] = *p; - p++; - } - addr->bitlen = NIP_ADDR_BIT_LEN_40; - } else { - return 0; - } - } else if (*p == ADDR_FIRST_FF) { - addr->nip_addr_field8[0] = *p; - p++; - addr->nip_addr_field8[1] = *p; - p++; - addr->bitlen = NIP_ADDR_BIT_LEN_16; - } else { + addr->nip_addr_field8[0] = *p; + addr_len = get_nip_addr_len(addr); + if (addr_len == 0) return 0; + + for (i = 0; i < addr_len; i++) { + addr->nip_addr_field8[i] = *p; + p++; } + addr->bitlen = addr_len * NIP_ADDR_BIT_LEN_8; + + ret = nip_addr_invalid(addr); + if (ret) + return 0; return p; } diff --git a/code/common/nip_addr.h b/code/common/nip_addr.h index 1af352311ca3e74de45bf3acbadfe9477855f026..552fd4c875acbbe378625eae95f37c02a9e9faaf 100644 --- a/code/common/nip_addr.h +++ b/code/common/nip_addr.h @@ -47,7 +47,7 @@ enum nip_addr_check_value { ADDR_FIRST_F1, ADDR_FIRST_F2, ADDR_FIRST_F3, - ADDR_FIRST_F4, + ADDR_FIRST_FE = 0xFE, ADDR_FIRST_FF = 0xFF, ADDR_SECOND_MIN_DD = 0xDD, ADDR_SECOND_MIN_F1 = 0x14, /* f1 14 00 */ diff --git a/code/linux/include/linux/nip.h b/code/linux/include/linux/nip.h index b663e7b406d775aaa857d64278d140e15bd8630e..1ef0a8a799b484c4aba0c1172a4419c034d397db 100644 --- a/code/linux/include/linux/nip.h +++ b/code/linux/include/linux/nip.h @@ -29,7 +29,7 @@ struct nip_devconf { * The common CB structure: struct sk_buff->char cb[48] * TCP CB structure : struct tcp_skb_cb * struct tcp_skb_cb->header is union, include IPv4/IPv6/NewIP xx_skb_parm, max size is 24 - * sizeof(struct ninet_skb_parm)=23 + * sizeof(struct ninet_skb_parm)=19 * sizeof(struct inet_skb_parm)=24 * sizeof(struct inet6_skb_parm)=20 * sizeof(struct tcp_skb_cb->exclude skb_parm)=24 |__ total size is 48, struct sk_buff->char cb[48] @@ -40,7 +40,6 @@ struct ninet_skb_parm { struct nip_addr dstaddr; struct nip_addr srcaddr; u8 nexthdr; - u32 pkt_total_len; }; #pragma pack() diff --git a/code/linux/net/newip/nip_addrconf.c b/code/linux/net/newip/nip_addrconf.c index f0e5f8b5b2aa23ff7ca3e3c06a923c11f355a997..7db4e49a7d4809de975a2d1435db91a544169e5a 100644 --- a/code/linux/net/newip/nip_addrconf.c +++ b/code/linux/net/newip/nip_addrconf.c @@ -671,9 +671,9 @@ static int nip_addrconf_ifdown(struct net_device *dev, bool unregister) spin_lock_bh(&addrconf_hash_lock); hlist_for_each_entry_rcu(ifa, h, addr_lst) { if (ifa->idev == idev) { - char addr[NIP_8BIT_ADDR_INDEX_MAX] = {0}; + char addr[NIP_ADDR_BIT_LEN_MAX] = {0}; - nip_addr_to_str(&ifa->addr, addr, NIP_8BIT_ADDR_INDEX_MAX); + nip_addr_to_str(&ifa->addr, addr, NIP_ADDR_BIT_LEN_MAX); DEBUG("%s: clear addr hash table.(addr=%s)", __func__, addr); hlist_del_init_rcu(&ifa->addr_lst); } diff --git a/code/linux/net/newip/nip_fib.c b/code/linux/net/newip/nip_fib.c index eefd81e327f3e1c27cfc8571cc6ea919d90b1fad..d3ad7e9cc55407d723ee06824ab99dd138dc9636 100644 --- a/code/linux/net/newip/nip_fib.c +++ b/code/linux/net/newip/nip_fib.c @@ -189,13 +189,13 @@ static void nip_fib_clean_hash(struct net *net, struct hlist_head *nip_tb_head, hlist_for_each_entry_safe(fn, tmp, h, fib_hlist) { if (func(fn->nip_route_info, arg) < 0) { - char dst[NIP_8BIT_ADDR_INDEX_MAX] = {0}; - char gateway[NIP_8BIT_ADDR_INDEX_MAX] = {0}; + char dst[NIP_ADDR_BIT_LEN_MAX] = {0}; + char gateway[NIP_ADDR_BIT_LEN_MAX] = {0}; nip_addr_to_str(&fn->nip_route_info->rt_dst, dst, - NIP_8BIT_ADDR_INDEX_MAX); + NIP_ADDR_BIT_LEN_MAX); nip_addr_to_str(&fn->nip_route_info->gateway, gateway, - NIP_8BIT_ADDR_INDEX_MAX); + NIP_ADDR_BIT_LEN_MAX); DEBUG("%s: try to del rt_info, rt_dst=%s, gateway=%s", __func__, dst, gateway); diff --git a/code/linux/net/newip/tcp_nip.c b/code/linux/net/newip/tcp_nip.c index 2140e6efcec36647a9453fa6f3f67d86d938bdf9..5d1aba3836ca4b7e0af0025563483d97b2e9efac 100644 --- a/code/linux/net/newip/tcp_nip.c +++ b/code/linux/net/newip/tcp_nip.c @@ -685,18 +685,12 @@ static int tcp_nip_keepalive_para_update(struct sock *sk, void tcp_nip_keepalive_enable(struct sock *sk) { int ret; - u32 nip_keepalive_time; - u32 pkt_len; struct tcp_sock *tp = tcp_sk(sk); struct sk_buff *skb = tcp_nip_send_head(sk); if (!skb) return; - pkt_len = NIPCB(skb)->pkt_total_len; - nip_keepalive_time = pkt_len < NIP_PKT_TOTAL_LEN_BOUNDARY ? - g_nip_keepalive_time_short_pkt : g_nip_keepalive_time; - if (tp->nip_keepalive_enable) { /* If keepalive set by setsockopt, backup para and change para to nip para */ if (tp->keepalive_time > HZ) { @@ -706,10 +700,10 @@ void tcp_nip_keepalive_enable(struct sock *sk) DEBUG("%s HZ=%u, change time/probes/intvl [%u, %u, %u] to [%u, %u, %u]", __func__, HZ, tp->keepalive_time, tp->keepalive_probes, - tp->keepalive_intvl, nip_keepalive_time, NIP_KEEPALIVE_PROBES, + tp->keepalive_intvl, g_nip_keepalive_time, NIP_KEEPALIVE_PROBES, g_nip_keepalive_intvl); - tp->keepalive_time = nip_keepalive_time; + tp->keepalive_time = g_nip_keepalive_time; tp->keepalive_probes = NIP_KEEPALIVE_PROBES; tp->keepalive_intvl = g_nip_keepalive_intvl; inet_csk_reset_keepalive_timer(sk, tp->keepalive_time); @@ -727,7 +721,7 @@ void tcp_nip_keepalive_enable(struct sock *sk) } /* change para to nip para */ - ret = tcp_nip_keepalive_para_update(sk, nip_keepalive_time, + ret = tcp_nip_keepalive_para_update(sk, g_nip_keepalive_time, g_nip_keepalive_intvl, NIP_KEEPALIVE_PROBES); if (ret != 0) { @@ -736,9 +730,9 @@ void tcp_nip_keepalive_enable(struct sock *sk) return; } - pr_crit("%s ok, HZ=%u, time/probes/intvl [%u, %u, %u], pkt_total_len=%u", + pr_crit("%s ok, HZ=%u, time/probes/intvl [%u, %u, %u]", __func__, HZ, tp->keepalive_time, tp->keepalive_probes, - tp->keepalive_intvl, pkt_len); + tp->keepalive_intvl); tp->nip_keepalive_enable = true; } @@ -967,7 +961,6 @@ restart: skb->tstamp = 0; process_backlog = true; - NIPCB(skb)->pkt_total_len = size; skb_nip_entail(sk, skb); copy = mss_now; diff --git a/code/linux/net/newip/tcp_nip_output.c b/code/linux/net/newip/tcp_nip_output.c index f11b422e80d9ba705044b974f89bbb38c433cb8c..d3fe24dc07a238743ef2167d5a1f4a8b43f4d3e1 100644 --- a/code/linux/net/newip/tcp_nip_output.c +++ b/code/linux/net/newip/tcp_nip_output.c @@ -1083,7 +1083,8 @@ static bool tcp_nip_write_xmit(struct sock *sk, unsigned int mss_now, int nonagl u32 snd_num = g_nip_tcp_snd_win_enable ? (tp->nip_ssthresh / mss_now) : 0xFFFFFFFF; u32 last_nip_ssthresh = tp->nip_ssthresh; bool snd_wnd_ready; - const char *str[] = {"can`t send pkt because no window", "have window to send pkt"}; + static const char * const str[] = {"can`t send pkt because no window", + "have window to send pkt"}; tcp_nip_keepalive_enable(sk); tp->idle_ka_probes_out = 0; diff --git a/code/linux/net/newip/tcp_nip_parameter.c b/code/linux/net/newip/tcp_nip_parameter.c index 7238dc0a0e7e55e7290eac477fe97c3e4480890f..dcd42eb13ce8809d676132cfed584a51d09cbfd0 100644 --- a/code/linux/net/newip/tcp_nip_parameter.c +++ b/code/linux/net/newip/tcp_nip_parameter.c @@ -136,9 +136,6 @@ module_param_named(nip_keepalive_time, g_nip_keepalive_time, int, 0644); int g_nip_keepalive_intvl = 25; module_param_named(nip_keepalive_intvl, g_nip_keepalive_intvl, int, 0644); -int g_nip_keepalive_time_short_pkt = 150; -module_param_named(nip_keepalive_time_short_pkt, g_nip_keepalive_time_short_pkt, int, 0644); - /*********************************************************************************************/ /* window mode parameters */ /*********************************************************************************************/ diff --git a/code/linux/net/newip/tcp_nip_parameter.h b/code/linux/net/newip/tcp_nip_parameter.h index 39a9303e16e8ff36bfc80eb042f281adc64ece1b..9d830beaa75730b4b6320d7aa765b19f3552906f 100644 --- a/code/linux/net/newip/tcp_nip_parameter.h +++ b/code/linux/net/newip/tcp_nip_parameter.h @@ -69,7 +69,6 @@ extern int g_ssthresh_high_step; extern int g_nip_idle_ka_probes_out; extern int g_nip_keepalive_time; extern int g_nip_keepalive_intvl; -extern int g_nip_keepalive_time_short_pkt; /*********************************************************************************************/ /* window mode parameters */ diff --git a/patches/linux-5.10/newip.patch b/patches/linux-5.10/newip.patch index 4b64d06f1a32bfd940800924d2ae92abc4a99ebb..197fb6d4bfd9fd74a81c991c9e22b146aabb79ee 100644 --- a/patches/linux-5.10/newip.patch +++ b/patches/linux-5.10/newip.patch @@ -1,6 +1,6 @@ diff -Naur old/include/linux/netdevice.h new/include/linux/netdevice.h ---- old/include/linux/netdevice.h 2022-08-17 10:51:51.503816820 +0800 -+++ new/include/linux/netdevice.h 2022-08-17 10:51:51.533816820 +0800 +--- old/include/linux/netdevice.h 2022-08-23 10:45:41.521257329 +0800 ++++ new/include/linux/netdevice.h 2022-08-23 10:45:41.561257329 +0800 @@ -2016,6 +2016,9 @@ struct dn_dev __rcu *dn_ptr; #endif @@ -11,57 +11,9 @@ diff -Naur old/include/linux/netdevice.h new/include/linux/netdevice.h #if IS_ENABLED(CONFIG_AX25) void *ax25_ptr; #endif -@@ -4214,8 +4217,7 @@ - static inline void __netif_tx_lock(struct netdev_queue *txq, int cpu) - { - spin_lock(&txq->_xmit_lock); -- /* Pairs with READ_ONCE() in __dev_queue_xmit() */ -- WRITE_ONCE(txq->xmit_lock_owner, cpu); -+ txq->xmit_lock_owner = cpu; - } - - static inline bool __netif_tx_acquire(struct netdev_queue *txq) -@@ -4232,32 +4234,26 @@ - static inline void __netif_tx_lock_bh(struct netdev_queue *txq) - { - spin_lock_bh(&txq->_xmit_lock); -- /* Pairs with READ_ONCE() in __dev_queue_xmit() */ -- WRITE_ONCE(txq->xmit_lock_owner, smp_processor_id()); -+ txq->xmit_lock_owner = smp_processor_id(); - } - - static inline bool __netif_tx_trylock(struct netdev_queue *txq) - { - bool ok = spin_trylock(&txq->_xmit_lock); -- -- if (likely(ok)) { -- /* Pairs with READ_ONCE() in __dev_queue_xmit() */ -- WRITE_ONCE(txq->xmit_lock_owner, smp_processor_id()); -- } -+ if (likely(ok)) -+ txq->xmit_lock_owner = smp_processor_id(); - return ok; - } - - static inline void __netif_tx_unlock(struct netdev_queue *txq) - { -- /* Pairs with READ_ONCE() in __dev_queue_xmit() */ -- WRITE_ONCE(txq->xmit_lock_owner, -1); -+ txq->xmit_lock_owner = -1; - spin_unlock(&txq->_xmit_lock); - } - - static inline void __netif_tx_unlock_bh(struct netdev_queue *txq) - { -- /* Pairs with READ_ONCE() in __dev_queue_xmit() */ -- WRITE_ONCE(txq->xmit_lock_owner, -1); -+ txq->xmit_lock_owner = -1; - spin_unlock_bh(&txq->_xmit_lock); - } - diff -Naur old/include/linux/socket.h new/include/linux/socket.h ---- old/include/linux/socket.h 2022-08-17 10:51:51.503816820 +0800 -+++ new/include/linux/socket.h 2022-08-17 10:51:51.533816820 +0800 +--- old/include/linux/socket.h 2022-08-23 10:45:41.521257329 +0800 ++++ new/include/linux/socket.h 2022-08-23 10:45:41.561257329 +0800 @@ -223,8 +223,8 @@ * reuses AF_INET address family */ @@ -82,8 +34,8 @@ diff -Naur old/include/linux/socket.h new/include/linux/socket.h /* Maximum queue length specifiable by listen. */ diff -Naur old/include/linux/tcp.h new/include/linux/tcp.h ---- old/include/linux/tcp.h 2022-08-17 10:51:51.503816820 +0800 -+++ new/include/linux/tcp.h 2022-08-17 10:51:51.533816820 +0800 +--- old/include/linux/tcp.h 2022-08-23 10:45:41.531257329 +0800 ++++ new/include/linux/tcp.h 2022-08-23 10:45:41.561257329 +0800 @@ -317,6 +317,9 @@ /* OOO segments go in this rbtree. Socket lock must be held. */ @@ -129,8 +81,8 @@ diff -Naur old/include/linux/tcp.h new/include/linux/tcp.h enum tsq_flags { diff -Naur old/include/net/dst.h new/include/net/dst.h ---- old/include/net/dst.h 2022-08-17 10:51:51.503816820 +0800 -+++ new/include/net/dst.h 2022-08-17 10:51:51.533816820 +0800 +--- old/include/net/dst.h 2022-08-23 10:45:41.531257329 +0800 ++++ new/include/net/dst.h 2022-08-23 10:45:41.561257329 +0800 @@ -35,6 +35,8 @@ int (*output)(struct net *net, struct sock *sk, struct sk_buff *skb); @@ -141,8 +93,8 @@ diff -Naur old/include/net/dst.h new/include/net/dst.h #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-08-17 10:51:51.503816820 +0800 -+++ new/include/net/inet_hashtables.h 2022-08-17 10:51:51.533816820 +0800 +--- old/include/net/inet_hashtables.h 2022-08-23 10:45:41.531257329 +0800 ++++ new/include/net/inet_hashtables.h 2022-08-23 10:45:41.561257329 +0800 @@ -83,6 +83,9 @@ #if IS_ENABLED(CONFIG_IPV6) struct in6_addr fast_v6_rcv_saddr; @@ -168,8 +120,8 @@ diff -Naur old/include/net/inet_hashtables.h new/include/net/inet_hashtables.h { 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-08-17 10:51:51.503816820 +0800 -+++ new/include/net/inet_sock.h 2022-08-17 10:51:51.533816820 +0800 +--- old/include/net/inet_sock.h 2022-08-23 10:45:41.531257329 +0800 ++++ new/include/net/inet_sock.h 2022-08-23 10:45:41.561257329 +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 @@ -195,8 +147,8 @@ diff -Naur old/include/net/inet_sock.h new/include/net/inet_sock.h }; diff -Naur old/include/net/neighbour.h new/include/net/neighbour.h ---- old/include/net/neighbour.h 2022-08-17 10:51:51.503816820 +0800 -+++ new/include/net/neighbour.h 2022-08-17 10:51:51.533816820 +0800 +--- old/include/net/neighbour.h 2022-08-23 10:45:41.531257329 +0800 ++++ new/include/net/neighbour.h 2022-08-23 10:45:41.571257329 +0800 @@ -232,6 +232,9 @@ NEIGH_ARP_TABLE = 0, NEIGH_ND_TABLE = 1, @@ -208,8 +160,8 @@ diff -Naur old/include/net/neighbour.h new/include/net/neighbour.h 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-08-17 10:51:51.503816820 +0800 -+++ new/include/net/net_namespace.h 2022-08-17 10:51:51.533816820 +0800 +--- old/include/net/net_namespace.h 2022-08-23 10:45:41.531257329 +0800 ++++ new/include/net/net_namespace.h 2022-08-23 10:45:41.571257329 +0800 @@ -38,6 +38,9 @@ #include #include @@ -231,8 +183,8 @@ diff -Naur old/include/net/net_namespace.h new/include/net/net_namespace.h 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-08-17 10:51:51.503816820 +0800 -+++ new/include/net/secure_seq.h 2022-08-17 10:51:51.533816820 +0800 +--- old/include/net/secure_seq.h 2022-08-23 10:45:41.531257329 +0800 ++++ new/include/net/secure_seq.h 2022-08-23 10:45:41.571257329 +0800 @@ -19,4 +19,11 @@ u64 secure_dccpv6_sequence_number(__be32 *saddr, __be32 *daddr, __be16 sport, __be16 dport); @@ -246,8 +198,8 @@ diff -Naur old/include/net/secure_seq.h new/include/net/secure_seq.h +#endif #endif /* _NET_SECURE_SEQ */ diff -Naur old/include/net/sock.h new/include/net/sock.h ---- old/include/net/sock.h 2022-08-17 10:51:51.503816820 +0800 -+++ new/include/net/sock.h 2022-08-17 10:51:51.533816820 +0800 +--- old/include/net/sock.h 2022-08-23 10:45:41.541257329 +0800 ++++ new/include/net/sock.h 2022-08-23 10:45:41.571257329 +0800 @@ -68,6 +68,9 @@ #include #include @@ -279,37 +231,9 @@ diff -Naur old/include/net/sock.h new/include/net/sock.h #define sk_cookie __sk_common.skc_cookie #define sk_incoming_cpu __sk_common.skc_incoming_cpu #define sk_flags __sk_common.skc_flags -@@ -2322,22 +2332,19 @@ - * @sk: socket - * - * Use the per task page_frag instead of the per socket one for -- * optimization when we know that we're in process context and own -+ * optimization when we know that we're in the normal context and owns - * everything that's associated with %current. - * -- * Both direct reclaim and page faults can nest inside other -- * socket operations and end up recursing into sk_page_frag() -- * while it's already in use: explicitly avoid task page_frag -- * usage if the caller is potentially doing any of them. -- * This assumes that page fault handlers use the GFP_NOFS flags. -+ * gfpflags_allow_blocking() isn't enough here as direct reclaim may nest -+ * inside other socket operations and end up recursing into sk_page_frag() -+ * while it's already in use. - * - * Return: a per task page_frag if context allows that, - * otherwise a per socket one. - */ - static inline struct page_frag *sk_page_frag(struct sock *sk) - { -- if ((sk->sk_allocation & (__GFP_DIRECT_RECLAIM | __GFP_MEMALLOC | __GFP_FS)) == -- (__GFP_DIRECT_RECLAIM | __GFP_FS)) -+ if (gfpflags_normal_context(sk->sk_allocation)) - return ¤t->task_frag; - - return &sk->sk_frag; diff -Naur old/include/net/tcp.h new/include/net/tcp.h ---- old/include/net/tcp.h 2022-08-17 10:51:51.513816820 +0800 -+++ new/include/net/tcp.h 2022-08-17 10:51:51.533816820 +0800 +--- old/include/net/tcp.h 2022-08-23 10:45:41.541257329 +0800 ++++ new/include/net/tcp.h 2022-08-23 10:45:41.571257329 +0800 @@ -40,7 +40,9 @@ #include #include @@ -332,8 +256,8 @@ diff -Naur old/include/net/tcp.h new/include/net/tcp.h 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-08-17 10:51:51.513816820 +0800 -+++ new/include/uapi/linux/if_ether.h 2022-08-17 10:51:51.533816820 +0800 +--- old/include/uapi/linux/if_ether.h 2022-08-23 10:45:41.541257329 +0800 ++++ new/include/uapi/linux/if_ether.h 2022-08-23 10:45:41.571257329 +0800 @@ -72,6 +72,7 @@ #define ETH_P_ERSPAN 0x88BE /* ERSPAN type II */ #define ETH_P_IPX 0x8137 /* IPX over DIX */ @@ -343,8 +267,8 @@ diff -Naur old/include/uapi/linux/if_ether.h new/include/uapi/linux/if_ether.h #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-08-17 10:51:51.513816820 +0800 -+++ new/net/Kconfig 2022-08-17 10:51:51.543816820 +0800 +--- old/net/Kconfig 2022-08-23 10:45:41.551257329 +0800 ++++ new/net/Kconfig 2022-08-23 10:45:41.581257329 +0800 @@ -93,6 +93,7 @@ if INET source "net/ipv4/Kconfig" @@ -354,8 +278,8 @@ diff -Naur old/net/Kconfig new/net/Kconfig source "net/mptcp/Kconfig" diff -Naur old/net/Makefile new/net/Makefile ---- old/net/Makefile 2022-08-17 10:51:51.513816820 +0800 -+++ new/net/Makefile 2022-08-17 10:51:51.543816820 +0800 +--- old/net/Makefile 2022-08-23 10:45:41.551257329 +0800 ++++ new/net/Makefile 2022-08-23 10:45:41.581257329 +0800 @@ -20,6 +20,7 @@ obj-$(CONFIG_XFRM) += xfrm/ obj-$(CONFIG_UNIX_SCM) += unix/ @@ -365,22 +289,9 @@ diff -Naur old/net/Makefile new/net/Makefile 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-08-17 10:51:51.513816820 +0800 -+++ new/net/core/neighbour.c 2022-08-17 10:51:51.533816820 +0800 -@@ -734,10 +734,11 @@ - - ASSERT_RTNL(); - -- n = kzalloc(sizeof(*n) + key_len, GFP_KERNEL); -+ n = kmalloc(sizeof(*n) + key_len, GFP_KERNEL); - if (!n) - goto out; - -+ n->protocol = 0; - write_pnet(&n->net, net); - memcpy(n->key, pkey, key_len); - n->dev = dev; -@@ -1778,6 +1779,11 @@ +--- old/net/core/neighbour.c 2022-08-23 10:45:41.541257329 +0800 ++++ new/net/core/neighbour.c 2022-08-23 10:45:41.571257329 +0800 +@@ -1778,6 +1778,11 @@ case AF_DECnet: tbl = neigh_tables[NEIGH_DN_TABLE]; break; @@ -393,8 +304,8 @@ diff -Naur old/net/core/neighbour.c new/net/core/neighbour.c return tbl; diff -Naur old/net/core/secure_seq.c new/net/core/secure_seq.c ---- old/net/core/secure_seq.c 2022-08-17 10:51:51.513816820 +0800 -+++ new/net/core/secure_seq.c 2022-08-17 10:51:51.533816820 +0800 +--- old/net/core/secure_seq.c 2022-08-23 10:45:41.541257329 +0800 ++++ new/net/core/secure_seq.c 2022-08-23 10:45:41.571257329 +0800 @@ -151,6 +151,51 @@ EXPORT_SYMBOL_GPL(secure_ipv4_port_ephemeral); #endif @@ -448,8 +359,8 @@ diff -Naur old/net/core/secure_seq.c new/net/core/secure_seq.c 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-08-17 10:51:51.513816820 +0800 -+++ new/net/ipv4/inet_connection_sock.c 2022-08-17 10:51:51.533816820 +0800 +--- old/net/ipv4/inet_connection_sock.c 2022-08-23 10:45:41.541257329 +0800 ++++ new/net/ipv4/inet_connection_sock.c 2022-08-23 10:45:41.571257329 +0800 @@ -22,7 +22,34 @@ #include #include @@ -537,8 +448,8 @@ diff -Naur old/net/ipv4/inet_connection_sock.c new/net/ipv4/inet_connection_sock } 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-08-17 10:51:51.513816820 +0800 -+++ new/net/ipv4/inet_hashtables.c 2022-08-17 10:51:51.543816820 +0800 +--- old/net/ipv4/inet_hashtables.c 2022-08-23 10:45:41.541257329 +0800 ++++ new/net/ipv4/inet_hashtables.c 2022-08-23 10:45:41.581257329 +0800 @@ -52,6 +52,15 @@ &sk->sk_v6_rcv_saddr, sk->sk_num, &sk->sk_v6_daddr, sk->sk_dport); @@ -556,8 +467,8 @@ diff -Naur old/net/ipv4/inet_hashtables.c new/net/ipv4/inet_hashtables.c 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-08-17 10:51:51.523816820 +0800 -+++ new/security/selinux/hooks.c 2022-08-17 10:51:51.543816820 +0800 +--- old/security/selinux/hooks.c 2022-08-23 10:45:41.551257329 +0800 ++++ new/security/selinux/hooks.c 2022-08-23 10:45:41.581257329 +0800 @@ -1271,7 +1271,7 @@ return SECCLASS_SMC_SOCKET; case PF_XDP: @@ -567,18 +478,9 @@ diff -Naur old/security/selinux/hooks.c new/security/selinux/hooks.c #error New address family defined, please update this function. #endif } -@@ -5665,7 +5665,7 @@ - struct common_audit_data ad; - struct lsm_network_audit net = {0,}; - char *addrp; -- u8 proto = 0; -+ u8 proto; - - if (sk == NULL) - return NF_ACCEPT; diff -Naur old/security/selinux/include/classmap.h new/security/selinux/include/classmap.h ---- old/security/selinux/include/classmap.h 2022-08-17 10:51:51.523816820 +0800 -+++ new/security/selinux/include/classmap.h 2022-08-17 10:51:51.543816820 +0800 +--- old/security/selinux/include/classmap.h 2022-08-23 10:45:41.551257329 +0800 ++++ new/security/selinux/include/classmap.h 2022-08-23 10:45:41.581257329 +0800 @@ -253,6 +253,6 @@ { NULL } };