Skip to contentSkip to conversation

net/tun: Call netdev notifiers

PATCH Superseded Martin Schiller 2 participants 3 messages Nov 16, 2020 – Nov 18, 2020

Subsystems (3)

v3 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 net/tun: Call netdev notifiers

Call netdev notifiers before and after changing the device type.

---

Change from v2:
use subject_prefix 'net-next' to fix 'fixes_present' issue

Change from v1:
fix 'subject_prefix' and 'checkpatch' warnings

---
 drivers/net/tun.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/net/tun.c +4 -0
index 3d45d56172cb..2d9a00f41023 100644
@@ -3071,9 +3071,13 @@ static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
 				   "Linktype set failed because interface is up\n");
 			ret = -EBUSY;
 		} else {
+			call_netdevice_notifiers(NETDEV_PRE_TYPE_CHANGE,
+						 tun->dev);
 			tun->dev->type = (int) arg;
 			netif_info(tun, drv, tun->dev, "linktype set to %d\n",
 				   tun->dev->type);
+			call_netdevice_notifiers(NETDEV_POST_TYPE_CHANGE,
+						 tun->dev);
 			ret = 0;
 		}
 		break;
Signature · 1 line
2.20.1
maintainer
#1 lore raw
Quoted 20 lines · On Mon, 16 Nov 2020 11:41:21 +0100 Martin Schiller wrote:

Call netdev notifiers before and after changing the device type.

---

Change from v2:
use subject_prefix 'net-next' to fix 'fixes_present' issue

Change from v1:
fix 'subject_prefix' and 'checkpatch' warnings

---
 drivers/net/tun.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/net/tun.c +0 -0
index 3d45d56172cb..2d9a00f41023 100644

drivers/net/tun.c static long __tun_chr_ioctl(struct file *file, unsigned int cmd, · line 3075

Quoted 5 lines
drivers/net/tun.c +2 -0
@@ -3071,9 +3071,13 @@ static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
 				   "Linktype set failed because interface is up\n");
 			ret = -EBUSY;
 		} else {
+			call_netdevice_notifiers(NETDEV_PRE_TYPE_CHANGE,
+						 tun->dev);

This call may return an error (which has to be unpacked with notifier_to_errno()).

Quoted 8 lines
drivers/net/tun.c +2 -0
 			tun->dev->type = (int) arg;
 			netif_info(tun, drv, tun->dev, "linktype set to %d\n",
 				   tun->dev->type);
+			call_netdevice_notifiers(NETDEV_POST_TYPE_CHANGE,
+						 tun->dev);
 			ret = 0;
 		}
 		break;
#2 lore raw
Quoted 16 lines · Jakub Kicinski
Quoted 15 lines · On Mon, 16 Nov 2020 11:41:21 +0100 Martin Schiller wrote:

Call netdev notifiers before and after changing the device type.

---

Change from v2:
use subject_prefix 'net-next' to fix 'fixes_present' issue

Change from v1:
fix 'subject_prefix' and 'checkpatch' warnings

---
 drivers/net/tun.c | 4 ++++
 1 file changed, 4 insertions(+)
Quoted 14 lines

drivers/net/tun.c static long __tun_chr_ioctl(struct file *file, · line 3076

Quoted 11 lines
drivers/net/tun.c +2 -0
index 3d45d56172cb..2d9a00f41023 100644
@@ -3071,9 +3071,13 @@ static long __tun_chr_ioctl(struct file *file, 
 unsigned int cmd,
 				   "Linktype set failed because interface is up\n");
 			ret = -EBUSY;
 		} else {
+			call_netdevice_notifiers(NETDEV_PRE_TYPE_CHANGE,
+						 tun->dev);

This call may return an error (which has to be unpacked with notifier_to_errno()).

OK, I'll fix that and send a v3 patch.

Quoted 9 lines
Quoted 9 lines
drivers/net/tun.c +2 -0
 			tun->dev->type = (int) arg;
 			netif_info(tun, drv, tun->dev, "linktype set to %d\n",
 				   tun->dev->type);
+			call_netdevice_notifiers(NETDEV_POST_TYPE_CHANGE,
+						 tun->dev);
 			ret = 0;
 		}

break;