linux-kselftest.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
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 2/3] macvlan: fix NETDEV_UP/NETDEV_DOWN event handling
Date: Thu,  3 Apr 2025 08:58:56 +0000	[thread overview]
Message-ID: <20250403085857.17868-3-liuhangbin@gmail.com> (raw)
In-Reply-To: <20250403085857.17868-1-liuhangbin@gmail.com>

Setting the link down does not necessarily change the carrier state for
virtual interfaces like bonding. Therefore, handling the device up/down
event via netif_stacked_transfer_operstate() is not sufficient.

If the lower link and macvlan are in different namespaces, the upper link
state may become out of sync. Fix this by updating the handling logic to be
similar to VLAN.

Fixes: de7d244d0a35 ("macvlan: make operstate and carrier more accurate")
Fixes: 80fd2d6ca546 ("macvlan: Change status when lower device goes down")
Signed-off-by: Hangbin Liu <liuhangbin@gmail.com>
---
 drivers/net/macvlan.c | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

diff --git a/drivers/net/macvlan.c b/drivers/net/macvlan.c
index d0dfa6bca6cc..f254cda14dac 100644
--- a/drivers/net/macvlan.c
+++ b/drivers/net/macvlan.c
@@ -1781,10 +1781,12 @@ static void update_port_bc_queue_len(struct macvlan_port *port)
 static int macvlan_device_event(struct notifier_block *unused,
 				unsigned long event, void *ptr)
 {
+	struct netlink_ext_ack *extack = netdev_notifier_info_to_extack(ptr);
 	struct net_device *dev = netdev_notifier_info_to_dev(ptr);
 	struct macvlan_dev *vlan, *next;
 	struct macvlan_port *port;
 	LIST_HEAD(list_kill);
+	int flags;
 
 	if (!netif_is_macvlan_port(dev))
 		return NOTIFY_DONE;
@@ -1793,7 +1795,25 @@ static int macvlan_device_event(struct notifier_block *unused,
 
 	switch (event) {
 	case NETDEV_UP:
+		list_for_each_entry(vlan, &port->vlans, list) {
+			flags = vlan->dev->flags;
+			if (flags & IFF_UP)
+				continue;
+			dev_change_flags(vlan->dev, flags | IFF_UP, extack);
+			netif_stacked_transfer_operstate(vlan->lowerdev,
+							 vlan->dev);
+		}
+		break;
 	case NETDEV_DOWN:
+		list_for_each_entry(vlan, &port->vlans, list) {
+			flags = vlan->dev->flags;
+			if (!(flags & IFF_UP))
+				continue;
+			dev_close(vlan->dev);
+			netif_stacked_transfer_operstate(vlan->lowerdev,
+							 vlan->dev);
+		}
+		break;
 	case NETDEV_CHANGE:
 		list_for_each_entry(vlan, &port->vlans, list)
 			netif_stacked_transfer_operstate(vlan->lowerdev,
-- 
2.46.0


  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 ` [PATCH net 1/3] ipvlan: fix NETDEV_UP/NETDEV_DOWN event handling Hangbin Liu
2025-04-03 10:28   ` 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 ` Hangbin Liu [this message]
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-3-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).