lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:   Tue, 9 Aug 2022 16:17:01 -0700
From:   Tim Harvey <tharvey@...eworks.com>
To:     Pali Rohár <pali@...nel.org>
Cc:     Sean Anderson <sean.anderson@...o.com>,
        Michal Suchánek <msuchanek@...e.de>,
        Stephen Hemminger <stephen@...workplumber.org>,
        netdev <netdev@...r.kernel.org>, u-boot <u-boot@...ts.denx.de>,
        Device Tree Mailing List <devicetree@...r.kernel.org>
Subject: Re: ethernet<n> dt aliases implications in U-Boot and Linux

On Tue, Aug 9, 2022 at 3:45 PM Pali Rohár <pali@...nel.org> wrote:
>
> On Tuesday 09 August 2022 18:41:25 Sean Anderson wrote:
> >
> >
> > On 8/9/22 5:42 PM, Pali Rohár wrote:
> > > On Tuesday 09 August 2022 17:36:52 Sean Anderson wrote:
> > >> On 8/9/22 5:31 PM, Pali Rohár wrote:
> > >> > On Tuesday 09 August 2022 16:48:23 Sean Anderson wrote:
> > >> >> On 8/8/22 5:45 PM, Michal Suchánek wrote:
> > >> >> > On Mon, Aug 08, 2022 at 02:38:35PM -0700, Stephen Hemminger wrote:
> > >> >> >> On Mon, 8 Aug 2022 23:09:45 +0200
> > >> >> >> Michal Suchánek <msuchanek@...e.de> wrote:
> > >> >> >>
> > >> >> >> > On Mon, Aug 08, 2022 at 03:57:55PM -0400, Sean Anderson wrote:
> > >> >> >> > > Hi Tim,
> > >> >> >> > >
> > >> >> >> > > On 8/8/22 3:18 PM, Tim Harvey wrote:
> > >> >> >> > > > Greetings,
> > >> >> >> > > >
> > >> >> >> > > > I'm trying to understand if there is any implication of 'ethernet<n>'
> > >> >> >> > > > aliases in Linux such as:
> > >> >> >> > > >         aliases {
> > >> >> >> > > >                 ethernet0 = &eqos;
> > >> >> >> > > >                 ethernet1 = &fec;
> > >> >> >> > > >                 ethernet2 = &lan1;
> > >> >> >> > > >                 ethernet3 = &lan2;
> > >> >> >> > > >                 ethernet4 = &lan3;
> > >> >> >> > > >                 ethernet5 = &lan4;
> > >> >> >> > > >                 ethernet6 = &lan5;
> > >> >> >> > > >         };
> > >> >> >> > > >
> > >> >> >> > > > I know U-Boot boards that use device-tree will use these aliases to
> > >> >> >> > > > name the devices in U-Boot such that the device with alias 'ethernet0'
> > >> >> >> > > > becomes eth0 and alias 'ethernet1' becomes eth1 but for Linux it
> > >> >> >> > > > appears that the naming of network devices that are embedded (ie SoC)
> > >> >> >> > > > vs enumerated (ie pci/usb) are always based on device registration
> > >> >> >> > > > order which for static drivers depends on Makefile linking order and
> > >> >> >> > > > has nothing to do with device-tree.
> > >> >> >> > > >
> > >> >> >> > > > Is there currently any way to control network device naming in Linux
> > >> >> >> > > > other than udev?
> > >> >> >> > >
> > >> >> >> > > You can also use systemd-networkd et al. (but that is the same kind of mechanism)
> > >> >> >> > >
> > >> >> >> > > > Does Linux use the ethernet<n> aliases for anything at all?
> > >> >> >> > >
> > >> >> >> > > No :l
> > >> >> >> >
> > >> >> >> > Maybe it's a great opportunity for porting biosdevname to DT based
> > >> >> >> > platforms ;-)
> > >> >> >>
> > >> >> >> Sorry, biosdevname was wrong way to do things.
> > >> >> >> Did you look at the internals, it was dumpster diving as root into BIOS.
> > >> >> >
> > >> >> > When it's BIOS what defines the names then you have to read them from
> > >> >> > the BIOS. Recently it was updated to use some sysfs file or whatver.
> > >> >> > It's not like you would use any of that code with DT, anyway.
> > >> >> >
> > >> >> >> Systemd-networkd does things in much more supportable manner using existing
> > >> >> >> sysfs API's.
> > >> >> >
> > >> >> > Which is a dumpster of systemd code, no thanks.
> > >> >> >
> > >> >> > I want my device naming independent of the init system, especially if
> > >> >> > it's systemd.
> > >> >>
> > >> >> Well, there's always nameif...
> > >> >>
> > >> >> That said, I have made [1] for people using systemd-networkd.
> > >> >>
> > >> >> --Sean
> > >> >>
> > >> >> [1] https://github.com/systemd/systemd/pull/24265
> > >> >
> > >> > Hello!
> > >> >
> > >> > In some cases "label" DT property can be used also as interface name.
> > >> > For example this property is already used by DSA kernel driver.
> > >> >
> > >> > I created very simple script which renames all interfaces in system to
> > >> > their "label" DT property (if there is any defined).
> > >> >
> > >> > #!/bin/sh
> > >> > for iface in `ls /sys/class/net/`; do
> > >> >  for of_node in of_node device/of_node; do
> > >> >          if test -e /sys/class/net/$iface/$of_node/; then
> > >> >                  label=`cat /sys/class/net/$iface/$of_node/label 2>/dev/null`
> > >> >                  if test -n "$label" && test "$label" != "$iface"; then
> > >> >                          echo "Renaming net interface $iface to $label..."
> > >> >                          up=$((`cat /sys/class/net/$iface/flags 2>/dev/null || echo 1` & 0x1))
> > >> >                          if test "$up" != "0"; then
> > >> >                                  ip link set dev $iface down
> > >> >                          fi
> > >> >                          ip link set dev $iface name "$label" && iface=$label
> > >> >                          if test "$up" != "0"; then
> > >> >                                  ip link set dev $iface up
> > >> >                          fi
> > >> >                  fi
> > >> >                  break
> > >> >          fi
> > >> >  done
> > >> > done
> > >> >
> > >> > Maybe it would be better first to use "label" and then use ethernet alias?
> > >> >
> > >>
> > >> It looks like there is already precedent for using ID_NET_LABEL_ONBOARD for
> > >> this purpose (on SMBios boards). It should be a fairly simple extension to
> > >> add that as well. However, I didn't find any uses of this in Linux or U-Boot
> > >> (although I did find plenty of ethernet LEDs). Do you have an example you
> > >> could point me to?
> > >>
> > >> --Sean
> > >
> > > In linux:
> > > $ git grep '"label"' net/dsa/dsa2.c
> > > net/dsa/dsa2.c: const char *name = of_get_property(dn, "label", NULL);
> > >
> >
> > Hm, if Linux is using the label, then do we need to rename things in userspace?
>
> It uses it _only_ for DSA drivers. For all other drivers (e.g. USB or
> PCIe based network adapters) it does not use label.

and to my point it doesn't use label for platform devices.

Is something like the following really that crazy of an idea?
diff --git a/net/core/dev.c b/net/core/dev.c
index e0878a500aa9..a679c74a63c6 100644
--- a/net/core/dev.c
+++ b/net/core/dev.c
@@ -1151,6 +1151,15 @@ static int dev_alloc_name_ns(struct net *net,
        int ret;

        BUG_ON(!net);
+#ifdef CONFIG_OF
+       if (dev->dev.parent && dev->dev.parent->of_node) {
+               const char *name =
of_get_property(dev->dev.parent->of_node, "label", NULL);
+               if (name) {
+                       strlcpy(dev->name, name, IFNAMSIZ);
+                       return 0;
+               }
+       }
+#endif
        ret = __dev_alloc_name(net, name, buf);
        if (ret >= 0)
                strlcpy(dev->name, buf, IFNAMSIZ);

I still like using the index from aliases/ethernet* instead as there
is a precedence for that in other Linux drivers as well as U-Boot

Best Regards,

Tim

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ