macvtap add missing ioctls - fix wrapping
authorJustin Cormack <justin@myriabit.com>
Mon, 11 May 2015 19:00:10 +0000 (20:00 +0100)
committerDavid S. Miller <davem@davemloft.net>
Wed, 13 May 2015 03:01:01 +0000 (23:01 -0400)
The macvtap driver tries to emulate all the ioctls supported by a normal
tun/tap driver, however it was missing the generic SIOCGIFHWADDR and
SIOCSIFHWADDR ioctls to get and set the mac address that are supported
by tun/tap. This patch adds these.

Signed-off-by: Justin Cormack <justin@netbsd.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/macvtap.c

index 0398631a3c2474cf7eb94a9f5a99d53e970ca182..c8a23896d54e103178df3ad2a41128be8ed6bf53 100644 (file)
@@ -1101,6 +1101,35 @@ static long macvtap_ioctl(struct file *file, unsigned int cmd,
                rtnl_unlock();
                return ret;
 
+       case SIOCGIFHWADDR:
+               rtnl_lock();
+               vlan = macvtap_get_vlan(q);
+               if (!vlan) {
+                       rtnl_unlock();
+                       return -ENOLINK;
+               }
+               ret = 0;
+               u = vlan->dev->type;
+               if (copy_to_user(&ifr->ifr_name, vlan->dev->name, IFNAMSIZ) ||
+                   copy_to_user(&ifr->ifr_hwaddr.sa_data, vlan->dev->dev_addr, ETH_ALEN) ||
+                   put_user(u, &ifr->ifr_hwaddr.sa_family))
+                       ret = -EFAULT;
+               macvtap_put_vlan(vlan);
+               rtnl_unlock();
+               return ret;
+
+       case SIOCSIFHWADDR:
+               rtnl_lock();
+               vlan = macvtap_get_vlan(q);
+               if (!vlan) {
+                       rtnl_unlock();
+                       return -ENOLINK;
+               }
+               ret = dev_set_mac_address(vlan->dev, &ifr->ifr_hwaddr);
+               macvtap_put_vlan(vlan);
+               rtnl_unlock();
+               return ret;
+
        default:
                return -EINVAL;
        }