[dpdk-dev,2/2] net/tap: update redirection rule after MAC change

Message ID eb463571ff1a69117cb4c71478cf41d7cc311010.1490780602.git.pascal.mazon@6wind.com (mailing list archive)
State Superseded, archived
Delegated to: Ferruh Yigit
Headers

Checks

Context Check Description
ci/Intel-compilation success Compilation OK
ci/checkpatch success coding style OK

Commit Message

Pascal Mazon March 29, 2017, 9:44 a.m. UTC
  This is necessary to ensure packets with the new MAC address as
destination get redirected to the tap device.

Also make the change only if the requested MAC address is different from
the current one.

Fixes: 75b6a1f7f004 ("net/tap: add remote netdevice traffic capture")
Signed-off-by: Pascal Mazon <pascal.mazon@6wind.com>
---
 drivers/net/tap/rte_eth_tap.c | 15 +++++++++++++++
 1 file changed, 15 insertions(+)
  

Patch

diff --git a/drivers/net/tap/rte_eth_tap.c b/drivers/net/tap/rte_eth_tap.c
index 6567bba75b47..069200199573 100644
--- a/drivers/net/tap/rte_eth_tap.c
+++ b/drivers/net/tap/rte_eth_tap.c
@@ -772,6 +772,8 @@  tap_mac_set(struct rte_eth_dev *dev, struct ether_addr *mac_addr)
 	struct pmd_internals *pmd = dev->data->dev_private;
 	struct ifreq ifr;
 
+	if (is_same_ether_addr(mac_addr, &pmd->eth_addr))
+		return;
 	if (is_zero_ether_addr(mac_addr)) {
 		RTE_LOG(ERR, PMD, "%s: can't set an empty MAC address\n",
 			dev->data->name);
@@ -783,6 +785,19 @@  tap_mac_set(struct rte_eth_dev *dev, struct ether_addr *mac_addr)
 	if (tap_ioctl(pmd, SIOCSIFHWADDR, &ifr, 1) < 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",
+				pmd->remote_iface);
+			return;
+		}
+		if (tap_flow_implicit_create(pmd, TAP_REMOTE_LOCAL_MAC) < 0)
+			RTE_LOG(ERR, PMD,
+				"%s: Couldn't add MAC redirection rule\n",
+				pmd->remote_iface);
+	}
 }
 
 static int