]> The Tcpdump Group git mirrors - tcpdump/blobdiff - print-tcp.c
Print src > dst, not dst > src.
[tcpdump] / print-tcp.c
index bc200e2f8e21a5d243985e2a5ed3eae0b93f7aec..5c979235e6fe19f2612ff510c52731a0c29898e6 100644 (file)
@@ -28,7 +28,6 @@
 __RCSID("$NetBSD: print-tcp.c,v 1.8 2007/07/24 11:53:48 drochner Exp $");
 #endif
 
-#define NETDISSECT_REWORKED
 #ifdef HAVE_CONFIG_H
 #include "config.h"
 #endif
@@ -64,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
 
@@ -135,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 }
 };
@@ -584,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);
@@ -595,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:
@@ -797,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