2007-08-29 10:31:44 +08:00
|
|
|
/* $NetBSD: print-tcp.c,v 1.9 2007/07/26 18:15:12 plunky Exp $ */
|
|
|
|
|
1999-10-08 07:47:09 +08:00
|
|
|
/*
|
|
|
|
* Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997
|
|
|
|
* The Regents of the University of California. All rights reserved.
|
|
|
|
*
|
2005-04-07 02:53:56 +08:00
|
|
|
* Copyright (c) 1999-2004 The tcpdump.org project
|
|
|
|
*
|
1999-10-08 07:47:09 +08:00
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that: (1) source code distributions
|
|
|
|
* retain the above copyright notice and this paragraph in its entirety, (2)
|
|
|
|
* distributions including binary code include the above copyright notice and
|
|
|
|
* this paragraph in its entirety in the documentation or other materials
|
|
|
|
* provided with the distribution, and (3) all advertising materials mentioning
|
|
|
|
* features or use of this software display the following acknowledgement:
|
|
|
|
* ``This product includes software developed by the University of California,
|
|
|
|
* Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
|
|
|
|
* the University nor the names of its contributors may be used to endorse
|
|
|
|
* or promote products derived from this software without specific prior
|
|
|
|
* written permission.
|
|
|
|
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
|
|
|
|
* WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
|
|
|
|
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
*/
|
|
|
|
|
2016-08-14 21:42:19 +08:00
|
|
|
/* \summary: TCP printer */
|
|
|
|
|
2003-11-16 17:36:07 +08:00
|
|
|
#ifndef lint
|
2008-11-10 07:35:03 +08:00
|
|
|
#else
|
2007-08-29 10:31:44 +08:00
|
|
|
__RCSID("$NetBSD: print-tcp.c,v 1.8 2007/07/24 11:53:48 drochner Exp $");
|
2003-11-16 17:36:07 +08:00
|
|
|
#endif
|
1999-11-21 17:36:43 +08:00
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
2018-01-22 04:27:08 +08:00
|
|
|
#include <config.h>
|
1999-10-08 07:47:09 +08:00
|
|
|
#endif
|
|
|
|
|
2018-01-20 22:59:49 +08:00
|
|
|
#include "netdissect-stdinc.h"
|
1999-10-08 07:47:09 +08:00
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
2015-09-06 05:35:58 +08:00
|
|
|
#include "netdissect.h"
|
1999-10-08 07:47:09 +08:00
|
|
|
#include "addrtoname.h"
|
|
|
|
#include "extract.h"
|
|
|
|
|
2000-09-23 16:26:30 +08:00
|
|
|
#include "tcp.h"
|
|
|
|
|
2000-09-23 16:54:24 +08:00
|
|
|
#include "ip.h"
|
2000-10-07 13:53:09 +08:00
|
|
|
#include "ip6.h"
|
2003-06-07 19:57:51 +08:00
|
|
|
#include "ipproto.h"
|
2004-12-27 08:41:29 +08:00
|
|
|
#include "rpc_auth.h"
|
|
|
|
#include "rpc_msg.h"
|
2000-09-23 16:54:24 +08:00
|
|
|
|
2004-03-23 15:15:36 +08:00
|
|
|
#ifdef HAVE_LIBCRYPTO
|
|
|
|
#include <openssl/md5.h>
|
2015-07-03 20:26:54 +08:00
|
|
|
#include "signature.h"
|
2004-09-15 09:21:17 +08:00
|
|
|
|
2014-04-02 16:59:56 +08:00
|
|
|
static int tcp_verify_signature(netdissect_options *ndo,
|
|
|
|
const struct ip *ip, const struct tcphdr *tp,
|
2018-01-12 03:52:30 +08:00
|
|
|
const u_char *data, u_int length, const u_char *rcvsig);
|
2004-03-23 15:15:36 +08:00
|
|
|
#endif
|
|
|
|
|
2017-12-14 02:17:47 +08:00
|
|
|
static void print_tcp_rst_data(netdissect_options *, const u_char *sp, u_int length);
|
|
|
|
static void print_tcp_fastopen_option(netdissect_options *ndo, const u_char *cp,
|
2015-04-08 08:42:55 +08:00
|
|
|
u_int datalen, int exp);
|
2000-07-29 17:06:23 +08:00
|
|
|
|
|
|
|
#define MAX_RST_DATA_LEN 30
|
|
|
|
|
2000-04-27 19:09:08 +08:00
|
|
|
|
1999-10-08 07:47:09 +08:00
|
|
|
struct tha {
|
2007-01-29 17:59:42 +08:00
|
|
|
struct in_addr src;
|
|
|
|
struct in_addr dst;
|
|
|
|
u_int port;
|
1999-10-08 07:47:09 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
struct tcp_seq_hash {
|
2007-01-29 17:59:42 +08:00
|
|
|
struct tcp_seq_hash *nxt;
|
|
|
|
struct tha addr;
|
2017-12-11 16:17:47 +08:00
|
|
|
uint32_t seq;
|
|
|
|
uint32_t ack;
|
1999-10-08 07:47:09 +08:00
|
|
|
};
|
|
|
|
|
2013-10-06 07:56:02 +08:00
|
|
|
struct tha6 {
|
|
|
|
struct in6_addr src;
|
|
|
|
struct in6_addr dst;
|
|
|
|
u_int port;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct tcp_seq_hash6 {
|
|
|
|
struct tcp_seq_hash6 *nxt;
|
|
|
|
struct tha6 addr;
|
2017-12-11 16:17:47 +08:00
|
|
|
uint32_t seq;
|
|
|
|
uint32_t ack;
|
2013-10-06 07:56:02 +08:00
|
|
|
};
|
|
|
|
|
1999-10-08 07:47:09 +08:00
|
|
|
#define TSEQ_HASHSIZE 919
|
|
|
|
|
|
|
|
/* These tcp optinos do not have the size octet */
|
|
|
|
#define ZEROLENOPT(o) ((o) == TCPOPT_EOL || (o) == TCPOPT_NOP)
|
|
|
|
|
2013-10-06 07:56:02 +08:00
|
|
|
static struct tcp_seq_hash tcp_seq_hash4[TSEQ_HASHSIZE];
|
|
|
|
static struct tcp_seq_hash6 tcp_seq_hash6[TSEQ_HASHSIZE];
|
1999-10-08 07:47:09 +08:00
|
|
|
|
2013-09-25 00:46:24 +08:00
|
|
|
static const struct tok tcp_flag_values[] = {
|
2007-01-29 17:59:42 +08:00
|
|
|
{ TH_FIN, "F" },
|
|
|
|
{ TH_SYN, "S" },
|
|
|
|
{ TH_RST, "R" },
|
|
|
|
{ TH_PUSH, "P" },
|
|
|
|
{ TH_ACK, "." },
|
|
|
|
{ TH_URG, "U" },
|
|
|
|
{ TH_ECNECHO, "E" },
|
|
|
|
{ TH_CWR, "W" },
|
|
|
|
{ 0, NULL }
|
|
|
|
};
|
1999-10-08 07:47:09 +08:00
|
|
|
|
2013-09-25 00:46:24 +08:00
|
|
|
static const struct tok tcp_option_values[] = {
|
2007-01-29 17:59:42 +08:00
|
|
|
{ TCPOPT_EOL, "eol" },
|
|
|
|
{ TCPOPT_NOP, "nop" },
|
|
|
|
{ TCPOPT_MAXSEG, "mss" },
|
|
|
|
{ TCPOPT_WSCALE, "wscale" },
|
|
|
|
{ TCPOPT_SACKOK, "sackOK" },
|
|
|
|
{ TCPOPT_SACK, "sack" },
|
|
|
|
{ TCPOPT_ECHO, "echo" },
|
|
|
|
{ TCPOPT_ECHOREPLY, "echoreply" },
|
|
|
|
{ TCPOPT_TIMESTAMP, "TS" },
|
|
|
|
{ TCPOPT_CC, "cc" },
|
|
|
|
{ TCPOPT_CCNEW, "ccnew" },
|
|
|
|
{ TCPOPT_CCECHO, "" },
|
|
|
|
{ TCPOPT_SIGNATURE, "md5" },
|
2016-05-06 03:31:01 +08:00
|
|
|
{ TCPOPT_SCPS, "scps" },
|
2016-11-08 07:43:17 +08:00
|
|
|
{ TCPOPT_UTO, "uto" },
|
2016-11-02 01:05:01 +08:00
|
|
|
{ TCPOPT_TCPAO, "tcp-ao" },
|
2013-04-17 22:05:21 +08:00
|
|
|
{ TCPOPT_MPTCP, "mptcp" },
|
2015-04-08 08:42:55 +08:00
|
|
|
{ TCPOPT_FASTOPEN, "tfo" },
|
2013-06-16 11:46:54 +08:00
|
|
|
{ TCPOPT_EXPERIMENT2, "exp" },
|
2007-01-29 17:59:42 +08:00
|
|
|
{ 0, NULL }
|
|
|
|
};
|
1999-11-21 23:57:50 +08:00
|
|
|
|
2014-04-02 16:59:56 +08:00
|
|
|
static int
|
|
|
|
tcp_cksum(netdissect_options *ndo,
|
2017-12-14 02:17:47 +08:00
|
|
|
const struct ip *ip,
|
|
|
|
const struct tcphdr *tp,
|
|
|
|
u_int len)
|
2000-08-02 01:28:09 +08:00
|
|
|
{
|
2014-04-23 15:20:40 +08:00
|
|
|
return nextproto4_cksum(ndo, ip, (const uint8_t *)tp, len, len,
|
2014-02-15 19:32:44 +08:00
|
|
|
IPPROTO_TCP);
|
2000-08-02 01:28:09 +08:00
|
|
|
}
|
|
|
|
|
2016-02-13 12:26:39 +08:00
|
|
|
static int
|
|
|
|
tcp6_cksum(netdissect_options *ndo,
|
2017-12-14 02:17:47 +08:00
|
|
|
const struct ip6_hdr *ip6,
|
|
|
|
const struct tcphdr *tp,
|
|
|
|
u_int len)
|
2016-02-13 12:26:39 +08:00
|
|
|
{
|
|
|
|
return nextproto6_cksum(ndo, ip6, (const uint8_t *)tp, len, len,
|
|
|
|
IPPROTO_TCP);
|
|
|
|
}
|
|
|
|
|
1999-10-08 07:47:09 +08:00
|
|
|
void
|
2014-04-02 16:59:56 +08:00
|
|
|
tcp_print(netdissect_options *ndo,
|
2017-12-14 02:17:47 +08:00
|
|
|
const u_char *bp, u_int length,
|
|
|
|
const u_char *bp2, int fragmented)
|
1999-10-08 07:47:09 +08:00
|
|
|
{
|
2017-12-14 02:17:47 +08:00
|
|
|
const struct tcphdr *tp;
|
|
|
|
const struct ip *ip;
|
|
|
|
u_char flags;
|
|
|
|
u_int hlen;
|
|
|
|
char ch;
|
2014-04-23 15:20:40 +08:00
|
|
|
uint16_t sport, dport, win, urp;
|
|
|
|
uint32_t seq, ack, thseq, thack;
|
2009-09-22 01:02:05 +08:00
|
|
|
u_int utoval;
|
2014-04-23 15:20:40 +08:00
|
|
|
uint16_t magic;
|
2017-12-14 02:17:47 +08:00
|
|
|
int rev;
|
|
|
|
const struct ip6_hdr *ip6;
|
1999-10-08 07:47:09 +08:00
|
|
|
|
2015-04-27 08:24:42 +08:00
|
|
|
tp = (const struct tcphdr *)bp;
|
|
|
|
ip = (const struct ip *)bp2;
|
2007-01-29 17:59:42 +08:00
|
|
|
if (IP_V(ip) == 6)
|
2015-04-27 08:24:42 +08:00
|
|
|
ip6 = (const struct ip6_hdr *)bp2;
|
2007-01-29 17:59:42 +08:00
|
|
|
else
|
|
|
|
ip6 = NULL;
|
|
|
|
ch = '\0';
|
2018-01-09 06:14:20 +08:00
|
|
|
if (!ND_TTEST_2(tp->th_dport)) {
|
2018-01-31 16:43:45 +08:00
|
|
|
if (ip6) {
|
|
|
|
ND_PRINT("%s > %s: ",
|
|
|
|
ip6addr_string(ndo, ip6->ip6_src),
|
|
|
|
ip6addr_string(ndo, ip6->ip6_dst));
|
|
|
|
} else {
|
|
|
|
ND_PRINT("%s > %s: [|tcp]",
|
|
|
|
ipaddr_string(ndo, ip->ip_src),
|
|
|
|
ipaddr_string(ndo, ip->ip_dst));
|
|
|
|
}
|
2007-01-29 17:59:42 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-12-12 11:38:35 +08:00
|
|
|
sport = EXTRACT_BE_U_2(tp->th_sport);
|
|
|
|
dport = EXTRACT_BE_U_2(tp->th_dport);
|
2007-01-29 17:59:42 +08:00
|
|
|
|
|
|
|
if (ip6) {
|
2017-12-12 11:38:35 +08:00
|
|
|
if (EXTRACT_U_1(ip6->ip6_nxt) == IPPROTO_TCP) {
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT("%s.%s > %s.%s: ",
|
2018-01-31 16:43:45 +08:00
|
|
|
ip6addr_string(ndo, ip6->ip6_src),
|
2015-09-06 04:28:04 +08:00
|
|
|
tcpport_string(ndo, sport),
|
2018-01-31 16:43:45 +08:00
|
|
|
ip6addr_string(ndo, ip6->ip6_dst),
|
2018-01-07 18:47:30 +08:00
|
|
|
tcpport_string(ndo, dport));
|
2007-01-29 17:59:42 +08:00
|
|
|
} else {
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT("%s > %s: ",
|
|
|
|
tcpport_string(ndo, sport), tcpport_string(ndo, dport));
|
2007-01-29 17:59:42 +08:00
|
|
|
}
|
2015-09-18 05:56:44 +08:00
|
|
|
} else {
|
2017-12-11 08:23:34 +08:00
|
|
|
if (EXTRACT_U_1(ip->ip_p) == IPPROTO_TCP) {
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT("%s.%s > %s.%s: ",
|
2018-01-31 16:43:45 +08:00
|
|
|
ipaddr_string(ndo, ip->ip_src),
|
2015-09-06 04:28:04 +08:00
|
|
|
tcpport_string(ndo, sport),
|
2018-01-31 16:43:45 +08:00
|
|
|
ipaddr_string(ndo, ip->ip_dst),
|
2018-01-07 18:47:30 +08:00
|
|
|
tcpport_string(ndo, dport));
|
2007-01-29 17:59:42 +08:00
|
|
|
} else {
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT("%s > %s: ",
|
|
|
|
tcpport_string(ndo, sport), tcpport_string(ndo, dport));
|
2007-01-29 17:59:42 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-04 04:32:07 +08:00
|
|
|
ND_TCHECK_SIZE(tp);
|
2015-07-04 07:47:12 +08:00
|
|
|
|
|
|
|
hlen = TH_OFF(tp) * 4;
|
|
|
|
|
2007-01-29 17:59:42 +08:00
|
|
|
if (hlen < sizeof(*tp)) {
|
2018-01-12 03:52:30 +08:00
|
|
|
ND_PRINT(" tcp %u [bad hdr length %u - too short, < %lu]",
|
2018-01-07 18:47:30 +08:00
|
|
|
length - hlen, hlen, (unsigned long)sizeof(*tp));
|
2007-01-29 17:59:42 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-12-12 11:38:35 +08:00
|
|
|
seq = EXTRACT_BE_U_4(tp->th_seq);
|
|
|
|
ack = EXTRACT_BE_U_4(tp->th_ack);
|
|
|
|
win = EXTRACT_BE_U_2(tp->th_win);
|
|
|
|
urp = EXTRACT_BE_U_2(tp->th_urp);
|
2007-01-29 17:59:42 +08:00
|
|
|
|
2014-04-02 16:59:56 +08:00
|
|
|
if (ndo->ndo_qflag) {
|
2018-01-12 03:52:30 +08:00
|
|
|
ND_PRINT("tcp %u", length - hlen);
|
2007-01-29 17:59:42 +08:00
|
|
|
if (hlen > length) {
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT(" [bad hdr length %u - too long, > %u]",
|
|
|
|
hlen, length);
|
2007-01-29 17:59:42 +08:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-12-11 16:17:47 +08:00
|
|
|
flags = EXTRACT_U_1(tp->th_flags);
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT("Flags [%s]", bittok2str_nosep(tcp_flag_values, "none", flags));
|
2007-01-29 17:59:42 +08:00
|
|
|
|
2014-04-02 16:59:56 +08:00
|
|
|
if (!ndo->ndo_Sflag && (flags & TH_ACK)) {
|
2007-01-29 17:59:42 +08:00
|
|
|
/*
|
|
|
|
* Find (or record) the initial sequence numbers for
|
|
|
|
* this conversation. (we pick an arbitrary
|
|
|
|
* collating order so there's only one entry for
|
|
|
|
* both directions).
|
|
|
|
*/
|
|
|
|
rev = 0;
|
|
|
|
if (ip6) {
|
2017-12-14 02:17:47 +08:00
|
|
|
struct tcp_seq_hash6 *th;
|
2013-10-06 07:56:02 +08:00
|
|
|
struct tcp_seq_hash6 *tcp_seq_hash;
|
2017-07-23 04:25:46 +08:00
|
|
|
const void *src, *dst;
|
2013-10-06 07:56:02 +08:00
|
|
|
struct tha6 tha;
|
|
|
|
|
|
|
|
tcp_seq_hash = tcp_seq_hash6;
|
2017-07-23 04:25:46 +08:00
|
|
|
src = (const void *)&ip6->ip6_src;
|
|
|
|
dst = (const void *)&ip6->ip6_dst;
|
2007-01-29 17:59:42 +08:00
|
|
|
if (sport > dport)
|
|
|
|
rev = 1;
|
|
|
|
else if (sport == dport) {
|
2014-01-19 04:13:57 +08:00
|
|
|
if (UNALIGNED_MEMCMP(src, dst, sizeof ip6->ip6_dst) > 0)
|
2007-01-29 17:59:42 +08:00
|
|
|
rev = 1;
|
|
|
|
}
|
|
|
|
if (rev) {
|
2014-01-19 04:13:57 +08:00
|
|
|
UNALIGNED_MEMCPY(&tha.src, dst, sizeof ip6->ip6_dst);
|
|
|
|
UNALIGNED_MEMCPY(&tha.dst, src, sizeof ip6->ip6_src);
|
2007-01-29 17:59:42 +08:00
|
|
|
tha.port = dport << 16 | sport;
|
|
|
|
} else {
|
2014-01-19 04:13:57 +08:00
|
|
|
UNALIGNED_MEMCPY(&tha.dst, dst, sizeof ip6->ip6_dst);
|
|
|
|
UNALIGNED_MEMCPY(&tha.src, src, sizeof ip6->ip6_src);
|
2007-01-29 17:59:42 +08:00
|
|
|
tha.port = sport << 16 | dport;
|
|
|
|
}
|
2013-10-06 07:56:02 +08:00
|
|
|
|
|
|
|
for (th = &tcp_seq_hash[tha.port % TSEQ_HASHSIZE];
|
|
|
|
th->nxt; th = th->nxt)
|
|
|
|
if (memcmp((char *)&tha, (char *)&th->addr,
|
|
|
|
sizeof(th->addr)) == 0)
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (!th->nxt || (flags & TH_SYN)) {
|
|
|
|
/* didn't find it or new conversation */
|
|
|
|
if (th->nxt == NULL) {
|
|
|
|
th->nxt = (struct tcp_seq_hash6 *)
|
|
|
|
calloc(1, sizeof(*th));
|
|
|
|
if (th->nxt == NULL)
|
2015-09-06 02:11:12 +08:00
|
|
|
(*ndo->ndo_error)(ndo,
|
|
|
|
"tcp_print: calloc");
|
2013-10-06 07:56:02 +08:00
|
|
|
}
|
|
|
|
th->addr = tha;
|
|
|
|
if (rev)
|
|
|
|
th->ack = seq, th->seq = ack - 1;
|
|
|
|
else
|
|
|
|
th->seq = seq, th->ack = ack - 1;
|
|
|
|
} else {
|
|
|
|
if (rev)
|
|
|
|
seq -= th->ack, ack -= th->seq;
|
|
|
|
else
|
|
|
|
seq -= th->seq, ack -= th->ack;
|
|
|
|
}
|
|
|
|
|
|
|
|
thseq = th->seq;
|
|
|
|
thack = th->ack;
|
2007-01-29 17:59:42 +08:00
|
|
|
} else {
|
2017-12-14 02:17:47 +08:00
|
|
|
struct tcp_seq_hash *th;
|
2013-10-06 07:56:02 +08:00
|
|
|
struct tcp_seq_hash *tcp_seq_hash;
|
|
|
|
struct tha tha;
|
|
|
|
|
|
|
|
tcp_seq_hash = tcp_seq_hash4;
|
2007-01-29 17:59:42 +08:00
|
|
|
if (sport > dport)
|
|
|
|
rev = 1;
|
|
|
|
else if (sport == dport) {
|
2018-01-31 21:31:20 +08:00
|
|
|
if (UNALIGNED_MEMCMP(ip->ip_src, ip->ip_dst, sizeof ip->ip_dst) > 0)
|
2007-01-29 17:59:42 +08:00
|
|
|
rev = 1;
|
|
|
|
}
|
|
|
|
if (rev) {
|
2018-01-31 21:31:20 +08:00
|
|
|
UNALIGNED_MEMCPY(&tha.src, ip->ip_dst,
|
|
|
|
sizeof ip->ip_dst);
|
|
|
|
UNALIGNED_MEMCPY(&tha.dst, ip->ip_src,
|
|
|
|
sizeof ip->ip_src);
|
2007-01-29 17:59:42 +08:00
|
|
|
tha.port = dport << 16 | sport;
|
|
|
|
} else {
|
2018-01-31 21:31:20 +08:00
|
|
|
UNALIGNED_MEMCPY(&tha.dst, ip->ip_dst,
|
|
|
|
sizeof ip->ip_dst);
|
|
|
|
UNALIGNED_MEMCPY(&tha.src, ip->ip_src,
|
|
|
|
sizeof ip->ip_src);
|
2007-01-29 17:59:42 +08:00
|
|
|
tha.port = sport << 16 | dport;
|
|
|
|
}
|
1999-10-08 07:47:09 +08:00
|
|
|
|
2013-10-06 07:56:02 +08:00
|
|
|
for (th = &tcp_seq_hash[tha.port % TSEQ_HASHSIZE];
|
|
|
|
th->nxt; th = th->nxt)
|
|
|
|
if (memcmp((char *)&tha, (char *)&th->addr,
|
|
|
|
sizeof(th->addr)) == 0)
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (!th->nxt || (flags & TH_SYN)) {
|
|
|
|
/* didn't find it or new conversation */
|
|
|
|
if (th->nxt == NULL) {
|
|
|
|
th->nxt = (struct tcp_seq_hash *)
|
|
|
|
calloc(1, sizeof(*th));
|
|
|
|
if (th->nxt == NULL)
|
2015-09-06 02:11:12 +08:00
|
|
|
(*ndo->ndo_error)(ndo,
|
|
|
|
"tcp_print: calloc");
|
2013-10-06 07:56:02 +08:00
|
|
|
}
|
|
|
|
th->addr = tha;
|
|
|
|
if (rev)
|
|
|
|
th->ack = seq, th->seq = ack - 1;
|
|
|
|
else
|
|
|
|
th->seq = seq, th->ack = ack - 1;
|
|
|
|
} else {
|
|
|
|
if (rev)
|
|
|
|
seq -= th->ack, ack -= th->seq;
|
|
|
|
else
|
|
|
|
seq -= th->seq, ack -= th->ack;
|
2007-01-29 17:59:42 +08:00
|
|
|
}
|
|
|
|
|
2013-10-06 07:56:02 +08:00
|
|
|
thseq = th->seq;
|
|
|
|
thack = th->ack;
|
|
|
|
}
|
2007-01-29 17:59:42 +08:00
|
|
|
} else {
|
|
|
|
/*fool gcc*/
|
2013-10-06 07:37:15 +08:00
|
|
|
thseq = thack = rev = 0;
|
2007-01-29 17:59:42 +08:00
|
|
|
}
|
|
|
|
if (hlen > length) {
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT(" [bad hdr length %u - too long, > %u]",
|
|
|
|
hlen, length);
|
2007-01-29 17:59:42 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-04-02 16:59:56 +08:00
|
|
|
if (ndo->ndo_vflag && !ndo->ndo_Kflag && !fragmented) {
|
2011-06-17 12:50:26 +08:00
|
|
|
/* Check the checksum, if possible. */
|
2014-04-23 15:20:40 +08:00
|
|
|
uint16_t sum, tcp_sum;
|
2004-04-25 01:19:00 +08:00
|
|
|
|
2011-06-17 12:50:26 +08:00
|
|
|
if (IP_V(ip) == 4) {
|
2017-12-15 04:48:23 +08:00
|
|
|
if (ND_TTEST_LEN(tp->th_sport, length)) {
|
2014-04-02 16:59:56 +08:00
|
|
|
sum = tcp_cksum(ndo, ip, tp, length);
|
2017-12-12 11:38:35 +08:00
|
|
|
tcp_sum = EXTRACT_BE_U_2(tp->th_sum);
|
2011-06-17 12:50:26 +08:00
|
|
|
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT(", cksum 0x%04x", tcp_sum);
|
2011-06-17 12:50:26 +08:00
|
|
|
if (sum != 0)
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT(" (incorrect -> 0x%04x)",
|
|
|
|
in_cksum_shouldbe(tcp_sum, sum));
|
2011-06-17 12:50:26 +08:00
|
|
|
else
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT(" (correct)");
|
2011-06-17 12:50:26 +08:00
|
|
|
}
|
2015-09-18 05:56:44 +08:00
|
|
|
} else if (IP_V(ip) == 6 && ip6->ip6_plen) {
|
2017-12-15 04:48:23 +08:00
|
|
|
if (ND_TTEST_LEN(tp->th_sport, length)) {
|
2016-02-13 12:26:39 +08:00
|
|
|
sum = tcp6_cksum(ndo, ip6, tp, length);
|
2017-12-12 11:38:35 +08:00
|
|
|
tcp_sum = EXTRACT_BE_U_2(tp->th_sum);
|
2007-01-29 17:59:42 +08:00
|
|
|
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT(", cksum 0x%04x", tcp_sum);
|
2011-06-17 12:50:26 +08:00
|
|
|
if (sum != 0)
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT(" (incorrect -> 0x%04x)",
|
|
|
|
in_cksum_shouldbe(tcp_sum, sum));
|
2011-06-17 12:50:26 +08:00
|
|
|
else
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT(" (correct)");
|
2011-06-17 12:50:26 +08:00
|
|
|
|
|
|
|
}
|
2007-01-29 17:59:42 +08:00
|
|
|
}
|
2011-06-17 12:50:26 +08:00
|
|
|
}
|
2000-08-02 01:28:09 +08:00
|
|
|
|
2007-01-29 17:59:42 +08:00
|
|
|
length -= hlen;
|
2014-04-02 16:59:56 +08:00
|
|
|
if (ndo->ndo_vflag > 1 || length > 0 || flags & (TH_SYN | TH_FIN | TH_RST)) {
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT(", seq %u", seq);
|
2007-01-29 17:59:42 +08:00
|
|
|
|
|
|
|
if (length > 0) {
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT(":%u", seq + length);
|
2007-01-29 17:59:42 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (flags & TH_ACK) {
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT(", ack %u", ack);
|
2007-01-29 17:59:42 +08:00
|
|
|
}
|
|
|
|
|
2018-01-12 03:52:30 +08:00
|
|
|
ND_PRINT(", win %u", win);
|
2007-01-29 17:59:42 +08:00
|
|
|
|
|
|
|
if (flags & TH_URG)
|
2018-01-12 03:52:30 +08:00
|
|
|
ND_PRINT(", urg %u", urp);
|
2007-01-29 17:59:42 +08:00
|
|
|
/*
|
|
|
|
* Handle any options.
|
|
|
|
*/
|
|
|
|
if (hlen > sizeof(*tp)) {
|
2017-12-14 02:17:47 +08:00
|
|
|
const u_char *cp;
|
|
|
|
u_int i, opt, datalen;
|
|
|
|
u_int len;
|
2007-01-29 17:59:42 +08:00
|
|
|
|
|
|
|
hlen -= sizeof(*tp);
|
|
|
|
cp = (const u_char *)tp + sizeof(*tp);
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT(", options [");
|
2007-01-29 17:59:42 +08:00
|
|
|
while (hlen > 0) {
|
2007-04-04 04:02:56 +08:00
|
|
|
if (ch != '\0')
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT("%c", ch);
|
2017-12-05 03:21:48 +08:00
|
|
|
ND_TCHECK_1(cp);
|
2017-11-23 06:54:09 +08:00
|
|
|
opt = EXTRACT_U_1(cp);
|
2017-11-22 03:23:59 +08:00
|
|
|
cp++;
|
2007-01-29 17:59:42 +08:00
|
|
|
if (ZEROLENOPT(opt))
|
|
|
|
len = 1;
|
|
|
|
else {
|
2017-12-05 03:21:48 +08:00
|
|
|
ND_TCHECK_1(cp);
|
2017-11-23 06:54:09 +08:00
|
|
|
len = EXTRACT_U_1(cp);
|
2017-11-22 03:23:59 +08:00
|
|
|
cp++; /* total including type, len */
|
2007-01-29 17:59:42 +08:00
|
|
|
if (len < 2 || len > hlen)
|
|
|
|
goto bad;
|
|
|
|
--hlen; /* account for length byte */
|
|
|
|
}
|
|
|
|
--hlen; /* account for type byte */
|
|
|
|
datalen = 0;
|
1999-10-08 07:47:09 +08:00
|
|
|
|
|
|
|
/* Bail if "l" bytes of data are not left or were not captured */
|
2017-12-11 19:46:51 +08:00
|
|
|
#define LENCHECK(l) { if ((l) > hlen) goto bad; ND_TCHECK_LEN(cp, l); }
|
1999-10-08 07:47:09 +08:00
|
|
|
|
2007-01-29 17:59:42 +08:00
|
|
|
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT("%s", tok2str(tcp_option_values, "unknown-%u", opt));
|
2007-01-29 17:59:42 +08:00
|
|
|
|
|
|
|
switch (opt) {
|
|
|
|
|
|
|
|
case TCPOPT_MAXSEG:
|
|
|
|
datalen = 2;
|
|
|
|
LENCHECK(datalen);
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT(" %u", EXTRACT_BE_U_2(cp));
|
2007-01-29 17:59:42 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case TCPOPT_WSCALE:
|
|
|
|
datalen = 1;
|
|
|
|
LENCHECK(datalen);
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT(" %u", EXTRACT_U_1(cp));
|
2007-01-29 17:59:42 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case TCPOPT_SACK:
|
|
|
|
datalen = len - 2;
|
|
|
|
if (datalen % 8 != 0) {
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT(" invalid sack");
|
2007-01-29 17:59:42 +08:00
|
|
|
} else {
|
2014-04-23 15:20:40 +08:00
|
|
|
uint32_t s, e;
|
2007-01-29 17:59:42 +08:00
|
|
|
|
2018-01-12 03:52:30 +08:00
|
|
|
ND_PRINT(" %u ", datalen / 8);
|
2007-01-29 17:59:42 +08:00
|
|
|
for (i = 0; i < datalen; i += 8) {
|
|
|
|
LENCHECK(i + 4);
|
2017-11-23 06:54:09 +08:00
|
|
|
s = EXTRACT_BE_U_4(cp + i);
|
2007-01-29 17:59:42 +08:00
|
|
|
LENCHECK(i + 8);
|
2017-11-23 06:54:09 +08:00
|
|
|
e = EXTRACT_BE_U_4(cp + i + 4);
|
2013-10-06 07:37:15 +08:00
|
|
|
if (rev) {
|
2007-01-29 17:59:42 +08:00
|
|
|
s -= thseq;
|
|
|
|
e -= thseq;
|
|
|
|
} else {
|
|
|
|
s -= thack;
|
|
|
|
e -= thack;
|
|
|
|
}
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT("{%u:%u}", s, e);
|
2007-01-29 17:59:42 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
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);
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT(" %u", EXTRACT_BE_U_4(cp));
|
2007-01-29 17:59:42 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case TCPOPT_TIMESTAMP:
|
|
|
|
datalen = 8;
|
|
|
|
LENCHECK(datalen);
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT(" val %u ecr %u",
|
2017-11-23 06:54:09 +08:00
|
|
|
EXTRACT_BE_U_4(cp),
|
2018-01-07 18:47:30 +08:00
|
|
|
EXTRACT_BE_U_4(cp + 4));
|
2007-01-29 17:59:42 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case TCPOPT_SIGNATURE:
|
|
|
|
datalen = TCP_SIGLEN;
|
|
|
|
LENCHECK(datalen);
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT(" ");
|
2004-03-23 15:15:36 +08:00
|
|
|
#ifdef HAVE_LIBCRYPTO
|
2014-04-02 16:59:56 +08:00
|
|
|
switch (tcp_verify_signature(ndo, ip, tp,
|
2007-01-29 17:59:42 +08:00
|
|
|
bp + TH_OFF(tp) * 4, length, cp)) {
|
|
|
|
|
|
|
|
case SIGNATURE_VALID:
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT("valid");
|
2007-01-29 17:59:42 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case SIGNATURE_INVALID:
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT("invalid");
|
2007-01-29 17:59:42 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case CANT_CHECK_SIGNATURE:
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT("can't check - ");
|
2007-01-29 17:59:42 +08:00
|
|
|
for (i = 0; i < TCP_SIGLEN; ++i)
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT("%02x", EXTRACT_U_1(cp + i));
|
2007-01-29 17:59:42 +08:00
|
|
|
break;
|
|
|
|
}
|
2004-03-23 15:15:36 +08:00
|
|
|
#else
|
2007-01-29 17:59:42 +08:00
|
|
|
for (i = 0; i < TCP_SIGLEN; ++i)
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT("%02x", EXTRACT_U_1(cp + i));
|
2004-03-23 15:15:36 +08:00
|
|
|
#endif
|
2007-01-29 17:59:42 +08:00
|
|
|
break;
|
2004-03-23 15:15:36 +08:00
|
|
|
|
2016-05-06 03:31:01 +08:00
|
|
|
case TCPOPT_SCPS:
|
|
|
|
datalen = 2;
|
|
|
|
LENCHECK(datalen);
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT(" cap %02x id %u", EXTRACT_U_1(cp), EXTRACT_U_1(cp + 1));
|
2016-05-06 03:31:01 +08:00
|
|
|
break;
|
|
|
|
|
2016-11-02 01:05:01 +08:00
|
|
|
case TCPOPT_TCPAO:
|
|
|
|
datalen = len - 2;
|
|
|
|
/* RFC 5925 Section 2.2:
|
|
|
|
* "The Length value MUST be greater than or equal to 4."
|
|
|
|
* (This includes the Kind and Length fields already processed
|
|
|
|
* at this point.)
|
|
|
|
*/
|
|
|
|
if (datalen < 2) {
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT(" invalid");
|
2016-11-02 01:05:01 +08:00
|
|
|
} else {
|
|
|
|
LENCHECK(1);
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT(" keyid %u", EXTRACT_U_1(cp));
|
2016-11-02 01:05:01 +08:00
|
|
|
LENCHECK(2);
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT(" rnextkeyid %u", EXTRACT_U_1(cp + 1));
|
2016-11-02 01:05:01 +08:00
|
|
|
if (datalen > 2) {
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT(" mac 0x");
|
2016-11-02 01:05:01 +08:00
|
|
|
for (i = 2; i < datalen; i++) {
|
|
|
|
LENCHECK(i + 1);
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT("%02x", EXTRACT_U_1(cp + i));
|
2016-11-02 01:05:01 +08:00
|
|
|
}
|
|
|
|
}
|
2005-11-29 17:07:47 +08:00
|
|
|
}
|
2007-01-29 17:59:42 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case TCPOPT_EOL:
|
|
|
|
case TCPOPT_NOP:
|
|
|
|
case TCPOPT_SACKOK:
|
|
|
|
/*
|
|
|
|
* Nothing interesting.
|
|
|
|
* fall through
|
|
|
|
*/
|
|
|
|
break;
|
|
|
|
|
2009-08-19 06:02:37 +08:00
|
|
|
case TCPOPT_UTO:
|
|
|
|
datalen = 2;
|
|
|
|
LENCHECK(datalen);
|
2017-11-23 06:54:09 +08:00
|
|
|
utoval = EXTRACT_BE_U_2(cp);
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT(" 0x%x", utoval);
|
2009-08-19 06:02:37 +08:00
|
|
|
if (utoval & 0x0001)
|
|
|
|
utoval = (utoval >> 1) * 60;
|
|
|
|
else
|
|
|
|
utoval >>= 1;
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT(" %u", utoval);
|
2009-08-19 06:02:37 +08:00
|
|
|
break;
|
|
|
|
|
2013-02-26 00:00:02 +08:00
|
|
|
case TCPOPT_MPTCP:
|
|
|
|
datalen = len - 2;
|
2013-04-17 22:05:21 +08:00
|
|
|
LENCHECK(datalen);
|
2014-04-02 16:59:56 +08:00
|
|
|
if (!mptcp_print(ndo, cp-2, len, flags))
|
2013-02-26 00:00:02 +08:00
|
|
|
goto bad;
|
|
|
|
break;
|
|
|
|
|
2015-04-08 08:42:55 +08:00
|
|
|
case TCPOPT_FASTOPEN:
|
|
|
|
datalen = len - 2;
|
|
|
|
LENCHECK(datalen);
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT(" ");
|
2015-04-08 08:42:55 +08:00
|
|
|
print_tcp_fastopen_option(ndo, cp, datalen, FALSE);
|
|
|
|
break;
|
|
|
|
|
2013-06-16 11:46:54 +08:00
|
|
|
case TCPOPT_EXPERIMENT2:
|
|
|
|
datalen = len - 2;
|
|
|
|
LENCHECK(datalen);
|
|
|
|
if (datalen < 2)
|
|
|
|
goto bad;
|
2013-10-03 15:10:26 +08:00
|
|
|
/* RFC6994 */
|
2017-11-23 06:54:09 +08:00
|
|
|
magic = EXTRACT_BE_U_2(cp);
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT("-");
|
2013-06-16 11:46:54 +08:00
|
|
|
|
|
|
|
switch(magic) {
|
|
|
|
|
2015-04-08 08:42:55 +08:00
|
|
|
case 0xf989: /* TCP Fast Open RFC 7413 */
|
|
|
|
print_tcp_fastopen_option(ndo, cp + 2, datalen - 2, TRUE);
|
2013-06-16 11:46:54 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
/* Unknown magic number */
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT("%04x", magic);
|
2013-06-16 11:46:54 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2007-01-29 17:59:42 +08:00
|
|
|
default:
|
|
|
|
datalen = len - 2;
|
2013-10-26 16:21:04 +08:00
|
|
|
if (datalen)
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT(" 0x");
|
2007-01-29 17:59:42 +08:00
|
|
|
for (i = 0; i < datalen; ++i) {
|
2015-07-04 03:37:37 +08:00
|
|
|
LENCHECK(i + 1);
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT("%02x", EXTRACT_U_1(cp + i));
|
2007-01-29 17:59:42 +08:00
|
|
|
}
|
|
|
|
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)
|
2018-01-12 03:52:30 +08:00
|
|
|
ND_PRINT("[len %u]", len);
|
2007-01-29 17:59:42 +08:00
|
|
|
ch = ',';
|
|
|
|
if (opt == TCPOPT_EOL)
|
|
|
|
break;
|
|
|
|
}
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT("]");
|
2007-01-29 17:59:42 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Print length field before crawling down the stack.
|
|
|
|
*/
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT(", length %u", length);
|
2007-01-29 17:59:42 +08:00
|
|
|
|
|
|
|
if (length <= 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Decode payload if necessary.
|
|
|
|
*/
|
|
|
|
bp += TH_OFF(tp) * 4;
|
2014-04-02 16:59:56 +08:00
|
|
|
if ((flags & TH_RST) && ndo->ndo_vflag) {
|
|
|
|
print_tcp_rst_data(ndo, bp, length);
|
2007-01-29 17:59:42 +08:00
|
|
|
return;
|
2014-01-02 10:27:54 +08:00
|
|
|
}
|
2007-01-29 17:59:42 +08:00
|
|
|
|
2014-04-02 16:59:56 +08:00
|
|
|
if (ndo->ndo_packettype) {
|
|
|
|
switch (ndo->ndo_packettype) {
|
2013-02-09 21:36:24 +08:00
|
|
|
case PT_ZMTP1:
|
2014-04-02 16:59:56 +08:00
|
|
|
zmtp1_print(ndo, bp, length);
|
2013-02-09 21:36:24 +08:00
|
|
|
break;
|
2016-01-13 01:32:55 +08:00
|
|
|
case PT_RESP:
|
|
|
|
resp_print(ndo, bp, length);
|
|
|
|
break;
|
2013-02-09 21:36:24 +08:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-12-15 03:28:14 +08:00
|
|
|
if (IS_SRC_OR_DST_PORT(TELNET_PORT)) {
|
2014-10-20 04:01:59 +08:00
|
|
|
telnet_print(ndo, bp, length);
|
2015-12-15 03:28:14 +08:00
|
|
|
} else if (IS_SRC_OR_DST_PORT(SMTP_PORT)) {
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT(": ");
|
2014-10-20 02:21:44 +08:00
|
|
|
smtp_print(ndo, bp, length);
|
2017-10-08 01:41:42 +08:00
|
|
|
} else if (IS_SRC_OR_DST_PORT(WHOIS_PORT)) {
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT(": ");
|
2017-10-08 01:41:42 +08:00
|
|
|
txtproto_print(ndo, bp, length, "whois", NULL, 0); /* RFC 3912 */
|
2015-12-15 03:28:14 +08:00
|
|
|
} else if (IS_SRC_OR_DST_PORT(BGP_PORT))
|
2014-04-02 16:59:56 +08:00
|
|
|
bgp_print(ndo, bp, length);
|
2015-12-15 03:28:14 +08:00
|
|
|
else if (IS_SRC_OR_DST_PORT(PPTP_PORT))
|
2014-04-02 16:59:56 +08:00
|
|
|
pptp_print(ndo, bp);
|
2016-01-13 01:32:55 +08:00
|
|
|
else if (IS_SRC_OR_DST_PORT(REDIS_PORT))
|
|
|
|
resp_print(ndo, bp, length);
|
2015-10-08 22:36:23 +08:00
|
|
|
#ifdef ENABLE_SMB
|
2015-12-15 03:28:14 +08:00
|
|
|
else if (IS_SRC_OR_DST_PORT(NETBIOS_SSN_PORT))
|
2014-04-02 16:59:56 +08:00
|
|
|
nbt_tcp_print(ndo, bp, length);
|
2015-12-15 03:28:14 +08:00
|
|
|
else if (IS_SRC_OR_DST_PORT(SMB_PORT))
|
2014-04-02 16:59:56 +08:00
|
|
|
smb_tcp_print(ndo, bp, length);
|
2001-10-04 17:18:45 +08:00
|
|
|
#endif
|
2015-12-15 03:28:14 +08:00
|
|
|
else if (IS_SRC_OR_DST_PORT(BEEP_PORT))
|
2014-04-02 16:59:56 +08:00
|
|
|
beep_print(ndo, bp, length);
|
2015-12-15 03:28:14 +08:00
|
|
|
else if (IS_SRC_OR_DST_PORT(OPENFLOW_PORT_OLD) || IS_SRC_OR_DST_PORT(OPENFLOW_PORT_IANA))
|
2014-04-02 16:59:56 +08:00
|
|
|
openflow_print(ndo, bp, length);
|
2015-12-15 03:28:14 +08:00
|
|
|
else if (IS_SRC_OR_DST_PORT(FTP_PORT)) {
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT(": ");
|
2014-10-20 02:21:44 +08:00
|
|
|
ftp_print(ndo, bp, length);
|
2015-12-15 03:28:14 +08:00
|
|
|
} else if (IS_SRC_OR_DST_PORT(HTTP_PORT) || IS_SRC_OR_DST_PORT(HTTP_PORT_ALT)) {
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT(": ");
|
2014-10-20 02:21:44 +08:00
|
|
|
http_print(ndo, bp, length);
|
2015-12-15 03:28:14 +08:00
|
|
|
} else if (IS_SRC_OR_DST_PORT(RTSP_PORT) || IS_SRC_OR_DST_PORT(RTSP_PORT_ALT)) {
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT(": ");
|
2014-10-20 02:21:44 +08:00
|
|
|
rtsp_print(ndo, bp, length);
|
|
|
|
} else if (length > 2 &&
|
2015-12-15 03:28:14 +08:00
|
|
|
(IS_SRC_OR_DST_PORT(NAMESERVER_PORT))) {
|
2007-01-29 17:59:42 +08:00
|
|
|
/*
|
|
|
|
* TCP DNS query has 2byte length at the head.
|
|
|
|
* XXX packet could be unaligned, it can go strange
|
|
|
|
*/
|
2017-11-16 16:40:19 +08:00
|
|
|
domain_print(ndo, bp + 2, length - 2, 0);
|
2015-12-15 03:28:14 +08:00
|
|
|
} else if (IS_SRC_OR_DST_PORT(MSDP_PORT)) {
|
2014-04-02 16:59:56 +08:00
|
|
|
msdp_print(ndo, bp, length);
|
2015-12-15 03:28:14 +08:00
|
|
|
} else if (IS_SRC_OR_DST_PORT(RPKI_RTR_PORT)) {
|
2014-04-02 16:59:56 +08:00
|
|
|
rpki_rtr_print(ndo, bp, length);
|
2007-01-29 17:59:42 +08:00
|
|
|
}
|
2015-12-15 03:28:14 +08:00
|
|
|
else if (length > 0 && (IS_SRC_OR_DST_PORT(LDP_PORT))) {
|
2014-04-02 16:59:56 +08:00
|
|
|
ldp_print(ndo, bp, length);
|
2007-01-29 17:59:42 +08:00
|
|
|
}
|
2015-12-15 03:28:14 +08:00
|
|
|
else if ((IS_SRC_OR_DST_PORT(NFS_PORT)) &&
|
2017-11-25 05:48:55 +08:00
|
|
|
length >= 4 && ND_TTEST_4(bp)) {
|
2013-10-18 07:56:18 +08:00
|
|
|
/*
|
|
|
|
* 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.
|
|
|
|
*/
|
2014-04-23 15:20:40 +08:00
|
|
|
uint32_t fraglen;
|
2017-12-14 02:17:47 +08:00
|
|
|
const struct sunrpc_msg *rp;
|
2013-10-18 07:56:18 +08:00
|
|
|
enum sunrpc_msg_type direction;
|
|
|
|
|
2017-11-23 06:54:09 +08:00
|
|
|
fraglen = EXTRACT_BE_U_4(bp) & 0x7FFFFFFF;
|
2013-10-18 07:56:18 +08:00
|
|
|
if (fraglen > (length) - 4)
|
|
|
|
fraglen = (length) - 4;
|
2015-04-27 08:24:42 +08:00
|
|
|
rp = (const struct sunrpc_msg *)(bp + 4);
|
2018-01-09 06:14:20 +08:00
|
|
|
if (ND_TTEST_4(rp->rm_direction)) {
|
2018-01-09 01:40:03 +08:00
|
|
|
direction = (enum sunrpc_msg_type) EXTRACT_BE_U_4(rp->rm_direction);
|
2013-10-18 07:56:18 +08:00
|
|
|
if (dport == NFS_PORT && direction == SUNRPC_CALL) {
|
2018-01-09 01:40:03 +08:00
|
|
|
ND_PRINT(": NFS request xid %u ",
|
|
|
|
EXTRACT_BE_U_4(rp->rm_xid));
|
2017-11-16 20:49:06 +08:00
|
|
|
nfsreq_noaddr_print(ndo, (const u_char *)rp, fraglen, (const u_char *)ip);
|
2013-10-18 07:56:18 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (sport == NFS_PORT && direction == SUNRPC_REPLY) {
|
2018-01-09 01:40:03 +08:00
|
|
|
ND_PRINT(": NFS reply xid %u ",
|
|
|
|
EXTRACT_BE_U_4(rp->rm_xid));
|
2017-11-16 20:49:06 +08:00
|
|
|
nfsreply_noaddr_print(ndo, (const u_char *)rp, fraglen, (const u_char *)ip);
|
2013-10-18 07:56:18 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2007-01-29 17:59:42 +08:00
|
|
|
|
|
|
|
return;
|
|
|
|
bad:
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT("[bad opt]");
|
2007-01-29 17:59:42 +08:00
|
|
|
if (ch != '\0')
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT(">");
|
2007-01-29 17:59:42 +08:00
|
|
|
return;
|
|
|
|
trunc:
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT("[|tcp]");
|
2007-01-29 17:59:42 +08:00
|
|
|
if (ch != '\0')
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT(">");
|
1999-10-08 07:47:09 +08:00
|
|
|
}
|
|
|
|
|
2000-07-29 17:06:23 +08:00
|
|
|
/*
|
|
|
|
* RFC1122 says the following on data in RST segments:
|
|
|
|
*
|
|
|
|
* 4.2.2.12 RST Segment: RFC-793 Section 3.4
|
|
|
|
*
|
|
|
|
* A TCP SHOULD allow a received RST segment to include data.
|
|
|
|
*
|
|
|
|
* DISCUSSION
|
|
|
|
* It has been suggested that a RST segment could contain
|
|
|
|
* ASCII text that encoded and explained the cause of the
|
|
|
|
* RST. No standard has yet been established for such
|
|
|
|
* data.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
static void
|
2014-04-02 16:59:56 +08:00
|
|
|
print_tcp_rst_data(netdissect_options *ndo,
|
2017-12-14 02:17:47 +08:00
|
|
|
const u_char *sp, u_int length)
|
2000-07-29 17:06:23 +08:00
|
|
|
{
|
2007-01-29 17:59:42 +08:00
|
|
|
int c;
|
|
|
|
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT(ND_TTEST_LEN(sp, length) ? " [RST" : " [!RST");
|
2007-01-29 17:59:42 +08:00
|
|
|
if (length > MAX_RST_DATA_LEN) {
|
|
|
|
length = MAX_RST_DATA_LEN; /* can use -X for longer */
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT("+"); /* indicate we truncate */
|
2007-01-29 17:59:42 +08:00
|
|
|
}
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT(" ");
|
2016-02-13 06:51:44 +08:00
|
|
|
while (length-- && sp < ndo->ndo_snapend) {
|
2017-11-23 06:54:09 +08:00
|
|
|
c = EXTRACT_U_1(sp);
|
2017-11-22 03:23:59 +08:00
|
|
|
sp++;
|
2014-04-02 16:59:56 +08:00
|
|
|
safeputchar(ndo, c);
|
2007-01-29 17:59:42 +08:00
|
|
|
}
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT("]");
|
2000-07-29 17:06:23 +08:00
|
|
|
}
|
2004-03-23 15:15:36 +08:00
|
|
|
|
2015-04-08 08:42:55 +08:00
|
|
|
static void
|
2017-12-14 02:17:47 +08:00
|
|
|
print_tcp_fastopen_option(netdissect_options *ndo, const u_char *cp,
|
2015-04-08 08:42:55 +08:00
|
|
|
u_int datalen, int exp)
|
|
|
|
{
|
|
|
|
u_int i;
|
|
|
|
|
|
|
|
if (exp)
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT("tfo");
|
2015-04-08 08:42:55 +08:00
|
|
|
|
|
|
|
if (datalen == 0) {
|
|
|
|
/* Fast Open Cookie Request */
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT(" cookiereq");
|
2015-04-08 08:42:55 +08:00
|
|
|
} else {
|
|
|
|
/* Fast Open Cookie */
|
|
|
|
if (datalen % 2 != 0 || datalen < 4 || datalen > 16) {
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT(" invalid");
|
2015-04-08 08:42:55 +08:00
|
|
|
} else {
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT(" cookie ");
|
2015-04-08 08:42:55 +08:00
|
|
|
for (i = 0; i < datalen; ++i)
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT("%02x", EXTRACT_U_1(cp + i));
|
2015-04-08 08:42:55 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-03-23 15:15:36 +08:00
|
|
|
#ifdef HAVE_LIBCRYPTO
|
2013-10-16 21:59:13 +08:00
|
|
|
USES_APPLE_DEPRECATED_API
|
2004-03-23 15:15:36 +08:00
|
|
|
static int
|
2014-04-02 16:59:56 +08:00
|
|
|
tcp_verify_signature(netdissect_options *ndo,
|
|
|
|
const struct ip *ip, const struct tcphdr *tp,
|
2018-01-12 03:52:30 +08:00
|
|
|
const u_char *data, u_int length, const u_char *rcvsig)
|
2004-03-23 15:15:36 +08:00
|
|
|
{
|
2004-04-05 08:12:54 +08:00
|
|
|
struct tcphdr tp1;
|
2007-01-29 17:59:42 +08:00
|
|
|
u_char sig[TCP_SIGLEN];
|
|
|
|
char zero_proto = 0;
|
|
|
|
MD5_CTX ctx;
|
2014-04-23 15:20:40 +08:00
|
|
|
uint16_t savecsum, tlen;
|
2015-04-27 08:24:42 +08:00
|
|
|
const struct ip6_hdr *ip6;
|
2014-04-23 15:20:40 +08:00
|
|
|
uint32_t len32;
|
|
|
|
uint8_t nxt;
|
2007-01-29 17:59:42 +08:00
|
|
|
|
2014-04-02 16:59:56 +08:00
|
|
|
if (data + length > ndo->ndo_snapend) {
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT("snaplen too short, ");
|
2009-02-26 17:45:39 +08:00
|
|
|
return (CANT_CHECK_SIGNATURE);
|
|
|
|
}
|
|
|
|
|
2007-01-29 17:59:42 +08:00
|
|
|
tp1 = *tp;
|
|
|
|
|
2014-04-02 16:59:56 +08:00
|
|
|
if (ndo->ndo_sigsecret == NULL) {
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT("shared secret not supplied with -M, ");
|
2014-04-15 21:14:51 +08:00
|
|
|
return (CANT_CHECK_SIGNATURE);
|
2009-02-26 17:45:39 +08:00
|
|
|
}
|
2007-01-29 17:59:42 +08:00
|
|
|
|
|
|
|
MD5_Init(&ctx);
|
|
|
|
/*
|
|
|
|
* Step 1: Update MD5 hash with IP pseudo-header.
|
|
|
|
*/
|
|
|
|
if (IP_V(ip) == 4) {
|
2015-04-27 08:24:42 +08:00
|
|
|
MD5_Update(&ctx, (const char *)&ip->ip_src, sizeof(ip->ip_src));
|
|
|
|
MD5_Update(&ctx, (const char *)&ip->ip_dst, sizeof(ip->ip_dst));
|
|
|
|
MD5_Update(&ctx, (const char *)&zero_proto, sizeof(zero_proto));
|
|
|
|
MD5_Update(&ctx, (const char *)&ip->ip_p, sizeof(ip->ip_p));
|
2017-12-12 11:38:35 +08:00
|
|
|
tlen = EXTRACT_BE_U_2(ip->ip_len) - IP_HL(ip) * 4;
|
2007-01-29 17:59:42 +08:00
|
|
|
tlen = htons(tlen);
|
2015-04-27 08:24:42 +08:00
|
|
|
MD5_Update(&ctx, (const char *)&tlen, sizeof(tlen));
|
2007-01-29 17:59:42 +08:00
|
|
|
} else if (IP_V(ip) == 6) {
|
2015-04-27 08:24:42 +08:00
|
|
|
ip6 = (const struct ip6_hdr *)ip;
|
|
|
|
MD5_Update(&ctx, (const char *)&ip6->ip6_src, sizeof(ip6->ip6_src));
|
|
|
|
MD5_Update(&ctx, (const char *)&ip6->ip6_dst, sizeof(ip6->ip6_dst));
|
2017-12-12 11:38:35 +08:00
|
|
|
len32 = htonl(EXTRACT_BE_U_2(ip6->ip6_plen));
|
2015-04-27 08:24:42 +08:00
|
|
|
MD5_Update(&ctx, (const char *)&len32, sizeof(len32));
|
2007-01-29 17:59:42 +08:00
|
|
|
nxt = 0;
|
2015-04-27 08:24:42 +08:00
|
|
|
MD5_Update(&ctx, (const char *)&nxt, sizeof(nxt));
|
|
|
|
MD5_Update(&ctx, (const char *)&nxt, sizeof(nxt));
|
|
|
|
MD5_Update(&ctx, (const char *)&nxt, sizeof(nxt));
|
2007-01-29 17:59:42 +08:00
|
|
|
nxt = IPPROTO_TCP;
|
2015-04-27 08:24:42 +08:00
|
|
|
MD5_Update(&ctx, (const char *)&nxt, sizeof(nxt));
|
2009-02-26 17:45:39 +08:00
|
|
|
} else {
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT("IP version not 4 or 6, ");
|
2007-01-29 17:59:42 +08:00
|
|
|
return (CANT_CHECK_SIGNATURE);
|
2009-02-26 17:45:39 +08:00
|
|
|
}
|
2007-01-29 17:59:42 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Step 2: Update MD5 hash with TCP header, excluding options.
|
|
|
|
* The TCP checksum must be set to zero.
|
|
|
|
*/
|
2017-12-11 18:53:24 +08:00
|
|
|
memcpy(&savecsum, tp1.th_sum, sizeof(savecsum));
|
|
|
|
memset(tp1.th_sum, 0, sizeof(tp1.th_sum));
|
2015-04-27 08:24:42 +08:00
|
|
|
MD5_Update(&ctx, (const char *)&tp1, sizeof(struct tcphdr));
|
2017-12-11 18:53:24 +08:00
|
|
|
memcpy(tp1.th_sum, &savecsum, sizeof(tp1.th_sum));
|
2007-01-29 17:59:42 +08:00
|
|
|
/*
|
|
|
|
* Step 3: Update MD5 hash with TCP segment data, if present.
|
|
|
|
*/
|
|
|
|
if (length > 0)
|
|
|
|
MD5_Update(&ctx, data, length);
|
|
|
|
/*
|
|
|
|
* Step 4: Update MD5 hash with shared secret.
|
|
|
|
*/
|
2014-04-02 16:59:56 +08:00
|
|
|
MD5_Update(&ctx, ndo->ndo_sigsecret, strlen(ndo->ndo_sigsecret));
|
2007-01-29 17:59:42 +08:00
|
|
|
MD5_Final(sig, &ctx);
|
|
|
|
|
|
|
|
if (memcmp(rcvsig, sig, TCP_SIGLEN) == 0)
|
|
|
|
return (SIGNATURE_VALID);
|
|
|
|
else
|
|
|
|
return (SIGNATURE_INVALID);
|
2004-03-23 15:15:36 +08:00
|
|
|
}
|
2013-10-16 21:59:13 +08:00
|
|
|
USES_APPLE_RST
|
2004-03-23 15:15:36 +08:00
|
|
|
#endif /* HAVE_LIBCRYPTO */
|
2007-01-29 17:59:42 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Local Variables:
|
|
|
|
* c-style: whitesmith
|
|
|
|
* c-basic-offset: 8
|
|
|
|
* End:
|
|
|
|
*/
|