* [PATCH v3] leds: trigger: netdev: refactor dev matching in netdev_trig_notify()
@ 2025-04-25 13:20 Tobias Junghans
2025-04-29 18:50 ` Jakub Kicinski
0 siblings, 1 reply; 2+ messages in thread
From: Tobias Junghans @ 2025-04-25 13:20 UTC (permalink / raw)
To: Lee Jones, Andrew Lunn, linux-leds, netdev; +Cc: Tobias Junghans
If there are network devices with the same name in different
namespaces, ledtrig-netdev gets confused easily and switches between
these devices whenever there are NETDEV_CHANGENAME/NETDEV_REGISTER
notifications. This happens since ledtrig-netdev only checks for
device name equality regardless of previous associations with another
network device with the same name.
Real world example: eth0 is the primary physical network interface and
ledltrig-netdev is associated with that interface. If now Docker creates
a virtual Ethernet interface (vethXXXX), moves it to the
container's net namespace and renames it to eth0, ledtrig-netdev
switches to this device and the LED no longer blinks for the original
(physical) network device.
Fix this by refactoring the conditions under which to return early with
NOTIFY_DONE inside netdev_trig_notify():
- For processing NETDEV_REGISTER events, the device name has to match
and no association with a net_dev must exist.
- For processing NETDEV_CHANGENAME events, the associated and notified
network device have to match. Alternatively the device name has to
match and no association with a net_dev must exist.
- For all other events, the associated and notified network device have
to match.
Signed-off-by: Tobias Junghans <tobias.junghans@inhub.de>
---
drivers/leds/trigger/ledtrig-netdev.c | 29 +++++++++++++++++++--------
1 file changed, 21 insertions(+), 8 deletions(-)
diff --git a/drivers/leds/trigger/ledtrig-netdev.c b/drivers/leds/trigger/ledtrig-netdev.c
index 4b0863db901a..75d8c8fe9afc 100644
--- a/drivers/leds/trigger/ledtrig-netdev.c
+++ b/drivers/leds/trigger/ledtrig-netdev.c
@@ -574,15 +574,28 @@ static int netdev_trig_notify(struct notifier_block *nb,
container_of(nb, struct led_netdev_data, notifier);
struct led_classdev *led_cdev = trigger_data->led_cdev;
- if (evt != NETDEV_UP && evt != NETDEV_DOWN && evt != NETDEV_CHANGE
- && evt != NETDEV_REGISTER && evt != NETDEV_UNREGISTER
- && evt != NETDEV_CHANGENAME)
- return NOTIFY_DONE;
-
- if (!(dev == trigger_data->net_dev ||
- (evt == NETDEV_CHANGENAME && !strcmp(dev->name, trigger_data->device_name)) ||
- (evt == NETDEV_REGISTER && !strcmp(dev->name, trigger_data->device_name))))
+ switch (evt) {
+ case NETDEV_REGISTER:
+ if (trigger_data->net_dev ||
+ strcmp(dev->name, trigger_data->device_name))
+ return NOTIFY_DONE;
+ break;
+ case NETDEV_CHANGENAME:
+ if (trigger_data->net_dev != dev &&
+ (trigger_data->net_dev ||
+ strcmp(dev->name, trigger_data->device_name)))
+ return NOTIFY_DONE;
+ break;
+ case NETDEV_UNREGISTER:
+ case NETDEV_UP:
+ case NETDEV_DOWN:
+ case NETDEV_CHANGE:
+ if (trigger_data->net_dev != dev)
+ return NOTIFY_DONE;
+ break;
+ default:
return NOTIFY_DONE;
+ }
cancel_delayed_work_sync(&trigger_data->work);
--
2.43.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH v3] leds: trigger: netdev: refactor dev matching in netdev_trig_notify()
2025-04-25 13:20 [PATCH v3] leds: trigger: netdev: refactor dev matching in netdev_trig_notify() Tobias Junghans
@ 2025-04-29 18:50 ` Jakub Kicinski
0 siblings, 0 replies; 2+ messages in thread
From: Jakub Kicinski @ 2025-04-29 18:50 UTC (permalink / raw)
To: Tobias Junghans; +Cc: Lee Jones, Andrew Lunn, linux-leds, netdev
On Fri, 25 Apr 2025 15:20:45 +0200 Tobias Junghans wrote:
> If there are network devices with the same name in different
> namespaces, ledtrig-netdev gets confused easily and switches between
> these devices whenever there are NETDEV_CHANGENAME/NETDEV_REGISTER
> notifications. This happens since ledtrig-netdev only checks for
> device name equality regardless of previous associations with another
> network device with the same name.
>
> Real world example: eth0 is the primary physical network interface and
> ledltrig-netdev is associated with that interface. If now Docker creates
> a virtual Ethernet interface (vethXXXX), moves it to the
> container's net namespace and renames it to eth0, ledtrig-netdev
> switches to this device and the LED no longer blinks for the original
> (physical) network device.
>
> Fix this by refactoring the conditions under which to return early with
> NOTIFY_DONE inside netdev_trig_notify():
>
> - For processing NETDEV_REGISTER events, the device name has to match
> and no association with a net_dev must exist.
>
> - For processing NETDEV_CHANGENAME events, the associated and notified
> network device have to match. Alternatively the device name has to
> match and no association with a net_dev must exist.
>
> - For all other events, the associated and notified network device have
> to match.
Could you split this into two patches for ease of review?
First which factors out all the logic related to deciding if the event
needs to be handled, move it to a new helper which takes the relevant
args are turns bool of whether we should return NOTIFY_DONE immediately
or not. And then a second patch which modifies this logic.
Having the refactor squashed with the change makes it harder to review.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2025-04-29 18:50 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-04-25 13:20 [PATCH v3] leds: trigger: netdev: refactor dev matching in netdev_trig_notify() Tobias Junghans
2025-04-29 18:50 ` Jakub Kicinski
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).