All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] net: add operstate for vcan and dummy
@ 2022-06-02  8:19 Kaarel Pärtel
  2022-06-03  2:46 ` Jakub Kicinski
  2022-06-03  3:39 ` Stephen Hemminger
  0 siblings, 2 replies; 3+ messages in thread
From: Kaarel Pärtel @ 2022-06-02  8:19 UTC (permalink / raw)
  To: Wolfgang Grandegger, Marc Kleine-Budde, David S. Miller,
	Eric Dumazet, Jakub Kicinski, Paolo Abeni
  Cc: Kaarel Pärtel, linux-can, netdev, linux-kernel

The idea here is simple. The vcan and the dummy network devices
currently do not set the operational state of the interface.
The result is that the interface state will be UNKNOWN.

The kernel considers the unknown state to be the same as up:
https://elixir.bootlin.com/linux/latest/source/include/linux/netdevice.h#L4125

However for users this creates confusion:
https://serverfault.com/questions/629676/dummy-network-interface-in-linux

The change in this patch is very simple. When the interface is set up, the
operational state is set to IF_OPER_UP.

Signed-off-by: Kaarel Pärtel <kaarelp2rtel@gmail.com>
---
 drivers/net/can/vcan.c | 1 +
 drivers/net/dummy.c    | 1 +
 2 files changed, 2 insertions(+)

diff --git a/drivers/net/can/vcan.c b/drivers/net/can/vcan.c
index a15619d883ec..79768f9d4294 100644
--- a/drivers/net/can/vcan.c
+++ b/drivers/net/can/vcan.c
@@ -162,6 +162,7 @@ static void vcan_setup(struct net_device *dev)
 
 	dev->netdev_ops		= &vcan_netdev_ops;
 	dev->needs_free_netdev	= true;
+	dev->operstate = IF_OPER_UP;
 }
 
 static struct rtnl_link_ops vcan_link_ops __read_mostly = {
diff --git a/drivers/net/dummy.c b/drivers/net/dummy.c
index f82ad7419508..ab128f66de00 100644
--- a/drivers/net/dummy.c
+++ b/drivers/net/dummy.c
@@ -133,6 +133,7 @@ static void dummy_setup(struct net_device *dev)
 
 	dev->min_mtu = 0;
 	dev->max_mtu = 0;
+	dev->operstate = IF_OPER_UP;
 }
 
 static int dummy_validate(struct nlattr *tb[], struct nlattr *data[],
-- 
2.25.1


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

* Re: [PATCH] net: add operstate for vcan and dummy
  2022-06-02  8:19 [PATCH] net: add operstate for vcan and dummy Kaarel Pärtel
@ 2022-06-03  2:46 ` Jakub Kicinski
  2022-06-03  3:39 ` Stephen Hemminger
  1 sibling, 0 replies; 3+ messages in thread
From: Jakub Kicinski @ 2022-06-03  2:46 UTC (permalink / raw)
  To: Kaarel Pärtel
  Cc: Wolfgang Grandegger, Marc Kleine-Budde, David S. Miller,
	Eric Dumazet, Paolo Abeni, linux-can, netdev, linux-kernel

On Thu,  2 Jun 2022 11:19:29 +0300 Kaarel Pärtel wrote:
> The idea here is simple. The vcan and the dummy network devices
> currently do not set the operational state of the interface.
> The result is that the interface state will be UNKNOWN.
> 
> The kernel considers the unknown state to be the same as up:
> https://elixir.bootlin.com/linux/latest/source/include/linux/netdevice.h#L4125
> 
> However for users this creates confusion:
> https://serverfault.com/questions/629676/dummy-network-interface-in-linux
> 
> The change in this patch is very simple. When the interface is set up, the
> operational state is set to IF_OPER_UP.
> 
> Signed-off-by: Kaarel Pärtel <kaarelp2rtel@gmail.com>

You can change the carrier state from user space on a dummy device,
that will inform the kernel of the operstate:

# ip link add type dummy
# ip link show dev dummy0
8: dummy0: <BROADCAST,NOARP> mtu 1500 qdisc noop state DOWN mode DEFAULT group default qlen 1000
    link/ether 8e:35:15:22:e3:d7 brd ff:ff:ff:ff:ff:ff
# ip link set dev dummy0 up
# ip link show dev dummy0
8: dummy0: <BROADCAST,NOARP,UP,LOWER_UP> mtu 1500 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1000
    link/ether 8e:35:15:22:e3:d7 brd ff:ff:ff:ff:ff:ff
# ip link set dev dummy0 carrier off
# ip link set dev dummy0 carrier on
# ip link show dev dummy0
8: dummy0: <BROADCAST,NOARP,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP mode DEFAULT group default qlen 1000
    link/ether 8e:35:15:22:e3:d7 brd ff:ff:ff:ff:ff:ff


Flipping all soft devices which don't have a lower or don't expect user
space management to UP is fine but doing it one by one feels icky.
Yet another random thing a driver author has to know to flip.

If people are confused about seeing UNKNOWN in ip link output maybe we
should move displaying that under the -d flag (detailed output)?
Saves space, and nobody will get confused.

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

* Re: [PATCH] net: add operstate for vcan and dummy
  2022-06-02  8:19 [PATCH] net: add operstate for vcan and dummy Kaarel Pärtel
  2022-06-03  2:46 ` Jakub Kicinski
@ 2022-06-03  3:39 ` Stephen Hemminger
  1 sibling, 0 replies; 3+ messages in thread
From: Stephen Hemminger @ 2022-06-03  3:39 UTC (permalink / raw)
  To: Kaarel Pärtel
  Cc: Wolfgang Grandegger, Marc Kleine-Budde, David S. Miller,
	Eric Dumazet, Jakub Kicinski, Paolo Abeni, linux-can, netdev,
	linux-kernel

On Thu,  2 Jun 2022 11:19:29 +0300
Kaarel Pärtel <kaarelp2rtel@gmail.com> wrote:

> The idea here is simple. The vcan and the dummy network devices
> currently do not set the operational state of the interface.
> The result is that the interface state will be UNKNOWN.
> 
> The kernel considers the unknown state to be the same as up:
> https://elixir.bootlin.com/linux/latest/source/include/linux/netdevice.h#L4125
> 
> However for users this creates confusion:
> https://serverfault.com/questions/629676/dummy-network-interface-in-linux
> 
> The change in this patch is very simple. When the interface is set up, the
> operational state is set to IF_OPER_UP.
> 
> Signed-off-by: Kaarel Pärtel <kaarelp2rtel@gmail.com>
> ---
>  drivers/net/can/vcan.c | 1 +
>  drivers/net/dummy.c    | 1 +
>  2 files changed, 2 insertions(+)
> 
> diff --git a/drivers/net/can/vcan.c b/drivers/net/can/vcan.c
> index a15619d883ec..79768f9d4294 100644
> --- a/drivers/net/can/vcan.c
> +++ b/drivers/net/can/vcan.c
> @@ -162,6 +162,7 @@ static void vcan_setup(struct net_device *dev)
>  
>  	dev->netdev_ops		= &vcan_netdev_ops;
>  	dev->needs_free_netdev	= true;
> +	dev->operstate = IF_OPER_UP;
>  }
>  
>  static struct rtnl_link_ops vcan_link_ops __read_mostly = {
> diff --git a/drivers/net/dummy.c b/drivers/net/dummy.c
> index f82ad7419508..ab128f66de00 100644
> --- a/drivers/net/dummy.c
> +++ b/drivers/net/dummy.c
> @@ -133,6 +133,7 @@ static void dummy_setup(struct net_device *dev)
>  
>  	dev->min_mtu = 0;
>  	dev->max_mtu = 0;
> +	dev->operstate = IF_OPER_UP;
>  }
>  
>  static int dummy_validate(struct nlattr *tb[], struct nlattr *data[],

Normally carrier state is propogated to operstate by linkwatch.
You may need to add a call for that.


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

end of thread, other threads:[~2022-06-03  3:39 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-02  8:19 [PATCH] net: add operstate for vcan and dummy Kaarel Pärtel
2022-06-03  2:46 ` Jakub Kicinski
2022-06-03  3:39 ` Stephen Hemminger

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.