Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/netinet Minor changes: style, improve comments (and put ...



details:   https://anonhg.NetBSD.org/src/rev/1747dc8b2590
branches:  trunk
changeset: 831382:1747dc8b2590
user:      maxv <maxv%NetBSD.org@localhost>
date:      Wed Mar 28 13:50:14 2018 +0000

description:
Minor changes: style, improve comments (and put them at the correct place),
use NULL for pointers, and add {}s to prevent confusion.

diffstat:

 sys/netinet/tcp_input.c |  246 ++++++++++++++++++++++++-----------------------
 1 files changed, 127 insertions(+), 119 deletions(-)

diffs (truncated from 724 to 300 lines):

diff -r 0ccde89b12b8 -r 1747dc8b2590 sys/netinet/tcp_input.c
--- a/sys/netinet/tcp_input.c   Wed Mar 28 06:48:55 2018 +0000
+++ b/sys/netinet/tcp_input.c   Wed Mar 28 13:50:14 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: tcp_input.c,v 1.388 2018/03/23 09:30:55 maxv Exp $     */
+/*     $NetBSD: tcp_input.c,v 1.389 2018/03/28 13:50:14 maxv Exp $     */
 
 /*
  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -148,7 +148,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: tcp_input.c,v 1.388 2018/03/23 09:30:55 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: tcp_input.c,v 1.389 2018/03/28 13:50:14 maxv Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -458,10 +458,10 @@
        TCP_REASS_LOCK_CHECK(tp);
 
        /*
-        * Call with th==0 after become established to
+        * Call with th==NULL after become established to
         * force pre-ESTABLISHED data up to user socket.
         */
-       if (th == 0)
+       if (th == NULL)
                goto present;
 
        m_claimm(m, &tcp_reass_mowner);
@@ -847,8 +847,7 @@
        if (ip) {
                in_print(src, sizeof(src), &ip->ip_src);
                in_print(dst, sizeof(dst), &ip->ip_dst);
-       }
-       else {
+       } else {
                strlcpy(src, "(unknown)", sizeof(src));
                strlcpy(dst, "(unknown)", sizeof(dst));
        }
@@ -868,8 +867,7 @@
        if (ip6) {
                in6_print(src, sizeof(src), &ip6->ip6_src);
                in6_print(dst, sizeof(dst), &ip6->ip6_dst);
-       }
-       else {
+       } else {
                strlcpy(src, "(unknown v6)", sizeof(src));
                strlcpy(dst, "(unknown v6)", sizeof(dst));
        }
@@ -990,16 +988,19 @@
        return -1;
 }
 
-/* When a packet arrives addressed to a vestigial tcpbp, we
+/*
+ * When a packet arrives addressed to a vestigial tcpbp, we
  * nevertheless have to respond to it per the spec.
+ *
+ * This code is duplicated from the one in tcp_input().
  */
 static void tcp_vtw_input(struct tcphdr *th, vestigial_inpcb_t *vp,
     struct mbuf *m, int tlen)
 {
-       int             tiflags;
-       int             todrop;
-       uint32_t        t_flags = 0;
-       uint64_t        *tcps;
+       int tiflags;
+       int todrop;
+       uint32_t t_flags = 0;
+       uint64_t *tcps;
 
        tiflags = th->th_flags;
        todrop  = vp->rcv_nxt - th->th_seq;
@@ -1026,6 +1027,7 @@
                        if (tiflags & TH_RST)
                                goto drop;
                        tiflags &= ~(TH_FIN|TH_RST);
+
                        /*
                         * Send an ACK to resynchronize and drop any data.
                         * But keep on processing for RST or ACK.
@@ -1036,8 +1038,8 @@
                        tcps[TCP_STAT_RCVDUPPACK] += 1;
                        tcps[TCP_STAT_RCVDUPBYTE] += todrop;
                        TCP_STAT_PUTREF();
-               } else if ((tiflags & TH_RST)
-                          && th->th_seq != vp->rcv_nxt) {
+               } else if ((tiflags & TH_RST) &&
+                   th->th_seq != vp->rcv_nxt) {
                        /*
                         * Test for reset before adjusting the sequence
                         * number for overlapping data.
@@ -1077,7 +1079,7 @@
         * If segment ends after window, drop trailing data
         * (and PUSH and FIN); if nothing left, just ACK.
         */
-       todrop = (th->th_seq + tlen) - (vp->rcv_nxt+vp->rcv_wnd);
+       todrop = (th->th_seq + tlen) - (vp->rcv_nxt + vp->rcv_wnd);
 
        if (todrop > 0) {
                TCP_STATINC(TCP_STAT_RCVPACKAFTERWIN);
@@ -1089,19 +1091,22 @@
                         * th->th_seq >= vp->rcv_nxt + vp->rcv_wnd
                         */
                        TCP_STATADD(TCP_STAT_RCVBYTEAFTERWIN, tlen);
+
                        /*
                         * If a new connection request is received
                         * while in TIME_WAIT, drop the old connection
                         * and start over if the sequence numbers
                         * are above the previous ones.
                         */
-                       if ((tiflags & TH_SYN)
-                           && SEQ_GT(th->th_seq, vp->rcv_nxt)) {
-                               /* We only support this in the !NOFDREF case, which
+                       if ((tiflags & TH_SYN) &&
+                           SEQ_GT(th->th_seq, vp->rcv_nxt)) {
+                               /*
+                                * We only support this in the !NOFDREF case, which
                                 * is to say: not here.
                                 */
                                goto dropwithreset;
                        }
+
                        /*
                         * If window is closed can only take segments at
                         * window edge, and have to drop data and PUSH from
@@ -1112,10 +1117,12 @@
                        if (vp->rcv_wnd == 0 && th->th_seq == vp->rcv_nxt) {
                                t_flags |= TF_ACKNOW;
                                TCP_STATINC(TCP_STAT_RCVWINPROBE);
-                       } else
+                       } else {
                                goto dropafterack;
-               } else
+                       }
+               } else {
                        TCP_STATADD(TCP_STAT_RCVBYTEAFTERWIN, todrop);
+               }
                m_adj(m, -todrop);
                tlen -= todrop;
                tiflags &= ~(TH_PUSH|TH_FIN);
@@ -1161,15 +1168,14 @@
         * We may want to rate-limit ACKs against SYN/RST attack.
         */
        if (ppsratecheck(&tcp_ackdrop_ppslim_last, &tcp_ackdrop_ppslim_count,
-                        tcp_ackdrop_ppslim) == 0) {
+           tcp_ackdrop_ppslim) == 0) {
                /* XXX stat */
                goto drop;
        }
        /* ...fall into dropafterack2... */
 
 dropafterack2:
-       (void)tcp_respond(0, m, m, th, th->th_seq + tlen, th->th_ack,
-                         TH_ACK);
+       (void)tcp_respond(0, m, m, th, th->th_seq + tlen, th->th_ack, TH_ACK);
        return;
 
 dropwithreset:
@@ -1180,13 +1186,13 @@
        if (tiflags & TH_RST)
                goto drop;
 
-       if (tiflags & TH_ACK)
+       if (tiflags & TH_ACK) {
                tcp_respond(0, m, m, th, (tcp_seq)0, th->th_ack, TH_RST);
-       else {
+       } else {
                if (tiflags & TH_SYN)
                        ++tlen;
                (void)tcp_respond(0, m, m, th, th->th_seq + tlen, (tcp_seq)0,
-                                 TH_RST|TH_ACK);
+                   TH_RST|TH_ACK);
        }
        return;
 drop:
@@ -1858,18 +1864,24 @@
        }
 
        /*
-        * Header prediction: check for the two common cases
-        * of a uni-directional data xfer.  If the packet has
-        * no control flags, is in-sequence, the window didn't
-        * change and we're not retransmitting, it's a
-        * candidate.  If the length is zero and the ack moved
-        * forward, we're the sender side of the xfer.  Just
-        * free the data acked & wake any higher level process
-        * that was blocked waiting for space.  If the length
-        * is non-zero and the ack didn't move, we're the
-        * receiver side.  If we're getting packets in-order
-        * (the reassembly queue is empty), add the data to
-        * the socket buffer and note that we need a delayed ack.
+        * Fast path: check for the two common cases of a uni-directional
+        * data transfer. If:
+        *    o We are in the ESTABLISHED state, and
+        *    o The packet has no control flags, and
+        *    o The packet is in-sequence, and
+        *    o The window didn't change, and
+        *    o We are not retransmitting
+        * It's a candidate.
+        *
+        * If the length (tlen) is zero and the ack moved forward, we're
+        * the sender side of the transfer. Just free the data acked and
+        * wake any higher level process that was blocked waiting for
+        * space.
+        *
+        * If the length is non-zero and the ack didn't move, we're the
+        * receiver side. If we're getting packets in-order (the reassembly
+        * queue is empty), add the data to the socket buffer and note
+        * that we need a delayed ack.
         */
        if (tp->t_state == TCPS_ESTABLISHED &&
            (tiflags & (TH_SYN|TH_FIN|TH_RST|TH_URG|TH_ECE|TH_CWR|TH_ACK))
@@ -1888,8 +1900,7 @@
                 * note that we already know
                 *      TSTMP_GEQ(opti.ts_val, tp->ts_recent)
                 */
-               if (opti.ts_present &&
-                   SEQ_LEQ(th->th_seq, tp->last_ack_sent)) {
+               if (opti.ts_present && SEQ_LEQ(th->th_seq, tp->last_ack_sent)) {
                        tp->ts_recent_age = tcp_now;
                        tp->ts_recent = opti.ts_val;
                }
@@ -1949,7 +1960,7 @@
                                sowwakeup(so);
                                if (so->so_snd.sb_cc) {
                                        KERNEL_LOCK(1, NULL);
-                                       (void) tcp_output(tp);
+                                       (void)tcp_output(tp);
                                        KERNEL_UNLOCK_ONE(NULL);
                                }
                                if (tcp_saveti)
@@ -1959,7 +1970,7 @@
                } else if (th->th_ack == tp->snd_una &&
                    TAILQ_FIRST(&tp->segq) == NULL &&
                    tlen <= sbspace(&so->so_rcv)) {
-                       int newsize = 0;        /* automatic sockbuf scaling */
+                       int newsize = 0;
 
                        /*
                         * this is a pure, in-sequence data packet
@@ -2030,9 +2041,9 @@
                         * Drop TCP, IP headers and TCP options then add data
                         * to socket buffer.
                         */
-                       if (so->so_state & SS_CANTRCVMORE)
+                       if (so->so_state & SS_CANTRCVMORE) {
                                m_freem(m);
-                       else {
+                       } else {
                                /*
                                 * Set new socket buffer size.
                                 * Give up when limit is reached.
@@ -2048,7 +2059,7 @@
                        tcp_setup_ack(tp, th);
                        if (tp->t_flags & TF_ACKNOW) {
                                KERNEL_LOCK(1, NULL);
-                               (void) tcp_output(tp);
+                               (void)tcp_output(tp);
                                KERNEL_UNLOCK_ONE(NULL);
                        }
                        if (tcp_saveti)
@@ -2118,7 +2129,6 @@
                                tp->t_flags |= TF_ECN_PERMIT;
                                TCP_STATINC(TCP_STAT_ECN_SHS);
                        }
-
                }
                tp->irs = th->th_seq;
                tcp_rcvseqinit(tp);
@@ -2169,8 +2179,9 @@
                         */
                        if (tp->t_rtttime)
                                tcp_xmit_timer(tp, tcp_now - tp->t_rtttime);
-               } else
+               } else {
                        tp->t_state = TCPS_SYN_RECEIVED;
+               }
 
                /*
                 * Advance th->th_seq to correspond to first data byte.
@@ -2212,13 +2223,8 @@
            tp->t_state != TCPS_SYN_SENT);
 
        /*
-        * First check timestamp, if present.
-        * Then check that at least some bytes of segment are within
-        * receive window.  If segment begins before rcv_nxt,
-        * drop leading data (and SYN); if nothing left, just ack.
-        *
-        * RFC 1323 PAWS: If we have a timestamp reply on this segment
-        * and it's less than ts_recent, drop it.
+        * RFC1323 PAWS: if we have a timestamp reply on this segment and
+        * it's less than ts_recent, drop it.
         */
        if (opti.ts_present && (tiflags & TH_RST) == 0 && tp->ts_recent &&



Home | Main Index | Thread Index | Old Index