diff mbox series

[net-next] net: uevent: also pass network device driver

Message ID 20241115183346.597503-1-mail@tk154.de (mailing list archive)
State Changes Requested
Delegated to: Netdev Maintainers
Headers show
Series [net-next] net: uevent: also pass network device driver | expand

Checks

Context Check Description
netdev/series_format success Single patches do not need cover letters
netdev/tree_selection success Clearly marked for net-next
netdev/ynl success Generated files up to date; no warnings/errors; no diff in generated;
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 3 this patch: 3
netdev/build_tools success No tools touched, skip
netdev/cc_maintainers fail 4 maintainers not CCed: kuba@kernel.org edumazet@google.com horms@kernel.org pabeni@redhat.com
netdev/build_clang success Errors and warnings before: 3 this patch: 3
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 No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 4 this patch: 4
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 19 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
netdev/contest success net-next-2024-11-15--21-00 (tests: 789)

Commit Message

Til Kaiser Nov. 15, 2024, 6:33 p.m. UTC
Currently, for uevent, the interface name and
index are passed via shell variables.

This commit also passes the network device
driver as a shell variable to uevent.

Signed-off-by: Til Kaiser <mail@tk154.de>
---
 net/core/net-sysfs.c | 7 +++++++
 1 file changed, 7 insertions(+)

Comments

Jakub Kicinski Nov. 15, 2024, 10:06 p.m. UTC | #1
On Fri, 15 Nov 2024 19:33:46 +0100 Til Kaiser wrote:
> Currently, for uevent, the interface name and
> index are passed via shell variables.
> 
> This commit also passes the network device
> driver as a shell variable to uevent.

Can you add more information to the commit message for the 'why'?

I'm guessing this can only be used for local one off hacks, or 
can a generic (eg distro level) naming policy benefit from the driver
name?
Til Kaiser Nov. 16, 2024, 4:30 p.m. UTC | #2
Hi, thanks for the response.

I have added a short explanation to the commit message.

I aim to retrieve the network interface's driver when it
gets created on the Linux OpenWrt OS. OpenWrt doesn't use
udev but uses its own hotplug implementation where the driver
name isn't available per a shell variable.

As I mentioned in my commit message, I could add the driver
query to the hotplug implementation. But I think it might also
be beneficial for other Linux OS that the driver name comes
directly from the Linux Kernel.

Furthermore, I think it's more comfortable for a user that he
can directly check the driver name through the sysfs uevent file.

Kind regards
Til

Changes in v2:
 - Updated the commit message to clarify the purpose of the patch.
diff mbox series

Patch

diff --git a/net/core/net-sysfs.c b/net/core/net-sysfs.c
index 05cf5347f25e..67aad5ca82f8 100644
--- a/net/core/net-sysfs.c
+++ b/net/core/net-sysfs.c
@@ -2000,6 +2000,7 @@  EXPORT_SYMBOL_GPL(net_ns_type_operations);
 static int netdev_uevent(const struct device *d, struct kobj_uevent_env *env)
 {
 	const struct net_device *dev = to_net_dev(d);
+	const char *driver = netdev_drivername(dev);
 	int retval;
 
 	/* pass interface to uevent. */
@@ -2012,6 +2013,12 @@  static int netdev_uevent(const struct device *d, struct kobj_uevent_env *env)
 	 * and is what RtNetlink uses natively.
 	 */
 	retval = add_uevent_var(env, "IFINDEX=%d", dev->ifindex);
+	if (retval)
+		goto exit;
+
+	if (driver[0])
+		/* pass driver to uevent. */
+		retval = add_uevent_var(env, "DRIVER=%s", driver);
 
 exit:
 	return retval;