lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-Id: <20180828205811.125925-1-marcel@holtmann.org>
Date:   Tue, 28 Aug 2018 22:58:11 +0200
From:   Marcel Holtmann <marcel@...tmann.org>
To:     netdev@...r.kernel.org, davem@...emloft.net
Subject: [PATCH] rtnetlink: expose value from SET_NETDEV_DEVTYPE via IFLA_DEVTYPE attribute

The name value from SET_NETDEV_DEVTYPE only ended up in the uevent sysfs
file as DEVTYPE= information. To avoid any kind of race conditions
between netlink messages and reading from sysfs, it is useful to add the
same string as new IFLA_DEVTYPE attribute included in the RTM_NEWLINK
messages.

For network managing daemons that have to classify ARPHRD_ETHER network
devices into different types (like Wireless LAN, Bluetooth etc.), this
avoids the extra round trip to sysfs and parsing of the uevent file.

Signed-off-by: Marcel Holtmann <marcel@...tmann.org>
---
 include/uapi/linux/if_link.h |  2 ++
 net/core/rtnetlink.c         | 12 ++++++++++++
 2 files changed, 14 insertions(+)

diff --git a/include/uapi/linux/if_link.h b/include/uapi/linux/if_link.h
index 43391e2d1153..781294972bb4 100644
--- a/include/uapi/linux/if_link.h
+++ b/include/uapi/linux/if_link.h
@@ -166,6 +166,8 @@ enum {
 	IFLA_NEW_IFINDEX,
 	IFLA_MIN_MTU,
 	IFLA_MAX_MTU,
+	IFLA_DEVTYPE,		/* Name value from SET_NETDEV_DEVTYPE */
+#define IFLA_DEVTYPE IFLA_DEVTYPE
 	__IFLA_MAX
 };
 
diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
index 24431e578310..bd288710f9bf 100644
--- a/net/core/rtnetlink.c
+++ b/net/core/rtnetlink.c
@@ -970,6 +970,14 @@ static size_t rtnl_xdp_size(void)
 	return xdp_size;
 }
 
+static size_t rtnl_devtype_size(const struct net_device *dev)
+{
+	if (!dev->dev.type || !dev->dev.type->name)
+		return 0;
+
+	return strlen(dev->dev.type->name) + 1;
+}
+
 static noinline size_t if_nlmsg_size(const struct net_device *dev,
 				     u32 ext_filter_mask)
 {
@@ -1017,6 +1025,7 @@ static noinline size_t if_nlmsg_size(const struct net_device *dev,
 	       + nla_total_size(4)  /* IFLA_CARRIER_DOWN_COUNT */
 	       + nla_total_size(4)  /* IFLA_MIN_MTU */
 	       + nla_total_size(4)  /* IFLA_MAX_MTU */
+	       + rtnl_devtype_size(dev) /* IFLA_DEVTYPE */
 	       + 0;
 }
 
@@ -1679,6 +1688,8 @@ static int rtnl_fill_ifinfo(struct sk_buff *skb,
 	    nla_put_s32(skb, IFLA_NEW_IFINDEX, new_ifindex) < 0)
 		goto nla_put_failure;
 
+	if (dev->dev.type && dev->dev.type->name)
+		nla_put_string(skb, IFLA_DEVTYPE, dev->dev.type->name);
 
 	rcu_read_lock();
 	if (rtnl_fill_link_af(skb, dev, ext_filter_mask))
@@ -1738,6 +1749,7 @@ static const struct nla_policy ifla_policy[IFLA_MAX+1] = {
 	[IFLA_CARRIER_DOWN_COUNT] = { .type = NLA_U32 },
 	[IFLA_MIN_MTU]		= { .type = NLA_U32 },
 	[IFLA_MAX_MTU]		= { .type = NLA_U32 },
+	[IFLA_DEVTYPE]		= { .type = NLA_STRING },
 };
 
 static const struct nla_policy ifla_info_policy[IFLA_INFO_MAX+1] = {
-- 
2.14.4

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ