]> The Tcpdump Group git mirrors - tcpdump/commitdiff
Add support for TCP Fast Open official IANA option number 449/head
authorDaniel Lee <[email protected]>
Wed, 8 Apr 2015 00:42:55 +0000 (17:42 -0700)
committerDaniel Lee <[email protected]>
Wed, 8 Apr 2015 19:45:33 +0000 (12:45 -0700)
https://tools.ietf.org/html/rfc7413

print-tcp.c
tcp.h

index 466fc48e9755b79cd44a0195463cfcfd2c0a2c8c..5c979235e6fe19f2612ff510c52731a0c29898e6 100644 (file)
@@ -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 c18d1382511c53d0d1a662673807c0b659999bb0..e8c8d2ca9b89eae112888256c5cd3f9fdd024a55 100644 (file)
--- 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      \