net/tun: Call netdev notifiers
Subsystems (3)
PATCH v5 1/1 net/tun: Call netdev notifiers
Call netdev notifiers before and after changing the device type.
---
Changes to v4:
* Fix copy'n'paste error
Changes to v3:
* Handle return value of call_netdevice_notifiers()
Changes to v2:
* Use subject_prefix 'net-next' to fix 'fixes_present' issue
Changes to v1:
* Fix 'subject_prefix' and 'checkpatch' warnings
--- drivers/net/tun.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-)
drivers/net/tun.c +10 -1
@@ -3071,10 +3071,19 @@ static long __tun_chr_ioctl(struct file *file, unsigned int cmd, "Linktype set failed because interface is up\n"); ret = -EBUSY ; }else { + ret =call_netdevice_notifiers (NETDEV_PRE_TYPE_CHANGE , + tun->dev); + ret =notifier_to_errno (ret); +if (ret) { +netif_info (tun, drv, tun->dev, +"Refused to change device type\n" ); +break ; + } tun->dev->type = (int ) arg;netif_info (tun, drv, tun->dev,"linktype set to %d\n" , tun->dev->type); - ret =0 ; +call_netdevice_notifiers (NETDEV_POST_TYPE_CHANGE , + tun->dev); }break ;
Signature · 1 line
2.20.1
Jakub Kicinski
maintainerQuoted 3 lines · On Wed, 18 Nov 2020 07:39:19 +0100 Martin Schiller wrote:
Call netdev notifiers before and after changing the device type.
Signed-off-by Martin Schiller <[email protected]>
This is a fix, right? Can you give an example of something that goes wrong without this patch?
Quoted 7 lines · Jakub Kicinski
Quoted 3 lines · On Wed, 18 Nov 2020 07:39:19 +0100 Martin Schiller wrote:
Call netdev notifiers before and after changing the device type.
Signed-off-by Martin Schiller <[email protected]>This is a fix, right? Can you give an example of something that goes wrong without this patch?
This change is related to my latest patches to the X.25 Subsystem:
https://patchwork.kernel.org/project/netdevbpf/list/?series=388087
I use a tun interface in a XoT (X.25 over TCP) application and use the TUNSETLINK ioctl to change the device type to ARPHRD_X25. As the default device type is ARPHRD_NONE the initial NETDEV_REGISTER event won't be catched by the X.25 Stack.
Therefore I have to use the NETDEV_POST_TYPE_CHANGE to make sure that the corresponding neighbour structure is created.
I could imagine that other protocols have similar requirements.
Whether this is a fix or a functional extension is hard to say.
Some time ago there was also a corresponding patch for the WAN/HDLC subsystem:
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit?id=2f8364a291e8
Jakub Kicinski
maintainerQuoted 20 lines · On Mon, 23 Nov 2020 07:18:07 +0100 Martin Schiller wrote:
Quoted 7 lines · Jakub Kicinski
Quoted 3 lines · On Wed, 18 Nov 2020 07:39:19 +0100 Martin Schiller wrote:
Call netdev notifiers before and after changing the device type.
Signed-off-by Martin Schiller <[email protected]>This is a fix, right? Can you give an example of something that goes wrong without this patch?
This change is related to my latest patches to the X.25 Subsystem:
https://patchwork.kernel.org/project/netdevbpf/list/?series=388087I use a tun interface in a XoT (X.25 over TCP) application and use the TUNSETLINK ioctl to change the device type to
ARPHRD_X25. As the default device type isARPHRD_NONEthe initialNETDEV_REGISTERevent won't be catched by the X.25 Stack.Therefore I have to use the
NETDEV_POST_TYPE_CHANGEto make sure that the corresponding neighbour structure is created.
Quoted 8 lines
I could imagine that other protocols have similar requirements.
Whether this is a fix or a functional extension is hard to say.
Some time ago there was also a corresponding patch for the WAN/HDLC subsystem:
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit?id=2f8364a291e8
Thanks for this info, applied to net-next.