From: Hangbin Liu <liuhangbin@gmail.com>
To: netdev@vger.kernel.org
Cc: Andrew Lunn <andrew+netdev@lunn.ch>,
"David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@google.com>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
Simon Horman <horms@kernel.org>, Shuah Khan <shuah@kernel.org>,
Xiao Liang <shaw.leon@gmail.com>,
Kuniyuki Iwashima <kuniyu@amazon.com>,
Alexander Lobakin <aleksander.lobakin@intel.com>,
Stanislav Fomichev <sdf@fomichev.me>,
Venkat Venkatsubra <venkat.x.venkatsubra@oracle.com>,
Etienne Champetier <champetier.etienne@gmail.com>,
Di Zhu <zhudi21@huawei.com>,
Nikolay Aleksandrov <razor@blackwall.org>,
Travis Brown <travisb@arista.com>,
Suresh Krishnan <skrishnan@arista.com>,
linux-kselftest@vger.kernel.org,
Hangbin Liu <liuhangbin@gmail.com>
Subject: [PATCH net 1/3] ipvlan: fix NETDEV_UP/NETDEV_DOWN event handling
Date: Thu, 3 Apr 2025 08:58:55 +0000 [thread overview]
Message-ID: <20250403085857.17868-2-liuhangbin@gmail.com> (raw)
In-Reply-To: <20250403085857.17868-1-liuhangbin@gmail.com>
When setting the lower-layer link up/down, the ipvlan device synchronizes
its state via netif_stacked_transfer_operstate(), which only checks the
carrier state. However, setting the link down does not necessarily change
the carrier state for virtual interfaces like bonding. This causes the
ipvlan state to become out of sync with the lower-layer link state.
If the lower link and ipvlan are in the same namespace, this issue is
hidden because ip link show checks the link state in IFLA_LINK and has
a m_flag to control the state, displaying M-DOWN in the flags. However,
if the ipvlan and the lower link are in different namespaces, this
information is not available, and the ipvlan link state remains unchanged.
For example:
1. Add an ipvlan over bond0.
2. Move the ipvlan to a separate namespace and bring it up.
3. Set bond0 link down.
4. The ipvlan remains up.
This issue affects containers and pods, causing them to display an
incorrect link state for ipvlan. Fix this by explicitly changing the
IFF_UP flag, similar to how VLAN handles it.
Fixes: 57fb346cc7d0 ("ipvlan: Add handling of NETDEV_UP events")
Fixes: 229783970838 ("ipvlan: handle NETDEV_DOWN event")
Signed-off-by: Hangbin Liu <liuhangbin@gmail.com>
---
drivers/net/ipvlan/ipvlan_main.c | 20 +++++++++++++++++++-
1 file changed, 19 insertions(+), 1 deletion(-)
diff --git a/drivers/net/ipvlan/ipvlan_main.c b/drivers/net/ipvlan/ipvlan_main.c
index 0ed2fd833a5d..2abe6ddc4d15 100644
--- a/drivers/net/ipvlan/ipvlan_main.c
+++ b/drivers/net/ipvlan/ipvlan_main.c
@@ -730,7 +730,7 @@ static int ipvlan_device_event(struct notifier_block *unused,
struct ipvl_dev *ipvlan, *next;
struct ipvl_port *port;
LIST_HEAD(lst_kill);
- int err;
+ int flags, err;
if (!netif_is_ipvlan_port(dev))
return NOTIFY_DONE;
@@ -739,7 +739,25 @@ static int ipvlan_device_event(struct notifier_block *unused,
switch (event) {
case NETDEV_UP:
+ list_for_each_entry(ipvlan, &port->ipvlans, pnode) {
+ flags = ipvlan->dev->flags;
+ if (flags & IFF_UP)
+ continue;
+ dev_change_flags(ipvlan->dev, flags | IFF_UP, extack);
+ netif_stacked_transfer_operstate(ipvlan->phy_dev,
+ ipvlan->dev);
+ }
+ break;
case NETDEV_DOWN:
+ list_for_each_entry(ipvlan, &port->ipvlans, pnode) {
+ flags = ipvlan->dev->flags;
+ if (!(flags & IFF_UP))
+ continue;
+ dev_close(ipvlan->dev);
+ netif_stacked_transfer_operstate(ipvlan->phy_dev,
+ ipvlan->dev);
+ }
+ break;
case NETDEV_CHANGE:
list_for_each_entry(ipvlan, &port->ipvlans, pnode)
netif_stacked_transfer_operstate(ipvlan->phy_dev,
--
2.46.0
next prev parent reply other threads:[~2025-04-03 8:59 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-04-03 8:58 [PATCH net 0/3] fix ipvlan/macvlan link event handing Hangbin Liu
2025-04-03 8:58 ` Hangbin Liu [this message]
2025-04-03 10:28 ` [PATCH net 1/3] ipvlan: fix NETDEV_UP/NETDEV_DOWN event handling Sabrina Dubroca
2025-04-03 13:09 ` Hangbin Liu
2025-04-03 15:00 ` Sabrina Dubroca
2025-04-14 7:02 ` Hangbin Liu
2025-04-03 8:58 ` [PATCH net 2/3] macvlan: " Hangbin Liu
2025-04-03 8:58 ` [PATCH net 3/3] selftests/rtnetlink.sh: add vlan/ipvlan/macvlan link state test Hangbin Liu
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=20250403085857.17868-2-liuhangbin@gmail.com \
--to=liuhangbin@gmail.com \
--cc=aleksander.lobakin@intel.com \
--cc=andrew+netdev@lunn.ch \
--cc=champetier.etienne@gmail.com \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=horms@kernel.org \
--cc=kuba@kernel.org \
--cc=kuniyu@amazon.com \
--cc=linux-kselftest@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=razor@blackwall.org \
--cc=sdf@fomichev.me \
--cc=shaw.leon@gmail.com \
--cc=shuah@kernel.org \
--cc=skrishnan@arista.com \
--cc=travisb@arista.com \
--cc=venkat.x.venkatsubra@oracle.com \
--cc=zhudi21@huawei.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;
as well as URLs for NNTP newsgroup(s).