add ability to trace changes only, with timestamp; even up output fields
authorMike Karels <karels@ucbvax.Berkeley.EDU>
Wed, 1 Jun 1988 02:52:10 +0000 (18:52 -0800)
committerMike Karels <karels@ucbvax.Berkeley.EDU>
Wed, 1 Jun 1988 02:52:10 +0000 (18:52 -0800)
SCCS-vsn: sbin/routed/trace.c 5.5
SCCS-vsn: sbin/routed/trace.h 5.4

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

index dca8fd2..cdc8e27 100644 (file)
@@ -1,5 +1,5 @@
 /*
 /*
- * Copyright (c) 1983 Regents of the University of California.
+ * Copyright (c) 1983, 1988 Regents of the University of California.
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms are permitted
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms are permitted
@@ -11,7 +11,7 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)trace.c    5.4 (Berkeley) %G%";
+static char sccsid[] = "@(#)trace.c    5.5 (Berkeley) %G%";
 #endif /* not lint */
 
 /*
 #endif /* not lint */
 
 /*
@@ -20,11 +20,12 @@ static char sccsid[] = "@(#)trace.c 5.4 (Berkeley) %G%";
 #define        RIPCMDS
 #include "defs.h"
 #include <sys/stat.h>
 #define        RIPCMDS
 #include "defs.h"
 #include <sys/stat.h>
+#include <sys/signal.h>
 
 #define        NRECORDS        50              /* size of circular trace buffer */
 #ifdef DEBUG
 FILE   *ftrace = stdout;
 
 #define        NRECORDS        50              /* size of circular trace buffer */
 #ifdef DEBUG
 FILE   *ftrace = stdout;
-int    tracing = 1;
+int    traceactions = 1;
 #endif
 
 traceinit(ifp)
 #endif
 
 traceinit(ifp)
@@ -34,7 +35,7 @@ traceinit(ifp)
        if (iftraceinit(ifp, &ifp->int_input) &&
            iftraceinit(ifp, &ifp->int_output))
                return;
        if (iftraceinit(ifp, &ifp->int_input) &&
            iftraceinit(ifp, &ifp->int_output))
                return;
-       tracing = 0;
+       tracehistory = 0;
        fprintf(stderr, "traceinit: can't init %s\n", ifp->int_name);
 }
 
        fprintf(stderr, "traceinit: can't init %s\n", ifp->int_name);
 }
 
@@ -73,17 +74,34 @@ traceon(file)
                return;
        dup2(fileno(ftrace), 1);
        dup2(fileno(ftrace), 2);
                return;
        dup2(fileno(ftrace), 1);
        dup2(fileno(ftrace), 2);
-       tracing = 1;
+       traceactions = 1;
 }
 
 traceoff()
 {
 }
 
 traceoff()
 {
-       if (!tracing)
+       if (!traceactions)
                return;
        if (ftrace != NULL)
                fclose(ftrace);
        ftrace = NULL;
                return;
        if (ftrace != NULL)
                fclose(ftrace);
        ftrace = NULL;
-       tracing = 0;
+       traceactions = 0;
+       tracehistory = 0;
+}
+
+sigtrace(s)
+       int s;
+{
+       if (s == SIGUSR2) {
+               traceoff();
+               tracepackets = 0;
+       } else if (traceactions == 0)
+               traceactions++;
+       else if (tracehistory == 0)
+               tracehistory++;
+       else {
+               tracepackets++;
+               tracehistory = 0;
+       }
 }
 
 trace(ifd, who, p, len, m)
 }
 
 trace(ifd, who, p, len, m)
@@ -149,6 +167,10 @@ traceaction(fd, action, rt)
 
        if (fd == NULL)
                return;
 
        if (fd == NULL)
                return;
+       if (curtime) {
+               fprintf(fd, "\n%s", curtime);
+               curtime = NULL;
+       }
        fprintf(fd, "%s ", action);
        dst = (struct sockaddr_in *)&rt->rt_dst;
        gate = (struct sockaddr_in *)&rt->rt_router;
        fprintf(fd, "%s ", action);
        dst = (struct sockaddr_in *)&rt->rt_dst;
        gate = (struct sockaddr_in *)&rt->rt_router;
@@ -176,19 +198,38 @@ traceaction(fd, action, rt)
                        first = 0;
                }
        }
                        first = 0;
                }
        }
-       putc('\n', fd);
+       fprintf(fd, " timer %d\n", rt->rt_timer);
        if (!tracepackets && (rt->rt_state & RTS_PASSIVE) == 0 && rt->rt_ifp)
                dumpif(fd, rt->rt_ifp);
        fflush(fd);
 }
 
        if (!tracepackets && (rt->rt_state & RTS_PASSIVE) == 0 && rt->rt_ifp)
                dumpif(fd, rt->rt_ifp);
        fflush(fd);
 }
 
+tracenewmetric(fd, rt, newmetric)
+       FILE *fd;
+       struct rt_entry *rt;
+       int newmetric;
+{
+       struct sockaddr_in *dst, *gate;
+
+       if (fd == NULL)
+               return;
+       dst = (struct sockaddr_in *)&rt->rt_dst;
+       gate = (struct sockaddr_in *)&rt->rt_router;
+       fprintf(fd, "CHANGE metric dst %s, ", inet_ntoa(dst->sin_addr));
+       fprintf(fd, "router %s, from %d to %d\n",
+            inet_ntoa(gate->sin_addr), rt->rt_metric, newmetric);
+       fflush(fd);
+}
+
 dumpif(fd, ifp)
        register struct interface *ifp;
 {
        if (ifp->int_input.ifd_count || ifp->int_output.ifd_count) {
                fprintf(fd, "*** Packet history for interface %s ***\n",
                        ifp->int_name);
 dumpif(fd, ifp)
        register struct interface *ifp;
 {
        if (ifp->int_input.ifd_count || ifp->int_output.ifd_count) {
                fprintf(fd, "*** Packet history for interface %s ***\n",
                        ifp->int_name);
+#ifdef notneeded
                dumptrace(fd, "to", &ifp->int_output);
                dumptrace(fd, "to", &ifp->int_output);
+#endif
                dumptrace(fd, "from", &ifp->int_input);
                fprintf(fd, "*** end packet history ***\n");
        }
                dumptrace(fd, "from", &ifp->int_input);
                fprintf(fd, "*** end packet history ***\n");
        }
@@ -218,17 +259,17 @@ dumptrace(fd, dir, ifd)
                        t = ifd->ifd_records;
                if (t->ift_size == 0)
                        continue;
                        t = ifd->ifd_records;
                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);
+               dumppacket(fd, dir, &t->ift_who, t->ift_packet, t->ift_size,
+                   &t->ift_stamp);
        }
 }
 
        }
 }
 
-dumppacket(fd, dir, who, cp, size)
+dumppacket(fd, dir, who, cp, size, tstamp)
        FILE *fd;
        struct sockaddr_in *who;                /* should be sockaddr */
        char *dir, *cp;
        register int size;
        FILE *fd;
        struct sockaddr_in *who;                /* should be sockaddr */
        char *dir, *cp;
        register int size;
+       time_t *tstamp;
 {
        register struct rip *msg = (struct rip *)cp;
        register struct netinfo *n;
 {
        register struct rip *msg = (struct rip *)cp;
        register struct netinfo *n;
@@ -237,17 +278,18 @@ dumppacket(fd, dir, who, cp, size)
                fprintf(fd, "%s %s %s.%d", ripcmds[msg->rip_cmd],
                    dir, inet_ntoa(who->sin_addr), ntohs(who->sin_port));
        else {
                fprintf(fd, "%s %s %s.%d", ripcmds[msg->rip_cmd],
                    dir, inet_ntoa(who->sin_addr), ntohs(who->sin_port));
        else {
-               fprintf(fd, "Bad cmd 0x%x %s %x.%d\n", msg->rip_cmd,
-                   dir, inet_ntoa(who->sin_addr), ntohs(who->sin_port));
+               fprintf(fd, "Bad cmd 0x%x %s %x.%d %.24s\n", msg->rip_cmd,
+                   dir, inet_ntoa(who->sin_addr), ntohs(who->sin_port),
+                   ctime(tstamp));
                fprintf(fd, "size=%d cp=%x packet=%x\n", size, cp, packet);
                fflush(fd);
                return;
        }
                fprintf(fd, "size=%d cp=%x packet=%x\n", size, cp, packet);
                fflush(fd);
                return;
        }
+       fprintf(fd, " %.24s:\n", ctime(tstamp));
        switch (msg->rip_cmd) {
 
        case RIPCMD_REQUEST:
        case RIPCMD_RESPONSE:
        switch (msg->rip_cmd) {
 
        case RIPCMD_REQUEST:
        case RIPCMD_RESPONSE:
-               fprintf(fd, ":\n");
                size -= 4 * sizeof (char);
                n = msg->rip_nets;
                for (; size > 0; n++, size -= sizeof (struct netinfo)) {
                size -= 4 * sizeof (char);
                n = msg->rip_nets;
                for (; size > 0; n++, size -= sizeof (struct netinfo)) {
@@ -261,11 +303,10 @@ dumppacket(fd, dir, who, cp, size)
                break;
 
        case RIPCMD_TRACEON:
                break;
 
        case RIPCMD_TRACEON:
-               fprintf(fd, "file=%*s\n", size, msg->rip_tracefile);
+               fprintf(fd, "\tfile=%*s\n", size, msg->rip_tracefile);
                break;
 
        case RIPCMD_TRACEOFF:
                break;
 
        case RIPCMD_TRACEOFF:
-               fprintf(fd, "\n");
                break;
        }
        fflush(fd);
                break;
        }
        fflush(fd);
index 3046d0f..1d0903a 100644 (file)
@@ -1,5 +1,5 @@
 /*
 /*
- * Copyright (c) 1983 Regents of the University of California.
+ * Copyright (c) 1983, 1988 Regents of the University of California.
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms are permitted
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms are permitted
@@ -9,7 +9,7 @@
  * software without specific prior written permission. This software
  * is provided ``as is'' without express or implied warranty.
  *
  * software without specific prior written permission. This software
  * is provided ``as is'' without express or implied warranty.
  *
- *     @(#)trace.h     5.3 (Berkeley) %G%
+ *     @(#)trace.h     5.4 (Berkeley) %G%
  */
 
 /*
  */
 
 /*
@@ -44,26 +44,38 @@ struct      ifdebug {
  * Packet tracing stuff.
  */
 int    tracepackets;           /* watch packets as they go by */
  * Packet tracing stuff.
  */
 int    tracepackets;           /* watch packets as they go by */
-int    tracing;                /* on/off */
+int    traceactions;           /* on/off */
+int    tracehistory;           /* on/off */
 FILE   *ftrace;                /* output trace file */
 FILE   *ftrace;                /* output trace file */
+char   *curtime;               /* current timestamp string */
 
 #define        TRACE_ACTION(action, route) { \
 
 #define        TRACE_ACTION(action, route) { \
-         if (tracing) \
-               traceaction(ftrace, "action", route); \
+         if (traceactions) \
+               traceaction(ftrace, action, route); \
+       }
+#define        TRACE_NEWMETRIC(route, newmetric) { \
+         if (traceactions) \
+               tracenewmetric(ftrace, route, newmetric); \
        }
 #define        TRACE_INPUT(ifp, src, size) { \
        }
 #define        TRACE_INPUT(ifp, src, size) { \
-         if (tracing) { \
+         if (tracehistory) { \
                ifp = if_iflookup(src); \
                if (ifp) \
                        trace(&ifp->int_input, src, packet, size, \
                                ntohl(ifp->int_metric)); \
          } \
                ifp = if_iflookup(src); \
                if (ifp) \
                        trace(&ifp->int_input, src, packet, size, \
                                ntohl(ifp->int_metric)); \
          } \
-         if (tracepackets) \
-               dumppacket(stdout, "from", src, packet, size); \
+         if (tracepackets) { \
+               time_t t; \
+               t = time(0); \
+               dumppacket(stdout, "from", src, packet, size, &t); \
+         } \
        }
 #define        TRACE_OUTPUT(ifp, dst, size) { \
        }
 #define        TRACE_OUTPUT(ifp, dst, size) { \
-         if (tracing && ifp) \
+         if (tracehistory && ifp) \
                trace(&ifp->int_output, dst, packet, size, ifp->int_metric); \
                trace(&ifp->int_output, dst, packet, size, ifp->int_metric); \
-         if (tracepackets) \
-               dumppacket(stdout, "to", dst, packet, size); \
+         if (tracepackets) { \
+               time_t t; \
+               t = time(0); \
+               dumppacket(stdout, "to", dst, packet, size, &t); \
+         } \
        }
        }