git: eda82511883f - main - netmap: pkt-gen: fix ifname before cmp in source_hwaddr

From: Vincenzo Maffione <vmaffione_at_FreeBSD.org>
Date: Sat, 24 Dec 2022 16:08:13 UTC
The branch main has been updated by vmaffione:

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

commit eda82511883f540cd18f8afd2268636c7db97685
Author:     Vincenzo Maffione <vmaffione@FreeBSD.org>
AuthorDate: 2022-12-24 16:06:05 +0000
Commit:     Vincenzo Maffione <vmaffione@FreeBSD.org>
CommitDate: 2022-12-24 16:06:05 +0000

    netmap: pkt-gen: fix ifname before cmp in source_hwaddr
    
    In source_hwaddr(), the configured ifname is compared against all
    interfaces. However, in main(), the string 'netmap:' is prepended to the
    interface string if no explicit type is given. Therefore the ifname will
    not match any system interface and the source MAC address is always
    empty.
    
    Check for the leading 'netmap:' string and skip past it to match against
    system interfaces. Note that 'tap:' and 'pcap:' devices strip the type
    string from the ifname in main() so no further work is needed.
    
    MFC after:      7 days
    Submitted by:   Brian Poole <brian90013@gmail.com>
---
 tools/tools/netmap/pkt-gen.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/tools/tools/netmap/pkt-gen.c b/tools/tools/netmap/pkt-gen.c
index c6bae50188e2..c6cf78ad85ee 100644
--- a/tools/tools/netmap/pkt-gen.c
+++ b/tools/tools/netmap/pkt-gen.c
@@ -684,6 +684,10 @@ source_hwaddr(const char *ifname, char *buf)
 		return (-1);
 	}
 
+	/* remove 'netmap:' prefix before comparing interfaces */
+	if (!strncmp(ifname, "netmap:", 7))
+		ifname = &ifname[7];
+
 	for (ifap = ifaphead; ifap; ifap = ifap->ifa_next) {
 		struct sockaddr_dl *sdl =
 			(struct sockaddr_dl *)ifap->ifa_addr;