upper level protocols now call when setting socket level options
[unix-history] / usr / src / sys / netiso / iso.c
index 4c56147..51e04c7 100644 (file)
@@ -1,3 +1,12 @@
+/*-
+ * Copyright (c) 1991 The Regents of the University of California.
+ * All rights reserved.
+ *
+ * %sccs.include.redist.c%
+ *
+ *     @(#)iso.c       7.16 (Berkeley) %G%
+ */
+
 /***********************************************************
                Copyright IBM Corporation 1987
 
 /***********************************************************
                Copyright IBM Corporation 1987
 
@@ -27,16 +36,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.5 (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 +48,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 +62,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 +75,15 @@ 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:                      
  */
  *
  * NOTES:                      
  */
-struct radix_node_head *iso_rnhead;
 iso_init()
 {
 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++;
-               bzero((caddr_t)iso_snpac, iso_snpac_size * sizeof(struct snpa_cache));
-               rn_inithead(&iso_rnhead, 40, AF_ISO);
+       if (rt_tables[AF_ISO] == 0) {
+               rn_inithead(rt_tables + AF_ISO, 48);
        }
 }
 
        }
 }
 
@@ -438,8 +433,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 +473,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 +495,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 +565,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 +576,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 +590,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,21 +609,35 @@ 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;
        if (ifp->if_flags & IFF_LOOPBACK) {
                ia->ia_ifa.ifa_dstaddr = ia->ia_ifa.ifa_addr;
-               rtinit(&(ia->ia_ifa), (int)RTM_ADD, RTF_HOST|RTF_UP);
+               error = rtinit(&(ia->ia_ifa), (int)RTM_ADD, RTF_HOST|RTF_UP);
        } else if (ifp->if_flags & IFF_POINTOPOINT &&
                 ia->ia_dstaddr.siso_family == AF_ISO)
        } else if (ifp->if_flags & IFF_POINTOPOINT &&
                 ia->ia_dstaddr.siso_family == AF_ISO)
-               rtinit(&(ia->ia_ifa), (int)RTM_ADD, RTF_HOST|RTF_UP);
+               error = rtinit(&(ia->ia_ifa), (int)RTM_ADD, RTF_HOST|RTF_UP);
        else {
        else {
-               rtinit(&(ia->ia_ifa), (int)RTM_ADD, RTF_UP);
+               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);
        }
        }
+       ia->ia_addr.siso_tlen = nsellength;
        ia->ia_flags |= IFA_ROUTE;
        splx(s);
        ia->ia_flags |= IFA_ROUTE;
        splx(s);
-       return (0);
+       return (error);
 }
 #ifdef notdef
 
 }
 #ifdef notdef
 
@@ -772,7 +784,7 @@ iso_localifa(siso)
                        cp1 = ia->ia_sockmask.siso_data;
                        cp2 = siso->siso_data;
                        cp3 = ia->ia_addr.siso_data;
                        cp1 = ia->ia_sockmask.siso_data;
                        cp2 = siso->siso_data;
                        cp3 = ia->ia_addr.siso_data;
-                       while (cp2 < cplim)
+                       while (cp1 < cplim)
                                if (*cp1++ & (*cp2++ ^ *cp3++))
                                        goto next;
                        ia_maybe = ia;
                                if (*cp1++ & (*cp2++ ^ *cp3++))
                                        goto next;
                        ia_maybe = ia;
@@ -784,9 +796,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
  *
@@ -828,7 +840,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;
@@ -847,58 +859,15 @@ 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;
        }
-
+       if (cmd == PRCO_SETOPT)
+               m_freem(m);
        return error;
 }
        return error;
 }
-
-/*
- * FUNCTION:           iso_routeifp
- *
- * PURPOSE:                    Route on a sockaddr and return ifp
- *
- * RETURNS:                    ifp of outgoing interface, or null
- *
- * SIDE EFFECTS:       
- *
- * NOTES:                      
- */
-struct iso_ifaddr *
-iso_routeifa(dst)
-struct sockaddr        *dst;           /* destination to route to */
-{
-       struct rtentry  *rt;
-       struct ifaddr *ifa = 0;
-       struct ifnet *ifp = 0;
-
-
-       IFDEBUG(D_ROUTE)
-               printf("iso_routeifp: dst:");
-               dump_isoaddr((struct sockaddr_iso *)dst);
-       ENDDEBUG
-
-       rt = rtalloc1(dst, 0);
-
-       if (rt) {
-               ifa = rt->rt_ifa;
-               ifp = rt->rt_ifp;
-               RTFREE(rt);
-       }
-
-       IFDEBUG(D_ROUTE)
-               printf("iso_routeifp: ifa x%x", ifa);
-               if (ifp)
-                       printf(" (%s%d)\n", ifp->if_name, ifp->if_unit);
-               else
-                       printf("\n");
-       ENDDEBUG
-
-       return((struct iso_ifaddr *)ifa);
-}
 #endif ISO
 
 #ifdef ARGO_DEBUG
 #endif ISO
 
 #ifdef ARGO_DEBUG