git: 9a7abd932727 - main - pkt-gen: flip IPv4 address in ping-pong mode

From: Vincenzo Maffione <vmaffione_at_FreeBSD.org>
Date: Wed, 24 Aug 2022 08:22:35 UTC
The branch main has been updated by vmaffione:

URL: https://cgit.FreeBSD.org/src/commit/?id=9a7abd932727dbf593cda85b18de87855b2e7e06

commit 9a7abd932727dbf593cda85b18de87855b2e7e06
Author:     Vincenzo Maffione <vmaffione@FreeBSD.org>
AuthorDate: 2022-08-24 08:20:57 +0000
Commit:     Vincenzo Maffione <vmaffione@FreeBSD.org>
CommitDate: 2022-08-24 08:20:57 +0000

    pkt-gen: flip IPv4 address in ping-pong mode
    
    MFC after:      7 days
---
 tools/tools/netmap/pkt-gen.c | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

diff --git a/tools/tools/netmap/pkt-gen.c b/tools/tools/netmap/pkt-gen.c
index f43469cf7ad6..7ae4d60f8813 100644
--- a/tools/tools/netmap/pkt-gen.c
+++ b/tools/tools/netmap/pkt-gen.c
@@ -1322,6 +1322,10 @@ ping_body(void *data)
 		return NULL;
 	}
 
+	if (targ->g->af == AF_INET6) {
+		D("Warning: ping-pong with IPv6 not supported");
+	}
+
 	bzero(&buckets, sizeof(buckets));
 	clock_gettime(CLOCK_REALTIME_PRECISE, &last_print);
 	now = last_print;
@@ -1504,6 +1508,11 @@ pong_body(void *data)
 	if (n > 0)
 		D("understood ponger %llu but don't know how to do it",
 			(unsigned long long)n);
+
+	if (targ->g->af == AF_INET6) {
+		D("Warning: ping-pong with IPv6 not supported");
+	}
+
 	while (!targ->cancel && (n == 0 || sent < n)) {
 		uint32_t txhead, txavail;
 //#define BUSYWAIT
@@ -1547,7 +1556,15 @@ pong_body(void *data)
 				dpkt[3] = spkt[0];
 				dpkt[4] = spkt[1];
 				dpkt[5] = spkt[2];
+				/* swap source and destination IPv4 */
+				if (spkt[6] == htons(ETHERTYPE_IP)) {
+					dpkt[13] = spkt[15];
+					dpkt[14] = spkt[16];
+					dpkt[15] = spkt[13];
+					dpkt[16] = spkt[14];
+				}
 				txring->slot[txhead].len = slot->len;
+				//dump_payload(dst, slot->len, txring, txhead);
 				txhead = nm_ring_next(txring, txhead);
 				txavail--;
 				sent++;