linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net-next v5] net/tun: Call netdev notifiers
@ 2020-11-18  6:39 Martin Schiller
  2020-11-20 18:28 ` Jakub Kicinski
  0 siblings, 1 reply; 4+ messages in thread
From: Martin Schiller @ 2020-11-18  6:39 UTC (permalink / raw)
  To: davem, kuba; +Cc: netdev, linux-kernel, Martin Schiller

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

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


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH net-next v5] net/tun: Call netdev notifiers
  2020-11-18  6:39 [PATCH net-next v5] net/tun: Call netdev notifiers Martin Schiller
@ 2020-11-20 18:28 ` Jakub Kicinski
  2020-11-23  6:18   ` Martin Schiller
  0 siblings, 1 reply; 4+ messages in thread
From: Jakub Kicinski @ 2020-11-20 18:28 UTC (permalink / raw)
  To: Martin Schiller; +Cc: davem, netdev, linux-kernel

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?

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH net-next v5] net/tun: Call netdev notifiers
  2020-11-20 18:28 ` Jakub Kicinski
@ 2020-11-23  6:18   ` Martin Schiller
  2020-11-23 18:40     ` Jakub Kicinski
  0 siblings, 1 reply; 4+ messages in thread
From: Martin Schiller @ 2020-11-23  6:18 UTC (permalink / raw)
  To: Jakub Kicinski; +Cc: davem, netdev, linux-kernel

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

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH net-next v5] net/tun: Call netdev notifiers
  2020-11-23  6:18   ` Martin Schiller
@ 2020-11-23 18:40     ` Jakub Kicinski
  0 siblings, 0 replies; 4+ messages in thread
From: Jakub Kicinski @ 2020-11-23 18:40 UTC (permalink / raw)
  To: Martin Schiller; +Cc: davem, netdev, linux-kernel

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.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2020-11-23 18:41 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-11-18  6:39 [PATCH net-next v5] net/tun: Call netdev notifiers Martin Schiller
2020-11-20 18:28 ` Jakub Kicinski
2020-11-23  6:18   ` Martin Schiller
2020-11-23 18:40     ` Jakub Kicinski

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).