From: Stephen Hemminger <stephen@networkplumber.org>
To: dev@dpdk.org
Cc: Stephen Hemminger <stephen@networkplumber.org>
Subject: [PATCH 11/12] net/pcap: support MAC address set
Date: Tue, 6 Jan 2026 10:26:50 -0800 [thread overview]
Message-ID: <20260106182823.192350-12-stephen@networkplumber.org> (raw)
In-Reply-To: <20260106182823.192350-1-stephen@networkplumber.org>
When using pcap on a single interface, it is possible for
driver to proxy the mac address set operation.
Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
drivers/net/pcap/pcap_ethdev.c | 13 ++++++++++++
drivers/net/pcap/pcap_osdep.h | 1 +
drivers/net/pcap/pcap_osdep_freebsd.c | 23 ++++++++++++++++++++
drivers/net/pcap/pcap_osdep_linux.c | 30 ++++++++++++++++++++++++++-
4 files changed, 66 insertions(+), 1 deletion(-)
diff --git a/drivers/net/pcap/pcap_ethdev.c b/drivers/net/pcap/pcap_ethdev.c
index bf863e8708..79f2e28fbc 100644
--- a/drivers/net/pcap/pcap_ethdev.c
+++ b/drivers/net/pcap/pcap_ethdev.c
@@ -1103,6 +1103,18 @@ eth_mtu_set(struct rte_eth_dev *dev, uint16_t mtu)
return 0;
}
+static int
+eth_dev_macaddr_set(struct rte_eth_dev *dev, struct rte_ether_addr *addr)
+{
+ struct pmd_internals *internals = dev->data->dev_private;
+
+ if (internals->single_iface)
+ return osdep_iface_mac_set(internals->if_index, addr);
+ else
+ return -ENOTSUP;
+}
+
+
/* Timestamp values in receive packets from libpcap are in UTC */
static int
eth_rx_clock(struct rte_eth_dev *dev __rte_unused, uint64_t *timestamp)
@@ -1127,6 +1139,7 @@ static const struct eth_dev_ops ops = {
.rx_queue_stop = eth_rx_queue_stop,
.tx_queue_stop = eth_tx_queue_stop,
.link_update = eth_link_update,
+ .mac_addr_set = eth_dev_macaddr_set,
.mtu_set = eth_mtu_set,
.stats_get = eth_stats_get,
.stats_reset = eth_stats_reset,
diff --git a/drivers/net/pcap/pcap_osdep.h b/drivers/net/pcap/pcap_osdep.h
index 3c8b7ff27b..00944e0843 100644
--- a/drivers/net/pcap/pcap_osdep.h
+++ b/drivers/net/pcap/pcap_osdep.h
@@ -14,6 +14,7 @@ extern int eth_pcap_logtype;
int osdep_iface_index_get(const char *name);
int osdep_iface_mac_get(const char *name, struct rte_ether_addr *mac);
+int osdep_iface_mac_set(int ifindex, const struct rte_ether_addr *mac);
int osdep_iface_mtu_set(int index, uint16_t mtu);
#endif
diff --git a/drivers/net/pcap/pcap_osdep_freebsd.c b/drivers/net/pcap/pcap_osdep_freebsd.c
index 0279dbf00b..39227da63a 100644
--- a/drivers/net/pcap/pcap_osdep_freebsd.c
+++ b/drivers/net/pcap/pcap_osdep_freebsd.c
@@ -58,6 +58,29 @@ osdep_iface_mac_get(const char *if_name, struct rte_ether_addr *mac)
return 0;
}
+int
+osdep_iface_mac_set(int ifindex, const struct rte_ether_addr *mac)
+{
+ char ifname[IFNAMSIZ];
+
+ if (if_indextoname(ifindex, ifname) == NULL)
+ return -errno;
+
+ int s = socket(AF_INET, SOCK_DGRAM, 0);
+ if (s < 0)
+ return -errno;
+
+ struct ifreq ifr = { 0 };
+ strlcpy(ifr.ifr_name, ifname, IFNAMSIZ);
+ ifr.ifr_addr.sa_family = AF_LINK;
+ memcpy(ifr.ifr_addr.sa_data, mac, sizeof(*mac));
+
+ int ret = ioctl(s, SIOCSIFLLADDR, &ifr);
+ close(s);
+
+ return (ret < 0) ? -errno : 0;
+}
+
int osdep_iface_mtu_set(int ifindex, uint16_t mtu)
{
char ifname[IFNAMSIZ];
diff --git a/drivers/net/pcap/pcap_osdep_linux.c b/drivers/net/pcap/pcap_osdep_linux.c
index d180e9b4b4..d5a3855a0a 100644
--- a/drivers/net/pcap/pcap_osdep_linux.c
+++ b/drivers/net/pcap/pcap_osdep_linux.c
@@ -4,13 +4,18 @@
* All rights reserved.
*/
+#include <string.h>
+#include <stdint.h>
+#include <unistd.h>
+#include <errno.h>
#include <net/if.h>
+#include <net/if_arp.h>
#include <sys/ioctl.h>
#include <sys/socket.h>
-#include <unistd.h>
#include <rte_memcpy.h>
#include <rte_string_fns.h>
+#include <rte_ether.h>
#include "pcap_osdep.h"
@@ -41,6 +46,29 @@ osdep_iface_mac_get(const char *if_name, struct rte_ether_addr *mac)
return 0;
}
+int
+osdep_iface_mac_set(int ifindex, const struct rte_ether_addr *mac)
+{
+ char ifname[IFNAMSIZ];
+
+ if (if_indextoname(ifindex, ifname) == NULL)
+ return -errno;
+
+ int s = socket(AF_INET, SOCK_DGRAM, 0);
+ if (s < 0)
+ return -errno;
+
+ struct ifreq ifr = { 0 };
+ strlcpy(ifr.ifr_name, ifname, IFNAMSIZ);
+ ifr.ifr_hwaddr.sa_family = ARPHRD_ETHER;
+ memcpy(ifr.ifr_hwaddr.sa_data, mac, sizeof(*mac));
+
+ int ret = ioctl(s, SIOCSIFHWADDR, &ifr);
+ close(s);
+
+ return (ret < 0) ? -errno : 0;
+}
+
int
osdep_iface_mtu_set(int ifindex, uint16_t mtu)
{
--
2.51.0
next prev parent reply other threads:[~2026-01-06 18:34 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-01-06 18:26 [PATCH 00/12] net/pcap: cleanups and test Stephen Hemminger
2026-01-06 18:26 ` [PATCH 01/12] net/pcap: avoid using rte_malloc and rte_memcpy Stephen Hemminger
2026-01-06 18:26 ` [PATCH 02/12] net/pcap: support MTU set Stephen Hemminger
2026-01-06 18:26 ` [PATCH 03/12] net/pcap: use bool for flags Stephen Hemminger
2026-01-07 10:28 ` Marat Khalili
2026-01-09 0:23 ` Stephen Hemminger
2026-01-06 18:26 ` [PATCH 04/12] net/pcap: support Tx offloads Stephen Hemminger
2026-01-06 18:26 ` [PATCH 05/12] net/pcap: support nanosecond timestamp precision Stephen Hemminger
2026-01-06 18:26 ` [PATCH 06/12] net/pcap: remove global variables Stephen Hemminger
2026-01-07 9:48 ` Marat Khalili
2026-01-06 18:26 ` [PATCH 07/12] net/pcap: avoid use of volatile Stephen Hemminger
2026-01-07 10:31 ` Marat Khalili
2026-01-06 18:26 ` [PATCH 08/12] net/pcap: optimize calculation of receive timestamp Stephen Hemminger
2026-01-07 10:58 ` Marat Khalili
2026-01-06 18:26 ` [PATCH 09/12] net/pcap: report receive clock Stephen Hemminger
2026-01-06 18:26 ` [PATCH 10/12] net/pcap: cleanup MAC address handling Stephen Hemminger
2026-01-06 18:26 ` Stephen Hemminger [this message]
2026-01-06 18:26 ` [PATCH 12/12] test: add test for pcap PMD Stephen Hemminger
2026-01-09 1:16 ` [PATCH v2 0/9] pcap: cleanup pcap PMD and add test Stephen Hemminger
2026-01-09 1:16 ` [PATCH v2 1/9] net/pcap: avoid using rte_malloc and rte_memcpy Stephen Hemminger
2026-01-09 1:16 ` [PATCH v2 2/9] net/pcap: support MTU set Stephen Hemminger
2026-01-09 1:16 ` [PATCH v2 3/9] net/pcap: use bool for flags Stephen Hemminger
2026-01-09 1:16 ` [PATCH v2 4/9] net/pcap: support Tx offloads Stephen Hemminger
2026-01-09 1:16 ` [PATCH v2 5/9] net/pcap: support nanosecond timestamp precision Stephen Hemminger
2026-01-09 1:16 ` [PATCH v2 6/9] net/pcap: remove global variables Stephen Hemminger
2026-01-09 1:16 ` [PATCH v2 7/9] net/pcap: avoid use of volatile Stephen Hemminger
2026-01-09 1:16 ` [PATCH v2 8/9] net/pcap: support MAC address set Stephen Hemminger
2026-01-09 1:16 ` [PATCH v2 9/9] test: add test for pcap PMD Stephen Hemminger
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260106182823.192350-12-stephen@networkplumber.org \
--to=stephen@networkplumber.org \
--cc=dev@dpdk.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).