hyperv: Add support for setting MAC from within guests
Subsystems (3)
Haiyang Zhang
maintainerPATCH 1/1 hyperv: Add support for setting MAC from within guests
This adds support for setting synthetic NIC MAC address from within Linux guests. Before using this feature, the option "spoofing of MAC address" should be enabled at the Hyper-V manager / Settings of the synthetic NIC.
Thanks to Kin Cho <[email protected]> for the initial implementation and tests. And, thanks to Long Li <[email protected]> for the debugging works.
--- drivers/net/hyperv/hyperv_net.h | 1 + drivers/net/hyperv/netvsc_drv.c | 30 +++++++++++++- drivers/net/hyperv/rndis_filter.c | 79 +++++++++++++++++++++++++++++++++++++ 3 files changed, 109 insertions(+), 1 deletions(-)
drivers/net/hyperv/hyperv_net.h +1 -0
@@ -131,6 +131,7 @@ int rndis_filter_send(struct hv_device *dev, struct hv_netvsc_packet *pkt);int rndis_filter_set_packet_filter (struct rndis_device *dev,u32 new_filter); +int rndis_filter_set_device_mac (struct hv_device *hdev,char *mac);#define NVSP_INVALID_PROTOCOL_VERSION ((u32)0xFFFFFFFF)
drivers/net/hyperv/netvsc_drv.c +29 -1
@@ -341,6 +341,34 @@ static int netvsc_change_mtu(struct net_device *ndev, int mtu)return 0 ; } + +static int netvsc_set_mac_addr (struct net_device *ndev,void *p) +{ +struct net_device_context *ndevctx =netdev_priv (ndev); +struct hv_device *hdev = ndevctx->device_ctx; +struct sockaddr *addr = p; +char save_adr[14 ]; +unsigned char save_aatype; +int err; + +memcpy (save_adr, ndev->dev_addr,ETH_ALEN ); + save_aatype = ndev->addr_assign_type; + + err =eth_mac_addr (ndev, p); +if (err !=0 ) +return err; + + err =rndis_filter_set_device_mac (hdev, addr->sa_data); +if (err !=0 ) { +/* roll back to saved MAC */ +memcpy (ndev->dev_addr, save_adr,ETH_ALEN ); + ndev->addr_assign_type = save_aatype; + } + +return err; +} + +static const struct ethtool_ops ethtool_ops = { .get_drvinfo = netvsc_get_drvinfo, .get_link = ethtool_op_get_link,
@@ -353,7 +381,7 @@ static const struct net_device_ops device_ops = { .ndo_set_rx_mode = netvsc_set_multicast_list, .ndo_change_mtu = netvsc_change_mtu, .ndo_validate_addr = eth_validate_addr, - .ndo_set_mac_address = eth_mac_addr, + .ndo_set_mac_address = netvsc_set_mac_addr, };/*
drivers/net/hyperv/rndis_filter.c +79 -0
97 lines not on this page · raw message
Signature · 1 line
1.7.4.1
Quoted 4 lines · Haiyang Zhang
This adds support for setting synthetic NIC MAC address from within Linux guests. Before using this feature, the option "spoofing of MAC address" should be enabled at the Hyper-V manager / Settings of the synthetic NIC.
[...]
Quoted 2 lines
drivers/net/hyperv/rndis_filter.c +2
-0+int rndis_filter_set_device_mac (struct hv_device *hdev,char *mac) +{
[...]
drivers/net/hyperv/rndis_filter.c static int rndis_filter_query_device_mac(struct rndis_device *dev) · line 584
Quoted 12 lines
drivers/net/hyperv/rndis_filter.c +12
-0+ t =wait_for_completion_timeout (&request->wait_event,5 *HZ ); +if (t ==0 ) { +netdev_err (ndev,"timeout before we got a set response...\n" ); +/* +* can't put_rndis_request, since we may still receive a +* send-completion. +*/ +return -EBUSY ; + }else { + set_complete = &request->response_msg.msg.set_complete; +if (set_complete->status !=RNDIS_STATUS_SUCCESS ) + ret = -EINVAL ;
[...]
Is there a specific error code that indicates the hypervisor is configured not to allow MAC address changes? If so, shouldn't that be translated to return EPERM rather than EINVAL?
Ben.
Signature · 3 lines
Ben Hutchings, Staff Engineer, Solarflare Not speaking for my employer; that's the marketing department's job. They asked us to note that Solarflare product names are trademarked.
Haiyang Zhang
maintainerQuoted 35 lines
-----Original Message-----
From: Ben Hutchings [mailto:[email protected]]
Sent: Friday, July 06, 2012 8:19 PM
To: Haiyang Zhang
Cc: [email protected]; [email protected]; KY Srinivasan; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH net,1/1] hyperv: Add support for setting MAC from within guestsQuoted 2 lines · Haiyang Zhang
This adds support for setting synthetic NIC MAC address from within Linux guests. Before using this feature, the option "spoofing of MAC
address"
Quoted 2 lines
should be enabled at the Hyper-V manager / Settings of the synthetic NIC.
[...]
Quoted 1 line
+int
rndis_filter_set_device_mac(struct hv_device *hdev, char *mac){[...]
drivers/net/hyperv/rndis_filter.c static int rndis_filter_query_device_mac(struct rndis_device *dev)
Quoted 3 lines
drivers/net/hyperv/rndis_filter.c +3
-0+ t =wait_for_completion_timeout (&request->wait_event,5 *HZ ); +if (t ==0 ) { + netdev_err(ndev, "timeout before we got a setresponse...\n");
Quoted 9 lines
drivers/net/hyperv/rndis_filter.c +9
-0+/* +* can't put_rndis_request, since we may still receive a +* send-completion. +*/ +return -EBUSY ; + }else { + set_complete = &request->response_msg.msg.set_complete; +if (set_complete->status !=RNDIS_STATUS_SUCCESS ) + ret = -EINVAL ;[...]
Quoted 3 lines
Is there a specific error code that indicates the hypervisor is configured not to allow MAC address changes? If so, shouldn't that be translated to return EPERM rather than EINVAL?
Will do.
Thanks,
- Haiyang
Haiyang Zhang
maintainerQuoted 38 lines
-----Original Message-----
From: Ben Hutchings [mailto:[email protected]]
Sent: Friday, July 06, 2012 8:19 PM
To: Haiyang Zhang
Cc: [email protected]; [email protected]; KY Srinivasan; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH net,1/1] hyperv: Add support for setting MAC from within guestsQuoted 1 line · Haiyang Zhang
This adds support for setting synthetic NIC MAC address from within
Linux
Quoted 1 line
guests. Before using this feature, the option "spoofing of MAC
address"
Quoted 2 lines
should be enabled at the Hyper-V manager / Settings of the synthetic NIC.
[...]
Quoted 2 lines
drivers/net/hyperv/rndis_filter.c +2
-0+int rndis_filter_set_device_mac (struct hv_device *hdev,char *mac) +{[...]
drivers/net/hyperv/rndis_filter.c static int rndis_filter_query_device_mac(struct rndis_device *dev)
Quoted 3 lines
drivers/net/hyperv/rndis_filter.c +3
-0+ t =wait_for_completion_timeout (&request->wait_event,5 *HZ ); +if (t ==0 ) { + netdev_err(ndev, "timeout before we got a setresponse...\n");
Quoted 9 lines
drivers/net/hyperv/rndis_filter.c +9
-0+/* +* can't put_rndis_request, since we may still receive a +* send-completion. +*/ +return -EBUSY ; + }else { + set_complete = &request->response_msg.msg.set_complete; +if (set_complete->status !=RNDIS_STATUS_SUCCESS ) + ret = -EINVAL ;[...]
Quoted 3 lines
Is there a specific error code that indicates the hypervisor is configured not to allow MAC address changes? If so, shouldn't that be translated to return EPERM rather than EINVAL?
I have check the return code, 0xc000000d, which is returned both when MAC spoofing is not enabled or the parameter contains other errors. So we can't tell if it permission error or not. I will re-submit this patch still using EINVAL.
Thanks,
- Haiyang
Quoted 37 lines · Haiyang Zhang
Quoted 37 lines
-----Original Message-----
From: Ben Hutchings [mailto:[email protected]]
Sent: Friday, July 06, 2012 8:19 PM
To: Haiyang Zhang
Cc: [email protected]; [email protected]; KY Srinivasan; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH net,1/1] hyperv: Add support for setting MAC from within guestsQuoted 1 line · Haiyang Zhang
This adds support for setting synthetic NIC MAC address from within
Linux
Quoted 1 line
guests. Before using this feature, the option "spoofing of MAC
address"
Quoted 2 lines
should be enabled at the Hyper-V manager / Settings of the synthetic NIC.
[...]
Quoted 2 lines
drivers/net/hyperv/rndis_filter.c +2
-0+int rndis_filter_set_device_mac (struct hv_device *hdev,char *mac) +{[...]
drivers/net/hyperv/rndis_filter.c static int rndis_filter_query_device_mac(struct rndis_device *dev)
Quoted 3 lines
drivers/net/hyperv/rndis_filter.c +3
-0+ t =wait_for_completion_timeout (&request->wait_event,5 *HZ ); +if (t ==0 ) { + netdev_err(ndev, "timeout before we got a setresponse...\n");
Quoted 9 lines
drivers/net/hyperv/rndis_filter.c +9
-0+/* +* can't put_rndis_request, since we may still receive a +* send-completion. +*/ +return -EBUSY ; + }else { + set_complete = &request->response_msg.msg.set_complete; +if (set_complete->status !=RNDIS_STATUS_SUCCESS ) + ret = -EINVAL ;[...]
Quoted 8 lines
Quoted 3 lines
Is there a specific error code that indicates the hypervisor is configured not to allow MAC address changes? If so, shouldn't that be translated to return EPERM rather than EINVAL?
I have check the return code,
0xc000000d, which is returned both when MAC spoofing is not enabled or the parameter contains other errors. So we can't tell if it permission error or not. I will re-submit this patch still using EINVAL.
Oh well, thanks for trying!
Ben.
Signature · 3 lines
Ben Hutchings, Staff Engineer, Solarflare Not speaking for my employer; that's the marketing department's job. They asked us to note that Solarflare product names are trademarked.