From: Mike Karels Date: Tue, 10 Apr 1984 06:05:58 +0000 (-0800) Subject: many cleanups; avoid interface timing out; put it back asap X-Git-Tag: BSD-4_3-Snapshot-Development~10148 X-Git-Url: https://git.subgeniuskitty.com/unix-history/.git/commitdiff_plain/b7e4f8be39c6136d120979447c3e6d5667014f18 many cleanups; avoid interface timing out; put it back asap 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 --- diff --git a/usr/src/include/protocols/routed.h b/usr/src/include/protocols/routed.h index 9135c329fc..a51ef3cdb5 100644 --- a/usr/src/include/protocols/routed.h +++ b/usr/src/include/protocols/routed.h @@ -1,4 +1,4 @@ -/* routed.h 4.10 83/08/11 */ +/* routed.h 4.11 84/04/09 */ /* * Routing Information Protocol * diff --git a/usr/src/sbin/routed/input.c b/usr/src/sbin/routed/input.c index 5f30b72c17..058e6f7c61 100644 --- a/usr/src/sbin/routed/input.c +++ b/usr/src/sbin/routed/input.c @@ -1,5 +1,5 @@ #ifndef lint -static char sccsid[] = "@(#)input.c 4.6 (Berkeley) %G%"; +static char sccsid[] = "@(#)input.c 4.7 (Berkeley) %G%"; #endif /* @@ -69,7 +69,7 @@ rip_input(from, size) 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'; @@ -88,12 +88,15 @@ rip_input(from, size) 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; } + /* 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++) { @@ -119,7 +122,7 @@ rip_input(from, size) * 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); diff --git a/usr/src/sbin/routed/main.c b/usr/src/sbin/routed/main.c index 3eccb1bc32..dc045bbcda 100644 --- a/usr/src/sbin/routed/main.c +++ b/usr/src/sbin/routed/main.c @@ -1,5 +1,5 @@ #ifndef lint -static char sccsid[] = "@(#)main.c 4.8 (Berkeley) %G%"; +static char sccsid[] = "@(#)main.c 4.9 (Berkeley) %G%"; #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 hup(); 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); + signal(SIGHUP, hup); timer(); for (;;) { diff --git a/usr/src/sbin/routed/output.c b/usr/src/sbin/routed/output.c index 1a83fb41a0..49b7fd8107 100644 --- a/usr/src/sbin/routed/output.c +++ b/usr/src/sbin/routed/output.c @@ -1,5 +1,5 @@ #ifndef lint -static char sccsid[] = "@(#)output.c 4.4 (Berkeley) %G%"; +static char sccsid[] = "@(#)output.c 4.5 (Berkeley) %G%"; #endif /* diff --git a/usr/src/sbin/routed/table.h b/usr/src/sbin/routed/table.h index bef5283a48..5a0d197797 100644 --- a/usr/src/sbin/routed/table.h +++ b/usr/src/sbin/routed/table.h @@ -1,4 +1,4 @@ -/* table.h 4.1 83/01/11 */ +/* table.h 4.2 84/04/09 */ /* * 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 */ -#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]; diff --git a/usr/src/sbin/routed/tables.c b/usr/src/sbin/routed/tables.c index 14317a14a6..94b43acbbd 100644 --- a/usr/src/sbin/routed/tables.c +++ b/usr/src/sbin/routed/tables.c @@ -1,5 +1,5 @@ #ifndef lint -static char sccsid[] = "@(#)tables.c 4.5 (Berkeley) %G%"; +static char sccsid[] = "@(#)tables.c 4.6 (Berkeley) %G%"; #endif /* @@ -150,27 +150,48 @@ rtchange(rt, gate, metric) { 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) { + if (metric != rt->rt_metric) metricchanged++; - rt->rt_metric = metric; - } 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; + 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) diff --git a/usr/src/sbin/routed/timer.c b/usr/src/sbin/routed/timer.c index 501ce9ad9f..8a8a0849d9 100644 --- a/usr/src/sbin/routed/timer.c +++ b/usr/src/sbin/routed/timer.c @@ -1,5 +1,5 @@ #ifndef lint -static char sccsid[] = "@(#)timer.c 4.4 (Berkeley) %G%"; +static char sccsid[] = "@(#)timer.c 4.5 (Berkeley) %G%"; #endif /* @@ -73,3 +73,30 @@ again: 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); +} diff --git a/usr/src/sbin/routed/trace.c b/usr/src/sbin/routed/trace.c index cc058a88e8..ce3e1d2acd 100644 --- a/usr/src/sbin/routed/trace.c +++ b/usr/src/sbin/routed/trace.c @@ -1,5 +1,5 @@ #ifndef lint -static char sccsid[] = "@(#)trace.c 4.5 (Berkeley) %G%"; +static char sccsid[] = "@(#)trace.c 4.6 (Berkeley) %G%"; #endif /* @@ -37,6 +37,7 @@ iftraceinit(ifp, ifd) 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; @@ -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; + if (ifd->ifd_count < NRECORDS) + ifd->ifd_count++; 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; { - 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) @@ -185,14 +188,12 @@ dumptrace(fd, dir, ifd) 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), diff --git a/usr/src/sbin/routed/trace.h b/usr/src/sbin/routed/trace.h index 48a15e0a93..3e30358a88 100644 --- a/usr/src/sbin/routed/trace.h +++ b/usr/src/sbin/routed/trace.h @@ -1,4 +1,4 @@ -/* trace.h 4.3 83/05/25 */ +/* trace.h 4.4 84/04/09 */ /* * 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 */ + int ifd_count; /* number of unprinted records */ struct interface *ifd_if; /* for locating stuff */ };