BSD 4_3_Net_2 release
[unix-history] / usr / src / sys / netiso / iso.c
index 3ce64f6..8044d89 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.c       7.14 (Berkeley) 6/27/91
+ */
+
 /***********************************************************
                Copyright IBM Corporation 1987
 
 /***********************************************************
                Copyright IBM Corporation 1987
 
@@ -27,16 +62,10 @@ SOFTWARE.
 /*
  * $Header: iso.c,v 4.11 88/09/19 14:58:35 root Exp $ 
  * $Source: /usr/argo/sys/netiso/RCS/iso.c,v $ 
 /*
  * $Header: iso.c,v 4.11 88/09/19 14:58:35 root Exp $ 
  * $Source: /usr/argo/sys/netiso/RCS/iso.c,v $ 
- *     @(#)iso.c       7.8 (Berkeley) %G%
  *
  * iso.c: miscellaneous routines to support the iso address family
  */
 
  *
  * iso.c: miscellaneous routines to support the iso address family
  */
 
-#ifndef lint
-static char *rcsid = "$Header: iso.c,v 4.11 88/09/19 14:58:35 root Exp $";
-#endif
-
-
 #include "types.h"
 #include "param.h"
 #include "ioctl.h"
 #include "types.h"
 #include "param.h"
 #include "ioctl.h"
@@ -45,7 +74,6 @@ static char *rcsid = "$Header: iso.c,v 4.11 88/09/19 14:58:35 root Exp $";
 #include "protosw.h"
 #include "socket.h"
 #include "socketvar.h"
 #include "protosw.h"
 #include "socket.h"
 #include "socketvar.h"
-#include "user.h"
 #include "errno.h"
 
 #include "../net/if.h"
 #include "errno.h"
 
 #include "../net/if.h"
@@ -60,10 +88,10 @@ static char *rcsid = "$Header: iso.c,v 4.11 88/09/19 14:58:35 root Exp $";
 #include "argo_debug.h"
 
 #ifdef ISO
 #include "argo_debug.h"
 
 #ifdef ISO
-#include "argoxtwentyfive.h"
 
 int    iso_interfaces = 0;             /* number of external interfaces */
 extern struct ifnet loif;      /* loopback interface */
 
 int    iso_interfaces = 0;             /* number of external interfaces */
 extern struct ifnet loif;      /* loopback interface */
+int ether_output(), llc_rtrequest();
 
 
 /*
 
 
 /*
@@ -73,22 +101,19 @@ extern     struct ifnet loif;      /* loopback interface */
  *
  * RETURNS:                    nothing
  *
  *
  * RETURNS:                    nothing
  *
- * SIDE EFFECTS:       1) zeros the maptab table.
- *                                     2) initializes the routing table.
+ * SIDE EFFECTS:       1) initializes the routing table.
+ *
  *
  * NOTES:                      
  */
 struct radix_node_head *iso_rnhead;
 iso_init()
 {
  *
  * NOTES:                      
  */
 struct radix_node_head *iso_rnhead;
 iso_init()
 {
-       extern struct spna_cache        iso_snpac[];
-       extern u_int                            iso_snpac_size;
        static iso_init_done;
 
        if (iso_init_done == 0) {
                iso_init_done++;
        static iso_init_done;
 
        if (iso_init_done == 0) {
                iso_init_done++;
-               bzero((caddr_t)iso_snpac, iso_snpac_size * sizeof(struct snpa_cache));
-               rn_inithead(&iso_rnhead, 40, AF_ISO);
+               rn_inithead(&iso_rnhead, 48, AF_ISO);
        }
 }
 
        }
 }
 
@@ -438,8 +463,8 @@ iso_control(so, cmd, data, ifp)
                            SAME_ISOADDR(&ia->ia_addr, &ifra->ifra_addr))
                                break;
                }
                            SAME_ISOADDR(&ia->ia_addr, &ifra->ifra_addr))
                                break;
                }
-               if (error = suser(u.u_cred, &u.u_acflag))
-                       return (error);
+               if ((so->so_state & SS_PRIV) == 0)
+                       return (EPERM);
                if (ifp == 0)
                        panic("iso_control");
                if (ia == (struct iso_ifaddr *)0) {
                if (ifp == 0)
                        panic("iso_control");
                if (ia == (struct iso_ifaddr *)0) {
@@ -478,7 +503,7 @@ iso_control(so, cmd, data, ifp)
 #define cmdbyte(x)     (((x) >> 8) & 0xff)
        default:
                if (cmdbyte(cmd) == 'a')
 #define cmdbyte(x)     (((x) >> 8) & 0xff)
        default:
                if (cmdbyte(cmd) == 'a')
-                       return (snpac_ioctl(cmd, data));
+                       return (snpac_ioctl(so, cmd, data));
                if (ia == (struct iso_ifaddr *)0)
                        return (EADDRNOTAVAIL);
                break;
                if (ia == (struct iso_ifaddr *)0)
                        return (EADDRNOTAVAIL);
                break;
@@ -500,7 +525,7 @@ iso_control(so, cmd, data, ifp)
                break;
 
        case SIOCAIFADDR_ISO:
                break;
 
        case SIOCAIFADDR_ISO:
-               maskIsNew = 0; hostIsNew = 1; error = u.u_error;
+               maskIsNew = 0; hostIsNew = 1; error = 0;
                if (ia->ia_addr.siso_family == AF_ISO) {
                        if (ifra->ifra_addr.siso_len == 0) {
                                ifra->ifra_addr = ia->ia_addr;
                if (ia->ia_addr.siso_family == AF_ISO) {
                        if (ifra->ifra_addr.siso_len == 0) {
                                ifra->ifra_addr = ia->ia_addr;
@@ -570,8 +595,10 @@ iso_ifscrub(ifp, ia)
        register struct ifnet *ifp;
        register struct iso_ifaddr *ia;
 {
        register struct ifnet *ifp;
        register struct iso_ifaddr *ia;
 {
+       int nsellength = ia->ia_addr.siso_tlen;
        if ((ia->ia_flags & IFA_ROUTE) == 0)
                return;
        if ((ia->ia_flags & IFA_ROUTE) == 0)
                return;
+       ia->ia_addr.siso_tlen = 0;
        if (ifp->if_flags & IFF_LOOPBACK)
                rtinit(&(ia->ia_ifa), (int)RTM_DELETE, RTF_HOST);
        else if (ifp->if_flags & IFF_POINTOPOINT)
        if (ifp->if_flags & IFF_LOOPBACK)
                rtinit(&(ia->ia_ifa), (int)RTM_DELETE, RTF_HOST);
        else if (ifp->if_flags & IFF_POINTOPOINT)
@@ -579,6 +606,7 @@ iso_ifscrub(ifp, ia)
        else {
                rtinit(&(ia->ia_ifa), (int)RTM_DELETE, 0);
        }
        else {
                rtinit(&(ia->ia_ifa), (int)RTM_DELETE, 0);
        }
+       ia->ia_addr.siso_tlen = nsellength;
        ia->ia_flags &= ~IFA_ROUTE;
 }
 
        ia->ia_flags &= ~IFA_ROUTE;
 }
 
@@ -592,7 +620,7 @@ iso_ifinit(ifp, ia, siso, scrub)
        struct sockaddr_iso *siso;
 {
        struct sockaddr_iso oldaddr;
        struct sockaddr_iso *siso;
 {
        struct sockaddr_iso oldaddr;
-       int s = splimp(), error;
+       int s = splimp(), error, nsellength;
 
        oldaddr = ia->ia_addr;
        ia->ia_addr = *siso;
 
        oldaddr = ia->ia_addr;
        ia->ia_addr = *siso;
@@ -611,9 +639,18 @@ iso_ifinit(ifp, ia, siso, scrub)
                iso_ifscrub(ifp, ia);
                ia->ia_ifa.ifa_addr = (struct sockaddr *)&ia->ia_addr;
        }
                iso_ifscrub(ifp, ia);
                ia->ia_ifa.ifa_addr = (struct sockaddr *)&ia->ia_addr;
        }
+       /* XXX -- The following is here temporarily out of laziness
+          in not changing every ethernet driver's if_ioctl routine */
+       if (ifp->if_output == ether_output) {
+               ia->ia_ifa.ifa_rtrequest = llc_rtrequest;
+               ia->ia_ifa.ifa_flags |= RTF_CLONING;
+               ia->ia_ifa.ifa_llinfolen = sizeof(struct llinfo_llc);
+       }
        /*
         * Add route for the network.
         */
        /*
         * Add route for the network.
         */
+       nsellength = ia->ia_addr.siso_tlen;
+       ia->ia_addr.siso_tlen = 0;
        if (ifp->if_flags & IFF_LOOPBACK) {
                ia->ia_ifa.ifa_dstaddr = ia->ia_ifa.ifa_addr;
                error = rtinit(&(ia->ia_ifa), (int)RTM_ADD, RTF_HOST|RTF_UP);
        if (ifp->if_flags & IFF_LOOPBACK) {
                ia->ia_ifa.ifa_dstaddr = ia->ia_ifa.ifa_addr;
                error = rtinit(&(ia->ia_ifa), (int)RTM_ADD, RTF_HOST|RTF_UP);
@@ -623,8 +660,11 @@ iso_ifinit(ifp, ia, siso, scrub)
        else {
                rt_maskedcopy(ia->ia_ifa.ifa_addr, ia->ia_ifa.ifa_dstaddr,
                        ia->ia_ifa.ifa_netmask);
        else {
                rt_maskedcopy(ia->ia_ifa.ifa_addr, ia->ia_ifa.ifa_dstaddr,
                        ia->ia_ifa.ifa_netmask);
+               ia->ia_dstaddr.siso_nlen =
+                       min(ia->ia_addr.siso_nlen, (ia->ia_sockmask.siso_len - 6));
                error = rtinit(&(ia->ia_ifa), (int)RTM_ADD, RTF_UP);
        }
                error = rtinit(&(ia->ia_ifa), (int)RTM_ADD, RTF_UP);
        }
+       ia->ia_addr.siso_tlen = nsellength;
        ia->ia_flags |= IFA_ROUTE;
        splx(s);
        return (error);
        ia->ia_flags |= IFA_ROUTE;
        splx(s);
        return (error);
@@ -786,9 +826,9 @@ iso_localifa(siso)
        return ia_maybe;
 }
 
        return ia_maybe;
 }
 
-#ifdef NARGOXTWENTYFIVE > 0
+#ifdef TPCONS
 #include "cons.h"
 #include "cons.h"
-#endif NARGOXTWENTYFIVE > 0
+#endif TPCONS
 /*
  * FUNCTION:           iso_nlctloutput
  *
 /*
  * FUNCTION:           iso_nlctloutput
  *
@@ -830,7 +870,7 @@ struct mbuf *m;                     /* data for set, buffer for get */
 
        switch (optname) {
 
 
        switch (optname) {
 
-#ifdef NARGOXTWENTYFIVE > 0
+#ifdef TPCONS
                case CONSOPT_X25CRUD:
                        if (cmd == PRCO_GETOPT) {
                                error = EOPNOTSUPP;
                case CONSOPT_X25CRUD:
                        if (cmd == PRCO_GETOPT) {
                                error = EOPNOTSUPP;
@@ -849,7 +889,7 @@ struct mbuf *m;                     /* data for set, buffer for get */
                        bcopy(data, (caddr_t)isop->isop_x25crud, (unsigned)data_len);
                        isop->isop_x25crud_len = data_len;
                        break;
                        bcopy(data, (caddr_t)isop->isop_x25crud, (unsigned)data_len);
                        isop->isop_x25crud_len = data_len;
                        break;
-#endif NARGOXTWENTYFIVE > 0
+#endif TPCONS
 
                default:
                        error = EOPNOTSUPP;
 
                default:
                        error = EOPNOTSUPP;