don't send net route to subnet gw's unless on subnet 0;
[unix-history] / usr / src / sbin / routed / trace.c
index ce3e1d2..b86fd04 100644 (file)
@@ -1,12 +1,19 @@
+/*
+ * Copyright (c) 1983 Regents of the University of California.
+ * All rights reserved.  The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ */
+
 #ifndef lint
 #ifndef lint
-static char sccsid[] = "@(#)trace.c    4.6 (Berkeley) %G%";
-#endif
+static char sccsid[] = "@(#)trace.c    5.3 (Berkeley) %G%";
+#endif not lint
 
 /*
  * Routing Table Management Daemon
  */
 #define        RIPCMDS
 #include "defs.h"
 
 /*
  * Routing Table Management Daemon
  */
 #define        RIPCMDS
 #include "defs.h"
+#include <sys/stat.h>
 
 #define        NRECORDS        50              /* size of circular trace buffer */
 #ifdef DEBUG
 
 #define        NRECORDS        50              /* size of circular trace buffer */
 #ifdef DEBUG
@@ -49,9 +56,12 @@ iftraceinit(ifp, ifd)
 traceon(file)
        char *file;
 {
 traceon(file)
        char *file;
 {
+       struct stat stbuf;
 
        if (ftrace != NULL)
                return;
 
        if (ftrace != NULL)
                return;
+       if (stat(file, &stbuf) >= 0 && (stbuf.st_mode & S_IFMT) != S_IFREG)
+               return;
        ftrace = fopen(file, "a");
        if (ftrace == NULL)
                return;
        ftrace = fopen(file, "a");
        if (ftrace == NULL)
                return;
@@ -85,18 +95,19 @@ trace(ifd, who, p, len, m)
                ifd->ifd_front = ifd->ifd_records;
        if (ifd->ifd_count < NRECORDS)
                ifd->ifd_count++;
                ifd->ifd_front = ifd->ifd_records;
        if (ifd->ifd_count < NRECORDS)
                ifd->ifd_count++;
-       if (t->ift_size > 0 && t->ift_packet)
+       if (t->ift_size > 0 && t->ift_size < len && t->ift_packet) {
                free(t->ift_packet);
                free(t->ift_packet);
-       t->ift_packet = 0;
+               t->ift_packet = 0;
+       }
        t->ift_stamp = time(0);
        t->ift_who = *who;
        t->ift_stamp = time(0);
        t->ift_who = *who;
-       if (len > 0) {
+       if (len > 0 && t->ift_packet == 0) {
                t->ift_packet = malloc(len);
                t->ift_packet = malloc(len);
-               if (t->ift_packet)
-                       bcopy(p, t->ift_packet, len);
-               else
+               if (t->ift_packet == 0)
                        len = 0;
        }
                        len = 0;
        }
+       if (len > 0)
+               bcopy(p, t->ift_packet, len);
        t->ift_size = len;
        t->ift_metric = m;
 }
        t->ift_size = len;
        t->ift_metric = m;
 }
@@ -120,6 +131,9 @@ traceaction(fd, action, rt)
                { RTS_REMOTE,   "REMOTE" },
                { RTS_INTERFACE,"INTERFACE" },
                { RTS_CHANGED,  "CHANGED" },
                { RTS_REMOTE,   "REMOTE" },
                { RTS_INTERFACE,"INTERFACE" },
                { RTS_CHANGED,  "CHANGED" },
+               { RTS_INTERNAL, "INTERNAL" },
+               { RTS_EXTERNAL, "EXTERNAL" },
+               { RTS_SUBNET,   "SUBNET" },
                { 0 }
        };
        register struct bits *p;
                { 0 }
        };
        register struct bits *p;
@@ -172,6 +186,7 @@ dumpif(fd, ifp)
                dumptrace(fd, "from", &ifp->int_input);
                fprintf(fd, "*** end packet history ***\n");
        }
                dumptrace(fd, "from", &ifp->int_input);
                fprintf(fd, "*** end packet history ***\n");
        }
+       fflush(fd);
 }
 
 dumptrace(fd, dir, ifd)
 }
 
 dumptrace(fd, dir, ifd)
@@ -185,6 +200,7 @@ dumptrace(fd, dir, ifd)
        if (ifd->ifd_front == ifd->ifd_records &&
            ifd->ifd_front->ift_size == 0) {
                fprintf(fd, "%s: no packets.\n", cp);
        if (ifd->ifd_front == ifd->ifd_records &&
            ifd->ifd_front->ift_size == 0) {
                fprintf(fd, "%s: no packets.\n", cp);
+               fflush(fd);
                return;
        }
        fprintf(fd, "%s trace:\n", cp);
                return;
        }
        fprintf(fd, "%s trace:\n", cp);
@@ -218,6 +234,7 @@ dumppacket(fd, dir, who, cp, size)
                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, "size=%d cp=%x packet=%x\n", size, cp, packet);
                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, "size=%d cp=%x packet=%x\n", size, cp, packet);
+               fflush(fd);
                return;
        }
        switch (msg->rip_cmd) {
                return;
        }
        switch (msg->rip_cmd) {
@@ -245,4 +262,5 @@ dumppacket(fd, dir, who, cp, size)
                fprintf(fd, "\n");
                break;
        }
                fprintf(fd, "\n");
                break;
        }
+       fflush(fd);
 }
 }