Skip to content

Commit 0fe554a

Browse files
shemmingerdavem330
authored andcommitted
hv_netvsc: propogate Hyper-V friendly name into interface alias
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 <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent c4ff0b0 commit 0fe554a

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

drivers/net/hyperv/rndis_filter.c

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include <linux/nls.h>
3030
#include <linux/vmalloc.h>
3131
#include <linux/rtnetlink.h>
32+
#include <linux/ucs2_string.h>
3233

3334
#include "hyperv_net.h"
3435
#include "netvsc_trace.h"
@@ -1223,6 +1224,29 @@ static int rndis_netdev_set_hwcaps(struct rndis_device *rndis_device,
12231224
return ret;
12241225
}
12251226

1227+
static void rndis_get_friendly_name(struct net_device *net,
1228+
struct rndis_device *rndis_device,
1229+
struct netvsc_device *net_device)
1230+
{
1231+
ucs2_char_t wname[256];
1232+
unsigned long len;
1233+
u8 ifalias[256];
1234+
u32 size;
1235+
1236+
size = sizeof(wname);
1237+
if (rndis_filter_query_device(rndis_device, net_device,
1238+
RNDIS_OID_GEN_FRIENDLY_NAME,
1239+
wname, &size) != 0)
1240+
return;
1241+
1242+
/* Convert Windows Unicode string to UTF-8 */
1243+
len = ucs2_as_utf8(ifalias, wname, sizeof(ifalias));
1244+
1245+
/* ignore the default value from host */
1246+
if (strcmp(ifalias, "Network Adapter") != 0)
1247+
dev_set_alias(net, ifalias, len);
1248+
}
1249+
12261250
struct netvsc_device *rndis_filter_device_add(struct hv_device *dev,
12271251
struct netvsc_device_info *device_info)
12281252
{
@@ -1276,6 +1300,10 @@ struct netvsc_device *rndis_filter_device_add(struct hv_device *dev,
12761300

12771301
memcpy(device_info->mac_adr, rndis_device->hw_mac_adr, ETH_ALEN);
12781302

1303+
/* Get friendly name as ifalias*/
1304+
if (!net->ifalias)
1305+
rndis_get_friendly_name(net, rndis_device, net_device);
1306+
12791307
/* Query and set hardware capabilities */
12801308
ret = rndis_netdev_set_hwcaps(rndis_device, net_device);
12811309
if (ret != 0)

net/core/dev.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1285,6 +1285,7 @@ int dev_set_alias(struct net_device *dev, const char *alias, size_t len)
12851285

12861286
return len;
12871287
}
1288+
EXPORT_SYMBOL(dev_set_alias);
12881289

12891290
/**
12901291
* dev_get_alias - get ifalias of a device

0 commit comments

Comments
 (0)