Skip to contentSkip to conversation

macvtap add missing ioctls

PATCH Superseded Justin Cormack 2 participants 13 messages May 6, 2015 – May 13, 2015

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 macvtap add missing ioctls

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 <[email protected]>

drivers/net/macvtap.c +29 -0
index 8c350c5..f37e8f9 100644
@@ -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;
 	}
maintainer
#1 lore raw

From: Justin Cormack <[email protected]>
Date: Wed, 06 May 2015 16:56:15 +0100

Quoted 5 lines

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 <[email protected]>

The correct format of a signoff is "Signed-off-by: " The exact format is important because scripts, GIT tools, and web applications parse these tags.

Also please format your commit message to ~80 columns.

Please fix this up and resubmit, thanks.

#2 lore raw

PATCH v2 1/1 macvtap add missing ioctls

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.

drivers/net/macvtap.c +0 -0
index 8c350c5..f37e8f9 100644
@@ -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;
}

#3 lore raw

Re: [PATCH v3] macvtap add missing ioctls - fix wrapping

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.

drivers/net/macvtap.c +29 -0
index 8c350c5..f37e8f9 100644
@@ -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;
 	}
maintainer
#4 lore raw

Re: [PATCH v3] macvtap add missing ioctls - fix wrapping

From: Justin Cormack <[email protected]>
Date: Sun, 10 May 2015 13:50:15 +0100

Quoted 17 lines

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.

drivers/net/macvtap.c +2 -0
index 8c350c5..f37e8f9 100644
@@ -1101,6 +1101,35 @@ static long macvtap_ioctl(struct file *file, unsigned int cmd,
 		rtnl_unlock();
 		return ret;
 
+	case SIOCGIFHWADDR:
+		rtnl_lock();

drivers/net/macvtap.c static long macvtap_ioctl(struct file *file, unsigned int cmd, · line 1115

Quoted 10 lines
drivers/net/macvtap.c +10 -0
+		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))

This is not indented correctly.

When an if() statement spans multiple lines, the second and subsequent lines should start exactly at the first column following the openning parenthesis of the first line. You should use the appropriate number of TAB then SPACE characters necessary to achieve this.

Thanks.

#5 lore raw

PATCH v4 1/1 macvtap add missing ioctls - fix wrapping

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.

drivers/net/macvtap.c +29 -0
index 8c350c5..5f98b34 100644
@@ -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;
 	}
maintainer Applied
#6 lore raw

Re: [PATCH v4] macvtap add missing ioctls - fix wrapping

From: Justin Cormack <[email protected]>
Date: Mon, 11 May 2015 20:00:10 +0100

Quoted 6 lines

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.

Applied to net-next, thanks.

#7 lore raw

Re: [PATCH v4] macvtap add missing ioctls - fix wrapping

Quoted 12 lines · David Miller

From: Justin Cormack <[email protected]>
Date: Mon, 11 May 2015 20:00:10 +0100

Quoted 6 lines

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.

Applied to net-next, thanks.

The kbuild test picked up a stupid error, should I send a new patch version, or a patch against net-next?

Justin

maintainer
#8 lore raw

Re: [PATCH v4] macvtap add missing ioctls - fix wrapping

From: Justin Cormack <[email protected]>
Date: Wed, 13 May 2015 11:06:01 +0100

Quoted 9 lines · David Miller
Quoted 8 lines

From: Justin Cormack <[email protected]>
Date: Mon, 11 May 2015 20:00:10 +0100

Quoted 5 lines

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.

Quoted 7 lines
Quoted 4 lines
Quoted 1 line

Applied to net-next, thanks.

The kbuild test picked up a stupid error, should I send a new patch version, or a patch against net-next?

Patches are never removable from my tree, so you must always send relative fixes.

#9 lore raw

PATCH v5 1/1 macvtap add missing ioctls

In reply to David Miller

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.

drivers/net/macvtap.c +32 -0
index 8c350c5..d2a7783 100644
@@ -1006,6 +1006,7 @@ static long macvtap_ioctl(struct file *file, unsigned int cmd,
 	unsigned int __user *up = argp;
 	unsigned short u;
 	int __user *sp = argp;
+	struct sockaddr sa;
 	int s;
 	int ret;
 
@@ -1101,6 +1102,37 @@ 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:
+		if (copy_from_user(&sa, &ifr->ifr_hwaddr, sizeof(sa)))
+			return -EFAULT;
+		rtnl_lock();
+		vlan = macvtap_get_vlan(q);
+		if (!vlan) {
+			rtnl_unlock();
+			return -ENOLINK;
+		}
+		ret = dev_set_mac_address(vlan->dev, &sa);
+		macvtap_put_vlan(vlan);
+		rtnl_unlock();
+		return ret;
+
 	default:
 		return -EINVAL;
 	}
maintainer
#10 lore raw

From: Justin Cormack <[email protected]>
Date: Wed, 13 May 2015 12:35:16 +0100

Quoted 6 lines

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.

As I stated, you cannot just send a new version of a patch I already applied to my tree.

It is in the permanent GIT commit record, and cannot be removed.

Therefore, you must send a relative fix.

#11 lore raw

PATCH 1/1 fix missing copy_from_user in macvtap

Fix missing copy_from_user in macvtap SIOCSIFHWADDR ioctl.

drivers/net/macvtap.c +4 -1
index c8a2389..483afb1 100644
@@ -1006,6 +1006,7 @@ static long macvtap_ioctl(struct file *file, unsigned int cmd,
 	unsigned int __user *up = argp;
 	unsigned short u;
 	int __user *sp = argp;
+	struct sockaddr sa;
 	int s;
 	int ret;
 
@@ -1119,13 +1120,15 @@ static long macvtap_ioctl(struct file *file, unsigned int cmd,
 		return ret;
 
 	case SIOCSIFHWADDR:
+		if (copy_from_user(&sa, &ifr->ifr_hwaddr, sizeof(sa)))
+			return -EFAULT;
 		rtnl_lock();
 		vlan = macvtap_get_vlan(q);
 		if (!vlan) {
 			rtnl_unlock();
 			return -ENOLINK;
 		}
-		ret = dev_set_mac_address(vlan->dev, &ifr->ifr_hwaddr);
+		ret = dev_set_mac_address(vlan->dev, &sa);
 		macvtap_put_vlan(vlan);
 		rtnl_unlock();
 		return ret;