bin/187149: Patch for fixng netmap's pkt-gen behavior with IP addresses or port range
Olivier Cochard-Labbe
olivier at cochard.me
Fri Feb 28 21:10:00 UTC 2014
>Number: 187149
>Category: bin
>Synopsis: Patch for fixng netmap's pkt-gen behavior with IP addresses or port range
>Confidential: no
>Severity: non-critical
>Priority: low
>Responsible: freebsd-bugs
>State: open
>Quarter:
>Keywords:
>Date-Required:
>Class: sw-bug
>Submitter-Id: current-users
>Arrival-Date: Fri Feb 28 21:10:00 UTC 2014
>Closed-Date:
>Last-Modified:
>Originator: Olivier Cochard-Labbe
>Release: -current
>Organization:
BSD Router Project
>Environment:
FreeBSD R1 11.0-CURRENT FreeBSD 11.0-CURRENT #0 r262618M: Fri Feb 28 21:07:26 CET 2014 root at orange.bsdrp.net:/usr/obj/BSDRPcur.amd64/usr/local/BSDRP/BSDRPcur/FreeBSD/src/sys/amd64 amd64
>Description:
Using range option of netmap's pkt-gen generate packets with bad IP and UDP checksum.
>How-To-Repeat:
If you pkt-gen this this kind of range option:
-f tx -l 60 -d 2.1.3.1-2.1.3.10 -s 1.1.3.1-1.1.3.10
A tcpdump on the receiving host will display that it's recveing lot's of packets with bad checksums:
19:31:28.029702 IP (tos 0x10, ttl 64, id 0, offset 0, flags [DF], proto UDP (17), length 46, bad cksum 31ac (->31a1)!)
1.1.3.9.0 > 2.1.3.4.0: [bad udp cksum 0x2a23 -> 0x2a18!] UDP, length 18
19:31:28.029704 IP (tos 0x10, ttl 64, id 0, offset 0, flags [DF], proto UDP (17), length 46, bad cksum 31ac (->31a3)!)
1.1.3.10.0 > 2.1.3.1.0: [bad udp cksum 0x2a23 -> 0x2a1a!] UDP, length 18
19:31:28.029705 IP (tos 0x10, ttl 64, id 0, offset 0, flags [DF], proto UDP (17), length 46, bad cksum 31ac (->31a6)!)
1.1.3.4.0 > 2.1.3.4.0: [bad udp cksum 0x2a23 -> 0x2a1d!] UDP, length 18
19:31:28.029706 IP (tos 0x10, ttl 64, id 0, offset 0, flags [DF], proto UDP (17), length 46, bad cksum 31ac (->31a4)!)
>Fix:
Applying the attached patch.
Patch attached with submission follows:
Index: tools/tools/netmap/pkt-gen.c
===================================================================
--- tools/tools/netmap/pkt-gen.c (revision 262618)
+++ tools/tools/netmap/pkt-gen.c (working copy)
@@ -546,6 +546,7 @@
{
uint32_t a;
uint16_t p;
+ struct ether_header *eh = &pkt->eh;
struct ip *ip = &pkt->ip;
struct udphdr *udp = &pkt->udp;
@@ -580,6 +581,25 @@
ip->ip_dst.s_addr = htonl(g->dst_ip.start);
} while (0);
// update checksum
+ /* Missing code here ? the comment "update checksum" should be followed
+ * by updating IP & UDP checksum. I will try to fix by simply copy/past
+ * checksum code from initialize_packet function */
+
+ ip->ip_sum = 0;
+ ip->ip_sum = wrapsum(checksum(ip, sizeof(*ip), 0));
+
+ /* UDP checksum */
+ uint16_t paylen = g->pkt_size - sizeof(*eh) - sizeof(struct ip);
+ udp->uh_sum = 0;
+ udp->uh_sum = wrapsum(checksum(udp, sizeof(*udp),
+ checksum(pkt->body,
+ paylen - sizeof(*udp),
+ checksum(&ip->ip_src, 2 * sizeof(ip->ip_src),
+ IPPROTO_UDP + (u_int32_t)ntohs(udp->uh_ulen)
+ )
+ )
+ ));
+
}
/*
>Release-Note:
>Audit-Trail:
>Unformatted:
More information about the freebsd-bugs
mailing list