from mo
[unix-history] / usr / src / sys / netinet / tcp_usrreq.c
index 5f7d027..77c4525 100644 (file)
@@ -1,4 +1,4 @@
-/*     tcp_usrreq.c    1.67    82/10/17        */
+/*     tcp_usrreq.c    1.74    83/02/10        */
 
 #include "../h/param.h"
 #include "../h/systm.h"
 
 #include "../h/param.h"
 #include "../h/systm.h"
@@ -6,11 +6,14 @@
 #include "../h/socket.h"
 #include "../h/socketvar.h"
 #include "../h/protosw.h"
 #include "../h/socket.h"
 #include "../h/socketvar.h"
 #include "../h/protosw.h"
-#include "../netinet/in.h"
+#include "../h/errno.h"
+
+#include "../net/if.h"
 #include "../net/route.h"
 #include "../net/route.h"
+
+#include "../netinet/in.h"
 #include "../netinet/in_pcb.h"
 #include "../netinet/in_systm.h"
 #include "../netinet/in_pcb.h"
 #include "../netinet/in_systm.h"
-#include "../net/if.h"
 #include "../netinet/ip.h"
 #include "../netinet/ip_var.h"
 #include "../netinet/tcp.h"
 #include "../netinet/ip.h"
 #include "../netinet/ip_var.h"
 #include "../netinet/tcp.h"
@@ -20,7 +23,6 @@
 #include "../netinet/tcp_var.h"
 #include "../netinet/tcpip.h"
 #include "../netinet/tcp_debug.h"
 #include "../netinet/tcp_var.h"
 #include "../netinet/tcpip.h"
 #include "../netinet/tcp_debug.h"
-#include <errno.h>
 
 /*
  * TCP protocol interface to socket abstraction.
 
 /*
  * TCP protocol interface to socket abstraction.
@@ -34,11 +36,10 @@ struct      tcpcb *tcp_newtcpcb();
  * (called from the software clock routine), then timertype tells which timer.
  */
 /*ARGSUSED*/
  * (called from the software clock routine), then timertype tells which timer.
  */
 /*ARGSUSED*/
-tcp_usrreq(so, req, m, nam, opt)
+tcp_usrreq(so, req, m, nam)
        struct socket *so;
        int req;
        struct mbuf *m, *nam;
        struct socket *so;
        int req;
        struct mbuf *m, *nam;
-       struct socketopt *opt;
 {
        register struct inpcb *inp = sotoinpcb(so);
        register struct tcpcb *tp;
 {
        register struct inpcb *inp = sotoinpcb(so);
        register struct tcpcb *tp;
@@ -78,7 +79,7 @@ tcp_usrreq(so, req, m, nam, opt)
                error = tcp_attach(so);
                if (error)
                        break;
                error = tcp_attach(so);
                if (error)
                        break;
-               if ((so->so_options & SO_DONTLINGER) == 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 +93,9 @@ tcp_usrreq(so, req, m, nam, opt)
         */
        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 +159,7 @@ tcp_usrreq(so, req, m, nam, opt)
         * 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 +182,9 @@ tcp_usrreq(so, req, m, nam, opt)
         */
        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 +211,7 @@ tcp_usrreq(so, req, m, nam, opt)
         * 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 +259,7 @@ tcp_usrreq(so, req, m, nam, opt)
         * 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;
 
@@ -286,7 +286,7 @@ tcp_attach(so)
        struct inpcb *inp;
        int error;
 
        struct inpcb *inp;
        int error;
 
-       error = in_pcbreserve(so, tcp_sendspace, tcp_recvspace);
+       error = soreserve(so, tcp_sendspace, tcp_recvspace);
        if (error)
                goto bad;
        error = in_pcballoc(so, &tcb);
        if (error)
                goto bad;
        error = in_pcballoc(so, &tcb);
@@ -314,21 +314,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 +344,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 +354,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 +366,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);
 }
 }