From 1184582b5f80b2915d45e4015fb4e762954119e3 Mon Sep 17 00:00:00 2001 From: Jacek Piasecki Date: Tue, 8 Aug 2017 14:56:43 +0200 Subject: [PATCH] net/bonding: fix bonding in 8023ad mode This patch blocks possibility to set master bonding by rte_eth_bond_mode_set() in 802.3ad mode, as the API doesn't prevent this. Fixes: 6d72657ce379 ("net/bonding: add other aggregator modes") Cc: stable@dpdk.org Signed-off-by: Jacek Piasecki Reviewed-by: Radu Nicolau --- drivers/net/bonding/rte_eth_bond_api.c | 29 +++++++++++++++++++++- drivers/net/bonding/rte_eth_bond_private.h | 3 +++ 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/drivers/net/bonding/rte_eth_bond_api.c b/drivers/net/bonding/rte_eth_bond_api.c index f42d318158..5777c1172b 100644 --- a/drivers/net/bonding/rte_eth_bond_api.c +++ b/drivers/net/bonding/rte_eth_bond_api.c @@ -33,6 +33,25 @@ valid_bonded_port_id(uint16_t port_id) return check_for_bonded_ethdev(&rte_eth_devices[port_id]); } +int +check_for_master_bonded_ethdev(const struct rte_eth_dev *eth_dev) +{ + int i; + struct bond_dev_private *internals; + + if (check_for_bonded_ethdev(eth_dev) != 0) + return 0; + + internals = eth_dev->data->dev_private; + + /* Check if any of slave devices is a bonded device */ + for (i = 0; i < internals->slave_count; i++) + if (valid_bonded_port_id(internals->slaves[i].port_id) == 0) + return 1; + + return 0; +} + int valid_slave_port_id(uint16_t port_id, uint8_t mode) { @@ -467,10 +486,18 @@ rte_eth_bond_slave_remove(uint16_t bonded_port_id, uint16_t slave_port_id) int rte_eth_bond_mode_set(uint16_t bonded_port_id, uint8_t mode) { + struct rte_eth_dev *bonded_eth_dev; + if (valid_bonded_port_id(bonded_port_id) != 0) return -1; - return bond_ethdev_mode_set(&rte_eth_devices[bonded_port_id], mode); + bonded_eth_dev = &rte_eth_devices[bonded_port_id]; + + if (check_for_master_bonded_ethdev(bonded_eth_dev) != 0 && + mode == BONDING_MODE_8023AD) + return -1; + + return bond_ethdev_mode_set(bonded_eth_dev, mode); } int diff --git a/drivers/net/bonding/rte_eth_bond_private.h b/drivers/net/bonding/rte_eth_bond_private.h index 3bade02acc..3b323113ac 100644 --- a/drivers/net/bonding/rte_eth_bond_private.h +++ b/drivers/net/bonding/rte_eth_bond_private.h @@ -153,6 +153,9 @@ struct bond_dev_private { extern const struct eth_dev_ops default_dev_ops; +int +check_for_master_bonded_ethdev(const struct rte_eth_dev *eth_dev); + int check_for_bonded_ethdev(const struct rte_eth_dev *eth_dev); -- 2.20.1