xref: /freebsd/contrib/tcpdump/print-mptcp.c (revision 0a7e5f1f02aad2ff5fff1c60f44c6975fd07e1d9)
13c602fabSXin LI /**
23c602fabSXin LI  * Copyright (c) 2012
33c602fabSXin LI  *
43c602fabSXin LI  * Gregory Detal <gregory.detal@uclouvain.be>
53c602fabSXin LI  * Christoph Paasch <christoph.paasch@uclouvain.be>
63c602fabSXin LI  *
73c602fabSXin LI  * Redistribution and use in source and binary forms, with or without
83c602fabSXin LI  * modification, are permitted provided that the following conditions
93c602fabSXin LI  * are met:
103c602fabSXin LI  *
113c602fabSXin LI  * 1. Redistributions of source code must retain the above copyright
123c602fabSXin LI  *    notice, this list of conditions and the following disclaimer.
133c602fabSXin LI  *
143c602fabSXin LI  * 2. Redistributions in binary form must reproduce the above copyright
153c602fabSXin LI  *    notice, this list of conditions and the following disclaimer in the
163c602fabSXin LI  *    documentation and/or other materials provided with the distribution.
173c602fabSXin LI  *
183c602fabSXin LI  * 3. Neither the name of the University nor of the Laboratory may be used
193c602fabSXin LI  *    to endorse or promote products derived from this software without
203c602fabSXin LI  *    specific prior written permission.
213c602fabSXin LI  *
223c602fabSXin LI  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
233c602fabSXin LI  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
243c602fabSXin LI  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
253c602fabSXin LI  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
263c602fabSXin LI  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
273c602fabSXin LI  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
283c602fabSXin LI  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
293c602fabSXin LI  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
303c602fabSXin LI  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
313c602fabSXin LI  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
323c602fabSXin LI  * SUCH DAMAGE.
333c602fabSXin LI  */
343c602fabSXin LI 
353340d773SGleb Smirnoff /* \summary: Multipath TCP (MPTCP) printer */
363340d773SGleb Smirnoff 
373340d773SGleb Smirnoff /* specification: RFC 6824 */
383340d773SGleb Smirnoff 
39*ee67461eSJoseph Mingrone #include <config.h>
403c602fabSXin LI 
41*ee67461eSJoseph Mingrone #include "netdissect-stdinc.h"
423c602fabSXin LI 
433340d773SGleb Smirnoff #include "netdissect.h"
443c602fabSXin LI #include "extract.h"
453c602fabSXin LI #include "addrtoname.h"
463c602fabSXin LI 
473c602fabSXin LI #include "tcp.h"
483c602fabSXin LI 
493c602fabSXin LI #define MPTCP_SUB_CAPABLE       0x0
503c602fabSXin LI #define MPTCP_SUB_JOIN          0x1
513c602fabSXin LI #define MPTCP_SUB_DSS           0x2
523c602fabSXin LI #define MPTCP_SUB_ADD_ADDR      0x3
533c602fabSXin LI #define MPTCP_SUB_REMOVE_ADDR   0x4
543c602fabSXin LI #define MPTCP_SUB_PRIO          0x5
553c602fabSXin LI #define MPTCP_SUB_FAIL          0x6
563c602fabSXin LI #define MPTCP_SUB_FCLOSE        0x7
573c602fabSXin LI 
583c602fabSXin LI struct mptcp_option {
59*ee67461eSJoseph Mingrone         nd_uint8_t     kind;
60*ee67461eSJoseph Mingrone         nd_uint8_t     len;
61*ee67461eSJoseph Mingrone         nd_uint8_t     sub_etc;        /* subtype upper 4 bits, other stuff lower 4 bits */
623c602fabSXin LI };
633c602fabSXin LI 
643c602fabSXin LI #define MPTCP_OPT_SUBTYPE(sub_etc)      (((sub_etc) >> 4) & 0xF)
653c602fabSXin LI 
663c602fabSXin LI struct mp_capable {
67*ee67461eSJoseph Mingrone         nd_uint8_t     kind;
68*ee67461eSJoseph Mingrone         nd_uint8_t     len;
69*ee67461eSJoseph Mingrone         nd_uint8_t     sub_ver;
70*ee67461eSJoseph Mingrone         nd_uint8_t     flags;
71*ee67461eSJoseph Mingrone         nd_uint64_t    sender_key;
72*ee67461eSJoseph Mingrone         nd_uint64_t    receiver_key;
733c602fabSXin LI };
743c602fabSXin LI 
753c602fabSXin LI #define MP_CAPABLE_OPT_VERSION(sub_ver) (((sub_ver) >> 0) & 0xF)
763c602fabSXin LI #define MP_CAPABLE_C                    0x80
773c602fabSXin LI #define MP_CAPABLE_S                    0x01
783c602fabSXin LI 
793c602fabSXin LI struct mp_join {
80*ee67461eSJoseph Mingrone         nd_uint8_t     kind;
81*ee67461eSJoseph Mingrone         nd_uint8_t     len;
82*ee67461eSJoseph Mingrone         nd_uint8_t     sub_b;
83*ee67461eSJoseph Mingrone         nd_uint8_t     addr_id;
843c602fabSXin LI         union {
853c602fabSXin LI                 struct {
86*ee67461eSJoseph Mingrone                         nd_uint32_t     token;
87*ee67461eSJoseph Mingrone                         nd_uint32_t     nonce;
883c602fabSXin LI                 } syn;
893c602fabSXin LI                 struct {
90*ee67461eSJoseph Mingrone                         nd_uint64_t     mac;
91*ee67461eSJoseph Mingrone                         nd_uint32_t     nonce;
923c602fabSXin LI                 } synack;
933c602fabSXin LI                 struct {
94*ee67461eSJoseph Mingrone                         nd_byte         mac[20];
953c602fabSXin LI                 } ack;
963c602fabSXin LI         } u;
973c602fabSXin LI };
983c602fabSXin LI 
993c602fabSXin LI #define MP_JOIN_B                       0x01
1003c602fabSXin LI 
1013c602fabSXin LI struct mp_dss {
102*ee67461eSJoseph Mingrone         nd_uint8_t     kind;
103*ee67461eSJoseph Mingrone         nd_uint8_t     len;
104*ee67461eSJoseph Mingrone         nd_uint8_t     sub;
105*ee67461eSJoseph Mingrone         nd_uint8_t     flags;
1063c602fabSXin LI };
1073c602fabSXin LI 
1083c602fabSXin LI #define MP_DSS_F                        0x10
1093c602fabSXin LI #define MP_DSS_m                        0x08
1103c602fabSXin LI #define MP_DSS_M                        0x04
1113c602fabSXin LI #define MP_DSS_a                        0x02
1123c602fabSXin LI #define MP_DSS_A                        0x01
1133c602fabSXin LI 
114*ee67461eSJoseph Mingrone static const struct tok mptcp_addr_subecho_bits[] = {
115*ee67461eSJoseph Mingrone         { 0x6, "v0-ip6" },
116*ee67461eSJoseph Mingrone         { 0x4, "v0-ip4" },
117*ee67461eSJoseph Mingrone         { 0x1, "v1-echo" },
118*ee67461eSJoseph Mingrone         { 0x0, "v1" },
119*ee67461eSJoseph Mingrone         { 0, NULL }
120*ee67461eSJoseph Mingrone };
121*ee67461eSJoseph Mingrone 
1223c602fabSXin LI struct mp_add_addr {
123*ee67461eSJoseph Mingrone         nd_uint8_t     kind;
124*ee67461eSJoseph Mingrone         nd_uint8_t     len;
125*ee67461eSJoseph Mingrone         nd_uint8_t     sub_echo;
126*ee67461eSJoseph Mingrone         nd_uint8_t     addr_id;
1273c602fabSXin LI         union {
1283c602fabSXin LI                 struct {
129*ee67461eSJoseph Mingrone                         nd_ipv4         addr;
130*ee67461eSJoseph Mingrone                         nd_uint16_t     port;
131*ee67461eSJoseph Mingrone                         nd_uint64_t     mac;
1323c602fabSXin LI                 } v4;
1333c602fabSXin LI                 struct {
134*ee67461eSJoseph Mingrone                         nd_ipv4         addr;
135*ee67461eSJoseph Mingrone                         nd_uint64_t     mac;
136*ee67461eSJoseph Mingrone                 } v4np;
137*ee67461eSJoseph Mingrone                 struct {
138*ee67461eSJoseph Mingrone                         nd_ipv6         addr;
139*ee67461eSJoseph Mingrone                         nd_uint16_t     port;
140*ee67461eSJoseph Mingrone                         nd_uint64_t     mac;
1413c602fabSXin LI                 } v6;
142*ee67461eSJoseph Mingrone                 struct {
143*ee67461eSJoseph Mingrone                         nd_ipv6         addr;
144*ee67461eSJoseph Mingrone                         nd_uint64_t     mac;
145*ee67461eSJoseph Mingrone                 } v6np;
1463c602fabSXin LI         } u;
1473c602fabSXin LI };
1483c602fabSXin LI 
1493c602fabSXin LI struct mp_remove_addr {
150*ee67461eSJoseph Mingrone         nd_uint8_t     kind;
151*ee67461eSJoseph Mingrone         nd_uint8_t     len;
152*ee67461eSJoseph Mingrone         nd_uint8_t     sub;
1533c602fabSXin LI         /* list of addr_id */
154*ee67461eSJoseph Mingrone         nd_uint8_t     addrs_id[1];
1553c602fabSXin LI };
1563c602fabSXin LI 
1573c602fabSXin LI struct mp_fail {
158*ee67461eSJoseph Mingrone         nd_uint8_t     kind;
159*ee67461eSJoseph Mingrone         nd_uint8_t     len;
160*ee67461eSJoseph Mingrone         nd_uint8_t     sub;
161*ee67461eSJoseph Mingrone         nd_uint8_t     resv;
162*ee67461eSJoseph Mingrone         nd_uint64_t    data_seq;
1633c602fabSXin LI };
1643c602fabSXin LI 
1653c602fabSXin LI struct mp_close {
166*ee67461eSJoseph Mingrone         nd_uint8_t     kind;
167*ee67461eSJoseph Mingrone         nd_uint8_t     len;
168*ee67461eSJoseph Mingrone         nd_uint8_t     sub;
169*ee67461eSJoseph Mingrone         nd_uint8_t     rsv;
170*ee67461eSJoseph Mingrone         nd_byte        key[8];
1713c602fabSXin LI };
1723c602fabSXin LI 
1733c602fabSXin LI struct mp_prio {
174*ee67461eSJoseph Mingrone         nd_uint8_t     kind;
175*ee67461eSJoseph Mingrone         nd_uint8_t     len;
176*ee67461eSJoseph Mingrone         nd_uint8_t     sub_b;
177*ee67461eSJoseph Mingrone         nd_uint8_t     addr_id;
1783c602fabSXin LI };
1793c602fabSXin LI 
1803c602fabSXin LI #define MP_PRIO_B                       0x01
1813c602fabSXin LI 
1823c602fabSXin LI static int
dummy_print(netdissect_options * ndo _U_,const u_char * opt _U_,u_int opt_len _U_,u_char flags _U_)1833c602fabSXin LI dummy_print(netdissect_options *ndo _U_,
1843c602fabSXin LI             const u_char *opt _U_, u_int opt_len _U_, u_char flags _U_)
1853c602fabSXin LI {
1863c602fabSXin LI         return 1;
1873c602fabSXin LI }
1883c602fabSXin LI 
1893c602fabSXin LI static int
mp_capable_print(netdissect_options * ndo,const u_char * opt,u_int opt_len,u_char flags)1903c602fabSXin LI mp_capable_print(netdissect_options *ndo,
1913c602fabSXin LI                  const u_char *opt, u_int opt_len, u_char flags)
1923c602fabSXin LI {
1933340d773SGleb Smirnoff         const struct mp_capable *mpc = (const struct mp_capable *) opt;
194*ee67461eSJoseph Mingrone         uint8_t version;
1953c602fabSXin LI 
196*ee67461eSJoseph Mingrone         if (!((opt_len == 12 || opt_len == 4) && flags & TH_SYN) &&
197*ee67461eSJoseph Mingrone             !((opt_len == 20 || opt_len == 22) && (flags & (TH_SYN | TH_ACK)) ==
198*ee67461eSJoseph Mingrone               TH_ACK))
1993c602fabSXin LI                 return 0;
2003c602fabSXin LI 
201*ee67461eSJoseph Mingrone         version = MP_CAPABLE_OPT_VERSION(GET_U_1(mpc->sub_ver));
202*ee67461eSJoseph Mingrone         switch (version) {
203*ee67461eSJoseph Mingrone                 case 0: /* fall through */
204*ee67461eSJoseph Mingrone                 case 1:
205*ee67461eSJoseph Mingrone                         ND_PRINT(" v%u", version);
206*ee67461eSJoseph Mingrone                         break;
207*ee67461eSJoseph Mingrone                 default:
208*ee67461eSJoseph Mingrone                         ND_PRINT(" Unknown Version (%u)", version);
2093c602fabSXin LI                         return 1;
2103c602fabSXin LI         }
2113c602fabSXin LI 
212*ee67461eSJoseph Mingrone         if (GET_U_1(mpc->flags) & MP_CAPABLE_C)
213*ee67461eSJoseph Mingrone                 ND_PRINT(" csum");
214*ee67461eSJoseph Mingrone         if (opt_len == 12 || opt_len >= 20) {
215*ee67461eSJoseph Mingrone                 ND_PRINT(" {0x%" PRIx64, GET_BE_U_8(mpc->sender_key));
216*ee67461eSJoseph Mingrone                 if (opt_len >= 20)
217*ee67461eSJoseph Mingrone                         ND_PRINT(",0x%" PRIx64, GET_BE_U_8(mpc->receiver_key));
218*ee67461eSJoseph Mingrone                 ND_PRINT("}");
219*ee67461eSJoseph Mingrone         }
2203c602fabSXin LI         return 1;
2213c602fabSXin LI }
2223c602fabSXin LI 
2233c602fabSXin LI static int
mp_join_print(netdissect_options * ndo,const u_char * opt,u_int opt_len,u_char flags)2243c602fabSXin LI mp_join_print(netdissect_options *ndo,
2253c602fabSXin LI               const u_char *opt, u_int opt_len, u_char flags)
2263c602fabSXin LI {
2273340d773SGleb Smirnoff         const struct mp_join *mpj = (const struct mp_join *) opt;
2283c602fabSXin LI 
2290bff6a5aSEd Maste         if (!(opt_len == 12 && (flags & TH_SYN)) &&
2303c602fabSXin LI             !(opt_len == 16 && (flags & (TH_SYN | TH_ACK)) == (TH_SYN | TH_ACK)) &&
2310bff6a5aSEd Maste             !(opt_len == 24 && (flags & TH_ACK)))
2323c602fabSXin LI                 return 0;
2333c602fabSXin LI 
2343c602fabSXin LI         if (opt_len != 24) {
235*ee67461eSJoseph Mingrone                 if (GET_U_1(mpj->sub_b) & MP_JOIN_B)
236*ee67461eSJoseph Mingrone                         ND_PRINT(" backup");
237*ee67461eSJoseph Mingrone                 ND_PRINT(" id %u", GET_U_1(mpj->addr_id));
2383c602fabSXin LI         }
2393c602fabSXin LI 
2403c602fabSXin LI         switch (opt_len) {
2413c602fabSXin LI         case 12: /* SYN */
242*ee67461eSJoseph Mingrone                 ND_PRINT(" token 0x%x" " nonce 0x%x",
243*ee67461eSJoseph Mingrone                         GET_BE_U_4(mpj->u.syn.token),
244*ee67461eSJoseph Mingrone                         GET_BE_U_4(mpj->u.syn.nonce));
2453c602fabSXin LI                 break;
2463c602fabSXin LI         case 16: /* SYN/ACK */
247*ee67461eSJoseph Mingrone                 ND_PRINT(" hmac 0x%" PRIx64 " nonce 0x%x",
248*ee67461eSJoseph Mingrone                         GET_BE_U_8(mpj->u.synack.mac),
249*ee67461eSJoseph Mingrone                         GET_BE_U_4(mpj->u.synack.nonce));
2503c602fabSXin LI                 break;
2513c602fabSXin LI         case 24: {/* ACK */
2523c602fabSXin LI                 size_t i;
253*ee67461eSJoseph Mingrone                 ND_PRINT(" hmac 0x");
2543c602fabSXin LI                 for (i = 0; i < sizeof(mpj->u.ack.mac); ++i)
255*ee67461eSJoseph Mingrone                         ND_PRINT("%02x", mpj->u.ack.mac[i]);
2563c602fabSXin LI         }
2573c602fabSXin LI         default:
2583c602fabSXin LI                 break;
2593c602fabSXin LI         }
2603c602fabSXin LI         return 1;
2613c602fabSXin LI }
2623c602fabSXin LI 
2633c602fabSXin LI static int
mp_dss_print(netdissect_options * ndo,const u_char * opt,u_int opt_len,u_char flags)2643c602fabSXin LI mp_dss_print(netdissect_options *ndo,
2653c602fabSXin LI              const u_char *opt, u_int opt_len, u_char flags)
2663c602fabSXin LI {
2673340d773SGleb Smirnoff         const struct mp_dss *mdss = (const struct mp_dss *) opt;
268*ee67461eSJoseph Mingrone         uint8_t mdss_flags;
2693c602fabSXin LI 
2700bff6a5aSEd Maste         /* We need the flags, at a minimum. */
2710bff6a5aSEd Maste         if (opt_len < 4)
2720bff6a5aSEd Maste                 return 0;
2730bff6a5aSEd Maste 
2740bff6a5aSEd Maste         if (flags & TH_SYN)
2753c602fabSXin LI                 return 0;
2763c602fabSXin LI 
277*ee67461eSJoseph Mingrone         mdss_flags = GET_U_1(mdss->flags);
278*ee67461eSJoseph Mingrone         if (mdss_flags & MP_DSS_F)
279*ee67461eSJoseph Mingrone                 ND_PRINT(" fin");
2803c602fabSXin LI 
2813c602fabSXin LI         opt += 4;
2820bff6a5aSEd Maste         opt_len -= 4;
283*ee67461eSJoseph Mingrone         if (mdss_flags & MP_DSS_A) {
2840bff6a5aSEd Maste                 /* Ack present */
285*ee67461eSJoseph Mingrone                 ND_PRINT(" ack ");
2860bff6a5aSEd Maste                 /*
2870bff6a5aSEd Maste                  * If the a flag is set, we have an 8-byte ack; if it's
2880bff6a5aSEd Maste                  * clear, we have a 4-byte ack.
2890bff6a5aSEd Maste                  */
290*ee67461eSJoseph Mingrone                 if (mdss_flags & MP_DSS_a) {
2910bff6a5aSEd Maste                         if (opt_len < 8)
2920bff6a5aSEd Maste                                 return 0;
293*ee67461eSJoseph Mingrone                         ND_PRINT("%" PRIu64, GET_BE_U_8(opt));
2943c602fabSXin LI                         opt += 8;
2950bff6a5aSEd Maste                         opt_len -= 8;
2963c602fabSXin LI                 } else {
2970bff6a5aSEd Maste                         if (opt_len < 4)
2980bff6a5aSEd Maste                                 return 0;
299*ee67461eSJoseph Mingrone                         ND_PRINT("%u", GET_BE_U_4(opt));
3003c602fabSXin LI                         opt += 4;
3010bff6a5aSEd Maste                         opt_len -= 4;
3023c602fabSXin LI                 }
3033c602fabSXin LI         }
3043c602fabSXin LI 
305*ee67461eSJoseph Mingrone         if (mdss_flags & MP_DSS_M) {
3060bff6a5aSEd Maste                 /*
3070bff6a5aSEd Maste                  * Data Sequence Number (DSN), Subflow Sequence Number (SSN),
3080bff6a5aSEd Maste                  * Data-Level Length present, and Checksum possibly present.
3090bff6a5aSEd Maste                  */
310*ee67461eSJoseph Mingrone                 ND_PRINT(" seq ");
3110bff6a5aSEd Maste                 /*
3120bff6a5aSEd Maste                  * If the m flag is set, we have an 8-byte NDS; if it's clear,
3130bff6a5aSEd Maste                  * we have a 4-byte DSN.
3140bff6a5aSEd Maste                  */
315*ee67461eSJoseph Mingrone                 if (mdss_flags & MP_DSS_m) {
3160bff6a5aSEd Maste                         if (opt_len < 8)
3170bff6a5aSEd Maste                                 return 0;
318*ee67461eSJoseph Mingrone                         ND_PRINT("%" PRIu64, GET_BE_U_8(opt));
3193c602fabSXin LI                         opt += 8;
3200bff6a5aSEd Maste                         opt_len -= 8;
3213c602fabSXin LI                 } else {
3220bff6a5aSEd Maste                         if (opt_len < 4)
3230bff6a5aSEd Maste                                 return 0;
324*ee67461eSJoseph Mingrone                         ND_PRINT("%u", GET_BE_U_4(opt));
3253c602fabSXin LI                         opt += 4;
3260bff6a5aSEd Maste                         opt_len -= 4;
3273c602fabSXin LI                 }
3280bff6a5aSEd Maste                 if (opt_len < 4)
3290bff6a5aSEd Maste                         return 0;
330*ee67461eSJoseph Mingrone                 ND_PRINT(" subseq %u", GET_BE_U_4(opt));
3313c602fabSXin LI                 opt += 4;
3320bff6a5aSEd Maste                 opt_len -= 4;
3330bff6a5aSEd Maste                 if (opt_len < 2)
3340bff6a5aSEd Maste                         return 0;
335*ee67461eSJoseph Mingrone                 ND_PRINT(" len %u", GET_BE_U_2(opt));
3363c602fabSXin LI                 opt += 2;
3370bff6a5aSEd Maste                 opt_len -= 2;
3383c602fabSXin LI 
3390bff6a5aSEd Maste                 /*
3400bff6a5aSEd Maste                  * The Checksum is present only if negotiated.
3410bff6a5aSEd Maste                  * If there are at least 2 bytes left, process the next 2
3420bff6a5aSEd Maste                  * bytes as the Checksum.
3430bff6a5aSEd Maste                  */
3440bff6a5aSEd Maste                 if (opt_len >= 2) {
345*ee67461eSJoseph Mingrone                         ND_PRINT(" csum 0x%x", GET_BE_U_2(opt));
3460bff6a5aSEd Maste                         opt_len -= 2;
3473c602fabSXin LI                 }
3480bff6a5aSEd Maste         }
3490bff6a5aSEd Maste         if (opt_len != 0)
3500bff6a5aSEd Maste                 return 0;
3513c602fabSXin LI         return 1;
3523c602fabSXin LI }
3533c602fabSXin LI 
3543c602fabSXin LI static int
add_addr_print(netdissect_options * ndo,const u_char * opt,u_int opt_len,u_char flags _U_)3553c602fabSXin LI add_addr_print(netdissect_options *ndo,
3563c602fabSXin LI                const u_char *opt, u_int opt_len, u_char flags _U_)
3573c602fabSXin LI {
3583340d773SGleb Smirnoff         const struct mp_add_addr *add_addr = (const struct mp_add_addr *) opt;
3593c602fabSXin LI 
360*ee67461eSJoseph Mingrone         if (!(opt_len == 8 || opt_len == 10 || opt_len == 16 || opt_len == 18 ||
361*ee67461eSJoseph Mingrone             opt_len == 20 || opt_len == 22 || opt_len == 28 || opt_len == 30))
3623c602fabSXin LI                 return 0;
3633c602fabSXin LI 
364*ee67461eSJoseph Mingrone         ND_PRINT(" %s",
365*ee67461eSJoseph Mingrone                  tok2str(mptcp_addr_subecho_bits, "[bad version/echo]",
366*ee67461eSJoseph Mingrone                          GET_U_1(add_addr->sub_echo) & 0xF));
367*ee67461eSJoseph Mingrone         ND_PRINT(" id %u", GET_U_1(add_addr->addr_id));
368*ee67461eSJoseph Mingrone         if (opt_len == 8 || opt_len == 10 || opt_len == 16 || opt_len == 18) {
369*ee67461eSJoseph Mingrone                 ND_PRINT(" %s", GET_IPADDR_STRING(add_addr->u.v4.addr));
370*ee67461eSJoseph Mingrone                 if (opt_len == 10 || opt_len == 18)
371*ee67461eSJoseph Mingrone                         ND_PRINT(":%u", GET_BE_U_2(add_addr->u.v4.port));
372*ee67461eSJoseph Mingrone                 if (opt_len == 16)
373*ee67461eSJoseph Mingrone                         ND_PRINT(" hmac 0x%" PRIx64, GET_BE_U_8(add_addr->u.v4np.mac));
374*ee67461eSJoseph Mingrone                 if (opt_len == 18)
375*ee67461eSJoseph Mingrone                         ND_PRINT(" hmac 0x%" PRIx64, GET_BE_U_8(add_addr->u.v4.mac));
376*ee67461eSJoseph Mingrone         }
377*ee67461eSJoseph Mingrone 
378*ee67461eSJoseph Mingrone         if (opt_len == 20 || opt_len == 22 || opt_len == 28 || opt_len == 30) {
379*ee67461eSJoseph Mingrone                 ND_PRINT(" %s", GET_IP6ADDR_STRING(add_addr->u.v6.addr));
380*ee67461eSJoseph Mingrone                 if (opt_len == 22 || opt_len == 30)
381*ee67461eSJoseph Mingrone                         ND_PRINT(":%u", GET_BE_U_2(add_addr->u.v6.port));
382*ee67461eSJoseph Mingrone                 if (opt_len == 28)
383*ee67461eSJoseph Mingrone                         ND_PRINT(" hmac 0x%" PRIx64, GET_BE_U_8(add_addr->u.v6np.mac));
384*ee67461eSJoseph Mingrone                 if (opt_len == 30)
385*ee67461eSJoseph Mingrone                         ND_PRINT(" hmac 0x%" PRIx64, GET_BE_U_8(add_addr->u.v6.mac));
3863c602fabSXin LI         }
3873c602fabSXin LI 
3883c602fabSXin LI         return 1;
3893c602fabSXin LI }
3903c602fabSXin LI 
3913c602fabSXin LI static int
remove_addr_print(netdissect_options * ndo,const u_char * opt,u_int opt_len,u_char flags _U_)3923c602fabSXin LI remove_addr_print(netdissect_options *ndo,
3933c602fabSXin LI                   const u_char *opt, u_int opt_len, u_char flags _U_)
3943c602fabSXin LI {
3953340d773SGleb Smirnoff         const struct mp_remove_addr *remove_addr = (const struct mp_remove_addr *) opt;
396*ee67461eSJoseph Mingrone         u_int i;
3973c602fabSXin LI 
3983c602fabSXin LI         if (opt_len < 4)
3993c602fabSXin LI                 return 0;
4003c602fabSXin LI 
4013c602fabSXin LI         opt_len -= 3;
402*ee67461eSJoseph Mingrone         ND_PRINT(" id");
403*ee67461eSJoseph Mingrone         for (i = 0; i < opt_len; i++)
404*ee67461eSJoseph Mingrone                 ND_PRINT(" %u", GET_U_1(remove_addr->addrs_id[i]));
4053c602fabSXin LI         return 1;
4063c602fabSXin LI }
4073c602fabSXin LI 
4083c602fabSXin LI static int
mp_prio_print(netdissect_options * ndo,const u_char * opt,u_int opt_len,u_char flags _U_)4093c602fabSXin LI mp_prio_print(netdissect_options *ndo,
4103c602fabSXin LI               const u_char *opt, u_int opt_len, u_char flags _U_)
4113c602fabSXin LI {
4123340d773SGleb Smirnoff         const struct mp_prio *mpp = (const struct mp_prio *) opt;
4133c602fabSXin LI 
4143c602fabSXin LI         if (opt_len != 3 && opt_len != 4)
4153c602fabSXin LI                 return 0;
4163c602fabSXin LI 
417*ee67461eSJoseph Mingrone         if (GET_U_1(mpp->sub_b) & MP_PRIO_B)
418*ee67461eSJoseph Mingrone                 ND_PRINT(" backup");
4193c602fabSXin LI         else
420*ee67461eSJoseph Mingrone                 ND_PRINT(" non-backup");
4213c602fabSXin LI         if (opt_len == 4)
422*ee67461eSJoseph Mingrone                 ND_PRINT(" id %u", GET_U_1(mpp->addr_id));
4233c602fabSXin LI 
4243c602fabSXin LI         return 1;
4253c602fabSXin LI }
4263c602fabSXin LI 
4273c602fabSXin LI static int
mp_fail_print(netdissect_options * ndo,const u_char * opt,u_int opt_len,u_char flags _U_)4283c602fabSXin LI mp_fail_print(netdissect_options *ndo,
4293c602fabSXin LI               const u_char *opt, u_int opt_len, u_char flags _U_)
4303c602fabSXin LI {
4313c602fabSXin LI         if (opt_len != 12)
4323c602fabSXin LI                 return 0;
4333c602fabSXin LI 
434*ee67461eSJoseph Mingrone         ND_PRINT(" seq %" PRIu64, GET_BE_U_8(opt + 4));
4353c602fabSXin LI         return 1;
4363c602fabSXin LI }
4373c602fabSXin LI 
4383c602fabSXin LI static int
mp_fast_close_print(netdissect_options * ndo,const u_char * opt,u_int opt_len,u_char flags _U_)4393c602fabSXin LI mp_fast_close_print(netdissect_options *ndo,
4403c602fabSXin LI                     const u_char *opt, u_int opt_len, u_char flags _U_)
4413c602fabSXin LI {
4423c602fabSXin LI         if (opt_len != 12)
4433c602fabSXin LI                 return 0;
4443c602fabSXin LI 
445*ee67461eSJoseph Mingrone         ND_PRINT(" key 0x%" PRIx64, GET_BE_U_8(opt + 4));
4463c602fabSXin LI         return 1;
4473c602fabSXin LI }
4483c602fabSXin LI 
4493c602fabSXin LI static const struct {
4503c602fabSXin LI         const char *name;
4513c602fabSXin LI         int (*print)(netdissect_options *, const u_char *, u_int, u_char);
4523c602fabSXin LI } mptcp_options[] = {
4533c602fabSXin LI         { "capable",    mp_capable_print },
4543c602fabSXin LI         { "join",       mp_join_print },
4553c602fabSXin LI         { "dss",        mp_dss_print },
4563c602fabSXin LI         { "add-addr",   add_addr_print },
4573c602fabSXin LI         { "rem-addr",   remove_addr_print },
4583c602fabSXin LI         { "prio",       mp_prio_print },
4593c602fabSXin LI         { "fail",       mp_fail_print },
4603c602fabSXin LI         { "fast-close", mp_fast_close_print },
4613c602fabSXin LI         { "unknown",    dummy_print },
4623c602fabSXin LI };
4633c602fabSXin LI 
4643c602fabSXin LI int
mptcp_print(netdissect_options * ndo,const u_char * cp,u_int len,u_char flags)4653c602fabSXin LI mptcp_print(netdissect_options *ndo,
4663c602fabSXin LI             const u_char *cp, u_int len, u_char flags)
4673c602fabSXin LI {
4683340d773SGleb Smirnoff         const struct mptcp_option *opt;
4693c602fabSXin LI         u_int subtype;
4703c602fabSXin LI 
471*ee67461eSJoseph Mingrone         ndo->ndo_protocol = "mptcp";
4723c602fabSXin LI         if (len < 3)
4733c602fabSXin LI                 return 0;
4743c602fabSXin LI 
4753340d773SGleb Smirnoff         opt = (const struct mptcp_option *) cp;
476*ee67461eSJoseph Mingrone         subtype = MPTCP_OPT_SUBTYPE(GET_U_1(opt->sub_etc));
477*ee67461eSJoseph Mingrone         subtype = ND_MIN(subtype, MPTCP_SUB_FCLOSE + 1);
4783c602fabSXin LI 
479*ee67461eSJoseph Mingrone         ND_PRINT(" %u", len);
480*ee67461eSJoseph Mingrone 
481*ee67461eSJoseph Mingrone         ND_PRINT(" %s", mptcp_options[subtype].name);
4823c602fabSXin LI         return mptcp_options[subtype].print(ndo, cp, len, flags);
4833c602fabSXin LI }
484