From 41f0e86033b9cff50e9894737a0a2f978510e2cf Mon Sep 17 00:00:00 2001 From: Pascal Mazon Date: Fri, 31 Mar 2017 15:54:11 +0200 Subject: [PATCH] net/tap: fix redirection rule after MAC change This is necessary to ensure packets with the new MAC address as destination get redirected to the tap device. Also change the MAC address only if the current one is different from the requested one. Fixes: 2bc06869cd94 ("net/tap: add remote netdevice traffic capture") Signed-off-by: Pascal Mazon --- drivers/net/tap/rte_eth_tap.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/drivers/net/tap/rte_eth_tap.c b/drivers/net/tap/rte_eth_tap.c index a780292b4e..8321863440 100644 --- a/drivers/net/tap/rte_eth_tap.c +++ b/drivers/net/tap/rte_eth_tap.c @@ -775,12 +775,35 @@ tap_mac_set(struct rte_eth_dev *dev, struct ether_addr *mac_addr) dev->data->name); return; } + /* Check the actual current MAC address on the tap netdevice */ + if (tap_ioctl(pmd, SIOCGIFHWADDR, &ifr, 0, LOCAL_ONLY) != 0) { + RTE_LOG(ERR, PMD, + "%s: couldn't check current tap MAC address\n", + dev->data->name); + return; + } + if (is_same_ether_addr((struct ether_addr *)&ifr.ifr_hwaddr.sa_data, + mac_addr)) + return; ifr.ifr_hwaddr.sa_family = AF_LOCAL; rte_memcpy(ifr.ifr_hwaddr.sa_data, mac_addr, ETHER_ADDR_LEN); if (tap_ioctl(pmd, SIOCSIFHWADDR, &ifr, 1, LOCAL_AND_REMOTE) < 0) return; rte_memcpy(&pmd->eth_addr, mac_addr, ETHER_ADDR_LEN); + if (pmd->remote_if_index) { + /* Replace MAC redirection rule after a MAC change */ + if (tap_flow_implicit_destroy(pmd, TAP_REMOTE_LOCAL_MAC) < 0) { + RTE_LOG(ERR, PMD, + "%s: Couldn't delete MAC redirection rule\n", + dev->data->name); + return; + } + if (tap_flow_implicit_create(pmd, TAP_REMOTE_LOCAL_MAC) < 0) + RTE_LOG(ERR, PMD, + "%s: Couldn't add MAC redirection rule\n", + dev->data->name); + } } static int -- 2.20.1