]> The Tcpdump Group git mirrors - tcpdump/blobdiff - print-mptcp.c
NDOize ATM, MPTCP, NTP, VTP & Whiteboard decoders
[tcpdump] / print-mptcp.c
index a604e56311eac62394f11f9151dd3c80d42ed3a7..292189afd885f69e88cadde69a728761585756bc 100644 (file)
  * SUCH DAMAGE.
  */
 
+#define NETDISSECT_REWORKED
 #ifdef HAVE_CONFIG_H
 #include "config.h"
 #endif
 
 #include <tcpdump-stdinc.h>
 
-#include <stdio.h>
-#include <string.h>
-
 #include "interface.h"
 #include "extract.h"
 #include "addrtoname.h"
 
-#include "ipproto.h"
 #include "tcp.h"
 
 #define MPTCP_SUB_CAPABLE       0x0
@@ -165,12 +162,16 @@ struct mp_prio {
 
 #define MP_PRIO_B                       0x01
 
-static int dummy_print(const u_char *opt _U_, u_int opt_len _U_, u_char flags _U_)
+static int
+dummy_print(netdissect_options *ndo _U_,
+            const u_char *opt _U_, u_int opt_len _U_, u_char flags _U_)
 {
         return 1;
 }
 
-static int mp_capable_print(const u_char *opt, u_int opt_len, u_char flags)
+static int
+mp_capable_print(netdissect_options *ndo,
+                 const u_char *opt, u_int opt_len, u_char flags)
 {
         struct mp_capable *mpc = (struct mp_capable *) opt;
 
@@ -179,20 +180,22 @@ static int mp_capable_print(const u_char *opt, u_int opt_len, u_char flags)
                 return 0;
 
         if (MP_CAPABLE_OPT_VERSION(mpc->sub_ver) != 0) {
-                printf(" Unknown Version (%d)", MP_CAPABLE_OPT_VERSION(mpc->sub_ver));
+                ND_PRINT((ndo, " Unknown Version (%d)", MP_CAPABLE_OPT_VERSION(mpc->sub_ver)));
                 return 1;
         }
 
         if (mpc->flags & MP_CAPABLE_C)
-                printf(" csum");
-        printf(" {0x%" PRIx64, EXTRACT_64BITS(mpc->sender_key));
+                ND_PRINT((ndo, " csum"));
+        ND_PRINT((ndo, " {0x%" PRIx64, EXTRACT_64BITS(mpc->sender_key)));
         if (opt_len == 20) /* ACK */
-                printf(",0x%" PRIx64, EXTRACT_64BITS(mpc->receiver_key));
-        printf("}");
+                ND_PRINT((ndo, ",0x%" PRIx64, EXTRACT_64BITS(mpc->receiver_key)));
+        ND_PRINT((ndo, "}"));
         return 1;
 }
 
-static int mp_join_print(const u_char *opt, u_int opt_len, u_char flags)
+static int
+mp_join_print(netdissect_options *ndo,
+              const u_char *opt, u_int opt_len, u_char flags)
 {
         struct mp_join *mpj = (struct mp_join *) opt;
 
@@ -203,26 +206,26 @@ static int mp_join_print(const u_char *opt, u_int opt_len, u_char flags)
 
         if (opt_len != 24) {
                 if (mpj->sub_b & MP_JOIN_B)
-                        printf(" backup");
-                printf(" id %u", mpj->addr_id);
+                        ND_PRINT((ndo, " backup"));
+                ND_PRINT((ndo, " id %u", mpj->addr_id));
         }
 
         switch (opt_len) {
         case 12: /* SYN */
-                printf(" token 0x%x" " nonce 0x%x",
+                ND_PRINT((ndo, " token 0x%x" " nonce 0x%x",
                         EXTRACT_32BITS(mpj->u.syn.token),
-                        EXTRACT_32BITS(mpj->u.syn.nonce));
+                        EXTRACT_32BITS(mpj->u.syn.nonce)));
                 break;
         case 16: /* SYN/ACK */
-                printf(" hmac 0x%" PRIx64 " nonce 0x%x",
+                ND_PRINT((ndo, " hmac 0x%" PRIx64 " nonce 0x%x",
                         EXTRACT_64BITS(mpj->u.synack.mac),
-                        EXTRACT_32BITS(mpj->u.synack.nonce));
+                        EXTRACT_32BITS(mpj->u.synack.nonce)));
                 break;
         case 24: {/* ACK */
                 size_t i;
-                printf(" hmac 0x");
+                ND_PRINT((ndo, " hmac 0x"));
                 for (i = 0; i < sizeof(mpj->u.ack.mac); ++i)
-                        printf("%02x", mpj->u.ack.mac[i]);
+                        ND_PRINT((ndo, "%02x", mpj->u.ack.mac[i]));
         }
         default:
                 break;
@@ -258,7 +261,9 @@ static u_int mp_dss_len(struct mp_dss *m, int csum)
        return len;
 }
 
-static int mp_dss_print(const u_char *opt, u_int opt_len, u_char flags)
+static int
+mp_dss_print(netdissect_options *ndo,
+             const u_char *opt, u_int opt_len, u_char flags)
 {
         struct mp_dss *mdss = (struct mp_dss *) opt;
 
@@ -267,41 +272,43 @@ static int mp_dss_print(const u_char *opt, u_int opt_len, u_char flags)
                 return 0;
 
         if (mdss->flags & MP_DSS_F)
-                printf(" fin");
+                ND_PRINT((ndo, " fin"));
 
         opt += 4;
         if (mdss->flags & MP_DSS_A) {
-                printf(" ack ");
+                ND_PRINT((ndo, " ack "));
                 if (mdss->flags & MP_DSS_a) {
-                        printf("%" PRIu64, EXTRACT_64BITS(opt));
+                        ND_PRINT((ndo, "%" PRIu64, EXTRACT_64BITS(opt)));
                         opt += 8;
                 } else {
-                        printf("%u", EXTRACT_32BITS(opt));
+                        ND_PRINT((ndo, "%u", EXTRACT_32BITS(opt)));
                         opt += 4;
                 }
         }
 
         if (mdss->flags & MP_DSS_M) {
-                printf(" seq ");
+                ND_PRINT((ndo, " seq "));
                 if (mdss->flags & MP_DSS_m) {
-                        printf("%" PRIu64, EXTRACT_64BITS(opt));
+                        ND_PRINT((ndo, "%" PRIu64, EXTRACT_64BITS(opt)));
                         opt += 8;
                 } else {
-                        printf("%u", EXTRACT_32BITS(opt));
+                        ND_PRINT((ndo, "%u", EXTRACT_32BITS(opt)));
                         opt += 4;
                 }
-                printf(" subseq %u", EXTRACT_32BITS(opt));
+                ND_PRINT((ndo, " subseq %u", EXTRACT_32BITS(opt)));
                 opt += 4;
-                printf(" len %u", EXTRACT_16BITS(opt));
+                ND_PRINT((ndo, " len %u", EXTRACT_16BITS(opt)));
                 opt += 2;
 
                 if (opt_len == mp_dss_len(mdss, 1))
-                        printf(" csum 0x%x", EXTRACT_16BITS(opt));
+                        ND_PRINT((ndo, " csum 0x%x", EXTRACT_16BITS(opt)));
         }
         return 1;
 }
 
-static int add_addr_print(const u_char *opt, u_int opt_len, u_char flags _U_)
+static int
+add_addr_print(netdissect_options *ndo,
+               const u_char *opt, u_int opt_len, u_char flags _U_)
 {
         struct mp_add_addr *add_addr = (struct mp_add_addr *) opt;
         u_int ipver = MP_ADD_ADDR_IPVER(add_addr->sub_ipver);
@@ -310,19 +317,19 @@ static int add_addr_print(const u_char *opt, u_int opt_len, u_char flags _U_)
             !((opt_len == 20 || opt_len == 22) && ipver == 6))
                 return 0;
 
-        printf(" id %u", add_addr->addr_id);
+        ND_PRINT((ndo, " id %u", add_addr->addr_id));
         switch (ipver) {
         case 4:
-                printf(" %s", ipaddr_string(add_addr->u.v4.addr));
+                ND_PRINT((ndo, " %s", ipaddr_string(add_addr->u.v4.addr)));
                 if (opt_len == 10)
-                        printf(":%u", EXTRACT_16BITS(add_addr->u.v4.port));
+                        ND_PRINT((ndo, ":%u", EXTRACT_16BITS(add_addr->u.v4.port)));
                 break;
         case 6:
 #ifdef INET6
-                printf(" %s", ip6addr_string(add_addr->u.v6.addr));
+                ND_PRINT((ndo, " %s", ip6addr_string(add_addr->u.v6.addr)));
 #endif
                 if (opt_len == 22)
-                        printf(":%u", EXTRACT_16BITS(add_addr->u.v6.port));
+                        ND_PRINT((ndo, ":%u", EXTRACT_16BITS(add_addr->u.v6.port)));
                 break;
         default:
                 return 0;
@@ -331,7 +338,9 @@ static int add_addr_print(const u_char *opt, u_int opt_len, u_char flags _U_)
         return 1;
 }
 
-static int remove_addr_print(const u_char *opt, u_int opt_len, u_char flags _U_)
+static int
+remove_addr_print(netdissect_options *ndo,
+                  const u_char *opt, u_int opt_len, u_char flags _U_)
 {
         struct mp_remove_addr *remove_addr = (struct mp_remove_addr *) opt;
         u_int8_t *addr_id = &remove_addr->addrs_id;
@@ -340,13 +349,15 @@ static int remove_addr_print(const u_char *opt, u_int opt_len, u_char flags _U_)
                 return 0;
 
         opt_len -= 3;
-        printf(" id");
+        ND_PRINT((ndo, " id"));
         while (opt_len--)
-                printf(" %u", *addr_id++);
+                ND_PRINT((ndo, " %u", *addr_id++));
         return 1;
 }
 
-static int mp_prio_print(const u_char *opt, u_int opt_len, u_char flags _U_)
+static int
+mp_prio_print(netdissect_options *ndo,
+              const u_char *opt, u_int opt_len, u_char flags _U_)
 {
         struct mp_prio *mpp = (struct mp_prio *) opt;
 
@@ -354,36 +365,40 @@ static int mp_prio_print(const u_char *opt, u_int opt_len, u_char flags _U_)
                 return 0;
 
         if (mpp->sub_b & MP_PRIO_B)
-                printf(" backup");
+                ND_PRINT((ndo, " backup"));
         else
-                printf(" non-backup");
+                ND_PRINT((ndo, " non-backup"));
         if (opt_len == 4)
-                printf(" id %u", mpp->addr_id);
+                ND_PRINT((ndo, " id %u", mpp->addr_id));
 
         return 1;
 }
 
-static int mp_fail_print(const u_char *opt, u_int opt_len, u_char flags _U_)
+static int
+mp_fail_print(netdissect_options *ndo,
+              const u_char *opt, u_int opt_len, u_char flags _U_)
 {
         if (opt_len != 12)
                 return 0;
 
-        printf(" seq %" PRIu64, EXTRACT_64BITS(opt + 4));
+        ND_PRINT((ndo, " seq %" PRIu64, EXTRACT_64BITS(opt + 4)));
         return 1;
 }
 
-static int mp_fast_close_print(const u_char *opt, u_int opt_len, u_char flags _U_)
+static int
+mp_fast_close_print(netdissect_options *ndo,
+                    const u_char *opt, u_int opt_len, u_char flags _U_)
 {
         if (opt_len != 12)
                 return 0;
 
-        printf(" key 0x%" PRIx64, EXTRACT_64BITS(opt + 4));
+        ND_PRINT((ndo, " key 0x%" PRIx64, EXTRACT_64BITS(opt + 4)));
         return 1;
 }
 
 static const struct {
         const char *name;
-        int (*print)(const u_char *, u_int, u_char);
+        int (*print)(netdissect_options *, const u_char *, u_int, u_char);
 } mptcp_options[] = {
         { "capable", mp_capable_print},
         { "join",       mp_join_print },
@@ -396,7 +411,9 @@ static const struct {
         { "unknown",    dummy_print },
 };
 
-int mptcp_print(const u_char *cp, u_int len, u_char flags)
+int
+mptcp_print(netdissect_options *ndo,
+            const u_char *cp, u_int len, u_char flags)
 {
         struct mptcp_option *opt;
         u_int subtype;
@@ -407,6 +424,6 @@ int mptcp_print(const u_char *cp, u_int len, u_char flags)
         opt = (struct mptcp_option *) cp;
         subtype = min(MPTCP_OPT_SUBTYPE(opt->sub_etc), MPTCP_SUB_FCLOSE + 1);
 
-        printf(" %s", mptcp_options[subtype].name);
-        return mptcp_options[subtype].print(cp, len, flags);
+        ND_PRINT((ndo, " %s", mptcp_options[subtype].name));
+        return mptcp_options[subtype].print(ndo, cp, len, flags);
 }