From 5add60f819000333688b13de4942a24467ea4778 Mon Sep 17 00:00:00 2001 From: yangyanjun Date: Wed, 28 Dec 2022 17:16:55 +0800 Subject: [PATCH] =?UTF-8?q?=E9=9B=B6=E7=AA=97=E5=8F=A3=E6=8E=A2=E6=B5=8B?= =?UTF-8?q?=EF=BC=8Crto=E8=B6=85=E6=97=B6=E9=87=8D=E4=BC=A0=E5=85=B3?= =?UTF-8?q?=E9=94=AEdebug=E8=B0=83=E6=95=B4=EF=BC=8Cnewip=20debug=E5=8F=82?= =?UTF-8?q?=E6=95=B0pr=5Ffmt(fmt)=E8=B0=83=E6=95=B4=EF=BC=8C=E9=9D=99?= =?UTF-8?q?=E6=80=81=E6=A3=80=E6=9F=A5=E5=91=8A=E8=AD=A6=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=EF=BC=8Crto=E8=B6=85=E6=97=B6=E5=AE=9A=E6=97=B6=E5=99=A8?= =?UTF-8?q?=E5=85=B3=E9=97=AD=E6=97=B6icsk=5Fbackoff=E7=BD=AE0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: yangyanjun --- examples/nip.h | 2 +- examples/nip_route.c | 2 +- examples/nip_uapi.h | 2 +- examples/nip_udp_client_demo.c | 2 +- src/linux/include/net/nip.h | 2 - src/linux/include/net/nip_route.h | 2 +- src/linux/include/net/tcp_nip.h | 16 +-- src/linux/include/uapi/linux/nip.h | 4 +- src/linux/net/newip/af_ninet.c | 19 +-- src/linux/net/newip/devninet.c | 3 + src/linux/net/newip/icmp.c | 5 +- src/linux/net/newip/ninet_connection_sock.c | 3 +- src/linux/net/newip/ninet_hashtables.c | 13 +- src/linux/net/newip/nip_addrconf.c | 41 +++--- src/linux/net/newip/nip_addrconf_core.c | 3 +- src/linux/net/newip/nip_fib.c | 8 +- src/linux/net/newip/nip_fib_rules.c | 3 +- src/linux/net/newip/nip_hooks_register.c | 3 +- src/linux/net/newip/nip_hooks_register.h | 2 +- src/linux/net/newip/nip_input.c | 15 +- src/linux/net/newip/nip_output.c | 42 +++--- src/linux/net/newip/nip_sockglue.c | 3 +- src/linux/net/newip/nndisc.c | 15 +- src/linux/net/newip/protocol.c | 3 +- src/linux/net/newip/route.c | 51 +++---- src/linux/net/newip/tcp_nip.c | 138 ++++++++---------- src/linux/net/newip/tcp_nip_input.c | 147 ++++++++++---------- src/linux/net/newip/tcp_nip_output.c | 101 +++++++------- src/linux/net/newip/tcp_nip_parameter.c | 2 + src/linux/net/newip/tcp_nip_parameter.h | 6 + src/linux/net/newip/tcp_nip_timer.c | 75 ++++++---- src/linux/net/newip/udp.c | 16 +-- 32 files changed, 382 insertions(+), 367 deletions(-) diff --git a/examples/nip.h b/examples/nip.h index f1cf685..b5c1233 100644 --- a/examples/nip.h +++ b/examples/nip.h @@ -124,4 +124,4 @@ enum nip_index { INDEX_MAX, }; -#endif /*_NIP_H */ +#endif /* _NIP_H */ diff --git a/examples/nip_route.c b/examples/nip_route.c index 4df8e47..84b7434 100644 --- a/examples/nip_route.c +++ b/examples/nip_route.c @@ -111,8 +111,8 @@ int parse_name(char **argv, int *ifindex, char *dev) int parse_cmd(char **argv, int *opt) { - char cmd[ARRAY_LEN]; int len = strlen(*argv); + char cmd[ARRAY_LEN]; memset(cmd, 0, ARRAY_LEN); if (!len || len >= (ARRAY_LEN - 1)) diff --git a/examples/nip_uapi.h b/examples/nip_uapi.h index 31e9789..f470acb 100644 --- a/examples/nip_uapi.h +++ b/examples/nip_uapi.h @@ -28,4 +28,4 @@ struct thread_args { struct sockaddr_nin si_server; }; -#endif /*_NIP_UAPI_H */ +#endif /* _NIP_UAPI_H */ diff --git a/examples/nip_udp_client_demo.c b/examples/nip_udp_client_demo.c index c644562..9b3b5da 100644 --- a/examples/nip_udp_client_demo.c +++ b/examples/nip_udp_client_demo.c @@ -118,8 +118,8 @@ END: return NULL; int main(int argc, char **argv) { - int cfd; pthread_t th; + int cfd; struct thread_args th_args; struct sockaddr_nin si_server; diff --git a/src/linux/include/net/nip.h b/src/linux/include/net/nip.h index b5580c3..db186e7 100644 --- a/src/linux/include/net/nip.h +++ b/src/linux/include/net/nip.h @@ -126,6 +126,4 @@ 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); -void nip_dbg(const char *fmt, ...); - #endif diff --git a/src/linux/include/net/nip_route.h b/src/linux/include/net/nip_route.h index 77e2f7e..6fa91ab 100644 --- a/src/linux/include/net/nip_route.h +++ b/src/linux/include/net/nip_route.h @@ -63,4 +63,4 @@ int nip_route_init(void); void nip_route_cleanup(void); -#endif /*_NET_NIP_ROUTE_H */ +#endif /* _NET_NIP_ROUTE_H */ diff --git a/src/linux/include/net/tcp_nip.h b/src/linux/include/net/tcp_nip.h index 0291b03..8d112ab 100644 --- a/src/linux/include/net/tcp_nip.h +++ b/src/linux/include/net/tcp_nip.h @@ -110,21 +110,6 @@ void tcp_nip_clear_xmit_timers(struct sock *sk); void tcp_nip_delack_timer_handler(struct sock *sk); void tcp_nip_write_timer_handler(struct sock *sk); -/* check probe0 timer */ -static inline void tcp_nip_check_probe_timer(struct sock *sk) -{ - unsigned long when; - - if (!tcp_sk(sk)->packets_out && !inet_csk(sk)->icsk_pending) { - when = tcp_probe0_base(sk); - nip_dbg("%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) { - nip_dbg("%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) { return sk->sk_send_head; @@ -151,6 +136,7 @@ static inline void tcp_nip_write_queue_purge(struct sock *sk) tcp_clear_all_retrans_hints(tcp_sk(sk)); sk->sk_send_head = NULL; + tcp_sk(sk)->packets_out = 0; inet_csk(sk)->icsk_backoff = 0; } diff --git a/src/linux/include/uapi/linux/nip.h b/src/linux/include/uapi/linux/nip.h index bada548..cd96325 100644 --- a/src/linux/include/uapi/linux/nip.h +++ b/src/linux/include/uapi/linux/nip.h @@ -33,7 +33,7 @@ struct sockaddr_nin { }; struct nip_devreq { - char nip_ifr_name[IFNAMSIZ]; /* if name, e.g. "eth0", "wlan0" */ + char nip_ifr_name[IFNAMSIZ]; /* if name, e.g. "eth0", "wlan0" */ union { struct sockaddr_nin addr; @@ -44,4 +44,4 @@ struct nip_devreq { #define nip_dev_addr devreq.addr /* nip address */ #define nip_dev_flags devreq.flags /* net device flags */ -#endif /*_UAPI_NEWIP_H */ +#endif /* _UAPI_NEWIP_H */ diff --git a/src/linux/net/newip/af_ninet.c b/src/linux/net/newip/af_ninet.c index e21e121..6512d09 100644 --- a/src/linux/net/newip/af_ninet.c +++ b/src/linux/net/newip/af_ninet.c @@ -7,7 +7,7 @@ * * Based on linux/net/ipv6/af_inet6.c */ -#define pr_fmt(fmt) "NIP: " fmt +#define pr_fmt(fmt) KBUILD_MODNAME ": [%s:%d] " fmt, __func__, __LINE__ #include #include @@ -50,6 +50,7 @@ #include #include "nip_hooks_register.h" #endif +#include "tcp_nip_parameter.h" MODULE_DESCRIPTION("NewIP protocol stack"); @@ -89,7 +90,7 @@ static int ninet_create(struct net *net, struct socket *sock, int protocol, num = atomic_add_return(1, &g_nip_socket_number); if (num > NIP_MAX_SOCKET_NUM) { - nip_dbg("The number of socket is biger than 1024"); + nip_dbg("The number of socket is biger than %u", NIP_MAX_SOCKET_NUM); err = -EPERM; goto number_sub; } @@ -210,7 +211,7 @@ int ninet_bind(struct socket *sock, struct sockaddr *uaddr, int addr_len) return -EACCES; if (nip_bind_addr_check(net, &addr->sin_addr) == false) { - nip_dbg("%s: binding-addr invalid, bitlen=%u", __func__, addr->sin_addr.bitlen); + nip_dbg("binding-addr invalid, bitlen=%u", addr->sin_addr.bitlen); return -EADDRNOTAVAIL; } lock_sock(sk); @@ -426,14 +427,14 @@ int ninet_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg) struct sock *sk = sock->sk; struct net *net = sock_net(sk); - nip_dbg("%s: cmd=0x%x", __func__, cmd); + nip_dbg("cmd=0x%x", cmd); switch (cmd) { case SIOCADDRT: case SIOCDELRT: { struct nip_rtmsg rtmsg; if (copy_from_user(&rtmsg, (void __user *)arg, sizeof(rtmsg))) { - nip_dbg("%s: fail to copy route cfg data", __func__); + nip_dbg("fail to copy route cfg data"); return -EFAULT; } return nip_route_ioctl(net, cmd, &rtmsg); @@ -447,7 +448,7 @@ int ninet_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg) default: if (!sk->sk_prot->ioctl) { - nip_dbg("%s: sock sk_prot ioctl is null, cmd=0x%x", __func__, cmd); + nip_dbg("sock sk_prot ioctl is null, cmd=0x%x", cmd); return -ENOIOCTLCMD; } return sk->sk_prot->ioctl(sk, cmd, arg); @@ -479,11 +480,11 @@ static int ninet_compat_routing_ioctl(struct sock *sk, unsigned int cmd, get_user(rt.rtmsg_metric, &ur->rtmsg_metric) || get_user(rt.rtmsg_info, &ur->rtmsg_info) || get_user(rt.rtmsg_flags, &ur->rtmsg_flags)) { - nip_dbg("%s: fail to convert input para, cmd=0x%x", __func__, cmd); + nip_dbg("fail to convert input para, cmd=0x%x", cmd); return -EFAULT; } - nip_dbg("%s: cmd=0x%x", __func__, cmd); + nip_dbg("cmd=0x%x", cmd); return nip_route_ioctl(sock_net(sk), cmd, &rt); } @@ -740,7 +741,7 @@ static int __init ninet_init(void) goto nip_packet_fail; } #endif - nip_dbg("NewIP: init newip address family ok"); + nip_dbg("init newip address family ok"); out: return err; diff --git a/src/linux/net/newip/devninet.c b/src/linux/net/newip/devninet.c index 3878510..e234498 100644 --- a/src/linux/net/newip/devninet.c +++ b/src/linux/net/newip/devninet.c @@ -10,8 +10,11 @@ * DEVICE - NEWIP device support. * Based on net/ipv4/devinet.c */ +#define pr_fmt(fmt) KBUILD_MODNAME ": [%s:%d] " fmt, __func__, __LINE__ + #include #include +#include "tcp_nip_parameter.h" int ninet_gifconf(struct net_device *dev, char __user *buf, int len, int size) { diff --git a/src/linux/net/newip/icmp.c b/src/linux/net/newip/icmp.c index 2ec0df2..0b388ef 100644 --- a/src/linux/net/newip/icmp.c +++ b/src/linux/net/newip/icmp.c @@ -8,7 +8,7 @@ * Based on net/ipv6/icmp.c * Based on net/ipv4/af_inet.c */ -#define pr_fmt(fmt) "NIP-ICMP: " fmt +#define pr_fmt(fmt) KBUILD_MODNAME ": [%s:%d] " fmt, __func__, __LINE__ #include #include @@ -29,6 +29,7 @@ #include #include "nip_hdr.h" +#include "tcp_nip_parameter.h" int nip_icmp_rcv(struct sk_buff *skb) { @@ -36,7 +37,7 @@ int nip_icmp_rcv(struct sk_buff *skb) struct nip_icmp_hdr *hdr = nip_icmp_header(skb); u8 type = hdr->nip_icmp_type; - nip_dbg("rcv newip icmp packet. type = %u", type); + nip_dbg("rcv newip icmp packet. type=%u", type); switch (type) { case NIP_ARP_NS: case NIP_ARP_NA: diff --git a/src/linux/net/newip/ninet_connection_sock.c b/src/linux/net/newip/ninet_connection_sock.c index 288cef5..c0dd907 100644 --- a/src/linux/net/newip/ninet_connection_sock.c +++ b/src/linux/net/newip/ninet_connection_sock.c @@ -11,7 +11,7 @@ * * Based on net/ipv4/inet_connection_sock.c */ -#define pr_fmt(fmt) "NIP: " fmt +#define pr_fmt(fmt) KBUILD_MODNAME ": [%s:%d] " fmt, __func__, __LINE__ #include #include @@ -25,6 +25,7 @@ #include #include #include +#include "tcp_nip_parameter.h" /* Function * Timeout handler for request processing, used to retransmit SYN+ACK diff --git a/src/linux/net/newip/ninet_hashtables.c b/src/linux/net/newip/ninet_hashtables.c index 3a8309d..908aecb 100644 --- a/src/linux/net/newip/ninet_hashtables.c +++ b/src/linux/net/newip/ninet_hashtables.c @@ -15,7 +15,7 @@ * Based on include/net/ipv6.h * Based on net/core/secure_seq.c */ -#define pr_fmt(fmt) "NIP: " fmt +#define pr_fmt(fmt) KBUILD_MODNAME ": [%s:%d] " fmt, __func__, __LINE__ #include #include @@ -25,6 +25,7 @@ #include #include #include +#include "tcp_nip_parameter.h" static siphash_key_t net_secret __read_mostly; @@ -294,7 +295,7 @@ begin: if (!NINET_MATCH(sk, net, saddr, daddr, ports, dif)) continue; if (unlikely(!refcount_inc_not_zero(&sk->sk_refcnt))) { - nip_dbg("[nip]%s:sk->sk_refcnt == 0", __func__); + nip_dbg("sk->sk_refcnt == 0"); goto out; } @@ -359,12 +360,12 @@ static struct sock *ninet_lhash2_lookup(struct net *net, sk = (struct sock *)icsk; score = nip_tcp_compute_score(sk, net, hnum, daddr, dif, sdif); if (score > hiscore) { - nip_dbg("%s: find sock in lhash table", __func__); + nip_dbg("find sock in lhash table"); result = sk; hiscore = score; reuseport = sk->sk_reuseport; if (reuseport) { - nip_dbg("%s: find reuseport sock in lhash table", __func__); + nip_dbg("find reuseport sock in lhash table"); phash = ninet_ehashfn(net, daddr, hnum, saddr, sport); matches = 1; } @@ -438,7 +439,7 @@ static int __ninet_check_established(struct inet_timewait_death_row *death_row, if (likely(NINET_MATCH(sk2, net, saddr, daddr, ports, dif))) { - nip_dbg("%s: found same sk in ehash", __func__); + nip_dbg("found same sk in ehash"); goto not_unique; } } @@ -446,7 +447,7 @@ static int __ninet_check_established(struct inet_timewait_death_row *death_row, /* Must record num and sport now. Otherwise we will see * in hash table socket with a funny identity. */ - nip_dbg("%s: add tcp sock into ehash table. sport=%u", __func__, lport); + nip_dbg("add tcp sock into ehash table. sport=%u", lport); inet->inet_num = lport; inet->inet_sport = htons(lport); sk->sk_hash = hash; diff --git a/src/linux/net/newip/nip_addrconf.c b/src/linux/net/newip/nip_addrconf.c index 079fa6d..135d46e 100644 --- a/src/linux/net/newip/nip_addrconf.c +++ b/src/linux/net/newip/nip_addrconf.c @@ -7,7 +7,7 @@ * * Based on net/ipv6/addrconf.c */ -#define pr_fmt(fmt) "NIP: " fmt +#define pr_fmt(fmt) KBUILD_MODNAME ": [%s:%d] " fmt, __func__, __LINE__ #include #include @@ -40,6 +40,7 @@ #include #include "nip_hdr.h" +#include "tcp_nip_parameter.h" #define INFINITY_LIFE_TIME 0xFFFFFFFF @@ -104,7 +105,7 @@ 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)) { - nip_dbg("%s: already assigned", __func__); + nip_dbg("already assigned"); err = -EEXIST; goto spin_lock_out; } @@ -158,7 +159,7 @@ rcu_lock_out: rcu_read_unlock_bh(); if (likely(err == 0)) { - nip_dbg("%s: success, idev->refcnt=%u", __func__, refcount_read(&idev->refcnt)); + nip_dbg("success, idev->refcnt=%u", refcount_read(&idev->refcnt)); } else { kfree(ifa); nin_dev_put(idev); @@ -202,7 +203,7 @@ static struct ninet_dev *nip_add_dev(struct net_device *dev) refcount_set(&ndev->refcnt, 1); - nip_dbg("%s: init ninet_dev success, set ndev->refcnt=1", __func__); + nip_dbg("init ninet_dev success, set ndev->refcnt=1"); if (netif_running(dev) && nip_addrconf_link_ready(dev)) ndev->if_flags |= IF_READY; @@ -288,7 +289,7 @@ static int ninet_addr_add(struct net *net, int ifindex, if (!IS_ERR(ifp)) { nin_ifa_put(ifp); nip_ins_rt(ifp->rt); - nip_dbg("%s: success, ifp->refcnt=%u", __func__, refcount_read(&ifp->refcnt)); + nip_dbg("success, ifp->refcnt=%u", refcount_read(&ifp->refcnt)); return 0; } @@ -300,13 +301,9 @@ void ninet_ifa_finish_destroy(struct ninet_ifaddr *ifp) { WARN_ON(!hlist_unhashed(&ifp->addr_lst)); - nip_dbg("%s: before idev put. idev->refcnt=%u", __func__, - refcount_read(&ifp->idev->refcnt)); - + nip_dbg("before idev put. idev->refcnt=%u", refcount_read(&ifp->idev->refcnt)); nin_dev_put(ifp->idev); - nip_rt_put(ifp->rt); - kfree_rcu(ifp, rcu); } @@ -380,22 +377,22 @@ static int ninet_addr_del(struct net *net, int ifindex, u32 ifa_flags, int nip_addrconf_ifaddr_check(struct net *net, void __user *arg, struct nip_ifreq *ireq) { if (!ns_capable(net->user_ns, CAP_NET_ADMIN)) { - nip_dbg("%s: not admin can`t cfg", __func__); + nip_dbg("not admin can`t cfg"); return -EPERM; } if (copy_from_user(ireq, arg, sizeof(struct nip_ifreq))) { - nip_dbg("%s: fail to copy cfg data", __func__); + nip_dbg("fail to copy cfg data"); return -EFAULT; } if (nip_addr_invalid(&ireq->ifrn_addr)) { - nip_dbg("%s: nip addr invalid, bitlen=%u", __func__, ireq->ifrn_addr.bitlen); + nip_dbg("nip addr invalid, bitlen=%u", ireq->ifrn_addr.bitlen); return -EFAULT; } if (nip_addr_public(&ireq->ifrn_addr)) { - nip_dbg("%s: The public address cannot be configured", __func__); + nip_dbg("The public address cannot be configured"); return -EFAULT; } return 0; @@ -408,7 +405,7 @@ int nip_addrconf_add_ifaddr(struct net *net, void __user *arg) err = nip_addrconf_ifaddr_check(net, arg, &ireq); if (err < 0) { - nip_dbg("%s: The ifaddr check failed", __func__); + nip_dbg("The ifaddr check failed"); return err; } @@ -427,7 +424,7 @@ int nip_addrconf_del_ifaddr(struct net *net, void __user *arg) err = nip_addrconf_ifaddr_check(net, arg, &ireq); if (err < 0) { - nip_dbg("%s: The ifaddr check failed", __func__); + nip_dbg("The ifaddr check failed"); return err; } @@ -604,8 +601,8 @@ static int nip_addrconf_ifdown(struct net_device *dev, bool unregister) ASSERT_RTNL(); - nip_dbg("%s: %s ifindex=%u, unregister=%u (unregister:1, down:0)", - __func__, dev->name, dev->ifindex, unregister); + nip_dbg("%s ifindex=%u, unregister=%u (unregister:1, down:0)", + dev->name, dev->ifindex, unregister); nip_rt_ifdown(net, dev); neigh_ifdown(&nnd_tbl, dev); @@ -632,7 +629,7 @@ static int nip_addrconf_ifdown(struct net_device *dev, bool unregister) char addr[NIP_ADDR_BIT_LEN_MAX] = {0}; nip_addr_to_str(&ifa->addr, addr, NIP_ADDR_BIT_LEN_MAX); - nip_dbg("%s: clear addr hash table.(addr=%s)", __func__, addr); + nip_dbg("clear addr hash table.(addr=%s)", addr); hlist_del_init_rcu(&ifa->addr_lst); } } @@ -671,7 +668,7 @@ static int nip_addrconf_ifdown(struct net_device *dev, bool unregister) if (unregister) { neigh_parms_release(&nnd_tbl, idev->nd_parms); neigh_ifdown(&nnd_tbl, dev); - nip_dbg("%s: %s (ifindex=%u) before idev put. idev->refcnt=%u", __func__, + nip_dbg("%s (ifindex=%u) before idev put. idev->refcnt=%u", dev->name, dev->ifindex, refcount_read(&idev->refcnt)); nin_dev_put(idev); } @@ -749,7 +746,7 @@ int __init nip_addrconf_init(void) err = register_pernet_subsys(&nip_route_proc_net_ops); if (err < 0) { - nip_dbg("%s: register_pernet_subsys failed", __func__); + nip_dbg("register_pernet_subsys failed"); goto out; } @@ -812,7 +809,7 @@ int nip_addrconf_get_ifaddr(struct net *net, unsigned int cmd, void __user *arg) ifr.nip_ifr_name[IFNAMSIZ - 1] = 0; snin = (struct sockaddr_nin *)&ifr.nip_dev_addr; - nip_dbg("%s, dev name is %s", __func__, ifr.nip_ifr_name); + nip_dbg("dev name is %s", ifr.nip_ifr_name); dev_load(net, ifr.nip_ifr_name); if (cmd == SIOCGIFADDR) { diff --git a/src/linux/net/newip/nip_addrconf_core.c b/src/linux/net/newip/nip_addrconf_core.c index e6835b2..914886b 100644 --- a/src/linux/net/newip/nip_addrconf_core.c +++ b/src/linux/net/newip/nip_addrconf_core.c @@ -7,12 +7,13 @@ * * Based on net/ipv6/addrconf_core.c */ -#define pr_fmt(fmt) "NIP: " fmt +#define pr_fmt(fmt) KBUILD_MODNAME ": [%s:%d] " fmt, __func__, __LINE__ #include #include #include #include +#include "tcp_nip_parameter.h" static void nin_dev_finish_destroy_rcu(struct rcu_head *head) { diff --git a/src/linux/net/newip/nip_fib.c b/src/linux/net/newip/nip_fib.c index 262c5bb..8832f90 100644 --- a/src/linux/net/newip/nip_fib.c +++ b/src/linux/net/newip/nip_fib.c @@ -7,7 +7,7 @@ * * Based on net/ipv6/ip6_fib.c */ -#define pr_fmt(fmt) "NIP: " fmt +#define pr_fmt(fmt) KBUILD_MODNAME ": [%s:%d] " fmt, __func__, __LINE__ #include #include @@ -23,6 +23,7 @@ #include #include +#include "tcp_nip_parameter.h" static struct kmem_cache *nip_fib_node_kmem __read_mostly; @@ -124,7 +125,7 @@ int nip_fib_add(struct hlist_head *nip_tb_head, struct nip_rt_info *rt) new_node = nip_node_alloc(); if (!new_node) { - nip_dbg("%s: fail to alloc mem", __func__); + nip_dbg("fail to alloc mem"); err = -ENOMEM; goto fail; } @@ -201,8 +202,7 @@ static void nip_fib_clean_hash(struct net *net, struct hlist_head *nip_tb_head, nip_addr_to_str(&fn->nip_route_info->gateway, gateway, NIP_ADDR_BIT_LEN_MAX); - nip_dbg("%s: try to del rt_info, rt_dst=%s, gateway=%s", - __func__, dst, gateway); + nip_dbg("try to del rt_info, rt_dst=%s, gateway=%s", dst, gateway); nip_fib_del(fn->nip_route_info, &info); } } diff --git a/src/linux/net/newip/nip_fib_rules.c b/src/linux/net/newip/nip_fib_rules.c index 1dc26ed..7ae1e6a 100644 --- a/src/linux/net/newip/nip_fib_rules.c +++ b/src/linux/net/newip/nip_fib_rules.c @@ -7,12 +7,13 @@ * Based on net/ipv6/fib_rules.c * Based on net/ipv6/fib6_rules.c */ -#define pr_fmt(fmt) "NIP: " fmt +#define pr_fmt(fmt) KBUILD_MODNAME ": [%s:%d] " fmt, __func__, __LINE__ #include #include #include #include +#include "tcp_nip_parameter.h" struct dst_entry *nip_fib_rule_lookup(struct net *net, struct flow_nip *fln, int flags, nip_pol_lookup_t lookup) diff --git a/src/linux/net/newip/nip_hooks_register.c b/src/linux/net/newip/nip_hooks_register.c index a88ab8f..1abb565 100644 --- a/src/linux/net/newip/nip_hooks_register.c +++ b/src/linux/net/newip/nip_hooks_register.c @@ -5,11 +5,12 @@ * Definitions for the NewIP Hooks Register module. */ #ifdef CONFIG_NEWIP_HOOKS -#define pr_fmt(fmt) "NIP: " fmt +#define pr_fmt(fmt) KBUILD_MODNAME ": [%s:%d] " fmt, __func__, __LINE__ #include /* ninet_ehashfn */ #include #include +#include "tcp_nip_parameter.h" void ninet_ehashfn_hook(void *data, const struct sock *sk, u32 *ret) { diff --git a/src/linux/net/newip/nip_hooks_register.h b/src/linux/net/newip/nip_hooks_register.h index 1d3a0e0..f5109ce 100644 --- a/src/linux/net/newip/nip_hooks_register.h +++ b/src/linux/net/newip/nip_hooks_register.h @@ -11,4 +11,4 @@ int ninet_hooks_register(void); #endif -#endif /* _NIP_HOOKS_REGISTER_H */ +#endif /* _NIP_HOOKS_REGISTER_H */ diff --git a/src/linux/net/newip/nip_input.c b/src/linux/net/newip/nip_input.c index 3282975..cacfd09 100644 --- a/src/linux/net/newip/nip_input.c +++ b/src/linux/net/newip/nip_input.c @@ -7,7 +7,7 @@ * * Based on net/ipv6/ip6_input.c */ -#define pr_fmt(fmt) "NIP-INPUT: " fmt +#define pr_fmt(fmt) KBUILD_MODNAME ": [%s:%d] " fmt, __func__, __LINE__ #include #include @@ -24,6 +24,7 @@ #include #include "nip_hdr.h" +#include "tcp_nip_parameter.h" static int _nip_update_recv_skb_len(struct sk_buff *skb, struct nip_hdr_decap *niph) @@ -32,8 +33,8 @@ static int _nip_update_recv_skb_len(struct sk_buff *skb, return 0; if (niph->total_len > skb->len) { - nip_dbg("%s: total_len(%u) is bigger than skb_len(%u), Drop a packet", - __func__, niph->total_len, skb->len); + nip_dbg("total_len(%u) is bigger than skb_len(%u), Drop a packet", + niph->total_len, skb->len); return NET_RX_DROP; } @@ -52,7 +53,7 @@ static int nip_rcv_finish(struct sk_buff *skb) if (net->ipv4.sysctl_ip_early_demux && !skb_dst(skb) && !skb->sk) { const struct ninet_protocol *ipprot; - nip_dbg("%s: try to early demux skb, nexthdr=0x%x", __func__, NIPCB(skb)->nexthdr); + nip_dbg("try to early demux skb, nexthdr=0x%x", NIPCB(skb)->nexthdr); ipprot = rcu_dereference(ninet_protos[NIPCB(skb)->nexthdr]); if (ipprot) edemux = READ_ONCE(ipprot->early_demux); @@ -87,14 +88,14 @@ int nip_rcv(struct sk_buff *skb, struct net_device *dev, memset(NIPCB(skb), 0, sizeof(struct ninet_skb_parm)); offset = nip_hdr_parse(skb->data, skb->len, &niph); if (offset <= 0) { - nip_dbg("%s check in failure, errcode=%d, Drop a packet (nexthdr=%u, hdr_len=%u)", - __func__, offset, niph.nexthdr, niph.hdr_len); + nip_dbg("check in failure, errcode=%d, Drop a packet (nexthdr=%u, hdr_len=%u)", + offset, niph.nexthdr, niph.hdr_len); goto drop; } if (niph.nexthdr != IPPROTO_UDP && niph.nexthdr != IPPROTO_TCP && niph.nexthdr != IPPROTO_NIP_ICMP) { - nip_dbg("%s nexthdr(%u) invalid, Drop a packet", __func__, niph.nexthdr); + nip_dbg("nexthdr(%u) invalid, Drop a packet", niph.nexthdr); goto drop; } diff --git a/src/linux/net/newip/nip_output.c b/src/linux/net/newip/nip_output.c index 99e327d..627b389 100644 --- a/src/linux/net/newip/nip_output.c +++ b/src/linux/net/newip/nip_output.c @@ -7,7 +7,7 @@ * * Based on net/ipv6/ip6_output.c */ -#define pr_fmt(fmt) "NIP-OUTPUT: " fmt +#define pr_fmt(fmt) KBUILD_MODNAME ": [%s:%d] " fmt, __func__, __LINE__ #include #include @@ -33,6 +33,7 @@ #include "nip_hdr.h" #include "nip_checksum.h" +#include "tcp_nip_parameter.h" #define NIP_BIT_TO_BYTE 1024 void update_memory_rate(const char *upper_fun) @@ -48,7 +49,7 @@ void update_memory_rate(const char *upper_fun) total = (unsigned long)mem_info.totalram * uint_kb; free = (unsigned long)mem_info.freeram * uint_kb; used = total - free; - nip_dbg("%s -> %s mem total: %ld KB, mem used: %ld KB", upper_fun, __func__, total, used); + nip_dbg("%s call cur-func mem total: %ld KB, mem used: %ld KB", upper_fun, total, used); } int nip_output(struct net *net, struct sock *sk, struct sk_buff *skb) @@ -106,7 +107,7 @@ int nip_send_skb(struct sk_buff *skb) if (err) { if (err > 0) err = net_xmit_errno(err); - nip_dbg("%s: failed to out skb, err = %d", __func__, err); + nip_dbg("failed to out skb, err = %d", err); } return err; @@ -139,7 +140,7 @@ static struct sk_buff *_nip_alloc_skb(struct sock *sk, len = NIP_ETH_HDR_LEN + nip_hdr_len + head->trans_hdr_len + seg_info->mid_usr_pkt_len; skb = alloc_skb(len, 0); if (!skb) { - nip_dbg("%s: no space for skb", __func__); + nip_dbg("no space for skb"); return NULL; } @@ -149,8 +150,7 @@ static struct sk_buff *_nip_alloc_skb(struct sock *sk, skb->sk = sk; dst_hold(dst); - nip_dbg("%s: malloc_len=%d, dst->__refcnt=%u", __func__, - len, atomic_read(&dst->__refcnt)); + nip_dbg("malloc_len=%d, dst->__refcnt=%u", len, atomic_read(&dst->__refcnt)); skb_dst_set(skb, dst); memset(NIPCB(skb), 0, sizeof(struct ninet_skb_parm)); @@ -169,7 +169,7 @@ static int _nip_udp_single_output(struct sock *sk, unsigned short check = 0; if (IS_ERR_OR_NULL(skb)) { - nip_dbg("%s: skb alloc fail", __func__); + nip_dbg("skb alloc fail"); return -ENOMEM; } @@ -198,7 +198,7 @@ static int _nip_udp_single_output(struct sock *sk, /* The DST has been set to the SKB. When the SKB is released, * the DST is automatically released */ - nip_dbg("%s: copy from iter fail (datalen=%u)", __func__, head->usr_data_len); + nip_dbg("copy from iter fail (datalen=%u)", head->usr_data_len); kfree_skb(skb); return -EFBIG; } @@ -224,7 +224,7 @@ static int _nip_udp_single_output(struct sock *sk, skb->priority = sk->sk_priority; ret = nip_send_skb(skb); - nip_dbg("%s: newip output finish (ret=%d, datalen=%u)", __func__, ret, head->usr_data_len); + nip_dbg("output finish (ret=%d, datalen=%u)", ret, head->usr_data_len); update_memory_rate(__func__); return ret; } @@ -302,7 +302,7 @@ static int nip_dst_lookup_tail(struct net *net, const struct sock *sk, err = (*dst)->error; if (err) { rt = NULL; - nip_dbg("%s: nip_route_output search error", __func__); + nip_dbg("route output search error"); goto out_err_release; } @@ -387,13 +387,13 @@ int tcp_nip_queue_xmit(struct sock *sk, struct sk_buff *skb, struct flowi *fl) fln.daddr = sk->sk_nip_daddr; dst = __sk_dst_check(sk, 0); if (!dst) { - nip_dbg("%s: no dst cache for sk, search newip rt", __func__); + nip_dbg("no dst cache for sk, search newip rt"); dst = nip_route_output(net, sk, &fln); err = dst->error; if (err) goto out_err_release; if (!dst) { - nip_dbg("%s: cannot find dst", __func__); + nip_dbg("cannot find dst"); goto out; } sk_dst_set(sk, dst); @@ -413,9 +413,9 @@ int tcp_nip_queue_xmit(struct sock *sk, struct sk_buff *skb, struct flowi *fl) head.total_len = skb->len; err = nip_send_skb(skb); if (err) - nip_dbg("%s: failed to send skb, skb->len=%u", __func__, head.total_len); + nip_dbg("failed to send skb, skb->len=%u", head.total_len); else - nip_dbg("%s: send skb ok, skb->len=%u", __func__, head.total_len); + nip_dbg("send skb ok, skb->len=%u", head.total_len); out: rcu_read_unlock(); @@ -474,10 +474,10 @@ void tcp_nip_actual_send_reset(struct sock *sk, struct sk_buff *skb, u32 seq, t1->rst = rst; t1->window = htons(win); t1->check = htons(nip_get_output_checksum_tcp(buff, *saddr, *daddr)); - nip_dbg("%s: host dport=%u, net dport=0x%x, host sport=%u, net sport=0x%x", - __func__, ntohs(t1->dest), t1->dest, ntohs(t1->source), t1->source); - nip_dbg("%s: host seq=%u, net seq=0x%x, host ack_seq=%u, net ack_seq=0x%x", - __func__, seq, t1->seq, ack_seq, t1->ack_seq); + nip_dbg("host dport=%u, net dport=0x%x, host sport=%u, net sport=0x%x", + ntohs(t1->dest), t1->dest, ntohs(t1->source), t1->source); + nip_dbg("host seq=%u, net seq=0x%x, host ack_seq=%u, net ack_seq=0x%x", + seq, t1->seq, ack_seq, t1->ack_seq); buff->protocol = htons(ETH_P_NEWIP); buff->ip_summed = CHECKSUM_NONE; @@ -497,7 +497,7 @@ void tcp_nip_actual_send_reset(struct sock *sk, struct sk_buff *skb, u32 seq, fln.daddr = *daddr; dst = nip_route_output(net, sk, &fln); // here, sk not used. if (!dst) { - nip_dbg("%s: cannot find dst", __func__); + nip_dbg("cannot find dst"); goto out; } skb_dst_set_noref(buff, dst); @@ -515,9 +515,9 @@ void tcp_nip_actual_send_reset(struct sock *sk, struct sk_buff *skb, u32 seq, head.total_len = buff->len; err = nip_send_skb(buff); if (err) - nip_dbg("%s: failed to send skb, skb->len=%u", __func__, head.total_len); + nip_dbg("failed to send skb, skb->len=%u", head.total_len); else - nip_dbg("%s: send skb ok, skb->len=%u", __func__, head.total_len); + nip_dbg("send skb ok, skb->len=%u", head.total_len); out: return; diff --git a/src/linux/net/newip/nip_sockglue.c b/src/linux/net/newip/nip_sockglue.c index c24b305..1ae978e 100644 --- a/src/linux/net/newip/nip_sockglue.c +++ b/src/linux/net/newip/nip_sockglue.c @@ -10,7 +10,7 @@ * * Based on net/ipv4/ip_sockglue.c */ -#define pr_fmt(fmt) "NIP: " fmt +#define pr_fmt(fmt) KBUILD_MODNAME ": [%s:%d] " fmt, __func__, __LINE__ #include #include @@ -23,6 +23,7 @@ #include #include #include +#include "tcp_nip_parameter.h" #define NIP_OPTNAME_MAX 255 diff --git a/src/linux/net/newip/nndisc.c b/src/linux/net/newip/nndisc.c index c0ffe3e..59d1a2a 100644 --- a/src/linux/net/newip/nndisc.c +++ b/src/linux/net/newip/nndisc.c @@ -7,7 +7,7 @@ * * Based on net/ipv6/ndisc.c */ -#define pr_fmt(fmt) "NIP-ND: " fmt +#define pr_fmt(fmt) KBUILD_MODNAME ": [%s:%d] " fmt, __func__, __LINE__ #include #include @@ -38,6 +38,7 @@ #include #include "nip_hdr.h" #include "nip_checksum.h" +#include "tcp_nip_parameter.h" /* NUD_INCOMPLETE * The neighbor request packet has been sent but no response has been received @@ -357,7 +358,7 @@ static void nndisc_send_ns(struct net_device *dev, ret = nndisc_send_skb(dev, skb, &head, payload_len); if (ret) - nip_dbg("%s: dst output fail", __func__); + nip_dbg("dst output fail"); } static void nndisc_solicit(struct neighbour *neigh, struct sk_buff *skb) @@ -386,7 +387,7 @@ static void nndisc_solicit(struct neighbour *neigh, struct sk_buff *skb) } read_unlock_bh(&idev->lock); } else { - nip_dbg("%s:idev don't exist", __func__); + nip_dbg("idev don't exist"); } rcu_read_unlock(); } @@ -439,7 +440,7 @@ static void nndisc_send_na(struct net_device *dev, ret = nndisc_send_skb(dev, skb, &head, payload_len); if (ret) - nip_dbg("%s: dst output fail", __func__); + nip_dbg("dst output fail"); } bool nip_addr_local(struct net_device *dev, struct nip_addr *addr) @@ -488,7 +489,7 @@ int nndisc_rcv_ns(struct sk_buff *skb) } if (nip_addr_invalid(&addr)) { - nip_dbg("%s: icmp hdr addr invalid, bitlen=%u", __func__, addr.bitlen); + nip_dbg("icmp hdr addr invalid, bitlen=%u", addr.bitlen); err = -EFAULT; goto out; } @@ -503,7 +504,7 @@ int nndisc_rcv_ns(struct sk_buff *skb) /* checksum parse */ if (!nip_get_nndisc_rcv_checksum(skb, p)) { - nip_dbg("%s:ns ICMP checksum failed, drop the packet", __func__); + nip_dbg("ns ICMP checksum failed, drop the packet"); err = -EINVAL; goto out; } @@ -535,7 +536,7 @@ int nndisc_rcv_na(struct sk_buff *skb) memcpy(lladdr, p, len); if (!nip_get_nndisc_rcv_checksum(skb, p + len)) { - nip_dbg("%s:na ICMP checksum failed, drop the packet", __func__); + nip_dbg("na ICMP checksum failed, drop the packet"); kfree_skb(skb); return 0; } diff --git a/src/linux/net/newip/protocol.c b/src/linux/net/newip/protocol.c index 8d7f3ea..928917a 100644 --- a/src/linux/net/newip/protocol.c +++ b/src/linux/net/newip/protocol.c @@ -10,12 +10,13 @@ * * Based on net/ipv6/protocol.c */ -#define pr_fmt(fmt) "NIP: " fmt +#define pr_fmt(fmt) KBUILD_MODNAME ": [%s:%d] " fmt, __func__, __LINE__ #include #include #include #include +#include "tcp_nip_parameter.h" const struct ninet_protocol __rcu *ninet_protos[MAX_INET_PROTOS] __read_mostly; diff --git a/src/linux/net/newip/route.c b/src/linux/net/newip/route.c index 5a89e1d..7e517d1 100644 --- a/src/linux/net/newip/route.c +++ b/src/linux/net/newip/route.c @@ -12,7 +12,7 @@ * Based on net/ipv4/route.c * Based on net/ipv6/route.c */ -#define pr_fmt(fmt) "NIP: " fmt +#define pr_fmt(fmt) KBUILD_MODNAME ": [%s:%d] " fmt, __func__, __LINE__ #include #include @@ -42,6 +42,7 @@ #include #include "nip_hdr.h" +#include "tcp_nip_parameter.h" static int nip_pkt_discard(struct sk_buff *skb); static int nip_pkt_discard_out(struct net *net, struct sock *sk, @@ -267,7 +268,7 @@ void nip_route_input(struct sk_buff *skb) }; if (nip_addr_eq(&fln.daddr, &nip_broadcast_addr_arp)) { - nip_dbg("%s: recv broadcast packet", __func__); + nip_dbg("recv broadcast packet"); dst_hold(&net->newip.nip_broadcast_entry->dst); skb_dst_set(skb, (struct dst_entry *)net->newip.nip_broadcast_entry); @@ -327,7 +328,7 @@ struct nip_rt_info *nip_pol_route(struct net *net, struct nip_fib_table *table, fn = nip_fib_locate(table->nip_tb_head, &fln->daddr); if (!fn) { rcu_read_unlock_bh(); - nip_dbg("%s: search fail", __func__); + nip_dbg("search fail"); rt = net->newip.nip_null_entry; dst_hold_and_use(&rt->dst, jiffies); return rt; @@ -338,10 +339,10 @@ struct nip_rt_info *nip_pol_route(struct net *net, struct nip_fib_table *table, rt->dst.lastuse = jiffies; rt->dst.__use++; pcpu_rt = nip_rt_get_pcpu_route(rt); - nip_dbg("%s: cpu id=%d", __func__, smp_processor_id()); + nip_dbg("cpu id=%d", smp_processor_id()); if (pcpu_rt) { rcu_read_unlock_bh(); - nip_dbg("%s: pcpu found", __func__); + nip_dbg("pcpu found"); } else { dst_hold(&rt->dst); rcu_read_unlock_bh(); @@ -349,7 +350,7 @@ struct nip_rt_info *nip_pol_route(struct net *net, struct nip_fib_table *table, dst_release(&rt->dst); } - nip_dbg("%s: rt dst.__refcnt=%d, pcpu dst.__refcnt=%d", __func__, + nip_dbg("rt dst.__refcnt=%d, pcpu dst.__refcnt=%d", atomic_read(&rt->dst.__refcnt), atomic_read(&pcpu_rt->dst.__refcnt)); return pcpu_rt; @@ -362,12 +363,12 @@ bool nip_bind_addr_check(struct net *net, struct nip_fib_table *fib_tbl = net->newip.nip_fib_local_tbl; if (nip_addr_invalid(addr)) { - nip_dbg("%s: binding-addr invalid, bitlen=%u", __func__, addr->bitlen); + nip_dbg("binding-addr invalid, bitlen=%u", addr->bitlen); return false; } if (nip_addr_eq(addr, &nip_any_addr)) { - nip_dbg("%s: binding-addr is any addr", __func__); + nip_dbg("binding-addr is any addr"); return true; } @@ -375,11 +376,11 @@ bool nip_bind_addr_check(struct net *net, fn = nip_fib_locate(fib_tbl->nip_tb_head, addr); rcu_read_unlock_bh(); if (!fn) { - nip_dbg("%s: binding-addr is not local addr", __func__); + nip_dbg("binding-addr is not local addr"); return false; } - nip_dbg("%s: binding-addr is local addr", __func__); + nip_dbg("binding-addr is local addr"); return true; } @@ -395,14 +396,14 @@ static struct nip_rt_info *nip_route_info_create(struct nip_fib_config *cfg) /* find net_device */ dev = dev_get_by_index(net, cfg->fc_ifindex); if (!dev) { - nip_dbg("%s: fail to get dev by ifindex(%u)", __func__, cfg->fc_ifindex); + nip_dbg("fail to get dev by ifindex(%u)", cfg->fc_ifindex); goto out; } /* find ninet_dev,which has the newip address list */ idev = nin_dev_get(dev); if (!idev) { - nip_dbg("%s: fail to get ninet dev (ifindex=%u)", __func__, cfg->fc_ifindex); + nip_dbg("fail to get ninet dev (ifindex=%u)", cfg->fc_ifindex); goto out; } @@ -412,13 +413,13 @@ static struct nip_rt_info *nip_route_info_create(struct nip_fib_config *cfg) err = -ENOBUFS; table = nip_fib_get_table(net, cfg->fc_table); if (!table) { - nip_dbg("%s: fail to get fib table (fc_table=%u)", __func__, cfg->fc_table); + nip_dbg("fail to get fib table (fc_table=%u)", cfg->fc_table); goto out; } rt = nip_dst_alloc(net, NULL, (cfg->fc_flags & RTF_ADDRCONF) ? 0 : DST_NOCOUNT); if (!rt) { - nip_dbg("%s: fail to alloc dst mem", __func__); + nip_dbg("fail to alloc dst mem"); err = -ENOMEM; goto out; } @@ -493,7 +494,7 @@ int nip_route_add(struct nip_fib_config *cfg) rt = nip_route_info_create(cfg); if (IS_ERR(rt)) { - nip_dbg("%s: fail to creat route info", __func__); + nip_dbg("fail to creat route info"); err = PTR_ERR(rt); rt = NULL; goto out; @@ -565,20 +566,20 @@ int nip_route_ioctl(struct net *net, unsigned int cmd, struct nip_rtmsg *rtmsg) int err; if (!ns_capable(net->user_ns, CAP_NET_ADMIN)) { - nip_dbg("%s: not admin can`t cfg", __func__); + nip_dbg("not admin can`t cfg"); return -EPERM; } rtmsg_to_fibni_config(net, rtmsg, &cfg); if (nip_addr_invalid(&cfg.fc_dst)) { - nip_dbg("%s: nip daddr invalid, bitlen=%u", __func__, cfg.fc_dst.bitlen); + nip_dbg("nip daddr invalid, bitlen=%u", cfg.fc_dst.bitlen); return -EFAULT; } if (cfg.fc_flags & RTF_GATEWAY) { if (nip_addr_invalid(&cfg.fc_gateway)) { - nip_dbg("%s: nip gateway daddr invalid, bitlen=%u", - __func__, cfg.fc_gateway.bitlen); + nip_dbg("nip gateway daddr invalid, bitlen=%u", + cfg.fc_gateway.bitlen); return -EFAULT; } } @@ -611,12 +612,12 @@ static void nip_dst_destroy(struct dst_entry *dst) idev = rt->rt_idev; if (idev) { rt->rt_idev = NULL; - nip_dbg("%s: idev->refcnt=%u", __func__, refcount_read(&idev->refcnt)); + nip_dbg("idev->refcnt=%u", refcount_read(&idev->refcnt)); nin_dev_put(idev); } if (from) - nip_dbg("%s: from->__refcnt=%d", __func__, atomic_read(&from->__refcnt)); + nip_dbg("from->__refcnt=%d", atomic_read(&from->__refcnt)); rt->from = NULL; dst_release(from); } @@ -778,10 +779,10 @@ static int nip_fib_ifdown(struct nip_rt_info *rt, void *arg) (dev_unregister || ignore_route_ifdown)) return -1; - nip_dbg("%s: don`t del route with %s down, ifindex=%u, not_same_dev=%u, not_null_entry=%u", - __func__, dev->name, dev->ifindex, not_same_dev, not_null_entry); - nip_dbg("%s: not_broadcast_entry=%u, dev_unregister=%u, ignore_route_ifdown=%u", - __func__, not_broadcast_entry, dev_unregister, ignore_route_ifdown); + nip_dbg("don`t del route with %s down, ifindex=%u, not_same_dev=%u, not_null_entry=%u", + dev->name, dev->ifindex, not_same_dev, not_null_entry); + nip_dbg("not_broadcast_entry=%u, dev_unregister=%u, ignore_route_ifdown=%u", + not_broadcast_entry, dev_unregister, ignore_route_ifdown); return 0; } diff --git a/src/linux/net/newip/tcp_nip.c b/src/linux/net/newip/tcp_nip.c index 2a1bf02..20f6a3a 100644 --- a/src/linux/net/newip/tcp_nip.c +++ b/src/linux/net/newip/tcp_nip.c @@ -50,7 +50,7 @@ * * TCP_CLOSE socket is finished */ -#define pr_fmt(fmt) "NIP-TCP: " fmt +#define pr_fmt(fmt) KBUILD_MODNAME ": [%s:%d] " fmt, __func__, __LINE__ #include #include @@ -104,7 +104,7 @@ static const unsigned char new_state[16] = { [TCP_LAST_ACK] = TCP_LAST_ACK, [TCP_LISTEN] = TCP_CLOSE, [TCP_CLOSING] = TCP_CLOSING, -[TCP_NEW_SYN_RECV] = TCP_CLOSE, /* should not happen ! */ +[TCP_NEW_SYN_RECV] = TCP_CLOSE, /* should not happen ! */ }; bool nip_get_tcp_input_checksum(struct sk_buff *skb) @@ -170,15 +170,15 @@ void tcp_nip_close(struct sock *sk, long timeout) lock_sock(sk); sk->sk_shutdown = SHUTDOWN_MASK; - nip_dbg("%s: sk_state:%d", __func__, sk->sk_state); + nip_dbg("sk_state:%d", sk->sk_state); if (sk->sk_state == TCP_LISTEN) { tcp_set_state(sk, TCP_CLOSE); sk_ack_backlog = READ_ONCE(sk->sk_ack_backlog); inet_csk_listen_stop(sk); - nip_dbg("%s: sk_state CLOSE, sk_ack_backlog=%u to %u, sk_max_ack_backlog=%u", - __func__, sk_ack_backlog, READ_ONCE(sk->sk_ack_backlog), + nip_dbg("sk_state CLOSE, sk_ack_backlog=%u to %u, sk_max_ack_backlog=%u", + sk_ack_backlog, READ_ONCE(sk->sk_ack_backlog), READ_ONCE(sk->sk_max_ack_backlog)); goto adjudge_to_death; } @@ -206,7 +206,7 @@ void tcp_nip_close(struct sock *sk, long timeout) * TCP_SYN_RECV -> TCP_FIN_WAIT1 (forget it, it's impossible) * TCP_CLOSE_WAIT -> TCP_LAST_ACK */ - nip_dbg("%s: ready to send fin, sk_state=%d", __func__, sk->sk_state); + nip_dbg("ready to send fin, sk_state=%d", sk->sk_state); tcp_nip_send_fin(sk); } @@ -326,11 +326,11 @@ static int tcp_nip_connect(struct sock *sk, struct sockaddr *uaddr, orig_dport = usin->sin_port; /* Find the route and obtain the source address */ - nip_dbg("%s, sk->sk_bound_dev_if is %d", __func__, sk->sk_bound_dev_if); + nip_dbg("sk->sk_bound_dev_if is %d", sk->sk_bound_dev_if); fln.flowin_oif = sk->sk_bound_dev_if; dst = nip_dst_lookup_flow(sock_net(sk), sk, &fln, NULL); if (IS_ERR(dst)) { - nip_dbg("%s cannot find dst", __func__); + nip_dbg("cannot find dst"); err = PTR_ERR(dst); goto failure; } @@ -341,13 +341,13 @@ static int tcp_nip_connect(struct sock *sk, struct sockaddr *uaddr, fln.saddr = sk->sk_nip_rcv_saddr; if (nip_addr_invalid(&fln.daddr)) { - nip_dbg("%s: nip daddr invalid, bitlen=%u", __func__, fln.daddr.bitlen); + nip_dbg("nip daddr invalid, bitlen=%u", fln.daddr.bitlen); err = -EFAULT; goto failure; } if (nip_addr_invalid(&fln.saddr)) { - nip_dbg("%s: nip saddr invalid, bitlen=%u", __func__, fln.saddr.bitlen); + nip_dbg("nip saddr invalid, bitlen=%u", fln.saddr.bitlen); err = -EFAULT; goto failure; } @@ -415,7 +415,7 @@ static void tcp_nip_send_reset(struct sock *sk, struct sk_buff *skb) if (th->rst) return; - nip_dbg("%s: send RST", __func__); + nip_dbg("send rst"); if (th->ack) seq = ntohl(th->ack_seq); else @@ -447,7 +447,7 @@ static int tcp_nip_send_synack(const struct sock *sk, struct dst_entry *dst, skb = tcp_nip_make_synack(sk, dst, req, foc, synack_type); if (skb) { - nip_dbg("%s: TCP server create SYN+ACK skb successfully", __func__); + nip_dbg("TCP server create SYN+ACK skb successfully"); rcu_read_lock(); err = nip_send_synack(req, skb); rcu_read_unlock(); @@ -641,7 +641,7 @@ static int tcp_nip_keepalive_para_update(struct sock *sk, /* set keep idle (TCP_KEEPIDLE) */ val = keepalive_time; if (val < 1 || val > MAX_NIP_TCP_KEEPIDLE) { - nip_dbg("%s keepalive_time(%u) invalid", __func__, val); + nip_dbg("keepalive_time(%u) invalid", val); return -EINVAL; } @@ -660,7 +660,7 @@ static int tcp_nip_keepalive_para_update(struct sock *sk, /* set keep intvl (TCP_KEEPINTVL) */ val = keepalive_intvl; if (val < 1 || val > MAX_NIP_TCP_KEEPINTVL) { - nip_dbg("%s keepalive_intvl(%u) invalid", __func__, val); + nip_dbg("keepalive_intvl(%u) invalid", val); return -EINVAL; } tp->keepalive_intvl = val; @@ -668,7 +668,7 @@ static int tcp_nip_keepalive_para_update(struct sock *sk, /* set keep cnt (TCP_KEEPCNT) */ val = keepalive_probes; if (val < 1 || val > MAX_NIP_TCP_KEEPCNT) { - nip_dbg("%s keepalive_probes(%u) invalid", __func__, val); + nip_dbg("keepalive_probes(%u) invalid", val); return -EINVAL; } tp->keepalive_probes = val; @@ -678,7 +678,7 @@ static int tcp_nip_keepalive_para_update(struct sock *sk, sk->sk_prot->keepalive(sk, 1); sock_valbool_flag(sk, SOCK_KEEPOPEN, 1); } else { - nip_dbg("%s keepalive func is null", __func__); + nip_dbg("keepalive func is null"); } return 0; @@ -705,8 +705,8 @@ void tcp_nip_keepalive_enable(struct sock *sk) ntp->keepalive_probes_bak = tp->keepalive_probes; ntp->keepalive_intvl_bak = tp->keepalive_intvl; - nip_dbg("%s HZ=%u, change time/probes/intvl [%u, %u, %u] to [%u, %u, %u]", - __func__, HZ, tp->keepalive_time, tp->keepalive_probes, + nip_dbg("HZ=%u, change time/probes/intvl [%u, %u, %u] to [%u, %u, %u]", + HZ, tp->keepalive_time, tp->keepalive_probes, tp->keepalive_intvl, get_nip_keepalive_time(), NIP_KEEPALIVE_PROBES, get_nip_keepalive_intvl()); @@ -723,7 +723,7 @@ void tcp_nip_keepalive_enable(struct sock *sk) ntp->keepalive_time_bak = tp->keepalive_time; ntp->keepalive_probes_bak = tp->keepalive_probes; ntp->keepalive_intvl_bak = tp->keepalive_intvl; - nip_dbg("%s HZ=%u, backup normal time/probes/intvl [%u, %u, %u]", __func__, + nip_dbg("HZ=%u, backup normal time/probes/intvl [%u, %u, %u]", HZ, tp->keepalive_time, tp->keepalive_probes, tp->keepalive_intvl); } @@ -732,14 +732,13 @@ void tcp_nip_keepalive_enable(struct sock *sk) get_nip_keepalive_intvl(), NIP_KEEPALIVE_PROBES); if (ret != 0) { - nip_dbg("%s fail, HZ=%u, time/probes/intvl [%u, %u, %u]", __func__, + nip_dbg("fail, HZ=%u, time/probes/intvl [%u, %u, %u]", HZ, tp->keepalive_time, tp->keepalive_probes, tp->keepalive_intvl); return; } - nip_dbg("%s ok, HZ=%u, time/probes/intvl [%u, %u, %u]", - __func__, HZ, tp->keepalive_time, tp->keepalive_probes, - tp->keepalive_intvl); + nip_dbg("ok, HZ=%u, time/probes/intvl [%u, %u, %u]", + HZ, tp->keepalive_time, tp->keepalive_probes, tp->keepalive_intvl); ntp->nip_keepalive_enable = true; #endif } @@ -755,7 +754,7 @@ void tcp_nip_keepalive_disable(struct sock *sk) if (!sock_flag(sk, SOCK_KEEPOPEN)) { ntp->nip_keepalive_enable = false; - nip_dbg("%s ok, HZ=%u, normal ka has disable", __func__, HZ); + nip_dbg("ok, HZ=%u, normal ka has disable", HZ); return; } @@ -764,8 +763,8 @@ void tcp_nip_keepalive_disable(struct sock *sk) /* newip keepalive change to normal keepalive */ if (ntp->keepalive_time_bak) { - nip_dbg("%s HZ=%u, change normal time/probes/intvl [%u, %u, %u] to [%u, %u, %u]", - __func__, HZ, tp->keepalive_time, tp->keepalive_probes, + nip_dbg("HZ=%u, change normal time/probes/intvl [%u, %u, %u] to [%u, %u, %u]", + HZ, tp->keepalive_time, tp->keepalive_probes, tp->keepalive_intvl, ntp->keepalive_time_bak, ntp->keepalive_probes_bak, ntp->keepalive_intvl_bak); tp->keepalive_time = ntp->keepalive_time_bak; @@ -784,7 +783,7 @@ void tcp_nip_keepalive_disable(struct sock *sk) sk->sk_prot->keepalive(sk, 0); sock_valbool_flag(sk, SOCK_KEEPOPEN, 0); - nip_dbg("%s ok, HZ=%u, idle_ka_probes_out=%u", __func__, HZ, get_nip_idle_ka_probes_out()); + nip_dbg("ok, HZ=%u, idle_ka_probes_out=%u", HZ, get_nip_idle_ka_probes_out()); ntp->nip_keepalive_enable = false; #endif } @@ -944,7 +943,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); - nip_dbg("%s: mss_now=%d", __func__, mss_now); + nip_dbg("mss_now=%d", mss_now); err = -EPIPE; if (sk->sk_err || (sk->sk_shutdown & SEND_SHUTDOWN)) @@ -986,7 +985,7 @@ restart: if (err) goto do_fault; } else { - nip_dbg("%s: msg too big, tcp cannot devide packet now", __func__); + nip_dbg("msg too big, tcp cannot devide packet now"); goto out; } @@ -1143,7 +1142,7 @@ int tcp_nip_recvmsg(struct sock *sk, struct msghdr *msg, size_t len, int nonbloc break; offset = *seq - TCP_SKB_CB(skb)->seq; if (unlikely(TCP_SKB_CB(skb)->tcp_flags & TCPHDR_SYN)) { - pr_err_once("%s: found a SYN, please report !", __func__); + pr_err_once("found a SYN, please report"); offset--; } if (offset < skb->len) @@ -1211,7 +1210,7 @@ int tcp_nip_recvmsg(struct sock *sk, struct msghdr *msg, size_t len, int nonbloc release_sock(sk); lock_sock(sk); } else { - nip_dbg("%s: no enough data receive queue, wait", __func__); + nip_dbg("no enough data receive queue, wait"); sk_wait_data(sk, &timeo, last); } continue; @@ -1219,11 +1218,11 @@ found_ok_skb: used = skb->len - offset; if (len_tmp < used) used = len_tmp; - nip_dbg("%s: copy data into msg, len=%ld", __func__, used); + nip_dbg("copy data into msg, len=%ld", used); if (!(flags & MSG_TRUNC)) { err = skb_copy_datagram_msg(skb, offset, msg, used); if (err) { - nip_dbg("%s: copy data failed", __func__); + nip_dbg("copy data failed"); if (!copied) copied = -EFAULT; break; @@ -1299,7 +1298,7 @@ void tcp_nip_destroy_sock(struct sock *sk) */ static int tcp_nip_do_rcv(struct sock *sk, struct sk_buff *skb) { - nip_dbg("%s: received newip tcp skb, sk_state=%d", __func__, sk->sk_state); + nip_dbg("received newip tcp skb, sk_state=%d", sk->sk_state); if (sk->sk_state == TCP_ESTABLISHED) { struct dst_entry *dst = sk->sk_rx_dst; @@ -1372,7 +1371,7 @@ static bool tcp_nip_add_backlog(struct sock *sk, struct sk_buff *skb) if (unlikely(sk_add_backlog(sk, skb, limit))) { bh_unlock_sock(sk); __NET_INC_STATS(sock_net(sk), LINUX_MIB_TCPBACKLOGDROP); - nip_dbg("%s: insert backlog fail", __func__); + nip_dbg("insert backlog fail"); return true; } return false; @@ -1393,40 +1392,39 @@ static int tcp_nip_rcv(struct sk_buff *skb) int dif = skb->skb_iif; if (skb->pkt_type != PACKET_HOST) { - nip_dbg("%s unknown pkt-type(%u), drop skb", __func__, skb->pkt_type); + nip_dbg("unknown pkt-type(%u), drop skb", skb->pkt_type); goto discard_it; } if (!nip_get_tcp_input_checksum(skb)) { - nip_dbg("%s checksum fail, drop skb", __func__); + nip_dbg("checksum fail, drop skb"); goto discard_it; } th = (const struct tcphdr *)skb->data; if (unlikely(th->doff < sizeof(struct tcphdr) / TCP_NUM_4)) { - nip_dbg("%s non-four byte alignment, drop skb", __func__); + nip_dbg("non-four byte alignment, drop skb"); goto discard_it; } sk = __ninet_lookup_skb(&tcp_hashinfo, skb, __tcp_hdrlen(th), th->source, th->dest, dif, &refcounted); if (!sk) { - nip_dbg("%s: can`t find related sock for skb, will disconnect", __func__); + nip_dbg("can`t find related sock for skb, will disconnect"); goto no_tcp_socket; } if (sk->sk_state == TCP_TIME_WAIT) { /* Handles the SK portion of the interrupt state */ - nip_dbg("%s sk_state is TCP_TIME_WAIT, drop skb", __func__); + nip_dbg("sk_state is TCP_TIME_WAIT, drop skb"); goto discard_it; } if (sk->sk_state == TCP_NEW_SYN_RECV) { struct request_sock *req = inet_reqsk(sk); struct sock *nsk; - nip_dbg("%s: TCP server into third shake hands, sk->sk_state:%d", - __func__, sk->sk_state); + nip_dbg("TCP server into third shake hands, sk->sk_state:%d", sk->sk_state); sk = req->rsk_listener; sock_hold(sk); @@ -1441,12 +1439,12 @@ static int tcp_nip_rcv(struct sk_buff *skb) nsk = tcp_nip_check_req(sk, skb, req); } if (!nsk || nsk == sk) { - nip_dbg("%s skb info error and create newsk failure, drop skb", __func__); + nip_dbg("skb info error and create newsk failure, drop skb"); reqsk_put(req); goto discard_and_relse; } if (tcp_nip_child_process(sk, nsk, skb)) { - nip_dbg("%s child process fail, drop skb", __func__); + nip_dbg("child process fail, drop skb"); goto discard_and_relse; } else { sock_put(sk); @@ -1457,15 +1455,14 @@ static int tcp_nip_rcv(struct sk_buff *skb) tcp_nip_fill_cb(skb, th); if (tcp_filter(sk, skb)) { - nip_dbg("%s tcp filter fail, drop skb", __func__); + nip_dbg("tcp filter fail, drop skb"); goto discard_and_relse; } th = (const struct tcphdr *)skb->data; skb->dev = NULL; if (sk->sk_state == TCP_LISTEN) { - nip_dbg("%s: TCP server into first shake hands! sk->sk_state:%d", - __func__, sk->sk_state); + nip_dbg("TCP server into first shake hands! sk->sk_state:%d", sk->sk_state); ret = tcp_nip_do_rcv(sk, skb); goto put_and_return; } @@ -1475,9 +1472,9 @@ static int tcp_nip_rcv(struct sk_buff *skb) if (!sock_owned_by_user(sk)) { ret = tcp_nip_do_rcv(sk, skb); } else { - nip_dbg("%s: sock locked by user, put packet into backlog", __func__); + nip_dbg("sock locked by user, put packet into backlog"); if (tcp_nip_add_backlog(sk, skb)) { - nip_dbg("%s add backlog fail, drop skb", __func__); + nip_dbg("add backlog fail, drop skb"); goto discard_and_relse; } } @@ -1530,7 +1527,7 @@ static void tcp_nip_early_demux(struct sk_buff *skb) if (dst) dst = dst_check(dst, 0); if (dst && inet_sk(sk)->rx_dst_ifindex == skb->skb_iif) { - nip_dbg("%s: find sock in ehash, set dst for skb", __func__); + nip_dbg("find sock in ehash, set dst for skb"); skb_dst_set_noref(skb, dst); } } @@ -1570,7 +1567,7 @@ void tcp_nip_done(struct sock *sk) this_cpu_dec(*sk->sk_prot->orphan_count); local_bh_enable(); sock_put(sk); - nip_dbg("%s: close sock done", __func__); + nip_dbg("close sock done"); } } @@ -1589,14 +1586,15 @@ int tcp_nip_disconnect(struct sock *sk, int flags) int old_state = sk->sk_state; u32 sk_ack_backlog; + nip_dbg("old_state=%u", old_state); if (old_state != TCP_CLOSE) tcp_set_state(sk, TCP_CLOSE); if (old_state == TCP_LISTEN) { sk_ack_backlog = READ_ONCE(sk->sk_ack_backlog); inet_csk_listen_stop(sk); - nip_dbg("%s: sk_state CLOSE, sk_ack_backlog=%u to %u, sk_max_ack_backlog=%u", - __func__, sk_ack_backlog, READ_ONCE(sk->sk_ack_backlog), + nip_dbg("sk_state CLOSE, sk_ack_backlog=%u to %u, sk_max_ack_backlog=%u", + sk_ack_backlog, READ_ONCE(sk->sk_ack_backlog), READ_ONCE(sk->sk_max_ack_backlog)); } else if (tcp_nip_need_reset(old_state) || (tp->snd_nxt != tp->write_seq && (1 << old_state) & (TCPF_CLOSING | TCPF_LAST_ACK))) { @@ -1620,7 +1618,12 @@ int tcp_nip_disconnect(struct sock *sk, int flags) if (tp->write_seq == 0) tp->write_seq = 1; tp->snd_cwnd = TCP_NUM_2; + icsk->icsk_backoff = 0; icsk->icsk_probes_out = 0; + icsk->icsk_probes_tstamp = 0; + icsk->icsk_rto = get_nip_rto() == 0 ? TCP_TIMEOUT_INIT : (HZ / get_nip_rto()); + icsk->icsk_rto_min = TCP_RTO_MIN; + icsk->icsk_delack_max = TCP_DELACK_MAX; tp->packets_out = 0; tp->snd_ssthresh = TCP_INFINITE_SSTHRESH; tp->snd_cwnd_cnt = 0; @@ -1662,8 +1665,8 @@ struct sock *ninet_csk_accept(struct sock *sk, int flags, int *err, bool kern) u32 sk_max_ack_backlog = READ_ONCE(sk->sk_max_ack_backlog); newsk = inet_csk_accept(sk, flags, err, kern); - nip_dbg("%s: accept %s, sk_ack_backlog_last=%u, sk_max_ack_backlog=%u", - __func__, (newsk ? "ok" : "fail"), sk_ack_backlog_last, sk_max_ack_backlog); + nip_dbg("accept %s, sk_ack_backlog_last=%u, sk_max_ack_backlog=%u", + (newsk ? "ok" : "fail"), sk_ack_backlog_last, sk_max_ack_backlog); return newsk; } @@ -1745,28 +1748,3 @@ void tcp_nip_exit(void) ninet_unregister_protosw(&tcp_nip_protosw); ninet_del_protocol(&tcp_nip_protocol, IPPROTO_TCP); } - -#define LOG_PRINT_MAX_LEN 256 -void nip_dbg(const char *fmt, ...) -{ - char str[LOG_PRINT_MAX_LEN]; - va_list args; - int len = 0; - - if (!get_nip_debug()) - return; - - memset(str, 0, sizeof(str)); - (void)memset(&args, 0, sizeof(va_list)); - va_start(args, fmt); - len += vsnprintf(str + len, LOG_PRINT_MAX_LEN - len, fmt, args); - va_end(args); - if (len < 0 || len > LOG_PRINT_MAX_LEN) { - pr_crit("nip log len error"); - printk_once(KERN_ERR "please increase LOG_PRINT_MAX_LEN"); - return; - } - - pr_crit("%s", str); -} - diff --git a/src/linux/net/newip/tcp_nip_input.c b/src/linux/net/newip/tcp_nip_input.c index 1073f38..94b77c5 100644 --- a/src/linux/net/newip/tcp_nip_input.c +++ b/src/linux/net/newip/tcp_nip_input.c @@ -13,7 +13,7 @@ * Based on net/ipv4/tcp_output.c * Based on net/ipv4/tcp_minisocks.c */ -#define pr_fmt(fmt) "NIP-TCP: " fmt +#define pr_fmt(fmt) KBUILD_MODNAME ": [%s:%d] " fmt, __func__, __LINE__ #include #include @@ -33,7 +33,7 @@ #define FLAG_DATA_SACKED 0x20 /* New SACK. */ #define FLAG_ECE 0x40 /* ECE in this ACK */ #define FLAG_LOST_RETRANS 0x80 /* This ACK marks some retransmission lost */ -#define FLAG_SLOWPATH 0x100 /* Do not skip RFC checks for window update.*/ +#define FLAG_SLOWPATH 0x100 /* Do not skip RFC checks for window update */ #define FLAG_ORIG_SACK_ACKED 0x200 /* Never retransmitted data are (s)acked */ #define FLAG_SND_UNA_ADVANCED 0x400 /* Snd_una was changed (!= FLAG_DATA_ACKED) */ #define FLAG_DSACKING_ACK 0x800 /* SACK blocks contained D-SACK info */ @@ -97,7 +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. */ - nip_dbg("%s: Impossible, sk->sk_state=%d", __func__, sk->sk_state); + nip_dbg("Impossible, sk->sk_state=%d", sk->sk_state); break; } @@ -220,30 +220,30 @@ static void tcp_nip_data_queue(struct sock *sk, struct sk_buff *skb) tp->snd_up = tp->snd_up > PKT_DISCARD_MAX ? 0 : tp->snd_up; if (TCP_SKB_CB(skb)->seq == TCP_SKB_CB(skb)->end_seq) { - nip_dbg("%s: no data, only handle ack", __func__); + nip_dbg("no data, only handle ack"); __kfree_skb(skb); return; } if (TCP_SKB_CB(skb)->seq == tp->rcv_nxt) { if (cur_win == 0) { - nip_dbg("%s: rcv window is 0", __func__); + nip_dbg("rcv window is 0"); goto out_of_window; } } /* Out of window. F.e. zero window probe. */ if (!before(TCP_SKB_CB(skb)->seq, seq_max)) { - nip_dbg("%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, + nip_dbg("out of rcv win, seq=[%u-%u], rcv_nxt=%u, seq_max=%u", + 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. */ - nip_dbg("%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); + nip_dbg("rcv retransmit pkt, seq=[%u-%u], rcv_nxt=%u", + TCP_SKB_CB(skb)->seq, TCP_SKB_CB(skb)->end_seq, tp->rcv_nxt); out_of_window: inet_csk_schedule_ack(sk); tcp_drop(sk, skb); @@ -253,8 +253,8 @@ out_of_window: __skb_pull(skb, tcp_hdr(skb)->doff * TCP_NUM_4); if (cur_win == 0 || after(TCP_SKB_CB(skb)->end_seq, seq_max)) { - nip_dbg("%s: win lack, drop pkt, seq=[%u-%u], seq_max=%u, rmem_alloc/rbuf=[%u:%u]", - __func__, TCP_SKB_CB(skb)->seq, TCP_SKB_CB(skb)->end_seq, + nip_dbg("win lack, drop pkt, seq=[%u-%u], seq_max=%u, rmem_alloc/rbuf=[%u:%u]", + 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); @@ -272,8 +272,8 @@ out_of_window: if (TCP_SKB_CB(skb)->seq != tp->rcv_nxt) tcp_nip_overlap_handle(tp, skb); - nip_dbg("%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, + nip_dbg("packet received. seq=[%u-%u], rcv_nxt=%u, skb->len=%u", + TCP_SKB_CB(skb)->seq, TCP_SKB_CB(skb)->end_seq, tp->rcv_nxt, skb->len); __skb_queue_tail(&sk->sk_receive_queue, skb); @@ -289,8 +289,8 @@ out_of_window: return; } - nip_dbg("%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, + nip_dbg("ofo packet received. seq=[%u-%u], rcv_nxt=%u, skb->len=%u", + TCP_SKB_CB(skb)->seq, TCP_SKB_CB(skb)->end_seq, tp->rcv_nxt, skb->len); tcp_nip_data_queue_ofo(sk, skb); @@ -341,7 +341,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))) { - nip_dbg("%s: ok", __func__); + nip_dbg("ok"); tcp_nip_send_ack(sk); return; } @@ -409,9 +409,15 @@ static void tcp_nip_snd_una_update(struct tcp_sock *tp, u32 ack) void tcp_nip_rearm_rto(struct sock *sk) { struct tcp_sock *tp = tcp_sk(sk); + struct inet_connection_sock *icsk = inet_csk(sk); if (!tp->packets_out) { + int icsk_backoff = icsk->icsk_backoff; + inet_csk_clear_xmit_timer(sk, ICSK_TIME_RETRANS); + icsk->icsk_backoff = 0; /* V4 no modified this line */ + nip_dbg("stop tcp retrans timer, icsk_backoff %u to %u", + icsk_backoff, icsk->icsk_backoff); } else { u32 rto = inet_csk(sk)->icsk_rto; @@ -433,7 +439,7 @@ static int tcp_nip_clean_rtx_queue(struct sock *sk, ktime_t *skb_snd_tstamp) if (after(scb->end_seq, tp->snd_una)) { if (tcp_skb_pcount(skb) == 1 || !after(tp->snd_una, scb->seq)) break; - nip_dbg("%s: ack error", __func__); + nip_dbg("ack error"); } else { prefetchw(skb->next); acked_pcount = tcp_skb_pcount(skb); @@ -455,7 +461,7 @@ static int tcp_nip_clean_rtx_queue(struct sock *sk, ktime_t *skb_snd_tstamp) sk_wmem_free_skb(sk, skb); } - icsk->icsk_rto = (unsigned int)(HZ / get_nip_rto()); + icsk->icsk_rto = (unsigned int)(HZ / get_nip_rto()); /* V4 no modified this line */ if (flag & FLAG_ACKED) tcp_nip_rearm_rto(sk); return 0; @@ -506,7 +512,7 @@ void tcp_nip_parse_mss(struct tcp_options_received *opt_rx, if (opsize == TCPOLEN_MSS && th->syn && !estab) { u16 in_mss = get_unaligned_be16(ptr); - nip_dbg("%s: in_mss %d", __func__, in_mss); + nip_dbg("in_mss %d", in_mss); if (in_mss) { if (opt_rx->user_mss && @@ -803,8 +809,8 @@ int _tcp_nip_conn_request(struct request_sock_ops *rsk_ops, */ if (sk_acceptq_is_full(sk)) { NET_INC_STATS(sock_net(sk), LINUX_MIB_LISTENOVERFLOWS); - nip_dbg("%s sk_acceptq_is_full, sk_ack_backlog=%u, sk_max_ack_backlog=%u", - __func__, READ_ONCE(sk->sk_ack_backlog), + nip_dbg("sk_acceptq_is_full, sk_ack_backlog=%u, sk_max_ack_backlog=%u", + READ_ONCE(sk->sk_ack_backlog), READ_ONCE(sk->sk_max_ack_backlog)); goto drop; } @@ -904,7 +910,7 @@ static void tcp_nip_ack_update_window(struct sock *sk, const struct sk_buff *skb tcp_update_wl(tp, ack_seq); if (tp->snd_wnd != nwin) { - nip_dbg("%s snd_wnd change [%u to %u]", __func__, tp->snd_wnd, nwin); + nip_dbg("snd_wnd change [%u to %u]", tp->snd_wnd, nwin); tp->snd_wnd = nwin; tp->pred_flags = 0; } @@ -921,7 +927,8 @@ 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; - nip_dbg("%s stop probe0 timer", __func__); + icsk->icsk_probes_tstamp = 0; + nip_dbg("stop probe0 timer"); 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! @@ -931,8 +938,8 @@ static void tcp_nip_ack_probe(struct sock *sk) unsigned long base_when = tcp_probe0_base(sk); u8 icsk_backoff = inet_csk(sk)->icsk_backoff; - nip_dbg("%s start probe0 timer, when=%u, RTO MAX=%u, base_when=%u, backoff=%u", - __func__, when, TCP_RTO_MAX, base_when, icsk_backoff); + nip_dbg("start probe0 timer, when=%lu, RTO MAX=%u, base_when=%lu, backoff=%u", + when, TCP_RTO_MAX, base_when, icsk_backoff); inet_csk_reset_xmit_timer(sk, ICSK_TIME_PROBE0, when, TCP_RTO_MAX); } } @@ -951,8 +958,8 @@ static void tcp_nip_ack_retrans(struct sock *sk, u32 ack, int ack_type, u32 retr skb_queue_walk_safe(&sk->sk_write_queue, skb, tmp) { if (skb == tcp_nip_send_head(sk)) { - ssthresh_dbg("%s %s ack retrans(%u) end, ack=%u, seq=%u~%u, pkt_out=%u", - __func__, ack_str[index], ntp->ack_retrans_num, ack, + ssthresh_dbg("%s ack retrans(%u) end, ack=%u, seq=%u~%u, pkt_out=%u", + ack_str[index], ntp->ack_retrans_num, ack, tp->selective_acks[0].start_seq, tp->selective_acks[0].end_seq, tp->packets_out); tp->selective_acks[0].start_seq = 0; @@ -963,8 +970,8 @@ static void tcp_nip_ack_retrans(struct sock *sk, u32 ack, int ack_type, u32 retr } if (TCP_SKB_CB(skb)->seq > tp->selective_acks[0].end_seq) { - ssthresh_dbg("%s %s ack retrans(%u) finish, ack=%u, seq=%u~%u, pkt_out=%u", - __func__, ack_str[index], ntp->ack_retrans_num, ack, + ssthresh_dbg("%s ack retrans(%u) finish, ack=%u, seq=%u~%u, pkt_out=%u", + ack_str[index], ntp->ack_retrans_num, ack, tp->selective_acks[0].start_seq, tp->selective_acks[0].end_seq, tp->packets_out); @@ -984,8 +991,8 @@ static void tcp_nip_ack_retrans(struct sock *sk, u32 ack, int ack_type, u32 retr ntp->ack_retrans_num++; ntp->ack_retrans_seq = TCP_SKB_CB(skb)->end_seq; } else { - retrans_dbg("%s %s ack retrans(%u) no end, ack=%u, seq=%u~%u, pkt_out=%u", - __func__, ack_str[index], ntp->ack_retrans_num, ack, + retrans_dbg("%s ack retrans(%u) no end, ack=%u, seq=%u~%u, pkt_out=%u", + ack_str[index], ntp->ack_retrans_num, ack, tp->selective_acks[0].start_seq, tp->selective_acks[0].end_seq, tp->packets_out); break; @@ -1014,8 +1021,8 @@ static void tcp_nip_dup_ack_retrans(struct sock *sk, const struct sk_buff *skb, u32 last_nip_ssthresh = ntp->nip_ssthresh; if (tp->selective_acks[0].end_seq) - ssthresh_dbg("%s last retans(%u) not end, seq=%u~%u, pkt_out=%u", - __func__, ntp->ack_retrans_num, + ssthresh_dbg("last retans(%u) not end, seq=%u~%u, pkt_out=%u", + ntp->ack_retrans_num, tp->selective_acks[0].start_seq, tp->selective_acks[0].end_seq, tp->packets_out); @@ -1026,8 +1033,8 @@ static void tcp_nip_dup_ack_retrans(struct sock *sk, const struct sk_buff *skb, ntp->ack_retrans_num = 0; ntp->nip_ssthresh = get_ssthresh_low(); - ssthresh_dbg("%s new dup ack, win %u to %u, discard_num=%u, seq=%u~%u", - __func__, last_nip_ssthresh, ntp->nip_ssthresh, discard_num, + ssthresh_dbg("new dup ack, win %u to %u, discard_num=%u, seq=%u~%u", + last_nip_ssthresh, ntp->nip_ssthresh, discard_num, tp->selective_acks[0].start_seq, tp->selective_acks[0].end_seq); @@ -1043,8 +1050,8 @@ static void tcp_nip_nor_ack_retrans(struct sock *sk, u32 ack, u32 retrans_num) if (tp->selective_acks[0].end_seq != 0) { if (ack >= tp->selective_acks[0].end_seq) { - ssthresh_dbg("%s nor ack retrans(%u) resume, seq=%u~%u, pkt_out=%u, ack=%u", - __func__, ntp->ack_retrans_num, + ssthresh_dbg("nor ack retrans(%u) resume, seq=%u~%u, pkt_out=%u, ack=%u", + ntp->ack_retrans_num, tp->selective_acks[0].start_seq, tp->selective_acks[0].end_seq, tp->packets_out, ack); tp->selective_acks[0].start_seq = 0; @@ -1072,8 +1079,8 @@ static void tcp_nip_ack_calc_ssthresh(struct sock *sk, u32 ack, int icsk_rto_las u32 nip_ssthresh; if (ntp->nip_ssthresh_reset != ack_reset) { - ssthresh_dbg("%s ack reset win %u to %u, ack=%u", - __func__, ntp->nip_ssthresh, get_ssthresh_low(), ack); + ssthresh_dbg("ack reset win %u to %u, ack=%u", + ntp->nip_ssthresh, get_ssthresh_low(), ack); ntp->nip_ssthresh_reset = ack_reset; ntp->nip_ssthresh = get_ssthresh_low(); } else { @@ -1081,21 +1088,21 @@ static void tcp_nip_ack_calc_ssthresh(struct sock *sk, u32 ack, int icsk_rto_las u32 rtt_tstamp = tp->rcv_tstamp - skb_snd_tstamp; if (rtt_tstamp >= get_rtt_tstamp_rto_up()) { - ssthresh_dbg("%s rtt %u >= %u, win %u to %u, rto %u to %u, ack=%u", - __func__, rtt_tstamp, get_rtt_tstamp_rto_up(), + ssthresh_dbg("rtt %u >= %u, win %u to %u, rto %u to %u, ack=%u", + rtt_tstamp, get_rtt_tstamp_rto_up(), ntp->nip_ssthresh, get_ssthresh_low_min(), icsk_rto_last, icsk->icsk_rto, ack); ntp->nip_ssthresh = get_ssthresh_low_min(); } else if (rtt_tstamp >= get_rtt_tstamp_high()) { - ssthresh_dbg("%s rtt %u >= %u, win %u to %u, ack=%u", - __func__, rtt_tstamp, get_rtt_tstamp_high(), + ssthresh_dbg("rtt %u >= %u, win %u to %u, ack=%u", + rtt_tstamp, get_rtt_tstamp_high(), ntp->nip_ssthresh, get_ssthresh_low(), ack); ntp->nip_ssthresh = get_ssthresh_low(); } else if (rtt_tstamp >= get_rtt_tstamp_mid_high()) { - ssthresh_dbg("%s rtt %u >= %u, win %u to %u, ack=%u", - __func__, rtt_tstamp, get_rtt_tstamp_mid_high(), + ssthresh_dbg("rtt %u >= %u, win %u to %u, ack=%u", + rtt_tstamp, get_rtt_tstamp_mid_high(), ntp->nip_ssthresh, get_ssthresh_mid_low(), ack); ntp->nip_ssthresh = get_ssthresh_mid_low(); @@ -1112,8 +1119,8 @@ static void tcp_nip_ack_calc_ssthresh(struct sock *sk, u32 ack, int icsk_rto_las nip_ssthresh = (ntp->nip_ssthresh * get_ssthresh_high_step() + nip_ssthresh) / (get_ssthresh_high_step() + 1); - ssthresh_dbg("%s rtt %u >= %u, win %u to %u, ack=%u", - __func__, rtt_tstamp, get_rtt_tstamp_mid_low(), + ssthresh_dbg("rtt %u >= %u, win %u to %u, ack=%u", + rtt_tstamp, get_rtt_tstamp_mid_low(), ntp->nip_ssthresh, nip_ssthresh, ack); ntp->nip_ssthresh = nip_ssthresh; @@ -1122,8 +1129,8 @@ static void tcp_nip_ack_calc_ssthresh(struct sock *sk, u32 ack, int icsk_rto_las get_ssthresh_high()) / (get_ssthresh_high_step() + 1); - ssthresh_dbg("%s rtt %u < %u, win %u to %u, ack=%u", - __func__, rtt_tstamp, get_rtt_tstamp_mid_low(), + ssthresh_dbg("rtt %u < %u, win %u to %u, ack=%u", + rtt_tstamp, get_rtt_tstamp_mid_low(), ntp->nip_ssthresh, nip_ssthresh, ack); ntp->nip_ssthresh = nip_ssthresh; @@ -1155,7 +1162,7 @@ static int tcp_nip_ack(struct sock *sk, const struct sk_buff *skb) /* maybe zero window probe */ if (!prior_packets) { - nip_dbg("%s: no unack pkt, seq=[%u-%u], rcv_nxt=%u, ack=%u", __func__, + nip_dbg("no unack pkt, seq=[%u-%u], rcv_nxt=%u, ack=%u", 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); @@ -1196,7 +1203,7 @@ static inline bool tcp_nip_sequence(const struct tcp_sock *tp, u32 seq, u32 end_ /* When we get a reset we do this. */ void tcp_nip_reset(struct sock *sk) { - nip_dbg("%s: handle RST", __func__); + nip_dbg("handle rst"); /* We want the right error as BSD sees it (and indeed as we do). */ switch (sk->sk_state) { @@ -1232,7 +1239,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); - nip_dbg("%s send dup ack", __func__); + nip_dbg("send dup ack"); tcp_nip_send_ack(sk); } @@ -1260,8 +1267,8 @@ static bool tcp_nip_validate_incoming(struct sock *sk, struct sk_buff *skb, * 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)) { - nip_dbg("%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, + nip_dbg("receive unexpected pkt, drop it. seq=[%u-%u], rec_win=[%u-%u]", + 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); @@ -1539,7 +1546,7 @@ int tcp_nip_rcv_state_process(struct sock *sk, struct sk_buff *skb) } goto discard; case TCP_SYN_SENT: - nip_dbg("%s TCP_SYN_SENT", __func__); + nip_dbg("TCP_SYN_SENT"); tp->rx_opt.saw_tstamp = 0; tcp_mstamp_refresh(tp); queued = tcp_nip_rcv_synsent_state_process(sk, skb, th); @@ -1588,7 +1595,7 @@ int tcp_nip_rcv_state_process(struct sock *sk, struct sk_buff *skb) break; case TCP_FIN_WAIT1: { if (tp->snd_una != tp->write_seq) { - nip_dbg("%s: tp->snd_una != tp->write_seq", __func__); + nip_dbg("tp->snd_una != tp->write_seq"); break; } @@ -1598,12 +1605,11 @@ int tcp_nip_rcv_state_process(struct sock *sk, struct sk_buff *skb) if (TCP_SKB_CB(skb)->end_seq != TCP_SKB_CB(skb)->seq && after(TCP_SKB_CB(skb)->end_seq - th->fin, tp->rcv_nxt)) { tcp_nip_done(sk); - nip_dbg("%s: received payload packets, call tcp_nip_done", __func__); + nip_dbg("received payload packets, call tcp_nip_done"); return 1; } - nip_dbg("%s: TCP_FIN_WAIT1: recvd ack for fin.Wait for fin from other side", - __func__); + nip_dbg("TCP_FIN_WAIT1: recvd ack for fin.Wait for fin from other side"); inet_csk_reset_keepalive_timer(sk, TCP_NIP_CSK_KEEPALIVE_CYCLE * HZ); break; @@ -1611,7 +1617,7 @@ int tcp_nip_rcv_state_process(struct sock *sk, struct sk_buff *skb) case TCP_CLOSING: if (tp->snd_una == tp->write_seq) { - nip_dbg("%s: TCP_CLOSING: recvd ack for fin.Ready to destroy", __func__); + nip_dbg("TCP_CLOSING: recvd ack for fin.Ready to destroy"); inet_csk_reset_keepalive_timer(sk, TCP_TIMEWAIT_LEN); goto discard; } @@ -1619,7 +1625,7 @@ int tcp_nip_rcv_state_process(struct sock *sk, struct sk_buff *skb) case TCP_LAST_ACK: nip_dbg("tcp_nip_rcv_state_process_2: TCP_LAST_ACK"); if (tp->snd_una == tp->write_seq) { - nip_dbg("%s: LAST_ACK: recvd ack for fin.Directly destroy", __func__); + nip_dbg("LAST_ACK: recvd ack for fin.Directly destroy"); tcp_nip_done(sk); goto discard; } @@ -1628,14 +1634,14 @@ int tcp_nip_rcv_state_process(struct sock *sk, struct sk_buff *skb) switch (sk->sk_state) { case TCP_CLOSE_WAIT: - nip_dbg("%s: into TCP_CLOSE_WAIT, rst = %d, seq = %u, end_seq = %u, rcv_nxt = %u", - __func__, th->rst, TCP_SKB_CB(skb)->seq, + nip_dbg("into TCP_CLOSE_WAIT, rst = %d, seq = %u, end_seq = %u, rcv_nxt = %u", + th->rst, TCP_SKB_CB(skb)->seq, TCP_SKB_CB(skb)->seq, tp->rcv_nxt); fallthrough; case TCP_CLOSING: case TCP_LAST_ACK: if (!before(TCP_SKB_CB(skb)->seq, tp->rcv_nxt)) { - nip_dbg("%s: break in TCP_LAST_ACK", __func__); + nip_dbg("break in TCP_LAST_ACK"); break; } nip_dbg("tcp_nip_rcv_state_process_3: TCP_LAST_ACK_2"); @@ -1649,7 +1655,7 @@ int tcp_nip_rcv_state_process(struct sock *sk, struct sk_buff *skb) if (TCP_SKB_CB(skb)->end_seq != TCP_SKB_CB(skb)->seq && after(TCP_SKB_CB(skb)->end_seq - th->fin, tp->rcv_nxt)) { tcp_nip_reset(sk); - nip_dbg("%s: call tcp_nip_reset", __func__); + nip_dbg("call tcp_nip_reset"); return 1; } } @@ -1723,26 +1729,25 @@ struct sock *tcp_nip_check_req(struct sock *sk, struct sk_buff *skb, if ((flg & TCP_FLAG_ACK) && (TCP_SKB_CB(skb)->ack_seq != tcp_rsk(req)->snt_isn + 1)) { - nip_dbg("%s ack_seq is wrong", __func__); + nip_dbg("ack_seq is wrong"); return sk; } /* The above process guarantees that there is an ACK, if not, return directly */ if (!(flg & TCP_FLAG_ACK)) { - nip_dbg("%s No TCP_FLAG_ACK", __func__); + nip_dbg("No TCP_FLAG_ACK"); return NULL; } /* The ack is valid and the child control block is created. * Note that the state of the child control block is TCP_SYN_RECV */ - child = inet_csk(sk)->icsk_af_ops->syn_recv_sock(sk, skb, req, NULL, - req, &own_req); + child = inet_csk(sk)->icsk_af_ops->syn_recv_sock(sk, skb, req, NULL, req, &own_req); if (!child) { - nip_dbg("%s No listen_overflow", __func__); + nip_dbg("No listen_overflow"); goto listen_overflow; } - nip_dbg("%s creat child sock successfully", __func__); + nip_dbg("creat child sock successfully"); sock_rps_save_rxhash(child, skb); /* Calculate the time spent synack-ack in three handshakes */ diff --git a/src/linux/net/newip/tcp_nip_output.c b/src/linux/net/newip/tcp_nip_output.c index dbc515f..d0a205d 100644 --- a/src/linux/net/newip/tcp_nip_output.c +++ b/src/linux/net/newip/tcp_nip_output.c @@ -12,7 +12,7 @@ * Based on net/ipv4/tcp_output.c * Based on net/ipv4/tcp_minisocks.c */ -#define pr_fmt(fmt) "NIP-TCP: " fmt +#define pr_fmt(fmt) KBUILD_MODNAME ": [%s:%d] " fmt, __func__, __LINE__ #include #include @@ -105,6 +105,21 @@ static void tcp_nip_event_new_data_sent(struct sock *sk, struct sk_buff *skb) tcp_nip_rearm_rto(sk); } +/* check probe0 timer */ +static void tcp_nip_check_probe_timer(struct sock *sk) +{ + unsigned long when; + + if (!tcp_sk(sk)->packets_out && !inet_csk(sk)->icsk_pending) { + when = tcp_probe0_base(sk); + nip_dbg("start probe0 timer, when=%lu, RTO MAX=%u", 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) { + nip_dbg("can`t start probe0 timer, packets_out=%u, icsk_pending=%u", + tcp_sk(sk)->packets_out, inet_csk(sk)->icsk_pending); + } +} + void __tcp_nip_push_pending_frames(struct sock *sk, unsigned int cur_mss, int nonagle) { @@ -138,8 +153,8 @@ u32 __nip_tcp_select_window(struct sock *sk) free_space = round_down(free_space, 1 << tp->rx_opt.rcv_wscale); if (free_space < (allowed_space >> TCP_NUM_4) || free_space < mss) { - nip_dbg("%s rcv_wnd is 0, [allowed|full|free]space=[%u, %u, %u], mss=%u", - __func__, allowed_space, full_space, free_space, mss); + nip_dbg("rcv_wnd is 0, [allowed|full|free]space=[%u, %u, %u], mss=%u", + allowed_space, full_space, free_space, mss); return 0; } } @@ -165,9 +180,8 @@ u32 __nip_tcp_select_window(struct sock *sk) * 1< mss. */ window = ALIGN(window, (1 << tp->rx_opt.rcv_wscale)); - nip_dbg("%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); + nip_dbg("wscale(%u) win change [%u to %u], [allowed|free]space=[%u, %u], mss=%u", + tp->rx_opt.rcv_wscale, free_space, window, allowed_space, free_space, mss); return window; } @@ -200,8 +214,8 @@ static u16 nip_tcp_select_window(struct sock *sk) 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); - nip_dbg("%s when new_win(%u) < cur_win(%u), win change [%u to %u]", - __func__, new_win_bak, cur_win, new_win_bak, new_win); + nip_dbg("when new_win(%u) < cur_win(%u), win change [%u to %u]", + new_win_bak, cur_win, new_win_bak, new_win); } tp->rcv_wnd = new_win; tp->rcv_wup = tp->rcv_nxt; @@ -219,8 +233,7 @@ static u16 nip_tcp_select_window(struct sock *sk) */ new_win_bak = new_win; new_win >>= tp->rx_opt.rcv_wscale; - nip_dbg("%s wscale(%u) win change [%u to %u]", - __func__, tp->rx_opt.rcv_wscale, new_win_bak, new_win); + nip_dbg("wscale(%u) win change [%u to %u]", tp->rx_opt.rcv_wscale, new_win_bak, new_win); if (new_win == 0) { tp->pred_flags = 0; if (old_win) @@ -523,8 +536,8 @@ static int __tcp_nip_transmit_skb(struct sock *sk, struct sk_buff *skb, th->window = htons(min(tp->rcv_wnd, TCP_NIP_WINDOW_MAX)); ack = tcb->tcp_flags & TCPHDR_ACK; - nip_dbg("%s sport=%u, dport=%u, win=%u, rcvbuf=%d, sk_rmem_alloc=%d, ack=%u, skb->len=%u", - __func__, ntohs(inet->inet_sport), ntohs(inet->inet_dport), ntohs(th->window), + nip_dbg("sport=%u, dport=%u, win=%u, rcvbuf=%d, sk_rmem_alloc=%d, ack=%u, skb->len=%u", + 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 */ @@ -618,9 +631,9 @@ unsigned int tcp_nip_sync_mss(struct sock *sk, u32 pmtu) icsk->icsk_mtup.search_high = pmtu; mss_now = tcp_nip_mtu_to_mss(sk, pmtu); - nip_dbg("%s: sync mtu_to_mss %d", __func__, mss_now); + nip_dbg("sync mtu_to_mss %d", mss_now); mss_now = tcp_bound_to_half_wnd(tp, mss_now); - nip_dbg("%s: sync bound to half wnd %d", __func__, mss_now); + nip_dbg("sync bound to half wnd %d", mss_now); /* And store cached results */ icsk->icsk_pmtu_cookie = pmtu; @@ -628,7 +641,7 @@ unsigned int tcp_nip_sync_mss(struct sock *sk, u32 pmtu) mss_now = min(mss_now, tcp_nip_mtu_to_mss(sk, icsk->icsk_mtup.search_low)); tp->mss_cache = mss_now; - nip_dbg("%s: sync final mss %d", __func__, mss_now); + nip_dbg("sync final mss %d", mss_now); return mss_now; } @@ -852,9 +865,9 @@ int __nip_send_synack(struct request_sock *req, struct sk_buff *skb) head.total_len = skb->len; err = nip_send_skb(skb); if (err) - nip_dbg("%s: failed to send skb, skb->len=%u", __func__, head.total_len); + nip_dbg("failed to send skb, skb->len=%u", head.total_len); else - nip_dbg("%s: send skb ok, skb->len=%u", __func__, head.total_len); + nip_dbg("send skb ok, skb->len=%u", head.total_len); return err; } @@ -943,7 +956,7 @@ void tcp_nip_send_fin(struct sock *sk) struct tcp_sock *tp = tcp_sk(sk); u32 cur_mss; - nip_dbg("%s: send fin", __func__); + nip_dbg("send fin"); /* Set the fin position of the last packet to 1 */ if (tskb && tcp_nip_send_head(sk)) { coalesce: @@ -972,7 +985,7 @@ void tcp_nip_send_active_reset(struct sock *sk, gfp_t priority) { struct sk_buff *skb; - nip_dbg("%s: send RST", __func__); + nip_dbg("send rst"); /* NOTE: No TCP options attached and we never retransmit this. */ skb = alloc_skb(MAX_TCP_HEADER, priority); if (!skb) @@ -1048,8 +1061,8 @@ static bool tcp_nip_write_xmit(struct sock *sk, unsigned int mss_now, int nonagl if (tstamp >= get_ack_to_nxt_snd_tstamp()) { ntp->nip_ssthresh = get_ssthresh_low_min(); snd_num = ntp->nip_ssthresh / mss_now; - ssthresh_dbg("%s new snd tstamp %u >= %u, ssthresh %u to %u, snd_num=%u", - __func__, tstamp, get_ack_to_nxt_snd_tstamp(), + ssthresh_dbg("new snd tstamp %u >= %u, ssthresh %u to %u, snd_num=%u", + tstamp, get_ack_to_nxt_snd_tstamp(), last_nip_ssthresh, ntp->nip_ssthresh, snd_num); } } @@ -1059,8 +1072,7 @@ static bool tcp_nip_write_xmit(struct sock *sk, unsigned int mss_now, int nonagl tcp_nip_init_tso_segs(skb, mss_now); snd_wnd_ready = tcp_nip_snd_wnd_test(tp, skb, mss_now); - nip_dbg("%s %s, skb->len=%u", __func__, - (snd_wnd_ready ? str[1] : str[0]), skb->len); + nip_dbg("%s, skb->len=%u", (snd_wnd_ready ? str[1] : str[0]), skb->len); if (unlikely(!snd_wnd_ready)) break; @@ -1225,7 +1237,7 @@ static int tcp_nip_xmit_probe_skb(struct sock *sk, int urgent, int mib) NET_INC_STATS(sock_net(sk), mib); ret = tcp_nip_transmit_skb(sk, skb, 0, (__force gfp_t)0); - nip_dbg("%s: send %s probe packet, ret=%d", __func__, str[probe_type], ret); + nip_dbg("send %s probe packet, ret=%d", str[probe_type], ret); return ret; } @@ -1234,8 +1246,10 @@ int tcp_nip_write_wakeup(struct sock *sk, int mib) struct tcp_sock *tp = tcp_sk(sk); struct sk_buff *skb; - if (sk->sk_state == TCP_CLOSE) + if (sk->sk_state == TCP_CLOSE) { + nip_dbg("no probe0 when tcp close"); return -1; + } skb = tcp_nip_send_head(sk); /* If the serial number of the next packet is in the sending window */ @@ -1252,13 +1266,14 @@ 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) { - nip_dbg("%s tcp_fragment return err=%d", __func__, err); + nip_dbg("tcp_fragment return err=%d", err); return -1; } } err = tcp_nip_transmit_skb(sk, skb, 1, GFP_ATOMIC); if (!err) tcp_nip_event_new_data_sent(sk, skb); + nip_dbg("transmit skb %s", (!err ? "ok" : "fail")); return err; } else { return tcp_nip_xmit_probe_skb(sk, 0, mib); @@ -1271,8 +1286,7 @@ void tcp_nip_send_probe0(struct sock *sk) struct inet_connection_sock *icsk = inet_csk(sk); struct tcp_sock *tp = tcp_sk(sk); struct net *net = sock_net(sk); - unsigned long probe_max; - int when; + unsigned long when; /* An ACK packet with snd_UNa-1 and length 0 is sent as a zero-window detection packet */ int err = tcp_nip_write_wakeup(sk, LINUX_MIB_TCPWINPROBE); @@ -1281,38 +1295,29 @@ void tcp_nip_send_probe0(struct sock *sk) */ if (tp->packets_out || !tcp_nip_send_head(sk)) { /* Cancel probe timer, if it is not required. */ - nip_dbg("%s packets_out(%u) not 0 or send_head is NULL, cancel probe0 timer", - __func__, tp->packets_out); + nip_dbg("packets_out(%u) not 0 or send_head is NULL, cancel probe0 timer", + tp->packets_out); icsk->icsk_probes_out = 0; icsk->icsk_backoff = 0; return; } /* Err: 0 succeeded, -1 failed */ + icsk->icsk_probes_out++; /* Number of probes +1 */ 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; - nip_dbg("%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); + when = tcp_probe0_when(sk, TCP_RTO_MAX); + nip_dbg("probe0 %s, probes_out=%u, probe0_base=%lu, icsk_backoff=%u, when=%lu", + (!err ? "send ok" : "send fail"), icsk->icsk_probes_out, + tcp_probe0_base(sk), icsk->icsk_backoff, when); } 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; - nip_dbg("%s probe0 not sent due to local congestion, make timer time out faster", - __func__); + when = TCP_RESOURCE_PROBE_INTERVAL; + nip_dbg("probe0 not sent due to local congestion, make timer out faster"); } - when = tcp_probe0_when(sk, probe_max); - nip_dbg("%s restart probe0 timer, when=%u, probe_max=%u", __func__, when, probe_max); + nip_dbg("restart probe0 timer, when=%lu, icsk_backoff=%u, probe_max=%u", + when, icsk->icsk_backoff, TCP_RTO_MAX); inet_csk_reset_xmit_timer(sk, ICSK_TIME_PROBE0, when, TCP_RTO_MAX); } diff --git a/src/linux/net/newip/tcp_nip_parameter.c b/src/linux/net/newip/tcp_nip_parameter.c index 7a12755..2a2955e 100644 --- a/src/linux/net/newip/tcp_nip_parameter.c +++ b/src/linux/net/newip/tcp_nip_parameter.c @@ -9,6 +9,8 @@ * * Definitions for the NewIP parameter module. */ +#define pr_fmt(fmt) KBUILD_MODNAME ": [%s:%d] " fmt, __func__, __LINE__ + #include #include #include diff --git a/src/linux/net/newip/tcp_nip_parameter.h b/src/linux/net/newip/tcp_nip_parameter.h index b8409cb..a9cea6c 100644 --- a/src/linux/net/newip/tcp_nip_parameter.h +++ b/src/linux/net/newip/tcp_nip_parameter.h @@ -48,6 +48,12 @@ bool get_ack_retrans_debug(void); /*********************************************************************************************/ /* nip debug parameters */ /*********************************************************************************************/ +#define nip_dbg(fmt, ...) \ +do { \ + if (get_nip_debug()) \ + pr_crit(fmt, ##__VA_ARGS__); \ +} while (0) + /* Debugging of threshold change */ #define ssthresh_dbg(fmt, ...) \ do { \ diff --git a/src/linux/net/newip/tcp_nip_timer.c b/src/linux/net/newip/tcp_nip_timer.c index 5073550..ad91350 100644 --- a/src/linux/net/newip/tcp_nip_timer.c +++ b/src/linux/net/newip/tcp_nip_timer.c @@ -11,7 +11,7 @@ * * Based on net/ipv4/tcp_timer.c */ -#define pr_fmt(fmt) "NIP-TCP: " fmt +#define pr_fmt(fmt) KBUILD_MODNAME ": [%s:%d] " fmt, __func__, __LINE__ #include #include @@ -100,7 +100,7 @@ static bool retransmits_nip_timed_out(struct sock *sk, * Currently, it determines whether the timeout period is based on * the retransmission times */ - nip_dbg("%s: icsk->retransmits=%u, boundary=%u", __func__, + nip_dbg("icsk->retransmits=%u, boundary=%u", inet_csk(sk)->icsk_retransmits, boundary); return inet_csk(sk)->icsk_retransmits > boundary; } @@ -127,7 +127,7 @@ static int tcp_nip_write_timeout(struct sock *sk) if (retransmits_nip_timed_out(sk, retry_until, syn_set ? 0 : icsk->icsk_user_timeout, syn_set)) { - nip_dbg("%s: tcp retransmit time out", __func__); + nip_dbg("tcp retransmit time out"); tcp_nip_write_err(sk); return 1; } @@ -141,6 +141,7 @@ void tcp_nip_retransmit_timer(struct sock *sk) struct inet_connection_sock *icsk = inet_csk(sk); struct sk_buff *skb = tcp_write_queue_head(sk); struct tcp_skb_cb *scb = TCP_SKB_CB(skb); + struct net *net = sock_net(sk); u32 icsk_rto_last; if (!tp->packets_out) @@ -161,20 +162,41 @@ void tcp_nip_retransmit_timer(struct sock *sk) min(icsk->icsk_rto, TCP_RESOURCE_PROBE_INTERVAL), TCP_RTO_MAX); - ssthresh_dbg("%s seq %u retransmit fail, win=%u, rto=%u, pkt_out=%u", - __func__, scb->seq, ntp->nip_ssthresh, - icsk->icsk_rto, tp->packets_out); + nip_dbg("seq %u retransmit fail, win=%u, rto=%u, pkt_out=%u, icsk_backoff=%u", + scb->seq, ntp->nip_ssthresh, + icsk->icsk_rto, tp->packets_out, icsk->icsk_backoff); return; } - icsk->icsk_backoff++; + + if (icsk->icsk_backoff < net->ipv4.sysctl_tcp_retries2) + icsk->icsk_backoff++; icsk->icsk_retransmits++; icsk_rto_last = icsk->icsk_rto; - icsk->icsk_rto = min(icsk->icsk_rto << 1, TCP_RTO_MAX); + /* If stream is thin, use linear timeouts. Since 'icsk_backoff' is + * used to reset timer, set to 0. Recalculate 'icsk_rto' as this + * might be increased if the stream oscillates between thin and thick, + * thus the old value might already be too high compared to the value + * set by 'tcp_set_rto' in tcp_input.c which resets the rto without + * backoff. Limit to TCP_THIN_LINEAR_RETRIES before initiating + * exponential backoff behaviour to avoid continue hammering + * linear-timeout retransmissions into a black hole + */ + if (sk->sk_state == TCP_ESTABLISHED && + (tp->thin_lto || net->ipv4.sysctl_tcp_thin_linear_timeouts) && + tcp_stream_is_thin(tp) && + icsk->icsk_retransmits <= TCP_THIN_LINEAR_RETRIES) { + icsk->icsk_backoff = 0; + icsk->icsk_rto = min(__tcp_set_rto(tp), TCP_RTO_MAX); + } else { + /* Use normal (exponential) backoff */ + icsk->icsk_rto = min(icsk->icsk_rto << 1, TCP_RTO_MAX); + } - ssthresh_dbg("%s seq %u, reset win %u to %u, rto %u to %u, pkt_out=%u", - __func__, scb->seq, ntp->nip_ssthresh, get_ssthresh_low(), - icsk_rto_last, icsk->icsk_rto, tp->packets_out); + nip_dbg("seq %u, win[%u-%u] rto[%u-%u] pkt_out=%u, icsk_backoff=%u, retransmits=%u", + scb->seq, ntp->nip_ssthresh, get_ssthresh_low(), + icsk_rto_last, icsk->icsk_rto, tp->packets_out, icsk->icsk_backoff, + icsk->icsk_retransmits); ntp->nip_ssthresh = get_ssthresh_low(); @@ -191,9 +213,10 @@ void tcp_nip_probe_timer(struct sock *sk) if (tp->packets_out || !tcp_nip_send_head(sk)) { icsk->icsk_probes_out = 0; - icsk->icsk_backoff = 0; // V4 no modified this line - nip_dbg("%s packets_out(%u) not 0 or send_head is NULL, cancel probe0 timer", - __func__, tp->packets_out); + icsk->icsk_probes_tstamp = 0; + icsk->icsk_backoff = 0; /* V4 no modified this line */ + nip_dbg("packets_out(%u) not 0 or send_head is NULL, cancel probe0 timer", + tp->packets_out); return; } @@ -204,11 +227,11 @@ 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); - nip_dbg("%s sock dead, icsk_backoff=%u, max_probes=%u, alive=%u", - __func__, icsk->icsk_backoff, max_probes, alive); + nip_dbg("sock dead, icsk_backoff=%u, max_probes=%u, alive=%u", + icsk->icsk_backoff, max_probes, alive); if (!alive && icsk->icsk_backoff >= max_probes) { - nip_dbg("%s will close session, icsk_backoff=%u, max_probes=%u", - __func__, icsk->icsk_backoff, max_probes); + nip_dbg("will close session, icsk_backoff=%u, max_probes=%u", + icsk->icsk_backoff, max_probes); goto abort; } } @@ -216,14 +239,14 @@ 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; - nip_dbg("%s close session, icsk_probes_out=%u, icsk_backoff=%u, max_probes=%u", - __func__, icsk_probes_out, icsk_backoff, max_probes); + nip_dbg("close session, probes_out=%u, icsk_backoff=%u, max_probes=%u", + icsk_probes_out, icsk_backoff, max_probes); tcp_nip_write_err(sk); } else { icsk_backoff = icsk->icsk_backoff; icsk_probes_out = icsk->icsk_probes_out; - nip_dbg("%s will send probe0, icsk_probes_out=%u, icsk_backoff=%u, max_probes=%u", - __func__, icsk_probes_out, icsk_backoff, max_probes); + nip_dbg("will send probe0, probes_out=%u, icsk_backoff=%u, max_probes=%u", + icsk_probes_out, icsk_backoff, max_probes); /* Only send another probe if we didn't close things up. */ tcp_nip_send_probe0(sk); } @@ -294,8 +317,8 @@ static bool tcp_nip_keepalive_is_timeout(struct sock *sk, u32 elapsed) ntp->nip_keepalive_out > 0) || (icsk->icsk_user_timeout == 0 && ntp->nip_keepalive_out >= keepalive_probes(tp))) { - nip_dbg("%s normal keepalive timeout, keepalive_out=%u", - __func__, ntp->nip_keepalive_out); + nip_dbg("normal keepalive timeout, keepalive_out=%u", + ntp->nip_keepalive_out); tcp_nip_write_err(sk); is_timeout = true; } @@ -320,7 +343,7 @@ static void tcp_nip_keepalive_timer(struct timer_list *t) } if (sk->sk_state == TCP_LISTEN) { - nip_dbg("%s: keepalive on a LISTEN", __func__); + nip_dbg("keepalive on a LISTEN"); goto out; } tcp_mstamp_refresh(tp); @@ -330,7 +353,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)) { - nip_dbg("%s: finish wait, close sock, sk_state=%u", __func__, sk->sk_state); + nip_dbg("finish wait, close sock, sk_state=%u", sk->sk_state); goto death; } diff --git a/src/linux/net/newip/udp.c b/src/linux/net/newip/udp.c index 680c05d..276019b 100644 --- a/src/linux/net/newip/udp.c +++ b/src/linux/net/newip/udp.c @@ -12,7 +12,7 @@ * Based on net/ipv4/udp.c * Based on net/ipv6/udp.c */ -#define pr_fmt(fmt) "NIP-UDP: " fmt +#define pr_fmt(fmt) KBUILD_MODNAME ": [%s:%d] " fmt, __func__, __LINE__ #include #include @@ -38,6 +38,7 @@ #include #include "nip_hdr.h" #include "nip_checksum.h" +#include "tcp_nip_parameter.h" static u32 nip_udp_portaddr_hash(const struct net *net, const struct nip_addr *niaddr, @@ -220,7 +221,7 @@ int nip_udp_recvmsg(struct sock *sk, struct msghdr *msg, size_t len, /* copy data */ datalen = copy_to_iter(skb->data, copied, &msg->msg_iter); if (datalen < 0) { - nip_dbg("%s: copy to iter in failure, len=%d", __func__, datalen); + nip_dbg("copy to iter in failure, len=%d", datalen); err = -EFAULT; return err; } @@ -292,7 +293,7 @@ int nip_udp_input(struct sk_buff *skb) struct udphdr *udphead = udp_hdr(skb); if (!nip_get_udp_input_checksum(skb)) { - nip_dbg("%s: checksum failed, drop the packet", __func__); + nip_dbg("checksum failed, drop the packet"); kfree_skb(skb); rc = -1; goto end; @@ -301,9 +302,8 @@ int nip_udp_input(struct sk_buff *skb) sk = __nip_udp_lib_lookup_skb(skb, udphead->source, udphead->dest, &udp_table); if (!sk) { - nip_dbg("%s: dport not match, drop the packet. sport=%u, dport=%u, data_len=%u", - __func__, ntohs(udphead->source), - ntohs(udphead->dest), ntohs(udphead->len)); + nip_dbg("dport not match, drop the packet. sport=%u, dport=%u, data_len=%u", + ntohs(udphead->source), ntohs(udphead->dest), ntohs(udphead->len)); kfree_skb(skb); rc = -1; goto end; @@ -335,11 +335,11 @@ int nip_udp_output(struct sock *sk, struct msghdr *msg, size_t len) return -EDESTADDRREQ; if (sin->sin_family != AF_NINET) { - nip_dbg("%s: sin_family false", __func__); + nip_dbg("sin_family false"); return -EAFNOSUPPORT; } if (nip_addr_invalid(&sin->sin_addr)) { - nip_dbg("%s: sin_addr false", __func__); + nip_dbg("sin_addr false"); return -EFAULT; } -- Gitee