[v2] net: dsa: use more appropriate NET_NAME_* constants for user ports
Commit Message
When a user port has a label in device tree, the corresponding
netdevice is "predictably named by the kernel".
Expose that information properly for the benefit of userspace tools
that make decisions based on the name_assign_type attribute,
e.g. a systemd-udev rule with "kernel" in NamePolicy.
Similarly, when we fall back to the eth%d scheme, the proper constant
to use is NET_NAME_ENUM. See also commit e9f656b7a214 ("net: ethernet:
set default assignment identifier to NET_NAME_ENUM"), which in turn
quoted commit 685343fc3ba6 ("net: add name_assign_type netdev
attribute"):
... when the kernel has given the interface a name using global
device enumeration based on order of discovery (ethX, wlanY, etc)
... are labelled NET_NAME_ENUM.
Signed-off-by: Rasmus Villemoes <linux@rasmusvillemoes.dk>
---
v2: switch to NET_NAME_ENUM in the eth%d case (Andrew, Jakub). Update
commit message accordingly.
net/dsa/dsa2.c | 3 ---
net/dsa/slave.c | 13 +++++++++++--
2 files changed, 11 insertions(+), 5 deletions(-)
Comments
On Tue, 15 Nov 2022 08:43:55 +0100 Rasmus Villemoes wrote:
> + if (port->name) {
> + name = port->name;
> + assign_type = NET_NAME_PREDICTABLE;
> + } else {
> + name = "eth%d";
> + assign_type = NET_NAME_ENUM;
Per Andrew's comment lets make the change in two steps.
Which one should come first is a judgment call :)
On 15/11/2022 17.38, Jakub Kicinski wrote:
> On Tue, 15 Nov 2022 08:43:55 +0100 Rasmus Villemoes wrote:
>> + if (port->name) {
>> + name = port->name;
>> + assign_type = NET_NAME_PREDICTABLE;
>> + } else {
>> + name = "eth%d";
>> + assign_type = NET_NAME_ENUM;
>
> Per Andrew's comment lets make the change in two steps.
> Which one should come first is a judgment call :)
OK. I think I'll actually do it in three steps, with the first being
this patch but with NET_NAME_UNKNOWN kept in both places (i.e. pure
refactoring), and the latter two just changing one assign_type at a
time, so they can be reverted independently.
Rasmus
On Tue, 15 Nov 2022 19:55:24 +0100 Rasmus Villemoes wrote:
> OK. I think I'll actually do it in three steps, with the first being
> this patch but with NET_NAME_UNKNOWN kept in both places (i.e. pure
> refactoring), and the latter two just changing one assign_type at a
> time, so they can be reverted independently.
Even better :)
@@ -1364,9 +1364,6 @@ static struct dsa_port *dsa_port_touch(struct dsa_switch *ds, int index)
static int dsa_port_parse_user(struct dsa_port *dp, const char *name)
{
- if (!name)
- name = "eth%d";
-
dp->type = DSA_PORT_TYPE_USER;
dp->name = name;
@@ -2374,16 +2374,25 @@ int dsa_slave_create(struct dsa_port *port)
{
struct net_device *master = dsa_port_to_master(port);
struct dsa_switch *ds = port->ds;
- const char *name = port->name;
struct net_device *slave_dev;
struct dsa_slave_priv *p;
+ const char *name;
+ int assign_type;
int ret;
if (!ds->num_tx_queues)
ds->num_tx_queues = 1;
+ if (port->name) {
+ name = port->name;
+ assign_type = NET_NAME_PREDICTABLE;
+ } else {
+ name = "eth%d";
+ assign_type = NET_NAME_ENUM;
+ }
+
slave_dev = alloc_netdev_mqs(sizeof(struct dsa_slave_priv), name,
- NET_NAME_UNKNOWN, ether_setup,
+ assign_type, ether_setup,
ds->num_tx_queues, 1);
if (slave_dev == NULL)
return -ENOMEM;