了解Linux以太网设备

了解Linux以太网设备

我在 mips SoC 上有一个小型、嵌入式、完全自交叉编译的安装。

SoC 基于 Mediatek MT7628,配备 Wifi 接口(仅 2.4MHz)、100Mbps 以太网 MAC 和内部 5 端口以太网交换机(其中一个端口连接到 MAC)。

我将以太网设备驱动程序(mtk-eth.ko)编译为可安装模块。

如果我启动没有该模块(我实际上重命名了它,因此udevd无法“自动”安装它)我没有以太网设备,正如预期的那样:

# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
3: wlan0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue qlen 1000
    link/ether b8:d8:12:64:b9:a0 brd ff:ff:ff:ff:ff:ff
    inet 192.168.7.130/24 brd 192.168.7.255 scope global noprefixroute wlan0
       valid_lft forever preferred_lft forever

到目前为止没有什么奇怪的。接下来我手动安装该模块:

# modprobe mtk-eth
[ 6591.429607] mtk_soc_eth 10100000.ethernet: generated random MAC address 0a:90:77:c7:1d:f3
[ 6591.461683] mtk_soc_eth 10100000.ethernet eth0: mediatek frame engine at 0xb0100000, irq 5
[ 6591.659810] libphy: dsa slave smi: probed
[ 6591.674778] mt7628-esw 10110000.esw: nonfatal error -122 setting MTU on port 0
[ 6591.693746] mt7628-esw 10110000.esw lan (uninitialized): PHY [dsa-0.0:00] driver [Generic PHY] (irq=POLL)
[ 6591.728356] mt7628-esw 10110000.esw: configuring for fixed/mii link mode
[ 6591.736381] DSA: tree 0 setup
[ 6591.751095] mt7628-esw 10110000.esw: Link is Up - 100Mbps/Full - flow control off
[ 6595.094324] mt7628-esw 10110000.esw: port 0 link changed 0x1
# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
3: wlan0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue qlen 1000
    link/ether b8:d8:12:64:b9:a0 brd ff:ff:ff:ff:ff:ff
    inet 192.168.7.130/24 brd 192.168.7.255 scope global noprefixroute wlan0
       valid_lft forever preferred_lft forever
4: eth0: <BROADCAST,MULTICAST> mtu 1500 qdisc noop qlen 1000
    link/ether 0a:90:77:c7:1d:f3 brd ff:ff:ff:ff:ff:ff
5: lan@eth0: <BROADCAST,MULTICAST,M-DOWN> mtu 1500 qdisc noop qlen 1000
    link/ether 0a:90:77:c7:1d:f3 brd ff:ff:ff:ff:ff:ff

这给了我devices:意料之中的eth0,意外的lan@eth0但仍然没有连接。这是正确的,因为我没有运行 DHCP 客户端(WiFi 由 IWD 单独处理)。

启动 DHCP 客户端即可连接:

# dhcpcd -b eth0
dhcpcd-9.4.0 starting
sandbox unavailable: seccomp
DUID 00:01:00:01:c7:92:bc:8f:b8:d8:12:64:b9:a2
dhcp_vendor: No such process
sandbox unavailable: seccomp
forked to background, child pid 850
[ 6671.439622] mtk_soc_eth 10100000.ethernet eth0: configuring for fixed/mii link mode
[ 6671.447753] mtk_soc_eth 10100000.ethernet eth0: Link is Up - 100Mbps/Full - flow control rx/tx
# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
3: wlan0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue qlen 1000
    link/ether b8:d8:12:64:b9:a0 brd ff:ff:ff:ff:ff:ff
    inet 192.168.7.130/24 brd 192.168.7.255 scope global noprefixroute wlan0
       valid_lft forever preferred_lft forever
5: lan@if4: <BROADCAST,MULTICAST,M-DOWN> mtu 1500 qdisc noop qlen 1000
    link/ether 0a:90:77:c7:1d:f3 brd ff:ff:ff:ff:ff:ff
6: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast qlen 1000
    link/ether 9a:cf:60:d9:2e:a1 brd ff:ff:ff:ff:ff:ff
    inet 192.168.7.106/24 brd 192.168.7.255 scope global dynamic noprefixroute eth0
       valid_lft 43191sec preferred_lft 37791sec

请注意,只有“标准”eth0实际上获得了 IP 地址,而“辅助”接口更改了名称lan@eth0-> lan@if4

第二个“设备”是什么?它的目的是什么以及我应该如何使用它(IFF我应该使用它)。还请注意,关闭eth0实际上似乎作用于“辅助”设备:

# ip l set eth0 down
[ 8558.176702] mtk_soc_eth 10100000.ethernet eth0: Link is Down
# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
3: wlan0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue qlen 1000
    link/ether b8:d8:12:64:b9:a0 brd ff:ff:ff:ff:ff:ff
    inet 192.168.7.130/24 brd 192.168.7.255 scope global noprefixroute wlan0
       valid_lft forever preferred_lft forever
5: lan@if4: <BROADCAST,MULTICAST,M-DOWN> mtu 1500 qdisc noop qlen 1000
    link/ether 0a:90:77:c7:1d:f3 brd ff:ff:ff:ff:ff:ff
6: eth0: <BROADCAST,MULTICAST> mtu 1500 qdisc pfifo_fast qlen 1000

尝试删除mtk-eth模块会导致内核错误:

# rmmod mtk-eth
[ 6634.791361] ------------[ cut here ]------------
[ 6634.796077] WARNING: CPU: 0 PID: 841 at drivers/net/phy/phylink.c:1151 0x80302674
[ 6634.809938] RTNL: assertion failed at drivers/net/phy/phylink.c (1151)
[ 6634.819931] Modules linked in: mtk_eth(-) des_generic libdes cbc ecb algif_skcipher hmac sha512_generic sha1_generic md5 md4 algif_hash af_alg mt7603e mt76 mac80211 sha256_generic libsha256 ehci_platform ohci_platform ohci_hcd ehci_hcd cfg80211 rfkill usbcore libarc4 usb_common
[ 6634.848585] CPU: 0 PID: 841 Comm: rmmod Not tainted 5.8.0 #2
[ 6634.857694] Stack : 80450000 80410e8c 804493fc 864d1d24 00000000 00000000 00000000 00000000
[ 6634.869806]         00000000 00000000 00000000 00000000 00000000 00000001 864d1cd0 80490000
[ 6634.881851]         864d1d68 00000000 00000000 ffff00fe 00000038 8025e724 00000006 876d5e58
[ 6634.890364]         7fca7028 7fca706c 7fca7070 7fca7074 8041e310 80490000 80000000 00000009
[ 6634.905154]         80467cc0 7fc3e284 00420000 004f0950 80495220 32cc152e 08072098 80500000
[ 6634.917055]         ...
[ 6634.919556] Call Trace:
[ 6634.919579] [<8025e724>] 0x8025e724
[ 6634.931103] [<8000abf4>] 0x8000abf4
[ 6634.934661] [<8000abfc>] 0x8000abfc
[ 6634.938196] [<8001d990>] 0x8001d990
[ 6634.955157] [<80302674>] 0x80302674
[ 6634.958716] [<80302674>] 0x80302674
[ 6634.968796] [<80302674>] 0x80302674
[ 6634.975843] [<8001da04>] 0x8001da04
[ 6634.979408] [<80302674>] 0x80302674
[ 6634.989141] [<80158110>] 0x80158110
[ 6634.996066] [<c00b10c4>] 0xc00b10c4
[ 6634.999625] [<c00b12c4>] 0xc00b12c4
[ 6635.009387] [<802c9c5c>] 0x802c9c5c
[ 6635.016419] [<802c991c>] 0x802c991c
[ 6635.019974] [<802c9dc0>] 0x802c9dc0
[ 6635.029705] [<802c86e0>] 0x802c86e0
[ 6635.036620] [<8007849c>] 0x8007849c
[ 6635.040176] [<800bc5a4>] 0x800bc5a4
[ 6635.049933] [<8002ec50>] 0x8002ec50
[ 6635.056920] [<8000f14c>] 0x8000f14c
[ 6635.060492] 
[ 6635.068472] ---[ end trace a60217f8a7ca79c8 ]---
[ 6635.076697] ------------[ cut here ]------------
[ 6635.084835] WARNING: CPU: 0 PID: 841 at drivers/net/phy/phylink.c:1030 0x80301a4c
[ 6635.095828] RTNL: assertion failed at drivers/net/phy/phylink.c (1030)
[ 6635.105831] Modules linked in: mtk_eth(-) des_generic libdes cbc ecb algif_skcipher hmac sha512_generic sha1_generic md5 md4 algif_hash af_alg mt7603e mt76 mac80211 sha256_generic libsha256 ehci_platform ohci_platform ohci_hcd ehci_hcd cfg80211 rfkill usbcore libarc4 usb_common
[ 6635.134359] CPU: 0 PID: 841 Comm: rmmod Tainted: G        W         5.8.0 #2
[ 6635.145331] Stack : 80450000 80410e80 804493fc 864d1d14 00000000 00000000 00000000 00000000
[ 6635.157222]         00000000 00000000 00000000 00000000 00000000 00000001 864d1cc0 80490000
[ 6635.169427]         864d1d58 00000000 00000000 ffff00fe 00000038 8025e724 00000006 876d5e58
[ 6635.181471]         7fca7028 7fca706c 7fca7070 7fca7074 8041e310 80490000 80000000 00000009
[ 6635.190097]         80467cc0 0000007c 00420000 004f0950 80495220 32cc152e 08072098 80500000
[ 6635.204965]         ...
[ 6635.207470] Call Trace:
[ 6635.207493] [<8025e724>] 0x8025e724
[ 6635.221955] [<8000abf4>] 0x8000abf4
[ 6635.225509] [<8000abfc>] 0x8000abfc
[ 6635.229045] [<8001d990>] 0x8001d990
[ 6635.241166] [<80301a4c>] 0x80301a4c
[ 6635.244725] [<80301a4c>] 0x80301a4c
[ 6635.248258] [<80301a4c>] 0x80301a4c
[ 6635.262154] [<8001da04>] 0x8001da04
[ 6635.265718] [<c00af0c0>] 0xc00af0c0
[ 6635.269251] [<80406134>] 0x80406134
[ 6635.282048] [<80301a4c>] 0x80301a4c
[ 6635.285608] [<80302690>] 0x80302690
[ 6635.289142] [<80158110>] 0x80158110
[ 6635.301514] [<c00b1120>] 0xc00b1120
[ 6635.305074] [<c00b12c4>] 0xc00b12c4
[ 6635.308611] [<802c9c5c>] 0x802c9c5c
[ 6635.321116] [<802c991c>] 0x802c991c
[ 6635.324673] [<802c9dc0>] 0x802c9dc0
[ 6635.328209] [<802c86e0>] 0x802c86e0
[ 6635.341418] [<8007849c>] 0x8007849c
[ 6635.344976] [<800bc5a4>] 0x800bc5a4
[ 6635.348511] [<8002ec50>] 0x8002ec50
[ 6635.361159] [<8000f14c>] 0x8000f14c
[ 6635.364729] 
[ 6635.366243] ---[ end trace a60217f8a7ca79c9 ]---
[ 6635.380166] ------------[ cut here ]------------
[ 6635.385575] WARNING: CPU: 0 PID: 841 at lib/refcount.c:28 0xc00b1258
[ 6635.397959] refcount_t: underflow; use-after-free.
[ 6635.406183] Modules linked in: mtk_eth(-) des_generic libdes cbc ecb algif_skcipher hmac sha512_generic sha1_generic md5 md4 algif_hash af_alg mt7603e mt76 mac80211 sha256_generic libsha256 ehci_platform ohci_platform ohci_hcd ehci_hcd cfg80211 rfkill usbcore libarc4 usb_common
[ 6635.434814] CPU: 0 PID: 841 Comm: rmmod Tainted: G        W         5.8.0 #2
[ 6635.445430] Stack : 80450000 80410e80 804493fc 864d1d44 00000000 00000000 00000000 00000000
[ 6635.457327]         00000000 00000000 00000000 00000000 00000000 00000001 864d1cf0 80490000
[ 6635.469233]         864d1d88 00000000 00000000 ffff00fe 00000038 8025e724 00000006 876d5e58
[ 6635.481410]         7fca7028 7fca706c 7fca7070 7fca7074 8041e310 80490000 80000000 00000009
[ 6635.489923]         8043f744 0000007c 00420000 004f0950 80495220 32cc152e 08072098 80500000
[ 6635.504762]         ...
[ 6635.507267] Call Trace:
[ 6635.507290] [<8025e724>] 0x8025e724
[ 6635.521960] [<8000abf4>] 0x8000abf4
[ 6635.525515] [<8000abfc>] 0x8000abfc
[ 6635.529050] [<8001d990>] 0x8001d990
[ 6635.541211] [<c00b1258>] 0xc00b1258
[ 6635.544767] [<c00b1258>] 0xc00b1258
[ 6635.548302] [<c00b1258>] 0xc00b1258
[ 6635.562011] [<8001da04>] 0x8001da04
[ 6635.565574] [<c00af0c0>] 0xc00af0c0
[ 6635.569108] [<80406134>] 0x80406134
[ 6635.579120] [<c00b1258>] 0xc00b1258
[ 6635.588795] [<c00b12c4>] 0xc00b12c4
[ 6635.593036] [<802c9c5c>] 0x802c9c5c
[ 6635.596590] [<802c991c>] 0x802c991c
[ 6635.600126] [<802c9dc0>] 0x802c9dc0
[ 6635.615364] [<802c86e0>] 0x802c86e0
[ 6635.618920] [<8007849c>] 0x8007849c
[ 6635.628652] [<800bc5a4>] 0x800bc5a4
[ 6635.635599] [<8002ec50>] 0x8002ec50
[ 6635.639157] [<8000f14c>] 0x8000f14c
[ 6635.649356] 
[ 6635.650891] ---[ end trace a60217f8a7ca79ca ]---

但系统似乎功能正常,甚至以太网也可以工作(如果我重新加载模块)。

我想更好地了解到底发生了什么。

欢迎文档指导和解释。

答案1

类似的结构foo@eth0通常是 802.11q VLAN 的虚拟接口。名称的右侧是物理接口。名称的左侧是 VLAN。内核从物理设备中挑选带有适当 VLAN 标记的帧,并将它们呈现给 IP 层,就好像它们是一个单独的接口一样。然后可以在VLAN接口上配置IP地址等。

对于您所描述的消费者互联网网关设备类型,通常所有外部 RJ-45 以太网端口都连接到单个交换机 ASIC。运行 Linux 的处理器也连接到同一交换机 ASIC 上的“内部”端口。 (它们可能都是同一个 SoC 的一部分,但从逻辑上讲,它们是独立的组件。)VLAN 分配用于将物理端口指定为“WAN”或“LAN”或其他端口,并将它们单独引入 Linux 内核。

至于为什么会这样,我们需要有关正在运行的软件的更多信息。您根本没有描述软件环境(分发、用户空间配置自动化,如 NetworkManager 等)。许多针对消费者网关的软件套件(例如 OpenWrt)会自动设置,假设您将在 ISP 和 LAN 之间构建 NAT。

内核错误几乎肯定是一个不相关的问题。听起来像是个越野车司机。 assertion failed意味着代码进行了内部检查,发现事情与预期不符,因此中止了进程/线程。 refcount_t: underflow; use-after-free指示内核正在记录对某些资源的引用计数,并且某些资源在释放后尝试使用该资源。 (我认为这具体意味着内核发现驱动程序代码的引用计数想法高于内核的想法,但我不能 100% 确定这一点。)

相关内容