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
63 nd_uint8_t sub_etc
; /* subtype upper 4 bits, other stuff lower 4 bits */
66 #define MPTCP_OPT_SUBTYPE(sub_etc) ((GET_U_1(sub_etc) >> 4) & 0xF)
73 nd_uint64_t sender_key
;
74 nd_uint64_t receiver_key
;
77 #define MP_CAPABLE_OPT_VERSION(sub_ver) ((GET_U_1(sub_ver) >> 0) & 0xF)
78 #define MP_CAPABLE_C 0x80
79 #define MP_CAPABLE_S 0x01
101 #define MP_JOIN_B 0x01
110 #define MP_DSS_F 0x10
111 #define MP_DSS_m 0x08
112 #define MP_DSS_M 0x04
113 #define MP_DSS_a 0x02
114 #define MP_DSS_A 0x01
116 static const struct tok mptcp_addr_subecho_bits
[] = {
151 struct mp_remove_addr
{
155 /* list of addr_id */
156 nd_uint8_t addrs_id
[1];
164 nd_uint64_t data_seq
;
182 #define MP_PRIO_B 0x01
185 dummy_print(netdissect_options
*ndo _U_
,
186 const u_char
*opt _U_
, u_int opt_len _U_
, u_char flags _U_
)
192 mp_capable_print(netdissect_options
*ndo
,
193 const u_char
*opt
, u_int opt_len
, u_char flags
)
195 const struct mp_capable
*mpc
= (const struct mp_capable
*) opt
;
197 if (!((opt_len
== 12 || opt_len
== 4) && flags
& TH_SYN
) &&
198 !((opt_len
== 20 || opt_len
== 22) && (flags
& (TH_SYN
| TH_ACK
)) ==
202 switch (MP_CAPABLE_OPT_VERSION(mpc
->sub_ver
)) {
203 case 0: /* fall through */
205 ND_PRINT(" v%u", MP_CAPABLE_OPT_VERSION(mpc
->sub_ver
));
208 ND_PRINT(" Unknown Version (%u)",
209 MP_CAPABLE_OPT_VERSION(mpc
->sub_ver
));
213 if (GET_U_1(mpc
->flags
) & MP_CAPABLE_C
)
215 if (opt_len
== 12 || opt_len
>= 20) {
216 ND_PRINT(" {0x%" PRIx64
, GET_BE_U_8(mpc
->sender_key
));
218 ND_PRINT(",0x%" PRIx64
, GET_BE_U_8(mpc
->receiver_key
));
225 mp_join_print(netdissect_options
*ndo
,
226 const u_char
*opt
, u_int opt_len
, u_char flags
)
228 const struct mp_join
*mpj
= (const struct mp_join
*) opt
;
230 if (!(opt_len
== 12 && (flags
& TH_SYN
)) &&
231 !(opt_len
== 16 && (flags
& (TH_SYN
| TH_ACK
)) == (TH_SYN
| TH_ACK
)) &&
232 !(opt_len
== 24 && (flags
& TH_ACK
)))
236 if (GET_U_1(mpj
->sub_b
) & MP_JOIN_B
)
238 ND_PRINT(" id %u", GET_U_1(mpj
->addr_id
));
243 ND_PRINT(" token 0x%x" " nonce 0x%x",
244 GET_BE_U_4(mpj
->u
.syn
.token
),
245 GET_BE_U_4(mpj
->u
.syn
.nonce
));
247 case 16: /* SYN/ACK */
248 ND_PRINT(" hmac 0x%" PRIx64
" nonce 0x%x",
249 GET_BE_U_8(mpj
->u
.synack
.mac
),
250 GET_BE_U_4(mpj
->u
.synack
.nonce
));
254 ND_PRINT(" hmac 0x");
255 for (i
= 0; i
< sizeof(mpj
->u
.ack
.mac
); ++i
)
256 ND_PRINT("%02x", mpj
->u
.ack
.mac
[i
]);
265 mp_dss_print(netdissect_options
*ndo
,
266 const u_char
*opt
, u_int opt_len
, u_char flags
)
268 const struct mp_dss
*mdss
= (const struct mp_dss
*) opt
;
271 /* We need the flags, at a minimum. */
278 mdss_flags
= GET_U_1(mdss
->flags
);
279 if (mdss_flags
& MP_DSS_F
)
284 if (mdss_flags
& MP_DSS_A
) {
288 * If the a flag is set, we have an 8-byte ack; if it's
289 * clear, we have a 4-byte ack.
291 if (mdss_flags
& MP_DSS_a
) {
294 ND_PRINT("%" PRIu64
, GET_BE_U_8(opt
));
300 ND_PRINT("%u", GET_BE_U_4(opt
));
306 if (mdss_flags
& MP_DSS_M
) {
308 * Data Sequence Number (DSN), Subflow Sequence Number (SSN),
309 * Data-Level Length present, and Checksum possibly present.
313 * If the m flag is set, we have an 8-byte NDS; if it's clear,
314 * we have a 4-byte DSN.
316 if (mdss_flags
& MP_DSS_m
) {
319 ND_PRINT("%" PRIu64
, GET_BE_U_8(opt
));
325 ND_PRINT("%u", GET_BE_U_4(opt
));
331 ND_PRINT(" subseq %u", GET_BE_U_4(opt
));
336 ND_PRINT(" len %u", GET_BE_U_2(opt
));
341 * The Checksum is present only if negotiated.
342 * If there are at least 2 bytes left, process the next 2
343 * bytes as the Checksum.
346 ND_PRINT(" csum 0x%x", GET_BE_U_2(opt
));
356 add_addr_print(netdissect_options
*ndo
,
357 const u_char
*opt
, u_int opt_len
, u_char flags _U_
)
359 const struct mp_add_addr
*add_addr
= (const struct mp_add_addr
*) opt
;
361 if (!(opt_len
== 8 || opt_len
== 10 || opt_len
== 16 || opt_len
== 18 ||
362 opt_len
== 20 || opt_len
== 22 || opt_len
== 28 || opt_len
== 30))
366 tok2str(mptcp_addr_subecho_bits
, "[bad version/echo]",
367 GET_U_1(add_addr
->sub_echo
) & 0xF));
368 ND_PRINT(" id %u", GET_U_1(add_addr
->addr_id
));
369 if (opt_len
== 8 || opt_len
== 10 || opt_len
== 16 || opt_len
== 18) {
370 ND_PRINT(" %s", GET_IPADDR_STRING(add_addr
->u
.v4
.addr
));
371 if (opt_len
== 10 || opt_len
== 18)
372 ND_PRINT(":%u", GET_BE_U_2(add_addr
->u
.v4
.port
));
374 ND_PRINT(" hmac 0x%" PRIx64
, GET_BE_U_8(add_addr
->u
.v4np
.mac
));
376 ND_PRINT(" hmac 0x%" PRIx64
, GET_BE_U_8(add_addr
->u
.v4
.mac
));
379 if (opt_len
== 20 || opt_len
== 22 || opt_len
== 28 || opt_len
== 30) {
380 ND_PRINT(" %s", GET_IP6ADDR_STRING(add_addr
->u
.v6
.addr
));
381 if (opt_len
== 22 || opt_len
== 30)
382 ND_PRINT(":%u", GET_BE_U_2(add_addr
->u
.v6
.port
));
384 ND_PRINT(" hmac 0x%" PRIx64
, GET_BE_U_8(add_addr
->u
.v6np
.mac
));
386 ND_PRINT(" hmac 0x%" PRIx64
, GET_BE_U_8(add_addr
->u
.v6
.mac
));
393 remove_addr_print(netdissect_options
*ndo
,
394 const u_char
*opt
, u_int opt_len
, u_char flags _U_
)
396 const struct mp_remove_addr
*remove_addr
= (const struct mp_remove_addr
*) opt
;
404 for (i
= 0; i
< opt_len
; i
++)
405 ND_PRINT(" %u", GET_U_1(remove_addr
->addrs_id
[i
]));
410 mp_prio_print(netdissect_options
*ndo
,
411 const u_char
*opt
, u_int opt_len
, u_char flags _U_
)
413 const struct mp_prio
*mpp
= (const struct mp_prio
*) opt
;
415 if (opt_len
!= 3 && opt_len
!= 4)
418 if (GET_U_1(mpp
->sub_b
) & MP_PRIO_B
)
421 ND_PRINT(" non-backup");
423 ND_PRINT(" id %u", GET_U_1(mpp
->addr_id
));
429 mp_fail_print(netdissect_options
*ndo
,
430 const u_char
*opt
, u_int opt_len
, u_char flags _U_
)
435 ND_PRINT(" seq %" PRIu64
, GET_BE_U_8(opt
+ 4));
440 mp_fast_close_print(netdissect_options
*ndo
,
441 const u_char
*opt
, u_int opt_len
, u_char flags _U_
)
446 ND_PRINT(" key 0x%" PRIx64
, GET_BE_U_8(opt
+ 4));
450 static const struct {
452 int (*print
)(netdissect_options
*, const u_char
*, u_int
, u_char
);
453 } mptcp_options
[] = {
454 { "capable", mp_capable_print
},
455 { "join", mp_join_print
},
456 { "dss", mp_dss_print
},
457 { "add-addr", add_addr_print
},
458 { "rem-addr", remove_addr_print
},
459 { "prio", mp_prio_print
},
460 { "fail", mp_fail_print
},
461 { "fast-close", mp_fast_close_print
},
462 { "unknown", dummy_print
},
466 mptcp_print(netdissect_options
*ndo
,
467 const u_char
*cp
, u_int len
, u_char flags
)
469 const struct mptcp_option
*opt
;
472 ndo
->ndo_protocol
= "mptcp";
476 opt
= (const struct mptcp_option
*) cp
;
478 subtype
= ND_MIN(MPTCP_OPT_SUBTYPE(opt
->sub_etc
), MPTCP_SUB_FCLOSE
+ 1);
480 ND_PRINT(" %s", mptcp_options
[subtype
].name
);
481 return mptcp_options
[subtype
].print(ndo
, cp
, len
, flags
);