Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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 <sthemmin@microsoft.com>
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by

Stephen Hemminger and committed by
David S. Miller
0fe554a4 c4ff0b0f

+29
+28
drivers/net/hyperv/rndis_filter.c
··· 29 29 #include <linux/nls.h> 30 30 #include <linux/vmalloc.h> 31 31 #include <linux/rtnetlink.h> 32 + #include <linux/ucs2_string.h> 32 33 33 34 #include "hyperv_net.h" 34 35 #include "netvsc_trace.h" ··· 1224 1223 return ret; 1225 1224 } 1226 1225 1226 + static void rndis_get_friendly_name(struct net_device *net, 1227 + struct rndis_device *rndis_device, 1228 + struct netvsc_device *net_device) 1229 + { 1230 + ucs2_char_t wname[256]; 1231 + unsigned long len; 1232 + u8 ifalias[256]; 1233 + u32 size; 1234 + 1235 + size = sizeof(wname); 1236 + if (rndis_filter_query_device(rndis_device, net_device, 1237 + RNDIS_OID_GEN_FRIENDLY_NAME, 1238 + wname, &size) != 0) 1239 + return; 1240 + 1241 + /* Convert Windows Unicode string to UTF-8 */ 1242 + len = ucs2_as_utf8(ifalias, wname, sizeof(ifalias)); 1243 + 1244 + /* ignore the default value from host */ 1245 + if (strcmp(ifalias, "Network Adapter") != 0) 1246 + dev_set_alias(net, ifalias, len); 1247 + } 1248 + 1227 1249 struct netvsc_device *rndis_filter_device_add(struct hv_device *dev, 1228 1250 struct netvsc_device_info *device_info) 1229 1251 { ··· 1299 1275 goto err_dev_remv; 1300 1276 1301 1277 memcpy(device_info->mac_adr, rndis_device->hw_mac_adr, ETH_ALEN); 1278 + 1279 + /* Get friendly name as ifalias*/ 1280 + if (!net->ifalias) 1281 + rndis_get_friendly_name(net, rndis_device, net_device); 1302 1282 1303 1283 /* Query and set hardware capabilities */ 1304 1284 ret = rndis_netdev_set_hwcaps(rndis_device, net_device);
+1
net/core/dev.c
··· 1285 1285 1286 1286 return len; 1287 1287 } 1288 + EXPORT_SYMBOL(dev_set_alias); 1288 1289 1289 1290 /** 1290 1291 * dev_get_alias - get ifalias of a device