include file for per-architecture Makefiles
[unix-history] / usr / src / sys / netiso / iso_snpac.c
index 74d4e35..de12d2d 100644 (file)
@@ -1,3 +1,12 @@
+/*-
+ * Copyright (c) 1991 The Regents of the University of California.
+ * All rights reserved.
+ *
+ * %sccs.include.redist.c%
+ *
+ *     @(#)iso_snpac.c 7.16 (Berkeley) %G%
+ */
+
 /***********************************************************
                Copyright IBM Corporation 1987
 
 /***********************************************************
                Copyright IBM Corporation 1987
 
@@ -26,18 +35,12 @@ SOFTWARE.
  */
 /* $Header: iso_snpac.c,v 1.8 88/09/19 13:51:36 hagens Exp $ */
 /* $Source: /usr/argo/sys/netiso/RCS/iso_snpac.c,v $ */
  */
 /* $Header: iso_snpac.c,v 1.8 88/09/19 13:51:36 hagens Exp $ */
 /* $Source: /usr/argo/sys/netiso/RCS/iso_snpac.c,v $ */
-/*     @(#)iso_snpac.c 7.11 (Berkeley) %G% */
-
-#ifndef lint
-static char *rcsid = "$Header: iso_snpac.c,v 1.8 88/09/19 13:51:36 hagens Exp $";
-#endif lint
 
 #ifdef ISO
 
 #include "types.h"
 #include "param.h"
 #include "systm.h"
 
 #ifdef ISO
 
 #include "types.h"
 #include "param.h"
 #include "systm.h"
-#include "user.h"
 #include "mbuf.h"
 #include "domain.h"
 #include "protosw.h"
 #include "mbuf.h"
 #include "domain.h"
 #include "protosw.h"
@@ -45,7 +48,6 @@ static char *rcsid = "$Header: iso_snpac.c,v 1.8 88/09/19 13:51:36 hagens Exp $"
 #include "socketvar.h"
 #include "errno.h"
 #include "ioctl.h"
 #include "socketvar.h"
 #include "errno.h"
 #include "ioctl.h"
-#include "kernel.h"
 #include "syslog.h"
 
 #include "../net/if.h"
 #include "syslog.h"
 
 #include "../net/if.h"
@@ -62,7 +64,9 @@ static char *rcsid = "$Header: iso_snpac.c,v 1.8 88/09/19 13:51:36 hagens Exp $"
 
 int                            iso_systype = SNPA_ES;  /* default to be an ES */
 extern short   esis_holding_time, esis_config_time, esis_esconfig_time;
 
 int                            iso_systype = SNPA_ES;  /* default to be an ES */
 extern short   esis_holding_time, esis_config_time, esis_esconfig_time;
-extern int esis_config();
+extern struct  timeval time;
+extern int esis_config(), hz;
+static void snpac_fixdstandmask();
 
 struct sockaddr_iso blank_siso = {sizeof(blank_siso), AF_ISO};
 extern u_long iso_hashchar();
 
 struct sockaddr_iso blank_siso = {sizeof(blank_siso), AF_ISO};
 extern u_long iso_hashchar();
@@ -74,8 +78,8 @@ static struct sockaddr_iso
        zmk = {1};
 #define zsi blank_siso
 #define zero_isoa      zsi.siso_addr
        zmk = {1};
 #define zsi blank_siso
 #define zero_isoa      zsi.siso_addr
-#define zap_isoaddr(a, b) (bzero((caddr_t)&a.siso_addr, sizeof(*r)), \
-          ((r = b) && bcopy((caddr_t)r, (caddr_t)&a.siso_addr, 1 + (r)->isoa_len)))
+#define zap_isoaddr(a, b) {Bzero(&a.siso_addr, sizeof(*r)); r = b; \
+          Bcopy(r, &a.siso_addr, 1 + (r)->isoa_len);}
 #define S(x) ((struct sockaddr *)&(x))
 
 static struct sockaddr_dl blank_dl = {sizeof(blank_dl), AF_LINK};
 #define S(x) ((struct sockaddr *)&(x))
 
 static struct sockaddr_dl blank_dl = {sizeof(blank_dl), AF_LINK};
@@ -133,51 +137,25 @@ struct sockaddr *sa;
        struct rtentry *rt2;
        struct ifnet *ifp = rt->rt_ifp;
        int addrlen = ifp->if_addrlen;
        struct rtentry *rt2;
        struct ifnet *ifp = rt->rt_ifp;
        int addrlen = ifp->if_addrlen;
-       static struct rtentry *recursing = 0;
+#define LLC_SIZE 3 /* XXXXXX do this right later */
 
        IFDEBUG (D_SNPA)
                printf("llc_rtrequest(%d, %x, %x)\n", req, rt, sa);
        ENDDEBUG
 
        IFDEBUG (D_SNPA)
                printf("llc_rtrequest(%d, %x, %x)\n", req, rt, sa);
        ENDDEBUG
-       if (rt->rt_flags & RTF_GATEWAY) {
-               if (recursing) {
-                       log(LOG_DEBUG, "llc_rtrequest: gateway route points to same type %x %x\n",
-                               recursing, rt);
-               } else switch (req) {
-               case RTM_RESOLVE:
-               case RTM_ADD:
-                       recursing = rt;
-                       rt->rt_llinfo = (caddr_t)rtalloc1(&gate->sa, 1);
-                       recursing = 0;
-                       return;
-
-               case RTM_DELETE:
-                       if (lc)
-                               RTFREE((struct rtentry *)lc);
-                       rt->rt_llinfo = 0;
-               }
-       } else switch (req) {
+       if (rt->rt_flags & RTF_GATEWAY)
+               return;
+       else switch (req) {
        case RTM_ADD:
                /*
                 * Case 1: This route may come from a route to iface with mask
                 * or from a default route.
                 */
                if (rt->rt_flags & RTF_CLONING) {
        case RTM_ADD:
                /*
                 * Case 1: This route may come from a route to iface with mask
                 * or from a default route.
                 */
                if (rt->rt_flags & RTF_CLONING) {
-                       register struct ifaddr *ifa;
-                       register struct sockaddr *sa;
-                       for (ifa = ifp->if_addrlist; ifa; ifa->ifa_next)
-                               if ((sa = ifa->ifa_addr)->sa_family == AF_LINK) {
-                                       if (sa->sa_len > gate->sa.sa_len)
-                                               log(LOG_DEBUG, "llc_rtrequest: cloning address too small\n");
-                                       else {
-                                               Bcopy(sa, gate, gate->sa.sa_len);
-                                               gate->sdl.sdl_alen = 0;
-                                       }
-                                       return;
-                               }
-                       if (ifa == 0)
-                               log(LOG_DEBUG, "llc_rtrequest: can't find LL ifaddr for iface\n");
+                       rt_setgate(rt, rt_key(rt), &blank_dl);
                        return;
                }
                        return;
                }
+               if (lc != 0)
+                       return; /* happens on a route change */
                /* FALLTHROUGH */
        case RTM_RESOLVE:
                /*
                /* FALLTHROUGH */
        case RTM_RESOLVE:
                /*
@@ -186,15 +164,13 @@ struct sockaddr *sa;
                 */
                if (gate->sdl.sdl_family != AF_LINK) {
                        log(LOG_DEBUG, "llc_rtrequest: got non-link non-gateway route\n");
                 */
                if (gate->sdl.sdl_family != AF_LINK) {
                        log(LOG_DEBUG, "llc_rtrequest: got non-link non-gateway route\n");
-                       return;
+                       break;
                }
                }
-               if (lc != 0)
-                       log(LOG_DEBUG, "llc_rtrequest: losing old rt_llinfo\n");
                R_Malloc(lc, struct llinfo_llc *, sizeof (*lc));
                rt->rt_llinfo = (caddr_t)lc;
                if (lc == 0) {
                        log(LOG_DEBUG, "llc_rtrequest: malloc failed\n");
                R_Malloc(lc, struct llinfo_llc *, sizeof (*lc));
                rt->rt_llinfo = (caddr_t)lc;
                if (lc == 0) {
                        log(LOG_DEBUG, "llc_rtrequest: malloc failed\n");
-                       return;
+                       break;
                }
                Bzero(lc, sizeof(*lc));
                lc->lc_rt = rt;
                }
                Bzero(lc, sizeof(*lc));
                lc->lc_rt = rt;
@@ -216,6 +192,9 @@ struct sockaddr *sa;
                rt->rt_flags &= ~RTF_LLINFO;
                break;
        }
                rt->rt_flags &= ~RTF_LLINFO;
                break;
        }
+       if (rt->rt_rmx.rmx_mtu == 0) {
+                       rt->rt_rmx.rmx_mtu = rt->rt_ifp->if_mtu - LLC_SIZE;
+       }
 }
 /*
  * FUNCTION:           iso_snparesolve
 }
 /*
  * FUNCTION:           iso_snparesolve
@@ -344,7 +323,7 @@ int                                 nsellength;     /* nsaps may differ only in trailing bytes */
        struct  rtentry *mrt = 0;
        register struct iso_addr *r; /* for zap_isoaddr macro */
        int             snpalen = min(ifp->if_addrlen, MAX_SNPALEN);
        struct  rtentry *mrt = 0;
        register struct iso_addr *r; /* for zap_isoaddr macro */
        int             snpalen = min(ifp->if_addrlen, MAX_SNPALEN);
-       int             new_entry = 0, index = ifp->if_index;
+       int             new_entry = 0, index = ifp->if_index, if_type = ifp->if_type;
 
        IFDEBUG(D_SNPA)
                printf("snpac_add(%x, %x, %x, %x, %x, %x)\n",
 
        IFDEBUG(D_SNPA)
                printf("snpac_add(%x, %x, %x, %x, %x, %x)\n",
@@ -367,6 +346,7 @@ int                                 nsellength;     /* nsaps may differ only in trailing bytes */
                }
                new_entry = 1;
                zap_linkaddr((&gte_dl), snpa, snpalen, index);
                }
                new_entry = 1;
                zap_linkaddr((&gte_dl), snpa, snpalen, index);
+               gte_dl.sdl_type = if_type;
                if (rtrequest(RTM_ADD, S(dst), S(gte_dl), netmask, flags, &mrt) ||
                        mrt == 0)
                        return (0);
                if (rtrequest(RTM_ADD, S(dst), S(gte_dl), netmask, flags, &mrt) ||
                        mrt == 0)
                        return (0);
@@ -400,19 +380,21 @@ int                                       nsellength;     /* nsaps may differ only in trailing bytes */
                        }
                        zap_linkaddr(sdl, snpa, snpalen, index);
                        sdl->sdl_len = old_sdl_len;
                        }
                        zap_linkaddr(sdl, snpa, snpalen, index);
                        sdl->sdl_len = old_sdl_len;
+                       sdl->sdl_type = if_type;
                        new_entry = 1;
                }
        }
        if ((lc = (struct llinfo_llc *)rt->rt_llinfo) == 0)
                panic("snpac_rtrequest");
                        new_entry = 1;
                }
        }
        if ((lc = (struct llinfo_llc *)rt->rt_llinfo) == 0)
                panic("snpac_rtrequest");
-       rt->rt_idle = ht;
+       rt->rt_rmx.rmx_expire = ht + time.tv_sec;
        lc->lc_flags = SNPA_VALID | type;
        if (type & SNPA_IS)
                snpac_logdefis(rt);
        return (new_entry);
 }
 
        lc->lc_flags = SNPA_VALID | type;
        if (type & SNPA_IS)
                snpac_logdefis(rt);
        return (new_entry);
 }
 
-static snpac_fixdstandmask(nsellength)
+static void
+snpac_fixdstandmask(nsellength)
 {
        register char *cp = msk.siso_data, *cplim;
 
 {
        register char *cp = msk.siso_data, *cplim;
 
@@ -438,7 +420,8 @@ static snpac_fixdstandmask(nsellength)
  *
  * NOTES:                      
  */
  *
  * NOTES:                      
  */
-snpac_ioctl (cmd, data)
+snpac_ioctl (so, cmd, data)
+struct socket *so;
 int            cmd;    /* ioctl to process */
 caddr_t        data;   /* data for the cmd */
 {
 int            cmd;    /* ioctl to process */
 caddr_t        data;   /* data for the cmd */
 {
@@ -453,8 +436,8 @@ caddr_t     data;   /* data for the cmd */
        ENDDEBUG
 
        if (cmd == SIOCSSTYPE) {
        ENDDEBUG
 
        if (cmd == SIOCSSTYPE) {
-               if (suser(u.u_cred, &u.u_acflag))
-                       return(EACCES);
+               if ((so->so_state & SS_PRIV) == 0)
+                       return (EPERM);
                if ((rq->sr_type & (SNPA_ES|SNPA_IS)) == (SNPA_ES|SNPA_IS))
                        return(EINVAL);
                if (rq->sr_type & SNPA_ES) {
                if ((rq->sr_type & (SNPA_ES|SNPA_IS)) == (SNPA_ES|SNPA_IS))
                        return(EINVAL);
                if (rq->sr_type & SNPA_ES) {
@@ -501,6 +484,7 @@ register struct rtentry *sc;
        register struct rtentry *rt = rtalloc1((struct sockaddr *)&zsi, 0);
 
        zap_linkaddr((&gte_dl), LLADDR(sdl), sdl->sdl_alen, sdl->sdl_index);
        register struct rtentry *rt = rtalloc1((struct sockaddr *)&zsi, 0);
 
        zap_linkaddr((&gte_dl), LLADDR(sdl), sdl->sdl_alen, sdl->sdl_index);
+       gte_dl.sdl_type = sc->rt_ifp->if_type;
        if (known_is == 0)
                known_is = sc;
        if (known_is != sc) {
        if (known_is == 0)
                known_is = sc;
        if (known_is != sc) {
@@ -541,17 +525,19 @@ register struct rtentry *sc;
  */
 snpac_age()
 {
  */
 snpac_age()
 {
-       register struct llinfo_llc      *lc;
+       register struct llinfo_llc *lc, *nlc;
+       register struct rtentry *rt;
 
        timeout(snpac_age, (caddr_t)0, SNPAC_AGE * hz);
 
 
        timeout(snpac_age, (caddr_t)0, SNPAC_AGE * hz);
 
-       for (lc = llinfo_llc.lc_next; lc != & llinfo_llc; lc = lc->lc_next) {
+       for (lc = llinfo_llc.lc_next; lc != & llinfo_llc; lc = nlc) {
+               nlc = lc->lc_next;
                if (((lc->lc_flags & SNPA_PERM) == 0) && (lc->lc_flags & SNPA_VALID)) {
                if (((lc->lc_flags & SNPA_PERM) == 0) && (lc->lc_flags & SNPA_VALID)) {
-                       lc->lc_rt->rt_idle -= SNPAC_AGE;
-                       if (lc->lc_rt->rt_idle > 0)
-                               continue;
-                       else
+                       rt = lc->lc_rt;
+                       if (rt->rt_rmx.rmx_expire && rt->rt_rmx.rmx_expire < time.tv_sec)
                                snpac_free(lc);
                                snpac_free(lc);
+                       else
+                               continue;
                }
        }
 }
                }
        }
 }