]> The Tcpdump Group git mirrors - tcpdump/blobdiff - print-mptcp.c
NTP: Use tstr for truncation indicator.
[tcpdump] / print-mptcp.c
index 292189afd885f69e88cadde69a728761585756bc..e757ea48f3a0a6025b77eac7f25081dbb6768d1e 100644 (file)
  * SUCH DAMAGE.
  */
 
-#define NETDISSECT_REWORKED
+/* \summary: Multipath TCP (MPTCP) printer */
+
+/* specification: RFC 6824 */
+
 #ifdef HAVE_CONFIG_H
 #include "config.h"
 #endif
 
-#include <tcpdump-stdinc.h>
+#include <netdissect-stdinc.h>
 
-#include "interface.h"
+#include "netdissect.h"
 #include "extract.h"
 #include "addrtoname.h"
 
 #define MPTCP_SUB_FCLOSE        0x7
 
 struct mptcp_option {
-        u_int8_t        kind;
-        u_int8_t        len;
-        u_int8_t        sub_etc;        /* subtype upper 4 bits, other stuff lower 4 bits */
+        uint8_t        kind;
+        uint8_t        len;
+        uint8_t        sub_etc;        /* subtype upper 4 bits, other stuff lower 4 bits */
 };
 
 #define MPTCP_OPT_SUBTYPE(sub_etc)      (((sub_etc) >> 4) & 0xF)
 
 struct mp_capable {
-        u_int8_t        kind;
-        u_int8_t        len;
-        u_int8_t        sub_ver;
-        u_int8_t        flags;
-        u_int8_t        sender_key[8];
-        u_int8_t        receiver_key[8];
+        uint8_t        kind;
+        uint8_t        len;
+        uint8_t        sub_ver;
+        uint8_t        flags;
+        uint8_t        sender_key[8];
+        uint8_t        receiver_key[8];
 };
 
 #define MP_CAPABLE_OPT_VERSION(sub_ver) (((sub_ver) >> 0) & 0xF)
@@ -76,21 +79,21 @@ struct mp_capable {
 #define MP_CAPABLE_S                    0x01
 
 struct mp_join {
-        u_int8_t        kind;
-        u_int8_t        len;
-        u_int8_t        sub_b;
-        u_int8_t        addr_id;
+        uint8_t        kind;
+        uint8_t        len;
+        uint8_t        sub_b;
+        uint8_t        addr_id;
         union {
                 struct {
-                        u_int8_t         token[4];
-                        u_int8_t         nonce[4];
+                        uint8_t         token[4];
+                        uint8_t         nonce[4];
                 } syn;
                 struct {
-                        u_int8_t         mac[8];
-                        u_int8_t         nonce[4];
+                        uint8_t         mac[8];
+                        uint8_t         nonce[4];
                 } synack;
                 struct {
-                        u_int8_t        mac[20];
+                        uint8_t        mac[20];
                 } ack;
         } u;
 };
@@ -98,10 +101,10 @@ struct mp_join {
 #define MP_JOIN_B                       0x01
 
 struct mp_dss {
-        u_int8_t        kind;
-        u_int8_t        len;
-        u_int8_t        sub;
-        u_int8_t        flags;
+        uint8_t        kind;
+        uint8_t        len;
+        uint8_t        sub;
+        uint8_t        flags;
 };
 
 #define MP_DSS_F                        0x10
@@ -111,18 +114,18 @@ struct mp_dss {
 #define MP_DSS_A                        0x01
 
 struct mp_add_addr {
-        u_int8_t        kind;
-        u_int8_t        len;
-        u_int8_t        sub_ipver;
-        u_int8_t        addr_id;
+        uint8_t        kind;
+        uint8_t        len;
+        uint8_t        sub_ipver;
+        uint8_t        addr_id;
         union {
                 struct {
-                        u_int8_t         addr[4];
-                        u_int8_t         port[2];
+                        uint8_t         addr[4];
+                        uint8_t         port[2];
                 } v4;
                 struct {
-                        u_int8_t         addr[16];
-                        u_int8_t         port[2];
+                        uint8_t         addr[16];
+                        uint8_t         port[2];
                 } v6;
         } u;
 };
@@ -130,34 +133,34 @@ struct mp_add_addr {
 #define MP_ADD_ADDR_IPVER(sub_ipver)    (((sub_ipver) >> 0) & 0xF)
 
 struct mp_remove_addr {
-        u_int8_t        kind;
-        u_int8_t        len;
-        u_int8_t        sub;
+        uint8_t        kind;
+        uint8_t        len;
+        uint8_t        sub;
         /* list of addr_id */
-        u_int8_t        addrs_id;
+        uint8_t        addrs_id;
 };
 
 struct mp_fail {
-        u_int8_t        kind;
-        u_int8_t        len;
-        u_int8_t        sub;
-        u_int8_t        resv;
-        u_int8_t        data_seq[8];
+        uint8_t        kind;
+        uint8_t        len;
+        uint8_t        sub;
+        uint8_t        resv;
+        uint8_t        data_seq[8];
 };
 
 struct mp_close {
-        u_int8_t        kind;
-        u_int8_t        len;
-        u_int8_t        sub;
-        u_int8_t        rsv;
-        u_int8_t        key[8];
+        uint8_t        kind;
+        uint8_t        len;
+        uint8_t        sub;
+        uint8_t        rsv;
+        uint8_t        key[8];
 };
 
 struct mp_prio {
-        u_int8_t        kind;
-        u_int8_t        len;
-        u_int8_t        sub_b;
-        u_int8_t        addr_id;
+        uint8_t        kind;
+        uint8_t        len;
+        uint8_t        sub_b;
+        uint8_t        addr_id;
 };
 
 #define MP_PRIO_B                       0x01
@@ -173,7 +176,7 @@ 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;
+        const struct mp_capable *mpc = (const struct mp_capable *) opt;
 
         if (!(opt_len == 12 && flags & TH_SYN) &&
             !(opt_len == 20 && (flags & (TH_SYN | TH_ACK)) == TH_ACK))
@@ -197,7 +200,7 @@ 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;
+        const struct mp_join *mpj = (const struct mp_join *) opt;
 
         if (!(opt_len == 12 && flags & TH_SYN) &&
             !(opt_len == 16 && (flags & (TH_SYN | TH_ACK)) == (TH_SYN | TH_ACK)) &&
@@ -233,7 +236,7 @@ mp_join_print(netdissect_options *ndo,
         return 1;
 }
 
-static u_int mp_dss_len(struct mp_dss *m, int csum)
+static u_int mp_dss_len(const  struct mp_dss *m, int csum)
 {
         u_int len;
 
@@ -265,7 +268,7 @@ 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;
+        const struct mp_dss *mdss = (const struct mp_dss *) opt;
 
         if ((opt_len != mp_dss_len(mdss, 1) &&
              opt_len != mp_dss_len(mdss, 0)) || flags & TH_SYN)
@@ -310,7 +313,7 @@ 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;
+        const struct mp_add_addr *add_addr = (const struct mp_add_addr *) opt;
         u_int ipver = MP_ADD_ADDR_IPVER(add_addr->sub_ipver);
 
         if (!((opt_len == 8 || opt_len == 10) && ipver == 4) &&
@@ -320,14 +323,12 @@ add_addr_print(netdissect_options *ndo,
         ND_PRINT((ndo, " id %u", add_addr->addr_id));
         switch (ipver) {
         case 4:
-                ND_PRINT((ndo, " %s", ipaddr_string(add_addr->u.v4.addr)));
+                ND_PRINT((ndo, " %s", ipaddr_string(ndo, add_addr->u.v4.addr)));
                 if (opt_len == 10)
                         ND_PRINT((ndo, ":%u", EXTRACT_16BITS(add_addr->u.v4.port)));
                 break;
         case 6:
-#ifdef INET6
-                ND_PRINT((ndo, " %s", ip6addr_string(add_addr->u.v6.addr)));
-#endif
+                ND_PRINT((ndo, " %s", ip6addr_string(ndo, add_addr->u.v6.addr)));
                 if (opt_len == 22)
                         ND_PRINT((ndo, ":%u", EXTRACT_16BITS(add_addr->u.v6.port)));
                 break;
@@ -342,8 +343,8 @@ 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;
+        const struct mp_remove_addr *remove_addr = (const struct mp_remove_addr *) opt;
+        const uint8_t *addr_id = &remove_addr->addrs_id;
 
         if (opt_len < 4)
                 return 0;
@@ -359,7 +360,7 @@ 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;
+        const struct mp_prio *mpp = (const struct mp_prio *) opt;
 
         if (opt_len != 3 && opt_len != 4)
                 return 0;
@@ -415,13 +416,13 @@ int
 mptcp_print(netdissect_options *ndo,
             const u_char *cp, u_int len, u_char flags)
 {
-        struct mptcp_option *opt;
+        const struct mptcp_option *opt;
         u_int subtype;
 
         if (len < 3)
                 return 0;
 
-        opt = (struct mptcp_option *) cp;
+        opt = (const struct mptcp_option *) cp;
         subtype = min(MPTCP_OPT_SUBTYPE(opt->sub_etc), MPTCP_SUB_FCLOSE + 1);
 
         ND_PRINT((ndo, " %s", mptcp_options[subtype].name));