trailing comment after #else or #endif
[unix-history] / usr / src / sys / netiso / esis.c
index 16727c2..ba27d3a 100644 (file)
@@ -1,3 +1,12 @@
+/*-
+ * Copyright (c) 1991 The Regents of the University of California.
+ * All rights reserved.
+ *
+ * %sccs.include.redist.c%
+ *
+ *     @(#)esis.c      7.23 (Berkeley) %G%
+ */
+
 /***********************************************************
                Copyright IBM Corporation 1987
 
 /***********************************************************
                Copyright IBM Corporation 1987
 
@@ -24,39 +33,33 @@ SOFTWARE.
 /*
  * ARGO Project, Computer Sciences Dept., University of Wisconsin - Madison
  */
 /*
  * ARGO Project, Computer Sciences Dept., University of Wisconsin - Madison
  */
-/*     @(#)esis.c      7.12 (Berkeley) %G% */
-#ifndef lint
-static char *rcsid = "$Header: esis.c,v 4.10 88/09/15 18:57:03 hagens Exp $";
-#endif
 
 #ifdef ISO
 
 
 #ifdef ISO
 
-#include "types.h"
-#include "param.h"
-#include "systm.h"
-#include "mbuf.h"
-#include "domain.h"
-#include "protosw.h"
-#include "user.h"
-#include "socket.h"
-#include "socketvar.h"
-#include "errno.h"
-#include "kernel.h"
-
-#include "../net/if.h"
-#include "../net/if_dl.h"
-#include "../net/route.h"
-#include "../net/raw_cb.h"
-
-#include "iso.h"
-#include "iso_pcb.h"
-#include "iso_var.h"
-#include "iso_snpac.h"
-#include "clnl.h"
-#include "clnp.h"
-#include "clnp_stat.h"
-#include "esis.h"
-#include "argo_debug.h"
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/mbuf.h>
+#include <sys/domain.h>
+#include <sys/protosw.h>
+#include <sys/socket.h>
+#include <sys/socketvar.h>
+#include <sys/errno.h>
+#include <sys/kernel.h>
+
+#include <net/if.h>
+#include <net/if_dl.h>
+#include <net/route.h>
+#include <net/raw_cb.h>
+
+#include <netiso/iso.h>
+#include <netiso/iso_pcb.h>
+#include <netiso/iso_var.h>
+#include <netiso/iso_snpac.h>
+#include <netiso/clnl.h>
+#include <netiso/clnp.h>
+#include <netiso/clnp_stat.h>
+#include <netiso/esis.h>
+#include <netiso/argo_debug.h>
 
 /*
  *     Global variables to esis implementation
 
 /*
  *     Global variables to esis implementation
@@ -68,6 +71,7 @@ static char *rcsid = "$Header: esis.c,v 4.10 88/09/15 18:57:03 hagens Exp $";
  *
  */
 struct rawcb   esis_pcb;
  *
  */
 struct rawcb   esis_pcb;
+void                           esis_config(), snpac_age();
 int                            esis_sendspace = 2048;
 int                            esis_recvspace = 2048;
 short                  esis_holding_time = ESIS_HT;
 int                            esis_sendspace = 2048;
 int                            esis_recvspace = 2048;
 short                  esis_holding_time = ESIS_HT;
@@ -101,7 +105,6 @@ esis_init()
 {
        extern struct clnl_protosw clnl_protox[256];
        int     esis_input(), isis_input();
 {
        extern struct clnl_protosw clnl_protox[256];
        int     esis_input(), isis_input();
-       int     esis_config(), snpac_age();
 #ifdef ISO_X25ESIS
        int     x25esis_input();
 #endif ISO_X25ESIS
 #ifdef ISO_X25ESIS
        int     x25esis_input();
 #endif ISO_X25ESIS
@@ -140,7 +143,7 @@ struct mbuf         *control;       /* optional control */
        struct rawcb *rp = sotorawcb(so);
        int error = 0;
 
        struct rawcb *rp = sotorawcb(so);
        int error = 0;
 
-       if (suser(u.u_cred, &u.u_acflag)) {
+       if ((so->so_state & SS_PRIV) == 0) {
                error = EACCES;
                goto release;
        }
                error = EACCES;
                goto release;
        }
@@ -159,6 +162,7 @@ struct mbuf         *control;       /* optional control */
                if (so->so_pcb = (caddr_t)rp) {
                        bzero(so->so_pcb, sizeof(*rp));
                        insque(rp, &esis_pcb);
                if (so->so_pcb = (caddr_t)rp) {
                        bzero(so->so_pcb, sizeof(*rp));
                        insque(rp, &esis_pcb);
+                       rp->rcb_socket = so;
                        error = soreserve(so, esis_sendspace, esis_recvspace);
                } else
                        error = ENOBUFS;
                        error = soreserve(so, esis_sendspace, esis_recvspace);
                } else
                        error = ENOBUFS;
@@ -412,7 +416,7 @@ struct rtentry              *rt;                    /* snpa cache info regarding next hop of
        siso.siso_nlen = 6 + 1; /* should be taken from snpa_hdr */
                                                                                /* +1 is for AFI */
        bcopy(inbound_shp->snh_shost, siso.siso_data + 1, 6);
        siso.siso_nlen = 6 + 1; /* should be taken from snpa_hdr */
                                                                                /* +1 is for AFI */
        bcopy(inbound_shp->snh_shost, siso.siso_data + 1, 6);
-       (ifp->if_output)(ifp, m0, &siso, 0);
+       (ifp->if_output)(ifp, m0, (struct sockaddr *)&siso, 0);
 }
 
 /*
 }
 
 /*
@@ -575,6 +579,8 @@ struct snpa_hdr     *shp;   /* subnetwork header */
        while (buf < buflim) {
                switch (*buf) {
                case ESISOVAL_ESCT:
        while (buf < buflim) {
                switch (*buf) {
                case ESISOVAL_ESCT:
+                       if (iso_systype & SNPA_IS)
+                               break;
                        if (buf[1] != 2)
                                goto bad;
                        CTOH(buf[2], buf[3], newct);
                        if (buf[1] != 2)
                                goto bad;
                        CTOH(buf[2], buf[3], newct);
@@ -710,6 +716,7 @@ bad: ;    /* Needed by ESIS_NEXT_OPTION */
  *
  * NOTES:                      Called every esis_config_time seconds
  */
  *
  * NOTES:                      Called every esis_config_time seconds
  */
+void
 esis_config()
 {
        register struct ifnet   *ifp;
 esis_config()
 {
        register struct ifnet   *ifp;
@@ -719,13 +726,18 @@ esis_config()
        /* 
         *      Report configuration for each interface that 
         *      - is UP
        /* 
         *      Report configuration for each interface that 
         *      - is UP
-        *      - is not loopback
+        *      - has BROADCAST capability
         *      - has an ISO address
         */
         *      - has an ISO address
         */
+       /* Todo: a better way would be to construct the esh or ish
+        * once and copy it out for all devices, possibly calling
+        * a method in the iso_ifaddr structure to encapsulate and
+        * transmit it.  This could work to advantage for non-broadcast media
+        */
        
        for (ifp = ifnet; ifp; ifp = ifp->if_next) {
                if ((ifp->if_flags & IFF_UP) &&
        
        for (ifp = ifnet; ifp; ifp = ifp->if_next) {
                if ((ifp->if_flags & IFF_UP) &&
-                       ((ifp->if_flags & IFF_LOOPBACK) == 0)) {
+                   (ifp->if_flags & IFF_BROADCAST)) {
                        /* search for an ISO address family */
                        struct ifaddr   *ia;
 
                        /* search for an ISO address family */
                        struct ifaddr   *ia;
 
@@ -856,6 +868,22 @@ struct     iso_addr *isoa;
 
        if (type == ESIS_ESH)
                *naddrp = naddr;
 
        if (type == ESIS_ESH)
                *naddrp = naddr;
+       else {
+               /* add suggested es config timer option to ISH */
+               if (M_TRAILINGSPACE(m) < 4) {
+                       printf("esis_shoutput: extending packet\n");
+                       EXTEND_PACKET(m, m0, cp);
+               }
+               *cp++ = ESISOVAL_ESCT;
+               *cp++ = 2;
+               HTOC(*cp, *(cp+1), esis_esconfig_time);
+               len += 4;
+               m->m_len += 4;
+               IFDEBUG(D_ESISOUTPUT)
+                       printf("m0 0x%x, m 0x%x, data 0x%x, len %d, cp 0x%x\n",
+                       m0, m, m->m_data, m->m_len, cp);
+               ENDDEBUG
+       }
 
        m0->m_pkthdr.len = len;
        pdu->esis_hdr_len = len;
 
        m0->m_pkthdr.len = len;
        pdu->esis_hdr_len = len;
@@ -866,7 +894,7 @@ struct      iso_addr *isoa;
        siso.siso_data[0] = AFI_SNA;
        siso.siso_nlen = sn_len + 1;
        bcopy(sn_addr, siso.siso_data + 1, (unsigned)sn_len);
        siso.siso_data[0] = AFI_SNA;
        siso.siso_nlen = sn_len + 1;
        bcopy(sn_addr, siso.siso_data + 1, (unsigned)sn_len);
-       (ifp->if_output)(ifp, m0, &siso, 0);
+       (ifp->if_output)(ifp, m0, (struct sockaddr *)&siso, 0);
 }
 
 /*
 }
 
 /*
@@ -885,9 +913,8 @@ struct mbuf         *m0;            /* ptr to first mbuf of pkt */
 struct snpa_hdr        *shp;   /* subnetwork header */
 {
        register int type;
 struct snpa_hdr        *shp;   /* subnetwork header */
 {
        register int type;
-       struct rawcb *rp;
+       register struct rawcb *rp, *first_rp = 0;
        struct ifnet *ifp = shp->snh_ifp;
        struct ifnet *ifp = shp->snh_ifp;
-       struct sockbuf *sb = 0;
        char workbuf[16];
        struct mbuf *mm;
 
        char workbuf[16];
        struct mbuf *mm;
 
@@ -907,15 +934,15 @@ struct snpa_hdr   *shp;   /* subnetwork header */
        esis_dl.sdl_index = ifp->if_index;
        bcopy(shp->snh_shost, (caddr_t)esis_dl.sdl_data, esis_dl.sdl_alen);
        for (rp = esis_pcb.rcb_next; rp != &esis_pcb; rp = rp->rcb_next) {
        esis_dl.sdl_index = ifp->if_index;
        bcopy(shp->snh_shost, (caddr_t)esis_dl.sdl_data, esis_dl.sdl_alen);
        for (rp = esis_pcb.rcb_next; rp != &esis_pcb; rp = rp->rcb_next) {
-               if (sb == 0) {
-                       sb = &rp->rcb_socket->so_rcv;
+               if (first_rp == 0) {
+                       first_rp = rp;
                        continue;
                }
                if (mm = m_copy(m0, 0, M_COPYALL)) { /*can't block at interrupt level */
                        if (sbappendaddr(&rp->rcb_socket->so_rcv,
                        continue;
                }
                if (mm = m_copy(m0, 0, M_COPYALL)) { /*can't block at interrupt level */
                        if (sbappendaddr(&rp->rcb_socket->so_rcv,
-                                                         &esis_dl, mm, (struct mbuf *)0) != 0)
+                                                         &esis_dl, mm, (struct mbuf *)0) != 0) {
                                sorwakeup(rp->rcb_socket);
                                sorwakeup(rp->rcb_socket);
-                       else {
+                        } else {
                                IFDEBUG(D_ISISINPUT)
                                        printf("Error in sbappenaddr, mm = 0x%x\n", mm);
                                ENDDEBUG
                                IFDEBUG(D_ISISINPUT)
                                        printf("Error in sbappenaddr, mm = 0x%x\n", mm);
                                ENDDEBUG
@@ -923,13 +950,12 @@ struct snpa_hdr   *shp;   /* subnetwork header */
                        }
                }
        }
                        }
                }
        }
-       if (sb) {
-               if (sbappendaddr(&rp->rcb_socket->so_rcv,
-                                                         &esis_dl, mm, (struct mbuf *)0) != 0)
-                       sorwakeup(rp->rcb_socket);
-               else
-                       m_freem(m0);
+       if (first_rp && sbappendaddr(&first_rp->rcb_socket->so_rcv,
+                                                         &esis_dl, m0, (struct mbuf *)0) != 0) {
+               sorwakeup(first_rp->rcb_socket);
+               return;
        }
        }
+       m_freem(m0);
 }
 
 isis_output(sdl, m)
 }
 
 isis_output(sdl, m)
@@ -942,7 +968,7 @@ struct mbuf *m;
        int error = 0;
        unsigned sn_len;
 
        int error = 0;
        unsigned sn_len;
 
-       ifa = ifa_ifwithnet(sdl);       /* extract ifp from sockaddr_dl */
+       ifa = ifa_ifwithnet((struct sockaddr *)sdl);    /* get ifp from sdl */
        if (ifa == 0) {
                IFDEBUG(D_ISISOUTPUT)
                        printf("isis_output: interface not found\n");
        if (ifa == 0) {
                IFDEBUG(D_ISISOUTPUT)
                        printf("isis_output: interface not found\n");
@@ -951,7 +977,7 @@ struct mbuf *m;
                goto release;
        }
        ifp = ifa->ifa_ifp;
                goto release;
        }
        ifp = ifa->ifa_ifp;
-       sn_len = ifp->if_addrlen;
+       sn_len = sdl->sdl_alen;
        IFDEBUG(D_ISISOUTPUT)
                u_char *cp = (u_char *)LLADDR(sdl), *cplim = cp + sn_len;
                printf("isis_output: ifp 0x%x (%s%d), to: ",
        IFDEBUG(D_ISISOUTPUT)
                u_char *cp = (u_char *)LLADDR(sdl), *cplim = cp + sn_len;
                printf("isis_output: ifp 0x%x (%s%d), to: ",