All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH net-next] hv_netvsc: propogate Hyper-V friendly name into interface alias
@ 2018-04-17 21:25 Stephen Hemminger
  2018-04-19  1:20 ` David Miller
  0 siblings, 1 reply; 2+ messages in thread
From: Stephen Hemminger @ 2018-04-17 21:25 UTC (permalink / raw)
  To: davem, haiyangz; +Cc: netdev, Stephen Hemminger

This patch implement the 'Device Naming' feature of the Hyper-V
network device API. In Hyper-V on the host through the GUI or PowerShell
it is possible to enable the device naming feature which causes
the host to make available to the guest the name of the device.
This shows up in the RNDIS protocol as the friendly name.

The name has no particular meaning and is limited to 256 characters.
The value can only be set via PowerShell on the host, but could
be scripted for mass deployments. The default value is the
string 'Network Adapter' and since that is the same for all devices
and useless, the driver ignores it.

In Windows, the value goes into a registry key for use in SNMP
ifAlias. For Linux, this patch puts the value in the network
device alias property; where it is visible in ip tools and SNMP.

The host provided ifAlias is just a suggestion, and can be
overridden by later ip commands.

Also requires exporting dev_set_alias in netdev core.

Signed-off-by: Stephen Hemminger <sthemmin@microsoft.com>
---
 drivers/net/hyperv/rndis_filter.c | 28 ++++++++++++++++++++++++++++
 net/core/dev.c                    |  1 +
 2 files changed, 29 insertions(+)

diff --git a/drivers/net/hyperv/rndis_filter.c b/drivers/net/hyperv/rndis_filter.c
index 6b127be781d9..3b6dbacaf77d 100644
--- a/drivers/net/hyperv/rndis_filter.c
+++ b/drivers/net/hyperv/rndis_filter.c
@@ -29,6 +29,7 @@
 #include <linux/nls.h>
 #include <linux/vmalloc.h>
 #include <linux/rtnetlink.h>
+#include <linux/ucs2_string.h>
 
 #include "hyperv_net.h"
 #include "netvsc_trace.h"
@@ -1223,6 +1224,29 @@ static int rndis_netdev_set_hwcaps(struct rndis_device *rndis_device,
 	return ret;
 }
 
+static void rndis_get_friendly_name(struct net_device *net,
+				    struct rndis_device *rndis_device,
+				    struct netvsc_device *net_device)
+{
+	ucs2_char_t wname[256];
+	unsigned long len;
+	u8 ifalias[256];
+	u32 size;
+
+	size = sizeof(wname);
+	if (rndis_filter_query_device(rndis_device, net_device,
+				      RNDIS_OID_GEN_FRIENDLY_NAME,
+				      wname, &size) != 0)
+		return;
+
+	/* Convert Windows Unicode string to UTF-8 */
+	len = ucs2_as_utf8(ifalias, wname, sizeof(ifalias));
+
+	/* ignore the default value from host */
+	if (strcmp(ifalias, "Network Adapter") != 0)
+		dev_set_alias(net, ifalias, len);
+}
+
 struct netvsc_device *rndis_filter_device_add(struct hv_device *dev,
 				      struct netvsc_device_info *device_info)
 {
@@ -1276,6 +1300,10 @@ struct netvsc_device *rndis_filter_device_add(struct hv_device *dev,
 
 	memcpy(device_info->mac_adr, rndis_device->hw_mac_adr, ETH_ALEN);
 
+	/* Get friendly name as ifalias*/
+	if (!net->ifalias)
+		rndis_get_friendly_name(net, rndis_device, net_device);
+
 	/* Query and set hardware capabilities */
 	ret = rndis_netdev_set_hwcaps(rndis_device, net_device);
 	if (ret != 0)
diff --git a/net/core/dev.c b/net/core/dev.c
index 9b04a9fd1dfd..f3be3e9e9493 100644
--- a/net/core/dev.c
+++ b/net/core/dev.c
@@ -1285,6 +1285,7 @@ int dev_set_alias(struct net_device *dev, const char *alias, size_t len)
 
 	return len;
 }
+EXPORT_SYMBOL(dev_set_alias);
 
 /**
  *	dev_get_alias - get ifalias of a device
-- 
2.17.0

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH net-next] hv_netvsc: propogate Hyper-V friendly name into interface alias
  2018-04-17 21:25 [PATCH net-next] hv_netvsc: propogate Hyper-V friendly name into interface alias Stephen Hemminger
@ 2018-04-19  1:20 ` David Miller
  0 siblings, 0 replies; 2+ messages in thread
From: David Miller @ 2018-04-19  1:20 UTC (permalink / raw)
  To: stephen; +Cc: haiyangz, netdev, sthemmin

From: Stephen Hemminger <stephen@networkplumber.org>
Date: Tue, 17 Apr 2018 14:25:30 -0700

> This patch implement the 'Device Naming' feature of the Hyper-V
> network device API. In Hyper-V on the host through the GUI or PowerShell
> it is possible to enable the device naming feature which causes
> the host to make available to the guest the name of the device.
> This shows up in the RNDIS protocol as the friendly name.
> 
> The name has no particular meaning and is limited to 256 characters.
> The value can only be set via PowerShell on the host, but could
> be scripted for mass deployments. The default value is the
> string 'Network Adapter' and since that is the same for all devices
> and useless, the driver ignores it.
> 
> In Windows, the value goes into a registry key for use in SNMP
> ifAlias. For Linux, this patch puts the value in the network
> device alias property; where it is visible in ip tools and SNMP.
> 
> The host provided ifAlias is just a suggestion, and can be
> overridden by later ip commands.
> 
> Also requires exporting dev_set_alias in netdev core.
> 
> Signed-off-by: Stephen Hemminger <sthemmin@microsoft.com>

This looks fine, applied, thanks.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2018-04-19  1:20 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-04-17 21:25 [PATCH net-next] hv_netvsc: propogate Hyper-V friendly name into interface alias Stephen Hemminger
2018-04-19  1:20 ` David Miller

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.