4 * Gregory Detal <gregory.detal@uclouvain.be>
5 * Christoph Paasch <christoph.paasch@uclouvain.be>
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
18 * 3. Neither the name of the University nor of the Laboratory may be used
19 * to endorse or promote products derived from this software without
20 * specific prior written permission.
22 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35 /* \summary: Multipath TCP (MPTCP) printer */
37 /* specification: RFC 6824 */
41 #include "netdissect-stdinc.h"
43 #include "netdissect.h"
45 #include "addrtoname.h"
49 #define MPTCP_SUB_CAPABLE 0x0
50 #define MPTCP_SUB_JOIN 0x1
51 #define MPTCP_SUB_DSS 0x2
52 #define MPTCP_SUB_ADD_ADDR 0x3
53 #define MPTCP_SUB_REMOVE_ADDR 0x4
54 #define MPTCP_SUB_PRIO 0x5
55 #define MPTCP_SUB_FAIL 0x6
56 #define MPTCP_SUB_FCLOSE 0x7
57 #define MPTCP_SUB_TCPRST 0x8
62 nd_uint8_t sub_etc
; /* subtype upper 4 bits, other stuff lower 4 bits */
65 #define MPTCP_OPT_SUBTYPE(sub_etc) (((sub_etc) >> 4) & 0xF)
67 #define MP_CAPABLE_A 0x80
69 static const struct tok mp_capable_flags
[] = {
70 { MP_CAPABLE_A
, "A" },
86 nd_uint64_t sender_key
;
87 nd_uint64_t receiver_key
;
91 #define MP_CAPABLE_OPT_VERSION(sub_ver) (((sub_ver) >> 0) & 0xF)
113 #define MP_JOIN_B 0x01
122 #define MP_DSS_F 0x10
123 #define MP_DSS_m 0x08
124 #define MP_DSS_M 0x04
125 #define MP_DSS_a 0x02
126 #define MP_DSS_A 0x01
128 static const struct tok mptcp_addr_subecho_bits
[] = {
163 struct mp_remove_addr
{
167 /* list of addr_id */
168 nd_uint8_t addrs_id
[1];
176 nd_uint64_t data_seq
;
194 #define MP_PRIO_B 0x01
196 static const struct tok mp_tcprst_flags
[] = {
204 static const struct tok mp_tcprst_reasons
[] = {
205 { 0x06, "Middlebox interference" },
206 { 0x05, "Unacceptable performance" },
207 { 0x04, "Too much outstanding data" },
208 { 0x03, "Administratively prohibited" },
209 { 0x02, "Lack of resources" },
210 { 0x01, "MPTCP-specific error" },
211 { 0x00, "Unspecified error" },
223 dummy_print(netdissect_options
*ndo _U_
,
224 const u_char
*opt _U_
, u_int opt_len _U_
, u_char flags _U_
)
230 mp_capable_print(netdissect_options
*ndo
,
231 const u_char
*opt
, u_int opt_len
, u_char flags
)
233 const struct mp_capable
*mpc
= (const struct mp_capable
*) opt
;
234 uint8_t version
, csum_enabled
;
236 if (!((opt_len
== 12 || opt_len
== 4) && flags
& TH_SYN
) &&
237 !((opt_len
== 20 || opt_len
== 22 || opt_len
== 24) && (flags
& (TH_SYN
| TH_ACK
)) ==
241 version
= MP_CAPABLE_OPT_VERSION(GET_U_1(mpc
->sub_ver
));
243 case 0: /* fall through */
245 ND_PRINT(" v%u", version
);
248 ND_PRINT(" Unknown Version (%u)", version
);
252 ND_PRINT(" flags [%s]", bittok2str_nosep(mp_capable_flags
, "none",
253 GET_U_1(mpc
->flags
)));
255 csum_enabled
= GET_U_1(mpc
->flags
) & MP_CAPABLE_A
;
258 if (opt_len
== 12 || opt_len
>= 20) {
259 ND_PRINT(" {0x%" PRIx64
, GET_BE_U_8(mpc
->sender_key
));
261 ND_PRINT(",0x%" PRIx64
, GET_BE_U_8(mpc
->receiver_key
));
263 /* RFC 8684 Section 3.1 */
264 if ((opt_len
== 22 && !csum_enabled
) || opt_len
== 24)
265 ND_PRINT(",data_len=%u", GET_BE_U_2(mpc
->data_len
));
272 mp_join_print(netdissect_options
*ndo
,
273 const u_char
*opt
, u_int opt_len
, u_char flags
)
275 const struct mp_join
*mpj
= (const struct mp_join
*) opt
;
277 if (!(opt_len
== 12 && (flags
& TH_SYN
)) &&
278 !(opt_len
== 16 && (flags
& (TH_SYN
| TH_ACK
)) == (TH_SYN
| TH_ACK
)) &&
279 !(opt_len
== 24 && (flags
& TH_ACK
)))
283 if (GET_U_1(mpj
->sub_b
) & MP_JOIN_B
)
285 ND_PRINT(" id %u", GET_U_1(mpj
->addr_id
));
290 ND_PRINT(" token 0x%x" " nonce 0x%x",
291 GET_BE_U_4(mpj
->u
.syn
.token
),
292 GET_BE_U_4(mpj
->u
.syn
.nonce
));
294 case 16: /* SYN/ACK */
295 ND_PRINT(" hmac 0x%" PRIx64
" nonce 0x%x",
296 GET_BE_U_8(mpj
->u
.synack
.mac
),
297 GET_BE_U_4(mpj
->u
.synack
.nonce
));
301 ND_PRINT(" hmac 0x");
302 for (i
= 0; i
< sizeof(mpj
->u
.ack
.mac
); ++i
)
303 ND_PRINT("%02x", mpj
->u
.ack
.mac
[i
]);
312 mp_dss_print(netdissect_options
*ndo
,
313 const u_char
*opt
, u_int opt_len
, u_char flags
)
315 const struct mp_dss
*mdss
= (const struct mp_dss
*) opt
;
318 /* We need the flags, at a minimum. */
325 mdss_flags
= GET_U_1(mdss
->flags
);
326 if (mdss_flags
& MP_DSS_F
)
331 if (mdss_flags
& MP_DSS_A
) {
335 * If the a flag is set, we have an 8-byte ack; if it's
336 * clear, we have a 4-byte ack.
338 if (mdss_flags
& MP_DSS_a
) {
341 ND_PRINT("%" PRIu64
, GET_BE_U_8(opt
));
347 ND_PRINT("%u", GET_BE_U_4(opt
));
353 if (mdss_flags
& MP_DSS_M
) {
355 * Data Sequence Number (DSN), Subflow Sequence Number (SSN),
356 * Data-Level Length present, and Checksum possibly present.
360 * If the m flag is set, we have an 8-byte NDS; if it's clear,
361 * we have a 4-byte DSN.
363 if (mdss_flags
& MP_DSS_m
) {
366 ND_PRINT("%" PRIu64
, GET_BE_U_8(opt
));
372 ND_PRINT("%u", GET_BE_U_4(opt
));
378 ND_PRINT(" subseq %u", GET_BE_U_4(opt
));
383 ND_PRINT(" len %u", GET_BE_U_2(opt
));
388 * The Checksum is present only if negotiated.
389 * If there are at least 2 bytes left, process the next 2
390 * bytes as the Checksum.
393 ND_PRINT(" csum 0x%x", GET_BE_U_2(opt
));
403 add_addr_print(netdissect_options
*ndo
,
404 const u_char
*opt
, u_int opt_len
, u_char flags _U_
)
406 const struct mp_add_addr
*add_addr
= (const struct mp_add_addr
*) opt
;
408 if (!(opt_len
== 8 || opt_len
== 10 || opt_len
== 16 || opt_len
== 18 ||
409 opt_len
== 20 || opt_len
== 22 || opt_len
== 28 || opt_len
== 30))
413 tok2str(mptcp_addr_subecho_bits
, "[bad version/echo]",
414 GET_U_1(add_addr
->sub_echo
) & 0xF));
415 ND_PRINT(" id %u", GET_U_1(add_addr
->addr_id
));
416 if (opt_len
== 8 || opt_len
== 10 || opt_len
== 16 || opt_len
== 18) {
417 ND_PRINT(" %s", GET_IPADDR_STRING(add_addr
->u
.v4
.addr
));
418 if (opt_len
== 10 || opt_len
== 18)
419 ND_PRINT(":%u", GET_BE_U_2(add_addr
->u
.v4
.port
));
421 ND_PRINT(" hmac 0x%" PRIx64
, GET_BE_U_8(add_addr
->u
.v4np
.mac
));
423 ND_PRINT(" hmac 0x%" PRIx64
, GET_BE_U_8(add_addr
->u
.v4
.mac
));
426 if (opt_len
== 20 || opt_len
== 22 || opt_len
== 28 || opt_len
== 30) {
427 ND_PRINT(" %s", GET_IP6ADDR_STRING(add_addr
->u
.v6
.addr
));
428 if (opt_len
== 22 || opt_len
== 30)
429 ND_PRINT(":%u", GET_BE_U_2(add_addr
->u
.v6
.port
));
431 ND_PRINT(" hmac 0x%" PRIx64
, GET_BE_U_8(add_addr
->u
.v6np
.mac
));
433 ND_PRINT(" hmac 0x%" PRIx64
, GET_BE_U_8(add_addr
->u
.v6
.mac
));
440 remove_addr_print(netdissect_options
*ndo
,
441 const u_char
*opt
, u_int opt_len
, u_char flags _U_
)
443 const struct mp_remove_addr
*remove_addr
= (const struct mp_remove_addr
*) opt
;
451 for (i
= 0; i
< opt_len
; i
++)
452 ND_PRINT(" %u", GET_U_1(remove_addr
->addrs_id
[i
]));
457 mp_prio_print(netdissect_options
*ndo
,
458 const u_char
*opt
, u_int opt_len
, u_char flags _U_
)
460 const struct mp_prio
*mpp
= (const struct mp_prio
*) opt
;
462 if (opt_len
!= 3 && opt_len
!= 4)
465 if (GET_U_1(mpp
->sub_b
) & MP_PRIO_B
)
468 ND_PRINT(" non-backup");
470 ND_PRINT(" id %u", GET_U_1(mpp
->addr_id
));
476 mp_fail_print(netdissect_options
*ndo
,
477 const u_char
*opt
, u_int opt_len
, u_char flags _U_
)
482 ND_PRINT(" seq %" PRIu64
, GET_BE_U_8(opt
+ 4));
487 mp_fast_close_print(netdissect_options
*ndo
,
488 const u_char
*opt
, u_int opt_len
, u_char flags _U_
)
493 ND_PRINT(" key 0x%" PRIx64
, GET_BE_U_8(opt
+ 4));
498 mp_tcprst_print(netdissect_options
*ndo
,
499 const u_char
*opt
, u_int opt_len
, u_char flags _U_
)
501 const struct mp_tcprst
*mpr
= (const struct mp_tcprst
*)opt
;
506 ND_PRINT(" flags [%s]", bittok2str_nosep(mp_tcprst_flags
, "none",
507 GET_U_1(mpr
->sub_b
)));
509 ND_PRINT(" reason %s", tok2str(mp_tcprst_reasons
, "unknown (0x%02x)",
510 GET_U_1(mpr
->reason
)));
514 static const struct {
516 int (*print
)(netdissect_options
*, const u_char
*, u_int
, u_char
);
517 } mptcp_options
[] = {
518 { "capable", mp_capable_print
},
519 { "join", mp_join_print
},
520 { "dss", mp_dss_print
},
521 { "add-addr", add_addr_print
},
522 { "rem-addr", remove_addr_print
},
523 { "prio", mp_prio_print
},
524 { "fail", mp_fail_print
},
525 { "fast-close", mp_fast_close_print
},
526 { "tcprst", mp_tcprst_print
},
527 { "unknown", dummy_print
},
531 mptcp_print(netdissect_options
*ndo
,
532 const u_char
*cp
, u_int len
, u_char flags
)
534 const struct mptcp_option
*opt
;
537 ndo
->ndo_protocol
= "mptcp";
541 opt
= (const struct mptcp_option
*) cp
;
542 subtype
= MPTCP_OPT_SUBTYPE(GET_U_1(opt
->sub_etc
));
543 subtype
= ND_MIN(subtype
, MPTCP_SUB_TCPRST
+ 1);
545 ND_PRINT(" %u", len
);
547 ND_PRINT(" %s", mptcp_options
[subtype
].name
);
548 return mptcp_options
[subtype
].print(ndo
, cp
, len
, flags
);