new signals
[unix-history] / usr / src / sys / netinet / tcp_usrreq.c
index eea1712..ebed585 100644 (file)
@@ -1,13 +1,25 @@
 /*
 /*
- * Copyright (c) 1982 Regents of the University of California.
- * All rights reserved.  The Berkeley software License Agreement
- * specifies the terms and conditions for redistribution.
+ * Copyright (c) 1982, 1986, 1988 Regents of the University of California.
+ * All rights reserved.
  *
  *
- *     @(#)tcp_usrreq.c        6.10 (Berkeley) %G%
+ * Redistribution and use in source and binary forms are permitted
+ * provided that the above copyright notice and this paragraph are
+ * duplicated in all such forms and that any documentation,
+ * advertising materials, and other materials related to such
+ * distribution and use acknowledge that the software was developed
+ * by the University of California, Berkeley.  The name of the
+ * University may not be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
+ * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+ *
+ *     @(#)tcp_usrreq.c        7.12 (Berkeley) %G%
  */
 
 #include "param.h"
 #include "systm.h"
  */
 
 #include "param.h"
 #include "systm.h"
+#include "malloc.h"
 #include "mbuf.h"
 #include "socket.h"
 #include "socketvar.h"
 #include "mbuf.h"
 #include "socket.h"
 #include "socketvar.h"
@@ -36,7 +48,6 @@
  */
 extern char *tcpstates[];
 struct tcpcb *tcp_newtcpcb();
  */
 extern char *tcpstates[];
 struct tcpcb *tcp_newtcpcb();
-int    tcpsenderrors;
 
 /*
  * Process a TCP user request for TCP tb.  If this is a send request
 
 /*
  * Process a TCP user request for TCP tb.  If this is a send request
@@ -49,19 +60,25 @@ tcp_usrreq(so, req, m, nam, rights)
        int req;
        struct mbuf *m, *nam, *rights;
 {
        int req;
        struct mbuf *m, *nam, *rights;
 {
-       register struct inpcb *inp = sotoinpcb(so);
+       register struct inpcb *inp;
        register struct tcpcb *tp;
        register struct tcpcb *tp;
-       int s = splnet();
+       int s;
        int error = 0;
        int ostate;
 
        int error = 0;
        int ostate;
 
+#if BSD>=43
        if (req == PRU_CONTROL)
                return (in_control(so, (int)m, (caddr_t)nam,
                        (struct ifnet *)rights));
        if (req == PRU_CONTROL)
                return (in_control(so, (int)m, (caddr_t)nam,
                        (struct ifnet *)rights));
-       if (rights && rights->m_len) {
-               splx(s);
+#else
+       if (req == PRU_CONTROL)
+               return(EOPNOTSUPP);
+#endif
+       if (rights && rights->m_len)
                return (EINVAL);
                return (EINVAL);
-       }
+
+       s = splnet();
+       inp = sotoinpcb(so);
        /*
         * When a TCP is attached to a socket, then there will be
         * a (struct inpcb) pointed at by the socket, and this
        /*
         * When a TCP is attached to a socket, then there will be
         * a (struct inpcb) pointed at by the socket, and this
@@ -155,8 +172,9 @@ tcp_usrreq(so, req, m, nam, rights)
                        break;
                }
                soisconnecting(so);
                        break;
                }
                soisconnecting(so);
+               tcpstat.tcps_connattempt++;
                tp->t_state = TCPS_SYN_SENT;
                tp->t_state = TCPS_SYN_SENT;
-               tp->t_timer[TCPT_KEEP] = TCPTV_KEEP;
+               tp->t_timer[TCPT_KEEP] = TCPTV_KEEP_INIT;
                tp->iss = tcp_iss; tcp_iss += TCP_ISSINCR/2;
                tcp_sendseqinit(tp);
                error = tcp_output(tp);
                tp->iss = tcp_iss; tcp_iss += TCP_ISSINCR/2;
                tcp_sendseqinit(tp);
                error = tcp_output(tp);
@@ -194,6 +212,7 @@ tcp_usrreq(so, req, m, nam, rights)
 
                nam->m_len = sizeof (struct sockaddr_in);
                sin->sin_family = AF_INET;
 
                nam->m_len = sizeof (struct sockaddr_in);
                sin->sin_family = AF_INET;
+               sin->sin_len = sizeof(*sin);
                sin->sin_port = inp->inp_fport;
                sin->sin_addr = inp->inp_faddr;
                break;
                sin->sin_port = inp->inp_fport;
                sin->sin_addr = inp->inp_faddr;
                break;
@@ -222,16 +241,7 @@ tcp_usrreq(so, req, m, nam, rights)
         */
        case PRU_SEND:
                sbappend(&so->so_snd, m);
         */
        case PRU_SEND:
                sbappend(&so->so_snd, m);
-#ifdef notdef
-               if (tp->t_flags & TF_PUSH)
-                       tp->snd_end = tp->snd_una + so->so_snd.sb_cc;
-#endif
                error = tcp_output(tp);
                error = tcp_output(tp);
-               if (error) {            /* XXX fix to use other path */
-                       if (error == ENOBUFS)           /* XXX */
-                               error = 0;              /* XXX */
-                       tcpsenderrors++;
-               }
                break;
 
        /*
                break;
 
        /*
@@ -243,11 +253,15 @@ tcp_usrreq(so, req, m, nam, rights)
 
        case PRU_SENSE:
                ((struct stat *) m)->st_blksize = so->so_snd.sb_hiwat;
 
        case PRU_SENSE:
                ((struct stat *) m)->st_blksize = so->so_snd.sb_hiwat;
+               (void) splx(s);
                return (0);
 
        case PRU_RCVOOB:
                if ((so->so_oobmark == 0 &&
                    (so->so_state & SS_RCVATMARK) == 0) ||
                return (0);
 
        case PRU_RCVOOB:
                if ((so->so_oobmark == 0 &&
                    (so->so_state & SS_RCVATMARK) == 0) ||
+#ifdef SO_OOBINLINE
+                   so->so_options & SO_OOBINLINE ||
+#endif
                    tp->t_oobflags & TCPOOB_HADDATA) {
                        error = EINVAL;
                        break;
                    tp->t_oobflags & TCPOOB_HADDATA) {
                        error = EINVAL;
                        break;
@@ -268,8 +282,16 @@ tcp_usrreq(so, req, m, nam, rights)
                        error = ENOBUFS;
                        break;
                }
                        error = ENOBUFS;
                        break;
                }
-               tp->snd_up = tp->snd_una + so->so_snd.sb_cc + 1;
+               /*
+                * According to RFC961 (Assigned Protocols),
+                * the urgent pointer points to the last octet
+                * of urgent data.  We continue, however,
+                * to consider it to indicate the first octet
+                * of data past the urgent section.
+                * Otherwise, snd_up should be one lower.
+                */
                sbappend(&so->so_snd, m);
                sbappend(&so->so_snd, m);
+               tp->snd_up = tp->snd_una + so->so_snd.sb_cc;
                tp->t_force = 1;
                error = tcp_output(tp);
                tp->t_force = 0;
                tp->t_force = 1;
                error = tcp_output(tp);
                tp->t_force = 0;
@@ -301,6 +323,7 @@ tcp_usrreq(so, req, m, nam, rights)
        return (error);
 }
 
        return (error);
 }
 
+#if BSD>=43
 tcp_ctloutput(op, so, level, optname, mp)
        int op;
        struct socket *so;
 tcp_ctloutput(op, so, level, optname, mp)
        int op;
        struct socket *so;
@@ -335,7 +358,8 @@ tcp_ctloutput(op, so, level, optname, mp)
                        error = EINVAL;
                        break;
                }
                        error = EINVAL;
                        break;
                }
-               (void)m_free(m);
+               if (m)
+                       (void) m_free(m);
                break;
 
        case PRCO_GETOPT:
                break;
 
        case PRCO_GETOPT:
@@ -357,9 +381,11 @@ tcp_ctloutput(op, so, level, optname, mp)
        }
        return (error);
 }
        }
        return (error);
 }
+#endif
+
+u_long tcp_sendspace = 1024*4;
+u_long tcp_recvspace = 1024*4;
 
 
-int    tcp_sendspace = 1024*4;
-int    tcp_recvspace = 1024*4;
 /*
  * Attach TCP protocol to socket, allocating
  * internet protocol control block, tcp control block,
 /*
  * Attach TCP protocol to socket, allocating
  * internet protocol control block, tcp control block,
@@ -372,9 +398,11 @@ tcp_attach(so)
        struct inpcb *inp;
        int error;
 
        struct inpcb *inp;
        int error;
 
-       error = soreserve(so, tcp_sendspace, tcp_recvspace);
-       if (error)
-               return (error);
+       if (so->so_snd.sb_hiwat == 0 || so->so_rcv.sb_hiwat == 0) {
+               error = soreserve(so, tcp_sendspace, tcp_recvspace);
+               if (error)
+                       return (error);
+       }
        error = in_pcballoc(so, &tcb);
        if (error)
                return (error);
        error = in_pcballoc(so, &tcb);
        if (error)
                return (error);