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 uint8_t sub_etc; /* subtype upper 4 bits, other stuff lower 4 bits */
66 #define MPTCP_OPT_SUBTYPE(sub_etc) (((sub_etc) >> 4) & 0xF)
73 uint8_t sender_key[8];
74 uint8_t receiver_key[8];
77 #define MP_CAPABLE_OPT_VERSION(sub_ver) (((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
133 #define MP_ADD_ADDR_IPVER(sub_ipver) (((sub_ipver) >> 0) & 0xF)
135 struct mp_remove_addr {
139 /* list of addr_id */
166 #define MP_PRIO_B 0x01
169 dummy_print(netdissect_options *ndo _U_,
170 const u_char *opt _U_, u_int opt_len _U_, u_char flags _U_)
176 mp_capable_print(netdissect_options *ndo,
177 const u_char *opt, u_int opt_len, u_char flags)
179 const struct mp_capable *mpc = (const struct mp_capable *) opt;
181 if (!(opt_len == 12 && flags & TH_SYN) &&
182 !(opt_len == 20 && (flags & (TH_SYN | TH_ACK)) == TH_ACK))
185 if (MP_CAPABLE_OPT_VERSION(mpc->sub_ver) != 0) {
186 ND_PRINT((ndo, " Unknown Version (%d)", MP_CAPABLE_OPT_VERSION(mpc->sub_ver)));
190 if (mpc->flags & MP_CAPABLE_C)
191 ND_PRINT((ndo, " csum"));
192 ND_PRINT((ndo, " {0x%" PRIx64, EXTRACT_64BITS(mpc->sender_key)));
193 if (opt_len == 20) /* ACK */
194 ND_PRINT((ndo, ",0x%" PRIx64, EXTRACT_64BITS(mpc->receiver_key)));
195 ND_PRINT((ndo, "}"));
200 mp_join_print(netdissect_options *ndo,
201 const u_char *opt, u_int opt_len, u_char flags)
203 const struct mp_join *mpj = (const struct mp_join *) opt;
205 if (!(opt_len == 12 && flags & TH_SYN) &&
206 !(opt_len == 16 && (flags & (TH_SYN | TH_ACK)) == (TH_SYN | TH_ACK)) &&
207 !(opt_len == 24 && flags & TH_ACK))
211 if (mpj->sub_b & MP_JOIN_B)
212 ND_PRINT((ndo, " backup"));
213 ND_PRINT((ndo, " id %u", mpj->addr_id));
218 ND_PRINT((ndo, " token 0x%x" " nonce 0x%x",
219 EXTRACT_32BITS(mpj->u.syn.token),
220 EXTRACT_32BITS(mpj->u.syn.nonce)));
222 case 16: /* SYN/ACK */
223 ND_PRINT((ndo, " hmac 0x%" PRIx64 " nonce 0x%x",
224 EXTRACT_64BITS(mpj->u.synack.mac),
225 EXTRACT_32BITS(mpj->u.synack.nonce)));
229 ND_PRINT((ndo, " hmac 0x"));
230 for (i = 0; i < sizeof(mpj->u.ack.mac); ++i)
231 ND_PRINT((ndo, "%02x", mpj->u.ack.mac[i]));
239 static u_int mp_dss_len(const struct mp_dss *m, int csum)
244 if (m->flags & MP_DSS_A) {
245 /* Ack present - 4 or 8 octets */
246 len += (m->flags & MP_DSS_a) ? 8 : 4;
248 if (m->flags & MP_DSS_M) {
250 * Data Sequence Number (DSN), Subflow Sequence Number (SSN),
251 * Data-Level Length present, and Checksum possibly present.
252 * All but the Checksum are 10 bytes if the m flag is
253 * clear (4-byte DSN) and 14 bytes if the m flag is set
256 len += (m->flags & MP_DSS_m) ? 14 : 10;
259 * The Checksum is present only if negotiated.
268 mp_dss_print(netdissect_options *ndo,
269 const u_char *opt, u_int opt_len, u_char flags)
271 const struct mp_dss *mdss = (const struct mp_dss *) opt;
273 if ((opt_len != mp_dss_len(mdss, 1) &&
274 opt_len != mp_dss_len(mdss, 0)) || flags & TH_SYN)
277 if (mdss->flags & MP_DSS_F)
278 ND_PRINT((ndo, " fin"));
281 if (mdss->flags & MP_DSS_A) {
282 ND_PRINT((ndo, " ack "));
283 if (mdss->flags & MP_DSS_a) {
284 ND_PRINT((ndo, "%" PRIu64, EXTRACT_64BITS(opt)));
287 ND_PRINT((ndo, "%u", EXTRACT_32BITS(opt)));
292 if (mdss->flags & MP_DSS_M) {
293 ND_PRINT((ndo, " seq "));
294 if (mdss->flags & MP_DSS_m) {
295 ND_PRINT((ndo, "%" PRIu64, EXTRACT_64BITS(opt)));
298 ND_PRINT((ndo, "%u", EXTRACT_32BITS(opt)));
301 ND_PRINT((ndo, " subseq %u", EXTRACT_32BITS(opt)));
303 ND_PRINT((ndo, " len %u", EXTRACT_16BITS(opt)));
306 if (opt_len == mp_dss_len(mdss, 1))
307 ND_PRINT((ndo, " csum 0x%x", EXTRACT_16BITS(opt)));
313 add_addr_print(netdissect_options *ndo,
314 const u_char *opt, u_int opt_len, u_char flags _U_)
316 const struct mp_add_addr *add_addr = (const struct mp_add_addr *) opt;
317 u_int ipver = MP_ADD_ADDR_IPVER(add_addr->sub_ipver);
319 if (!((opt_len == 8 || opt_len == 10) && ipver == 4) &&
320 !((opt_len == 20 || opt_len == 22) && ipver == 6))
323 ND_PRINT((ndo, " id %u", add_addr->addr_id));
326 ND_PRINT((ndo, " %s", ipaddr_string(ndo, add_addr->u.v4.addr)));
328 ND_PRINT((ndo, ":%u", EXTRACT_16BITS(add_addr->u.v4.port)));
331 ND_PRINT((ndo, " %s", ip6addr_string(ndo, add_addr->u.v6.addr)));
333 ND_PRINT((ndo, ":%u", EXTRACT_16BITS(add_addr->u.v6.port)));
343 remove_addr_print(netdissect_options *ndo,
344 const u_char *opt, u_int opt_len, u_char flags _U_)
346 const struct mp_remove_addr *remove_addr = (const struct mp_remove_addr *) opt;
347 const uint8_t *addr_id = &remove_addr->addrs_id;
353 ND_PRINT((ndo, " id"));
355 ND_PRINT((ndo, " %u", *addr_id++));
360 mp_prio_print(netdissect_options *ndo,
361 const u_char *opt, u_int opt_len, u_char flags _U_)
363 const struct mp_prio *mpp = (const struct mp_prio *) opt;
365 if (opt_len != 3 && opt_len != 4)
368 if (mpp->sub_b & MP_PRIO_B)
369 ND_PRINT((ndo, " backup"));
371 ND_PRINT((ndo, " non-backup"));
373 ND_PRINT((ndo, " id %u", mpp->addr_id));
379 mp_fail_print(netdissect_options *ndo,
380 const u_char *opt, u_int opt_len, u_char flags _U_)
385 ND_PRINT((ndo, " seq %" PRIu64, EXTRACT_64BITS(opt + 4)));
390 mp_fast_close_print(netdissect_options *ndo,
391 const u_char *opt, u_int opt_len, u_char flags _U_)
396 ND_PRINT((ndo, " key 0x%" PRIx64, EXTRACT_64BITS(opt + 4)));
400 static const struct {
402 int (*print)(netdissect_options *, const u_char *, u_int, u_char);
403 } mptcp_options[] = {
404 { "capable", mp_capable_print},
405 { "join", mp_join_print },
406 { "dss", mp_dss_print },
407 { "add-addr", add_addr_print },
408 { "rem-addr", remove_addr_print },
409 { "prio", mp_prio_print },
410 { "fail", mp_fail_print },
411 { "fast-close", mp_fast_close_print },
412 { "unknown", dummy_print },
416 mptcp_print(netdissect_options *ndo,
417 const u_char *cp, u_int len, u_char flags)
419 const struct mptcp_option *opt;
425 opt = (const struct mptcp_option *) cp;
426 subtype = min(MPTCP_OPT_SUBTYPE(opt->sub_etc), MPTCP_SUB_FCLOSE + 1);
428 ND_PRINT((ndo, " %s", mptcp_options[subtype].name));
429 return mptcp_options[subtype].print(ndo, cp, len, flags);