net: loopback: use NET_NAME_PREDICTABLE for name_assign_type

Message ID 20221123141829.1825170-1-linux@rasmusvillemoes.dk
State New
Headers
Series net: loopback: use NET_NAME_PREDICTABLE for name_assign_type |

Commit Message

Rasmus Villemoes Nov. 23, 2022, 2:18 p.m. UTC
  When the name_assign_type attribute was introduced (commit
685343fc3ba6, "net: add name_assign_type netdev attribute"), the
loopback device was explicitly mentioned as one which would make use
of NET_NAME_PREDICTABLE:

    The name_assign_type attribute gives hints where the interface name of a
    given net-device comes from. These values are currently defined:
...
      NET_NAME_PREDICTABLE:
        The ifname has been assigned by the kernel in a predictable way
        that is guaranteed to avoid reuse and always be the same for a
        given device. Examples include statically created devices like
        the loopback device [...]

Switch to that so that reading /sys/class/net/lo/name_assign_type
produces something sensible instead of returning -EINVAL.

Signed-off-by: Rasmus Villemoes <linux@rasmusvillemoes.dk>
---

This is mostly cosmetic, but ideally I'd like to get to a situation
where I don't need to do

  assign_type=$(cat /sys/class/net/$dev/name_assign_type 2> /dev/null || echo 0)

or otherwise special-case [ $dev = "lo" ].

As always, there's a small chance that this could cause a regression,
but it seems extremely unlikely that anybody relies on
/sys/class/net/lo/name_assign_type being unreadable and thus
effectively is known to be NET_NAME_UNKNOWN.

 drivers/net/loopback.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
  

Comments

Jacob Keller Nov. 23, 2022, 8:16 p.m. UTC | #1
> -----Original Message-----
> From: Rasmus Villemoes <linux@rasmusvillemoes.dk>
> Sent: Wednesday, November 23, 2022 6:18 AM
> To: David S. Miller <davem@davemloft.net>; Eric Dumazet
> <edumazet@google.com>; Jakub Kicinski <kuba@kernel.org>; Paolo Abeni
> <pabeni@redhat.com>
> Cc: Rasmus Villemoes <linux@rasmusvillemoes.dk>; netdev@vger.kernel.org;
> linux-kernel@vger.kernel.org
> Subject: [PATCH] net: loopback: use NET_NAME_PREDICTABLE for
> name_assign_type
> 
> When the name_assign_type attribute was introduced (commit
> 685343fc3ba6, "net: add name_assign_type netdev attribute"), the
> loopback device was explicitly mentioned as one which would make use
> of NET_NAME_PREDICTABLE:
> 
>     The name_assign_type attribute gives hints where the interface name of a
>     given net-device comes from. These values are currently defined:
> ...
>       NET_NAME_PREDICTABLE:
>         The ifname has been assigned by the kernel in a predictable way
>         that is guaranteed to avoid reuse and always be the same for a
>         given device. Examples include statically created devices like
>         the loopback device [...]
> 

Heh, so the doc says loopback is an example of this but we weren't using it for that :D

> Switch to that so that reading /sys/class/net/lo/name_assign_type
> produces something sensible instead of returning -EINVAL.
> 

This seems reasonable to me.

> Signed-off-by: Rasmus Villemoes <linux@rasmusvillemoes.dk>
> ---
> 
> This is mostly cosmetic, but ideally I'd like to get to a situation
> where I don't need to do
> 
>   assign_type=$(cat /sys/class/net/$dev/name_assign_type 2> /dev/null || echo
> 0)
> 
> or otherwise special-case [ $dev = "lo" ].
> 
> As always, there's a small chance that this could cause a regression,
> but it seems extremely unlikely that anybody relies on
> /sys/class/net/lo/name_assign_type being unreadable and thus
> effectively is known to be NET_NAME_UNKNOWN.
> 

I don't think I would consider this a regression. Previously name_assign_type was returning an error here, now it reports something useful. And we know the name is predictable because 
it is the loopback device.

Reviewed-by: Jacob Keller <jacob.e.keller@intel.com>

>  drivers/net/loopback.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/net/loopback.c b/drivers/net/loopback.c
> index 14e8d04cb434..2e9742952c4e 100644
> --- a/drivers/net/loopback.c
> +++ b/drivers/net/loopback.c
> @@ -211,7 +211,7 @@ static __net_init int loopback_net_init(struct net *net)
>  	int err;
> 
>  	err = -ENOMEM;
> -	dev = alloc_netdev(0, "lo", NET_NAME_UNKNOWN, loopback_setup);
> +	dev = alloc_netdev(0, "lo", NET_NAME_PREDICTABLE, loopback_setup);
>  	if (!dev)
>  		goto out;
> 
> --
> 2.37.2
  
patchwork-bot+netdevbpf@kernel.org Nov. 25, 2022, 9:50 a.m. UTC | #2
Hello:

This patch was applied to netdev/net.git (master)
by David S. Miller <davem@davemloft.net>:

On Wed, 23 Nov 2022 15:18:28 +0100 you wrote:
> When the name_assign_type attribute was introduced (commit
> 685343fc3ba6, "net: add name_assign_type netdev attribute"), the
> loopback device was explicitly mentioned as one which would make use
> of NET_NAME_PREDICTABLE:
> 
>     The name_assign_type attribute gives hints where the interface name of a
>     given net-device comes from. These values are currently defined:
> ...
>       NET_NAME_PREDICTABLE:
>         The ifname has been assigned by the kernel in a predictable way
>         that is guaranteed to avoid reuse and always be the same for a
>         given device. Examples include statically created devices like
>         the loopback device [...]
> 
> [...]

Here is the summary with links:
  - net: loopback: use NET_NAME_PREDICTABLE for name_assign_type
    https://git.kernel.org/netdev/net/c/31d929de5a11

You are awesome, thank you!
  

Patch

diff --git a/drivers/net/loopback.c b/drivers/net/loopback.c
index 14e8d04cb434..2e9742952c4e 100644
--- a/drivers/net/loopback.c
+++ b/drivers/net/loopback.c
@@ -211,7 +211,7 @@  static __net_init int loopback_net_init(struct net *net)
 	int err;
 
 	err = -ENOMEM;
-	dev = alloc_netdev(0, "lo", NET_NAME_UNKNOWN, loopback_setup);
+	dev = alloc_netdev(0, "lo", NET_NAME_PREDICTABLE, loopback_setup);
 	if (!dev)
 		goto out;