(no message)
authorBill Joy <root@ucbvax.Berkeley.EDU>
Sun, 25 Jul 1982 09:12:43 +0000 (01:12 -0800)
committerBill Joy <root@ucbvax.Berkeley.EDU>
Sun, 25 Jul 1982 09:12:43 +0000 (01:12 -0800)
SCCS-vsn: sys/netinet/in_pcb.c 4.29

usr/src/sys/netinet/in_pcb.c

index 6ba0ab2..83dcec2 100644 (file)
@@ -1,4 +1,4 @@
-/*     in_pcb.c        4.28    82/06/20        */
+/*     in_pcb.c        4.29    82/07/24        */
 
 #include "../h/param.h"
 #include "../h/systm.h"
 
 #include "../h/param.h"
 #include "../h/systm.h"
@@ -38,7 +38,7 @@
  * hold on to the protocol control block for a unreasonably long time
  * after the connection is used up to avoid races in later connection
  * establishment.  To handle this we allow higher-level routines to
  * hold on to the protocol control block for a unreasonably long time
  * after the connection is used up to avoid races in later connection
  * establishment.  To handle this we allow higher-level routines to
- * disassociate themselves from the socket, marking it SS_USERGONE while
+ * disassociate themselves from the socket, marking it SS_NOFDREF while
  * the disconnect is in progress.  We notice that this has happened
  * when the disconnect is complete, and perform the PRU_DETACH operation,
  * freeing the socket.
  * the disconnect is in progress.  We notice that this has happened
  * when the disconnect is complete, and perform the PRU_DETACH operation,
  * freeing the socket.
  */
 struct in_addr zeroin_addr;
 
  */
 struct in_addr zeroin_addr;
 
+in_pcbreserve(so, sndcc, rcvcc)
+       struct socket *so;
+       int sndcc, rcvcc;
+{
+
+       if (sbreserve(&so->so_snd, sndcc) == 0)
+               goto bad;
+       if (sbreserve(&so->so_rcv, rcvcc) == 0)
+               goto bad2;
+       return (0);
+bad2:
+       sbrelease(&so->so_snd);
+bad:
+       return (ENOBUFS);
+}
+
+in_pcballoc(so, head)
+       struct socket *so;
+       struct inpcb *head;
+{
+       struct mbuf *m;
+       register struct inpcb *inp;
+
+       m = m_getclr(M_DONTWAIT);
+       if (m == 0)
+               return (ENOBUFS);
+       inp = mtod(m, struct inpcb *);
+       inp->inp_head = head;
+       inp->inp_socket = so;
+       insque(inp, head);
+       so->so_pcb = (caddr_t)inp;
+       return (0);
+}
+       
+in_pcbbind(inp, sin)
+       register struct inpcb *inp;
+       struct sockaddr_in *sin;
+{
+       register struct socket *so = inp->inp_socket;
+       register struct inpcb *head = inp->inp_head;
+       u_short lport = 0;
+
+       if (ifnet == 0)
+               return (EADDRNOTAVAIL);
+       if (sin) {
+               if (sin->sin_family != AF_INET)
+                       return (EAFNOSUPPORT);
+               if (sin->sin_addr.s_addr) {
+                       int tport = sin->sin_port;
+
+                       sin->sin_port = 0;              /* yech... */
+                       if (if_ifwithaddr((struct sockaddr *)sin) == 0)
+                               return (EADDRNOTAVAIL);
+                       sin->sin_port = tport;
+               }
+               lport = sin->sin_port;
+               if (lport) {
+                       u_short aport = lport;
+                       int wild = 0;
+#if vax
+                       aport = htons(aport);
+#endif
+                       /* GROSS */
+                       if (aport < IPPORT_RESERVED && u.u_uid != 0)
+                               return (EACCES);
+                       if ((so->so_proto->pr_flags & PR_CONNREQUIRED) == 0 ||
+                           (so->so_options & SO_ACCEPTCONN) == 0)
+                               wild = INPLOOKUP_WILDCARD;
+                       if (in_pcblookup(head,
+                           zeroin_addr, 0, sin->sin_addr, lport, wild))
+                               return (EADDRINUSE);
+               }
+       }
+       if (sin)
+               inp->inp_laddr = sin->sin_addr;
+       if (lport == 0)
+               do {
+                       if (head->inp_lport++ < IPPORT_RESERVED)
+                               head->inp_lport = IPPORT_RESERVED;
+                       lport = htons(head->inp_lport);
+               } while (in_pcblookup(head,
+                           zeroin_addr, 0, inp->inp_laddr, lport, 0));
+       inp->inp_lport = lport;
+       return (0);
+}
+
+/* BEGIN DEPRECATED */
 /*
  * Allocate a protocol control block, space
  * for send and receive data, and local host information.
 /*
  * Allocate a protocol control block, space
  * for send and receive data, and local host information.
@@ -123,6 +210,7 @@ bad:
        (void) m_free(m);
        return (ENOBUFS);
 }
        (void) m_free(m);
        return (ENOBUFS);
 }
+/* END DEPRECATED */
 
 /*
  * Connect from a socket to a specified address.
 
 /*
  * Connect from a socket to a specified address.
@@ -176,7 +264,7 @@ in_pcbdisconnect(inp)
 
        inp->inp_faddr.s_addr = 0;
        inp->inp_fport = 0;
 
        inp->inp_faddr.s_addr = 0;
        inp->inp_fport = 0;
-       if (inp->inp_socket->so_state & SS_USERGONE)
+       if (inp->inp_socket->so_state & SS_NOFDREF)
                in_pcbdetach(inp);
 }
 
                in_pcbdetach(inp);
 }