DPDK patches and discussions
 help / color / mirror / Atom feed
* [dpdk-dev] [PATCH 20.05] net/af_packet: support default mac address change
@ 2020-02-15 19:20 Stephen Hemminger
  2020-02-27 14:20 ` Ferruh Yigit
  0 siblings, 1 reply; 2+ messages in thread
From: Stephen Hemminger @ 2020-02-15 19:20 UTC (permalink / raw)
  To: linville; +Cc: dev, Stephen Hemminger

Since packet is talking to a network device (probably tap)
it is possible for the device driver to change the hardware address
by making an ioctl to kernel.

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
 drivers/net/af_packet/rte_eth_af_packet.c | 28 +++++++++++++++++++++++
 1 file changed, 28 insertions(+)

diff --git a/drivers/net/af_packet/rte_eth_af_packet.c b/drivers/net/af_packet/rte_eth_af_packet.c
index f5806bf42c46..ae3c25f2b619 100644
--- a/drivers/net/af_packet/rte_eth_af_packet.c
+++ b/drivers/net/af_packet/rte_eth_af_packet.c
@@ -19,6 +19,7 @@
 #include <linux/if_packet.h>
 #include <arpa/inet.h>
 #include <net/if.h>
+#include <net/if_arp.h>
 #include <sys/types.h>
 #include <sys/socket.h>
 #include <sys/ioctl.h>
@@ -468,6 +469,32 @@ eth_dev_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;
+	struct ifreq ifr = { };
+	int sockfd = internals->rx_queue[0].sockfd;
+	int ret;
+
+	if (sockfd == -1) {
+		PMD_LOG(ERR, "receive socket not found");
+		return -EINVAL;
+	}
+
+	strlcpy(ifr.ifr_name, internals->if_name, IFNAMSIZ);
+	ifr.ifr_hwaddr.sa_family = ARPHRD_ETHER;
+	memcpy(ifr.ifr_hwaddr.sa_data, addr, sizeof(*addr));
+	ret = ioctl(sockfd, SIOCSIFHWADDR, &ifr);
+
+	if (ret < 0) {
+		PMD_LOG_ERRNO(ERR, "ioctl(SIOCSIFHWADDR) failed");
+		return -EINVAL;
+	}
+
+	return 0;
+}
+
 static int
 eth_dev_change_flags(char *if_name, uint32_t flags, uint32_t mask)
 {
@@ -517,6 +544,7 @@ static const struct eth_dev_ops ops = {
 	.dev_close = eth_dev_close,
 	.dev_configure = eth_dev_configure,
 	.dev_infos_get = eth_dev_info,
+	.mac_addr_set = eth_dev_macaddr_set,
 	.mtu_set = eth_dev_mtu_set,
 	.promiscuous_enable = eth_dev_promiscuous_enable,
 	.promiscuous_disable = eth_dev_promiscuous_disable,
-- 
2.20.1


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [dpdk-dev] [PATCH 20.05] net/af_packet: support default mac address change
  2020-02-15 19:20 [dpdk-dev] [PATCH 20.05] net/af_packet: support default mac address change Stephen Hemminger
@ 2020-02-27 14:20 ` Ferruh Yigit
  0 siblings, 0 replies; 2+ messages in thread
From: Ferruh Yigit @ 2020-02-27 14:20 UTC (permalink / raw)
  To: Stephen Hemminger, linville; +Cc: dev

On 2/15/2020 7:20 PM, Stephen Hemminger wrote:
> Since packet is talking to a network device (probably tap)
> it is possible for the device driver to change the hardware address
> by making an ioctl to kernel.
> 
> Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>

Reviewed-by: Ferruh Yigit <ferruh.yigit@intel.com>

Applied to dpdk-next-net/master, thanks.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2020-02-27 14:21 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-02-15 19:20 [dpdk-dev] [PATCH 20.05] net/af_packet: support default mac address change Stephen Hemminger
2020-02-27 14:20 ` Ferruh Yigit

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).