Skip to content

Commit 55dc320

Browse files
rscheffinfrastation
authored andcommitted
TCP: Add support for the AE (AccECN) flag.
Print the new flag using lowercase "e" to avoid confusion with the existing uppercase flags and "." for ACK. Add/update tests. Document it in the man page using "AE" as the shorthand.
1 parent 5eea848 commit 55dc320

14 files changed

+62
-19
lines changed

CHANGES

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ DayOfTheWeek, Month DD, YYYY / The Tcpdump Group
2626
advance the packet data pointer
2727
OSPF: Print more truncation indications
2828
OSPF: Add more length checks
29+
TCP: Add support for the AE (AccECN) flag.
2930
User interface:
3031
Add optional unit suffix on -C file size.
3132
Add --print-sampling to print every Nth packet instead of all.

print-tcp.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ const struct tok tcp_flag_values[] = {
113113
{ TH_URG, "U" },
114114
{ TH_ECNECHO, "E" },
115115
{ TH_CWR, "W" },
116+
{ TH_AE, "e" },
116117
{ 0, NULL }
117118
};
118119

@@ -166,7 +167,7 @@ tcp_print(netdissect_options *ndo,
166167
{
167168
const struct tcphdr *tp;
168169
const struct ip *ip;
169-
u_char flags;
170+
uint16_t flags;
170171
u_int hlen;
171172
char ch;
172173
uint16_t sport, dport, win, urp;
@@ -248,7 +249,7 @@ tcp_print(netdissect_options *ndo,
248249
return;
249250
}
250251

251-
flags = GET_U_1(tp->th_flags);
252+
flags = tcp_get_flags(tp);
252253
ND_PRINT("Flags [%s]", bittok2str_nosep(tcp_flag_values, "none", flags));
253254

254255
if (!ndo->ndo_Sflag && (flags & TH_ACK)) {

tcp.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ struct tcphdr {
5050
};
5151

5252
#define TH_OFF(th) ((GET_U_1((th)->th_offx2) & 0xf0) >> 4)
53+
#define tcp_get_flags(th) ((GET_U_1((th)->th_flags)) | \
54+
((GET_U_1((th)->th_offx2) & 0x0f) << 8))
5355

5456
/* TCP flags */
5557
#define TH_FIN 0x01
@@ -60,6 +62,7 @@ struct tcphdr {
6062
#define TH_URG 0x20
6163
#define TH_ECNECHO 0x40 /* ECN Echo */
6264
#define TH_CWR 0x80 /* ECN Cwnd Reduced */
65+
#define TH_AE 0x100 /* AccECN (draft-ietf-tcpm-accurate-ecn;rfc7560) part of L4S (rfc9330) */
6366
extern const struct tok tcp_flag_values[];
6467

6568

tcpdump.1.in

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1380,8 +1380,8 @@ The general format of a TCP protocol line is:
13801380
.RE
13811381
\fISrc\fP and \fIdst\fP are the source and destination IP
13821382
addresses and ports.
1383-
\fITcpflags\fP are some combination of S (SYN),
1384-
F (FIN), P (PSH), R (RST), U (URG), W (CWR), E (ECE) or
1383+
\fITcpflags\fP are some combination of S (SYN), F (FIN),
1384+
P (PSH), R (RST), U (URG), W (CWR), E (ECE), e (AE) or
13851385
`.' (ACK), or `none' if no flags are set.
13861386
\fIData-seqno\fP describes the portion of sequence space covered
13871387
by the data in this packet (see example below).
@@ -1472,10 +1472,10 @@ long enough for the options to actually be there, \fItcpdump\fP reports
14721472
it as ``[\fIbad hdr length\fP]''.
14731473
.SS Particular TCP Flag Combinations (SYN-ACK, URG-ACK, etc.)
14741474
.PP
1475-
There are 8 bits in the control bits section of the TCP header:
1476-
.IP
1477-
.I CWR | ECE | URG | ACK | PSH | RST | SYN | FIN
1478-
.PP
1475+
There are 9 bits in the control bits section of the TCP header:
1476+
.LP
1477+
\fIAE(e) CWR(W) ECE(E) URG(U) ACK(.) PSH(P) RST(R) SYN(S) FIN(F)\fP
1478+
.LP
14791479
Let's assume that we want to watch packets used in establishing
14801480
a TCP connection.
14811481
Recall that TCP uses a 3-way handshake protocol
@@ -1510,7 +1510,9 @@ Recall the structure of a TCP header without options:
15101510
-----------------------------------------------------------------
15111511
| acknowledgment number |
15121512
-----------------------------------------------------------------
1513-
| HL | rsvd |C|E|U|A|P|R|S|F| window size |
1513+
|header |re |A|C|E|U|A|P|R|S|F| |
1514+
|length |serv |E|W|C|R|C|S|S|Y|I| window size |
1515+
| | ed | |R|E|G|K|H|T|N|N| |
15141516
-----------------------------------------------------------------
15151517
| TCP checksum | urgent pointer |
15161518
-----------------------------------------------------------------
@@ -1522,12 +1524,14 @@ The first line of the graph contains octets 0 - 3, the
15221524
second line shows octets 4 - 7 etc.
15231525
.PP
15241526
Starting to count with 0, the relevant TCP control bits are contained
1525-
in octet 13:
1527+
in octets 12 and 13:
15261528
.PP
15271529
.nf
15281530
0 7| 15| 23| 31
15291531
----------------|---------------|---------------|----------------
1530-
| HL | rsvd |C|E|U|A|P|R|S|F| window size |
1532+
|header |re |A|C|E|U|A|P|R|S|F| |
1533+
|length |serv |E|W|C|R|C|S|S|Y|I| window size |
1534+
| | ed | |R|E|G|K|H|T|N|N| |
15311535
----------------|---------------|---------------|----------------
15321536
| | 13th octet | | |
15331537
.fi
@@ -1538,6 +1542,8 @@ Let's have a closer look at octet no. 13:
15381542
| |
15391543
|---------------|
15401544
|C|E|U|A|P|R|S|F|
1545+
|W|C|R|C|S|S|Y|I|
1546+
|R|E|G|K|H|T|N|N|
15411547
|---------------|
15421548
|7 5 3 0|
15431549
.fi
@@ -1553,6 +1559,8 @@ with the SYN bit set in its header:
15531559
.PP
15541560
.nf
15551561
|C|E|U|A|P|R|S|F|
1562+
|W|C|R|C|S|S|Y|I|
1563+
|R|E|G|K|H|T|N|N|
15561564
|---------------|
15571565
|0 0 0 0 0 0 1 0|
15581566
|---------------|
@@ -1602,6 +1610,8 @@ with SYN-ACK set arrives:
16021610
.PP
16031611
.nf
16041612
|C|E|U|A|P|R|S|F|
1613+
|W|C|R|C|S|S|Y|I|
1614+
|R|E|G|K|H|T|N|N|
16051615
|---------------|
16061616
|0 0 0 1 0 0 1 0|
16071617
|---------------|

tests/TESTLIST

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -971,3 +971,6 @@ ip6-snmp-oid-unsigned ip6-snmp-oid-unsigned.pcap ip6-snmp-oid-unsigned.out
971971
lwres-pointer-arithmetic-ub lwres-pointer-arithmetic-ub.pcap lwres-pointer-arithmetic-ub.out
972972
ospf-signed-integer-ubsan ospf-signed-integer-ubsan.pcap ospf-signed-integer-ubsan.out -vv
973973
bgp-ub bgp-ub.pcap bgp-ub.out -v
974+
975+
# AccECN tests
976+
accecn_handshake accecn_handshake.pcap accecn_handshake.out -v

tests/accecn_handshake.out

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
1 2022-07-26 06:26:07.794026 IP (tos 0x0, ttl 64, id 0, offset 0, flags [DF], proto TCP (6), length 60)
2+
31.133.146.248.16433 > 66.228.43.12.80: Flags [SEWe], cksum 0x209c (incorrect -> 0xe443), seq 1948076589, win 65535, options [mss 1460,nop,wscale 6,sackOK,TS val 112147477 ecr 0], length 0
3+
2 2022-07-26 06:26:08.016156 IP (tos 0x0, ttl 54, id 0, offset 0, flags [DF], proto TCP (6), length 72)
4+
66.228.43.12.80 > 31.133.146.248.16433: Flags [S.W], cksum 0x22a8 (correct), seq 2972234643, ack 1948076590, win 65160, options [mss 1460,sackOK,TS val 2783239876 ecr 112147477,exp-acc0,wscale 7], length 0
5+
3 2022-07-26 06:26:08.016573 IP (tos 0x0, ttl 64, id 0, offset 0, flags [DF], proto TCP (6), length 68)
6+
31.133.146.248.16433 > 66.228.43.12.80: Flags [.W], cksum 0x20a4 (incorrect -> 0x3b19), ack 1, win 1027, options [nop,nop,TS val 112147698 ecr 2783239876,exp-acc0,eol], length 0
7+
4 2022-07-26 06:26:08.017141 IP (tos 0x2,ECT(0), ttl 64, id 0, offset 0, flags [DF], proto TCP (6), length 130)
8+
31.133.146.248.16433 > 66.228.43.12.80: Flags [P.Ee], cksum 0x20e2 (incorrect -> 0x9373), seq 1:79, ack 1, win 1027, options [nop,nop,TS val 112147698 ecr 2783239876], length 78: HTTP, length: 78
9+
GET /1M HTTP/1.1
10+
Host: 66.228.43.12
11+
User-Agent: curl/7.69.1
12+
Accept: */*
13+
14+
5 2022-07-26 06:26:08.056144 IP (tos 0x1,ECT(1), ttl 54, id 45724, offset 0, flags [DF], proto TCP (6), length 52)
15+
66.228.43.12.80 > 31.133.146.248.16433: Flags [.Ee], cksum 0x26c6 (correct), ack 79, win 509, options [nop,nop,TS val 2783239918 ecr 112147698], length 0
16+
6 2022-07-26 06:26:08.075386 IP (tos 0x1,ECT(1), ttl 54, id 45725, offset 0, flags [DF], proto TCP (6), length 1500)
17+
66.228.43.12.80 > 31.133.146.248.16433: Flags [.Ee], cksum 0xcfbd (correct), seq 1:1449, ack 79, win 509, options [nop,nop,TS val 2783239922 ecr 112147698], length 1448: HTTP, length: 1448
18+
HTTP/1.1 200 OK
19+
Date: Mon, 25 Jul 2022 15:45:42 GMT
20+
Server: Apache/2.4.41 (Ubuntu)
21+
Last-Modified: Sun, 24 Jul 2022 18:49:15 GMT
22+
ETag: "f4240-5e491862a86d8"
23+
Accept-Ranges: bytes
24+
Content-Length: 1000000
25+

tests/accecn_handshake.pcap

2.04 KB
Binary file not shown.

tests/babel_update_oobr.out

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
0x0010: b1b1 b1b1 b158 5e0a 02f4 0ab1 0402 0f0f .....X^.........
77
0x0020: ff80 0f0f 0f0f 0f00 80a1 00b2 b2b2 b20d ................
88
0x0030: 0d3a 3400 0001 00 .:4....
9-
5 1970-03-17 20:26:40.2097152 IP 6.3.218.255.6379 > 0.1.31.99.52759: Flags [S.UW], seq 2751463404:2751463426, ack 1006637056, win 45746, urg 25778, length 22: RESP [|resp]
10-
6 1970-03-17 20:27:12.000000 IP 6.3.208.255.6379 > 0.1.31.99.52759: Flags [S.UW], seq 2751463404:2751463426, ack 1006640128, win 45746, urg 25778, length 22: RESP "M-2M-2M-2M-2M-2M-7dM-2M-2M-2M-2M-2" [|resp]
9+
5 1970-03-17 20:26:40.2097152 IP 6.3.218.255.6379 > 0.1.31.99.52759: Flags [S.UWe], seq 2751463404:2751463426, ack 1006637056, win 45746, urg 25778, length 22: RESP [|resp]
10+
6 1970-03-17 20:27:12.000000 IP 6.3.208.255.6379 > 0.1.31.99.52759: Flags [S.UWe], seq 2751463404:2751463426, ack 1006640128, win 45746, urg 25778, length 22: RESP "M-2M-2M-2M-2M-2M-7dM-2M-2M-2M-2M-2" [|resp]
1111
7 1970-03-17 20:27:12.000000 IP 208.21.10.1.654 > 31.99.100.232.80: aodv rrep 34 prefix 4 hops 11
1212
dst 237.34.38.84 dseq 32203525 src 232.11.2.0 67108864 ms
1313
ext 0 0

tests/beep-oobr.out

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
1 1995-08-15 05:27:12.808464432 unknown ip 3
2-
2 1995-08-15 05:27:12.808464432 IP6 3030:3030:3030:3030:3030:3030:3030:3030.10288 > 3030:3030:3030:3030:3030:3030:3030:3030.12336: Flags [.U], seq 808464432:808476740, ack 808464432, win 12336, urg 12336, options [eol], length 12308 [remaining caplen(24) < header length(28)] [|tcp]
2+
2 1995-08-15 05:27:12.808464432 IP6 3030:3030:3030:3030:3030:3030:3030:3030.10288 > 3030:3030:3030:3030:3030:3030:3030:3030.12336: Flags [.Ue], seq 808464432:808476740, ack 808464432, win 12336, urg 12336, options [eol], length 12308 [remaining caplen(24) < header length(28)] [|tcp]

tests/bgp-bgp_capabilities_print-oobr-1.out

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
1 1970-03-16 01:04:13.49220352 IP (tos 0x1f,CE, ttl 254, id 38671, offset 0, flags [+, DF, rsvd], proto TCP (6), length 4135, bad cksum 200 (->1fdd)!)
2-
226.219.0.0.179 > 16.233.34.0.100: Flags [SPUE], seq 347537408:347541483, win 511, urg 65535, options [eol], length 4075: BGP [|bgp]
2+
226.219.0.0.179 > 16.233.34.0.100: Flags [SPUEe], seq 347537408:347541483, win 511, urg 65535, options [eol], length 4075: BGP [|bgp]
33
Open Message (1), length: 59
44
Version 255, my AS 65528, Holdtime 4324s, ID 144.8.32.4
55
Optional parameters, length: 29

0 commit comments

Comments
 (0)