Skip to content
This repository has been archived by the owner on Nov 15, 2022. It is now read-only.

Commit

Permalink
IP: Enable TSO (TCP Segmentation Offload) support
Browse files Browse the repository at this point in the history
It's a follow-up to c862396.

The support is now enabled by default. No more "#ifdef GUESS_TSO".

Output example:
  length 2016 [was 0, presumed TSO]

Add a test file with presumed TSO.
(From http://cloudshark.org/captures/25e40f73bc1c, found via
https://osqa-ask.wireshark.org/questions/16279/)

Use ND_ICHECKMSG_U() to test an invalid total length < header length.

Output example:
  [total length 19 < 20] (invalid)

Add a test file for this case.

Move ND_TCHECK_SIZE(ip) after the new tests.

Add a const qualifier for the ip_print() parameter 'length'.

Update the man page.

(backported from commit 3465ec4)
  • Loading branch information
fxlb committed Oct 25, 2023
1 parent bf70c3a commit 4c9a2df
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 19 deletions.
2 changes: 1 addition & 1 deletion netdissect.h
Original file line number Diff line number Diff line change
Expand Up @@ -657,7 +657,7 @@ extern void igmp_print(netdissect_options *, const u_char *, u_int);
extern void igrp_print(netdissect_options *, const u_char *, u_int);
extern void ip6_print(netdissect_options *, const u_char *, u_int);
extern void ipN_print(netdissect_options *, const u_char *, u_int);
extern void ip_print(netdissect_options *, const u_char *, u_int);
extern void ip_print(netdissect_options *, const u_char *, const u_int);
extern void ipcomp_print(netdissect_options *, const u_char *);
extern void ipx_netbios_print(netdissect_options *, const u_char *, u_int);
extern void ipx_print(netdissect_options *, const u_char *, u_int);
Expand Down
30 changes: 13 additions & 17 deletions print-ip.c
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ static const struct tok ip_frag_values[] = {
void
ip_print(netdissect_options *ndo,
const u_char *bp,
u_int length)
const u_int length)
{
const struct ip *ip;
u_int off;
Expand All @@ -329,6 +329,7 @@ ip_print(netdissect_options *ndo,
uint16_t sum, ip_sum;
const char *p_name;
int truncated = 0;
int presumed_tso = 0;

ndo->ndo_protocol = "ip";
ip = (const struct ip *)bp;
Expand All @@ -350,22 +351,14 @@ ip_print(netdissect_options *ndo,
nd_print_invalid(ndo);
ND_PRINT(" ");
}
ND_TCHECK_SIZE(ip);
if (len < hlen) {
#ifdef GUESS_TSO
if (len) {
ND_PRINT("bad-len %u", len);
return;
} else {
/* we guess that it is a TSO send */
len = length;
}
#else
ND_PRINT("bad-len %u", len);
return;
#endif /* GUESS_TSO */
}
if (len == 0) {
/* we guess that it is a TSO send */
len = length;
presumed_tso = 1;
} else
ND_ICHECKMSG_U("total length", len, <, hlen);

ND_TCHECK_SIZE(ip);
/*
* Cut off the snapshot length to the end of the IP payload.
*/
Expand Down Expand Up @@ -418,7 +411,10 @@ ip_print(netdissect_options *ndo,
tok2str(ipproto_values, "unknown", ip_proto),
ip_proto);

ND_PRINT(", length %u", GET_BE_U_2(ip->ip_len));
if (presumed_tso)
ND_PRINT(", length %u [was 0, presumed TSO]", length);
else
ND_PRINT(", length %u", GET_BE_U_2(ip->ip_len));

if ((hlen - sizeof(struct ip)) > 0) {
ND_PRINT(", options (");
Expand Down
3 changes: 2 additions & 1 deletion tcpdump.1.in
Original file line number Diff line number Diff line change
Expand Up @@ -1267,7 +1267,8 @@ part of a fragmented datagram or not.
and \fBDF\fP is reported if F is set. If neither are set, \fB.\fP is
reported.
\fIproto\fP is the protocol ID field.
\fIlength\fP is the total length field.
\fIlength\fP is the total length field; if the packet is a presumed TSO
(TCP Segmentation Offload) send, [was 0, presumed TSO] is reported.
\fIoptions\fP are the IP options, if any.
.LP
Next, for TCP and UDP packets, the source and destination IP addresses
Expand Down
2 changes: 2 additions & 0 deletions tests/TESTLIST
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,8 @@ ipv4_invalid_length ipv4_invalid_length.pcap ipv4_invalid_length.out -v
ipv4_invalid_hdr_length ipv4_invalid_hdr_length.pcap ipv4_invalid_hdr_length.out -v
ipv4_invalid_total_length ipv4_invalid_total_length.pcap ipv4_invalid_total_length.out -v
ipv4_tcp_http_xml ipv4_tcp_http_xml.pcap ipv4_tcp_http_xml.out -v
ipv4_invalid_total_length_2 ipv4_invalid_total_length_2.pcap ipv4_invalid_total_length_2.out -v
ipv4_tcp_http_xml_tso ipv4_tcp_http_xml_tso.pcap ipv4_tcp_http_xml_tso.out -v

#IPv6 tests
ipv6-bad-version ipv6-bad-version.pcap ipv6-bad-version.out
Expand Down
1 change: 1 addition & 0 deletions tests/ipv4_invalid_total_length_2.out
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1 08:57:44.621711 IP [total length 19 < 20] (invalid)
Binary file added tests/ipv4_invalid_total_length_2.pcap
Binary file not shown.
14 changes: 14 additions & 0 deletions tests/ipv4_tcp_http_xml_tso.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
1 19:50:14.587897 IP (tos 0x0, ttl 128, id 17097, offset 0, flags [DF], proto TCP (6), length 2016 [was 0, presumed TSO], bad cksum 0 (->d8df)!)
30.7.181.121.39556 > 199.43.68.163.8080: Flags [P.], cksum 0xdf55 (incorrect -> 0x9cf2), seq 1891338696:1891340672, ack 727404759, win 256, length 1976: HTTP, length: 1976
POST http://gwm-ml-a2.wsodqa.com//research/module-loader/module-loader.asp?user_id=test HTTP/1.1
Content-Type: text/xml; charset=utf-8
SOAPAction: ""
User-Agent: Axis/1.4-LISA
lisaFrameRoot: true
lisaFrameRemoteIP: 169.254.169.30
lisaFrameID: 3ae1f0b0-0293-11e2-aa16-78e7d164f804
Host: gwm-ml-a2.wsodqa.com
Proxy-Connection: Keep-Alive
Content-Length: 1607

<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Body><GetResponse xmlns="http://tempuri.org/"><req><wgt wID="143"><inpt><mxRltm>false</mxRltm><hlds><HoldingsCount>0</HoldingsCount></hlds><wtlsts /><BondType /><IsCollapsed>false</IsCollapsed></inpt></wgt><wgt wID="151"><inpt><mxRltm>false</mxRltm><lnkUrls><url><key>RUN_RIReviewMarketsUI_RevMktNews</key><val>/RIReviewMarketsUI/RevMktNews.aspx</val></url><url><key>RUN_RIReviewMarketsUI_RevMktNewsFullStory</key><val>/RIReviewMarketsUI/RevMktNewsFullStory.aspx</val></url></lnkUrls><BondType /><IsCollapsed>false</IsCollapsed></inpt></wgt><wgt wID="144"><inpt><mxRltm>false</mxRltm><BondType /><IsCollapsed>false</IsCollapsed></inpt></wgt><wgt wID="146"><inpt><mxRltm>false</mxRltm><lnkUrls><url><key>RUN_RIStocksUI_RIStocksOverview</key><val>/RIStocksUI/RIStocksOverview.aspx</val></url><url><key>RUN_RIMutualFundsUI_RIMFOverview</key><val>/RIMutualFundsUI/RIMFOverview.aspx</val></url><url><key>RUN_RIEtfsUI_RIEtfsOverview</key><val>/RIEtfsUI/RIEtfsOverview.aspx</val></url><url><key>RUN_RIOptionsUI_RIOptionsOverview</key><val>/RIOptionsUI/RIOptionsOverview.aspx</val></url></lnkUrls><BondType /><IsCollapsed>false</IsCollapsed></inpt></wgt><wgt wID="145"><inpt><mxRltm>false</mxRltm><BondType /><IsCollapsed>false</IsCollapsed></inpt></wgt><wgt wID="147"><inpt><mxRltm>false</mxRltm><BondType /><IsCollapsed>false</IsCollapsed></inpt></wgt></req></GetResponse></soap:Body></soap:Envelope>
Binary file added tests/ipv4_tcp_http_xml_tso.pcap
Binary file not shown.

0 comments on commit 4c9a2df

Please sign in to comment.