BSD 4_3_Net_2 release
[unix-history] / usr / src / sys / netiso / iso_pcb.c
index f6c63b3..f7e3eb3 100644 (file)
@@ -1,3 +1,38 @@
+/*-
+ * Copyright (c) 1991 The Regents of the University of California.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *     This product includes software developed by the University of
+ *     California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ *     @(#)iso_pcb.c   7.10 (Berkeley) 6/27/91
+ */
+
 /***********************************************************
                Copyright IBM Corporation 1987
 
 /***********************************************************
                Copyright IBM Corporation 1987
 
@@ -27,23 +62,19 @@ SOFTWARE.
 /*
  * $Header: iso_pcb.c,v 4.5 88/06/29 14:59:56 hagens Exp $
  * $Source: /usr/argo/sys/netiso/RCS/iso_pcb.c,v $
 /*
  * $Header: iso_pcb.c,v 4.5 88/06/29 14:59:56 hagens Exp $
  * $Source: /usr/argo/sys/netiso/RCS/iso_pcb.c,v $
- *     @(#)iso_pcb.c   7.7 (Berkeley) 4/16/90
  *
  * Iso address family net-layer(s) pcb stuff. NEH 1/29/87
  */
 
  *
  * Iso address family net-layer(s) pcb stuff. NEH 1/29/87
  */
 
-#ifndef lint
-static char *rcsid = "$Header: iso_pcb.c,v 4.5 88/06/29 14:59:56 hagens Exp $";
-#endif
-
 #ifdef ISO
 
 #include "param.h"
 #include "systm.h"
 #ifdef ISO
 
 #include "param.h"
 #include "systm.h"
-#include "user.h"
 #include "mbuf.h"
 #include "socket.h"
 #include "socketvar.h"
 #include "mbuf.h"
 #include "socket.h"
 #include "socketvar.h"
+#include "errno.h"
+
 #include "argo_debug.h"
 #include "iso.h"
 #include "clnp.h"
 #include "argo_debug.h"
 #include "iso.h"
 #include "clnp.h"
@@ -54,6 +85,12 @@ static char *rcsid = "$Header: iso_pcb.c,v 4.5 88/06/29 14:59:56 hagens Exp $";
 #include "iso_var.h"
 #include "protosw.h"
 
 #include "iso_var.h"
 #include "protosw.h"
 
+#ifdef TPCONS
+#include "../netccitt/x25.h"
+#include "../netccitt/pk.h"
+#include "../netccitt/pk_var.h"
+#endif
+
 #define PCBNULL (struct isopcb *)0
 struct iso_addr zeroiso_addr = {
        0
 #define PCBNULL (struct isopcb *)0
 struct iso_addr zeroiso_addr = {
        0
@@ -86,7 +123,8 @@ iso_pcballoc(so, head)
        isop->isop_head = head;
        isop->isop_socket = so;
        insque(isop, head);
        isop->isop_head = head;
        isop->isop_socket = so;
        insque(isop, head);
-       so->so_pcb = (caddr_t)isop;
+       if (so)
+               so->so_pcb = (caddr_t)isop;
        return 0;
 }
        
        return 0;
 }
        
@@ -182,7 +220,7 @@ iso_pcbbind(isop, nam)
        bcopy((caddr_t)siso, (caddr_t)isop->isop_laddr, siso->siso_len);
        if (suf.s || siso->siso_tlen != 2) {
                if((suf.s < ISO_PORT_RESERVED) && (siso->siso_tlen <= 2) &&
        bcopy((caddr_t)siso, (caddr_t)isop->isop_laddr, siso->siso_len);
        if (suf.s || siso->siso_tlen != 2) {
                if((suf.s < ISO_PORT_RESERVED) && (siso->siso_tlen <= 2) &&
-                  (u.u_uid != 0))
+                  (isop->isop_socket->so_state && SS_PRIV) == 0)
                        return EACCES;
                if ((isop->isop_socket->so_options & SO_REUSEADDR) == 0 &&
                        iso_pcblookup(head, 0, (caddr_t)0, isop->isop_laddr))
                        return EACCES;
                if ((isop->isop_socket->so_options & SO_REUSEADDR) == 0 &&
                        iso_pcblookup(head, 0, (caddr_t)0, isop->isop_laddr))
@@ -418,7 +456,17 @@ iso_pcbdetach(isop)
                printf("iso_pcbdetach(isop 0x%x socket 0x%x so 0x%x)\n", 
                        isop, isop->isop_socket, so);
        ENDDEBUG
                printf("iso_pcbdetach(isop 0x%x socket 0x%x so 0x%x)\n", 
                        isop, isop->isop_socket, so);
        ENDDEBUG
-       if (so ) { /* in the x.25 domain, we sometimes have no socket */
+#ifdef TPCONS
+       if (isop->isop_refcnt) {
+               register struct pklcd *lcp = (struct pklcd *)isop->isop_chan;
+               if (--isop->isop_refcnt > 0)
+                       return;
+               if (lcp && lcp->lcd_state == DATA_TRANSFER)
+                       pk_disconnect(lcp);
+               isop->isop_chan = 0;
+       }
+#endif
+       if (so) { /* in the x.25 domain, we sometimes have no socket */
                so->so_pcb = 0;
                sofree(so); 
        }
                so->so_pcb = 0;
                sofree(so); 
        }