2020-11-18 06:41:27

by Martin Schiller

[permalink] [raw]
Subject: [PATCH net-next v5] net/tun: Call netdev notifiers

Call netdev notifiers before and after changing the device type.

Signed-off-by: Martin Schiller <[email protected]>
---

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(-)

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;

--
2.20.1


2020-11-20 18:33:34

by Jakub Kicinski

[permalink] [raw]
Subject: Re: [PATCH net-next v5] net/tun: Call netdev notifiers

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?

2020-11-23 06:30:50

by Martin Schiller

[permalink] [raw]
Subject: Re: [PATCH net-next v5] net/tun: Call netdev notifiers

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 <[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

2020-11-23 18:42:40

by Jakub Kicinski

[permalink] [raw]
Subject: Re: [PATCH net-next v5] net/tun: Call netdev notifiers

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 <[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

Thanks for this info, applied to net-next.