diff mbox series

[net] rtnetlink: allow to set iface down before enslaving it

Message ID 20231229100835.3996906-1-nicolas.dichtel@6wind.com (mailing list archive)
State Changes Requested
Delegated to: Netdev Maintainers
Headers show
Series [net] rtnetlink: allow to set iface down before enslaving it | expand

Checks

Context Check Description
netdev/series_format success Single patches do not need cover letters
netdev/tree_selection success Clearly marked for net
netdev/ynl success SINGLE THREAD; Generated files up to date; no warnings/errors; no diff in generated;
netdev/fixes_present success Fixes tag present in non-next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 1115 this patch: 1115
netdev/cc_maintainers warning 2 maintainers not CCed: idosch@nvidia.com lucien.xin@gmail.com
netdev/build_clang success Errors and warnings before: 1141 this patch: 1141
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success Fixes tag looks correct
netdev/build_allmodconfig_warn success Errors and warnings before: 1142 this patch: 1142
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 14 lines checked
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Nicolas Dichtel Dec. 29, 2023, 10:08 a.m. UTC
The below commit adds support for:
> ip link set dummy0 down
> ip link set dummy0 master bond0 up

but breaks the opposite:
> ip link set dummy0 up
> ip link set dummy0 master bond0 down

Let's add a workaround to have both commands working.

Cc: stable@vger.kernel.org
Fixes: a4abfa627c38 ("net: rtnetlink: Enslave device before bringing it up")
Signed-off-by: Nicolas Dichtel <nicolas.dichtel@6wind.com>
---
 net/core/rtnetlink.c | 8 ++++++++
 1 file changed, 8 insertions(+)

Comments

David Ahern Dec. 31, 2023, 4:36 p.m. UTC | #1
On 12/29/23 5:08 AM, Nicolas Dichtel wrote:
> The below commit adds support for:
>> ip link set dummy0 down
>> ip link set dummy0 master bond0 up
> 
> but breaks the opposite:
>> ip link set dummy0 up
>> ip link set dummy0 master bond0 down
> 
> Let's add a workaround to have both commands working.
> 
> Cc: stable@vger.kernel.org
> Fixes: a4abfa627c38 ("net: rtnetlink: Enslave device before bringing it up")
> Signed-off-by: Nicolas Dichtel <nicolas.dichtel@6wind.com>
> ---
>  net/core/rtnetlink.c | 8 ++++++++
>  1 file changed, 8 insertions(+)
> 

add tests to tools/testing/selftests/net/rtnetlink.sh
Phil Sutter Jan. 1, 2024, 10:10 p.m. UTC | #2
On Fri, Dec 29, 2023 at 11:08:35AM +0100, Nicolas Dichtel wrote:
> The below commit adds support for:
> > ip link set dummy0 down
> > ip link set dummy0 master bond0 up
> 
> but breaks the opposite:
> > ip link set dummy0 up
> > ip link set dummy0 master bond0 down
> 
> Let's add a workaround to have both commands working.
> 
> Cc: stable@vger.kernel.org
> Fixes: a4abfa627c38 ("net: rtnetlink: Enslave device before bringing it up")
> Signed-off-by: Nicolas Dichtel <nicolas.dichtel@6wind.com>
> ---
>  net/core/rtnetlink.c | 8 ++++++++
>  1 file changed, 8 insertions(+)
> 
> diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
> index e8431c6c8490..dd79693c2d91 100644
> --- a/net/core/rtnetlink.c
> +++ b/net/core/rtnetlink.c
> @@ -2905,6 +2905,14 @@ static int do_setlink(const struct sk_buff *skb,
>  		call_netdevice_notifiers(NETDEV_CHANGEADDR, dev);
>  	}
>  
> +	/* Backward compat: enable to set interface down before enslaving it */
> +	if (!(ifm->ifi_flags & IFF_UP) && ifm->ifi_change & IFF_UP) {
> +		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)

Doesn't this merely revert to the old behaviour of setting the interface
up before enslaving if both IFF_UP and IFLA_MASTER are present? Did you
test this with a bond-type master?

Cheers, Phil
Nicolas Dichtel Jan. 2, 2024, 12:14 p.m. UTC | #3
Le 01/01/2024 à 23:10, Phil Sutter a écrit :
> On Fri, Dec 29, 2023 at 11:08:35AM +0100, Nicolas Dichtel wrote:
>> The below commit adds support for:
>>> ip link set dummy0 down
>>> ip link set dummy0 master bond0 up
>>
>> but breaks the opposite:
>>> ip link set dummy0 up
>>> ip link set dummy0 master bond0 down
>>
>> Let's add a workaround to have both commands working.
>>
>> Cc: stable@vger.kernel.org
>> Fixes: a4abfa627c38 ("net: rtnetlink: Enslave device before bringing it up")
>> Signed-off-by: Nicolas Dichtel <nicolas.dichtel@6wind.com>
>> ---
>>  net/core/rtnetlink.c | 8 ++++++++
>>  1 file changed, 8 insertions(+)
>>
>> diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
>> index e8431c6c8490..dd79693c2d91 100644
>> --- a/net/core/rtnetlink.c
>> +++ b/net/core/rtnetlink.c
>> @@ -2905,6 +2905,14 @@ static int do_setlink(const struct sk_buff *skb,
>>  		call_netdevice_notifiers(NETDEV_CHANGEADDR, dev);
>>  	}
>>  
>> +	/* Backward compat: enable to set interface down before enslaving it */
>> +	if (!(ifm->ifi_flags & IFF_UP) && ifm->ifi_change & IFF_UP) {
>> +		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)
> 
> Doesn't this merely revert to the old behaviour of setting the interface
> up before enslaving if both IFF_UP and IFLA_MASTER are present? Did you
> test this with a bond-type master?
Yes, both command sequences (cf commit log) work after the patch.
dev_change_flags() is called before do_set_master() only if the user asks to
remove the flag IFF_UP.


Regards,
Nicolas
Nicolas Dichtel Jan. 2, 2024, 12:14 p.m. UTC | #4
Le 31/12/2023 à 17:36, David Ahern a écrit :
> On 12/29/23 5:08 AM, Nicolas Dichtel wrote:
>> The below commit adds support for:
>>> ip link set dummy0 down
>>> ip link set dummy0 master bond0 up
>>
>> but breaks the opposite:
>>> ip link set dummy0 up
>>> ip link set dummy0 master bond0 down
>>
>> Let's add a workaround to have both commands working.
>>
>> Cc: stable@vger.kernel.org
>> Fixes: a4abfa627c38 ("net: rtnetlink: Enslave device before bringing it up")
>> Signed-off-by: Nicolas Dichtel <nicolas.dichtel@6wind.com>
>> ---
>>  net/core/rtnetlink.c | 8 ++++++++
>>  1 file changed, 8 insertions(+)
>>
> 
> add tests to tools/testing/selftests/net/rtnetlink.sh
> 
Will do.


Thanks,
Nicolas
Phil Sutter Jan. 2, 2024, 10:03 p.m. UTC | #5
On Tue, Jan 02, 2024 at 01:14:21PM +0100, Nicolas Dichtel wrote:
> Le 01/01/2024 à 23:10, Phil Sutter a écrit :
> > On Fri, Dec 29, 2023 at 11:08:35AM +0100, Nicolas Dichtel wrote:
> >> The below commit adds support for:
> >>> ip link set dummy0 down
> >>> ip link set dummy0 master bond0 up
> >>
> >> but breaks the opposite:
> >>> ip link set dummy0 up
> >>> ip link set dummy0 master bond0 down
> >>
> >> Let's add a workaround to have both commands working.
> >>
> >> Cc: stable@vger.kernel.org
> >> Fixes: a4abfa627c38 ("net: rtnetlink: Enslave device before bringing it up")
> >> Signed-off-by: Nicolas Dichtel <nicolas.dichtel@6wind.com>
> >> ---
> >>  net/core/rtnetlink.c | 8 ++++++++
> >>  1 file changed, 8 insertions(+)
> >>
> >> diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
> >> index e8431c6c8490..dd79693c2d91 100644
> >> --- a/net/core/rtnetlink.c
> >> +++ b/net/core/rtnetlink.c
> >> @@ -2905,6 +2905,14 @@ static int do_setlink(const struct sk_buff *skb,
> >>  		call_netdevice_notifiers(NETDEV_CHANGEADDR, dev);
> >>  	}
> >>  
> >> +	/* Backward compat: enable to set interface down before enslaving it */
> >> +	if (!(ifm->ifi_flags & IFF_UP) && ifm->ifi_change & IFF_UP) {
> >> +		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)
> > 
> > Doesn't this merely revert to the old behaviour of setting the interface
> > up before enslaving if both IFF_UP and IFLA_MASTER are present? Did you
> > test this with a bond-type master?
> Yes, both command sequences (cf commit log) work after the patch.
> dev_change_flags() is called before do_set_master() only if the user asks to
> remove the flag IFF_UP.

Ah, indeed! I should have looked at rtnl_dev_combine_flags() before
commenting. When submitting v2, feel free to add my:

Acked-by: Phil Sutter <phil@nwl.cc>

Thanks, Phil
diff mbox series

Patch

diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
index e8431c6c8490..dd79693c2d91 100644
--- a/net/core/rtnetlink.c
+++ b/net/core/rtnetlink.c
@@ -2905,6 +2905,14 @@  static int do_setlink(const struct sk_buff *skb,
 		call_netdevice_notifiers(NETDEV_CHANGEADDR, dev);
 	}
 
+	/* Backward compat: enable to set interface down before enslaving it */
+	if (!(ifm->ifi_flags & IFF_UP) && ifm->ifi_change & IFF_UP) {
+		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)