subnet routing; don't copy routes from the gateways files everywhere
authorMike Karels <karels@ucbvax.Berkeley.EDU>
Wed, 11 Apr 1984 12:44:06 +0000 (04:44 -0800)
committerMike Karels <karels@ucbvax.Berkeley.EDU>
Wed, 11 Apr 1984 12:44:06 +0000 (04:44 -0800)
SCCS-vsn: sbin/routed/startup.c 4.5
SCCS-vsn: sbin/routed/tables.c 4.7

usr/src/sbin/routed/startup.c
usr/src/sbin/routed/tables.c

index 1747b66..8ef1b94 100644 (file)
@@ -1,11 +1,12 @@
 #ifndef lint
 #ifndef lint
-static char sccsid[] = "@(#)startup.c  4.4 (Berkeley) %G%";
+static char sccsid[] = "@(#)startup.c  4.5 (Berkeley) %G%";
 #endif
 
 /*
  * Routing Table Management Daemon
  */
 #include "defs.h"
 #endif
 
 /*
  * Routing Table Management Daemon
  */
 #include "defs.h"
+#include <sys/ioctl.h>
 #include <net/if.h>
 #include <nlist.h>
 
 #include <net/if.h>
 #include <nlist.h>
 
@@ -14,6 +15,7 @@ int   kmem = -1;
 int    lookforinterfaces = 1;
 int    performnlist = 1;
 int    externalinterfaces = 0;         /* # of remote and local interfaces */
 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 */
 
 struct nlist nl[] = {
 #define        N_IFNET         0
 
 struct nlist nl[] = {
 #define        N_IFNET         0
@@ -41,6 +43,8 @@ ifinit()
                        goto bad;
                }
                performnlist = 0;
                        goto bad;
                }
                performnlist = 0;
+               if (gateway)
+                       rtdefault();
        }
        if (kmem < 0) {
                kmem = open("/dev/kmem", 0);
        }
        if (kmem < 0) {
                kmem = open("/dev/kmem", 0);
@@ -89,6 +93,14 @@ ifinit()
                if ((ifs.if_flags & IFF_POINTOPOINT) == 0 ||
                    if_ifwithaddr(&ifs.if_dstaddr) == 0)
                        externalinterfaces++;
                if ((ifs.if_flags & IFF_POINTOPOINT) == 0 ||
                    if_ifwithaddr(&ifs.if_dstaddr) == 0)
                        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;
+                       rtdefault();
+               }
                lseek(kmem, ifs.if_name, 0);
                read(kmem, name, sizeof (name));
                name[sizeof (name) - 1] = '\0';
                lseek(kmem, ifs.if_name, 0);
                read(kmem, name, sizeof (name));
                name[sizeof (name) - 1] = '\0';
@@ -165,6 +177,7 @@ gwkludge()
        char *type, *dname, *gname, *qual, buf[BUFSIZ];
        struct interface *ifp;
        int metric;
        char *type, *dname, *gname, *qual, buf[BUFSIZ];
        struct interface *ifp;
        int metric;
+       struct rt_entry route;
 
        fp = fopen("/etc/gateways", "r");
        if (fp == NULL)
 
        fp = fopen("/etc/gateways", "r");
        if (fp == NULL)
@@ -175,6 +188,7 @@ gwkludge()
        type = buf + (((BUFSIZ - 64) * 2) / 3);
        bzero((char *)&dst, sizeof (dst));
        bzero((char *)&gate, sizeof (gate));
        type = buf + (((BUFSIZ - 64) * 2) / 3);
        bzero((char *)&dst, sizeof (dst));
        bzero((char *)&gate, sizeof (gate));
+       bzero((char *)&route, sizeof(route));
        /* format: {net | host} XX gateway XX metric DD [passive]\n */
 #define        readentry(fp) \
        fscanf((fp), "%s %s gateway %s metric %d %s\n", \
        /* format: {net | host} XX gateway XX metric DD [passive]\n */
 #define        readentry(fp) \
        fscanf((fp), "%s %s gateway %s metric %d %s\n", \
@@ -186,6 +200,26 @@ gwkludge()
                        continue;
                if (!gethostnameornumber(gname, &gate))
                        continue;
                        continue;
                if (!gethostnameornumber(gname, &gate))
                        continue;
+               if (strcmp(qual, "passive") == 0) {
+                       /*
+                        * Passive entries aren't placed in our tables,
+                        * only the kernel's, so we don't copy all of the
+                        * external routing information within a net.
+                        * Internal machines should use the default
+                        * route to a suitable gateway (like us).
+                        */
+                       route.rt_dst = *(struct sockaddr *) &dst;
+                       route.rt_router = *(struct sockaddr *) &gate;
+                       route.rt_flags = RTF_UP;
+                       if (strcmp(type, "host") == 0)
+                               route.rt_flags |= RTF_HOST;
+                       if (metric)
+                               route.rt_flags |= RTF_GATEWAY;
+                       (void) ioctl(s, SIOCADDRT, (char *)&route.rt_rt);
+                       continue;
+               }
+               /* assume no duplicate entries */
+               externalinterfaces++;
                ifp = (struct interface *)malloc(sizeof (*ifp));
                bzero((char *)ifp, sizeof (*ifp));
                ifp->int_flags = IFF_REMOTE;
                ifp = (struct interface *)malloc(sizeof (*ifp));
                bzero((char *)ifp, sizeof (*ifp));
                ifp->int_flags = IFF_REMOTE;
@@ -195,11 +229,6 @@ gwkludge()
                        ifp->int_flags |= IFF_POINTOPOINT;
                        ifp->int_dstaddr = *((struct sockaddr *)&dst);
                }
                        ifp->int_flags |= IFF_POINTOPOINT;
                        ifp->int_dstaddr = *((struct sockaddr *)&dst);
                }
-               if (strcmp(qual, "passive") == 0)
-                       ifp->int_flags |= IFF_PASSIVE;
-               else
-                       /* assume no duplicate entries */
-                       externalinterfaces++;
                ifp->int_addr = *((struct sockaddr *)&gate);
                ifp->int_metric = metric;
                ifp->int_next = ifnet;
                ifp->int_addr = *((struct sockaddr *)&gate);
                ifp->int_metric = metric;
                ifp->int_next = ifnet;
index 94b43ac..db76f3f 100644 (file)
@@ -1,5 +1,5 @@
 #ifndef lint
 #ifndef lint
-static char sccsid[] = "@(#)tables.c   4.6 (Berkeley) %G%";
+static char sccsid[] = "@(#)tables.c   4.7 (Berkeley) %G%";
 #endif
 
 /*
 #endif
 
 /*
@@ -150,26 +150,12 @@ rtchange(rt, gate, metric)
 {
        int doioctl = 0, metricchanged = 0;
        struct rtentry oldroute;
 {
        int doioctl = 0, metricchanged = 0;
        struct rtentry oldroute;
-#define        NDEBUG
-#ifdef NDEBUG
-       int turntraceoff = 0;
-#endif
 
        if (!equal(&rt->rt_router, gate))
                doioctl++;
        if (metric != rt->rt_metric)
                metricchanged++;
        if (doioctl || metricchanged) {
 
        if (!equal(&rt->rt_router, gate))
                doioctl++;
        if (metric != rt->rt_metric)
                metricchanged++;
        if (doioctl || metricchanged) {
-#ifdef NDEBUG
-               if (rt->rt_state & RTS_INTERFACE) {
-                   if (!tracing) {
-                       traceon("/usr/adm/routed.log");
-                       turntraceoff = 1;
-                       fprintf(ftrace, "**** Changing route from interface\n");
-                       fprintf(ftrace, "rt_timer = %d\n", rt->rt_timer);
-                   }
-               }
-#endif
                TRACE_ACTION(CHANGE FROM, rt);
                if (doioctl) {
                        oldroute = rt->rt_rt;
                TRACE_ACTION(CHANGE FROM, rt);
                if (doioctl) {
                        oldroute = rt->rt_rt;
@@ -188,10 +174,6 @@ rtchange(rt, gate, metric)
                if (ioctl(s, SIOCDELRT, (char *)&oldroute) < 0)
                        perror("SIOCDELRT");
        }
                if (ioctl(s, SIOCDELRT, (char *)&oldroute) < 0)
                        perror("SIOCDELRT");
        }
-#ifdef NDEBUG
-       if (turntraceoff)
-               traceoff();
-#endif
 }
 
 rtdelete(rt)
 }
 
 rtdelete(rt)
@@ -205,6 +187,37 @@ rtdelete(rt)
        free((char *)rt);
 }
 
        free((char *)rt);
 }
 
+/*
+ * If we have an interface to the wide, wide world,
+ * add an entry for an Internet default route (wildcard) to the internal
+ * tables and advertise it.  This route is not added to the kernel routes,
+ * but this entry prevents us from listening to other people's defaults
+ * and installing them in the kernel here.
+ */
+rtdefault()
+{
+       struct afhash h;
+       register struct rt_entry *rt;
+       struct rthash *rh;
+       extern struct sockaddr inet_default;
+
+       rt = (struct rt_entry *)malloc(sizeof (*rt));
+       if (rt == 0)
+               return;
+       rt->rt_hash = h.afh_nethash;
+       rt->rt_dst = inet_default;
+       rt->rt_router = rt->rt_dst;
+       (*afswitch[AF_INET].af_hash)(&rt->rt_dst, &h);
+       rh = &nethash[h.afh_nethash % ROUTEHASHSIZ];
+       rt->rt_metric = 0;
+       rt->rt_timer = 0;
+       rt->rt_flags = RTF_UP | RTF_GATEWAY;
+       rt->rt_state = RTS_CHANGED | RTS_PASSIVE;
+       rt->rt_ifp = 0;
+       insque(rt, rh);
+       TRACE_ACTION(ADD, rt);
+}
+
 rtinit()
 {
        register struct rthash *rh;
 rtinit()
 {
        register struct rthash *rh;