From 490c9055def7d74eef075b2c4dadf715bdd2c6ea Mon Sep 17 00:00:00 2001 From: yangyanjun Date: Wed, 17 Aug 2022 11:35:39 +0800 Subject: [PATCH] =?UTF-8?q?1=E3=80=810=E7=AA=97=E5=8F=A3=E9=80=9A=E5=91=8A?= =?UTF-8?q?=E6=9C=BA=E5=88=B6=E4=BC=98=E5=8C=96=EF=BC=8C=E5=8F=AA=E8=A6=81?= =?UTF-8?q?=E6=8E=A5=E6=94=B6=E7=AA=97=E5=8F=A3=E4=B8=8D=E4=B8=BA0?= =?UTF-8?q?=EF=BC=8C=E5=B9=B6=E4=B8=94=E8=83=BD=E5=AE=B9=E7=BA=B3=E5=BD=93?= =?UTF-8?q?=E5=89=8D=E5=8C=85=E9=95=BF=E5=B0=B1=E6=94=B6=E5=8C=85=E3=80=82?= =?UTF-8?q?=202=E3=80=81debug=E8=B0=83=E6=95=B4=EF=BC=8Cpr=5Fcrit/pr=5Ferr?= =?UTF-8?q?=E6=9B=BF=E6=8D=A2=E6=88=90DEBUG=E3=80=82debug=E6=89=93?= =?UTF-8?q?=E5=8D=B0=E4=BC=98=E5=8C=96=E5=A2=9E=E5=8A=A0=E5=8F=AF=E7=BB=B4?= =?UTF-8?q?=E6=8A=A4=E6=80=A7=E3=80=82DEBUG=E5=A2=9E=E5=8A=A0=E5=BC=80?= =?UTF-8?q?=E5=85=B3=E6=8E=A7=E5=88=B6=E3=80=82=203=E3=80=81=E6=96=B0?= =?UTF-8?q?=E5=A2=9E=E7=9F=AD=E5=9C=B0=E5=9D=80=E5=AD=97=E7=AC=A6=E4=B8=B2?= =?UTF-8?q?=E6=A0=BC=E5=BC=8F=E5=8C=96+=E6=8E=A9=E6=8E=89=E9=83=A8?= =?UTF-8?q?=E5=88=86=E6=95=B0=E5=80=BC=E4=BB=A5=E6=BB=A1=E8=B6=B3=E5=AE=89?= =?UTF-8?q?=E5=85=A8=E5=90=88=E8=A7=84=E8=A6=81=E6=B1=82=E3=80=82=204?= =?UTF-8?q?=E3=80=81probe=E6=8E=A2=E6=B5=8B=E6=8A=A5=E6=96=87=E5=8F=91?= =?UTF-8?q?=E9=80=81debug=E5=A2=9E=E5=8A=A0=E6=8A=A5=E6=96=87=E7=B1=BB?= =?UTF-8?q?=E5=9E=8B=EF=BC=8C=E4=B9=8B=E5=89=8D=E6=89=93=E5=8D=B0=E6=97=A0?= =?UTF-8?q?=E6=B3=95=E5=8C=BA=E5=88=86=E6=98=AFka=EF=BC=8C=E8=BF=98?= =?UTF-8?q?=E6=98=AFprobe0=E5=8F=91=E9=80=81=E7=9A=84=E6=8E=A2=E6=B5=8B?= =?UTF-8?q?=E6=8A=A5=E6=96=87=E3=80=82=205=E3=80=81=E5=B0=86keepalive?= =?UTF-8?q?=EF=BC=8Cprope0=E8=B6=85=E6=97=B6=E8=AE=A1=E6=95=B0=E5=8F=98?= =?UTF-8?q?=E9=87=8F=E5=88=86=E5=BC=80=E8=AE=A1=E6=95=B0=EF=BC=8C=E8=A7=A3?= =?UTF-8?q?=E5=86=B3session=E8=87=AA=E5=8A=A8=E6=96=AD=E5=BC=80=E9=97=AE?= =?UTF-8?q?=E9=A2=98=E3=80=82=206=E3=80=81=E5=88=A0=E9=99=A4=E4=B8=8D?= =?UTF-8?q?=E4=BD=BF=E7=94=A8=E7=9A=84nip=E5=8F=82=E6=95=B0=E3=80=82=207?= =?UTF-8?q?=E3=80=81=E5=88=A0=E9=99=A4rtt=E9=9D=9E=E5=B8=B8=E5=A4=A7?= =?UTF-8?q?=E6=97=B6=E7=BC=A9=E7=9F=ADrto=E8=B6=85=E6=97=B6=E5=91=A8?= =?UTF-8?q?=E6=9C=9F=EF=BC=8C=E5=87=8F=E5=B0=91dup=20ack=E5=8F=91=E9=80=81?= =?UTF-8?q?=E6=AC=A1=E6=95=B0=E6=8F=90=E5=8D=87rtt=E6=80=A7=E8=83=BD?= =?UTF-8?q?=E3=80=82=208=E3=80=81=E5=9F=BA=E4=BA=8Eurg=5Fptr=E4=BF=9D?= =?UTF-8?q?=E5=AD=98=E4=B8=A2=E5=8C=85=E4=B8=AA=E6=95=B0=EF=BC=8C=E9=85=8D?= =?UTF-8?q?=E5=90=88dup=20ack=E7=AE=80=E5=8C=96=E7=89=88=E5=8F=AF=E4=BB=A5?= =?UTF-8?q?=E7=B2=BE=E5=87=86=E9=87=8D=E4=BC=A0=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: yangyanjun --- code/common/nip_addr.h | 24 +++ code/linux/include/linux/nip.h | 10 +- code/linux/include/net/nip.h | 30 +-- code/linux/include/net/nip_addrconf.h | 1 + code/linux/include/net/tcp_nip.h | 13 +- code/linux/net/newip/af_ninet.c | 30 ++- code/linux/net/newip/ninet_hashtables.c | 3 - code/linux/net/newip/nip_addrconf.c | 113 ++++++++--- code/linux/net/newip/nip_fib.c | 13 +- code/linux/net/newip/route.c | 2 + code/linux/net/newip/tcp_nip.c | 154 +++++++++++--- code/linux/net/newip/tcp_nip_input.c | 100 +++++---- code/linux/net/newip/tcp_nip_output.c | 171 +++++++++++----- code/linux/net/newip/tcp_nip_parameter.c | 53 ++--- code/linux/net/newip/tcp_nip_parameter.h | 48 +++-- code/linux/net/newip/tcp_nip_timer.c | 81 ++++---- ...urus.flag => hispark_taurus_standard.flag} | 0 patches/linux-5.10/newip.patch | 191 +++++++++++++----- 18 files changed, 699 insertions(+), 338 deletions(-) rename patches/{hispark_taurus.flag => hispark_taurus_standard.flag} (100%) diff --git a/code/common/nip_addr.h b/code/common/nip_addr.h index a22411e..1af3523 100644 --- a/code/common/nip_addr.h +++ b/code/common/nip_addr.h @@ -32,6 +32,8 @@ #define NIP_ADDR_LEN_3 3 #define NIP_ADDR_LEN_4 4 #define NIP_ADDR_LEN_5 5 +#define NIP_ADDR_LEN_7 7 +#define NIP_ADDR_LEN_8 8 #define NIP_ADDR_BIT_LEN_8 8 #define NIP_ADDR_BIT_LEN_16 16 @@ -50,6 +52,7 @@ enum nip_addr_check_value { 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 { @@ -95,8 +98,29 @@ struct nip_addr { unsigned char bitlen; struct nip_addr_field v; }; + #pragma pack() +enum nip_index { + INDEX_0 = 0, + INDEX_1 = 1, + INDEX_2 = 2, + INDEX_3 = 3, + INDEX_4 = 4, + INDEX_5 = 5, + INDEX_6 = 6, + INDEX_7 = 7, + INDEX_8 = 8, + INDEX_9 = 9, + INDEX_10 = 10, + INDEX_11 = 11, + INDEX_12 = 12, + INDEX_13 = 13, + INDEX_14 = 14, + INDEX_15 = 15, + INDEX_MAX, +}; + extern const struct nip_addr nip_any_addr; extern const struct nip_addr nip_broadcast_addr_arp; diff --git a/code/linux/include/linux/nip.h b/code/linux/include/linux/nip.h index d65846a..b663e7b 100644 --- a/code/linux/include/linux/nip.h +++ b/code/linux/include/linux/nip.h @@ -26,13 +26,21 @@ struct nip_devconf { }; /* This structure contains results of exthdrs parsing - * as offsets from skb->nh. + * 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 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] + * sizeof(struct tcp_skb_cb->include skb_parm)=24 | */ #pragma pack(1) 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/include/net/nip.h b/code/linux/include/net/nip.h index 72257c1..e8c1400 100644 --- a/code/linux/include/net/nip.h +++ b/code/linux/include/net/nip.h @@ -131,34 +131,8 @@ 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); -/* 0 - No LOG - * 1 - Logging the kernel (for the official version) - * 2 - Logs are directly printed on the screen for debugging - */ -#define __NIP_DEBUG 0 - -#if __NIP_DEBUG >= 2 -#define TRACE_OUT(fmt, ...) \ - do { \ - pr_crit("%s:%s:%d", __FILE__, __func__, __LINE__); \ - pr_crit(fmt, ##__VA_ARGS__); \ - pr_crit("\n"); \ - } while (0) -#define TRACE(fmt, ...) pr_crit(fmt, ##__VA_ARGS__) -#elif __NIP_DEBUG >= 1 -#define TRACE_OUT(fmt, ...) \ - do { \ - pr_warn("%s:%s:%d", __FILE__, __func__, __LINE__); \ - pr_warn(fmt, ##__VA_ARGS__); \ - pr_warn("\n"); \ - } while (0) -#define TRACE(fmt, ...) pr_warn(fmt, ##__VA_ARGS__) -#else -#define TRACE(fmt, ...) -#define TRACE_OUT(fmt, ...) -#endif -#define DEBUG(format, ...) TRACE(format, ##__VA_ARGS__) -#define DEBUG_TRACE(format, ...) TRACE_OUT(format, ##__VA_ARGS__) +void nip_dbg(const char *fmt, ...); +#define DEBUG(format, ...) nip_dbg(format, ##__VA_ARGS__) #endif diff --git a/code/linux/include/net/nip_addrconf.h b/code/linux/include/net/nip_addrconf.h index 9268601..16214b4 100644 --- a/code/linux/include/net/nip_addrconf.h +++ b/code/linux/include/net/nip_addrconf.h @@ -26,6 +26,7 @@ int nip_dev_get_saddr(struct net *net, const struct net_device *dev, int nip_addrconf_init(void); void nip_addrconf_cleanup(void); +void nip_addr_to_str(const struct nip_addr *addr, unsigned char *buf, int buf_len); /** * __nin_dev_get - get ninet_dev pointer from netdevice diff --git a/code/linux/include/net/tcp_nip.h b/code/linux/include/net/tcp_nip.h index 1e39fd5..7c9cf4f 100644 --- a/code/linux/include/net/tcp_nip.h +++ b/code/linux/include/net/tcp_nip.h @@ -109,9 +109,16 @@ void tcp_nip_write_timer_handler(struct sock *sk); /* check probe0 timer */ static inline void tcp_nip_check_probe_timer(struct sock *sk) { - if (!tcp_sk(sk)->packets_out && !inet_csk(sk)->icsk_pending) - inet_csk_reset_xmit_timer(sk, ICSK_TIME_PROBE0, - tcp_probe0_base(sk), TCP_RTO_MAX); + unsigned long when; + + if (!tcp_sk(sk)->packets_out && !inet_csk(sk)->icsk_pending) { + when = tcp_probe0_base(sk); + DEBUG("%s start probe0 timer, when=%u, RTO MAX=%u", __func__, when, TCP_RTO_MAX); + inet_csk_reset_xmit_timer(sk, ICSK_TIME_PROBE0, when, TCP_RTO_MAX); + } else if (inet_csk(sk)->icsk_pending != ICSK_TIME_PROBE0) { + DEBUG("%s can`t start probe0 timer, packets_out=%u, icsk_pending=%u", + __func__, tcp_sk(sk)->packets_out, inet_csk(sk)->icsk_pending); + } } static inline struct sk_buff *tcp_nip_send_head(const struct sock *sk) diff --git a/code/linux/net/newip/af_ninet.c b/code/linux/net/newip/af_ninet.c index b2fa293..06a7c85 100644 --- a/code/linux/net/newip/af_ninet.c +++ b/code/linux/net/newip/af_ninet.c @@ -596,20 +596,18 @@ out: return ret; out_permanent: - pr_err("Attempt to override permanent protocol %d\n", protocol); + DEBUG("Attempt to override permanent protocol %d", protocol); goto out; out_illegal: - pr_err("Ignoring attempt to register invalid socket type %d\n", - p->type); + DEBUG("Ignoring attempt to register invalid socket type %d", p->type); goto out; } void ninet_unregister_protosw(struct inet_protosw *p) { if (INET_PROTOSW_PERMANENT & p->flags) { - pr_err("Attempt to unregister permanent protocol %d\n", - p->protocol); + DEBUG("Attempt to unregister permanent protocol %d", p->protocol); } else { spin_lock_bh(&inetsw_nip_lock); list_del_rcu(&p->list); @@ -659,14 +657,14 @@ static int __init ninet_init(void) sock_skb_cb_check_size(sizeof(struct ninet_skb_parm)); - DEBUG("NET: start to init nip network.\n"); + DEBUG("NET: start to init nip network."); /* register the socket-side information for ninet_create */ 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\n"); + DEBUG("reboot required to enable"); goto out; } @@ -676,31 +674,31 @@ static int __init ninet_init(void) err = proto_register(&nip_udp_prot, 1); if (err) { - DEBUG_TRACE("failed to register udp proto!\n"); + DEBUG("failed to register udp proto!"); goto out_udp_register_fail; } err = sock_register(&ninet_family_ops); if (err) { - DEBUG_TRACE("failed to register newip_family_ops!"); + DEBUG("failed to register newip_family_ops!"); goto out_sock_register_fail; } err = register_pernet_subsys(&ninet_net_ops); if (err) { - DEBUG_TRACE("failed to register ninet_net_ops!\n"); + DEBUG("failed to register ninet_net_ops!"); goto register_pernet_fail; } err = nip_icmp_init(); if (err) { - DEBUG_TRACE("nip_icmp_init failed!\n"); + DEBUG("nip_icmp_init failed!"); goto nip_icmp_fail; } err = nndisc_init(); if (err) { - DEBUG_TRACE("nndisc_init failed!\n"); + DEBUG("nndisc_init failed!"); goto nndisc_fail; } @@ -714,13 +712,13 @@ static int __init ninet_init(void) err = nip_udp_init(); if (err) { - DEBUG_TRACE("failed to init udp layer!\n"); + DEBUG("failed to init udp layer!"); goto udp_fail; } err = tcp_nip_init(); if (err) { - DEBUG("failed to init tcp layer!\n"); + DEBUG("failed to init tcp layer!"); goto tcp_fail; } else { DEBUG("nip_tcp_init ok!"); @@ -728,7 +726,7 @@ static int __init ninet_init(void) err = nip_packet_init(); if (err) { - DEBUG_TRACE("failed to register to l2 layer!\n"); + DEBUG("failed to register to l2 layer!"); goto nip_packet_fail; } @@ -752,7 +750,7 @@ register_pernet_fail: out_sock_register_fail: proto_unregister(&nip_udp_prot); out_udp_register_fail: - DEBUG_TRACE("newip family init failed!!!\n"); + DEBUG("newip family init failed!!!"); goto out; } diff --git a/code/linux/net/newip/ninet_hashtables.c b/code/linux/net/newip/ninet_hashtables.c index 0e3419b..aca0ec4 100644 --- a/code/linux/net/newip/ninet_hashtables.c +++ b/code/linux/net/newip/ninet_hashtables.c @@ -222,8 +222,6 @@ struct sock *__ninet_lookup_established(struct net *net, begin: sk_nulls_for_each_rcu(sk, node, &head->chain) { - DEBUG("%s: sk->sk_hash:%u", __func__, sk->sk_hash); - DEBUG("%s: dif:%d", __func__, dif); if (sk->sk_hash != hash) continue; if (!NINET_MATCH(sk, net, saddr, daddr, ports, dif)) @@ -237,7 +235,6 @@ begin: sock_gen_put(sk); goto begin; } - DEBUG("%s: find sock in ehash table!", __func__); goto found; } if (get_nulls_value(node) != slot) diff --git a/code/linux/net/newip/nip_addrconf.c b/code/linux/net/newip/nip_addrconf.c index 69c3bb9..f0e5f8b 100644 --- a/code/linux/net/newip/nip_addrconf.c +++ b/code/linux/net/newip/nip_addrconf.c @@ -49,7 +49,7 @@ static bool nip_chk_same_addr(struct net *net, const struct nip_addr *addr, struct net_device *dev); static int nip_get_firstaddr(const struct net_device *dev, struct nip_addr *addr); -static int nip_addrconf_ifdown(struct net_device *dev, int how); +static int nip_addrconf_ifdown(struct net_device *dev, bool unregister); static struct nip_devconf newip_devconf_dflt __read_mostly = { .forwarding = 0, @@ -102,14 +102,14 @@ static struct ninet_ifaddr *nip_add_addr(struct ninet_dev *idev, /* Do not configure two same addresses in a netdevice */ if (nip_chk_same_addr(dev_net(idev->dev), addr, idev->dev)) { - DEBUG("%s: already assigned\n", __func__); + DEBUG("%s: already assigned", __func__); err = -EEXIST; goto out; } ifa = kzalloc(sizeof(*ifa), GFP_ATOMIC); if (!ifa) { - DEBUG("%s: malloc failed\n", __func__); + DEBUG("%s: malloc failed", __func__); err = -ENOBUFS; goto out; } @@ -154,7 +154,7 @@ out2: rcu_read_unlock_bh(); if (likely(err == 0)) { - DEBUG("%s: success! idev->refcnt=%u\n", __func__, + DEBUG("%s: success! idev->refcnt=%u", __func__, refcount_read(&idev->refcnt)); } else { kfree(ifa); @@ -199,7 +199,7 @@ static struct ninet_dev *nip_add_dev(struct net_device *dev) refcount_set(&ndev->refcnt, 1); - DEBUG("%s: init ninet_dev success!, set ndev->refcnt=1\n", __func__); + DEBUG("%s: init ninet_dev success!, set ndev->refcnt=1", __func__); if (netif_running(dev) && nip_addrconf_link_ready(dev)) ndev->if_flags |= IF_READY; @@ -291,8 +291,7 @@ static int ninet_addr_add(struct net *net, int ifindex, if (!IS_ERR(ifp)) { nin_ifa_put(ifp); nip_ins_rt(ifp->rt); - DEBUG("%s: success! ifp->refcnt=%u\n", __func__, - refcount_read(&ifp->refcnt)); + DEBUG("%s: success! ifp->refcnt=%u", __func__, refcount_read(&ifp->refcnt)); return 0; } @@ -304,7 +303,7 @@ void ninet_ifa_finish_destroy(struct ninet_ifaddr *ifp) { WARN_ON(!hlist_unhashed(&ifp->addr_lst)); - DEBUG("%s: before idev put. idev->refcnt=%u\n", __func__, + DEBUG("%s: before idev put. idev->refcnt=%u", __func__, refcount_read(&ifp->idev->refcnt)); nin_dev_put(ifp->idev); @@ -584,7 +583,7 @@ static int nip_addrconf_notify(struct notifier_block *this, unsigned long event, if (!nip_addrconf_link_ready(dev)) { /* device is not ready yet. */ DEBUG("NIP_ADDRCONF(NETDEV_UP): "); - DEBUG("%s:link is not ready\n", dev->name); + DEBUG("%s:link is not ready", dev->name); break; } @@ -603,7 +602,7 @@ static int nip_addrconf_notify(struct notifier_block *this, unsigned long event, idev->if_flags |= IF_READY; DEBUG("NIP_ADDRCONF(NETDEV_CHANGE):"); - DEBUG("%s:link becomes ready\n", dev->name); + DEBUG("%s:link becomes ready", dev->name); } if (!IS_ERR_OR_NULL(idev)) { @@ -621,8 +620,7 @@ static int nip_addrconf_notify(struct notifier_block *this, unsigned long event, * NIP_MIN_MTU stop New IP on this interface. */ if (dev->mtu < NIP_MIN_MTU) - nip_addrconf_ifdown(dev, - dev != net->loopback_dev); + nip_addrconf_ifdown(dev, dev != net->loopback_dev); } break; @@ -638,16 +636,19 @@ static int nip_addrconf_notify(struct notifier_block *this, unsigned long event, return NOTIFY_OK; } -static int nip_addrconf_ifdown(struct net_device *dev, int how) +static int nip_addrconf_ifdown(struct net_device *dev, bool unregister) { struct net *net = dev_net(dev); struct ninet_dev *idev = __nin_dev_get(dev); struct ninet_ifaddr *ifa, *tmp; struct list_head del_list; - int state, i; + int i; ASSERT_RTNL(); + DEBUG("%s: %s ifindex=%u, unregister=%u (unregister:1, down:0)", + __func__, dev->name, dev->ifindex, unregister); + nip_rt_ifdown(net, dev); neigh_ifdown(&nnd_tbl, dev); if (!idev) @@ -656,7 +657,7 @@ static int nip_addrconf_ifdown(struct net_device *dev, int how) /* Step 1: remove reference to newip device from parent device. * Do not dev_put! */ - if (how) { + if (unregister) { idev->dead = 1; /* protected by rtnl_lock */ @@ -669,8 +670,13 @@ static int nip_addrconf_ifdown(struct net_device *dev, int how) spin_lock_bh(&addrconf_hash_lock); hlist_for_each_entry_rcu(ifa, h, addr_lst) { - if (ifa->idev == idev) + if (ifa->idev == idev) { + char addr[NIP_8BIT_ADDR_INDEX_MAX] = {0}; + + nip_addr_to_str(&ifa->addr, addr, NIP_8BIT_ADDR_INDEX_MAX); + DEBUG("%s: clear addr hash table.(addr=%s)", __func__, addr); hlist_del_init_rcu(&ifa->addr_lst); + } } spin_unlock_bh(&addrconf_hash_lock); } @@ -678,26 +684,25 @@ static int nip_addrconf_ifdown(struct net_device *dev, int how) write_lock_bh(&idev->lock); /* Step 2: clear flags for stateless addrconf */ - if (!how) + if (!unregister) idev->if_flags &= ~(IF_RS_SENT | IF_RA_RCVD | IF_READY); - /* Step 3: clear addr list in idev */ + /* Step 3: Remove address node from ifa->if_list + * and insert it into the list to be del_list + */ INIT_LIST_HEAD(&del_list); list_for_each_entry_safe(ifa, tmp, &idev->addr_list, if_list) { list_move(&ifa->if_list, &del_list); write_unlock_bh(&idev->lock); spin_lock_bh(&ifa->lock); - - state = ifa->state; ifa->state = NINET_IFADDR_STATE_DEAD; - spin_unlock_bh(&ifa->lock); write_lock_bh(&idev->lock); } write_unlock_bh(&idev->lock); - /* now clean up addresses to be removed */ + /* Step 4: Unchain the node to be deleted and release IFA */ while (!list_empty(&del_list)) { ifa = list_first_entry(&del_list, struct ninet_ifaddr, if_list); list_del(&ifa->if_list); @@ -705,11 +710,11 @@ static int nip_addrconf_ifdown(struct net_device *dev, int how) } /* Last: Shot the device (if unregistered) */ - if (how) { + if (unregister) { neigh_parms_release(&nnd_tbl, idev->nd_parms); neigh_ifdown(&nnd_tbl, dev); - DEBUG("%s: before idev put. idev->refcnt=%u\n", __func__, - refcount_read(&idev->refcnt)); + DEBUG("%s: %s (ifindex=%u) before idev put. idev->refcnt=%u", __func__, + dev->name, dev->ifindex, refcount_read(&idev->refcnt)); nin_dev_put(idev); } return 0; @@ -790,7 +795,7 @@ int __init nip_addrconf_init(void) err = register_pernet_subsys(&nip_route_proc_net_ops); if (err < 0) { - DEBUG("%s: register_pernet_subsys failed!\n", __func__); + DEBUG("%s: register_pernet_subsys failed!", __func__); goto out; } @@ -883,3 +888,59 @@ done: out: return ret; } + +void nip_addr_to_str(const struct nip_addr *addr, unsigned char *buf, int buf_len) +{ + int i; + int len = 0; + int total_len = 0; + int addr_num = addr->bitlen / NIP_ADDR_BIT_LEN_8; + + if (!buf) + return; + + total_len = sprintf(buf, "%s", "0x"); + for (i = 0; (i < addr_num) && (total_len < buf_len); i++) { + len = sprintf(buf + total_len, "%02x", addr->nip_addr_field8[i]); + if (len <= 0) + break; + total_len += len; + } + + switch (addr_num) { + case NIP_ADDR_LEN_1: + buf[INDEX_2] = '*'; /* 0x*0 ~ 0x*C */ + break; + case NIP_ADDR_LEN_2: + buf[INDEX_2] = '*'; /* 0x**DD ~ 0x**FF */ + buf[INDEX_3] = '*'; + break; + case NIP_ADDR_LEN_3: + buf[INDEX_4] = '*'; /* 0xF1**00 ~ 0xF1**FF */ + buf[INDEX_5] = '*'; + break; + case NIP_ADDR_LEN_5: + buf[INDEX_4] = '*'; /* 0xF2 **** 0000 ~ 0xF2 **** FFFF */ + buf[INDEX_5] = '*'; + buf[INDEX_6] = '*'; + buf[INDEX_7] = '*'; + break; + case NIP_ADDR_LEN_7: + buf[INDEX_4] = '*'; /* 0xF3 **** 0000 0000 ~ 0xF3 **** FFFF FFFF */ + buf[INDEX_5] = '*'; + buf[INDEX_6] = '*'; + buf[INDEX_7] = '*'; + break; + case NIP_ADDR_LEN_8: + buf[INDEX_4] = '*'; /* 0xF4** **** 0000 0000 ~ 0xF4** **** FFFF FFFF */ + buf[INDEX_5] = '*'; + buf[INDEX_6] = '*'; + buf[INDEX_7] = '*'; + buf[INDEX_8] = '*'; + buf[INDEX_9] = '*'; + break; + default: + break; + } +} + diff --git a/code/linux/net/newip/nip_fib.c b/code/linux/net/newip/nip_fib.c index 14750ea..eefd81e 100644 --- a/code/linux/net/newip/nip_fib.c +++ b/code/linux/net/newip/nip_fib.c @@ -189,7 +189,16 @@ 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) { - DEBUG("%s: try to del nip_rt_info\n", __func__); + char dst[NIP_8BIT_ADDR_INDEX_MAX] = {0}; + char gateway[NIP_8BIT_ADDR_INDEX_MAX] = {0}; + + nip_addr_to_str(&fn->nip_route_info->rt_dst, dst, + NIP_8BIT_ADDR_INDEX_MAX); + nip_addr_to_str(&fn->nip_route_info->gateway, gateway, + NIP_8BIT_ADDR_INDEX_MAX); + + DEBUG("%s: try to del rt_info, rt_dst=%s, gateway=%s", + __func__, dst, gateway); nip_fib_del(fn->nip_route_info, &info); } } @@ -271,7 +280,7 @@ int __init nip_fib_init(void) if (!nip_fib_node_kmem) goto out; - DEBUG("nip_fib_node size is %lu\n", + DEBUG("nip_fib_node size is %lu", sizeof(struct nip_fib_node) + sizeof(struct nip_rt_info)); ret = register_pernet_subsys(&nip_fib_net_ops); diff --git a/code/linux/net/newip/route.c b/code/linux/net/newip/route.c index 5f637af..6fe8365 100644 --- a/code/linux/net/newip/route.c +++ b/code/linux/net/newip/route.c @@ -759,6 +759,8 @@ static int nip_fib_ifdown(struct nip_rt_info *rt, void *arg) !rt->rt_idev->cnf.ignore_routes_with_linkdown)) return -1; + DEBUG("%s: don`t del route with %s down, ifindex=%u", + __func__, dev->name, dev->ifindex); return 0; } diff --git a/code/linux/net/newip/tcp_nip.c b/code/linux/net/newip/tcp_nip.c index 7333d4e..2140e6e 100644 --- a/code/linux/net/newip/tcp_nip.c +++ b/code/linux/net/newip/tcp_nip.c @@ -680,25 +680,65 @@ static int tcp_nip_keepalive_para_update(struct sock *sk, return 0; } +#define NIP_PKT_TOTAL_LEN_BOUNDARY 100000 // 100K +#define NIP_KEEPALIVE_PROBES 255 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 (tp->nip_keepalive_enable) + if (!skb) return; - ret = tcp_nip_keepalive_para_update(sk, g_nip_keepalive_time, + 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) { + tp->keepalive_time_bak = tp->keepalive_time; + tp->keepalive_probes_bak = tp->keepalive_probes; + tp->keepalive_intvl_bak = tp->keepalive_intvl; + + 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, + g_nip_keepalive_intvl); + + tp->keepalive_time = 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); + } + return; + } + + /* If keepalive set by setsockopt, backup para */ + if (sock_flag(sk, SOCK_KEEPOPEN)) { + tp->keepalive_time_bak = tp->keepalive_time; + tp->keepalive_probes_bak = tp->keepalive_probes; + tp->keepalive_intvl_bak = tp->keepalive_intvl; + DEBUG("%s HZ=%u, backup normal time/probes/intvl [%u, %u, %u]", __func__, + HZ, tp->keepalive_time, tp->keepalive_probes, tp->keepalive_intvl); + } + + /* change para to nip para */ + ret = tcp_nip_keepalive_para_update(sk, nip_keepalive_time, g_nip_keepalive_intvl, - g_nip_keepalive_probes); + NIP_KEEPALIVE_PROBES); if (ret != 0) { - DEBUG("%s fail, ka_time=%u, ka_probes=%u, ka_intvl=%u", __func__, - tp->keepalive_time, tp->keepalive_probes, tp->keepalive_intvl); + DEBUG("%s fail, HZ=%u, time/probes/intvl [%u, %u, %u]", __func__, + HZ, tp->keepalive_time, tp->keepalive_probes, tp->keepalive_intvl); return; } - DEBUG("%s ok, ka_time=%u, ka_probes=%u, ka_intvl=%u", __func__, - tp->keepalive_time, tp->keepalive_probes, tp->keepalive_intvl); + pr_crit("%s ok, HZ=%u, time/probes/intvl [%u, %u, %u], pkt_total_len=%u", + __func__, HZ, tp->keepalive_time, tp->keepalive_probes, + tp->keepalive_intvl, pkt_len); tp->nip_keepalive_enable = true; } @@ -709,16 +749,65 @@ void tcp_nip_keepalive_disable(struct sock *sk) if (!tp->nip_keepalive_enable) return; + if (!sock_flag(sk, SOCK_KEEPOPEN)) { + tp->nip_keepalive_enable = false; + DEBUG("%s ok, HZ=%u, normal ka has disable.", __func__, HZ); + return; + } + if (tp->idle_ka_probes_out < g_nip_idle_ka_probes_out) return; + /* newip keepalive change to normal keepalive */ + if (tp->keepalive_time_bak) { + DEBUG("%s HZ=%u, change normal time/probes/intvl [%u, %u, %u] to [%u, %u, %u].", + __func__, HZ, tp->keepalive_time, tp->keepalive_probes, + tp->keepalive_intvl, tp->keepalive_time_bak, tp->keepalive_probes_bak, + tp->keepalive_intvl_bak); + tp->keepalive_time = tp->keepalive_time_bak; + tp->keepalive_probes = tp->keepalive_probes_bak; + tp->keepalive_intvl = tp->keepalive_intvl_bak; + inet_csk_reset_keepalive_timer(sk, tp->keepalive_time); + return; + } + + tp->keepalive_time_bak = 0; + tp->keepalive_probes_bak = 0; + tp->keepalive_intvl_bak = 0; + /* enable keepalive (SO_KEEPALIVE) */ if (sk->sk_prot->keepalive) sk->sk_prot->keepalive(sk, 0); sock_valbool_flag(sk, SOCK_KEEPOPEN, 0); - DEBUG("%s ok, idle_ka_probes_out=%u", __func__, g_nip_idle_ka_probes_out); + DEBUG("%s ok, HZ=%u, idle_ka_probes_out=%u", __func__, HZ, g_nip_idle_ka_probes_out); + tp->nip_keepalive_enable = false; +} + +static void tcp_nip_rtt_init(struct sock *sk) +{ + struct tcp_sock *tp = tcp_sk(sk); + + tp->sacked_out = 0; + tp->rcv_tstamp = 0; + tp->selective_acks[0].start_seq = 0; + tp->selective_acks[0].end_seq = 0; + tp->ack_retrans_seq = 0; + tp->ack_retrans_num = 0; + tp->nip_ssthresh = g_nip_ssthresh_default; + tp->nip_ssthresh_reset = 0; + tp->last_rcv_nxt = 0; + tp->dup_ack_cnt = 0; + tp->nip_keepalive_enable = false; + tp->nip_keepalive_out = 0; + tp->idle_ka_probes_out = 0; + tp->keepalive_time = 0; + tp->keepalive_probes = 0; + tp->keepalive_intvl = 0; + tp->keepalive_time_bak = 0; + tp->keepalive_probes_bak = 0; + tp->keepalive_intvl_bak = 0; } /* Function @@ -749,19 +838,7 @@ static int tcp_nip_init_sock(struct sock *sk) tp->snd_cwnd_clamp = ~0; tp->mss_cache = TCP_MSS_DEFAULT; - tp->sacked_out = 0; - tp->rcv_tstamp = 0; - tp->selective_acks[0].start_seq = 0; - tp->selective_acks[0].end_seq = 0; - tp->ack_retrans_seq = 0; - tp->ack_retrans_num = 0; - tp->nip_ssthresh = g_nip_ssthresh_default; - tp->nip_ssthresh_reset = 0; - tp->nip_keepalive_enable = false; - tp->idle_ka_probes_out = 0; - tp->nip_keepalive_timeout_scale = 0; - tp->last_rcv_nxt = 0; - tp->dup_ack_cnt = 0; + tcp_nip_rtt_init(sk); tp->reordering = sock_net(sk)->ipv4.sysctl_tcp_reordering; tp->tsoffset = 0; @@ -831,8 +908,6 @@ int tcp_nip_send_mss(struct sock *sk, int *size_goal, int flags) mss_now = tcp_nip_current_mss(sk); *size_goal = tcp_xmit_size_goal(sk, mss_now, !(flags & MSG_OOB)); - - DEBUG("%snip_send_mss%d", __func__, mss_now); return mss_now; } @@ -866,7 +941,7 @@ int tcp_nip_sendmsg(struct sock *sk, struct msghdr *msg, size_t size) restart: mss_now = tcp_nip_send_mss(sk, &size_goal, flags); - DEBUG("%s: tcp_nip_send_mss %d", __func__, mss_now); + DEBUG("%s: mss_now=%d", __func__, mss_now); err = -EPIPE; if (sk->sk_err || (sk->sk_shutdown & SEND_SHUTDOWN)) @@ -892,6 +967,7 @@ restart: skb->tstamp = 0; process_backlog = true; + NIPCB(skb)->pkt_total_len = size; skb_nip_entail(sk, skb); copy = mss_now; @@ -1431,7 +1507,6 @@ static void tcp_nip_early_demux(struct sk_buff *skb) &NIPCB(skb)->srcaddr, th->source, &NIPCB(skb)->dstaddr, ntohs(th->dest), skb->skb_iif); if (sk) { - DEBUG("%s: find related sock in ehash.", __func__); skb->sk = sk; skb->destructor = sock_edemux; if (sk_fullsock(sk)) { @@ -1439,7 +1514,7 @@ static void tcp_nip_early_demux(struct sk_buff *skb) if (dst && inet_sk(sk)->rx_dst_ifindex == skb->skb_iif) { - DEBUG("%s: set dst for skb.", __func__); + DEBUG("%s: find sock in ehash, set dst for skb", __func__); skb_dst_set_noref(skb, dst); } } @@ -1520,6 +1595,8 @@ int tcp_nip_disconnect(struct sock *sk, int flags) __skb_queue_purge(&sk->sk_receive_queue); tcp_write_queue_purge(sk); + tcp_nip_rtt_init(sk); + inet->inet_dport = 0; sk->sk_shutdown = 0; sock_reset_flag(sk, SOCK_DONE); @@ -1654,3 +1731,28 @@ void tcp_nip_exit(void) ninet_del_protocol(&tcp_nip_protocol, IPPROTO_TCP); } +#define LOG_PRINT_MAX_LEN 256 +void nip_dbg(const char *fmt, ...) +{ + u32 pos; + char str[LOG_PRINT_MAX_LEN]; + va_list args; + s32 ret; + + if (!g_nip_debug) + return; + + memset(str, 0, sizeof(str)); + pos = strlen(str); + (void)memset(&args, 0, sizeof(va_list)); + va_start(args, fmt); + ret = vsnprintf(str, sizeof(str), fmt, args) + 1; + va_end(args); + if (ret < 0 || ret > sizeof(str)) { + pr_crit("nip log len error"); + return; + } + + pr_crit("%s", str); +} + diff --git a/code/linux/net/newip/tcp_nip_input.c b/code/linux/net/newip/tcp_nip_input.c index ee7271b..d817f75 100644 --- a/code/linux/net/newip/tcp_nip_input.c +++ b/code/linux/net/newip/tcp_nip_input.c @@ -97,8 +97,7 @@ void tcp_nip_fin(struct sock *sk) /* Only TCP_LISTEN and TCP_CLOSE are left, in these * cases we should never reach this piece of code. */ - pr_err("%s: Impossible, sk->sk_state=%d", - __func__, sk->sk_state); + DEBUG("%s: Impossible, sk->sk_state=%d", __func__, sk->sk_state); break; } @@ -213,6 +212,8 @@ static void tcp_nip_data_queue(struct sock *sk, struct sk_buff *skb) int mss = tcp_nip_current_mss(sk); struct tcp_sock *tp = tcp_sk(sk); struct inet_connection_sock *icsk = inet_csk(sk); + u32 cur_win = tcp_receive_window(tp); + u32 seq_max = tp->rcv_nxt + cur_win; /* Newip Urg_ptr is disabled. Urg_ptr is used to carry the number of discarded packets */ tp->snd_up = (TCP_SKB_CB(skb)->seq - tcp_sk(sk)->rcv_nxt) / mss; @@ -225,38 +226,55 @@ static void tcp_nip_data_queue(struct sock *sk, struct sk_buff *skb) } if (TCP_SKB_CB(skb)->seq == tp->rcv_nxt) { - if (tcp_receive_window(tp) == 0) + if (cur_win == 0) { + DEBUG("%s: rcv window is 0.", __func__); goto out_of_window; + } } - if (!before(TCP_SKB_CB(skb)->seq, tp->rcv_wup + tp->rcv_wnd)) { - DEBUG("seq is %u and %u", TCP_SKB_CB(skb)->seq, tp->rcv_nxt); - __kfree_skb(skb); - return; + /* Out of window. F.e. zero window probe. */ + if (!before(TCP_SKB_CB(skb)->seq, seq_max)) { + DEBUG("%s: out of rcv win, seq=[%u-%u], rcv_nxt=%u, seq_max=%u", + __func__, TCP_SKB_CB(skb)->seq, TCP_SKB_CB(skb)->end_seq, + tp->rcv_nxt, seq_max); + goto out_of_window; } if (!after(TCP_SKB_CB(skb)->end_seq, tp->rcv_nxt)) { + /* A retransmit, 2nd most common case. Force an immediate ack. */ + DEBUG("%s: rcv retransmit pkt, seq=[%u-%u], rcv_nxt=%u", + __func__, TCP_SKB_CB(skb)->seq, TCP_SKB_CB(skb)->end_seq, tp->rcv_nxt); out_of_window: inet_csk_schedule_ack(sk); - __kfree_skb(skb); + tcp_drop(sk, skb); return; } icsk->icsk_ack.lrcvtime = tcp_jiffies32; __skb_pull(skb, tcp_hdr(skb)->doff * TCP_NUM_4); + if (cur_win == 0 || after(TCP_SKB_CB(skb)->end_seq, seq_max)) { + DEBUG("%s: win lack, drop pkt, seq=[%u-%u], seq_max=%u, rmem_alloc/rcvbuf=[%u:%u]", + __func__, TCP_SKB_CB(skb)->seq, TCP_SKB_CB(skb)->end_seq, + seq_max, atomic_read(&sk->sk_rmem_alloc), sk->sk_rcvbuf); + /* wake up processes that are blocked for lack of data */ + sk->sk_data_ready(sk); + inet_csk_schedule_ack(sk); + tcp_drop(sk, skb); + return; + } + + /* case1: seq == rcv_next + * case2: seq -- rcv_next -- end_seq ==> rcv_next(seq) -- end_seq + */ if (TCP_SKB_CB(skb)->seq == tp->rcv_nxt || (before(TCP_SKB_CB(skb)->seq, tp->rcv_nxt) && after(TCP_SKB_CB(skb)->end_seq, tp->rcv_nxt))) { - if (atomic_read(&sk->sk_rmem_alloc) > sk->sk_rcvbuf) { - sk->sk_data_ready(sk); - tcp_drop(sk, skb); - return; - } - if (TCP_SKB_CB(skb)->seq != tp->rcv_nxt) tcp_nip_overlap_handle(tp, skb); - DEBUG("%s: tcp newip packet received. data len:%d", __func__, skb->len); + DEBUG("%s: newip packet received. seq=[%u-%u], rcv_nxt=%u, skb->len=%u", + __func__, TCP_SKB_CB(skb)->seq, TCP_SKB_CB(skb)->end_seq, + tp->rcv_nxt, skb->len); __skb_queue_tail(&sk->sk_receive_queue, skb); skb_set_owner_r(skb, sk); @@ -270,6 +288,11 @@ out_of_window: sk->sk_data_ready(sk); return; } + + DEBUG("%s: newip ofo packet received. seq=[%u-%u], rcv_nxt=%u, skb->len=%u", + __func__, TCP_SKB_CB(skb)->seq, TCP_SKB_CB(skb)->end_seq, + tp->rcv_nxt, skb->len); + tcp_nip_data_queue_ofo(sk, skb); } @@ -319,6 +342,7 @@ void tcp_nip_send_delayed_ack(struct sock *sk) if (icsk->icsk_ack.pending & ICSK_ACK_TIMER) { if (time_before_eq(icsk->icsk_ack.timeout, jiffies + (ato >> TCP_NIP_4BYTE_PAYLOAD))) { + DEBUG("%s: ok", __func__); tcp_nip_send_ack(sk); return; } @@ -326,6 +350,7 @@ void tcp_nip_send_delayed_ack(struct sock *sk) if (!time_before(timeout, icsk->icsk_ack.timeout)) timeout = icsk->icsk_ack.timeout; } + icsk->icsk_ack.pending |= ICSK_ACK_SCHED | ICSK_ACK_TIMER; icsk->icsk_ack.timeout = timeout; sk_reset_timer(sk, &icsk->icsk_delack_timer, timeout); @@ -351,12 +376,13 @@ static void __tcp_nip_ack_snd_check(struct sock *sk, int ofo_possible) } if (tp->dup_ack_cnt < g_dup_ack_snd_max) tcp_nip_send_ack(sk); + else if (tp->dup_ack_cnt % g_dup_ack_snd_max == 0) + tcp_nip_send_ack(sk); } else { tcp_nip_send_ack(sk); } } else { /* Else, send delayed ack. */ - DEBUG("%s: send delayed ack!!", __func__); tcp_nip_send_delayed_ack(sk); } } @@ -389,8 +415,7 @@ void tcp_nip_rearm_rto(struct sock *sk) } else { u32 rto = inet_csk(sk)->icsk_rto; - inet_csk_reset_xmit_timer(sk, ICSK_TIME_RETRANS, rto, - TCP_RTO_MAX); + inet_csk_reset_xmit_timer(sk, ICSK_TIME_RETRANS, rto, TCP_RTO_MAX); } } @@ -430,11 +455,7 @@ static int tcp_nip_clean_rtx_queue(struct sock *sk, ktime_t *skb_snd_tstamp) sk_wmem_free_skb(sk, skb); } - if ((*skb_snd_tstamp != 0) && (tp->rcv_tstamp - *skb_snd_tstamp) >= g_rtt_tstamp_rto_up) - icsk->icsk_rto = (unsigned int)(HZ / g_nip_rto_up); - else - icsk->icsk_rto = (unsigned int)(HZ / g_nip_rto); - + icsk->icsk_rto = (unsigned int)(HZ / g_nip_rto); if (flag & FLAG_ACKED) tcp_nip_rearm_rto(sk); return 0; @@ -875,6 +896,7 @@ static int tcp_nip_ack_update_window(struct sock *sk, const struct sk_buff *skb, tcp_update_wl(tp, ack_seq); if (tp->snd_wnd != nwin) { + DEBUG("%s snd_wnd change [%u to %u]", __func__, tp->snd_wnd, nwin); tp->snd_wnd = nwin; tp->pred_flags = 0; } @@ -893,15 +915,19 @@ static void tcp_nip_ack_probe(struct sock *sk) if (!after(TCP_SKB_CB(tcp_nip_send_head(sk))->end_seq, tcp_wnd_end(tp))) { icsk->icsk_backoff = 0; + DEBUG("%s stop probe0 timer.", __func__); inet_csk_clear_xmit_timer(sk, ICSK_TIME_PROBE0); /* Socket must be waked up by subsequent tcp_data_snd_check(). * This function is not for random using! */ } else { unsigned long when = tcp_probe0_when(sk, TCP_RTO_MAX); + unsigned long base_when = tcp_probe0_base(sk); + u8 icsk_backoff = inet_csk(sk)->icsk_backoff; - inet_csk_reset_xmit_timer(sk, ICSK_TIME_PROBE0, - when, TCP_RTO_MAX); + DEBUG("%s start probe0 timer, when=%u, RTO MAX=%u, base_when=%u, icsk_backoff=%u", + __func__, when, TCP_RTO_MAX, base_when, icsk_backoff); + inet_csk_reset_xmit_timer(sk, ICSK_TIME_PROBE0, when, TCP_RTO_MAX); } } @@ -1111,17 +1137,19 @@ static int tcp_nip_ack(struct sock *sk, const struct sk_buff *skb, int flag) return -1; flag |= tcp_nip_ack_update_window(sk, skb, ack, ack_seq); + icsk->icsk_probes_out = 0; // probe0 cnt + tp->nip_keepalive_out = 0; // keepalive cnt + tp->rcv_tstamp = tcp_jiffies32; + /* maybe zero window probe */ if (!prior_packets) { - DEBUG("No prior pack and ack is %u", ack); + DEBUG("%s: no unack pkt, seq=[%u-%u], rcv_nxt=%u, ack=%u", + __func__, TCP_SKB_CB(skb)->seq, TCP_SKB_CB(skb)->end_seq, tp->rcv_nxt, ack); if (tcp_nip_send_head(sk)) tcp_nip_ack_probe(sk); + return 1; } - icsk->icsk_probes_out = 0; - tp->nip_keepalive_timeout_scale = 0; - tp->rcv_tstamp = tcp_jiffies32; - if (after(ack, prior_snd_una)) { icsk->icsk_retransmits = 0; tp->retrans_stamp = tcp_time_stamp(tp); @@ -1190,7 +1218,7 @@ static void tcp_nip_send_dupack(struct sock *sk, const struct sk_buff *skb) before(TCP_SKB_CB(skb)->seq, tp->rcv_nxt)) { NET_INC_STATS(sock_net(sk), LINUX_MIB_DELAYEDACKLOST); } - DEBUG("[nip]%s send dupack!", __func__); + DEBUG("%s send dup ack.", __func__); tcp_nip_send_ack(sk); } @@ -1213,12 +1241,14 @@ static bool tcp_nip_validate_incoming(struct sock *sk, struct sk_buff *skb, bool rst_seq_match = false; /* Step 1: check sequence number */ - /* Check for unexpected packets. For some probe packets, - * unexpected packets do not need to be processed, but reply for an ACK + /* 01.Check for unexpected packets. For some probe packets, + * unexpected packets do not need to be processed, but reply for an ACK. + * 02.Enter this branch when the receive window is 0 */ if (!tcp_nip_sequence(tp, TCP_SKB_CB(skb)->seq, TCP_SKB_CB(skb)->end_seq)) { - DEBUG("%s receive an err seq and seq is %u, ack is %u", __func__, - TCP_SKB_CB(skb)->seq, TCP_SKB_CB(skb)->end_seq); + DEBUG("%s receive unexpected pkt, drop it. seq=[%u-%u], rec_win=[%u-%u]", + __func__, TCP_SKB_CB(skb)->seq, TCP_SKB_CB(skb)->end_seq, + tp->rcv_wup, tp->rcv_nxt + tcp_receive_window(tp)); if (!th->rst) tcp_nip_send_dupack(sk, skb); else if (tcp_nip_reset_check(sk, skb)) diff --git a/code/linux/net/newip/tcp_nip_output.c b/code/linux/net/newip/tcp_nip_output.c index a216cff..f11b422 100644 --- a/code/linux/net/newip/tcp_nip_output.c +++ b/code/linux/net/newip/tcp_nip_output.c @@ -142,46 +142,36 @@ void __tcp_nip_push_pending_frames(struct sock *sk, unsigned int cur_mss, if (unlikely(sk->sk_state == TCP_CLOSE)) return; - if (tcp_nip_write_xmit(sk, cur_mss, nonagle, 0, - sk_gfp_mask(sk, GFP_ATOMIC))) { - DEBUG("%s check probe0 timer!", __func__); + if (tcp_nip_write_xmit(sk, cur_mss, nonagle, 0, sk_gfp_mask(sk, GFP_ATOMIC))) tcp_nip_check_probe_timer(sk); - } } u32 __nip_tcp_select_window(struct sock *sk) { struct inet_connection_sock *icsk = inet_csk(sk); struct tcp_sock *tp = tcp_sk(sk); - int mss = tcp_nip_current_mss(sk); // TCP_BASE_MSS - int free_space; - int allowed_space; - int full_space; + int mss = tcp_nip_current_mss(sk); /* TCP_BASE_MSS */ + int allowed_space = tcp_full_space(sk); + int full_space = min_t(int, tp->window_clamp, allowed_space); /* Total receive cache */ + int free_space = tcp_space(sk); /* 3/4 remaining receive cache */ int window; - if (g_rcv_win_max) { - allowed_space = g_rcv_win_max; - full_space = allowed_space; - WRITE_ONCE(sk->sk_rcvbuf, g_nip_rcvbuf); - free_space = tcp_space(sk); - } else { - allowed_space = tcp_full_space(sk); - full_space = min_t(int, tp->window_clamp, allowed_space); - free_space = tcp_space(sk); - } - if (unlikely(mss > full_space)) { mss = full_space; if (mss <= 0) return 0; } + /* receive buffer is half full */ if (free_space < (full_space >> 1)) { icsk->icsk_ack.quick = 0; free_space = round_down(free_space, 1 << tp->rx_opt.rcv_wscale); - if (free_space < (allowed_space >> TCP_NUM_4) || free_space < mss) + if (free_space < (allowed_space >> TCP_NUM_4) || free_space < mss) { + DEBUG("%s rcv_wnd is 0, [allowed|full|free]space=[%u, %u, %u], mss=%u", + __func__, allowed_space, full_space, free_space, mss); return 0; + } } if (g_nip_tcp_rcv_win_enable) { @@ -193,50 +183,94 @@ u32 __nip_tcp_select_window(struct sock *sk) free_space = free_space > g_ssthresh_high ? g_ssthresh_high : free_space; } - window = tp->rcv_wnd; + /* Don't do rounding if we are using window scaling, since the + * scaled window will not line up with the MSS boundary anyway. + */ if (tp->rx_opt.rcv_wscale) { window = free_space; - if (((window >> tp->rx_opt.rcv_wscale) << tp->rx_opt.rcv_wscale) != window) - window = (((window >> tp->rx_opt.rcv_wscale) + 1) - << tp->rx_opt.rcv_wscale); + + /* Advertise enough space so that it won't get scaled away. + * Import case: prevent zero window announcement if + * 1< mss. + */ + window = ALIGN(window, (1 << tp->rx_opt.rcv_wscale)); + 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 = (free_space / mss) * mss; + 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; } +/* The basic algorithm of window size selection: + * 1. Calculate the remaining size of the receiving window cur_win. + * 2. Calculate the new receive window size NEW_win, which is 3/4 of the remaining receive + * cache and cannot exceed RCV_SSTHresh. + * 3. Select the receiving window size with the larger median value of cur_win and new_win. + */ static u16 nip_tcp_select_window(struct sock *sk) { struct tcp_sock *tp = tcp_sk(sk); u32 old_win = tp->rcv_wnd; + /* The remaining size of the front receive window */ u32 cur_win = tcp_receive_window(tp); + /* Calculate the size of the new receive window based on the remaining receive cache */ u32 new_win = __nip_tcp_select_window(sk); + u32 new_win_bak; + /* Never shrink the offered window */ if (new_win < cur_win) { + /* Danger Will Robinson! + * Don't update rcv_wup/rcv_wnd here or else + * we will not be able to advertise a zero + * window in time. --DaveM + * + * Relax Will Robinson. + */ if (new_win == 0) - NET_INC_STATS(sock_net(sk), - LINUX_MIB_TCPWANTZEROWINDOWADV); + NET_INC_STATS(sock_net(sk), LINUX_MIB_TCPWANTZEROWINDOWADV); + new_win_bak = new_win; new_win = ALIGN(cur_win, 1 << tp->rx_opt.rcv_wscale); + DEBUG("%s when new_win(%u) < cur_win(%u), win change [%u to %u]", + __func__, new_win_bak, cur_win, new_win_bak, new_win); } tp->rcv_wnd = new_win; tp->rcv_wup = tp->rcv_nxt; - if (!tp->rx_opt.rcv_wscale && - sock_net(sk)->ipv4.sysctl_tcp_workaround_signed_windows) + /* Make sure we do not exceed the maximum possible + * scaled window. + */ + if (!tp->rx_opt.rcv_wscale && sock_net(sk)->ipv4.sysctl_tcp_workaround_signed_windows) new_win = min(new_win, MAX_TCP_WINDOW); else new_win = min(new_win, (65535U << tp->rx_opt.rcv_wscale)); + /* RFC1323 Scaling Applied. + * Scaling the receive window so that it can represent up to 30 bits + */ + new_win_bak = new_win; new_win >>= tp->rx_opt.rcv_wscale; + DEBUG("%s wscale(%u) win change [%u to %u]", + __func__, tp->rx_opt.rcv_wscale, new_win_bak, new_win); if (new_win == 0) { tp->pred_flags = 0; if (old_win) - NET_INC_STATS(sock_net(sk), - LINUX_MIB_TCPTOZEROWINDOWADV); + NET_INC_STATS(sock_net(sk), LINUX_MIB_TCPTOZEROWINDOWADV); } else if (old_win == 0) { NET_INC_STATS(sock_net(sk), LINUX_MIB_TCPFROMZEROWINDOWADV); } @@ -462,6 +496,7 @@ static int __tcp_nip_transmit_skb(struct sock *sk, struct sk_buff *skb, int err = 0; __be16 len; unsigned short check = 0; + bool ack; if (skb->tstamp == 0) skb->tstamp = tcp_jiffies32; @@ -506,10 +541,7 @@ static int __tcp_nip_transmit_skb(struct sock *sk, struct sk_buff *skb, skb_set_hash_from_sk(skb, sk); /* Increase allocated memory */ refcount_add(skb->truesize, &sk->sk_wmem_alloc); - DEBUG("th->inet_sport=%u, th->inet_dport=%u", - ntohs(inet->inet_sport), ntohs(inet->inet_dport)); - DEBUG("sk->sk_rcvbuf=%d, sk->sk_rmem_alloc=%d", - sk->sk_rcvbuf, atomic_read(&sk->sk_rmem_alloc)); + /* Build TCP header and checksum it. */ th = (struct tcphdr *)skb->data; th->source = inet->inet_sport; @@ -535,9 +567,14 @@ static int __tcp_nip_transmit_skb(struct sock *sk, struct sk_buff *skb, /* Window Settings */ if (likely(!(tcb->tcp_flags & TCPHDR_SYN))) - th->window = htons(nip_tcp_select_window(sk)); + th->window = htons(nip_tcp_select_window(sk)); else - th->window = htons(min(tp->rcv_wnd, TCP_NIP_WINDOW_MAX)); + th->window = htons(min(tp->rcv_wnd, TCP_NIP_WINDOW_MAX)); + + ack = tcb->tcp_flags & TCPHDR_ACK; + DEBUG("%s sport=%u, dport=%u, win=%u, sk_rcvbuf=%d, sk_rmem_alloc=%d, ack=%u, skb->len=%u", + __func__, ntohs(inet->inet_sport), ntohs(inet->inet_dport), ntohs(th->window), + sk->sk_rcvbuf, atomic_read(&sk->sk_rmem_alloc), ack, skb->len); /* Fill in checksum */ check = nip_get_output_checksum_tcp(skb, sk->sk_nip_rcv_saddr, sk->sk_nip_daddr); @@ -618,8 +655,7 @@ int __tcp_nip_connect(struct sock *sk) TCP_INC_STATS(sock_net(sk), TCP_MIB_ACTIVEOPENS); /* Timer for repeating the SYN until an answer. */ - inet_csk_reset_xmit_timer(sk, ICSK_TIME_RETRANS, - inet_csk(sk)->icsk_rto, TCP_RTO_MAX); + inet_csk_reset_xmit_timer(sk, ICSK_TIME_RETRANS, inet_csk(sk)->icsk_rto, TCP_RTO_MAX); return 0; } @@ -1046,6 +1082,8 @@ static bool tcp_nip_write_xmit(struct sock *sk, unsigned int mss_now, int nonagl struct sk_buff *skb; 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"}; tcp_nip_keepalive_enable(sk); tp->idle_ka_probes_out = 0; @@ -1065,9 +1103,10 @@ static bool tcp_nip_write_xmit(struct sock *sk, unsigned int mss_now, int nonagl } while ((skb = tcp_nip_send_head(sk)) && (snd_num--)) { - DEBUG("%s:tcp_nip_send_head head found!", __func__); tcp_nip_init_tso_segs(skb, mss_now); - if (unlikely(!tcp_nip_snd_wnd_test(tp, skb, mss_now))) + snd_wnd_ready = tcp_nip_snd_wnd_test(tp, skb, mss_now); + DEBUG("%s %s, skb->len=%u", __func__, (snd_wnd_ready ? str[1] : str[0]), skb->len); + if (unlikely(!snd_wnd_ready)) break; if (unlikely(tcp_nip_transmit_skb(sk, skb, 1, gfp))) @@ -1197,10 +1236,27 @@ void tcp_nip_release_cb(struct sock *sk) } } +enum nip_probe_type { + NIP_PROBE0 = 0, + NIP_KEEPALIVE = 1, + NIP_UNKNOWN = 2, + NIP_PROBE_MAX, +}; + static int tcp_nip_xmit_probe_skb(struct sock *sk, int urgent, int mib) { struct tcp_sock *tp = tcp_sk(sk); struct sk_buff *skb; + int ret; + int probe_type; + const char *str[NIP_PROBE_MAX] = {"probe0", "keepalive", "unknown"}; + + if (mib == LINUX_MIB_TCPWINPROBE) + probe_type = NIP_PROBE0; + else if (mib == LINUX_MIB_TCPKEEPALIVE) + probe_type = NIP_KEEPALIVE; + else + probe_type = NIP_UNKNOWN; /* We don't queue it, tcp_transmit_skb() sets ownership. */ skb = alloc_skb(MAX_TCP_HEADER, @@ -1214,8 +1270,9 @@ static int tcp_nip_xmit_probe_skb(struct sock *sk, int urgent, int mib) tcp_nip_init_nondata_skb(skb, tp->snd_una - !urgent, TCPHDR_ACK); NET_INC_STATS(sock_net(sk), mib); - DEBUG("[nip]%s: send probe packet!", __func__); - return tcp_nip_transmit_skb(sk, skb, 0, (__force gfp_t)0); + ret = tcp_nip_transmit_skb(sk, skb, 0, (__force gfp_t)0); + DEBUG("%s: send %s probe packet, ret=%d", __func__, str[probe_type], ret); + return ret; } int tcp_nip_write_wakeup(struct sock *sk, int mib) @@ -1241,7 +1298,7 @@ int tcp_nip_write_wakeup(struct sock *sk, int mib) err = tcp_fragment(sk, TCP_FRAG_IN_WRITE_QUEUE, skb, seg_size, mss, GFP_ATOMIC); if (err) { - DEBUG("[nip]:tcp_fragment return err = %d!", err); + DEBUG("%s tcp_fragment return err=%d", __func__, err); return -1; } } @@ -1261,31 +1318,47 @@ void tcp_nip_send_probe0(struct sock *sk) struct tcp_sock *tp = tcp_sk(sk); struct net *net = sock_net(sk); unsigned long probe_max; - int err; + int when; /* An ACK packet with snd_UNa-1 and length 0 is sent as a zero-window detection packet */ - err = tcp_nip_write_wakeup(sk, LINUX_MIB_TCPWINPROBE); + int err = tcp_nip_write_wakeup(sk, LINUX_MIB_TCPWINPROBE); /* If there are packets to be sent on the network and no packets to be * sent in the send queue, the packet is returned directly */ if (tp->packets_out || !tcp_nip_send_head(sk)) { /* Cancel probe timer, if it is not required. */ + DEBUG("%s packets_out(%u) not 0 or send_head is NULL, cancel probe0 timer.", + __func__, tp->packets_out); icsk->icsk_probes_out = 0; icsk->icsk_backoff = 0; return; } + /* Err: 0 succeeded, -1 failed */ if (err <= 0) { if (icsk->icsk_backoff < net->ipv4.sysctl_tcp_retries2) icsk->icsk_backoff++; icsk->icsk_probes_out++; /* Number of probes +1 */ probe_max = TCP_RTO_MAX; + DEBUG("%s probe0 send %s, icsk_probes_out=%u, icsk_backoff=%u, probe_max=%u", + __func__, (!err ? "ok" : "fail"), icsk->icsk_probes_out, + icsk->icsk_backoff, probe_max); } else { + /* If packet was not sent due to local congestion, + * do not backoff and do not remember icsk_probes_out. + * Let local senders to fight for local resources. + * Use accumulated backoff yet. + */ if (!icsk->icsk_probes_out) icsk->icsk_probes_out = 1; + + /* Makes the zero window probe timer time out faster */ probe_max = TCP_RESOURCE_PROBE_INTERVAL; + DEBUG("%s probe0 not sent due to local congestion, make timer time out faster", + __func__); } - inet_csk_reset_xmit_timer(sk, ICSK_TIME_PROBE0, - tcp_probe0_when(sk, probe_max), - TCP_RTO_MAX); + + when = tcp_probe0_when(sk, probe_max); + DEBUG("%s restart probe0 timer, when=%u, probe_max=%u", __func__, when, probe_max); + inet_csk_reset_xmit_timer(sk, ICSK_TIME_PROBE0, when, TCP_RTO_MAX); } diff --git a/code/linux/net/newip/tcp_nip_parameter.c b/code/linux/net/newip/tcp_nip_parameter.c index b402e52..7238dc0 100644 --- a/code/linux/net/newip/tcp_nip_parameter.c +++ b/code/linux/net/newip/tcp_nip_parameter.c @@ -31,17 +31,13 @@ module_param_named(af_ninet, g_af_ninet, int, 0444); int g_nip_rto = 50; module_param_named(nip_rto, g_nip_rto, int, 0644); -/* RTT RTO of a large delay scenario */ -int g_nip_rto_up = 100; -module_param_named(nip_rto_up, g_nip_rto_up, int, 0644); - /*********************************************************************************************/ /* TCP sending and receiving buffer configuration */ /*********************************************************************************************/ int g_nip_sndbuf = 1050000; // 1M module_param_named(nip_sndbuf, g_nip_sndbuf, int, 0644); -int g_nip_rcvbuf = 3000000; // 3M +int g_nip_rcvbuf = 2000000; // 2M module_param_named(nip_rcvbuf, g_nip_rcvbuf, int, 0644); /*********************************************************************************************/ @@ -66,17 +62,6 @@ module_param_named(ack_num, g_ack_num, int, 0644); int g_nip_ssthresh_reset = 10000000; // 10M module_param_named(nip_ssthresh_reset, g_nip_ssthresh_reset, int, 0644); -/*********************************************************************************************/ -/* Enables the debugging of special scenarios */ -/*********************************************************************************************/ -/* Debugging of threshold change */ -int g_rtt_ssthresh_debug; -module_param_named(rtt_ssthresh_debug, g_rtt_ssthresh_debug, int, 0644); - -/* Debugging of packet retransmission after ACK */ -int g_ack_retrans_debug; -module_param_named(ack_retrans_debug, g_ack_retrans_debug, int, 0644); - /*********************************************************************************************/ /* Retransmission parameters after ACK */ /*********************************************************************************************/ @@ -88,11 +73,7 @@ module_param_named(dup_ack_retrans_num, g_dup_ack_retrans_num, int, 0644); int g_ack_retrans_num = 5; module_param_named(ack_retrans_num, g_ack_retrans_num, int, 0644); -int g_dup_ack_snd_max = 500; /* - * fix session auto close - * Resolve multithreaded stability use cases to - * test individual socket disconnections - */ +int g_dup_ack_snd_max = 6; module_param_named(dup_ack_snd_max, g_dup_ack_snd_max, int, 0644); /*********************************************************************************************/ @@ -143,13 +124,10 @@ module_param_named(ssthresh_low_min, g_ssthresh_low_min, int, 0644); int g_ssthresh_high_step = 1; module_param_named(ssthresh_high_step, g_ssthresh_high_step, int, 0644); -int g_rcv_win_max = 512000; -module_param_named(rcv_win_max, g_rcv_win_max, int, 0644); - /*********************************************************************************************/ /* keepalive parameters */ /*********************************************************************************************/ -int g_nip_idle_ka_probes_out = 200; +int g_nip_idle_ka_probes_out = 20; module_param_named(nip_idle_ka_probes_out, g_nip_idle_ka_probes_out, int, 0644); int g_nip_keepalive_time = 25; @@ -158,14 +136,8 @@ 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_probes = 255; -module_param_named(nip_keepalive_probes, g_nip_keepalive_probes, int, 0644); - -/*********************************************************************************************/ -/* zero probeparameters */ -/*********************************************************************************************/ -int g_nip_tcp_zero_probe = 20; -module_param_named(nip_tcp_zero_probe, g_nip_tcp_zero_probe, 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 */ @@ -176,3 +148,18 @@ module_param_named(nip_tcp_snd_win_enable, g_nip_tcp_snd_win_enable, bool, 0644) bool g_nip_tcp_rcv_win_enable = true; module_param_named(nip_tcp_rcv_win_enable, g_nip_tcp_rcv_win_enable, bool, 0644); +/*********************************************************************************************/ +/* nip debug parameters */ +/*********************************************************************************************/ +/* Debugging for control DEBUG */ +bool g_nip_debug; +module_param_named(nip_debug, g_nip_debug, bool, 0644); + +/* Debugging of threshold change */ +int g_rtt_ssthresh_debug; +module_param_named(rtt_ssthresh_debug, g_rtt_ssthresh_debug, int, 0644); + +/* Debugging of packet retransmission after ACK */ +int g_ack_retrans_debug; +module_param_named(ack_retrans_debug, g_ack_retrans_debug, int, 0644); + diff --git a/code/linux/net/newip/tcp_nip_parameter.h b/code/linux/net/newip/tcp_nip_parameter.h index f0ab288..39a9303 100644 --- a/code/linux/net/newip/tcp_nip_parameter.h +++ b/code/linux/net/newip/tcp_nip_parameter.h @@ -16,7 +16,6 @@ /* Rto timeout timer period (HZ/n) */ /*********************************************************************************************/ extern int g_nip_rto; -extern int g_nip_rto_up; /*********************************************************************************************/ /* TCP sending and receiving buffer configuration */ @@ -36,23 +35,6 @@ extern int g_wscale; extern int g_ack_num; extern int g_nip_ssthresh_reset; -/*********************************************************************************************/ -/* Enables the debugging of special scenarios */ -/*********************************************************************************************/ -extern int g_rtt_ssthresh_debug; -#define SSTHRESH_DBG(fmt, ...) \ -do { \ - if (g_rtt_ssthresh_debug) \ - pr_crit(fmt, ##__VA_ARGS__); \ -} while (0) - -extern int g_ack_retrans_debug; -#define RETRANS_DBG(fmt, ...) \ -do { \ - if (g_ack_retrans_debug) \ - pr_crit(fmt, ##__VA_ARGS__); \ -} while (0) - /*********************************************************************************************/ /* Retransmission parameters after ACK */ /*********************************************************************************************/ @@ -80,7 +62,6 @@ extern int g_ssthresh_mid_low; extern int g_ssthresh_low; extern int g_ssthresh_low_min; extern int g_ssthresh_high_step; -extern int g_rcv_win_max; /*********************************************************************************************/ /* keepalive parameters */ @@ -88,12 +69,7 @@ extern int g_rcv_win_max; 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_probes; - -/*********************************************************************************************/ -/* zero probeparameters */ -/*********************************************************************************************/ -extern int g_nip_tcp_zero_probe; +extern int g_nip_keepalive_time_short_pkt; /*********************************************************************************************/ /* window mode parameters */ @@ -101,4 +77,26 @@ extern int g_nip_tcp_zero_probe; extern bool g_nip_tcp_snd_win_enable; extern bool g_nip_tcp_rcv_win_enable; +/*********************************************************************************************/ +/* nip debug parameters */ +/*********************************************************************************************/ +/* Debugging for control DEBUG */ +extern bool g_nip_debug; + +/* Debugging of threshold change */ +extern int g_rtt_ssthresh_debug; +#define SSTHRESH_DBG(fmt, ...) \ +do { \ + if (g_rtt_ssthresh_debug) \ + pr_crit(fmt, ##__VA_ARGS__); \ +} while (0) + +/* Debugging of packet retransmission after ACK */ +extern int g_ack_retrans_debug; + #define RETRANS_DBG(fmt, ...) \ +do { \ + if (g_ack_retrans_debug) \ + pr_crit(fmt, ##__VA_ARGS__); \ +} while (0) + #endif /* _TCP_NIP_PARAMETER_H */ diff --git a/code/linux/net/newip/tcp_nip_timer.c b/code/linux/net/newip/tcp_nip_timer.c index 5c25ef1..84aa31b 100644 --- a/code/linux/net/newip/tcp_nip_timer.c +++ b/code/linux/net/newip/tcp_nip_timer.c @@ -105,7 +105,6 @@ static bool retransmits_nip_timed_out(struct sock *sk, return inet_csk(sk)->icsk_retransmits > boundary; } -#define NIP_RETRY_UNTIL 200 // fix session auto close static int tcp_nip_write_timeout(struct sock *sk) { struct inet_connection_sock *icsk = inet_csk(sk); @@ -126,9 +125,6 @@ static int tcp_nip_write_timeout(struct sock *sk) } } -#ifdef NIP_RETRY_UNTIL - retry_until = NIP_RETRY_UNTIL; -#endif if (retransmits_nip_timed_out(sk, retry_until, syn_set ? 0 : icsk->icsk_user_timeout, syn_set)) { DEBUG("%s: tcp retransmit time out!!!", __func__); @@ -183,7 +179,7 @@ void tcp_nip_retransmit_timer(struct sock *sk) inet_csk_reset_xmit_timer(sk, ICSK_TIME_RETRANS, icsk->icsk_rto, TCP_RTO_MAX); } -#define NIP_MAX_PROBES 2000 // fix session auto close +#define NIP_MAX_PROBES 2000 void tcp_nip_probe_timer(struct sock *sk) { struct inet_connection_sock *icsk = inet_csk(sk); @@ -194,13 +190,14 @@ void tcp_nip_probe_timer(struct sock *sk) if (tp->packets_out || !tcp_nip_send_head(sk)) { icsk->icsk_probes_out = 0; - DEBUG("%s packets_out!=0 or send_head=NULL, don't send probe packet.", - __func__); + icsk->icsk_backoff = 0; // V4 no modified this line + DEBUG("%s packets_out(%u) not 0 or send_head is NULL, cancel probe0 timer.", + __func__, tp->packets_out); return; } #ifdef NIP_MAX_PROBES - max_probes = NIP_MAX_PROBES; + max_probes = NIP_MAX_PROBES; // 2000 - fix session auto close #else max_probes = sock_net(sk)->ipv4.sysctl_tcp_retries2; #endif @@ -209,6 +206,8 @@ void tcp_nip_probe_timer(struct sock *sk) const bool alive = inet_csk_rto_backoff(icsk, TCP_RTO_MAX) < TCP_RTO_MAX; max_probes = tcp_nip_orphan_retries(sk, alive); + DEBUG("%s sock dead, icsk_backoff=%u, max_probes=%u, alive=%u", + __func__, icsk->icsk_backoff, max_probes, alive); if (!alive && icsk->icsk_backoff >= max_probes) { DEBUG("%s will close session, icsk_backoff=%u, max_probes=%u", __func__, icsk->icsk_backoff, max_probes); @@ -219,10 +218,12 @@ void tcp_nip_probe_timer(struct sock *sk) if (icsk->icsk_probes_out >= max_probes) { abort: icsk_backoff = icsk->icsk_backoff; icsk_probes_out = icsk->icsk_probes_out; - tcp_nip_write_err(sk); DEBUG("%s close session, icsk_probes_out=%u, icsk_backoff=%u, max_probes=%u", __func__, icsk_probes_out, icsk_backoff, max_probes); + tcp_nip_write_err(sk); } else { + DEBUG("%s will send probe0, icsk_probes_out=%u, icsk_backoff=%u, max_probes=%u", + __func__, icsk_probes_out, icsk_backoff, max_probes); /* Only send another probe if we didn't close things up. */ tcp_nip_send_probe0(sk); } @@ -233,13 +234,12 @@ void tcp_nip_write_timer_handler(struct sock *sk) struct inet_connection_sock *icsk = inet_csk(sk); int event; - if (((1 << sk->sk_state) & (TCPF_CLOSE | TCPF_LISTEN)) || - !icsk->icsk_pending) - goto out; + if (((1 << sk->sk_state) & (TCPF_CLOSE | TCPF_LISTEN)) || !icsk->icsk_pending) + return; if (time_after(icsk->icsk_timeout, jiffies)) { sk_reset_timer(sk, &icsk->icsk_retransmit_timer, icsk->icsk_timeout); - goto out; + return; } tcp_mstamp_refresh(tcp_sk(sk)); event = icsk->icsk_pending; @@ -256,8 +256,6 @@ void tcp_nip_write_timer_handler(struct sock *sk) default: break; } - -out:; } static void tcp_nip_write_timer(struct timer_list *t) @@ -278,37 +276,36 @@ static void tcp_nip_write_timer(struct timer_list *t) sock_put(sk); } -#define NIP_KA_TIMEOUT_SCALE_MAX 1000 -static void tcp_nip_keepalive_timeout(struct sock *sk) +static bool tcp_nip_keepalive_is_timeout(struct sock *sk, u32 elapsed) { struct inet_connection_sock *icsk = inet_csk(sk); struct tcp_sock *tp = tcp_sk(sk); u32 keepalive_time = keepalive_time_when(tp); + bool is_timeout = false; + /* keepalive set by setsockopt */ if (keepalive_time > HZ) { - DEBUG("%s keepalive timeout, disconnect sock.", __func__); - tcp_nip_write_err(sk); - return; + /* If the TCP_USER_TIMEOUT option is enabled, use that + * to determine when to timeout instead. + */ + if ((icsk->icsk_user_timeout != 0 && + elapsed >= msecs_to_jiffies(icsk->icsk_user_timeout) && + tp->nip_keepalive_out > 0) || + (icsk->icsk_user_timeout == 0 && + tp->nip_keepalive_out >= keepalive_probes(tp))) { + DEBUG("%s normal keepalive timeout, keepalive_out=%u.", + __func__, tp->nip_keepalive_out); + tcp_nip_write_err(sk); + is_timeout = true; + } } - tp->nip_keepalive_timeout_scale++; - if (tp->nip_keepalive_timeout_scale <= NIP_KA_TIMEOUT_SCALE_MAX) { - icsk->icsk_probes_out = 0; - inet_csk_reset_keepalive_timer(sk, keepalive_time); - - DEBUG("%s ms keepalive scale(%u) < thresh, connect sock continue.", - __func__, tp->nip_keepalive_timeout_scale); - } else { - DEBUG("%s ms keepalive timeout(scale=%u), disconnect sock.", - __func__, tp->nip_keepalive_timeout_scale); - tcp_nip_write_err(sk); - } + return is_timeout; } static void tcp_nip_keepalive_timer(struct timer_list *t) { struct sock *sk = from_timer(sk, t, sk_timer); - struct inet_connection_sock *icsk = inet_csk(sk); struct tcp_sock *tp = tcp_sk(sk); u32 elapsed; @@ -321,7 +318,7 @@ static void tcp_nip_keepalive_timer(struct timer_list *t) } if (sk->sk_state == TCP_LISTEN) { - pr_err("Hmm... keepalive on a LISTEN"); + DEBUG("%s: keepalive on a LISTEN", __func__); goto out; } tcp_mstamp_refresh(tp); @@ -331,7 +328,7 @@ static void tcp_nip_keepalive_timer(struct timer_list *t) */ if ((sk->sk_state == TCP_FIN_WAIT2 || sk->sk_state == TCP_CLOSING) && sock_flag(sk, SOCK_DEAD)) { - DEBUG("%s: finish wait, close sock", __func__); + DEBUG("%s: finish wait, close sock, sk_state=%u", __func__, sk->sk_state); goto death; } @@ -347,19 +344,11 @@ static void tcp_nip_keepalive_timer(struct timer_list *t) elapsed = keepalive_time_elapsed(tp); if (elapsed >= keepalive_time_when(tp)) { - /* If the TCP_USER_TIMEOUT option is enabled, use that - * to determine when to timeout instead. - */ - if ((icsk->icsk_user_timeout != 0 && - elapsed >= msecs_to_jiffies(icsk->icsk_user_timeout) && - icsk->icsk_probes_out > 0) || - (icsk->icsk_user_timeout == 0 && - icsk->icsk_probes_out >= keepalive_probes(tp))) { - tcp_nip_keepalive_timeout(sk); + if (tcp_nip_keepalive_is_timeout(sk, elapsed)) goto out; - } + if (tcp_nip_write_wakeup(sk, LINUX_MIB_TCPKEEPALIVE) <= 0) { - icsk->icsk_probes_out++; + tp->nip_keepalive_out++; tp->idle_ka_probes_out++; elapsed = keepalive_intvl_when(tp); } else { diff --git a/patches/hispark_taurus.flag b/patches/hispark_taurus_standard.flag similarity index 100% rename from patches/hispark_taurus.flag rename to patches/hispark_taurus_standard.flag diff --git a/patches/linux-5.10/newip.patch b/patches/linux-5.10/newip.patch index a3ef784..4b64d06 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-07-26 16:28:51.526938875 +0800 -+++ new/include/linux/netdevice.h 2022-07-26 16:28:51.536938875 +0800 +--- 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 @@ -2016,6 +2016,9 @@ struct dn_dev __rcu *dn_ptr; #endif @@ -11,9 +11,57 @@ 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-07-26 16:28:51.526938875 +0800 -+++ new/include/linux/socket.h 2022-07-26 16:28:51.536938875 +0800 +--- 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 @@ -223,8 +223,8 @@ * reuses AF_INET address family */ @@ -34,8 +82,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-07-26 16:28:51.526938875 +0800 -+++ new/include/linux/tcp.h 2022-07-26 16:28:51.536938875 +0800 +--- 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 @@ -317,6 +317,9 @@ /* OOO segments go in this rbtree. Socket lock must be held. */ @@ -46,7 +94,7 @@ diff -Naur old/include/linux/tcp.h new/include/linux/tcp.h 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,19 @@ +@@ -412,6 +415,22 @@ */ struct request_sock __rcu *fastopen_rsk; struct saved_syn *saved_syn; @@ -59,14 +107,17 @@ diff -Naur old/include/linux/tcp.h new/include/linux/tcp.h + u32 nip_ssthresh_reset; + bool nip_keepalive_enable; + u32 idle_ka_probes_out; -+ u32 nip_keepalive_timeout_scale; ++ u32 nip_keepalive_out; + u32 last_rcv_nxt; + u32 dup_ack_cnt; ++ u32 keepalive_time_bak; ++ u32 keepalive_probes_bak; ++ u32 keepalive_intvl_bak; +#endif }; enum tsq_enum { -@@ -423,6 +439,10 @@ +@@ -423,6 +442,10 @@ TCP_MTU_REDUCED_DEFERRED, /* tcp_v{4|6}_err() could not call * tcp_v{4|6}_mtu_reduced() */ @@ -78,8 +129,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-07-26 16:28:51.526938875 +0800 -+++ new/include/net/dst.h 2022-07-26 16:28:51.536938875 +0800 +--- 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 @@ -35,6 +35,8 @@ int (*output)(struct net *net, struct sock *sk, struct sk_buff *skb); @@ -90,8 +141,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-07-26 16:28:51.526938875 +0800 -+++ new/include/net/inet_hashtables.h 2022-07-26 16:28:51.546938875 +0800 +--- 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 @@ -83,6 +83,9 @@ #if IS_ENABLED(CONFIG_IPV6) struct in6_addr fast_v6_rcv_saddr; @@ -117,8 +168,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-07-26 16:28:51.526938875 +0800 -+++ new/include/net/inet_sock.h 2022-07-26 16:28:51.546938875 +0800 +--- 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 @@ -73,6 +73,10 @@ #define ir_rmt_port req.__req_common.skc_dport #define ir_v6_rmt_addr req.__req_common.skc_v6_daddr @@ -144,8 +195,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-07-26 16:28:51.526938875 +0800 -+++ new/include/net/neighbour.h 2022-07-26 16:28:51.546938875 +0800 +--- 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 @@ -232,6 +232,9 @@ NEIGH_ARP_TABLE = 0, NEIGH_ND_TABLE = 1, @@ -157,8 +208,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-07-26 16:28:51.526938875 +0800 -+++ new/include/net/net_namespace.h 2022-07-26 16:28:51.546938875 +0800 +--- 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 @@ -38,6 +38,9 @@ #include #include @@ -180,8 +231,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-07-26 16:28:51.526938875 +0800 -+++ new/include/net/secure_seq.h 2022-07-26 16:28:51.546938875 +0800 +--- 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 @@ -19,4 +19,11 @@ u64 secure_dccpv6_sequence_number(__be32 *saddr, __be32 *daddr, __be16 sport, __be16 dport); @@ -195,8 +246,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-07-26 16:28:51.526938875 +0800 -+++ new/include/net/sock.h 2022-07-26 16:28:51.546938875 +0800 +--- 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 @@ -68,6 +68,9 @@ #include #include @@ -228,9 +279,37 @@ 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-07-26 16:28:51.526938875 +0800 -+++ new/include/net/tcp.h 2022-07-26 16:28:51.546938875 +0800 +--- 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 @@ -40,7 +40,9 @@ #include #include @@ -253,8 +332,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-07-26 16:28:51.526938875 +0800 -+++ new/include/uapi/linux/if_ether.h 2022-07-26 16:28:51.546938875 +0800 +--- 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 @@ -72,6 +72,7 @@ #define ETH_P_ERSPAN 0x88BE /* ERSPAN type II */ #define ETH_P_IPX 0x8137 /* IPX over DIX */ @@ -264,8 +343,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-07-26 16:28:51.526938875 +0800 -+++ new/net/Kconfig 2022-07-26 16:28:51.546938875 +0800 +--- old/net/Kconfig 2022-08-17 10:51:51.513816820 +0800 ++++ new/net/Kconfig 2022-08-17 10:51:51.543816820 +0800 @@ -93,6 +93,7 @@ if INET source "net/ipv4/Kconfig" @@ -275,8 +354,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-07-26 16:28:51.526938875 +0800 -+++ new/net/Makefile 2022-07-26 16:28:51.556938875 +0800 +--- old/net/Makefile 2022-08-17 10:51:51.513816820 +0800 ++++ new/net/Makefile 2022-08-17 10:51:51.543816820 +0800 @@ -20,6 +20,7 @@ obj-$(CONFIG_XFRM) += xfrm/ obj-$(CONFIG_UNIX_SCM) += unix/ @@ -286,9 +365,22 @@ 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-07-26 16:28:51.526938875 +0800 -+++ new/net/core/neighbour.c 2022-07-26 16:28:51.546938875 +0800 -@@ -1779,6 +1779,11 @@ +--- 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 @@ case AF_DECnet: tbl = neigh_tables[NEIGH_DN_TABLE]; break; @@ -301,8 +393,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-07-26 16:28:51.526938875 +0800 -+++ new/net/core/secure_seq.c 2022-07-26 16:28:51.546938875 +0800 +--- 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 @@ -151,6 +151,51 @@ EXPORT_SYMBOL_GPL(secure_ipv4_port_ephemeral); #endif @@ -356,14 +448,14 @@ 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-07-26 16:28:51.526938875 +0800 -+++ new/net/ipv4/inet_connection_sock.c 2022-07-26 16:28:51.546938875 +0800 +--- 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 @@ -22,7 +22,34 @@ #include #include #include +#if IS_ENABLED(CONFIG_NEWIP) -+#include ++#include +#include +#endif @@ -445,8 +537,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-07-26 16:28:51.526938875 +0800 -+++ new/net/ipv4/inet_hashtables.c 2022-07-26 16:28:51.546938875 +0800 +--- 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 @@ -52,6 +52,15 @@ &sk->sk_v6_rcv_saddr, sk->sk_num, &sk->sk_v6_daddr, sk->sk_dport); @@ -464,8 +556,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-07-26 16:28:51.526938875 +0800 -+++ new/security/selinux/hooks.c 2022-07-26 16:28:51.556938875 +0800 +--- 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 @@ -1271,7 +1271,7 @@ return SECCLASS_SMC_SOCKET; case PF_XDP: @@ -475,9 +567,18 @@ 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-07-26 16:28:51.536938875 +0800 -+++ new/security/selinux/include/classmap.h 2022-07-26 16:28:51.556938875 +0800 +--- 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 @@ -253,6 +253,6 @@ { NULL } }; -- Gitee