-#define LENCHECK(l) { if ((l) > hlen) goto bad; TCHECK2(*cp, l); }
-
- switch (opt) {
-
- case TCPOPT_MAXSEG:
- (void)printf("mss");
- datalen = 2;
- LENCHECK(datalen);
- (void)printf(" %u", EXTRACT_16BITS(cp));
-
- break;
-
- case TCPOPT_EOL:
- (void)printf("eol");
- break;
-
- case TCPOPT_NOP:
- (void)printf("nop");
- break;
-
- case TCPOPT_WSCALE:
- (void)printf("wscale");
- datalen = 1;
- LENCHECK(datalen);
- (void)printf(" %u", *cp);
- break;
-
- case TCPOPT_SACKOK:
- (void)printf("sackOK");
- break;
-
- case TCPOPT_SACK:
- (void)printf("sack");
- datalen = len - 2;
- if (datalen % 8 != 0) {
- (void)printf(" malformed sack ");
- } else {
- u_int32_t s, e;
-
- (void)printf(" sack %d ", datalen / 8);
- for (i = 0; i < datalen; i += 8) {
- LENCHECK(i + 4);
- s = EXTRACT_32BITS(cp + i);
- LENCHECK(i + 8);
- e = EXTRACT_32BITS(cp + i + 4);
- if (threv) {
- s -= thseq;
- e -= thseq;
- } else {
- s -= thack;
- e -= thack;
- }
- (void)printf("{%u:%u}", s, e);
- }
- (void)printf(" ");
- }
- break;
-
- case TCPOPT_ECHO:
- (void)printf("echo");
- datalen = 4;
- LENCHECK(datalen);
- (void)printf(" %u", EXTRACT_32BITS(cp));
- break;
-
- case TCPOPT_ECHOREPLY:
- (void)printf("echoreply");
- datalen = 4;
- LENCHECK(datalen);
- (void)printf(" %u", EXTRACT_32BITS(cp));
- break;
-
- case TCPOPT_TIMESTAMP:
- (void)printf("timestamp");
- datalen = 8;
- LENCHECK(4);
- (void)printf(" %u", EXTRACT_32BITS(cp));
- LENCHECK(datalen);
- (void)printf(" %u", EXTRACT_32BITS(cp + 4));
- break;
-
- case TCPOPT_CC:
- (void)printf("cc");
- datalen = 4;
- LENCHECK(datalen);
- (void)printf(" %u", EXTRACT_32BITS(cp));
- break;
-
- case TCPOPT_CCNEW:
- (void)printf("ccnew");
- datalen = 4;
- LENCHECK(datalen);
- (void)printf(" %u", EXTRACT_32BITS(cp));
- break;
-
- case TCPOPT_CCECHO:
- (void)printf("ccecho");
- datalen = 4;
- LENCHECK(datalen);
- (void)printf(" %u", EXTRACT_32BITS(cp));
- break;
-
- default:
- (void)printf("opt-%d:", opt);
- datalen = len - 2;
- for (i = 0; i < datalen; ++i) {
- LENCHECK(i);
- (void)printf("%02x", cp[i]);
- }
- break;
- }
-
- /* Account for data printed */
- cp += datalen;
- hlen -= datalen;
-
- /* Check specification against observed length */
- ++datalen; /* option octet */
- if (!ZEROLENOPT(opt))
- ++datalen; /* size octet */
- if (datalen != len)
- (void)printf("[len %d]", len);
- ch = ',';
- if (opt == TCPOPT_EOL)
- break;
- }
- putchar('>');
- }
-
- if (length <= 0)
- return;
-
- /*
- * Decode payload if necessary.
- */
- bp += (tp->th_off * 4);
- if (flags & TH_RST) {
- if (vflag)
- print_tcp_rst_data(bp, length);
- } else {
- if (sport == TELNET_PORT || dport == TELNET_PORT) {
- if (!qflag && vflag)
- telnet_print(bp, length);
- } else if (sport == BGP_PORT || dport == BGP_PORT)
- bgp_print(bp, length);
- else if (sport == NETBIOS_SSN_PORT || dport == NETBIOS_SSN_PORT)
- nbt_tcp_print(bp, length);
- }
- return;
-bad:
- fputs("[bad opt]", stdout);
- if (ch != '\0')
- putchar('>');
- return;
-trunc:
- fputs("[|tcp]", stdout);
- if (ch != '\0')
- putchar('>');
+#define LENCHECK(l) { if ((l) > hlen) goto bad; ND_TCHECK2(*cp, l); }
+
+
+ ND_PRINT((ndo, "%s", tok2str(tcp_option_values, "unknown-%u", opt)));
+
+ switch (opt) {
+
+ case TCPOPT_MAXSEG:
+ datalen = 2;
+ LENCHECK(datalen);
+ ND_PRINT((ndo, " %u", EXTRACT_16BITS(cp)));
+ break;
+
+ case TCPOPT_WSCALE:
+ datalen = 1;
+ LENCHECK(datalen);
+ ND_PRINT((ndo, " %u", *cp));
+ break;
+
+ case TCPOPT_SACK:
+ datalen = len - 2;
+ if (datalen % 8 != 0) {
+ ND_PRINT((ndo, "malformed sack"));
+ } else {
+ uint32_t s, e;
+
+ ND_PRINT((ndo, " %d ", datalen / 8));
+ for (i = 0; i < datalen; i += 8) {
+ LENCHECK(i + 4);
+ s = EXTRACT_32BITS(cp + i);
+ LENCHECK(i + 8);
+ e = EXTRACT_32BITS(cp + i + 4);
+ if (rev) {
+ s -= thseq;
+ e -= thseq;
+ } else {
+ s -= thack;
+ e -= thack;
+ }
+ ND_PRINT((ndo, "{%u:%u}", s, e));
+ }
+ }
+ break;
+
+ case TCPOPT_CC:
+ case TCPOPT_CCNEW:
+ case TCPOPT_CCECHO:
+ case TCPOPT_ECHO:
+ case TCPOPT_ECHOREPLY:
+
+ /*
+ * those options share their semantics.
+ * fall through
+ */
+ datalen = 4;
+ LENCHECK(datalen);
+ ND_PRINT((ndo, " %u", EXTRACT_32BITS(cp)));
+ break;
+
+ case TCPOPT_TIMESTAMP:
+ datalen = 8;
+ LENCHECK(datalen);
+ ND_PRINT((ndo, " val %u ecr %u",
+ EXTRACT_32BITS(cp),
+ EXTRACT_32BITS(cp + 4)));
+ break;
+
+ case TCPOPT_SIGNATURE:
+ datalen = TCP_SIGLEN;
+ LENCHECK(datalen);
+#ifdef HAVE_LIBCRYPTO
+ switch (tcp_verify_signature(ndo, ip, tp,
+ bp + TH_OFF(tp) * 4, length, cp)) {
+
+ case SIGNATURE_VALID:
+ ND_PRINT((ndo, "valid"));
+ break;
+
+ case SIGNATURE_INVALID:
+ ND_PRINT((ndo, "invalid"));
+ break;
+
+ case CANT_CHECK_SIGNATURE:
+ ND_PRINT((ndo, "can't check - "));
+ for (i = 0; i < TCP_SIGLEN; ++i)
+ ND_PRINT((ndo, "%02x", cp[i]));
+ break;
+ }
+#else
+ for (i = 0; i < TCP_SIGLEN; ++i)
+ ND_PRINT((ndo, "%02x", cp[i]));
+#endif
+ break;
+
+ case TCPOPT_AUTH:
+ ND_PRINT((ndo, "keyid %d", *cp++));
+ datalen = len - 3;
+ for (i = 0; i < datalen; ++i) {
+ LENCHECK(i);
+ ND_PRINT((ndo, "%02x", cp[i]));
+ }
+ break;
+
+
+ case TCPOPT_EOL:
+ case TCPOPT_NOP:
+ case TCPOPT_SACKOK:
+ /*
+ * Nothing interesting.
+ * fall through
+ */
+ break;
+
+ case TCPOPT_UTO:
+ datalen = 2;
+ LENCHECK(datalen);
+ utoval = EXTRACT_16BITS(cp);
+ ND_PRINT((ndo, "0x%x", utoval));
+ if (utoval & 0x0001)
+ utoval = (utoval >> 1) * 60;
+ else
+ utoval >>= 1;
+ ND_PRINT((ndo, " %u", utoval));
+ break;
+
+ case TCPOPT_MPTCP:
+ datalen = len - 2;
+ LENCHECK(datalen);
+ if (!mptcp_print(ndo, cp-2, len, flags))
+ goto bad;
+ break;
+
+ case TCPOPT_EXPERIMENT2:
+ datalen = len - 2;
+ LENCHECK(datalen);
+ if (datalen < 2)
+ goto bad;
+ /* RFC6994 */
+ magic = EXTRACT_16BITS(cp);
+ ND_PRINT((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]));
+ }
+ }
+ break;
+
+ default:
+ /* Unknown magic number */
+ ND_PRINT((ndo, "%04x", magic));
+ break;
+ }
+ break;
+
+ default:
+ datalen = len - 2;
+ if (datalen)
+ ND_PRINT((ndo, " 0x"));
+ for (i = 0; i < datalen; ++i) {
+ LENCHECK(i);
+ ND_PRINT((ndo, "%02x", cp[i]));
+ }
+ break;
+ }
+
+ /* Account for data printed */
+ cp += datalen;
+ hlen -= datalen;
+
+ /* Check specification against observed length */
+ ++datalen; /* option octet */
+ if (!ZEROLENOPT(opt))
+ ++datalen; /* size octet */
+ if (datalen != len)
+ ND_PRINT((ndo, "[len %d]", len));
+ ch = ',';
+ if (opt == TCPOPT_EOL)
+ break;
+ }
+ ND_PRINT((ndo, "]"));
+ }
+
+ /*
+ * Print length field before crawling down the stack.
+ */
+ ND_PRINT((ndo, ", length %u", length));
+
+ if (length <= 0)
+ return;
+
+ /*
+ * Decode payload if necessary.
+ */
+ bp += TH_OFF(tp) * 4;
+ if ((flags & TH_RST) && ndo->ndo_vflag) {
+ print_tcp_rst_data(ndo, bp, length);
+ return;
+ }
+
+ if (ndo->ndo_packettype) {
+ switch (ndo->ndo_packettype) {
+ case PT_ZMTP1:
+ zmtp1_print(ndo, bp, length);
+ break;
+ }
+ return;
+ }
+
+ if (sport == TELNET_PORT || dport == TELNET_PORT) {
+ telnet_print(ndo, bp, length);
+ } else if (sport == SMTP_PORT || dport == SMTP_PORT) {
+ ND_PRINT((ndo, ": "));
+ smtp_print(ndo, bp, length);
+ } else if (sport == BGP_PORT || dport == BGP_PORT)
+ bgp_print(ndo, bp, length);
+ else if (sport == PPTP_PORT || dport == PPTP_PORT)
+ pptp_print(ndo, bp);
+#ifdef TCPDUMP_DO_SMB
+ else if (sport == NETBIOS_SSN_PORT || dport == NETBIOS_SSN_PORT)
+ nbt_tcp_print(ndo, bp, length);
+ else if (sport == SMB_PORT || dport == SMB_PORT)
+ smb_tcp_print(ndo, bp, length);
+#endif
+ else if (sport == BEEP_PORT || dport == BEEP_PORT)
+ beep_print(ndo, bp, length);
+ else if (sport == OPENFLOW_PORT_OLD || dport == OPENFLOW_PORT_OLD ||
+ sport == OPENFLOW_PORT_IANA || dport == OPENFLOW_PORT_IANA)
+ openflow_print(ndo, bp, length);
+ else if (sport == FTP_PORT || dport == FTP_PORT) {
+ ND_PRINT((ndo, ": "));
+ ftp_print(ndo, bp, length);
+ } else if (sport == HTTP_PORT || dport == HTTP_PORT ||
+ sport == HTTP_PORT_ALT || dport == HTTP_PORT_ALT) {
+ ND_PRINT((ndo, ": "));
+ http_print(ndo, bp, length);
+ } else if (sport == RTSP_PORT || dport == RTSP_PORT ||
+ sport == RTSP_PORT_ALT || dport == RTSP_PORT_ALT) {
+ ND_PRINT((ndo, ": "));
+ rtsp_print(ndo, bp, length);
+ } else if (length > 2 &&
+ (sport == NAMESERVER_PORT || dport == NAMESERVER_PORT ||
+ sport == MULTICASTDNS_PORT || dport == MULTICASTDNS_PORT)) {
+ /*
+ * TCP DNS query has 2byte length at the head.
+ * XXX packet could be unaligned, it can go strange
+ */
+ ns_print(ndo, bp + 2, length - 2, 0);
+ } else if (sport == MSDP_PORT || dport == MSDP_PORT) {
+ msdp_print(ndo, bp, length);
+ } else if (sport == RPKI_RTR_PORT || dport == RPKI_RTR_PORT) {
+ rpki_rtr_print(ndo, bp, length);
+ }
+ else if (length > 0 && (sport == LDP_PORT || dport == LDP_PORT)) {
+ ldp_print(ndo, bp, length);
+ }
+ else if ((sport == NFS_PORT || dport == NFS_PORT) &&
+ length >= 4 && ND_TTEST2(*bp, 4)) {
+ /*
+ * If data present, header length valid, and NFS port used,
+ * assume NFS.
+ * Pass offset of data plus 4 bytes for RPC TCP msg length
+ * to NFS print routines.
+ */
+ uint32_t fraglen;
+ register struct sunrpc_msg *rp;
+ enum sunrpc_msg_type direction;
+
+ fraglen = EXTRACT_32BITS(bp) & 0x7FFFFFFF;
+ if (fraglen > (length) - 4)
+ fraglen = (length) - 4;
+ rp = (struct sunrpc_msg *)(bp + 4);
+ if (ND_TTEST(rp->rm_direction)) {
+ direction = (enum sunrpc_msg_type)EXTRACT_32BITS(&rp->rm_direction);
+ if (dport == NFS_PORT && direction == SUNRPC_CALL) {
+ ND_PRINT((ndo, ": NFS request xid %u ", EXTRACT_32BITS(&rp->rm_xid)));
+ nfsreq_print_noaddr(ndo, (u_char *)rp, fraglen, (u_char *)ip);
+ return;
+ }
+ if (sport == NFS_PORT && direction == SUNRPC_REPLY) {
+ ND_PRINT((ndo, ": NFS reply xid %u ", EXTRACT_32BITS(&rp->rm_xid)));
+ nfsreply_print_noaddr(ndo, (u_char *)rp, fraglen, (u_char *)ip);
+ return;
+ }
+ }
+ }
+
+ return;
+ bad:
+ ND_PRINT((ndo, "[bad opt]"));
+ if (ch != '\0')
+ ND_PRINT((ndo, ">"));
+ return;
+ trunc:
+ ND_PRINT((ndo, "[|tcp]"));
+ if (ch != '\0')
+ ND_PRINT((ndo, ">"));