How to tell whether device has network switch ports (DSA vs swconfig)?

Hi. What is the best way to determine on a running device (CLI command) whether or not it has network switch ports? I think I'm looking for the equivalent of determining whether or not the device's web UI will show a "Network > Switch" page for configuring VLANs and tags.

For example:

  • I have an x86/64 machine with multiple Ethernet ports (eth0-eth3) that does not have such a section in its UI
  • The Netgear WAC124 (ramips/mt7621) reports a single eth0, and also does not have those switch ports
  • The TP-Link Archer (ath79/generic) and Asus RT-N66U (bcm47xx/mips74k, albeit no WiFi) both report a single eth0, and do have a "Network > Switch" section in the web UI.

The closest thing I've found so far is that the Archer has a "uci show network.@switch[0]" available (e.g., a switch in /etc/config/network), but I was wondering if there was something more robust I could use, like something I could inspect in /proc or something like that.

Thank you

If you have the old switch menu in Luci (from 21.02) depends more if your device have DSA implemented or not. It doesn’t have much to do if you have a switch or not.
DSA = no switch menu.
Swconfig = switch menu

I see. So at some point when all devices have DSA support, I believe you are implying there will be no switch menu at all on any device.

Is there a special kernel module or something I can look (e.g., lsmod|grep) for to determine at runtime whether the device has DSA? How does the web UI know whether or not to display the "Switch" menu (the JavaScript code at /www/luci-static/resources/network.js seems to be figuring this all out at runtime, rather than being specifically built for the device).

Thank you.

You can use " ls -l /sys/class/net "

DSA have a switch menu under interface settings. It is called Devices.

But if you ask me, the day we finally get rid of swconfig the Luci menu system should have a L2 and L3 top menu with submenues for the functions like switch, interfaces etc.

You can use " ls -l /sys/class/net "

What am I looking for under /sys/class/net to determine whether or not the device is swconfig vs. DSA?

I should have stated my goal. I have a script to configure my devices via UCI (I copy script to device, then run the script on the device). Configuring VLANs may or may not involve network switch configuration.

The best I have come up with so far is to query network.@switch[0] to see if the device initially had one or not, but that feels a little fragile to me, so I would prefer to query something more intrinsic to the kernel or the OpenWrt image or something like that, that would be robust to a misconfiguration on my part.

Have you seen this Thread? Perhaps someone has posted something there that will stimulate your pursuit.

A few rules of thumb:

  • Prosumer or consumer x86/x86_64 systems with a built-in switch are pretty much non-existent. Almost all of them use separate NICs (Realtek, Intel, sometimes Atheros NICs).
  • Most dedicated consumer network hardware relies on SoCs with built-in switches.
  • Even access points etc. with a single physical network port often have a switch inside (part of the SoC).

I did find something that is a little better than examining existing uci configuration. On a TP-Link Archer A7:

# swconfig list
Found: switch0 - mdio.0

On an x86/64 in QEMU:

# type swconfig
swconfig: not found

Is it possible for a DSA-enabled image to still include the swconfig tool for some reason?

All devices I have no matter what with 21.02 installed have DSA setup and menus.
But some like the eap245v3 still needs swconfig to be the extra link between the actual port and the OpenWrt firmware.

No, it's an ath79 device and ath79 hasn't been ported to DSA yet (AFAIK just a few ath79 devices support DSA on OpenWrt at this point).

@CaptainBegin Swconfig and DSA are mutually exclusive AFAIK, and you're looking at kernel level changes, ie device drivers to talk to the switch fabric. So you cannot have both an you can't just swap them in and out at will. On how to find out if your device is using DSA and not swconfig, see this topic:

2 Likes

I still have to set up and configure them both.

Swconfig and DSA are mutually exclusive AFAIK

see this topic:

Thank you very much, this is the kind of thing I am looking for. But now I am still confused. Exactly one of swconfig or DSA must be present, or is there a third? On an x86/64 machine (4 NICs, but only eth0 has VLANs on it):

# uname -a
Linux gateway 5.4.154 #0 SMP Sun Oct 24 09:01:35 2021 x86_64 GNU/Linux

# cat /etc/openwrt_release 
DISTRIB_ID='OpenWrt'
DISTRIB_RELEASE='21.02.1'
DISTRIB_REVISION='r16325-88151b8303'
DISTRIB_TARGET='x86/64'
DISTRIB_ARCH='x86_64'
DISTRIB_DESCRIPTION='OpenWrt 21.02.1 r16325-88151b8303'
DISTRIB_TAINTS=''

# grep DEVTYPE /sys/class/net/*/uevent
/sys/class/net/br-lan/uevent:DEVTYPE=bridge
/sys/class/net/br-lan1/uevent:DEVTYPE=bridge
/sys/class/net/br-lan2/uevent:DEVTYPE=bridge
/sys/class/net/br-lan3/uevent:DEVTYPE=bridge
/sys/class/net/eth0.3/uevent:DEVTYPE=vlan
/sys/class/net/eth0.4/uevent:DEVTYPE=vlan
/sys/class/net/eth0.5/uevent:DEVTYPE=vlan

So neither DEVTYPE=dsa is present, nor is the swconfig tool ...

Like I said earlier, x86/x86_64 systems have separate NICs 99% of the time. Swconfig and DSA are both frameworks designed to allow you to manipulate single ports of a switch as if they were a separate interface, that does not apply when you are dealing with separate NICs already.

Thank you!

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.