From: Daniel Lee Date: Wed, 8 Apr 2015 00:42:55 +0000 (-0700) Subject: Add support for TCP Fast Open official IANA option number X-Git-Tag: tcpdump-4.8.0~282^2~32^2 X-Git-Url: https://git.tcpdump.org/tcpdump/commitdiff_plain/cc469325c3fa3c1867e2319012222add290f7ab5 Add support for TCP Fast Open official IANA option number https://tools.ietf.org/html/rfc7413 --- diff --git a/print-tcp.c b/print-tcp.c index 466fc48e..5c979235 100644 --- a/print-tcp.c +++ b/print-tcp.c @@ -63,6 +63,8 @@ static int tcp_verify_signature(netdissect_options *ndo, #endif static void print_tcp_rst_data(netdissect_options *, register const u_char *sp, u_int length); +static void print_tcp_fastopen_option(netdissect_options *ndo, register const u_char *cp, + u_int datalen, int exp); #define MAX_RST_DATA_LEN 30 @@ -134,6 +136,7 @@ static const struct tok tcp_option_values[] = { { TCPOPT_AUTH, "enhanced auth" }, { TCPOPT_UTO, "uto" }, { TCPOPT_MPTCP, "mptcp" }, + { TCPOPT_FASTOPEN, "tfo" }, { TCPOPT_EXPERIMENT2, "exp" }, { 0, NULL } }; @@ -583,6 +586,12 @@ tcp_print(netdissect_options *ndo, goto bad; break; + case TCPOPT_FASTOPEN: + datalen = len - 2; + LENCHECK(datalen); + print_tcp_fastopen_option(ndo, cp, datalen, FALSE); + break; + case TCPOPT_EXPERIMENT2: datalen = len - 2; LENCHECK(datalen); @@ -594,21 +603,8 @@ tcp_print(netdissect_options *ndo, switch(magic) { - case 0xf989: - /* TCP Fast Open: RFC 7413 */ - if (datalen == 2) { - /* Fast Open Cookie Request */ - ND_PRINT((ndo, "tfo cookiereq")); - } else { - /* Fast Open Cookie */ - if (datalen % 2 != 0 || datalen < 6 || datalen > 18) { - ND_PRINT((ndo, "tfo malformed")); - } else { - ND_PRINT((ndo, "tfo cookie ")); - for (i = 2; i < datalen; ++i) - ND_PRINT((ndo, "%02x", cp[i])); - } - } + case 0xf989: /* TCP Fast Open RFC 7413 */ + print_tcp_fastopen_option(ndo, cp + 2, datalen - 2, TRUE); break; default: @@ -796,6 +792,30 @@ print_tcp_rst_data(netdissect_options *ndo, ND_PRINT((ndo, "]")); } +static void +print_tcp_fastopen_option(netdissect_options *ndo, register const u_char *cp, + u_int datalen, int exp) +{ + u_int i; + + if (exp) + ND_PRINT((ndo, "tfo")); + + if (datalen == 0) { + /* Fast Open Cookie Request */ + ND_PRINT((ndo, " cookiereq")); + } else { + /* Fast Open Cookie */ + if (datalen % 2 != 0 || datalen < 4 || datalen > 16) { + ND_PRINT((ndo, " malformed")); + } else { + ND_PRINT((ndo, " cookie ")); + for (i = 0; i < datalen; ++i) + ND_PRINT((ndo, "%02x", cp[i])); + } + } +} + #ifdef HAVE_LIBCRYPTO USES_APPLE_DEPRECATED_API static int diff --git a/tcp.h b/tcp.h index c18d1382..e8c8d2ca 100644 --- a/tcp.h +++ b/tcp.h @@ -85,6 +85,7 @@ struct tcphdr { #define TCPOPT_UTO 28 /* tcp user timeout (rfc5482) */ #define TCPOLEN_UTO 4 #define TCPOPT_MPTCP 30 /* MPTCP options */ +#define TCPOPT_FASTOPEN 34 /* TCP Fast Open (rfc7413) */ #define TCPOPT_EXPERIMENT2 254 /* experimental headers (rfc4727) */ #define TCPOPT_TSTAMP_HDR \