*** empty log message ***
authorMatthew Mondor <mmondor@pulsar-zone.net>
Wed, 26 Dec 2007 17:32:09 +0000 (17:32 +0000)
committerMatthew Mondor <mmondor@pulsar-zone.net>
Wed, 26 Dec 2007 17:32:09 +0000 (17:32 +0000)
mmsoftware/tap-bridge/modules/tap-logger.c

index 0c9deb1..0399bcb 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: tap-logger.c,v 1.9 2007/12/26 16:23:21 mmondor Exp $ */
+/* $Id: tap-logger.c,v 1.10 2007/12/26 17:32:09 mmondor Exp $ */
 
 /*
  * Copyright (C) 2007, Matthew Mondor
@@ -49,6 +49,7 @@ static bool           mod_recv_ext(tap_t *, fnode_t *);
 static void            mod_exit(void);
 
 static void            logprintf(const char *, ...);
+static void            logdata(const void *, size_t, int);
 static void            frame_log(frame_t *, int);
 
 
@@ -126,6 +127,40 @@ logprintf(const char *fmt, ...)
        va_end(lst);
 }
 
+/*
+ * XXX We could make this more fancy but that's allright for now.
+ */
+static void
+logdata(const void *data, size_t len, int margin)
+{
+       static char     pad[80] = "                                        "
+                                 "                                        ";
+       const uint8_t   *dptr, *dtptr;
+       int             col = 80;
+       bool            first = true;
+
+       if (margin > 70)
+               margin = 70;
+       pad[margin] = '\0';
+
+       for (dptr = data, dtptr = &dptr[len]; dptr < dtptr; dptr++) {
+               if (col > 80 - 12) {
+                       if (!first)
+                               logprintf("\n%s", pad);
+                       else {
+                               logprintf("%s", pad);
+                               first = false;
+                       }
+                       col = margin;
+               }
+               logprintf("%02x ", *dptr);
+               col += 3;
+       }
+       logprintf("\n");
+
+       pad[margin] = ' ';
+}
+
 static void
 frame_log(frame_t *f, int d)
 {
@@ -188,6 +223,16 @@ frame_log(frame_t *f, int d)
                            BYTEORDER_HOST32(hdr->tpa));
                } else
                        logprintf("       Unsupported ARP packet type\n");
+
+               /* Extra payload, if any */
+               if (f->size > sizeof(struct hdr_tap) +
+                   sizeof(struct hdr_arp_p4h)) {
+                       logprintf("       EXTRA PAYLOAD:\n");
+                       logdata(f->data + sizeof(struct hdr_tap) +
+                           sizeof(struct hdr_arp_p4h), f->size -
+                           sizeof(struct hdr_tap) -
+                           sizeof(struct hdr_arp_p4h), 8);
+               }
                return;
        }
 
@@ -227,7 +272,7 @@ frame_log(frame_t *f, int d)
                        uint32_t        *optword;
 
                        /* XXX IP options */
-                       logprintf("      IP OPTIONS:\n");
+                       logprintf("      IP Options:\n");
                        for (optword = &((uint32_t *)hdrip)[5];
                            optword < (uint32_t *)ahdrip; optword++)
                                logprintf("       0x%08x\n",
@@ -251,7 +296,14 @@ frame_log(frame_t *f, int d)
                            BYTEORDER_HOST16(hdricmp->id),
                            BYTEORDER_HOST16(hdricmp->seq));
 
-                       /* XXX ICMP padding payload */
+                       /* ICMP padding payload, if any */
+                       if (f->size > (uint8_t *)(ahdrip +
+                           sizeof(struct hdr_icmp)) - f->data) {
+                               logprintf("        ICMP Padding:\n");
+                               logdata(ahdrip + sizeof(struct hdr_icmp),
+                                   f->size - ((uint8_t *)(ahdrip +
+                                   sizeof(struct hdr_icmp)) - f->data), 9); 
+                       }
                        return;
                }
 
@@ -300,19 +352,25 @@ frame_log(frame_t *f, int d)
                                uint32_t        *optword;
 
                                /* XXX TCP options */
-                               logprintf("       TCP OPTIONS:\n");
+                               logprintf("       TCP Options:\n");
                                for (optword = &((uint32_t *)hdrtcp)[5];
                                    optword < (uint32_t *)ahdrtcp; optword++)
                                        logprintf("        0x%08x\n",
                                            BYTEORDER_HOST32(*optword));
                        }
 
-                       /* XXX TCP payload */
+                       /* TCP payload */
+                       if (f->size > ((uint8_t *)ahdrtcp - f->data)) {
+                               logprintf("       TCP Payload:\n");
+                               logdata(ahdrtcp, f->size -
+                                   ((uint8_t *)ahdrtcp - f->data), 8);
+                       }
                        return;
                }
 
                if (hdrip->protocol == HDR_IP_PROTO_UDP) {
                        struct hdr_udp  *hdrudp;
+                       void            *ahdrudp;
 
                        if (f->size < (ahdrip - (void *)f->data) +
                            sizeof(struct hdr_udp)) {
@@ -328,7 +386,14 @@ frame_log(frame_t *f, int d)
                            BYTEORDER_HOST16(hdrudp->len),
                            BYTEORDER_HOST16(hdrudp->hsum));
 
-                       /* XXX UDP payload */
+                       ahdrudp = hdrudp + sizeof(struct hdr_udp);
+
+                       /* UDP payload */
+                       if (f->size > ((uint8_t *)ahdrudp - f->data)) {
+                               logprintf("       UDP Payload:\n");
+                               logdata(ahdrudp, f->size -
+                                   ((uint8_t *)ahdrudp - f->data), 8);
+                       }
                        return;
                }