]> The Tcpdump Group git mirrors - tcpdump/commitdiff
NDOize AHCP, OTV and VXLAN decoders
authorDenis Ovsienko <[email protected]>
Sat, 8 Mar 2014 11:28:13 +0000 (15:28 +0400)
committerDenis Ovsienko <[email protected]>
Sat, 8 Mar 2014 12:30:30 +0000 (16:30 +0400)
interface.h
netdissect.h
print-ahcp.c
print-otv.c
print-udp.c
print-vxlan.c

index e00748af8edf829fe8aa2533f3191c4d34e65a95..d8b41c93479aec5e7d8992c8b74cb1345be09bc3 100644 (file)
@@ -321,9 +321,6 @@ extern void syslog_print(const u_char *, u_int);
 extern int mptcp_print(const u_char *, u_int, u_char);
 extern u_int usb_linux_48_byte_print(const struct pcap_pkthdr *, const u_char *);
 extern u_int usb_linux_64_byte_print(const struct pcap_pkthdr *, const u_char *);
-extern void vxlan_print(const u_char *, u_int);
-extern void otv_print(const u_char *, u_int);
-extern void ahcp_print(const u_char *, const u_int);
 
 
 #ifdef INET6
index 25618c7a480fdc9fe38708a45b0467a54907dc65..c0bca50488386d03822f19f4551b982ba0fc1d2b 100644 (file)
@@ -384,6 +384,9 @@ extern u_int ap1394_if_print(netdissect_options *, const struct pcap_pkthdr *, c
 extern u_int bt_if_print(netdissect_options *, const struct pcap_pkthdr *, const u_char *);
 extern void lane_print(netdissect_options *, const u_char *, u_int, u_int);
 extern u_int lane_if_print(netdissect_options *, const struct pcap_pkthdr *, const u_char *);
+extern void otv_print(netdissect_options *, const u_char *, u_int);
+extern void ahcp_print(netdissect_options *, const u_char *, const u_int);
+extern void vxlan_print(netdissect_options *, const u_char *, u_int);
 
 /* stuff that has not yet been rototiled */
 extern const u_char * ns_nprint (register const u_char *, register const u_char *);
index b3abaa7b62c121edf0448c40290ce3614fb4db3e..1d498735acb069d9a08f25eb26df58d326293551 100644 (file)
@@ -35,7 +35,7 @@
 
 #include <tcpdump-stdinc.h>
 
-#include "interface.h"
+#include "netdissect.h"
 #include "extract.h"
 #include "addrtoname.h"
 
@@ -99,156 +99,156 @@ static const struct tok ahcp1_opt_str[] = {
 };
 
 static int
-ahcp_time_print(const u_char *cp, const u_char *ep) {
+ahcp_time_print(netdissect_options *ndo, const u_char *cp, const u_char *ep) {
        time_t t;
        struct tm *tm;
        char buf[BUFSIZE];
 
        if (cp + 4 != ep)
                goto corrupt;
-       TCHECK2(*cp, 4);
+       ND_TCHECK2(*cp, 4);
        t = EXTRACT_32BITS(cp);
        if (NULL == (tm = gmtime(&t)))
-               printf(": gmtime() error");
+               ND_PRINT((ndo, ": gmtime() error"));
        else if (0 == strftime(buf, sizeof(buf), "%Y-%m-%d %H:%M:%S", tm))
-               printf(": strftime() error");
+               ND_PRINT((ndo, ": strftime() error"));
        else
-               printf(": %s UTC", buf);
+               ND_PRINT((ndo, ": %s UTC", buf));
        return 0;
 
 corrupt:
-       printf(": %s", cstr);
-       TCHECK2(*cp, ep - cp);
+       ND_PRINT((ndo, ": %s", cstr));
+       ND_TCHECK2(*cp, ep - cp);
        return 0;
 trunc:
-       printf("%s", tstr);
+       ND_PRINT((ndo, "%s", tstr));
        return -1;
 }
 
 static int
-ahcp_seconds_print(const u_char *cp, const u_char *ep) {
+ahcp_seconds_print(netdissect_options *ndo, const u_char *cp, const u_char *ep) {
        if (cp + 4 != ep)
                goto corrupt;
-       TCHECK2(*cp, 4);
-       printf(": %us", EXTRACT_32BITS(cp));
+       ND_TCHECK2(*cp, 4);
+       ND_PRINT((ndo, ": %us", EXTRACT_32BITS(cp)));
        return 0;
 
 corrupt:
-       printf(": %s", cstr);
-       TCHECK2(*cp, ep - cp);
+       ND_PRINT((ndo, ": %s", cstr));
+       ND_TCHECK2(*cp, ep - cp);
        return 0;
 trunc:
-       printf("%s", tstr);
+       ND_PRINT((ndo, "%s", tstr));
        return -1;
 }
 
 static int
-ahcp_ipv6_addresses_print(const u_char *cp, const u_char *ep) {
+ahcp_ipv6_addresses_print(netdissect_options *ndo, const u_char *cp, const u_char *ep) {
        const char *sep = ": ";
 
        while (cp < ep) {
                if (cp + 16 > ep)
                        goto corrupt;
-               TCHECK2(*cp, 16);
-               printf("%s%s", sep,
+               ND_TCHECK2(*cp, 16);
+               ND_PRINT((ndo, "%s%s", sep,
 #ifdef INET6
                       ip6addr_string(cp)
 #else
                       "(compiled w/o IPv6)"
 #endif /* INET6 */
-                      );
+                      ));
                cp += 16;
                sep = ", ";
        }
        return 0;
 
 corrupt:
-       printf(": %s", cstr);
-       TCHECK2(*cp, ep - cp);
+       ND_PRINT((ndo, ": %s", cstr));
+       ND_TCHECK2(*cp, ep - cp);
        return 0;
 trunc:
-       printf("%s", tstr);
+       ND_PRINT((ndo, "%s", tstr));
        return -1;
 }
 
 static int
-ahcp_ipv4_addresses_print(const u_char *cp, const u_char *ep) {
+ahcp_ipv4_addresses_print(netdissect_options *ndo, const u_char *cp, const u_char *ep) {
        const char *sep = ": ";
 
        while (cp < ep) {
                if (cp + 4 > ep)
                        goto corrupt;
-               TCHECK2(*cp, 4);
-               printf("%s%s", sep, ipaddr_string(cp));
+               ND_TCHECK2(*cp, 4);
+               ND_PRINT((ndo, "%s%s", sep, ipaddr_string(cp)));
                cp += 4;
                sep = ", ";
        }
        return 0;
 
 corrupt:
-       printf(": %s", cstr);
-       TCHECK2(*cp, ep - cp);
+       ND_PRINT((ndo, ": %s", cstr));
+       ND_TCHECK2(*cp, ep - cp);
        return 0;
 trunc:
-       printf("%s", tstr);
+       ND_PRINT((ndo, "%s", tstr));
        return -1;
 }
 
 static int
-ahcp_ipv6_prefixes_print(const u_char *cp, const u_char *ep) {
+ahcp_ipv6_prefixes_print(netdissect_options *ndo, const u_char *cp, const u_char *ep) {
        const char *sep = ": ";
 
        while (cp < ep) {
                if (cp + 17 > ep)
                        goto corrupt;
-               TCHECK2(*cp, 17);
-               printf("%s%s/%u", sep,
+               ND_TCHECK2(*cp, 17);
+               ND_PRINT((ndo, "%s%s/%u", sep,
 #ifdef INET6
                       ip6addr_string(cp),
 #else
                       "(compiled w/o IPv6)",
 #endif /* INET6 */
-                      *(cp + 16));
+                      *(cp + 16)));
                cp += 17;
                sep = ", ";
        }
        return 0;
 
 corrupt:
-       printf(": %s", cstr);
-       TCHECK2(*cp, ep - cp);
+       ND_PRINT((ndo, ": %s", cstr));
+       ND_TCHECK2(*cp, ep - cp);
        return 0;
 trunc:
-       printf("%s", tstr);
+       ND_PRINT((ndo, "%s", tstr));
        return -1;
 }
 
 static int
-ahcp_ipv4_prefixes_print(const u_char *cp, const u_char *ep) {
+ahcp_ipv4_prefixes_print(netdissect_options *ndo, const u_char *cp, const u_char *ep) {
        const char *sep = ": ";
 
        while (cp < ep) {
                if (cp + 5 > ep)
                        goto corrupt;
-               TCHECK2(*cp, 5);
-               printf("%s%s/%u", sep, ipaddr_string(cp), *(cp + 4));
+               ND_TCHECK2(*cp, 5);
+               ND_PRINT((ndo, "%s%s/%u", sep, ipaddr_string(cp), *(cp + 4)));
                cp += 5;
                sep = ", ";
        }
        return 0;
 
 corrupt:
-       printf(": %s", cstr);
-       TCHECK2(*cp, ep - cp);
+       ND_PRINT((ndo, ": %s", cstr));
+       ND_TCHECK2(*cp, ep - cp);
        return 0;
 trunc:
-       printf("%s", tstr);
+       ND_PRINT((ndo, "%s", tstr));
        return -1;
 }
 
 /* Data decoders signal truncated data with -1. */
 static int
-(* const data_decoders[AHCP1_OPT_MAX + 1])(const u_char *, const u_char *) = {
+(* const data_decoders[AHCP1_OPT_MAX + 1])(netdissect_options *, const u_char *, const u_char *) = {
        /* [AHCP1_OPT_PAD]                    = */  NULL,
        /* [AHCP1_OPT_MANDATORY]              = */  NULL,
        /* [AHCP1_OPT_ORIGIN_TIME]            = */  ahcp_time_print,
@@ -266,151 +266,151 @@ static int
 };
 
 static void
-ahcp1_options_print(const u_char *cp, const u_char *ep) {
+ahcp1_options_print(netdissect_options *ndo, const u_char *cp, const u_char *ep) {
        uint8_t option_no, option_len;
 
        while (cp < ep) {
                /* Option no */
-               TCHECK2(*cp, 1);
+               ND_TCHECK2(*cp, 1);
                option_no = *cp;
                cp += 1;
-               printf("\n\t %s", tok2str(ahcp1_opt_str, "Unknown-%u", option_no));
+               ND_PRINT((ndo, "\n\t %s", tok2str(ahcp1_opt_str, "Unknown-%u", option_no)));
                if (option_no == AHCP1_OPT_PAD || option_no == AHCP1_OPT_MANDATORY)
                        continue;
                /* Length */
                if (cp + 1 > ep)
                        goto corrupt;
-               TCHECK2(*cp, 1);
+               ND_TCHECK2(*cp, 1);
                option_len = *cp;
                cp += 1;
                if (cp + option_len > ep)
                        goto corrupt;
                /* Value */
                if (option_no <= AHCP1_OPT_MAX && data_decoders[option_no] != NULL) {
-                       if (data_decoders[option_no](cp, cp + option_len) < 0)
+                       if (data_decoders[option_no](ndo, cp, cp + option_len) < 0)
                                break; /* truncated and already marked up */
                } else {
-                       printf(" (Length %u)", option_len);
-                       TCHECK2(*cp, option_len);
+                       ND_PRINT((ndo, " (Length %u)", option_len));
+                       ND_TCHECK2(*cp, option_len);
                }
                cp += option_len;
        }
        return;
 
 corrupt:
-       printf(" %s", cstr);
-       TCHECK2(*cp, ep - cp);
+       ND_PRINT((ndo, " %s", cstr));
+       ND_TCHECK2(*cp, ep - cp);
        return;
 trunc:
-       printf("%s", tstr);
+       ND_PRINT((ndo, "%s", tstr));
 }
 
 static void
-ahcp1_body_print(const u_char *cp, const u_char *ep) {
+ahcp1_body_print(netdissect_options *ndo, const u_char *cp, const u_char *ep) {
        uint8_t type, mbz;
        uint16_t body_len;
 
        if (cp + AHCP1_BODY_MIN_LEN > ep)
                goto corrupt;
        /* Type */
-       TCHECK2(*cp, 1);
+       ND_TCHECK2(*cp, 1);
        type = *cp;
        cp += 1;
        /* MBZ */
-       TCHECK2(*cp, 1);
+       ND_TCHECK2(*cp, 1);
        mbz = *cp;
        cp += 1;
        /* Length */
-       TCHECK2(*cp, 2);
+       ND_TCHECK2(*cp, 2);
        body_len = EXTRACT_16BITS(cp);
        cp += 2;
 
-       if (vflag) {
-               printf("\n\t%s", tok2str(ahcp1_msg_str, "Unknown-%u", type));
+       if (ndo->ndo_vflag) {
+               ND_PRINT((ndo, "\n\t%s", tok2str(ahcp1_msg_str, "Unknown-%u", type)));
                if (mbz != 0)
-                       printf(", MBZ %u", mbz);
-               printf(", Length %u", body_len);
+                       ND_PRINT((ndo, ", MBZ %u", mbz));
+               ND_PRINT((ndo, ", Length %u", body_len));
        }
        if (cp + body_len > ep)
                goto corrupt;
 
        /* Options */
-       if (vflag >= 2)
-               ahcp1_options_print(cp, cp + body_len); /* not ep (ignore extra data) */
+       if (ndo->ndo_vflag >= 2)
+               ahcp1_options_print(ndo, cp, cp + body_len); /* not ep (ignore extra data) */
        else
-               TCHECK2(*cp, body_len);
+               ND_TCHECK2(*cp, body_len);
        return;
 
 corrupt:
-       printf(" %s", cstr);
-       TCHECK2(*cp, ep - cp);
+       ND_PRINT((ndo, " %s", cstr));
+       ND_TCHECK2(*cp, ep - cp);
        return;
 trunc:
-       printf("%s", tstr);
+       ND_PRINT((ndo, "%s", tstr));
 }
 
 void
-ahcp_print(const u_char *cp, const u_int len) {
+ahcp_print(netdissect_options *ndo, const u_char *cp, const u_int len) {
        const u_char *ep = cp + len;
        uint8_t version;
 
-       printf("AHCP");
+       ND_PRINT((ndo, "AHCP"));
        if (len < 2)
                goto corrupt;
        /* Magic */
-       TCHECK2(*cp, 1);
+       ND_TCHECK2(*cp, 1);
        if (*cp != AHCP_MAGIC_NUMBER)
                goto corrupt;
        cp += 1;
        /* Version */
-       TCHECK2(*cp, 1);
+       ND_TCHECK2(*cp, 1);
        version = *cp;
        cp += 1;
        switch (version) {
                case AHCP_VERSION_1: {
-                       printf(" Version 1");
+                       ND_PRINT((ndo, " Version 1"));
                        if (len < AHCP1_HEADER_FIX_LEN)
                                goto corrupt;
-                       if (!vflag) {
-                               TCHECK2(*cp, AHCP1_HEADER_FIX_LEN - 2);
+                       if (!ndo->ndo_vflag) {
+                               ND_TCHECK2(*cp, AHCP1_HEADER_FIX_LEN - 2);
                                cp += AHCP1_HEADER_FIX_LEN - 2;
                        } else {
                                /* Hopcount */
-                               TCHECK2(*cp, 1);
-                               printf("\n\tHopcount %u", *cp);
+                               ND_TCHECK2(*cp, 1);
+                               ND_PRINT((ndo, "\n\tHopcount %u", *cp));
                                cp += 1;
                                /* Original Hopcount */
-                               TCHECK2(*cp, 1);
-                               printf(", Original Hopcount %u", *cp);
+                               ND_TCHECK2(*cp, 1);
+                               ND_PRINT((ndo, ", Original Hopcount %u", *cp));
                                cp += 1;
                                /* Nonce */
-                               TCHECK2(*cp, 4);
-                               printf(", Nonce 0x%08x", EXTRACT_32BITS(cp));
+                               ND_TCHECK2(*cp, 4);
+                               ND_PRINT((ndo, ", Nonce 0x%08x", EXTRACT_32BITS(cp)));
                                cp += 4;
                                /* Source Id */
-                               TCHECK2(*cp, 8);
-                               printf(", Source Id %s", linkaddr_string(cp, 0, 8));
+                               ND_TCHECK2(*cp, 8);
+                               ND_PRINT((ndo, ", Source Id %s", linkaddr_string(cp, 0, 8)));
                                cp += 8;
                                /* Destination Id */
-                               TCHECK2(*cp, 8);
-                               printf(", Destination Id %s", linkaddr_string(cp, 0, 8));
+                               ND_TCHECK2(*cp, 8);
+                               ND_PRINT((ndo, ", Destination Id %s", linkaddr_string(cp, 0, 8)));
                                cp += 8;
                        }
                        /* Body */
-                       ahcp1_body_print(cp, ep);
+                       ahcp1_body_print(ndo, cp, ep);
                        break;
                }
                default:
-                       printf(" Version %u (unknown)", version);
+                       ND_PRINT((ndo, " Version %u (unknown)", version));
                        break;
        }
        return;
 
 corrupt:
-       printf(" %s", cstr);
-       TCHECK2(*cp, ep - cp);
+       ND_PRINT((ndo, " %s", cstr));
+       ND_TCHECK2(*cp, ep - cp);
        return;
 trunc:
-       printf("%s", tstr);
+       ND_PRINT((ndo, "%s", tstr));
 }
 
index fd5a3c7dad542f29216a63bd620ac663086201e7..3b182f7e46a3fcbcba3533888db0859ce8dd9214 100644 (file)
 
 #include <tcpdump-stdinc.h>
 
-#include <stdio.h>
-#include <stdlib.h>
-
-#include "interface.h"
+#include "netdissect.h"
 #include "extract.h"
 
 /*
  */
 
 void
-otv_print(const u_char *bp, u_int len)
+otv_print(netdissect_options *ndo, const u_char *bp, u_int len)
 {
     u_int8_t flags;
     u_int32_t overlay_id;
     u_int32_t instance_id;
 
     if (len < 8) {
-        printf("[|OTV]");
+        ND_PRINT((ndo, "[|OTV]"));
         return;
     }
 
@@ -58,19 +55,10 @@ otv_print(const u_char *bp, u_int len)
     instance_id = EXTRACT_24BITS(bp);
     bp += 4;
 
-    printf("OTV, ");
-
-    fputs("flags [", stdout);
-    if (flags & 0x08)
-        fputs("I", stdout);
-    else
-        fputs(".", stdout);
-    fputs("] ", stdout);
-
-    printf("(0x%02x), ", flags);
-    printf("overlay %u, ", overlay_id);
-    printf("instance %u\n", instance_id);
+    ND_PRINT((ndo, "OTV, "));
+    ND_PRINT((ndo, "flags [%s] (0x%02x), ", flags & 0x08 ? "I" : ".", flags));
+    ND_PRINT((ndo, "overlay %u, ", overlay_id));
+    ND_PRINT((ndo, "instance %u\n", instance_id));
 
-    ether_print(gndo, bp, len - 8, len - 8, NULL, NULL);
-    return;
+    ether_print(ndo, bp, len - 8, len - 8, NULL, NULL);
 }
index 2bddae9cc3486168de4a5f14792e0b089424057f..2ff6d824d2f0062d85d0e4a0eb58b7bfea0e8f5b 100644 (file)
@@ -472,7 +472,7 @@ udp_print(register const u_char *bp, u_int length,
 
                case PT_VXLAN:
                        udpipaddr_print(ip, sport, dport);
-                       vxlan_print((const u_char *)(up + 1), length);
+                       vxlan_print(gndo, (const u_char *)(up + 1), length);
                        break;
 
                case PT_PGM:
@@ -627,7 +627,7 @@ udp_print(register const u_char *bp, u_int length,
                else if (ISPORT(DHCP6_SERV_PORT) || ISPORT(DHCP6_CLI_PORT))
                        dhcp6_print((const u_char *)(up + 1), length);
                else if (ISPORT(AHCP_PORT))
-                       ahcp_print((const u_char *)(up + 1), length);
+                       ahcp_print(gndo, (const u_char *)(up + 1), length);
                else if (ISPORT(BABEL_PORT) || ISPORT(BABEL_PORT_OLD))
                        babel_print((const u_char *)(up + 1), length);
 #endif /*INET6*/
@@ -678,9 +678,9 @@ udp_print(register const u_char *bp, u_int length,
                 else if (ISPORT(SYSLOG_PORT))
                        syslog_print((const u_char *)(up + 1), length);
                 else if (ISPORT(OTV_PORT))
-                       otv_print((const u_char *)(up + 1), length);
+                       otv_print(gndo, (const u_char *)(up + 1), length);
                 else if (ISPORT(VXLAN_PORT))
-                       vxlan_print((const u_char *)(up + 1), length);
+                       vxlan_print(gndo, (const u_char *)(up + 1), length);
                else
                        (void)printf("UDP, length %u",
                            (u_int32_t)(ulen - sizeof(*up)));
index 3ef9cf6a96249381638a534011f2fc5d7f845db7..6f60d92ae2a512d4c7cfd21a815d2fa751393a08 100644 (file)
 
 #include <tcpdump-stdinc.h>
 
-#include <stdio.h>
-#include <stdlib.h>
-
-#include "interface.h"
+#include "netdissect.h"
 #include "extract.h"
 
 /*
  */
 
 void
-vxlan_print(const u_char *bp, u_int len)
+vxlan_print(netdissect_options *ndo, const u_char *bp, u_int len)
 {
     u_int8_t flags;
     u_int32_t vni;
 
     if (len < 8) {
-        printf("[|VXLAN]");
+        ND_PRINT((ndo, "[|VXLAN]"));
         return;
     }
 
@@ -54,18 +51,9 @@ vxlan_print(const u_char *bp, u_int len)
     vni = EXTRACT_24BITS(bp);
     bp += 4;
 
-    printf("VXLAN, ");
-
-    fputs("flags [", stdout);
-    if (flags & 0x08)
-        fputs("I", stdout);
-    else
-        fputs(".", stdout);
-    fputs("] ", stdout);
-
-    printf("(0x%02x), ", flags);
-    printf("vni %u\n", vni);
+    ND_PRINT((ndo, "VXLAN, "));
+    ND_PRINT((ndo, "flags [%s] (0x%02x), ", flags & 0x08 ? "I" : ".", flags));
+    ND_PRINT((ndo, "vni %u\n", vni));
 
-    ether_print(gndo, bp, len - 8, len - 8, NULL, NULL);
-    return;
+    ether_print(ndo, bp, len - 8, len - 8, NULL, NULL);
 }