[ovs-dev] [PATCH v3 1/2] netdev-dpdk: Add ability to set MAC address.

Gaetan Rivet grive at u256.net
Wed Sep 16 15:17:33 UTC 2020


From: Ilya Maximets <i.maximets at ovn.org>

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 at ovn.org>
Signed-off-by: Gaetan Rivet <grive at u256.net>
---
 lib/netdev-dpdk.c | 32 +++++++++++++++++++++++++++++---
 1 file changed, 29 insertions(+), 3 deletions(-)

diff --git a/lib/netdev-dpdk.c b/lib/netdev-dpdk.c
index 18c4adcc7..4ef7f78a6 100644
--- a/lib/netdev-dpdk.c
+++ b/lib/netdev-dpdk.c
@@ -2909,19 +2909,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
-- 
2.28.0



More information about the dev mailing list