]> git.proxmox.com Git - mirror_ovs.git/commitdiff
netdev-dpdk: Add ability to set MAC address.
authorIlya Maximets <i.maximets@ovn.org>
Tue, 10 Nov 2020 11:51:48 +0000 (12:51 +0100)
committerIlya Maximets <i.maximets@ovn.org>
Mon, 16 Nov 2020 16:47:11 +0000 (17:47 +0100)
It is possible to set the MAC address of DPDK ports by calling
rte_eth_dev_default_mac_addr_set().  OvS does not actually call
this function for non-internal ports, but the implementation is
exposed to be used in a later commit.

Signed-off-by: Ilya Maximets <i.maximets@ovn.org>
Signed-off-by: Gaetan Rivet <grive@u256.net>
lib/netdev-dpdk.c

index 0b830be784ea10f804829e88bb9d4cab88b8b677..084f97807563ba0589b12048fb7ce81751c841bd 100644 (file)
@@ -2910,19 +2910,45 @@ netdev_dpdk_eth_send(struct netdev *netdev, int qid,
     return 0;
 }
 
+static int
+netdev_dpdk_set_etheraddr__(struct netdev_dpdk *dev, const struct eth_addr mac)
+    OVS_REQUIRES(dev->mutex)
+{
+    int err = 0;
+
+    if (dev->type == DPDK_DEV_ETH) {
+        struct rte_ether_addr ea;
+
+        memcpy(ea.addr_bytes, mac.ea, ETH_ADDR_LEN);
+        err = -rte_eth_dev_default_mac_addr_set(dev->port_id, &ea);
+    }
+    if (!err) {
+        dev->hwaddr = mac;
+    } else {
+        VLOG_WARN("%s: Failed to set requested mac("ETH_ADDR_FMT"): %s",
+                  netdev_get_name(&dev->up), ETH_ADDR_ARGS(mac),
+                  rte_strerror(err));
+    }
+
+    return err;
+}
+
 static int
 netdev_dpdk_set_etheraddr(struct netdev *netdev, const struct eth_addr mac)
 {
     struct netdev_dpdk *dev = netdev_dpdk_cast(netdev);
+    int err = 0;
 
     ovs_mutex_lock(&dev->mutex);
     if (!eth_addr_equals(dev->hwaddr, mac)) {
-        dev->hwaddr = mac;
-        netdev_change_seq_changed(netdev);
+        err = netdev_dpdk_set_etheraddr__(dev, mac);
+        if (!err) {
+            netdev_change_seq_changed(netdev);
+        }
     }
     ovs_mutex_unlock(&dev->mutex);
 
-    return 0;
+    return err;
 }
 
 static int