From: Ido Schimmel <idosch@nvidia.com>
To: netdev@vger.kernel.org
Cc: davem@davemloft.net, kuba@kernel.org, pabeni@redhat.com,
edumazet@google.com, horms@kernel.org, petrm@nvidia.com,
Ido Schimmel <idosch@nvidia.com>
Subject: [PATCH net-next v2 2/3] net: Do not unconditionally turn on carrier when turning off protodown
Date: Tue, 5 May 2026 11:16:54 +0300 [thread overview]
Message-ID: <20260505081656.463158-3-idosch@nvidia.com> (raw)
In-Reply-To: <20260505081656.463158-1-idosch@nvidia.com>
The protodown functionality allows user space to turn off the carrier of
a net device:
# ip link add name dummy1 up type dummy
# ip link add name macvlan1 up link dummy1 type macvlan mode bridge
# ip link set dev macvlan1 protodown on
$ ip -br link show dev macvlan1
macvlan1@dummy1 DOWN 0a:5c:a3:05:c7:86 <NO-CARRIER,BROADCAST,MULTICAST,UP>
When protodown is turned off, the core unconditionally turns on the
carrier of the net device:
# ip link set dev macvlan1 protodown off
$ ip -br link show dev macvlan1
macvlan1@dummy1 UP 0a:5c:a3:05:c7:86 <BROADCAST,MULTICAST,UP,LOWER_UP>
This is wrong as it means that a macvlan can end up with a carrier when
its lower device does not have a carrier:
# ip link set dev dummy1 carrier off
$ ip -br link show dev macvlan1
macvlan1@dummy1 LOWERLAYERDOWN 0a:5c:a3:05:c7:86 <NO-CARRIER,BROADCAST,MULTICAST,UP>
# ip link set dev macvlan1 protodown on
# ip link set dev macvlan1 protodown off
$ ip -br link show dev macvlan1
macvlan1@dummy1 UP 0a:5c:a3:05:c7:86 <BROADCAST,MULTICAST,UP,LOWER_UP>
Solve this by resolving the linked net device and if one exists, inherit
its operational state when protodown is turned off. Otherwise, as
before, simply turn on the carrier. Set 'dev->proto_down' before calling
netif_stacked_transfer_operstate() as this function is a NOP when
protodown is turned on.
Resolve the linked net device using a new helper and have it return the
device itself (in a similar fashion to dev_get_iflink()) if the device
does not implement both ndo_get_iflink() and get_link_net(). If the
latter is not implemented, it is unclear in which network namespace we
should look up the linked net device. Currently, this helper is only
used for net devices that support protodown (macvlan and vxlan) and for
both it returns the correct result.
Output with the patch:
# ip link add name dummy1 up type dummy
# ip link add name macvlan1 up link dummy1 type macvlan mode bridge
# ip link set dev dummy1 carrier off
$ ip -br link show dev macvlan1
macvlan1@dummy1 LOWERLAYERDOWN 0a:5c:a3:05:c7:86 <NO-CARRIER,BROADCAST,MULTICAST,UP>
# ip link set dev macvlan1 protodown on
# ip link set dev macvlan1 protodown off
$ ip -br link show dev macvlan1
macvlan1@dummy1 LOWERLAYERDOWN 0a:5c:a3:05:c7:86 <NO-CARRIER,BROADCAST,MULTICAST,UP>
# ip link set dev dummy1 carrier on
$ ip -br link show dev macvlan1
macvlan1@dummy1 UP 0a:5c:a3:05:c7:86 <BROADCAST,MULTICAST,UP,LOWER_UP>
# ip link set dev macvlan1 protodown on
# ip link set dev macvlan1 protodown off
$ ip -br link show dev macvlan1
macvlan1@dummy1 UP 0a:5c:a3:05:c7:86 <BROADCAST,MULTICAST,UP,LOWER_UP>
Signed-off-by: Ido Schimmel <idosch@nvidia.com>
---
net/core/dev.c | 25 +++++++++++++++++++++++--
1 file changed, 23 insertions(+), 2 deletions(-)
diff --git a/net/core/dev.c b/net/core/dev.c
index bfb0f297b234..46f8a2efd982 100644
--- a/net/core/dev.c
+++ b/net/core/dev.c
@@ -10141,17 +10141,38 @@ bool netdev_port_same_parent_id(struct net_device *a, struct net_device *b)
}
EXPORT_SYMBOL(netdev_port_same_parent_id);
+static struct net_device *dev_get_iflink_dev(struct net_device *dev)
+{
+ struct net *net;
+
+ ASSERT_RTNL();
+
+ if (!dev->netdev_ops->ndo_get_iflink || !dev->rtnl_link_ops ||
+ !dev->rtnl_link_ops->get_link_net)
+ return dev;
+
+ net = dev->rtnl_link_ops->get_link_net(dev);
+ return __dev_get_by_index(net, dev_get_iflink(dev));
+}
+
int netif_change_proto_down(struct net_device *dev, bool proto_down)
{
+ struct net_device *iflink_dev;
+
if (!dev->change_proto_down)
return -EOPNOTSUPP;
if (!netif_device_present(dev))
return -ENODEV;
+ iflink_dev = dev_get_iflink_dev(dev);
+ if (!iflink_dev)
+ return -ENODEV;
+ WRITE_ONCE(dev->proto_down, proto_down);
if (proto_down)
netif_carrier_off(dev);
- else
+ else if (dev == iflink_dev)
netif_carrier_on(dev);
- WRITE_ONCE(dev->proto_down, proto_down);
+ else
+ netif_stacked_transfer_operstate(iflink_dev, dev);
return 0;
}
--
2.54.0
next prev parent reply other threads:[~2026-05-05 8:17 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-05 8:16 [PATCH net-next v2 0/3] net: Fix protodown with macvlan Ido Schimmel
2026-05-05 8:16 ` [PATCH net-next v2 1/3] net: Do not inherit operational state when protodown is on Ido Schimmel
2026-05-05 8:16 ` Ido Schimmel [this message]
2026-05-05 8:16 ` [PATCH net-next v2 3/3] selftests: net: Add protodown tests Ido Schimmel
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260505081656.463158-3-idosch@nvidia.com \
--to=idosch@nvidia.com \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=horms@kernel.org \
--cc=kuba@kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=petrm@nvidia.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox