stuff from bill to insure no references are kept to free'd cb's
authorSam Leffler <sam@ucbvax.Berkeley.EDU>
Tue, 18 Jan 1983 10:05:40 +0000 (02:05 -0800)
committerSam Leffler <sam@ucbvax.Berkeley.EDU>
Tue, 18 Jan 1983 10:05:40 +0000 (02:05 -0800)
SCCS-vsn: sys/netinet/tcp_input.c 1.87
SCCS-vsn: sys/netinet/tcp_subr.c 4.39
SCCS-vsn: sys/netinet/tcp_timer.c 4.30
SCCS-vsn: sys/netinet/tcp_usrreq.c 1.73
SCCS-vsn: sys/netinet/tcp_var.h 4.18

usr/src/sys/netinet/tcp_input.c
usr/src/sys/netinet/tcp_subr.c
usr/src/sys/netinet/tcp_timer.c
usr/src/sys/netinet/tcp_usrreq.c
usr/src/sys/netinet/tcp_var.h

index 8c0455d..aded2cb 100644 (file)
@@ -1,4 +1,4 @@
-/*     tcp_input.c     1.86    83/01/08        */
+/*     tcp_input.c     1.87    83/01/17        */
 
 #include "../h/param.h"
 #include "../h/systm.h"
 
 #include "../h/param.h"
 #include "../h/systm.h"
@@ -257,10 +257,8 @@ tcp_input(m0)
                     SEQ_GT(ti->ti_ack, tp->snd_max)))
                        goto dropwithreset;
                if (tiflags & TH_RST) {
                     SEQ_GT(ti->ti_ack, tp->snd_max)))
                        goto dropwithreset;
                if (tiflags & TH_RST) {
-                       if (tiflags & TH_ACK) {
-                               tcp_drop(tp, ECONNREFUSED);
-                               tp = 0;
-                       }
+                       if (tiflags & TH_ACK)
+                               tp = tcp_drop(tp, ECONNREFUSED);
                        goto drop;
                }
                if ((tiflags & TH_SYN) == 0)
                        goto drop;
                }
                if ((tiflags & TH_SYN) == 0)
@@ -364,10 +362,9 @@ trimthenstep6:
         * If data is received on a connection after the
         * user processes are gone, then RST the other end.
         */
         * If data is received on a connection after the
         * user processes are gone, then RST the other end.
         */
-       if (so->so_state & SS_NOFDREF && tp->t_state > TCPS_CLOSE_WAIT &&
+       if ((so->so_state & SS_NOFDREF) && tp->t_state > TCPS_CLOSE_WAIT &&
            ti->ti_len) {
            ti->ti_len) {
-               tcp_close(tp);
-               tp = 0;
+               tp = tcp_close(tp);
                goto dropwithreset;
        }
 
                goto dropwithreset;
        }
 
@@ -384,23 +381,20 @@ trimthenstep6:
        if (tiflags&TH_RST) switch (tp->t_state) {
 
        case TCPS_SYN_RECEIVED:
        if (tiflags&TH_RST) switch (tp->t_state) {
 
        case TCPS_SYN_RECEIVED:
-               tcp_drop(tp, ECONNREFUSED);
-               tp = 0;
+               tp = tcp_drop(tp, ECONNREFUSED);
                goto drop;
 
        case TCPS_ESTABLISHED:
        case TCPS_FIN_WAIT_1:
        case TCPS_FIN_WAIT_2:
        case TCPS_CLOSE_WAIT:
                goto drop;
 
        case TCPS_ESTABLISHED:
        case TCPS_FIN_WAIT_1:
        case TCPS_FIN_WAIT_2:
        case TCPS_CLOSE_WAIT:
-               tcp_drop(tp, ECONNRESET);
-               tp = 0;
+               tp = tcp_drop(tp, ECONNRESET);
                goto drop;
 
        case TCPS_CLOSING:
        case TCPS_LAST_ACK:
        case TCPS_TIME_WAIT:
                goto drop;
 
        case TCPS_CLOSING:
        case TCPS_LAST_ACK:
        case TCPS_TIME_WAIT:
-               tcp_close(tp);
-               tp = 0;
+               tp = tcp_close(tp);
                goto drop;
        }
 
                goto drop;
        }
 
@@ -409,8 +403,7 @@ trimthenstep6:
         * error and we send an RST and drop the connection.
         */
        if (tiflags & TH_SYN) {
         * error and we send an RST and drop the connection.
         */
        if (tiflags & TH_SYN) {
-               tcp_drop(tp, ECONNRESET);
-               tp = 0;
+               tp = tcp_drop(tp, ECONNRESET);
                goto dropwithreset;
        }
 
                goto dropwithreset;
        }
 
@@ -544,10 +537,8 @@ trimthenstep6:
                 * and return.
                 */
                case TCPS_LAST_ACK:
                 * and return.
                 */
                case TCPS_LAST_ACK:
-                       if (ourfinisacked) {
-                               tcp_close(tp);
-                               tp = 0;
-                       }
+                       if (ourfinisacked)
+                               tp = tcp_close(tp);
                        goto drop;
 
                /*
                        goto drop;
 
                /*
index ed9e379..a68ec8c 100644 (file)
@@ -1,4 +1,4 @@
-/*     tcp_subr.c      4.38    83/01/04        */
+/*     tcp_subr.c      4.39    83/01/17        */
 
 #include "../h/param.h"
 #include "../h/systm.h"
 
 #include "../h/param.h"
 #include "../h/systm.h"
@@ -172,8 +172,9 @@ tcp_newtcpcb(inp)
  * the specified error.  If connection is synchronized,
  * then send a RST to peer.
  */
  * the specified error.  If connection is synchronized,
  * then send a RST to peer.
  */
+struct tcpcb *
 tcp_drop(tp, errno)
 tcp_drop(tp, errno)
-       struct tcpcb *tp;
+       register struct tcpcb *tp;
        int errno;
 {
        struct socket *so = tp->t_inpcb->inp_socket;
        int errno;
 {
        struct socket *so = tp->t_inpcb->inp_socket;
@@ -183,14 +184,14 @@ tcp_drop(tp, errno)
                (void) tcp_output(tp);
        }
        so->so_error = errno;
                (void) tcp_output(tp);
        }
        so->so_error = errno;
-       tcp_close(tp);
+       return (tcp_close(tp));
 }
 
 tcp_abort(inp)
        struct inpcb *inp;
 {
 
 }
 
 tcp_abort(inp)
        struct inpcb *inp;
 {
 
-       tcp_close((struct tcpcb *)inp->inp_ppcb);
+       (void) tcp_close((struct tcpcb *)inp->inp_ppcb);
 }
 
 /*
 }
 
 /*
@@ -199,6 +200,7 @@ tcp_abort(inp)
  *     discard internet protocol block
  *     wake up any sleepers
  */
  *     discard internet protocol block
  *     wake up any sleepers
  */
+struct tcpcb *
 tcp_close(tp)
        register struct tcpcb *tp;
 {
 tcp_close(tp)
        register struct tcpcb *tp;
 {
@@ -219,6 +221,7 @@ tcp_close(tp)
        inp->inp_ppcb = 0;
        soisdisconnected(so);
        in_pcbdetach(inp);
        inp->inp_ppcb = 0;
        soisdisconnected(so);
        in_pcbdetach(inp);
+       return ((struct tcpcb *)0);
 }
 
 tcp_drain()
 }
 
 tcp_drain()
index 564e50d..4c4589c 100644 (file)
@@ -1,4 +1,4 @@
-/*     tcp_timer.c     4.29    83/01/04        */
+/*     tcp_timer.c     4.30    83/01/17        */
 
 #include "../h/param.h"
 #include "../h/systm.h"
 
 #include "../h/param.h"
 #include "../h/systm.h"
@@ -107,6 +107,7 @@ int tcpexprexmtbackoff = 0;
 /*
  * TCP timer processing.
  */
 /*
  * TCP timer processing.
  */
+struct tcpcb *
 tcp_timers(tp, timer)
        register struct tcpcb *tp;
        int timer;
 tcp_timers(tp, timer)
        register struct tcpcb *tp;
        int timer;
@@ -119,8 +120,8 @@ tcp_timers(tp, timer)
         * control block.
         */
        case TCPT_2MSL:
         * control block.
         */
        case TCPT_2MSL:
-               tcp_close(tp);
-               return;
+               tp = tcp_close(tp);
+               break;
 
        /*
         * Retransmission timer went off.  Message has not
 
        /*
         * Retransmission timer went off.  Message has not
@@ -131,8 +132,8 @@ tcp_timers(tp, timer)
        case TCPT_REXMT:
                tp->t_rxtshift++;
                if (tp->t_rxtshift > TCP_MAXRXTSHIFT) {
        case TCPT_REXMT:
                tp->t_rxtshift++;
                if (tp->t_rxtshift > TCP_MAXRXTSHIFT) {
-                       tcp_drop(tp, ETIMEDOUT);
-                       return;
+                       tp = tcp_drop(tp, ETIMEDOUT);
+                       break;
                }
                TCPT_RANGESET(tp->t_timer[TCPT_REXMT],
                    (int)tp->t_srtt, TCPTV_MIN, TCPTV_MAX);
                }
                TCPT_RANGESET(tp->t_timer[TCPT_REXMT],
                    (int)tp->t_srtt, TCPTV_MIN, TCPTV_MAX);
@@ -149,7 +150,7 @@ tcp_timers(tp, timer)
                tp->snd_nxt = tp->snd_una;
                /* this only transmits one segment! */
                (void) tcp_output(tp);
                tp->snd_nxt = tp->snd_una;
                /* this only transmits one segment! */
                (void) tcp_output(tp);
-               return;
+               break;
 
        /*
         * Persistance timer into zero window.
 
        /*
         * Persistance timer into zero window.
@@ -160,7 +161,7 @@ tcp_timers(tp, timer)
                tp->t_force = 1;
                (void) tcp_output(tp);
                tp->t_force = 0;
                tp->t_force = 1;
                (void) tcp_output(tp);
                tp->t_force = 0;
-               return;
+               break;
 
        /*
         * Keep-alive timer went off; send something
 
        /*
         * Keep-alive timer went off; send something
@@ -187,9 +188,10 @@ tcp_timers(tp, timer)
                } else
                        tp->t_idle = 0;
                tp->t_timer[TCPT_KEEP] = TCPTV_KEEP;
                } else
                        tp->t_idle = 0;
                tp->t_timer[TCPT_KEEP] = TCPTV_KEEP;
-               return;
+               break;
        dropit:
        dropit:
-               tcp_drop(tp, ETIMEDOUT);
-               return;
+               tp = tcp_drop(tp, ETIMEDOUT);
+               break;
        }
        }
+       return (tp);
 }
 }
index 4b83833..69c8c19 100644 (file)
@@ -1,4 +1,4 @@
-/*     tcp_usrreq.c    1.72    83/01/13        */
+/*     tcp_usrreq.c    1.73    83/01/17        */
 
 #include "../h/param.h"
 #include "../h/systm.h"
 
 #include "../h/param.h"
 #include "../h/systm.h"
@@ -78,7 +78,7 @@ tcp_usrreq(so, req, m, nam)
                error = tcp_attach(so);
                if (error)
                        break;
                error = tcp_attach(so);
                if (error)
                        break;
-               if (so->so_options & SO_LINGER && so->so_linger == 0)
+               if ((so->so_options & SO_LINGER) && so->so_linger == 0)
                        so->so_linger = TCP_LINGERTIME;
                tp = sototcpcb(so);
                break;
                        so->so_linger = TCP_LINGERTIME;
                tp = sototcpcb(so);
                break;
@@ -92,11 +92,9 @@ tcp_usrreq(so, req, m, nam)
         */
        case PRU_DETACH:
                if (tp->t_state > TCPS_LISTEN)
         */
        case PRU_DETACH:
                if (tp->t_state > TCPS_LISTEN)
-                       tcp_disconnect(tp);
-               else {
-                       tcp_close(tp);
-                       tp = 0;
-               }
+                       tp = tcp_disconnect(tp);
+               else
+                       tp = tcp_close(tp);
                break;
 
        /*
                break;
 
        /*
@@ -160,7 +158,7 @@ tcp_usrreq(so, req, m, nam)
         * SHOULD IMPLEMENT LATER PRU_CONNECT VIA REALLOC TCPCB.
         */
        case PRU_DISCONNECT:
         * SHOULD IMPLEMENT LATER PRU_CONNECT VIA REALLOC TCPCB.
         */
        case PRU_DISCONNECT:
-               tcp_disconnect(tp);
+               tp = tcp_disconnect(tp);
                break;
 
        /*
                break;
 
        /*
@@ -183,8 +181,9 @@ tcp_usrreq(so, req, m, nam)
         */
        case PRU_SHUTDOWN:
                socantsendmore(so);
         */
        case PRU_SHUTDOWN:
                socantsendmore(so);
-               tcp_usrclosed(tp);
-               error = tcp_output(tp);
+               tp = tcp_usrclosed(tp);
+               if (tp)
+                       error = tcp_output(tp);
                break;
 
        /*
                break;
 
        /*
@@ -211,7 +210,7 @@ tcp_usrreq(so, req, m, nam)
         * Abort the TCP.
         */
        case PRU_ABORT:
         * Abort the TCP.
         */
        case PRU_ABORT:
-               tcp_drop(tp, ECONNABORTED);
+               tp = tcp_drop(tp, ECONNABORTED);
                break;
 
 /* SOME AS YET UNIMPLEMENTED HOOKS */
                break;
 
 /* SOME AS YET UNIMPLEMENTED HOOKS */
@@ -259,7 +258,7 @@ tcp_usrreq(so, req, m, nam)
         * routine for tracing's sake.
         */
        case PRU_SLOWTIMO:
         * routine for tracing's sake.
         */
        case PRU_SLOWTIMO:
-               tcp_timers(tp, (int)nam);
+               tp = tcp_timers(tp, (int)nam);
                req |= (int)nam << 8;           /* for debug's sake */
                break;
 
                req |= (int)nam << 8;           /* for debug's sake */
                break;
 
@@ -314,21 +313,24 @@ bad:
  * current input data; switch states based on user close, and
  * send segment to peer (with FIN).
  */
  * current input data; switch states based on user close, and
  * send segment to peer (with FIN).
  */
+struct tcpcb *
 tcp_disconnect(tp)
 tcp_disconnect(tp)
-       struct tcpcb *tp;
+       register struct tcpcb *tp;
 {
        struct socket *so = tp->t_inpcb->inp_socket;
 
        if (tp->t_state < TCPS_ESTABLISHED)
 {
        struct socket *so = tp->t_inpcb->inp_socket;
 
        if (tp->t_state < TCPS_ESTABLISHED)
-               tcp_close(tp);
+               tp = tcp_close(tp);
        else if (so->so_linger == 0)
        else if (so->so_linger == 0)
-               tcp_drop(tp, 0);
+               tp = tcp_drop(tp, 0);
        else {
                soisdisconnecting(so);
                sbflush(&so->so_rcv);
        else {
                soisdisconnecting(so);
                sbflush(&so->so_rcv);
-               tcp_usrclosed(tp);
-               (void) tcp_output(tp);
+               tp = tcp_usrclosed(tp);
+               if (tp)
+                       (void) tcp_output(tp);
        }
        }
+       return (tp);
 }
 
 /*
 }
 
 /*
@@ -341,8 +343,9 @@ tcp_disconnect(tp)
  * for peer to send FIN or not respond to keep-alives, etc.
  * We can let the user exit from the close as soon as the FIN is acked.
  */
  * for peer to send FIN or not respond to keep-alives, etc.
  * We can let the user exit from the close as soon as the FIN is acked.
  */
+struct tcpcb *
 tcp_usrclosed(tp)
 tcp_usrclosed(tp)
-       struct tcpcb *tp;
+       register struct tcpcb *tp;
 {
 
        switch (tp->t_state) {
 {
 
        switch (tp->t_state) {
@@ -350,7 +353,7 @@ tcp_usrclosed(tp)
        case TCPS_LISTEN:
        case TCPS_SYN_SENT:
                tp->t_state = TCPS_CLOSED;
        case TCPS_LISTEN:
        case TCPS_SYN_SENT:
                tp->t_state = TCPS_CLOSED;
-               tcp_close(tp);
+               tp = tcp_close(tp);
                break;
 
        case TCPS_SYN_RECEIVED:
                break;
 
        case TCPS_SYN_RECEIVED:
@@ -362,6 +365,7 @@ tcp_usrclosed(tp)
                tp->t_state = TCPS_LAST_ACK;
                break;
        }
                tp->t_state = TCPS_LAST_ACK;
                break;
        }
-       if (tp->t_state >= TCPS_FIN_WAIT_2)
+       if (tp && tp->t_state >= TCPS_FIN_WAIT_2)
                soisdisconnected(tp->t_inpcb->inp_socket);
                soisdisconnected(tp->t_inpcb->inp_socket);
+       return (tp);
 }
 }
index a51969c..a1ce743 100644 (file)
@@ -1,4 +1,4 @@
-/*     tcp_var.h       4.17    82/12/20        */
+/*     tcp_var.h       4.18    83/01/17        */
 
 /*
  * Kernel variables for tcp.
 
 /*
  * Kernel variables for tcp.
@@ -75,4 +75,6 @@ struct        tcpstat {
 struct inpcb tcb;              /* head of queue of active tcpcb's */
 struct tcpstat tcpstat;        /* tcp statistics */
 struct tcpiphdr *tcp_template();
 struct inpcb tcb;              /* head of queue of active tcpcb's */
 struct tcpstat tcpstat;        /* tcp statistics */
 struct tcpiphdr *tcp_template();
+struct tcpcb *tcp_close(), *tcp_drop();
+struct tcpcb *tcp_timers(), *tcp_disconnect(), *tcp_usrclosed();
 #endif
 #endif