cleanup
authorSam Leffler <sam@ucbvax.Berkeley.EDU>
Wed, 26 May 1982 09:56:08 +0000 (01:56 -0800)
committerSam Leffler <sam@ucbvax.Berkeley.EDU>
Wed, 26 May 1982 09:56:08 +0000 (01:56 -0800)
SCCS-vsn: sbin/routed/routed.c 4.6
SCCS-vsn: sbin/routed/defs.h 4.2

usr/src/sbin/routed/defs.h
usr/src/sbin/routed/routed.c

index a502ae1..ac888e4 100644 (file)
@@ -1,4 +1,4 @@
-/*     defs.h  4.1     82/05/22        */
+/*     defs.h  4.2     82/05/25        */
 
 /*
  * Internal data structure definitions for
 
 /*
  * Internal data structure definitions for
@@ -6,12 +6,13 @@
  * protocol specs with mods relevant to more
  * general addressing scheme.
  */
  * protocol specs with mods relevant to more
  * general addressing scheme.
  */
+#include <net/route.h>
 
 /*
  * Internal routing table structure.
  * Differs a bit from kernel tables.
  */
 
 /*
  * Internal routing table structure.
  * Differs a bit from kernel tables.
  */
-struct rt_hash {
+struct rthash {
        struct  rt_entry *rt_forw;
        struct  rt_entry *rt_back;
 };
        struct  rt_entry *rt_forw;
        struct  rt_entry *rt_back;
 };
@@ -19,16 +20,31 @@ struct rt_hash {
 struct rt_entry {
        struct  rt_entry *rt_forw;
        struct  rt_entry *rt_back;
 struct rt_entry {
        struct  rt_entry *rt_forw;
        struct  rt_entry *rt_back;
-       u_long  rt_hash;                /* for net or for host */
-       struct  sockaddr rt_dst;        /* match value */
-       struct  sockaddr rt_gateway;    /* who to forward to */
-       short   rt_flags;               /* see below */
-       short   rt_retry;               /* # ioctl retries */
-       int     rt_timer;               /* for invalidation */
-       int     rt_metric;              /* hop count of route */
-       struct  ifnet *rt_ifp;          /* corresponding interface */
+       union {
+               struct  rtentry rtu_rt;
+               struct {
+                       u_long  rtu_hash;
+                       struct  sockaddr rtu_dst;
+                       struct  sockaddr rtu_gateway;
+                       short   rtu_flags;
+                       short   rtu_retry;
+                       int     rtu_timer;
+                       int     rtu_metric;
+                       struct  ifnet *rtu_ifp;
+               } rtu_entry;
+       } rt_rtu;
 };
 
 };
 
+#define        rt_rt           rt_rtu.rtu_rt                   /* pass to ioctl */
+#define        rt_hash         rt_rtu.rtu_entry.rtu_hash       /* for net or host */
+#define        rt_dst          rt_rtu.rtu_entry.rtu_dst        /* match value */
+#define        rt_gateway      rt_rtu.rtu_entry.rtu_gateway    /* who to forward to */
+#define        rt_flags        rt_rtu.rtu_entry.rtu_flags      /* see below */
+#define        rt_retry        rt_rtu.rtu_entry.rtu_retry      /* retries of ioctl */
+#define        rt_timer        rt_rtu.rtu_entry.rtu_timer      /* for invalidation */
+#define        rt_metric       rt_rtu.rtu_entry.rtu_metric     /* cost of route */
+#define        rt_ifp          rt_rtu.rtu_entry.rtu_ifp        /* interface to take */
+
 #define        ROUTEHASHSIZ    19
 
 /*
 #define        ROUTEHASHSIZ    19
 
 /*
@@ -40,7 +56,7 @@ struct rt_entry {
 #define        RTF_ADDRT       0x20            /* add command pending */
 #define        RTF_SILENT      0x40            /* don't send to router */
 
 #define        RTF_ADDRT       0x20            /* add command pending */
 #define        RTF_SILENT      0x40            /* don't send to router */
 
-struct rt_hash nethash[ROUTEHASHSIZ], hosthash[ROUTEHASHSIZ];
+struct rthash nethash[ROUTEHASHSIZ], hosthash[ROUTEHASHSIZ];
 struct rt_entry *rtlookup();
 
 /*
 struct rt_entry *rtlookup();
 
 /*
index 424bf7e..f10612a 100644 (file)
@@ -1,14 +1,14 @@
 #ifndef lint
 #ifndef lint
-static char sccsid[] = "@(#)routed.c   4.5 %G%";
+static char sccsid[] = "@(#)routed.c   4.6 %G%";
 #endif
 
 #endif
 
-#include <sys/param.h>
-#include <sys/protosw.h>
+/*
+ * Routing Table Management Daemon
+ */
+#include <sys/types.h>
 #include <sys/ioctl.h>
 #include <sys/socket.h>
 #include <net/in.h>
 #include <sys/ioctl.h>
 #include <sys/socket.h>
 #include <net/in.h>
-#define        KERNEL
-#include <net/route.h>
 #include <net/if.h>
 #include <errno.h>
 #include <stdio.h>
 #include <net/if.h>
 #include <errno.h>
 #include <stdio.h>
@@ -47,6 +47,8 @@ int   trace = 0;
 
 char   packet[MAXPACKETSIZE];
 
 
 char   packet[MAXPACKETSIZE];
 
+struct in_addr if_makeaddr();
+struct ifnet *if_ifwithaddr(), *if_ifwithnet();
 extern char *malloc();
 extern int errno, exit();
 
 extern char *malloc();
 extern int errno, exit();
 
@@ -156,9 +158,9 @@ getothers()
  */
 timer()
 {
  */
 timer()
 {
-       register struct rt_hash *rh;
+       register struct rthash *rh;
        register struct rt_entry *rt;
        register struct rt_entry *rt;
-       struct rt_hash *base = hosthash;
+       struct rthash *base = hosthash;
        int doinghost = 1;
 
        if (trace)
        int doinghost = 1;
 
        if (trace)
@@ -198,7 +200,7 @@ again:
                        if (rt->rt_timer >= EXPIRE_TIME)
                                rt->rt_metric = HOPCNT_INFINITY;
                        if (rt->rt_flags & RTF_CHGRT)
                        if (rt->rt_timer >= EXPIRE_TIME)
                                rt->rt_metric = HOPCNT_INFINITY;
                        if (rt->rt_flags & RTF_CHGRT)
-                               if (!ioctl(s, SIOCCHGRT,(char *)&rt->rt_hash) ||
+                               if (!ioctl(s, SIOCCHGRT,(char *)&rt->rt_rt) ||
                                  --rt->rt_retry == 0)
                                        rt->rt_flags &= ~RTF_CHGRT;
 
                                  --rt->rt_retry == 0)
                                        rt->rt_flags &= ~RTF_CHGRT;
 
@@ -211,7 +213,7 @@ again:
                         * in use), retry the operation a few more times.
                         */
                        if (rt->rt_flags & RTF_ADDRT) {
                         * in use), retry the operation a few more times.
                         */
                        if (rt->rt_flags & RTF_ADDRT) {
-                               if (!ioctl(s, SIOCADDRT,(char *)&rt->rt_hash)) {
+                               if (!ioctl(s, SIOCADDRT,(char *)&rt->rt_rt)) {
                                        if (errno == EEXIST) {
                                                rt->rt_flags &= ~RTF_ADDRT;
                                                rt->rt_flags |= RTF_CHGRT;
                                        if (errno == EEXIST) {
                                                rt->rt_flags &= ~RTF_ADDRT;
                                                rt->rt_flags |= RTF_CHGRT;
@@ -241,6 +243,7 @@ again:
        alarm(TIMER_RATE);
 }
 
        alarm(TIMER_RATE);
 }
 
+struct ifnet *ifnet;
 /*
  * Find the network interfaces attached to this machine.
  * The info is used to:
 /*
  * Find the network interfaces attached to this machine.
  * The info is used to:
@@ -251,6 +254,13 @@ again:
  * (4) figure out if we're an internetwork gateway.
  *
  * We don't handle anything but Internet addresses.
  * (4) figure out if we're an internetwork gateway.
  *
  * We don't handle anything but Internet addresses.
+ *
+ * Note: this routine may be called periodically to
+ * scan for new interfaces.  In fact, the timer routine
+ * does so based on the flag lookforinterfaces.  The
+ * flag performnlist is set whenever something odd occurs
+ * while scanning the kernel; this is likely to occur
+ * if /vmunix isn't up to date (e.g. someone booted /ovmunix).
  */
 getinterfaces()
 {
  */
 getinterfaces()
 {
@@ -372,12 +382,15 @@ broadcast(entry)
        sendall();
 }
 
        sendall();
 }
 
+/*
+ * Send "packet" to all neighbors.
+ */
 sendall()
 {
 sendall()
 {
-       register struct rt_hash *rh;
+       register struct rthash *rh;
        register struct rt_entry *rt;
        register struct sockaddr *dst;
        register struct rt_entry *rt;
        register struct sockaddr *dst;
-       struct rt_hash *base = hosthash;
+       struct rthash *base = hosthash;
        int doinghost = 1;
 
 again:
        int doinghost = 1;
 
 again:
@@ -405,9 +418,9 @@ again:
 supplyall()
 {
        register struct rt_entry *rt;
 supplyall()
 {
        register struct rt_entry *rt;
-       register struct rt_hash *rh;
+       register struct rthash *rh;
        register struct sockaddr *dst;
        register struct sockaddr *dst;
-       struct rt_hash *base = hosthash;
+       struct rthash *base = hosthash;
        int doinghost = 1;
 
 again:
        int doinghost = 1;
 
 again:
@@ -437,9 +450,9 @@ supply(sa)
 {
        struct rip *msg = (struct rip *)packet;
        struct netinfo *n = msg->rip_nets;
 {
        struct rip *msg = (struct rip *)packet;
        struct netinfo *n = msg->rip_nets;
-       register struct rt_hash *rh;
+       register struct rthash *rh;
        register struct rt_entry *rt;
        register struct rt_entry *rt;
-       struct rt_hash *base = hosthash;
+       struct rthash *base = hosthash;
        int doinghost = 1, size;
        int (*output)() = afswitch[sa->sa_family].af_output;
 
        int doinghost = 1, size;
        int (*output)() = afswitch[sa->sa_family].af_output;
 
@@ -535,7 +548,8 @@ rip_input(from, size)
         */
        (*afswitch[from->sa_family].af_canon)(from);
        if (trace)
         */
        (*afswitch[from->sa_family].af_canon)(from);
        if (trace)
-               printf("input from %x\n", from->sin_addr);
+               printf("input from %x\n",
+                       ((struct sockaddr_in *)from)->sin_addr);
        /*
         * If response packet is from ourselves, use it only
         * to reset timer on entry.  Otherwise, we'd believe
        /*
         * If response packet is from ourselves, use it only
         * to reset timer on entry.  Otherwise, we'd believe
@@ -557,7 +571,8 @@ rip_input(from, size)
                if (size < sizeof (struct netinfo))
                        break;
                if (trace)
                if (size < sizeof (struct netinfo))
                        break;
                if (trace)
-                       printf("dst %x hc %d...", n->rip_dst.sin_addr,
+                       printf("dst %x hc %d...",
+                               ((struct sockaddr_in *)&n->rip_dst)->sin_addr,
                                n->rip_metric);
                rt = rtlookup(&n->rip_dst);
 
                                n->rip_metric);
                rt = rtlookup(&n->rip_dst);
 
@@ -575,8 +590,8 @@ rip_input(from, size)
 
                if (trace)
                        printf("ours: gate %x hc %d timer %d\n",
 
                if (trace)
                        printf("ours: gate %x hc %d timer %d\n",
-                       rt->rt_gateway.sin_addr,
-                       rt->rt_metric, rt->rt_timer);
+                         ((struct sockaddr_in *)&rt->rt_gateway)->sin_addr,
+                         rt->rt_metric, rt->rt_timer);
                /*
                 * Update the entry if one of the following is true:
                 *
                /*
                 * Update the entry if one of the following is true:
                 *
@@ -597,6 +612,16 @@ rip_input(from, size)
        }
 }
 
        }
 }
 
+rtinit()
+{
+       register struct rthash *rh;
+
+       for (rh = nethash; rh < &nethash[ROUTEHASHSIZ]; 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;
+}
+
 /*
  * Lookup an entry to the appropriate dstination.
  */
 /*
  * Lookup an entry to the appropriate dstination.
  */
@@ -605,7 +630,7 @@ rtlookup(dst)
        struct sockaddr *dst;
 {
        register struct rt_entry *rt;
        struct sockaddr *dst;
 {
        register struct rt_entry *rt;
-       register struct rt_hash *rh;
+       register struct rthash *rh;
        register int hash, (*match)();
        struct afhash h;
        int af = dst->sa_family, doinghost = 1;
        register int hash, (*match)();
        struct afhash h;
        int af = dst->sa_family, doinghost = 1;
@@ -639,16 +664,6 @@ again:
        return (0);
 }
 
        return (0);
 }
 
-rtinit()
-{
-       register struct rt_hash *rh;
-
-       for (rh = nethash; rh < &nethash[ROUTEHASHSIZ]; 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;
-}
-
 /*
  * Add a new entry.
  */
 /*
  * Add a new entry.
  */
@@ -658,7 +673,7 @@ rtadd(dst, gate, metric)
 {
        struct afhash h;
        register struct rt_entry *rt;
 {
        struct afhash h;
        register struct rt_entry *rt;
-       struct rt_hash *rh;
+       struct rthash *rh;
        int af = dst->sa_family, flags, hash;
 
        if (af >= AF_MAX)
        int af = dst->sa_family, flags, hash;
 
        if (af >= AF_MAX)
@@ -746,7 +761,7 @@ rtdelete(rt)
 {
        log("delete", rt);
        if (install)
 {
        log("delete", rt);
        if (install)
-               if (ioctl(s, SIOCDELRT, (char *)&rt->rt_hash) &&
+               if (ioctl(s, SIOCDELRT, (char *)&rt->rt_rt) &&
                  errno == EBUSY)
                        rt->rt_flags |= RTF_DELRT;
        remque(rt);
                  errno == EBUSY)
                        rt->rt_flags |= RTF_DELRT;
        remque(rt);
@@ -795,6 +810,9 @@ log(operation, rt)
        putchar('\n');
 }
 
        putchar('\n');
 }
 
+/*
+ * Find the interface with address "addr".
+ */
 struct ifnet *
 if_ifwithaddr(addr)
        struct sockaddr *addr;
 struct ifnet *
 if_ifwithaddr(addr)
        struct sockaddr *addr;
@@ -816,6 +834,11 @@ if_ifwithaddr(addr)
 #undef same
 }
 
 #undef same
 }
 
+/*
+ * Find the interface with network imbedded in
+ * the sockaddr "addr".  Must use per-af routine
+ * look for match.
+ */
 struct ifnet *
 if_ifwithnet(addr)
        register struct sockaddr *addr;
 struct ifnet *
 if_ifwithnet(addr)
        register struct sockaddr *addr;
@@ -836,6 +859,9 @@ if_ifwithnet(addr)
        return (ifp);
 }
 
        return (ifp);
 }
 
+/*
+ * Formulate an Internet address.
+ */
 struct in_addr
 if_makeaddr(net, host)
        int net, host;
 struct in_addr
 if_makeaddr(net, host)
        int net, host;