From 38ba1ae58256dbc5619e8388824351b9d11047e8 Mon Sep 17 00:00:00 2001 From: Martin Mares Date: Mon, 17 Jun 2013 18:27:20 +0200 Subject: [PATCH] Added an option to accept broken checksums This is needed for example when capturing on network interfaces which make use of hardware checksum offloading. --- netgrind/ip.c | 9 +++++++-- netgrind/netgrind.c | 6 +++++- netgrind/netgrind.h | 1 + 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/netgrind/ip.c b/netgrind/ip.c index b021335..5280b9e 100644 --- a/netgrind/ip.c +++ b/netgrind/ip.c @@ -1,7 +1,7 @@ /* * Netgrind -- IP Layer Analyser * - * (c) 2003 Martin Mares + * (c) 2003--2013 Martin Mares * * This software may be freely distributed and used according to the terms * of the GNU General Public License. @@ -15,6 +15,8 @@ #include #include +uns accept_broken_checksums; + uns tcpip_calc_checksum(void *data, uns len, uns csum) { /* FIXME: This is awfully slow and it probably consumes most of our run time */ @@ -45,7 +47,10 @@ uns tcpip_calc_checksum(void *data, uns len, uns csum) uns tcpip_verify_checksum(uns csum) { - return (csum == 0xffff); + if (accept_broken_checksums) + return 1; + else + return (csum == 0xffff); } struct pkt_stats stat_ip_in, stat_ip_invalid, stat_ip_uninteresting, stat_ip_fragmented, stat_ip_badsum; diff --git a/netgrind/netgrind.c b/netgrind/netgrind.c index b3d1a3c..c20524d 100644 --- a/netgrind/netgrind.c +++ b/netgrind/netgrind.c @@ -117,6 +117,7 @@ static void usage(void) fprintf(stderr, "Usage: netgrind [] \n\ \n\ -a TCP: Record arrival times instead of processing times\n\ +-b Accept broken checksums\n\ -c Stop after processing packets\n\ -d Dump connections to a given directory\n\ -D Dump connections with more details\n\ @@ -142,12 +143,15 @@ int main(int argc, char **argv) byte *histogram = NULL; tcp_default_appl = &appl_mux; - while ((c = getopt(argc, argv, "ac:d:D:f:h:stwx:")) >= 0) + while ((c = getopt(argc, argv, "abc:d:D:f:h:stwx:")) >= 0) switch (c) { case 'a': tcp_arrival_times = 1; break; + case 'b': + accept_broken_checksums = 1; + break; case 'c': max_packets = atol(optarg); break; diff --git a/netgrind/netgrind.h b/netgrind/netgrind.h index a72fc3d..b32fe74 100644 --- a/netgrind/netgrind.h +++ b/netgrind/netgrind.h @@ -18,6 +18,7 @@ void link_eth_got_packet(struct pkt *p); /* ip.c */ extern struct pkt_stats stat_ip_in, stat_ip_invalid, stat_ip_uninteresting, stat_ip_fragmented, stat_ip_badsum; +extern uns accept_broken_checksums; uns tcpip_calc_checksum(void *data, uns len, uns csum); uns tcpip_verify_checksum(uns csum); -- 2.39.2