net/tap: fix redirection rule after MAC change
authorPascal Mazon <pascal.mazon@6wind.com>
Fri, 31 Mar 2017 13:54:11 +0000 (15:54 +0200)
committerFerruh Yigit <ferruh.yigit@intel.com>
Tue, 4 Apr 2017 17:03:03 +0000 (19:03 +0200)
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 <pascal.mazon@6wind.com>
drivers/net/tap/rte_eth_tap.c

index a780292..8321863 100644 (file)
@@ -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