status as of 4.3 alpha tape
authorKeith Sklower <sklower@ucbvax.Berkeley.EDU>
Sat, 17 Aug 1985 11:44:23 +0000 (03:44 -0800)
committerKeith Sklower <sklower@ucbvax.Berkeley.EDU>
Sat, 17 Aug 1985 11:44:23 +0000 (03:44 -0800)
SCCS-vsn: sbin/XNSrouted/Makefile 5.2
SCCS-vsn: sbin/XNSrouted/af.c 5.2
SCCS-vsn: sbin/XNSrouted/defs.h 5.2
SCCS-vsn: sbin/XNSrouted/input.c 5.2
SCCS-vsn: sbin/XNSrouted/interface.h 5.2
SCCS-vsn: sbin/XNSrouted/main.c 5.2
SCCS-vsn: sbin/XNSrouted/output.c 5.2
SCCS-vsn: sbin/XNSrouted/protocol.h 5.2
SCCS-vsn: sbin/XNSrouted/startup.c 5.2
SCCS-vsn: sbin/XNSrouted/tables.c 5.2
SCCS-vsn: sbin/XNSrouted/timer.c 5.2
SCCS-vsn: sbin/XNSrouted/trace.c 5.2
SCCS-vsn: sbin/XNSrouted/trace.h 5.2

usr/src/sbin/XNSrouted/Makefile
usr/src/sbin/XNSrouted/af.c
usr/src/sbin/XNSrouted/defs.h
usr/src/sbin/XNSrouted/input.c
usr/src/sbin/XNSrouted/interface.h
usr/src/sbin/XNSrouted/main.c
usr/src/sbin/XNSrouted/output.c
usr/src/sbin/XNSrouted/startup.c
usr/src/sbin/XNSrouted/tables.c
usr/src/sbin/XNSrouted/timer.c
usr/src/sbin/XNSrouted/trace.c

index 5187f58..f191131 100644 (file)
@@ -1,7 +1,7 @@
 #      Makefile for Xerox Routing Information Protocol
 #      Daemon
 #
 #      Makefile for Xerox Routing Information Protocol
 #      Daemon
 #
-ALL=   xnsrouted
+ALL=   XNSrouted
 OBJS=  af.o if.o input.o main.o output.o startup.o tables.o timer.o \
        trace.o
 CFLAGS= -g
 OBJS=  af.o if.o input.o main.o output.o startup.o tables.o timer.o \
        trace.o
 CFLAGS= -g
@@ -12,11 +12,11 @@ LDFLAGS= -g
 
 all:   ${ALL}
 
 
 all:   ${ALL}
 
-xnsrouted: ${OBJS}
-       ${CC} -o xnsrouted ${LDFLAGS} ${OBJS}
+XNSrouted: ${OBJS}
+       ${CC} -o XNSrouted ${LDFLAGS} ${OBJS}
 
 
-install: xnsrouted
-       install -s xnsrouted ${DESTDIR}/etc
+install: XNSrouted
+       install -s XNSrouted ${DESTDIR}/etc
 
 # The following can be deleted where not appropriate to use the kernel's
 # inline code expansions.
 
 # The following can be deleted where not appropriate to use the kernel's
 # inline code expansions.
@@ -26,4 +26,4 @@ install: xnsrouted
 #      rm -f $*.s
 
 clean:
 #      rm -f $*.s
 
 clean:
-       rm -f xnsrouted *.o core a.out t.c linterrs typescript errs
+       rm -f XNSrouted *.o core a.out t.c linterrs typescript errs
index 38584a3..c4f7425 100644 (file)
@@ -25,31 +25,34 @@ int xnnet_hash(), xnnet_netmatch(), xnnet_output(),
 struct afswitch afswitch[AF_MAX] =
        { NIL, NIL, NIL, NIL, NIL, NIL, XNSNET, NIL, NIL, NIL, NIL };
 
 struct afswitch afswitch[AF_MAX] =
        { NIL, NIL, NIL, NIL, NIL, NIL, XNSNET, NIL, NIL, NIL, NIL };
 
-struct sockaddr_xn xnnet_default = { AF_XNS };
+struct sockaddr_ns xnnet_default = { AF_NS };
 
 
-xnnet_hash(sxn, hp)
-       register struct sockaddr_xn *sxn;
+xnnet_hash(sns, hp)
+       register struct sockaddr_ns *sns;
        struct afhash *hp;
 {
        struct afhash *hp;
 {
-       hp->afh_nethash = xnnet(sxn->sxn_addr.xn_net);
-       hp->afh_hosthash = *(int *)sxn->sxn_addr.xn_host;
+       register long hash = 0;
+       register u_short *s = sns->sns_addr.x_host.s_host;
+       hp->afh_nethash = xnnet(sns->sns_addr.x_net);
+       hash = *s++; hash <<= 8; hash += *s++; hash <<= 8; hash += *s;
+       hp->afh_hosthash = hash;
 }
 
 xnnet_netmatch(sxn1, sxn2)
 }
 
 xnnet_netmatch(sxn1, sxn2)
-       struct sockaddr_xn *sxn1, *sxn2;
+       struct sockaddr_ns *sxn1, *sxn2;
 {
 
 {
 
-       return (xnnet(sxn1->sxn_addr.xn_net) == xnnet(sxn2->sxn_addr.xn_net));
+       return (xnnet(sxn1->sns_addr.x_net) == xnnet(sxn2->sns_addr.x_net));
 }
 
 /*
  * Verify the message is from the right port.
  */
 }
 
 /*
  * Verify the message is from the right port.
  */
-xnnet_portmatch(sxn)
-       register struct sockaddr_xn *sxn;
+xnnet_portmatch(sns)
+       register struct sockaddr_ns *sns;
 {
        
 {
        
-       return (ntohs(sxn->sxn_addr.xn_socket) == IDPPORT_RIF );
+       return (ntohs(sns->sns_addr.x_port) == IDPPORT_RIF );
 }
 
 
 }
 
 
@@ -59,21 +62,21 @@ xnnet_portmatch(sxn)
 #ifdef DEBUG
 int do_output = 0;
 #endif
 #ifdef DEBUG
 int do_output = 0;
 #endif
-xnnet_output(s, flags, sxn, size)
-       int s, flags;
-       struct sockaddr_xn *sxn;
+xnnet_output(flags, sns, size)
+       int flags;
+       struct sockaddr_ns *sns;
        int size;
 {
        int size;
 {
-       struct sockaddr_xn dst;
+       struct sockaddr_ns dst;
 
 
-       dst = *sxn;
-       sxn = &dst;
-       if (sxn->sxn_addr.xn_socket == 0)
-               sxn->sxn_addr.xn_socket = htons(IDPPORT_RIF);
+       dst = *sns;
+       sns = &dst;
+       if (sns->sns_addr.x_port == 0)
+               sns->sns_addr.x_port = htons(IDPPORT_RIF);
 #ifdef DEBUG
        if(do_output || ntohs(msg->rip_cmd) == RIPCMD_REQUEST)
 #endif 
 #ifdef DEBUG
        if(do_output || ntohs(msg->rip_cmd) == RIPCMD_REQUEST)
 #endif 
-       if (sendto(s, msg, size, flags, sxn, sizeof (*sxn)) < 0)
+       if (sendto(s, msg, size, flags, sns, sizeof (*sns)) < 0)
                perror("sendto");
 }
 
                perror("sendto");
 }
 
@@ -81,8 +84,8 @@ xnnet_output(s, flags, sxn, size)
  * Return 1 if the address is believed
  *  -- THIS IS A KLUDGE.
  */
  * Return 1 if the address is believed
  *  -- THIS IS A KLUDGE.
  */
-xnnet_checkhost(sxn)
-       struct sockaddr_xn *sxn;
+xnnet_checkhost(sns)
+       struct sockaddr_ns *sns;
 {
        return (1);
 }
 {
        return (1);
 }
@@ -91,21 +94,22 @@ xnnet_checkhost(sxn)
  * Return 1 if the address is
  * for a host, 0 for a network.
  */
  * Return 1 if the address is
  * for a host, 0 for a network.
  */
-xnnet_ishost(sxn)
-       struct sockaddr_xn *sxn;
+xnnet_ishost(sns)
+struct sockaddr_ns *sns;
 {
 {
-       register int i;
+       register u_short *s = sns->sns_addr.x_host.s_host;
 
 
-       for (i = 0; i < 6; i++)
-               if (sxn->sxn_addr.xn_host[i] != 0) return (1);
-       return (0);
+       if ((s[0]==0xffff) && (s[1]==0xffff) && (s[2]==0xffff))
+               return (0);
+       else
+               return (1);
 }
 
 }
 
-xnnet_canon(sxn)
-       struct sockaddr_xn *sxn;
+xnnet_canon(sns)
+       struct sockaddr_ns *sns;
 {
 
 {
 
-       sxn->sxn_addr.xn_socket = 0;
+       sns->sns_addr.x_port = 0;
 }
 
 /*ARGSUSED*/
 }
 
 /*ARGSUSED*/
index 32a7cab..61b7e6b 100644 (file)
@@ -6,8 +6,10 @@
 #include <sys/socket.h>
 
 #include <net/route.h>
 #include <sys/socket.h>
 
 #include <net/route.h>
-#include <netxns/xn.h>
-#include <netxns/idp.h>
+#include <netns/ns.h>
+#include <netns/idp.h>
+#define xnnet(p) (*(long *)&(p))
+#define        IDPPORT_RIF     1
 
 #include <stdio.h>
 
 
 #include <stdio.h>
 
@@ -29,6 +31,8 @@
        (bcmp((caddr_t)(a1), (caddr_t)(a2), sizeof (struct sockaddr)) == 0)
 #define        min(a,b)        ((a)>(b)?(b):(a))
 
        (bcmp((caddr_t)(a1), (caddr_t)(a2), sizeof (struct sockaddr)) == 0)
 #define        min(a,b)        ((a)>(b)?(b):(a))
 
+struct sockaddr_ns addr;       /* Daemon's Address */
+int    s;                      /* Socket to listen on */
 int    kmem;
 int    supplier;               /* process should supply updates */
 int    install;                /* if 1 call kernel */
 int    kmem;
 int    supplier;               /* process should supply updates */
 int    install;                /* if 1 call kernel */
index d37ce34..b5cdf0c 100644 (file)
@@ -11,11 +11,13 @@ struct sockaddr *
 xns_nettosa(net)
 u_short *net;
 {
 xns_nettosa(net)
 u_short *net;
 {
-       static struct sockaddr_xn sxn;
+       static struct sockaddr_ns sxn;
+       extern char ether_broadcast_addr[6];
        
        
-       bzero(&sxn, sizeof (struct sockaddr_xn));
-       sxn.sxn_family = AF_XNS;
-       xnnet(sxn.sxn_addr.xn_net) = xnnet(net);
+       bzero(&sxn, sizeof (struct sockaddr_ns));
+       sxn.sns_family = AF_NS;
+       xnnet(sxn.sns_addr.x_net) = xnnet(net[0]);
+       sxn.sns_addr.x_host = *(union ns_host *)ether_broadcast_addr;
        return( (struct sockaddr *)&sxn);
        
 }
        return( (struct sockaddr *)&sxn);
        
 }
@@ -34,21 +36,12 @@ rip_input(from, size)
        struct afswitch *afp;
 
        
        struct afswitch *afp;
 
        
+       ifp = 0;
        TRACE_INPUT(ifp, from, size);
        if (from->sa_family >= AF_MAX)
                return;
        afp = &afswitch[from->sa_family];
        
        TRACE_INPUT(ifp, from, size);
        if (from->sa_family >= AF_MAX)
                return;
        afp = &afswitch[from->sa_family];
        
-       /* are we talking to ourselves? */
-       if (ifp = if_ifwithaddr(from)) {
-               rt = rtfind(from);
-               if (rt == 0 || (rt->rt_state & RTS_INTERFACE) == 0)
-                       addrouteforif(ifp);
-               else
-                       rt->rt_timer = 0;
-               return;
-       }
-       
        size -= sizeof (u_short)        /* command */;
        n = msg->rip_nets;
 
        size -= sizeof (u_short)        /* command */;
        n = msg->rip_nets;
 
@@ -67,10 +60,11 @@ rip_input(from, size)
                         * A single entry with rip_dst == DSTNETS_ALL and
                         * metric ``infinity'' means ``all routes''.
                         */
                         * A single entry with rip_dst == DSTNETS_ALL and
                         * metric ``infinity'' means ``all routes''.
                         */
-                       if (ntohl(xnnet(n->rip_dst)) == DSTNETS_ALL &&
-                           ntohs(n->rip_metric) == HOPCNT_INFINITY && size == 0) {
-                               if(ifp = if_ifwithnet(from))
-                                   supply(from, 0, ifp);
+                       if (ntohl(xnnet(n->rip_dst[0])) == DSTNETS_ALL &&
+                           ntohs(n->rip_metric) == HOPCNT_INFINITY &&
+                           size == 0) {
+                               ifp = if_ifwithnet(from);
+                               supply(from, 0, ifp);
                                return;
                        }
                        /*
                                return;
                        }
                        /*
@@ -86,7 +80,7 @@ rip_input(from, size)
                        newsize += sizeof (u_short);
                        /* should check for if with dstaddr(from) first */
                        if(ifp = if_ifwithnet(from))
                        newsize += sizeof (u_short);
                        /* should check for if with dstaddr(from) first */
                        if(ifp = if_ifwithnet(from))
-                           (*afp->af_output)(ifp->int_ripsock[0], 0, from, newsize);
+                           (*afp->af_output)(0, from, newsize);
                }
                return;
 
                }
                return;
 
@@ -94,6 +88,16 @@ rip_input(from, size)
                /* verify message came from a router */
                if ((*afp->af_portmatch)(from) == 0)
                        return;
                /* verify message came from a router */
                if ((*afp->af_portmatch)(from) == 0)
                        return;
+               (*afp->af_canon)(from);
+               /* are we talking to ourselves? */
+               if (ifp = if_ifwithaddr(from)) {
+                       rt = rtfind(from);
+                       if (rt == 0 || (rt->rt_state & RTS_INTERFACE) == 0)
+                               addrouteforif(ifp);
+                       else
+                               rt->rt_timer = 0;
+                       return;
+               }
                /* update timer for interface on which the packet arrived */
                if ((rt = rtfind(from)) && (rt->rt_state & RTS_INTERFACE))
                        rt->rt_timer = 0;
                /* update timer for interface on which the packet arrived */
                if ((rt = rtfind(from)) && (rt->rt_state & RTS_INTERFACE))
                        rt->rt_timer = 0;
@@ -102,7 +106,7 @@ rip_input(from, size)
                                break;
                        if ((unsigned) ntohs(n->rip_metric) > HOPCNT_INFINITY)
                                continue;
                                break;
                        if ((unsigned) ntohs(n->rip_metric) > HOPCNT_INFINITY)
                                continue;
-                       rt = rtlookup(xns_nettosa(n->rip_dst));
+                       rt = rtfind(xns_nettosa(n->rip_dst));
                        if (rt == 0) {
                                rtadd(xns_nettosa(n->rip_dst), from, ntohs(n->rip_metric), 0);
                                continue;
                        if (rt == 0) {
                                rtadd(xns_nettosa(n->rip_dst), from, ntohs(n->rip_metric), 0);
                                continue;
index 57e6e83..43f4848 100644 (file)
@@ -30,7 +30,6 @@ struct interface {
        int     int_opackets;                   /* output packets sent */
        char    *int_name;                      /* from kernel if structure */
        u_short int_transitions;                /* times gone up-down */
        int     int_opackets;                   /* output packets sent */
        char    *int_name;                      /* from kernel if structure */
        u_short int_transitions;                /* times gone up-down */
-       int     int_ripsock[2];                 /* socket to listen for RIP packets on */
 };
 
 /*
 };
 
 /*
index ab4c30e..5dacdb4 100644 (file)
@@ -14,6 +14,7 @@ static char rcsid[] = "$Header$";
 #include <errno.h>
 #include <nlist.h>
 #include <signal.h>
 #include <errno.h>
 #include <nlist.h>
 #include <signal.h>
+#include <syslog.h>
 
 int    supplier = -1;          /* process should supply updates */
 extern int gateway;
 
 int    supplier = -1;          /* process should supply updates */
 extern int gateway;
@@ -25,13 +26,16 @@ main(argc, argv)
        int argc;
        char *argv[];
 {
        int argc;
        char *argv[];
 {
+       int cc;
        struct sockaddr from;
        u_char retry;
        struct sockaddr from;
        u_char retry;
-       int selectbits;
-       struct interface *ifp;
-       extern struct interface *ifnet;
        
        argv0 = argv;
        
        argv0 = argv;
+       addr.sns_family = AF_NS;
+       addr.sns_port = htons(IDPPORT_RIF);
+       s = getsocket(SOCK_DGRAM, 0, &addr);
+       if (s < 0)
+               exit(1);
        argv++, argc--;
        while (argc > 0 && **argv == '-') {
                if (strcmp(*argv, "-s") == 0) {
        argv++, argc--;
        while (argc > 0 && **argv == '-') {
                if (strcmp(*argv, "-s") == 0) {
@@ -102,7 +106,7 @@ main(argc, argv)
                supplier = 0;
        /* request the state of the world */
        msg->rip_cmd = htons(RIPCMD_REQUEST);
                supplier = 0;
        /* request the state of the world */
        msg->rip_cmd = htons(RIPCMD_REQUEST);
-       xnnet(msg->rip_nets[0].rip_dst) = htonl(DSTNETS_ALL);
+       xnnet(msg->rip_nets[0].rip_dst[0]) = htonl(DSTNETS_ALL);
        msg->rip_nets[0].rip_metric =  htons(HOPCNT_INFINITY);
        toall(sendmsg);
        signal(SIGALRM, timer);
        msg->rip_nets[0].rip_metric =  htons(HOPCNT_INFINITY);
        toall(sendmsg);
        signal(SIGALRM, timer);
@@ -111,34 +115,18 @@ main(argc, argv)
        signal(SIGEMT, fkexit);
        timer();
        
        signal(SIGEMT, fkexit);
        timer();
        
-       /*
-        * Listen for RIF packets on all interfaces
-        */
-       selectbits = 0;
-       for( ifp = ifnet; ifp!=0; ifp = ifp->int_next) {
-               selectbits |= 1 << ifp->int_ripsock[0];
-               selectbits |= 1 << ifp->int_ripsock[1];
-       }
 
        for (;;) {
                int ibits;
                register int n;
 
 
        for (;;) {
                int ibits;
                register int n;
 
-               ibits = selectbits;
+               /*ibits = 1 << s;
                n = select(20, &ibits, 0, 0, 0);
                n = select(20, &ibits, 0, 0, 0);
-               if (n < 0) {
-                       if(errno != EINTR) {
-                               perror("main:select");
-                               exit(1);
-                       }
+               if (n < 0)
                        continue;
                        continue;
-               }
-               for( ifp = ifnet; ifp!=0; ifp = ifp->int_next) {
-                   /* take RIF packet off interface */
-                   for(n = 0; n < 2; n++)
-                       if(ibits & (1 << ifp->int_ripsock[n]))
-                               process(ifp->int_ripsock[n]);
-               }
+               if (ibits & (1 << s)) */
+                       process(s);
+               /* handle ICMP redirects */
        }
 }
 
        }
 }
 
@@ -158,46 +146,63 @@ process(fd)
        /* We get the IDP header in front of the RIF packet*/
        if (tracepackets > 1) {
            fprintf(ftrace,"rcv %d bytes on %s ",
        /* We get the IDP header in front of the RIF packet*/
        if (tracepackets > 1) {
            fprintf(ftrace,"rcv %d bytes on %s ",
-               cc, xns_ntoa(&idp->idp_dst));
-           fprintf(ftrace," from %s\n", xns_ntoa(&idp->idp_src));
+               cc, xns_ntoa(&idp->idp_dna));
+           fprintf(ftrace," from %s\n", xns_ntoa(&idp->idp_sna));
        }
        
        }
        
-       if (xnnet(idp->idp_src.xn_net) != xnnet(idp->idp_dst.xn_net)) {
+       if (ns_netof(idp->idp_sna) != ns_netof(idp->idp_dna)) {
                fprintf(ftrace, "XNSrouted: net of interface (%d) != net on ether (%d)!\n",
                fprintf(ftrace, "XNSrouted: net of interface (%d) != net on ether (%d)!\n",
-                       ntohl(xnnet(idp->idp_dst.xn_net)),
-                       ntohs(xnnet(idp->idp_src.xn_net)));
+                       ns_netof(idp->idp_dna), ns_netof(idp->idp_sna));
        }
                        
        cc -= sizeof (struct idp);
        }
                        
        cc -= sizeof (struct idp);
-       if (fromlen != sizeof (struct sockaddr_xn))
-               return;
+       if (fromlen != sizeof (struct sockaddr_ns))
+               fprintf(ftrace, "fromlen is %d instead of %d\n",
+               fromlen, sizeof (struct sockaddr_ns));
 #define        mask(s) (1<<((s)-1))
        omask = sigblock(mask(SIGALRM));
        rip_input(&from, cc);
        sigsetmask(omask);
 }
 
 #define        mask(s) (1<<((s)-1))
        omask = sigblock(mask(SIGALRM));
        rip_input(&from, cc);
        sigsetmask(omask);
 }
 
-getsocket(domain, type, proto, sxn)
-       int domain, type, proto;
-       struct sockaddr_xn *sxn;
+getsocket(type, proto, sns)
+       int type, proto; 
+       struct sockaddr_ns *sns;
 {
 {
-       int retry, s;
+       int domain = sns->sns_family;
+       int retry, s, on = 1;
 
        retry = 1;
 
        retry = 1;
-       while ((s = socket(domain, type, proto, 0)) < 0 && retry) {
+       while ((s = socket(domain, type, proto)) < 0 && retry) {
                perror("socket");
                sleep(5 * retry);
                retry <<= 1;
        }
        if (retry == 0)
                return (-1);
                perror("socket");
                sleep(5 * retry);
                retry <<= 1;
        }
        if (retry == 0)
                return (-1);
-       while (bind(s, sxn, sizeof (*sxn), 0) < 0 && retry) {
+       while (bind(s, sns, sizeof (*sns), 0) < 0 && retry) {
                perror("bind");
                sleep(5 * retry);
                retry <<= 1;
        }
        if (retry == 0)
                return (-1);
                perror("bind");
                sleep(5 * retry);
                retry <<= 1;
        }
        if (retry == 0)
                return (-1);
+       if (domain==AF_NS) {
+               struct idp idp;
+               if (setsockopt(s, 0, SO_HEADERS_ON_INPUT, &on, sizeof(on))) {
+                       perror("setsockopt SEE HEADERS");
+                       exit(1);
+               }
+               idp.idp_pt = NSPROTO_RI;
+               if (setsockopt(s, 0, SO_DEFAULT_HEADERS, &idp, sizeof(idp))) {
+                       perror("setsockopt SET HEADERS");
+                       exit(1);
+               }
+       }
+       if (setsockopt(s, SOL_SOCKET, SO_BROADCAST, &on, sizeof (on)) < 0) {
+               perror("setsockopt SO_BROADCAST");
+               exit(1);
+       }
        return (s);
 }
 
        return (s);
 }
 
index 02c8eab..ebb67b0 100644 (file)
@@ -42,8 +42,8 @@ sendmsg(dst, flags, ifp)
        struct interface *ifp;
 {
 
        struct interface *ifp;
 {
 
-       (*afswitch[dst->sa_family].af_output)(ifp->int_ripsock[0], flags,
-               dst, sizeof (struct rip));
+       (*afswitch[dst->sa_family].af_output)
+               (flags, dst, sizeof (struct rip));
        TRACE_OUTPUT(ifp, dst, sizeof (struct rip));
 }
 
        TRACE_OUTPUT(ifp, dst, sizeof (struct rip));
 }
 
@@ -61,7 +61,7 @@ supply(dst, flags, ifp)
        register struct rthash *rh;
        struct rthash *base = hosthash;
        int doinghost = 1, size;
        register struct rthash *rh;
        struct rthash *base = hosthash;
        int doinghost = 1, size;
-       struct sockaddr_xn *sxn =  (struct sockaddr_xn *) dst;
+       struct sockaddr_ns *sns =  (struct sockaddr_ns *) dst;
        int (*output)() = afswitch[dst->sa_family].af_output;
 
        msg->rip_cmd = ntohs(RIPCMD_RESPONSE);
        int (*output)() = afswitch[dst->sa_family].af_output;
 
        msg->rip_cmd = ntohs(RIPCMD_RESPONSE);
@@ -70,12 +70,12 @@ again:
        for (rt = rh->rt_forw; rt != (struct rt_entry *)rh; rt = rt->rt_forw) {
                size = (char *)n - (char *)msg;
                if (size > MAXPACKETSIZE - sizeof (struct netinfo)) {
        for (rt = rh->rt_forw; rt != (struct rt_entry *)rh; rt = rt->rt_forw) {
                size = (char *)n - (char *)msg;
                if (size > MAXPACKETSIZE - sizeof (struct netinfo)) {
-                       (*output)(ifp->int_ripsock[0], flags, dst, size);
+                       (*output)(flags, dst, size);
                        TRACE_OUTPUT(ifp, dst, size);
                        n = msg->rip_nets;
                }
                        TRACE_OUTPUT(ifp, dst, size);
                        n = msg->rip_nets;
                }
-               sxn = (struct sockaddr_xn *)&rt->rt_dst;
-               xnnet(n->rip_dst) = xnnet(((struct sockaddr_xn *)&rt->rt_dst)->sxn_addr.xn_net);
+               sns = (struct sockaddr_ns *)&rt->rt_dst;
+               xnnet(n->rip_dst[0]) = ns_netof(sns->sns_addr);
                n->rip_metric = htons(min(rt->rt_metric + 1, HOPCNT_INFINITY));
                n++;
        }
                n->rip_metric = htons(min(rt->rt_metric + 1, HOPCNT_INFINITY));
                n++;
        }
@@ -86,7 +86,7 @@ again:
        }
        if (n != msg->rip_nets) {
                size = (char *)n - (char *)msg;
        }
        if (n != msg->rip_nets) {
                size = (char *)n - (char *)msg;
-               (*output)(ifp->int_ripsock[0], flags, dst, size);
+               (*output)(flags, dst, size);
                TRACE_OUTPUT(ifp, dst, size);
        }
 }
                TRACE_OUTPUT(ifp, dst, size);
        }
 }
index e7cdcaf..ad0fc8c 100644 (file)
@@ -9,147 +9,115 @@ static char rcsid[] = "$Header$";
 #include <sys/ioctl.h>
 #include <net/if.h>
 #include <nlist.h>
 #include <sys/ioctl.h>
 #include <net/if.h>
 #include <nlist.h>
+#include <syslog.h>
 
 struct interface *ifnet;
 
 struct interface *ifnet;
-int    kmem = -1;
 int    lookforinterfaces = 1;
 int    performnlist = 1;
 int    externalinterfaces = 0;         /* # of remote and local interfaces */
 int    gateway = 0;            /* 1 if we are a gateway to parts beyond */
 char ether_broadcast_addr[6] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
 
 int    lookforinterfaces = 1;
 int    performnlist = 1;
 int    externalinterfaces = 0;         /* # of remote and local interfaces */
 int    gateway = 0;            /* 1 if we are a gateway to parts beyond */
 char ether_broadcast_addr[6] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
 
-struct nlist nl[] = {
-#define        N_IFNET         0
-       { "_ifnet" },
-       { "" },
-};
 
 /*
 
 /*
- * Probe the kernel through /dev/kmem to find the network
- * interfaces which have configured themselves.  If the
- * interface is present but not yet up (for example an
+ * Find the network interfaces which have configured themselves.
+ * If the interface is present but not yet up (for example an
  * ARPANET IMP), set the lookforinterfaces flag so we'll
  * come back later and look again.
  */
 ifinit()
 {
  * ARPANET IMP), set the lookforinterfaces flag so we'll
  * come back later and look again.
  */
 ifinit()
 {
-       struct interface *ifp;
-       struct ifnet ifs, *next;
-       char name[32], *cp, *index();
-       int j,iffound;
-       struct sockaddr ifaddr, ifdstaddr;
-       struct sockaddr_xn *sxn;
+       struct interface ifs, *ifp;
+       int s, n;
+       char buf[BUFSIZ];
+        struct ifconf ifc;
+        struct ifreq ifreq, *ifr;
+       u_long i;
 
 
-       if (performnlist) {
-               nlist("/vmunix", nl);
-               if (nl[N_IFNET].n_value == 0) {
-                       printf("ifnet: not in namelist\n");
-                       goto bad;
-               }
-               performnlist = 0;
-       }
-       if (kmem < 0) {
-               kmem = open("/dev/kmem", 0);
-               if (kmem < 0) {
-                       perror("/dev/kmem");
-                       goto bad;
-               }
-       }
-       if (lseek(kmem, (long)nl[N_IFNET].n_value, 0) == -1 ||
-           read(kmem, (char *)&next, sizeof (next)) != sizeof (next)) {
-               printf("ifnet: error reading kmem\n");
-               goto bad;
+       if ((s = socket(AF_NS, SOCK_DGRAM, 0)) < 0) {
+               syslog(LOG_ERR, "socket: %m");
+               exit(1);
        }
        }
+        ifc.ifc_len = sizeof (buf);
+        ifc.ifc_buf = buf;
+        if (ioctl(s, SIOCGIFCONF, (char *)&ifc) < 0) {
+                syslog(LOG_ERR, "ioctl (get interface configuration)");
+               close(s);
+                return (0);
+        }
+        ifr = ifc.ifc_req;
        lookforinterfaces = 0;
        lookforinterfaces = 0;
-       while (next) {
-               if (lseek(kmem, (long)next, 0) == -1 ||
-                   read(kmem, (char *)&ifs, sizeof (ifs)) != sizeof (ifs)) {
-                       perror("read");
-                       goto bad;
-               }
-               next = ifs.if_next;
-               if ((ifs.if_flags & IFF_UP) == 0) {
+        for (n = ifc.ifc_len / sizeof (struct ifreq); n > 0; n--, ifr++) {
+               bzero((char *)&ifs, sizeof(ifs));
+               ifs.int_addr = ifr->ifr_addr;
+               ifreq = *ifr;
+                if (ioctl(s, SIOCGIFFLAGS, (char *)&ifreq) < 0) {
+                        syslog(LOG_ERR, "ioctl (get interface flags)");
+                        continue;
+                }
+               ifs.int_flags = ifreq.ifr_flags | IFF_INTERFACE;
+               if ((ifs.int_flags & IFF_UP) == 0 ||
+                   ifr->ifr_addr.sa_family == AF_UNSPEC) {
                        lookforinterfaces = 1;
                        continue;
                }
                        lookforinterfaces = 1;
                        continue;
                }
-               /* Only interested in af XNS */
-               iffound = 0;
-               for( j = 0; j < NIFADDR; j++) {
-                   if (ifs.if_addr[j].sa_family != AF_XNS)
-                       continue;
-                   /* already known to us? */
-                   if (if_ifwithaddr(&ifs.if_addr[j]))
-                       continue; 
-                   ifaddr = ifs.if_addr[j];
-                   ifdstaddr = ifs.if_dstaddr[j];
-                   iffound++;
+               /* already known to us? */
+               if (if_ifwithaddr(&ifs.int_addr))
+                       continue;
+               /* argh, this'll have to change sometime */
+               if (ifs.int_addr.sa_family != AF_NS)
+                       continue;
+                if (ifs.int_flags & IFF_POINTOPOINT) {
+                        if (ioctl(s, SIOCGIFDSTADDR, (char *)&ifreq) < 0) {
+                                syslog(LOG_ERR, "ioctl (get dstaddr)");
+                                continue;
+                       }
+                       ifs.int_dstaddr = ifreq.ifr_dstaddr;
+               }
+                if (ifs.int_flags & IFF_BROADCAST) {
+                        if (ioctl(s, SIOCGIFBRDADDR, (char *)&ifreq) < 0) {
+                                syslog(LOG_ERR, "ioctl (get broadaddr)");
+                                continue;
+                        }
+                       ifs.int_broadaddr = ifreq.ifr_broadaddr;
                }
                }
-               if (!iffound) continue;
-               
+               /* no one cares about software loopback interfaces */
+               if (strcmp(ifr->ifr_name,"lo0")==0)
+                       continue;
                ifp = (struct interface *)malloc(sizeof (struct interface));
                if (ifp == 0) {
                        printf("routed: out of memory\n");
                        break;
                }
                ifp = (struct interface *)malloc(sizeof (struct interface));
                if (ifp == 0) {
                        printf("routed: out of memory\n");
                        break;
                }
+               *ifp = ifs;
                /*
                 * Count the # of directly connected networks
                 * and point to point links which aren't looped
                 * back to ourself.  This is used below to
                 * decide if we should be a routing ``supplier''.
                 */
                /*
                 * Count the # of directly connected networks
                 * and point to point links which aren't looped
                 * back to ourself.  This is used below to
                 * decide if we should be a routing ``supplier''.
                 */
-               if ((ifs.if_flags & IFF_POINTOPOINT) == 0 ||
-                   if_ifwithaddr(ifdstaddr) == 0)
+               if ((ifs.int_flags & IFF_POINTOPOINT) == 0 ||
+                   if_ifwithaddr(&ifs.int_dstaddr) == 0)
                        externalinterfaces++;
                        externalinterfaces++;
-               if ((ifs.if_flags & IFF_LOCAL) == 0 && gateway == 0) {
-                       /*
-                        * If we have an interface to a non-local network,
-                        * we are a candidate for use as a gateway.
-                        */
-                       gateway = 1;
-               }
-               lseek(kmem, ifs.if_name, 0);
-               read(kmem, name, sizeof (name));
-               name[sizeof (name) - 1] = '\0';
-               cp = index(name, '\0');
-               *cp++ = ifs.if_unit + '0';
-               *cp = '\0';
-               ifp->int_name = malloc(strlen(name) + 1);
+               ifp->int_name = malloc(strlen(ifr->ifr_name) + 1);
                if (ifp->int_name == 0) {
                        fprintf(stderr, "routed: ifinit: out of memory\n");
                        goto bad;               /* ??? */
                }
                if (ifp->int_name == 0) {
                        fprintf(stderr, "routed: ifinit: out of memory\n");
                        goto bad;               /* ??? */
                }
-               strcpy(ifp->int_name, name);
-               ifp->int_flags = (ifs.if_flags & 0x1ff) | IFF_INTERFACE;
-               ifp->int_addr = ifaddr;
-               /* this works because broadaddr overlaps dstaddr */
-               ifp->int_broadaddr = ifdstaddr;
+               strcpy(ifp->int_name, ifr->ifr_name);
                ifp->int_metric = 0;
                ifp->int_next = ifnet;
                ifp->int_metric = 0;
                ifp->int_next = ifnet;
-               /* 
-                * Now arrange for a socket to listen on.
-                * This nonsense is necessary because of the stupidity
-                * of the raw socket code.
-                */
-               /* listen on our own address... */
-               sxn = (struct sockaddr_xn *) &ifp->int_addr;
-               sxn->sxn_addr.xn_socket = htons(IDPPORT_RIF);
-               ifp->int_ripsock[0] = getsocket(AF_XNS, SOCK_RAW, IDPPROTO_RIF, sxn);
-               /* AND on our broadcast address if we have one */
-               if (ifp->int_flags & IFF_BROADCAST) {
-                   sxn = (struct sockaddr_xn *)  &ifp->int_broadaddr ;
-                   sxn->sxn_addr.xn_socket = htons(IDPPORT_RIF);
-                   ifp->int_ripsock[1] = getsocket(AF_XNS, SOCK_RAW, IDPPROTO_RIF, sxn);
-               }
                ifnet = ifp;
                traceinit(ifp);
                addrouteforif(ifp);
        }
        if (externalinterfaces > 1 && supplier < 0)
                supplier = 1;
                ifnet = ifp;
                traceinit(ifp);
                addrouteforif(ifp);
        }
        if (externalinterfaces > 1 && supplier < 0)
                supplier = 1;
+       close(s);
        return;
 bad:
        sleep(60);
        return;
 bad:
        sleep(60);
-       for(j = 3; j < 32; j++) close(j);
+       close(s);
        execv("/etc/XNSrouted", argv0);
        _exit(0177);
 }
        execv("/etc/XNSrouted", argv0);
        _exit(0177);
 }
@@ -157,7 +125,7 @@ bad:
 addrouteforif(ifp)
        struct interface *ifp;
 {
 addrouteforif(ifp)
        struct interface *ifp;
 {
-       struct sockaddr_xn net;
+       struct sockaddr_ns net;
        struct sockaddr *dst;
        int state, metric;
        struct rt_entry *rt;
        struct sockaddr *dst;
        int state, metric;
        struct rt_entry *rt;
@@ -165,16 +133,12 @@ addrouteforif(ifp)
        if (ifp->int_flags & IFF_POINTOPOINT)
                dst = &ifp->int_dstaddr;
        else {
        if (ifp->int_flags & IFF_POINTOPOINT)
                dst = &ifp->int_dstaddr;
        else {
-               bzero(&net, sizeof (net));
-               net.sxn_family = AF_XNS;
-               xnnet(net.sxn_addr.xn_net) = xnnet(((struct sockaddr_xn *)(&ifp->int_addr))->sxn_addr.xn_net);
-               dst = (struct sockaddr *)&net;
+               dst = &ifp->int_broadaddr;
        }
        rt = rtlookup(dst);
        }
        rt = rtlookup(dst);
-       rtadd(dst, &ifp->int_addr, ifp->int_metric,
-               ifp->int_flags & (IFF_INTERFACE|IFF_PASSIVE|IFF_REMOTE));
        if (rt)
                rtdelete(rt);
        if (rt)
                rtdelete(rt);
+       rtadd(dst, &ifp->int_addr, ifp->int_metric,
+               ifp->int_flags & (IFF_INTERFACE|IFF_PASSIVE|IFF_REMOTE));
 }
 
 }
 
-
index 755519f..4433629 100644 (file)
@@ -14,7 +14,7 @@ static char rcsid[] = "$Header$";
 #endif
 
 int    install = !DEBUG;               /* if 1 call kernel */
 #endif
 
 int    install = !DEBUG;               /* if 1 call kernel */
-static  int    s;                      /* for routing table ioctl's */
+int    delete = 1;
 /*
  * Lookup dst in the tables for an exact match.
  */
 /*
  * Lookup dst in the tables for an exact match.
  */
@@ -76,11 +76,10 @@ again:
                if (doinghost) {
                        if (equal(&rt->rt_dst, dst))
                                return (rt);
                if (doinghost) {
                        if (equal(&rt->rt_dst, dst))
                                return (rt);
-               } else {
-                       if (rt->rt_dst.sa_family == af &&
-                           (*match)(&rt->rt_dst, dst))
-                               return (rt);
                }
                }
+               if (rt->rt_dst.sa_family == af &&
+                   (*match)(&rt->rt_dst, dst))
+                       return (rt);
        }
        if (doinghost) {
                doinghost = 0;
        }
        if (doinghost) {
                doinghost = 0;
@@ -171,6 +170,7 @@ rtchange(rt, gate, metric)
        if (doioctl && install) {
                if (ioctl(s, SIOCADDRT, (char *)&rt->rt_rt) < 0)
                        perror("SIOCADDRT");
        if (doioctl && install) {
                if (ioctl(s, SIOCADDRT, (char *)&rt->rt_rt) < 0)
                        perror("SIOCADDRT");
+               if (delete)
                if (ioctl(s, SIOCDELRT, (char *)&oldroute) < 0)
                        perror("SIOCDELRT");
        }
                if (ioctl(s, SIOCDELRT, (char *)&oldroute) < 0)
                        perror("SIOCDELRT");
        }
@@ -181,7 +181,7 @@ rtdelete(rt)
 {
 
        TRACE_ACTION(DELETE, rt);
 {
 
        TRACE_ACTION(DELETE, rt);
-       if (install && ioctl(s, SIOCDELRT, (char *)&rt->rt_rt))
+       if (install && delete && ioctl(s, SIOCDELRT, (char *)&rt->rt_rt))
                perror("SIOCDELRT");
        remque(rt);
        free((char *)rt);
                perror("SIOCDELRT");
        remque(rt);
        free((char *)rt);
@@ -195,9 +195,4 @@ rtinit()
                rh->rt_forw = rh->rt_back = (struct rt_entry *)rh;
        for (rh = hosthash; rh < &hosthash[ROUTEHASHSIZ]; rh++)
                rh->rt_forw = rh->rt_back = (struct rt_entry *)rh;
                rh->rt_forw = rh->rt_back = (struct rt_entry *)rh;
        for (rh = hosthash; rh < &hosthash[ROUTEHASHSIZ]; rh++)
                rh->rt_forw = rh->rt_back = (struct rt_entry *)rh;
-               
-       if ((s = socket(AF_XNS, SOCK_RAW, IDPPROTO_RAW)) < 0) {
-               perror("socket");
-               exit(1);
-       }
 }
 }
index 892d30b..3b1b71b 100644 (file)
@@ -55,8 +55,8 @@ again:
                                if (!supplier || timetobroadcast)
                                        continue;
                                msg->rip_cmd = htons(RIPCMD_RESPONSE);
                                if (!supplier || timetobroadcast)
                                        continue;
                                msg->rip_cmd = htons(RIPCMD_RESPONSE);
-                               xnnet(msg->rip_nets[0].rip_dst) = 
-                                       htonl(xnnet(((struct sockaddr_xn *)&rt->rt_dst)->sxn_addr.xn_net));
+                               xnnet(msg->rip_nets[0].rip_dst[0]) = 
+                                       ns_netof(satons_addr(rt->rt_dst));
                                msg->rip_nets[0].rip_metric =
                                        htons(min(rt->rt_metric+1, HOPCNT_INFINITY));
                                toall(sendmsg);
                                msg->rip_nets[0].rip_metric =
                                        htons(min(rt->rt_metric+1, HOPCNT_INFINITY));
                                toall(sendmsg);
index 0d124a8..b4f44e7 100644 (file)
@@ -108,7 +108,7 @@ traceaction(fd, action, rt)
        char *action;
        struct rt_entry *rt;
 {
        char *action;
        struct rt_entry *rt;
 {
-       struct sockaddr_xn *dst, *gate;
+       struct sockaddr_ns *dst, *gate;
        static struct bits {
                int     t_bits;
                char    *t_name;
        static struct bits {
                int     t_bits;
                char    *t_name;
@@ -132,11 +132,11 @@ traceaction(fd, action, rt)
        if (fd == NULL)
                return;
        fprintf(fd, "%s ", action);
        if (fd == NULL)
                return;
        fprintf(fd, "%s ", action);
-       dst = (struct sockaddr_xn *)&rt->rt_dst;
-       gate = (struct sockaddr_xn *)&rt->rt_router;
-       fprintf(fd, "dst %s, ", xns_ntoa(&dst->sxn_addr));
+       dst = (struct sockaddr_ns *)&rt->rt_dst;
+       gate = (struct sockaddr_ns *)&rt->rt_router;
+       fprintf(fd, "dst %s, ", xns_ntoa(&dst->sns_addr));
        fprintf(fd, "router %s, metric %d, flags",
        fprintf(fd, "router %s, metric %d, flags",
-            xns_ntoa(&gate->sxn_addr), rt->rt_metric);
+            xns_ntoa(&gate->sns_addr), rt->rt_metric);
        cp = " %s";
        for (first = 1, p = flagbits; p->t_bits > 0; p++) {
                if ((rt->rt_flags & p->t_bits) == 0)
        cp = " %s";
        for (first = 1, p = flagbits; p->t_bits > 0; p++) {
                if ((rt->rt_flags & p->t_bits) == 0)
@@ -206,7 +206,7 @@ dumptrace(fd, dir, ifd)
 
 dumppacket(fd, dir, who, cp, size)
        FILE *fd;
 
 dumppacket(fd, dir, who, cp, size)
        FILE *fd;
-       struct sockaddr_xn *who;                /* should be sockaddr */
+       struct sockaddr_ns *who;                /* should be sockaddr */
        char *dir, *cp;
        register int size;
 {
        char *dir, *cp;
        register int size;
 {
@@ -215,10 +215,10 @@ dumppacket(fd, dir, who, cp, size)
 
        if (msg->rip_cmd && ntohs(msg->rip_cmd) < RIPCMD_MAX)
                fprintf(fd, "%s %s %s#%x", ripcmds[ntohs(msg->rip_cmd)],
 
        if (msg->rip_cmd && ntohs(msg->rip_cmd) < RIPCMD_MAX)
                fprintf(fd, "%s %s %s#%x", ripcmds[ntohs(msg->rip_cmd)],
-                   dir, xns_ntoa(&who->sxn_addr), ntohs(who->sxn_addr.xn_socket));
+                   dir, xns_ntoa(&who->sns_addr), ntohs(who->sns_addr.x_port));
        else {
                fprintf(fd, "Bad cmd 0x%x %s %s#%x\n", ntohs(msg->rip_cmd),
        else {
                fprintf(fd, "Bad cmd 0x%x %s %s#%x\n", ntohs(msg->rip_cmd),
-                   dir, xns_ntoa(&who->sxn_addr), ntohs(who->sxn_addr.xn_socket));
+                   dir, xns_ntoa(&who->sns_addr), ntohs(who->sns_addr.x_port));
                fprintf(fd, "size=%d cp=%x packet=%x\n", size, cp, packet);
                return;
        }
                fprintf(fd, "size=%d cp=%x packet=%x\n", size, cp, packet);
                return;
        }
@@ -233,7 +233,7 @@ dumppacket(fd, dir, who, cp, size)
                        if (size < sizeof (struct netinfo))
                                break;
                        fprintf(fd, "\tnet %#x metric %d\n",
                        if (size < sizeof (struct netinfo))
                                break;
                        fprintf(fd, "\tnet %#x metric %d\n",
-                            ntohl(xnnet(n->rip_dst)),
+                            ntohl(xnnet(n->rip_dst[0])),
                             ntohs(n->rip_metric));
                }
                break;
                             ntohs(n->rip_metric));
                }
                break;
@@ -243,15 +243,15 @@ dumppacket(fd, dir, who, cp, size)
 
 char *
 xns_ntoa(addr)
 
 char *
 xns_ntoa(addr)
-struct xn_addr *addr;
+struct ns_addr *addr;
 {
     static char buf[100];
 
     sprintf(buf, "%x#%x:%x:%x:%x:%x:%x",
 {
     static char buf[100];
 
     sprintf(buf, "%x#%x:%x:%x:%x:%x:%x",
-       ntohl(xnnet(addr->xn_net)),
-       addr->xn_host[0], addr->xn_host[1], 
-       addr->xn_host[2], addr->xn_host[3], 
-       addr->xn_host[4], addr->xn_host[5]);
+       ntohl(xnnet(addr->x_net)),
+       addr->x_host.c_host[0], addr->x_host.c_host[1], 
+       addr->x_host.c_host[2], addr->x_host.c_host[3], 
+       addr->x_host.c_host[4], addr->x_host.c_host[5]);
        
     return(buf);
 }
        
     return(buf);
 }