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 */
43 #include "netdissect-stdinc.h"
45 #include "netdissect.h"
47 #include "addrtoname.h"
51 #define MPTCP_SUB_CAPABLE 0x0
52 #define MPTCP_SUB_JOIN 0x1
53 #define MPTCP_SUB_DSS 0x2
54 #define MPTCP_SUB_ADD_ADDR 0x3
55 #define MPTCP_SUB_REMOVE_ADDR 0x4
56 #define MPTCP_SUB_PRIO 0x5
57 #define MPTCP_SUB_FAIL 0x6
58 #define MPTCP_SUB_FCLOSE 0x7
59 #define MPTCP_SUB_TCPRST 0x8
64 nd_uint8_t sub_etc
; /* subtype upper 4 bits, other stuff lower 4 bits */
67 #define MPTCP_OPT_SUBTYPE(sub_etc) (((sub_etc) >> 4) & 0xF)
69 #define MP_CAPABLE_A 0x80
71 static const struct tok mp_capable_flags
[] = {
72 { MP_CAPABLE_A
, "A" },
88 nd_uint64_t sender_key
;
89 nd_uint64_t receiver_key
;
93 #define MP_CAPABLE_OPT_VERSION(sub_ver) (((sub_ver) >> 0) & 0xF)
115 #define MP_JOIN_B 0x01
124 #define MP_DSS_F 0x10
125 #define MP_DSS_m 0x08
126 #define MP_DSS_M 0x04
127 #define MP_DSS_a 0x02
128 #define MP_DSS_A 0x01
130 static const struct tok mptcp_addr_subecho_bits
[] = {
165 struct mp_remove_addr
{
169 /* list of addr_id */
170 nd_uint8_t addrs_id
[1];
178 nd_uint64_t data_seq
;
196 #define MP_PRIO_B 0x01
198 static const struct tok mp_tcprst_flags
[] = {
206 static const struct tok mp_tcprst_reasons
[] = {
207 { 0x06, "Middlebox interference" },
208 { 0x05, "Unacceptable performance" },
209 { 0x04, "Too much outstanding data" },
210 { 0x03, "Administratively prohibited" },
211 { 0x02, "Lack of resources" },
212 { 0x01, "MPTCP-specific error" },
213 { 0x00, "Unspecified error" },
225 dummy_print(netdissect_options
*ndo _U_
,
226 const u_char
*opt _U_
, u_int opt_len _U_
, u_char flags _U_
)
232 mp_capable_print(netdissect_options
*ndo
,
233 const u_char
*opt
, u_int opt_len
, u_char flags
)
235 const struct mp_capable
*mpc
= (const struct mp_capable
*) opt
;
236 uint8_t version
, csum_enabled
;
238 if (!((opt_len
== 12 || opt_len
== 4) && flags
& TH_SYN
) &&
239 !((opt_len
== 20 || opt_len
== 22 || opt_len
== 24) && (flags
& (TH_SYN
| TH_ACK
)) ==
243 version
= MP_CAPABLE_OPT_VERSION(GET_U_1(mpc
->sub_ver
));
245 case 0: /* fall through */
247 ND_PRINT(" v%u", version
);
250 ND_PRINT(" Unknown Version (%u)", version
);
254 ND_PRINT(" flags [%s]", bittok2str_nosep(mp_capable_flags
, "none",
255 GET_U_1(mpc
->flags
)));
257 csum_enabled
= GET_U_1(mpc
->flags
) & MP_CAPABLE_A
;
260 if (opt_len
== 12 || opt_len
>= 20) {
261 ND_PRINT(" {0x%" PRIx64
, GET_BE_U_8(mpc
->sender_key
));
263 ND_PRINT(",0x%" PRIx64
, GET_BE_U_8(mpc
->receiver_key
));
265 /* RFC 8684 Section 3.1 */
266 if ((opt_len
== 22 && !csum_enabled
) || opt_len
== 24)
267 ND_PRINT(",data_len=%u", GET_BE_U_2(mpc
->data_len
));
274 mp_join_print(netdissect_options
*ndo
,
275 const u_char
*opt
, u_int opt_len
, u_char flags
)
277 const struct mp_join
*mpj
= (const struct mp_join
*) opt
;
279 if (!(opt_len
== 12 && (flags
& TH_SYN
)) &&
280 !(opt_len
== 16 && (flags
& (TH_SYN
| TH_ACK
)) == (TH_SYN
| TH_ACK
)) &&
281 !(opt_len
== 24 && (flags
& TH_ACK
)))
285 if (GET_U_1(mpj
->sub_b
) & MP_JOIN_B
)
287 ND_PRINT(" id %u", GET_U_1(mpj
->addr_id
));
292 ND_PRINT(" token 0x%x" " nonce 0x%x",
293 GET_BE_U_4(mpj
->u
.syn
.token
),
294 GET_BE_U_4(mpj
->u
.syn
.nonce
));
296 case 16: /* SYN/ACK */
297 ND_PRINT(" hmac 0x%" PRIx64
" nonce 0x%x",
298 GET_BE_U_8(mpj
->u
.synack
.mac
),
299 GET_BE_U_4(mpj
->u
.synack
.nonce
));
303 ND_PRINT(" hmac 0x");
304 for (i
= 0; i
< sizeof(mpj
->u
.ack
.mac
); ++i
)
305 ND_PRINT("%02x", mpj
->u
.ack
.mac
[i
]);
314 mp_dss_print(netdissect_options
*ndo
,
315 const u_char
*opt
, u_int opt_len
, u_char flags
)
317 const struct mp_dss
*mdss
= (const struct mp_dss
*) opt
;
320 /* We need the flags, at a minimum. */
327 mdss_flags
= GET_U_1(mdss
->flags
);
328 if (mdss_flags
& MP_DSS_F
)
333 if (mdss_flags
& MP_DSS_A
) {
337 * If the a flag is set, we have an 8-byte ack; if it's
338 * clear, we have a 4-byte ack.
340 if (mdss_flags
& MP_DSS_a
) {
343 ND_PRINT("%" PRIu64
, GET_BE_U_8(opt
));
349 ND_PRINT("%u", GET_BE_U_4(opt
));
355 if (mdss_flags
& MP_DSS_M
) {
357 * Data Sequence Number (DSN), Subflow Sequence Number (SSN),
358 * Data-Level Length present, and Checksum possibly present.
362 * If the m flag is set, we have an 8-byte NDS; if it's clear,
363 * we have a 4-byte DSN.
365 if (mdss_flags
& MP_DSS_m
) {
368 ND_PRINT("%" PRIu64
, GET_BE_U_8(opt
));
374 ND_PRINT("%u", GET_BE_U_4(opt
));
380 ND_PRINT(" subseq %u", GET_BE_U_4(opt
));
385 ND_PRINT(" len %u", GET_BE_U_2(opt
));
390 * The Checksum is present only if negotiated.
391 * If there are at least 2 bytes left, process the next 2
392 * bytes as the Checksum.
395 ND_PRINT(" csum 0x%x", GET_BE_U_2(opt
));
405 add_addr_print(netdissect_options
*ndo
,
406 const u_char
*opt
, u_int opt_len
, u_char flags _U_
)
408 const struct mp_add_addr
*add_addr
= (const struct mp_add_addr
*) opt
;
410 if (!(opt_len
== 8 || opt_len
== 10 || opt_len
== 16 || opt_len
== 18 ||
411 opt_len
== 20 || opt_len
== 22 || opt_len
== 28 || opt_len
== 30))
415 tok2str(mptcp_addr_subecho_bits
, "[bad version/echo]",
416 GET_U_1(add_addr
->sub_echo
) & 0xF));
417 ND_PRINT(" id %u", GET_U_1(add_addr
->addr_id
));
418 if (opt_len
== 8 || opt_len
== 10 || opt_len
== 16 || opt_len
== 18) {
419 ND_PRINT(" %s", GET_IPADDR_STRING(add_addr
->u
.v4
.addr
));
420 if (opt_len
== 10 || opt_len
== 18)
421 ND_PRINT(":%u", GET_BE_U_2(add_addr
->u
.v4
.port
));
423 ND_PRINT(" hmac 0x%" PRIx64
, GET_BE_U_8(add_addr
->u
.v4np
.mac
));
425 ND_PRINT(" hmac 0x%" PRIx64
, GET_BE_U_8(add_addr
->u
.v4
.mac
));
428 if (opt_len
== 20 || opt_len
== 22 || opt_len
== 28 || opt_len
== 30) {
429 ND_PRINT(" %s", GET_IP6ADDR_STRING(add_addr
->u
.v6
.addr
));
430 if (opt_len
== 22 || opt_len
== 30)
431 ND_PRINT(":%u", GET_BE_U_2(add_addr
->u
.v6
.port
));
433 ND_PRINT(" hmac 0x%" PRIx64
, GET_BE_U_8(add_addr
->u
.v6np
.mac
));
435 ND_PRINT(" hmac 0x%" PRIx64
, GET_BE_U_8(add_addr
->u
.v6
.mac
));
442 remove_addr_print(netdissect_options
*ndo
,
443 const u_char
*opt
, u_int opt_len
, u_char flags _U_
)
445 const struct mp_remove_addr
*remove_addr
= (const struct mp_remove_addr
*) opt
;
453 for (i
= 0; i
< opt_len
; i
++)
454 ND_PRINT(" %u", GET_U_1(remove_addr
->addrs_id
[i
]));
459 mp_prio_print(netdissect_options
*ndo
,
460 const u_char
*opt
, u_int opt_len
, u_char flags _U_
)
462 const struct mp_prio
*mpp
= (const struct mp_prio
*) opt
;
464 if (opt_len
!= 3 && opt_len
!= 4)
467 if (GET_U_1(mpp
->sub_b
) & MP_PRIO_B
)
470 ND_PRINT(" non-backup");
472 ND_PRINT(" id %u", GET_U_1(mpp
->addr_id
));
478 mp_fail_print(netdissect_options
*ndo
,
479 const u_char
*opt
, u_int opt_len
, u_char flags _U_
)
484 ND_PRINT(" seq %" PRIu64
, GET_BE_U_8(opt
+ 4));
489 mp_fast_close_print(netdissect_options
*ndo
,
490 const u_char
*opt
, u_int opt_len
, u_char flags _U_
)
495 ND_PRINT(" key 0x%" PRIx64
, GET_BE_U_8(opt
+ 4));
500 mp_tcprst_print(netdissect_options
*ndo
,
501 const u_char
*opt
, u_int opt_len
, u_char flags _U_
)
503 const struct mp_tcprst
*mpr
= (const struct mp_tcprst
*)opt
;
508 ND_PRINT(" flags [%s]", bittok2str_nosep(mp_tcprst_flags
, "none",
509 GET_U_1(mpr
->sub_b
)));
511 ND_PRINT(" reason %s", tok2str(mp_tcprst_reasons
, "unknown (0x%02x)",
512 GET_U_1(mpr
->reason
)));
516 static const struct {
518 int (*print
)(netdissect_options
*, const u_char
*, u_int
, u_char
);
519 } mptcp_options
[] = {
520 { "capable", mp_capable_print
},
521 { "join", mp_join_print
},
522 { "dss", mp_dss_print
},
523 { "add-addr", add_addr_print
},
524 { "rem-addr", remove_addr_print
},
525 { "prio", mp_prio_print
},
526 { "fail", mp_fail_print
},
527 { "fast-close", mp_fast_close_print
},
528 { "tcprst", mp_tcprst_print
},
529 { "unknown", dummy_print
},
533 mptcp_print(netdissect_options
*ndo
,
534 const u_char
*cp
, u_int len
, u_char flags
)
536 const struct mptcp_option
*opt
;
539 ndo
->ndo_protocol
= "mptcp";
543 opt
= (const struct mptcp_option
*) cp
;
544 subtype
= MPTCP_OPT_SUBTYPE(GET_U_1(opt
->sub_etc
));
545 subtype
= ND_MIN(subtype
, MPTCP_SUB_TCPRST
+ 1);
547 ND_PRINT(" %u", len
);
549 ND_PRINT(" %s", mptcp_options
[subtype
].name
);
550 return mptcp_options
[subtype
].print(ndo
, cp
, len
, flags
);