From: Huisong Li <lihuis...@huawei.com>

The dev->data->mac_addrs[0] will be changed to a new MAC address when
applications modify the default MAC address by
rte_eth_dev_default_mac_addr_set() API. However, If the new default
MAC address has been added as a non-default MAC address by
rte_eth_dev_mac_addr_add() API, the rte_eth_dev_default_mac_addr_set()
API doesn't remove it from dev->data->mac_addrs[]. As a result, one MAC
address occupies two index capacities in dev->data->mac_addrs[].

This patch adds the logic of removing MAC addresses for this scenario.

Fixes: 854d8ad4ef68 ("ethdev: add default mac address modifier")
Cc: sta...@dpdk.org

Signed-off-by: Huisong Li <lihuis...@huawei.com>
Signed-off-by: Min Hu (Connor) <humi...@huawei.com>
---
v2:
* fixed commit log.
---
 lib/ethdev/rte_ethdev.c | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/lib/ethdev/rte_ethdev.c b/lib/ethdev/rte_ethdev.c
index 028907bc4b..7faff17d9a 100644
--- a/lib/ethdev/rte_ethdev.c
+++ b/lib/ethdev/rte_ethdev.c
@@ -4340,6 +4340,7 @@ int
 rte_eth_dev_default_mac_addr_set(uint16_t port_id, struct rte_ether_addr *addr)
 {
        struct rte_eth_dev *dev;
+       int index;
        int ret;
 
        RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
@@ -4361,6 +4362,20 @@ rte_eth_dev_default_mac_addr_set(uint16_t port_id, 
struct rte_ether_addr *addr)
        if (ret < 0)
                return ret;
 
+       /*
+        * If the address has been added as a non-default MAC address by
+        * rte_eth_dev_mac_addr_add API, it should be removed from
+        * dev->data->mac_addrs[].
+        */
+       index = eth_dev_get_mac_addr_index(port_id, addr);
+       if (index > 0) {
+               /* remove address in NIC data structure */
+               rte_ether_addr_copy(&null_mac_addr,
+                                   &dev->data->mac_addrs[index]);
+               /* reset pool bitmap */
+               dev->data->mac_pool_sel[index] = 0;
+       }
+
        /* Update default address in NIC data structure */
        rte_ether_addr_copy(addr, &dev->data->mac_addrs[0]);
 
-- 
2.33.0

Reply via email to