Skip to contentSkip to conversation

net: rtnetlink: Enslave device before bringing it up

PATCH In review Phil Sutter 3 participants 5 messages May 29, 2019 – Jun 2, 2019

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 net: rtnetlink: Enslave device before bringing it up

Unlike with bridges, one can't add an interface to a bond and set it up at the same time:

| # ip link set dummy0 down
| # ip link set dummy0 master bond0 up
| Error: Device can not be enslaved while up.

Of all drivers with ndo_add_slave callback, bond and team decline if IFF_UP flag is set, vrf cycles the interface (i.e., sets it down and immediately up again) and the others just don't care.

Support the common notion of setting the interface up after enslaving it by sorting the operations accordingly.

---
 net/core/rtnetlink.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)
net/core/rtnetlink.c +7 -7
index adcc045952c2f..d81acace02ce5 100644
@@ -2488,13 +2488,6 @@ static int do_setlink(const struct sk_buff *skb,
 		call_netdevice_notifiers(NETDEV_CHANGEADDR, dev);
 	}
 
-	if (ifm->ifi_flags || ifm->ifi_change) {
-		err = dev_change_flags(dev, rtnl_dev_combine_flags(dev, ifm),
-				       extack);
-		if (err < 0)
-			goto errout;
-	}
-
 	if (tb[IFLA_MASTER]) {
 		err = do_set_master(dev, nla_get_u32(tb[IFLA_MASTER]), extack);
 		if (err)
@@ -2502,6 +2495,13 @@ static int do_setlink(const struct sk_buff *skb,
 		status |= DO_SETLINK_MODIFIED;
 	}
 
+	if (ifm->ifi_flags || ifm->ifi_change) {
+		err = dev_change_flags(dev, rtnl_dev_combine_flags(dev, ifm),
+				       extack);
+		if (err < 0)
+			goto errout;
+	}
+
 	if (tb[IFLA_CARRIER]) {
 		err = dev_change_carrier(dev, nla_get_u8(tb[IFLA_CARRIER]));
 		if (err)
Signature · 1 line
2.21.0
#1 lore raw
Quoted 11 lines · Phil Sutter

Unlike with bridges, one can't add an interface to a bond and set it up at the same time:

| # ip link set dummy0 down
| # ip link set dummy0 master bond0 up
| Error: Device can not be enslaved while up.

Of all drivers with ndo_add_slave callback, bond and team decline if IFF_UP flag is set, vrf cycles the interface (i.e., sets it down and immediately up again) and the others just don't care.

Quoted 8 lines

Support the common notion of setting the interface up after enslaving it by sorting the operations accordingly.

---
 net/core/rtnetlink.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

I agree with the intent - enslave before up.

Not sure how likely this is, but it does break the case:
ip li set dummy0 master bond0 down

#2 lore raw
Quoted 21 lines · David Ahern
Quoted 11 lines · Phil Sutter

Unlike with bridges, one can't add an interface to a bond and set it up at the same time:

| # ip link set dummy0 down
| # ip link set dummy0 master bond0 up
| Error: Device can not be enslaved while up.

Of all drivers with ndo_add_slave callback, bond and team decline if IFF_UP flag is set, vrf cycles the interface (i.e., sets it down and immediately up again) and the others just don't care.

Quoted 8 lines

Support the common notion of setting the interface up after enslaving it by sorting the operations accordingly.

---
 net/core/rtnetlink.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)
Quoted 4 lines

I agree with the intent - enslave before up.

Not sure how likely this is, but it does break the case:
ip li set dummy0 master bond0 down

That's right. I could allow for that by ordering the enslave and state change dynamically, but doubt it's worth the effort. Instead of the above I'd rather expect 'ip l s d0 nomaster down' to be a more common use-case (which is not affected by my patch).

Thanks, Phil

maintainer
#3 lore raw
In reply to Phil Sutter

From: Phil Sutter <[email protected]>
Date: Wed, 29 May 2019 15:51:20 +0200

Quoted 7 lines

Unlike with bridges, one can't add an interface to a bond and set it up at the same time:

| # ip link set dummy0 down
| # ip link set dummy0 master bond0 up
| Error: Device can not be enslaved while up.
Quoted 8 lines

Of all drivers with ndo_add_slave callback, bond and team decline if IFF_UP flag is set, vrf cycles the interface (i.e., sets it down and immediately up again) and the others just don't care.

Support the common notion of setting the interface up after enslaving it by sorting the operations accordingly.

What about other flags like IFF_PROMISCUITY?

#4 lore raw

Hi David,

Quoted 14 lines · David Miller

From: Phil Sutter <[email protected]>
Date: Wed, 29 May 2019 15:51:20 +0200

Quoted 11 lines

Unlike with bridges, one can't add an interface to a bond and set it up at the same time:

| # ip link set dummy0 down
| # ip link set dummy0 master bond0 up
| Error: Device can not be enslaved while up.

Of all drivers with ndo_add_slave callback, bond and team decline if IFF_UP flag is set, vrf cycles the interface (i.e., sets it down and immediately up again) and the others just don't care.

Quoted 6 lines
Quoted 4 lines

Support the common notion of setting the interface up after enslaving it by sorting the operations accordingly.

What about other flags like IFF_PROMISCUITY?

Crap, that's the crux: Upon enslaving, team driver propagates IFF_PROMISC and IFF_ALLMULTI flags from master to slave. With my change, these propagations roll back by accident. So please disregard this patch, I'll have to find a different solution.

Thanks, Phil