From edd5b1f9ab1093ac5bd56191117004a2fcb33197 Mon Sep 17 00:00:00 2001 From: yangyanjun Date: Wed, 9 Nov 2022 16:35:12 +0800 Subject: [PATCH] =?UTF-8?q?1=E3=80=81NewIP=20Kconfig=E8=B0=83=E7=94=A8sh?= =?UTF-8?q?=E8=84=9A=E6=9C=AC=E5=88=A4=E6=96=ADNewIP=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=E7=9B=AE=E5=BD=95=E6=98=AF=E5=90=A6=E5=AD=98=E5=9C=A8=EF=BC=8C?= =?UTF-8?q?=E8=87=AA=E5=8A=A8=E4=BD=BF=E8=83=BDNewIP=E3=80=82=20=E7=9B=AE?= =?UTF-8?q?=E5=89=8D=E5=86=85=E6=A0=B8=E4=BD=BF=E7=94=A8=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=E4=BB=93=E4=BB=A3=E7=A0=81=E7=94=9F=E6=88=90=E6=9F=90=E4=B8=AA?= =?UTF-8?q?=E6=AC=BE=E5=9E=8B=E6=9C=80=E7=BB=88.config=E6=96=87=E4=BB=B6?= =?UTF-8?q?=EF=BC=8C=E5=9B=A0=E6=AD=A4NewIP=20Kconfig=E5=85=88=E4=BD=BF?= =?UTF-8?q?=E7=94=A8=E4=BB=A3=E7=A0=81=E4=BB=93=E7=9B=B8=E5=AF=B9=E8=B7=AF?= =?UTF-8?q?=E5=BE=84=EF=BC=8C=E7=AD=89=E5=86=85=E6=A0=B8=E6=95=B4=E6=94=B9?= =?UTF-8?q?=E5=90=8E=E6=A0=B9=E6=8D=AEout=E7=9B=AE=E5=BD=95=E7=94=9F?= =?UTF-8?q?=E6=88=90=E6=9F=90=E4=B8=AA=E6=AC=BE=E5=9E=8B=E6=9C=80=E7=BB=88?= =?UTF-8?q?.config=E6=96=87=E4=BB=B6=E5=90=8E=EF=BC=8C=E5=86=8D=E4=BF=AE?= =?UTF-8?q?=E6=94=B9=E6=88=90out=E7=9B=AE=E5=BD=95=E7=9B=B8=E5=AF=B9?= =?UTF-8?q?=E8=B7=AF=E5=BE=84=E3=80=82=202=E3=80=81=E5=86=85=E6=A0=B8?= =?UTF-8?q?=E7=BC=96=E8=AF=91=E5=91=8A=E8=AD=A6=E4=BF=AE=E5=A4=8D=203?= =?UTF-8?q?=E3=80=81tcp=5Fnip=5Frcv=E5=87=BD=E6=95=B0=E4=B8=A2=E5=8C=85?= =?UTF-8?q?=E6=B5=81=E7=A8=8B=E5=A2=9E=E5=8A=A0debug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: yangyanjun --- src/linux/net/newip/nip_input.c | 2 +- src/linux/net/newip/nip_output.c | 3 +- src/linux/net/newip/tcp_nip.c | 49 ++++++++++++++----------- src/linux/net/newip/tcp_nip_input.c | 4 +- src/linux/net/newip/tcp_nip_output.c | 21 +++++------ src/linux/net/newip/tcp_nip_parameter.c | 6 +++ src/linux/net/newip/tcp_nip_parameter.h | 7 +++- src/linux/net/newip/tcp_nip_timer.c | 10 ++--- 8 files changed, 58 insertions(+), 44 deletions(-) diff --git a/src/linux/net/newip/nip_input.c b/src/linux/net/newip/nip_input.c index 5ea9443..64a5e90 100644 --- a/src/linux/net/newip/nip_input.c +++ b/src/linux/net/newip/nip_input.c @@ -44,7 +44,7 @@ static int _nip_update_recv_skb_len(struct sk_buff *skb, static int nip_rcv_finish(struct sk_buff *skb) { struct net *net = dev_net(skb->dev); - void (*edemux)(struct sk_buff *skb); + void (*edemux)(struct sk_buff *skb) = NULL; /* set /proc/sys/net/ipv4/ip_early_demux to change sysctl_ip_early_demux, * which is used by ipv4, ipv6 and newip diff --git a/src/linux/net/newip/nip_output.c b/src/linux/net/newip/nip_output.c index 6c5642a..3ede2a0 100644 --- a/src/linux/net/newip/nip_output.c +++ b/src/linux/net/newip/nip_output.c @@ -312,8 +312,7 @@ static int nip_dst_lookup_tail(struct net *net, const struct sock *sk, rt = (struct nip_rt_info *)*dst; if (*dst == &net->newip.nip_broadcast_entry->dst) { - if (!&fln->saddr) - fln->saddr = fln->daddr; + fln->saddr = fln->daddr; err = 0; } else { err = nip_route_get_saddr(net, rt, &fln->daddr, &fln->saddr); diff --git a/src/linux/net/newip/tcp_nip.c b/src/linux/net/newip/tcp_nip.c index 7c6a026..ce19f60 100644 --- a/src/linux/net/newip/tcp_nip.c +++ b/src/linux/net/newip/tcp_nip.c @@ -1108,7 +1108,7 @@ int tcp_nip_recvmsg(struct sock *sk, struct msghdr *msg, size_t len, int nonbloc int copied = 0; u32 *seq; unsigned long used; - int err; + int err = 0; int target; long timeo; size_t len_tmp = len; @@ -1381,25 +1381,35 @@ static int tcp_nip_rcv(struct sk_buff *skb) int ret; int dif = skb->skb_iif; - if (skb->pkt_type != PACKET_HOST) + if (skb->pkt_type != PACKET_HOST) { + DEBUG("%s unknown pkt-type(%u), drop skb.", __func__, skb->pkt_type); goto discard_it; + } - if (!nip_get_tcp_input_checksum(skb)) + if (!nip_get_tcp_input_checksum(skb)) { + DEBUG("%s checksum fail, drop skb.", __func__); goto discard_it; + } th = (const struct tcphdr *)skb->data; - if (unlikely(th->doff < sizeof(struct tcphdr) / TCP_NUM_4)) - goto bad_packet; + if (unlikely(th->doff < sizeof(struct tcphdr) / TCP_NUM_4)) { + DEBUG("%s non-four byte alignment, drop skb.", __func__); + goto discard_it; + } sk = __ninet_lookup_skb(&tcp_hashinfo, skb, __tcp_hdrlen(th), - th->source, th->dest, dif, - &refcounted); - if (!sk) + th->source, th->dest, dif, &refcounted); + if (!sk) { + DEBUG("%s: can`t find related sock for skb, will disconnect.", __func__); goto no_tcp_socket; + } - if (sk->sk_state == TCP_TIME_WAIT) - goto do_time_wait; + if (sk->sk_state == TCP_TIME_WAIT) { + /* Handles the SK portion of the interrupt state */ + DEBUG("%s sk_state is TCP_TIME_WAIT, drop skb.", __func__); + goto discard_it; + } if (sk->sk_state == TCP_NEW_SYN_RECV) { struct request_sock *req = inet_reqsk(sk); struct sock *nsk; @@ -1420,11 +1430,12 @@ static int tcp_nip_rcv(struct sk_buff *skb) nsk = tcp_nip_check_req(sk, skb, req); } if (!nsk || nsk == sk) { - DEBUG("%s skb info error and create newsk failure!!!", __func__); + DEBUG("%s skb info error and create newsk failure, drop skb.", __func__); reqsk_put(req); goto discard_and_relse; } if (tcp_nip_child_process(sk, nsk, skb)) { + DEBUG("%s child process fail, drop skb.", __func__); goto discard_and_relse; } else { sock_put(sk); @@ -1434,8 +1445,10 @@ static int tcp_nip_rcv(struct sk_buff *skb) tcp_nip_fill_cb(skb, th); - if (tcp_filter(sk, skb)) + if (tcp_filter(sk, skb)) { + DEBUG("%s tcp filter fail, drop skb.", __func__); goto discard_and_relse; + } th = (const struct tcphdr *)skb->data; skb->dev = NULL; @@ -1453,8 +1466,10 @@ static int tcp_nip_rcv(struct sk_buff *skb) } else { DEBUG("%s: sock locked by user! put packet into backlog", __func__); - if (tcp_nip_add_backlog(sk, skb)) + if (tcp_nip_add_backlog(sk, skb)) { + DEBUG("%s add backlog fail, drop skb.", __func__); goto discard_and_relse; + } } bh_unlock_sock(sk); @@ -1465,14 +1480,9 @@ put_and_return: return ret ? -1 : 0; no_tcp_socket: - /* Checksum checked, send reset back */ tcp_nip_send_reset(NULL, skb); - DEBUG("%s: cannot find related tcp sock for skb", __func__); - goto discard_it; -bad_packet: goto discard_it; discard_it: - DEBUG("%s: drop tcp newip skb and release it", __func__); kfree_skb(skb); return 0; @@ -1481,9 +1491,6 @@ discard_and_relse: if (refcounted) sock_put(sk); goto discard_it; -/* Handles the SK portion of the interrupt state */ -do_time_wait: - goto discard_it; } static void tcp_nip_early_demux(struct sk_buff *skb) diff --git a/src/linux/net/newip/tcp_nip_input.c b/src/linux/net/newip/tcp_nip_input.c index a01dcf1..7b2a3c8 100644 --- a/src/linux/net/newip/tcp_nip_input.c +++ b/src/linux/net/newip/tcp_nip_input.c @@ -429,7 +429,7 @@ static int tcp_nip_clean_rtx_queue(struct sock *sk, ktime_t *skb_snd_tstamp) while ((skb = tcp_write_queue_head(sk)) && skb != tcp_nip_send_head(sk)) { struct tcp_skb_cb *scb = TCP_SKB_CB(skb); - u32 acked_pcount; + u32 acked_pcount = 0; if (after(scb->end_seq, tp->snd_una)) { if (tcp_skb_pcount(skb) == 1 || !after(tp->snd_una, scb->seq)) @@ -827,7 +827,7 @@ int _tcp_nip_conn_request(struct request_sock_ops *rsk_ops, /* The best way to do this is to prink the value of user_mss and see if it is 0 */ tmp_opt.user_mss = tp->rx_opt.user_mss; /* Parsing of TCP options in SKB */ - tcp_nip_parse_options(skb, &tmp_opt, 0, false); + tcp_nip_parse_options(skb, &tmp_opt, 0, NULL); /* Tstamp_ok indicates the TIMESTAMP seen on the received SYN packet */ tmp_opt.tstamp_ok = tmp_opt.saw_tstamp; diff --git a/src/linux/net/newip/tcp_nip_output.c b/src/linux/net/newip/tcp_nip_output.c index 15d64bb..80a69ba 100644 --- a/src/linux/net/newip/tcp_nip_output.c +++ b/src/linux/net/newip/tcp_nip_output.c @@ -166,19 +166,18 @@ u32 __nip_tcp_select_window(struct sock *sk) /* Don't do rounding if we are using window scaling, since the * scaled window will not line up with the MSS boundary anyway. + * tp->rx_opt.rcv_wscale is always true */ - if (tp->rx_opt.rcv_wscale) { - window = free_space; + window = free_space; - /* 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); - } + /* 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); return window; } diff --git a/src/linux/net/newip/tcp_nip_parameter.c b/src/linux/net/newip/tcp_nip_parameter.c index dcd42eb..1badd91 100644 --- a/src/linux/net/newip/tcp_nip_parameter.c +++ b/src/linux/net/newip/tcp_nip_parameter.c @@ -136,6 +136,12 @@ 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); +/*********************************************************************************************/ +/* probe parameters */ +/*********************************************************************************************/ +int g_nip_probe_max = 2000; +module_param_named(nip_probe_max, g_nip_probe_max, int, 0644); + /*********************************************************************************************/ /* window mode parameters */ /*********************************************************************************************/ diff --git a/src/linux/net/newip/tcp_nip_parameter.h b/src/linux/net/newip/tcp_nip_parameter.h index 9d830be..6630f6d 100644 --- a/src/linux/net/newip/tcp_nip_parameter.h +++ b/src/linux/net/newip/tcp_nip_parameter.h @@ -76,6 +76,11 @@ extern int g_nip_keepalive_intvl; extern bool g_nip_tcp_snd_win_enable; extern bool g_nip_tcp_rcv_win_enable; +/*********************************************************************************************/ +/* probe parameters */ +/*********************************************************************************************/ +extern int g_nip_probe_max; + /*********************************************************************************************/ /* nip debug parameters */ /*********************************************************************************************/ @@ -92,7 +97,7 @@ do { \ /* Debugging of packet retransmission after ACK */ extern int g_ack_retrans_debug; - #define RETRANS_DBG(fmt, ...) \ +#define RETRANS_DBG(fmt, ...) \ do { \ if (g_ack_retrans_debug) \ pr_crit(fmt, ##__VA_ARGS__); \ diff --git a/src/linux/net/newip/tcp_nip_timer.c b/src/linux/net/newip/tcp_nip_timer.c index 07aeec2..aa7f1ca 100644 --- a/src/linux/net/newip/tcp_nip_timer.c +++ b/src/linux/net/newip/tcp_nip_timer.c @@ -181,7 +181,6 @@ 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 void tcp_nip_probe_timer(struct sock *sk) { struct inet_connection_sock *icsk = inet_csk(sk); @@ -198,11 +197,8 @@ void tcp_nip_probe_timer(struct sock *sk) return; } -#ifdef NIP_MAX_PROBES - max_probes = NIP_MAX_PROBES; // 2000 - fix session auto close -#else - max_probes = sock_net(sk)->ipv4.sysctl_tcp_retries2; -#endif + /* default: sock_net(sk)->ipv4.sysctl_tcp_retries2 */ + max_probes = g_nip_probe_max; /* fix session auto close */ if (sock_flag(sk, SOCK_DEAD)) { const bool alive = inet_csk_rto_backoff(icsk, TCP_RTO_MAX) < TCP_RTO_MAX; @@ -224,6 +220,8 @@ abort: icsk_backoff = icsk->icsk_backoff; __func__, 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; 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. */ -- Gitee