BSD 4_3_Net_2 release
[unix-history] / usr / src / sys / netiso / iso_snpac.c
index 74d4e35..df5d75c 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_snpac.c 7.14 (Berkeley) 6/27/91
+ */
+
 /***********************************************************
                Copyright IBM Corporation 1987
 
 /***********************************************************
                Copyright IBM Corporation 1987
 
@@ -26,18 +61,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 +74,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 +90,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 +104,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};
@@ -134,6 +164,7 @@ struct sockaddr *sa;
        struct ifnet *ifp = rt->rt_ifp;
        int addrlen = ifp->if_addrlen;
        static struct rtentry *recursing = 0;
        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);
 
        IFDEBUG (D_SNPA)
                printf("llc_rtrequest(%d, %x, %x)\n", req, rt, sa);
@@ -148,6 +179,13 @@ struct sockaddr *sa;
                        recursing = rt;
                        rt->rt_llinfo = (caddr_t)rtalloc1(&gate->sa, 1);
                        recursing = 0;
                        recursing = rt;
                        rt->rt_llinfo = (caddr_t)rtalloc1(&gate->sa, 1);
                        recursing = 0;
+                       if (rt->rt_rmx.rmx_mtu == 0) {
+                               rt->rt_rmx.rmx_mtu =
+                                   ((rt2 = (struct rtentry *)rt->rt_llinfo) &&
+                                           (rt2->rt_rmx.rmx_mtu)) ?
+                                   rt2->rt_rmx.rmx_mtu :
+                                   rt->rt_ifp->if_mtu - LLC_SIZE;
+                       }
                        return;
 
                case RTM_DELETE:
                        return;
 
                case RTM_DELETE:
@@ -172,11 +210,11 @@ struct sockaddr *sa;
                                                Bcopy(sa, gate, gate->sa.sa_len);
                                                gate->sdl.sdl_alen = 0;
                                        }
                                                Bcopy(sa, gate, gate->sa.sa_len);
                                                gate->sdl.sdl_alen = 0;
                                        }
-                                       return;
+                                       break;
                                }
                        if (ifa == 0)
                                log(LOG_DEBUG, "llc_rtrequest: can't find LL ifaddr for iface\n");
                                }
                        if (ifa == 0)
                                log(LOG_DEBUG, "llc_rtrequest: can't find LL ifaddr for iface\n");
-                       return;
+                       break;
                }
                /* FALLTHROUGH */
        case RTM_RESOLVE:
                }
                /* FALLTHROUGH */
        case RTM_RESOLVE:
@@ -186,15 +224,15 @@ 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)
                }
                if (lc != 0)
-                       log(LOG_DEBUG, "llc_rtrequest: losing old rt_llinfo\n");
+                       return; /* happens on a route change */
                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 +254,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
@@ -405,14 +446,15 @@ int                                       nsellength;     /* nsaps may differ only in trailing bytes */
        }
        if ((lc = (struct llinfo_llc *)rt->rt_llinfo) == 0)
                panic("snpac_rtrequest");
        }
        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 +480,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 +496,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) {
@@ -541,17 +584,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;
                }
        }
 }
                }
        }
 }