1: Index: tools/tools/netmap/pkt-gen.c
2: ===================================================================
3: --- tools/tools/netmap/pkt-gen.c (revision 283536)
4: +++ tools/tools/netmap/pkt-gen.c (working copy)
5: @@ -174,6 +174,7 @@
6: int nthreads;
7: int cpus;
8: int options; /* testing */
9: + int softchecksum; /* Software UDP checksum calculation */
10: #define OPT_PREFETCH 1
11: #define OPT_ACCESS 2
12: #define OPT_COPY 4
13: @@ -565,6 +566,7 @@
14: {
15: uint32_t a;
16: uint16_t p;
17: + struct ether_header *eh = &pkt->eh;
18: struct ip *ip = &pkt->ip;
19: struct udphdr *udp = &pkt->udp;
20:
21: @@ -611,6 +613,25 @@
22: ip->ip_dst.s_addr = htonl(g->dst_ip.start);
23: } while (0);
24: // update checksum
25: + /* Some NIC disable hardware CRC checksum in netmap mode
26: + * and don't allow to re-enable it */
27: +
28: + if (g->softchecksum) {
29: + ip->ip_sum = 0;
30: + ip->ip_sum = wrapsum(checksum(ip, sizeof(*ip), 0));
31: + /* UDP checksum */
32: + uint16_t paylen = g->pkt_size - sizeof(*eh) - sizeof(struct ip);
33: + udp->uh_sum = 0;
34: + udp->uh_sum = wrapsum(checksum(udp, sizeof(*udp),
35: + checksum(pkt->body,
36: + paylen - sizeof(*udp),
37: + checksum(&ip->ip_src, 2 * sizeof(ip->ip_src),
38: + IPPROTO_UDP + (u_int32_t)ntohs(udp->uh_ulen)
39: + )
40: + )
41: + ));
42: + }
43: +
44: }
45:
46: /*
47: @@ -1409,6 +1430,7 @@
48: "\t-X dump payload\n"
49: "\t-H len add empty virtio-net-header with size 'len'\n"
50: "\t-P file load packet from pcap file\n"
51: + "\t-U enable software UDP CRC chekcsum\n"
52: "\t-z use random IPv4 src address/port\n"
53: "\t-Z use random IPv4 dst address/port\n"
54: "",
55: @@ -1683,7 +1705,7 @@
56: g.virt_header = 0;
57:
58: while ( (ch = getopt(arc, argv,
59: - "a:f:F:n:i:Il:d:s:D:S:b:c:o:p:T:w:WvR:XC:H:e:m:P:zZ")) != -1) {
60: + "a:f:F:n:i:Il:d:s:D:S:b:c:o:p:T:Uw:WvR:XC:H:e:m:P:zZ")) != -1) {
61: struct sf *fn;
62:
63: switch(ch) {
64: @@ -1785,6 +1807,9 @@
65: case 'b': /* burst */
66: g.burst = atoi(optarg);
67: break;
68: + case 'U': /* software UDP checksum */
69: + g.softchecksum = 1;
70: + break;
71: case 'c':
72: g.cpus = atoi(optarg);
73: break;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>