@@ -387,7 +387,7 @@ static const struct bond_option bond_opts[BOND_OPT_LAST] = {
.id = BOND_OPT_SLAVES,
.name = "slaves",
.desc = "Slave membership management",
- .flags = BOND_OPTFLAG_RAWVAL,
+ .flags = BOND_OPTFLAG_RAWVAL | BOND_OPTFLAG_IFUP,
.set = bond_option_slaves_set
},
[BOND_OPT_TLB_DYNAMIC_LB] = {
@@ -583,6 +583,8 @@ static int bond_opt_check_deps(struct bonding *bond,
return -ENOTEMPTY;
if ((opt->flags & BOND_OPTFLAG_IFDOWN) && (bond->dev->flags & IFF_UP))
return -EBUSY;
+ if ((opt->flags & BOND_OPTFLAG_IFUP) && !(bond->dev->flags & IFF_UP))
+ return -EPERM;
return 0;
}
@@ -15,11 +15,13 @@
* BOND_OPTFLAG_NOSLAVES - check if the bond device is empty before setting
* BOND_OPTFLAG_IFDOWN - check if the bond device is down before setting
* BOND_OPTFLAG_RAWVAL - the option parses the value itself
+ * BOND_OPTFLAG_IFUP - check if the bond device is up before setting
*/
enum {
BOND_OPTFLAG_NOSLAVES = BIT(0),
BOND_OPTFLAG_IFDOWN = BIT(1),
- BOND_OPTFLAG_RAWVAL = BIT(2)
+ BOND_OPTFLAG_RAWVAL = BIT(2),
+ BOND_OPTFLAG_IFUP = BIT(3)
};
/* Value type flags:
We need to refuse to add slave devices to the bonding which does not set IFF_UP flag, otherwise some problems will be caused(such as bond_set_carrier() will not sync carrier state to upper net device). The ifenslave command can prevent such use case, but through the sysfs interface, slave devices can still be added regardless of whether the bonding is set with IFF_UP flag or not. So we introduce a new BOND_OPTFLAG_IFUP flag to avoid adding slave devices to inactive bonding. Signed-off-by: zhudi <zhudi21@huawei.com> --- drivers/net/bonding/bond_options.c | 4 +++- include/net/bond_options.h | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-)