Message ID | 20201118063919.29485-1-ms@dev.tdt.de (mailing list archive) |
---|---|
State | Accepted |
Delegated to: | Netdev Maintainers |
Headers | show |
Series | [net-next,v5] net/tun: Call netdev notifiers | expand |
Context | Check | Description |
---|---|---|
netdev/cover_letter | success | Link |
netdev/fixes_present | success | Link |
netdev/patch_count | success | Link |
netdev/tree_selection | success | Clearly marked for net-next |
netdev/subject_prefix | success | Link |
netdev/source_inline | success | Was 0 now: 0 |
netdev/verify_signedoff | success | Link |
netdev/module_param | success | Was 0 now: 0 |
netdev/build_32bit | success | Errors and warnings before: 0 this patch: 0 |
netdev/kdoc | success | Errors and warnings before: 0 this patch: 0 |
netdev/verify_fixes | success | Link |
netdev/checkpatch | success | total: 0 errors, 0 warnings, 0 checks, 20 lines checked |
netdev/build_allmodconfig_warn | success | Errors and warnings before: 0 this patch: 0 |
netdev/header_inline | success | Link |
netdev/stable | success | Stable not CCed |
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 <ms@dev.tdt.de> This is a fix, right? Can you give an example of something that goes wrong without this patch?
On 2020-11-20 19:28, Jakub Kicinski wrote: > 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 <ms@dev.tdt.de> > > 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
On Mon, 23 Nov 2020 07:18:07 +0100 Martin Schiller wrote: > On 2020-11-20 19:28, Jakub Kicinski wrote: > > 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 <ms@dev.tdt.de> > > > > 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 Thanks for this info, applied to net-next.
diff --git a/drivers/net/tun.c b/drivers/net/tun.c index 3d45d56172cb..7c62d82c57db 100644 --- a/drivers/net/tun.c +++ b/drivers/net/tun.c @@ -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;
Call netdev notifiers before and after changing the device type. Signed-off-by: Martin Schiller <ms@dev.tdt.de> --- 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(-)