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

index 3406f6a..204b036 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: tap-logger.c,v 1.6 2007/12/24 03:35:16 mmondor Exp $ */
+/* $Id: tap-logger.c,v 1.7 2007/12/24 17:31:32 mmondor Exp $ */
 
 /*
  * Copyright (C) 2007, Matthew Mondor
@@ -140,7 +140,7 @@ frame_log(frame_t *f, int d)
 
        (void) macaddr_string(origin, 31, &f->origin);
        (void) macaddr_string(destination, 31, &f->destination);
-       logprintf("%c src=%s, dst=%s etype=%04x size=%u\n",
+       logprintf("%c src=%s dst=%s etype=%04x size=%u\n",
            d, origin, destination, f->type, f->size);
 
        /*
@@ -149,6 +149,7 @@ frame_log(frame_t *f, int d)
         */
        if (f->type == HDR_TAP_ETYPE_ARP) {
                struct hdr_arp *hdrarp;
+               uint16_t        htype, ptype;
 
                if (f->size < sizeof(struct hdr_tap) +
                    sizeof(struct hdr_arp)) {
@@ -156,8 +157,37 @@ frame_log(frame_t *f, int d)
                        return;
                }
                hdrarp = ahdrtap;
-               /* XXX */
 
+               htype = BYTEORDER_HOST16(hdrarp->htype);
+               ptype = BYTEORDER_HOST16(hdrarp->ptype);
+
+               logprintf("  ARP: htype=0x%04x ptype=0x%04x hlen=%u plen=%u "
+                   "oper=%d\n",
+                   htype, ptype, hdrarp->hlen, hdrarp->plen,
+                   BYTEORDER_HOST16(hdrarp->oper));
+               if (htype == HDR_ARP_HTYPE_ETHERNET &&
+                   ptype == HDR_ARP_PTYPE_IPV4 &&
+                   hdrarp->hlen == 6 && hdrarp->plen == 4) {
+                       struct hdr_arp_p4h      *hdr;
+
+                       if (f->size < sizeof(struct hdr_tap) +
+                           sizeof(struct hdr_arp_p4h)) {
+                               logprintf("       Short header\n");
+                               return;
+                       }
+
+                       hdr = ahdrtap;
+                       logprintf("       sha=%02x:%02x:%02x:%02x:%02x:%02x "
+                           "spa=0x%08x\n       "
+                           "tha=%02x:%02x:%02x:%02x:%02x:%02x tpa=0x%08x\n",
+                           hdr->sha[0], hdr->sha[1], hdr->sha[2],
+                           hdr->sha[3], hdr->sha[4], hdr->sha[5],
+                           BYTEORDER_HOST32(hdr->spa),
+                           hdr->tha[0], hdr->tha[1], hdr->tha[2],
+                           hdr->tha[3], hdr->tha[4], hdr->tha[5],
+                           BYTEORDER_HOST32(hdr->tpa));
+               } else
+                       logprintf("       Unsupported ARP packet type\n");
                return;
        }
 
@@ -175,7 +205,7 @@ frame_log(frame_t *f, int d)
 
                ver = HDR_IP_VER_GET(hdrip->ver_hlen);
                hlen = HDR_IP_HLEN_GET(hdrip->ver_hlen);
-               if (hlen < 4) {
+               if (hlen < 5) {
                        logprintf("  Short IP header length (%d)\n", hlen);
                        return;
                }
@@ -185,17 +215,64 @@ frame_log(frame_t *f, int d)
                flags = HDR_IP_FLAGS_GET(t16);
                off = HDR_IP_OFF_GET(t16);
 
-               /* XXX */
+               logprintf("  IP: ver=%d hlen=%d tos=%u len=%u id=0x%04x "
+                   "flags=0x%01x off=%d ttl=%u proto=%u\n      "
+                   "hsum=0x%04x srcaddr=0x%08x dstaddr=0x%08x\n",
+                   ver, hlen, hdrip->tos, BYTEORDER_HOST16(hdrip->len),
+                   BYTEORDER_HOST16(hdrip->id), flags, off, hdrip->ttl,
+                   hdrip->protocol, BYTEORDER_HOST16(hdrip->hsum),
+                   BYTEORDER_HOST32(hdrip->srcaddr),
+                   BYTEORDER_HOST32(hdrip->dstaddr));
+               if (hlen > 5) {
+                       uint32_t        *optword;
+
+                       /* IP options */
+                       logprintf("      IP OPTIONS:\n");
+                       for (optword = &((uint32_t *)hdrip)[5];
+                           optword < (uint32_t *)ahdrip; optword++)
+                               logprintf("       0x%08x\n", *optword);
+               }
 
-               if (hdrip->protocol == HDR_IP_PROTO_UDP) {
+               if (hdrip->protocol == HDR_IP_PROTO_ICMP) {
+                       struct hdr_icmp *hdricmp;
+
+                       if (f->size < (ahdrip - (void *)f->data) +
+                           sizeof(struct hdr_icmp)) {
+                               logprintf("  Short ICMP header\n");
+                               return;
+                       }
+
+                       hdricmp = ahdrip;
+                       logprintf("  ICMP: type=%u code=%u hsum=0x%04x "
+                           "id=0x%04x seq=0x%04x\n",
+                           hdricmp->type, hdricmp->code,
+                           BYTEORDER_HOST16(hdricmp->hsum),
+                           BYTEORDER_HOST16(hdricmp->id),
+                           BYTEORDER_HOST16(hdricmp->seq));
                        return;
                }
 
                if (hdrip->protocol == HDR_IP_PROTO_TCP) {
+                       /* XXX */
                        return;
                }
 
-               if (hdrip->protocol == HDR_IP_PROTO_ICMP) {
+               if (hdrip->protocol == HDR_IP_PROTO_UDP) {
+                       struct hdr_udp  *hdrudp;
+
+                       if (f->size < (ahdrip - (void *)f->data) +
+                           sizeof(struct hdr_udp)) {
+                               logprintf("  Short UDP header\n");
+                               return;
+                       }
+
+                       hdrudp = ahdrip;
+                       logprintf("  UDP: srcport=%u dstport=%u len=%u "
+                           "hsum=0x%04x\n",
+                           BYTEORDER_HOST16(hdrudp->srcport),
+                           BYTEORDER_HOST16(hdrudp->dstport),
+                           BYTEORDER_HOST16(hdrudp->len),
+                           BYTEORDER_HOST16(hdrudp->hsum));
                        return;
                }
 
index 9b2fc62..89aed3a 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: tap-headers.h,v 1.2 2007/12/20 01:32:19 mmondor Exp $ */
+/* $Id: tap-headers.h,v 1.3 2007/12/24 17:31:32 mmondor Exp $ */
 
 /*
  * Copyright (C) 2007, Matthew Mondor
@@ -80,6 +80,9 @@ struct hdr_arp {
        uint16_t                oper;
 } __attribute__((__packed__));
 
+#define HDR_ARP_HTYPE_ETHERNET 0x0001
+#define HDR_ARP_PTYPE_IPV4     0x0800
+
 /* IPv4 -> MAC address resolution */
 struct hdr_arp_p4h {
        struct hdr_arp          hdr;
@@ -128,9 +131,9 @@ struct hdr_ip {
        /* Followed with options if any then by protocol-specific header */
 } __attribute__((__packed__));
 
-#define HDR_IP_PROTO_UDP       0x01
+#define HDR_IP_PROTO_ICMP      0x01
 #define HDR_IP_PROTO_TCP       0x06
-#define HDR_IP_PROTO_ICMP      0x11
+#define HDR_IP_PROTO_UDP       0x11
 
 /* Options are 32-bit padded but have an 16-bit header */
 struct hdr_ip_opt {
@@ -145,16 +148,6 @@ struct hdr_ip_opt {
        /* Followed by 32-bit padded variable size data */
 } __attribute__((__packed__));
 
-/* ICMP, after hdr_ip and options */
-struct hdr_icmp {
-       uint8_t                 type;
-       uint8_t                 code;
-       uint16_t                hsum;
-       uint16_t                id;
-       uint16_t                seq;
-       /* Followed with arbitrary data */
-} __attribute__((__packed__));
-
 /* UDP, after hdr_ip and options */
 struct hdr_udp {
        uint16_t                srcport;
@@ -186,5 +179,15 @@ struct hdr_tcp_opt {
        /* XXX */
 } __attribute__((__packed__));
 
+/* ICMP, after hdr_ip and options */
+struct hdr_icmp {
+       uint8_t                 type;
+       uint8_t                 code;
+       uint16_t                hsum;
+       uint16_t                id;
+       uint16_t                seq;
+       /* Followed with arbitrary data */
+} __attribute__((__packed__));
+
 
 #endif