X-Git-Url: https://git.tcpdump.org/tcpdump/blobdiff_plain/730d36df2c5582096e293cffc81e1682bbf26ef2..f53e36817312f87f7f41463b70fe320aeb21e02e:/print-tcp.c diff --git a/print-tcp.c b/print-tcp.c index 24025e59..f8e0ee72 100644 --- a/print-tcp.c +++ b/print-tcp.c @@ -94,7 +94,7 @@ struct tcp_seq_hash { static struct tcp_seq_hash tcp_seq_hash[TSEQ_HASHSIZE]; -struct tok tcp_flag_values[] = { +static const struct tok tcp_flag_values[] = { { TH_FIN, "F" }, { TH_SYN, "S" }, { TH_RST, "R" }, @@ -106,7 +106,7 @@ struct tok tcp_flag_values[] = { { 0, NULL } }; -struct tok tcp_option_values[] = { +static const struct tok tcp_option_values[] = { { TCPOPT_EOL, "eol" }, { TCPOPT_NOP, "nop" }, { TCPOPT_MAXSEG, "mss" }, @@ -122,6 +122,8 @@ struct tok tcp_option_values[] = { { TCPOPT_SIGNATURE, "md5" }, { TCPOPT_AUTH, "enhanced auth" }, { TCPOPT_UTO, "uto" }, + { TCPOPT_MPTCP, "mptcp" }, + { TCPOPT_EXPERIMENT2, "exp" }, { 0, NULL } }; @@ -129,30 +131,8 @@ static int tcp_cksum(register const struct ip *ip, register const struct tcphdr *tp, register u_int len) { - struct phdr { - u_int32_t src; - u_int32_t dst; - u_char mbz; - u_char proto; - u_int16_t len; - } ph; - struct cksum_vec vec[2]; - - /* pseudo-header.. */ - ph.len = htons((u_int16_t)len); - ph.mbz = 0; - ph.proto = IPPROTO_TCP; - memcpy(&ph.src, &ip->ip_src.s_addr, sizeof(u_int32_t)); - if (IP_HL(ip) == 5) - memcpy(&ph.dst, &ip->ip_dst.s_addr, sizeof(u_int32_t)); - else - ph.dst = ip_finddst(ip); - - vec[0].ptr = (const u_int8_t *)(void *)&ph; - vec[0].len = sizeof(ph); - vec[1].ptr = (const u_int8_t *)tp; - vec[1].len = len; - return in_cksum(vec, 2); + return (nextproto4_cksum(ip, (const u_int8_t *)tp, len, + IPPROTO_TCP)); } void @@ -167,7 +147,8 @@ tcp_print(register const u_char *bp, register u_int length, u_int16_t sport, dport, win, urp; u_int32_t seq, ack, thseq, thack; u_int utoval; - int threv; + u_int16_t magic; + register int rev; #ifdef INET6 register const struct ip6_hdr *ip6; #endif @@ -284,7 +265,6 @@ tcp_print(register const u_char *bp, register u_int length, if (!Sflag && (flags & TH_ACK)) { register struct tcp_seq_hash *th; const void *src, *dst; - register int rev; struct tha tha; /* * Find (or record) the initial sequence numbers for @@ -373,7 +353,6 @@ tcp_print(register const u_char *bp, register u_int length, } #endif - threv = rev; for (th = &tcp_seq_hash[tha.port % TSEQ_HASHSIZE]; th->nxt; th = th->nxt) if (memcmp((char *)&tha, (char *)&th->addr, @@ -404,7 +383,7 @@ tcp_print(register const u_char *bp, register u_int length, thack = th->ack; } else { /*fool gcc*/ - thseq = thack = threv = 0; + thseq = thack = rev = 0; } if (hlen > length) { (void)printf(" [bad hdr length %u - too long, > %u]", @@ -432,7 +411,7 @@ tcp_print(register const u_char *bp, register u_int length, #ifdef INET6 else if (IP_V(ip) == 6 && ip6->ip6_plen) { if (TTEST2(tp->th_sport, length)) { - sum = nextproto6_cksum(ip6, (u_short *)tp, length, IPPROTO_TCP); + sum = nextproto6_cksum(ip6, (const u_int8_t *)tp, length, IPPROTO_TCP); tcp_sum = EXTRACT_16BITS(&tp->th_sum); (void)printf(", cksum 0x%04x", tcp_sum); @@ -525,7 +504,7 @@ tcp_print(register const u_char *bp, register u_int length, s = EXTRACT_32BITS(cp + i); LENCHECK(i + 8); e = EXTRACT_32BITS(cp + i + 4); - if (threv) { + if (rev) { s -= thseq; e -= thseq; } else { @@ -618,6 +597,48 @@ tcp_print(register const u_char *bp, register u_int length, (void)printf(" %u", utoval); break; + case TCPOPT_MPTCP: + datalen = len - 2; + LENCHECK(datalen); + if (!mptcp_print(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); + (void)printf("-"); + + switch(magic) { + + case 0xf989: + /* TCP Fast Open: draft-ietf-tcpm-fastopen-04 */ + if (datalen == 2) { + /* Fast Open Cookie Request */ + (void)printf("tfo cookiereq"); + } else { + /* Fast Open Cookie */ + if (datalen % 2 != 0 || datalen < 6 || datalen > 18) { + (void)printf("tfo malformed"); + } else { + (void)printf("tfo cookie "); + for (i = 2; i < datalen; ++i) + (void)printf("%02x", cp[i]); + } + } + break; + + default: + /* Unknown magic number */ + (void)printf("%04x", magic); + break; + } + break; + default: datalen = len - 2; for (i = 0; i < datalen; ++i) { @@ -661,6 +682,15 @@ tcp_print(register const u_char *bp, register u_int length, return; } + if (packettype) { + switch (packettype) { + case PT_ZMTP1: + zmtp1_print(bp, length); + break; + } + return; + } + if (sport == TELNET_PORT || dport == TELNET_PORT) { if (!qflag && vflag) telnet_print(bp, length); @@ -676,6 +706,8 @@ tcp_print(register const u_char *bp, register u_int length, #endif else if (sport == BEEP_PORT || dport == BEEP_PORT) beep_print(bp, length); + else if (sport == OPENFLOW_PORT || dport == OPENFLOW_PORT) + openflow_print(bp, length); else if (length > 2 && (sport == NAMESERVER_PORT || dport == NAMESERVER_PORT || sport == MULTICASTDNS_PORT || dport == MULTICASTDNS_PORT)) { @@ -742,6 +774,7 @@ print_tcp_rst_data(register const u_char *sp, u_int length) } #ifdef HAVE_LIBCRYPTO +USES_APPLE_DEPRECATED_API static int tcp_verify_signature(const struct ip *ip, const struct tcphdr *tp, const u_char *data, int length, const u_char *rcvsig) @@ -828,6 +861,7 @@ tcp_verify_signature(const struct ip *ip, const struct tcphdr *tp, else return (SIGNATURE_INVALID); } +USES_APPLE_RST #endif /* HAVE_LIBCRYPTO */ /*