many cleanups; avoid interface timing out; put it back asap
authorMike Karels <karels@ucbvax.Berkeley.EDU>
Tue, 10 Apr 1984 06:05:58 +0000 (22:05 -0800)
committerMike Karels <karels@ucbvax.Berkeley.EDU>
Tue, 10 Apr 1984 06:05:58 +0000 (22:05 -0800)
SCCS-vsn: sbin/routed/input.c 4.7
SCCS-vsn: sbin/routed/main.c 4.9
SCCS-vsn: sbin/routed/output.c 4.5
SCCS-vsn: include/protocols/routed.h 4.11
SCCS-vsn: sbin/routed/table.h 4.2
SCCS-vsn: sbin/routed/tables.c 4.6
SCCS-vsn: sbin/routed/timer.c 4.5
SCCS-vsn: sbin/routed/trace.c 4.6
SCCS-vsn: sbin/routed/trace.h 4.4

usr/src/include/protocols/routed.h
usr/src/sbin/routed/input.c
usr/src/sbin/routed/main.c
usr/src/sbin/routed/output.c
usr/src/sbin/routed/table.h
usr/src/sbin/routed/tables.c
usr/src/sbin/routed/timer.c
usr/src/sbin/routed/trace.c
usr/src/sbin/routed/trace.h

index 9135c32..a51ef3c 100644 (file)
@@ -1,4 +1,4 @@
-/*     routed.h        4.10    83/08/11        */
+/*     routed.h        4.11    84/04/09        */
 /*
  * Routing Information Protocol
  *
 /*
  * Routing Information Protocol
  *
index 5f30b72..058e6f7 100644 (file)
@@ -1,5 +1,5 @@
 #ifndef lint
 #ifndef lint
-static char sccsid[] = "@(#)input.c    4.6 (Berkeley) %G%";
+static char sccsid[] = "@(#)input.c    4.7 (Berkeley) %G%";
 #endif
 
 /*
 #endif
 
 /*
@@ -69,7 +69,7 @@ rip_input(from, size)
 
        case RIPCMD_TRACEON:
        case RIPCMD_TRACEOFF:
 
        case RIPCMD_TRACEON:
        case RIPCMD_TRACEOFF:
-               /* verify message came from a priviledged port */
+               /* verify message came from a privileged port */
                if ((*afp->af_portcheck)(from) == 0)
                        return;
                packet[size] = '\0';
                if ((*afp->af_portcheck)(from) == 0)
                        return;
                packet[size] = '\0';
@@ -88,12 +88,15 @@ rip_input(from, size)
                ifp = if_ifwithaddr(from);
                if (ifp) {
                        rt = rtfind(from);
                ifp = if_ifwithaddr(from);
                if (ifp) {
                        rt = rtfind(from);
-                       if (rt == 0)
+                       if (rt == 0 || (rt->rt_state & RTS_INTERFACE) == 0)
                                addrouteforif(ifp);
                        else
                                rt->rt_timer = 0;
                        return;
                }
                                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;
                size -= 4 * sizeof (char);
                n = msg->rip_nets;
                for (; size > 0; size -= sizeof (struct netinfo), n++) {
                size -= 4 * sizeof (char);
                n = msg->rip_nets;
                for (; size > 0; size -= sizeof (struct netinfo), n++) {
@@ -119,7 +122,7 @@ rip_input(from, size)
                         * stale and equivalent.
                         */
                        if (equal(from, &rt->rt_router) ||
                         * stale and equivalent.
                         */
                        if (equal(from, &rt->rt_router) ||
-                           (unsigned) n->rip_metric < rt->rt_metric ||
+                           (unsigned) (n->rip_metric) < rt->rt_metric ||
                            (rt->rt_timer > (EXPIRE_TIME/2) &&
                            rt->rt_metric == n->rip_metric)) {
                                rtchange(rt, from, n->rip_metric);
                            (rt->rt_timer > (EXPIRE_TIME/2) &&
                            rt->rt_metric == n->rip_metric)) {
                                rtchange(rt, from, n->rip_metric);
index 3eccb1b..dc045bb 100644 (file)
@@ -1,5 +1,5 @@
 #ifndef lint
 #ifndef lint
-static char sccsid[] = "@(#)main.c     4.8 (Berkeley) %G%";
+static char sccsid[] = "@(#)main.c     4.9 (Berkeley) %G%";
 #endif
 
 /*
 #endif
 
 /*
@@ -18,6 +18,7 @@ static char sccsid[] = "@(#)main.c    4.8 (Berkeley) %G%";
 int    supplier = -1;          /* process should supply updates */
 
 struct rip *msg = (struct rip *)packet;
 int    supplier = -1;          /* process should supply updates */
 
 struct rip *msg = (struct rip *)packet;
+int    hup();
 
 main(argc, argv)
        int argc;
 
 main(argc, argv)
        int argc;
@@ -117,6 +118,7 @@ main(argc, argv)
        msg->rip_nets[0].rip_metric = htonl(HOPCNT_INFINITY);
        toall(sendmsg);
        signal(SIGALRM, timer);
        msg->rip_nets[0].rip_metric = htonl(HOPCNT_INFINITY);
        toall(sendmsg);
        signal(SIGALRM, timer);
+       signal(SIGHUP, hup);
        timer();
 
        for (;;) {
        timer();
 
        for (;;) {
index 1a83fb4..49b7fd8 100644 (file)
@@ -1,5 +1,5 @@
 #ifndef lint
 #ifndef lint
-static char sccsid[] = "@(#)output.c   4.4 (Berkeley) %G%";
+static char sccsid[] = "@(#)output.c   4.5 (Berkeley) %G%";
 #endif
 
 /*
 #endif
 
 /*
index bef5283..5a0d197 100644 (file)
@@ -1,4 +1,4 @@
-/*     table.h 4.1     83/01/11        */
+/*     table.h 4.2     84/04/09        */
 
 /*
  * Routing table management daemon.
 
 /*
  * Routing table management daemon.
@@ -49,9 +49,9 @@ struct rt_entry {
  * "State" of routing table entry.
  */
 #define        RTS_CHANGED     0x1             /* route has been altered recently */
  * "State" of routing table entry.
  */
 #define        RTS_CHANGED     0x1             /* route has been altered recently */
-#define        RTS_PASSIVE     0x20            /* don't time out route */
-#define        RTS_INTERFACE   0x40            /* route is for network interface */
-#define        RTS_REMOTE      0x80            /* route is for ``remote'' entity */
+#define        RTS_PASSIVE     IFF_PASSIVE     /* don't time out route */
+#define        RTS_INTERFACE   IFF_INTERFACE   /* route is for network interface */
+#define        RTS_REMOTE      IFF_REMOTE      /* route is for ``remote'' entity */
 
 struct rthash nethash[ROUTEHASHSIZ];
 struct rthash hosthash[ROUTEHASHSIZ];
 
 struct rthash nethash[ROUTEHASHSIZ];
 struct rthash hosthash[ROUTEHASHSIZ];
index 14317a1..94b43ac 100644 (file)
@@ -1,5 +1,5 @@
 #ifndef lint
 #ifndef lint
-static char sccsid[] = "@(#)tables.c   4.5 (Berkeley) %G%";
+static char sccsid[] = "@(#)tables.c   4.6 (Berkeley) %G%";
 #endif
 
 /*
 #endif
 
 /*
@@ -150,27 +150,48 @@ 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 (!equal(&rt->rt_router, gate))
                doioctl++;
-       if (metric != rt->rt_metric) {
+       if (metric != rt->rt_metric)
                metricchanged++;
                metricchanged++;
-               rt->rt_metric = metric;
-       }
        if (doioctl || metricchanged) {
        if (doioctl || metricchanged) {
-               TRACE_ACTION(CHANGE, rt);
+#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;
+                       rt->rt_router = *gate;
+               }
+               rt->rt_metric = metric;
+               rt->rt_state &= ~RTS_INTERFACE;
+               if (metric)
+                       rt->rt_state |= RTF_GATEWAY;
                rt->rt_state |= RTS_CHANGED;
                rt->rt_state |= RTS_CHANGED;
+               TRACE_ACTION(CHANGE TO, rt);
        }
        }
-       if (doioctl) {
-               oldroute = rt->rt_rt;
-               rt->rt_router = *gate;
-               if (install) {
-                       if (ioctl(s, SIOCADDRT, (char *)&rt->rt_rt) < 0)
-                               perror("SIOCADDRT");
-                       if (ioctl(s, SIOCDELRT, (char *)&oldroute) < 0)
-                               perror("SIOCDELRT");
-               }
+       if (doioctl && install) {
+               if (ioctl(s, SIOCADDRT, (char *)&rt->rt_rt) < 0)
+                       perror("SIOCADDRT");
+               if (ioctl(s, SIOCDELRT, (char *)&oldroute) < 0)
+                       perror("SIOCDELRT");
        }
        }
+#ifdef NDEBUG
+       if (turntraceoff)
+               traceoff();
+#endif
 }
 
 rtdelete(rt)
 }
 
 rtdelete(rt)
index 501ce9a..8a8a084 100644 (file)
@@ -1,5 +1,5 @@
 #ifndef lint
 #ifndef lint
-static char sccsid[] = "@(#)timer.c    4.4 (Berkeley) %G%";
+static char sccsid[] = "@(#)timer.c    4.5 (Berkeley) %G%";
 #endif
 
 /*
 #endif
 
 /*
@@ -73,3 +73,30 @@ again:
                toall(supply);
        alarm(TIMER_RATE);
 }
                toall(supply);
        alarm(TIMER_RATE);
 }
+
+/*
+ * On hangup, let everyone know we're going away.
+ */
+hup()
+{
+       register struct rthash *rh;
+       register struct rt_entry *rt;
+       struct rthash *base = hosthash;
+       int doinghost = 1;
+
+       if (supplier) {
+again:
+               for (rh = base; rh < &base[ROUTEHASHSIZ]; rh++) {
+                       rt = rh->rt_forw;
+                       for (; rt != (struct rt_entry *)rh; rt = rt->rt_forw)
+                               rt->rt_metric = HOPCNT_INFINITY;
+               }
+               if (doinghost) {
+                       doinghost = 0;
+                       base = nethash;
+                       goto again;
+               }
+               toall(supply);
+       }
+       exit(1);
+}
index cc058a8..ce3e1d2 100644 (file)
@@ -1,5 +1,5 @@
 #ifndef lint
 #ifndef lint
-static char sccsid[] = "@(#)trace.c    4.5 (Berkeley) %G%";
+static char sccsid[] = "@(#)trace.c    4.6 (Berkeley) %G%";
 #endif
 
 /*
 #endif
 
 /*
@@ -37,6 +37,7 @@ iftraceinit(ifp, ifd)
        if (ifd->ifd_records == 0)
                return (0);
        ifd->ifd_front = ifd->ifd_records;
        if (ifd->ifd_records == 0)
                return (0);
        ifd->ifd_front = ifd->ifd_records;
+       ifd->ifd_count = 0;
        for (t = ifd->ifd_records; t < ifd->ifd_records + NRECORDS; t++) {
                t->ift_size = 0;
                t->ift_packet = 0;
        for (t = ifd->ifd_records; t < ifd->ifd_records + NRECORDS; t++) {
                t->ift_size = 0;
                t->ift_packet = 0;
@@ -82,6 +83,8 @@ trace(ifd, who, p, len, m)
        t = ifd->ifd_front++;
        if (ifd->ifd_front >= ifd->ifd_records + NRECORDS)
                ifd->ifd_front = ifd->ifd_records;
        t = ifd->ifd_front++;
        if (ifd->ifd_front >= ifd->ifd_records + NRECORDS)
                ifd->ifd_front = ifd->ifd_records;
+       if (ifd->ifd_count < NRECORDS)
+               ifd->ifd_count++;
        if (t->ift_size > 0 && t->ift_packet)
                free(t->ift_packet);
        t->ift_packet = 0;
        if (t->ift_size > 0 && t->ift_packet)
                free(t->ift_packet);
        t->ift_packet = 0;
@@ -162,13 +165,13 @@ traceaction(fd, action, rt)
 dumpif(fd, ifp)
        register struct interface *ifp;
 {
 dumpif(fd, ifp)
        register struct interface *ifp;
 {
-       register struct ifdebug *ifd;
-       
-       fprintf(fd, "*** Packet history for interface %s ***\n",
-               ifp->int_name);
-       dumptrace(fd, "to", &ifp->int_output);
-       dumptrace(fd, "from", &ifp->int_output);
-       fprintf(fd, "*** end packet history ***\n");
+       if (ifp->int_input.ifd_count || ifp->int_output.ifd_count) {
+               fprintf(fd, "*** Packet history for interface %s ***\n",
+                       ifp->int_name);
+               dumptrace(fd, "to", &ifp->int_output);
+               dumptrace(fd, "from", &ifp->int_input);
+               fprintf(fd, "*** end packet history ***\n");
+       }
 }
 
 dumptrace(fd, dir, ifd)
 }
 
 dumptrace(fd, dir, ifd)
@@ -185,14 +188,12 @@ dumptrace(fd, dir, ifd)
                return;
        }
        fprintf(fd, "%s trace:\n", cp);
                return;
        }
        fprintf(fd, "%s trace:\n", cp);
-       for (t = ifd->ifd_front; t <= ifd->ifd_records + NRECORDS; t++) {
-               if (t->ift_size == 0)
-                       continue;
-               fprintf(fd, "%.24s: metric=%d\n", ctime(&t->ift_stamp),
-                       t->ift_metric);
-               dumppacket(fd, dir, &t->ift_who, t->ift_packet, t->ift_size);
-       }
-       for (t = ifd->ifd_records; t < ifd->ifd_front; t++) {
+       t = ifd->ifd_front - ifd->ifd_count;
+       if (t < ifd->ifd_records)
+               t += NRECORDS;
+       for ( ; ifd->ifd_count; ifd->ifd_count--, t++) {
+               if (t >= ifd->ifd_records + NRECORDS)
+                       t = ifd->ifd_records;
                if (t->ift_size == 0)
                        continue;
                fprintf(fd, "%.24s: metric=%d\n", ctime(&t->ift_stamp),
                if (t->ift_size == 0)
                        continue;
                fprintf(fd, "%.24s: metric=%d\n", ctime(&t->ift_stamp),
index 48a15e0..3e30358 100644 (file)
@@ -1,4 +1,4 @@
-/*     trace.h 4.3     83/05/25        */
+/*     trace.h 4.4     84/04/09        */
 
 /*
  * Routing table management daemon.
 
 /*
  * Routing table management daemon.
@@ -24,6 +24,7 @@ struct        iftrace {
 struct ifdebug {
        struct  iftrace *ifd_records;   /* array of trace records */
        struct  iftrace *ifd_front;     /* next empty trace record */
 struct ifdebug {
        struct  iftrace *ifd_records;   /* array of trace records */
        struct  iftrace *ifd_front;     /* next empty trace record */
+       int     ifd_count;              /* number of unprinted records */
        struct  interface *ifd_if;      /* for locating stuff */
 };
 
        struct  interface *ifd_if;      /* for locating stuff */
 };