X86 with two rtl8156 usb dongles

Hi,

Trying to upgrade part of my network to 2.5gb. When I add a second usb 3.0 adapter to my 2012 era Zotac ID-82 I get strange behavior. I don't understand how the mapping from usb adapter to device is achieved.

Here's output from two boots.

'''
[ 6.949340] usbcore: registered new interface driver cdc_ether
[ 6.957458] urngd: v1.0.2 started.
[ 6.973182] cdc_ncm 4-1:2.0: MAC-Address: xx:xx:xx:3f:6a:33
[ 6.973340] cdc_ncm 4-1:2.0: setting rx_max = 16384
[ 6.973930] cdc_ncm 4-1:2.0: setting tx_max = 16384
[ 6.974801] cdc_ncm 4-1:2.0 eth1: register 'cdc_ncm' at usb-0000:02:00.0-1, CDC NCM, xx:xx:xx:3f:6a:33
[ 6.993057] cdc_ncm 4-2:2.0: MAC-Address: xx:xx:xx:3d:da:cd
[ 6.993217] cdc_ncm 4-2:2.0: setting rx_max = 16384
[ 6.993804] cdc_ncm 4-2:2.0: setting tx_max = 16384
[ 6.994641] cdc_ncm 4-2:2.0 eth2: register 'cdc_ncm' at usb-0000:02:00.0-2, CDC NCM, xx:xx:xx:3d:da:cd

[ 6.943317] cdc_ncm 4-2:2.0: MAC-Address: xx:xx:xx:3d:da:cd
[ 6.943481] cdc_ncm 4-2:2.0: setting rx_max = 16384
[ 6.944064] cdc_ncm 4-2:2.0: setting tx_max = 16384
[ 6.944936] cdc_ncm 4-2:2.0 eth1: register 'cdc_ncm' at usb-0000:02:00.0-2, CDC NCM, xx:xx:xx:3d:da:cd
[ 6.963189] cdc_ncm 4-1:2.0: MAC-Address: xx:xx:xx:3f:6a:33
[ 6.963356] cdc_ncm 4-1:2.0: setting rx_max = 16384
[ 6.963938] cdc_ncm 4-1:2.0: setting tx_max = 16384
[ 6.964805] cdc_ncm 4-1:2.0 eth2: register 'cdc_ncm' at usb-0000:02:00.0-1, CDC NCM, xx:xx:xx:3f:6a:33
'''

Is this a race condition? Where can I codify which usb adapter shows up as which openwrt device?

I'm running OpenWrt 23.05.0-rc4 r23482-7fe85ce1f2 / LuCI openwrt-23.05 branch git-23.236.53405-fc638c8

Thanks!

Are you inserting and removing devices while the machine is running?

I certainly don't need to be able to hotplug it, but I'd like the configuration to survive an upgrade.

It doesn't seem to be dependent on the dongle's MAC nor upon which of the usb ports the dongle is plugged into. Knowing which wire is eth1 and which is eth2 seems important.

Thanks so much,

The answer you deleted seemed to better answer my inquiry.

To be clear:

  • You're saying the USB-based eth1 and eth2 alternate when rebooting the device - as evidenced by the MAC change?
  • This occurs without touching or moving the USB ports between boots?

No. I believe that they were unplugged and replugged (into the same usb3 socket
as before) between those two boots.

I will work on it some more and report back.

Thanks, so much for your help.

1 Like

This is always a problem when using multiple identical USB devices. It is a race condition to detect them on the bus and assign to drivers. See if they have unique USB serial numbers. I believe you can register by serial number in hotplug. The MAC address is not visible during initial enumeration so it's not useful to distinguish them.

2 Likes

There's https://openwrt.org/docs/guide-user/base-system/hotplug#rename_interfaces_by_mac_address

2 Likes

Cool, I didn't know that could be done.

This is great.

I'm trying to keep up. I followed the instructions at: https://openwrt.org/docs/guide-user/base-system/hotplug#rename_interfaces_by_mac_address.

I've added the file /etc/hotplug.d/iface/00-dev-rename with the code from the web page. I added:

exec >>/root/hotplug.log 2>&1

to the top of 00-dev-rename for logging. Then I rebooted.

Now, the contents of hotplug.log is:

ip: SIOCSIFNAME: No such device
ip: SIOCSIFNAME: No such device
.
.
.

If I issue uci commands, nothing happens:

root@OpenWrt:~# echo ${DEV_NAME}
usb_lan
root@OpenWrt:~# uci set network.${DEV_NAME}.device="${DEV_NAME}"
uci: Invalid argument

After some cleanup, I pasted all of the code into my console thus automatically creating 00-dev-rename and creating the two desired network devices usb-lan and usb-wan:

Here's the output:

root@OpenWrt:~# cat << "EOF" > /etc/hotplug.d/iface/00-dev-rename
> dev_rename() {
> local DEV_CONF="${1}"
> local DEV_ONAME DEV_NAME DEV_MAC
> config_get DEV_NAME "${DEV_CONF}" name
> config_get DEV_MAC "${DEV_CONF}" mac
> DEV_ONAME="$(grep -l -e "${DEV_MAC}" \
> $(find /sys/class/net/*/device/uevent \
> | sed -e "s|/device/uevent$|/address|") \
> | awk -F '/' '{print $5}')"
> if [ "${DEV_ONAME}" != "${DEV_NAME}" ]
> then ip link set "${DEV_ONAME}" name "${DEV_NAME}"
> fi
> }
> . /lib/functions.sh
> config_load network
> config_foreach dev_rename device
> EOF
root@OpenWrt:~#  
root@OpenWrt:~# while read -r DEV_NAME DEV_MAC
> do
> uci set network.${DEV_NAME}.device="${DEV_NAME}"
> uci set network.${DEV_NAME}6.device="${DEV_NAME}"
> uci -q delete network.${DEV_NAME}_dev
> uci set network.${DEV_NAME}_dev="device"
> uci set network.${DEV_NAME}_dev.name="${DEV_NAME}"
> uci set network.${DEV_NAME}_dev.mac="${DEV_MAC}"
> done << EOI
> usb_lan 11:22:33:44:55:77
> usb_wan 11:22:33:44:55:66
> EOI
uci: Invalid argument
uci: Invalid argument
uci: Invalid argument
uci: Invalid argument
root@OpenWrt:~# uci commit network
root@OpenWrt:~# /etc/init.d/network restart
root@OpenWrt:~# uci show network.usb_lan
uci: Entry not found

uci show network:

network.usb_lan_dev=device
network.usb_lan_dev.name='usb_lan'
network.usb_lan_dev.mac='11:22:33:44:55:66'
network.usb_wan_dev=device
network.usb_wan_dev.name='usb_wan'
network.usb_wan_dev.mac='11:22:33:44:55:77'

Back in luci, usb_lan and usb_wan are there, but I cant do anything with them and they aren't associated with a mac address.

The instructions call for preconfiguring usb_lan and usb_wan . Perhaps that is the part I am not achieving.

Thanks!

As a follow up, were any are able to assign a device to a fix name ? Indeed the kind of script do call for many variable.. But how can we just set : the mac adress of the dongle and set a proper name when detection ?