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
From: Haiyang Zhang <[email protected]>
Date: Tue, 10 Jul 2012 10:19:22 -0700
Quoted 5 lines
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 8 lines
Thanks to Kin Cho <[email protected]> for the initial implementation and tests. And, thanks to Long Li <[email protected]> for the debugging works.
Reported-and-tested-by Kin Cho <[email protected]>Reported-by Long Li <[email protected]>Signed-off-by Haiyang Zhang <[email protected]>Reviewed-by K. Y. Srinivasan <[email protected]>
Applied to net-next, thanks.
drivers/net/hyperv/rndis_filter.c struct rndis_request { · line 51
Quoted 9 lines · Haiyang Zhang
drivers/net/hyperv/rndis_filter.c +1
-0@@ -47,6 +48,7 @@ struct rndis_request {struct hv_page_buffer buf;/* FIXME: We assumed a fixed size request here. */ struct rndis_message request_msg; +u8 ext[100 ];
This array is not referenced in the patch.
Please add a comment to the code what the purpose of this array is, and why its size is 100 bytes.
Thanks.
Olaf
Haiyang Zhang
maintainerQuoted 13 lines
-----Original Message-----
From: Olaf Hering [mailto:[email protected]]
Sent: Monday, July 30, 2012 8:39 AM
To: Haiyang Zhang
Cc: [email protected]; [email protected]; KY Srinivasan; linux- [email protected]; [email protected]
Subject: Re: [PATCH net,1/1] hyperv: Add support for setting MAC from within guestsOn Tue, Jul 10, Haiyang Zhang wrote:
Quoted 14 lines
drivers/net/hyperv/rndis_filter.c struct rndis_request { · line 51
Quoted 10 lines
drivers/net/hyperv/rndis_filter.c +1
-0@@ -47,6 +48,7 @@ struct rndis_request {struct hv_page_buffer buf;/* FIXME: We assumed a fixed size request here. */ struct rndis_message request_msg; +u8 ext[100 ];This array is not referenced in the patch.
Please add a comment to the code what the purpose of this array is, and why its size is 100 bytes.
It's a buffer for the extended info after the RNDIS message. It's referenced based on the data offset in the RNDIS message. 100 byte size is enough for current needs, and should be sufficient for the near future.
I will add a comment to the code.
Thanks,
- Haiyang