目录
udevadm info -a -p /sys/class/net/FE0
udevadm info -a -p /sys/class/net/FE1
本人使用两张以太网卡,分别为emac、gmac,insmod加载两张网卡驱动后,一张为FE0,一张为eth0,与我的初衷需要生成的FE0、FE1不符合,出现问题的udev配置文件如下
- SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{dev_id}=="0x0", ATTR{type}=="1", KERNEL=="eth*", NAME="FE0"
-
- SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{dev_id}=="0x0", ATTR{type}=="1", KERNEL=="eth*", NAME="FE1"
通过udevadm monitor命令监控发现,其实以上两条规则匹配的内容是一致的,导致无法生产FE0、FE1,所以需要增加一条匹配键来区分这两个网卡设备。
首先我们需要找到这两个设备的差异项,通过udevadm info命令
- clou@SMIOS:/etc/udev/rules.d# udevadm info -a -p /sys/class/net/FE0
-
- Udevadm info starts with the device specified by the devpath and then
- walks up the chain of parent devices. It prints for every device
- found, all possible attributes in the udev rules key format.
- A rule to match, can be composed by the attributes of the device
- and the attributes from one single parent device.
-
- looking at device '/devices/soc/emac0/net/FE0':
- KERNEL=="FE0"
- SUBSYSTEM=="net"
- DRIVER==""
- ATTR{addr_assign_type}=="3"
- ATTR{addr_len}=="6"
- ATTR{address}=="7a:56:90:5b:2f:4f"
- ATTR{broadcast}=="ff:ff:ff:ff:ff:ff"
- ATTR{carrier}=="1"
- ATTR{dev_id}=="0x0"
- ATTR{dormant}=="0"
- ATTR{duplex}=="full"
- ATTR{flags}=="0x1003"
- ATTR{ifalias}==""
- ATTR{ifindex}=="19"
- ATTR{iflink}=="19"
- ATTR{link_mode}=="0"
- ATTR{mtu}=="1500"
- ATTR{netdev_group}=="0"
- ATTR{operstate}=="up"
- ATTR{power/async}=="disabled"
- ATTR{power/control}=="auto"
- ATTR{power/runtime_active_kids}=="0"
- ATTR{power/runtime_active_time}=="0"
- ATTR{power/runtime_enabled}=="disabled"
- ATTR{power/runtime_status}=="unsupported"
- ATTR{power/runtime_suspended_time}=="0"
- ATTR{power/runtime_usage}=="0"
- ATTR{queues/rx-0/rps_cpus}=="0"
- ATTR{queues/rx-0/rps_flow_cnt}=="0"
- ATTR{queues/tx-0/byte_queue_limits/hold_time}=="1000"
- ATTR{queues/tx-0/byte_queue_limits/inflight}=="0"
- ATTR{queues/tx-0/byte_queue_limits/limit}=="0"
- ATTR{queues/tx-0/byte_queue_limits/limit_max}=="1879048192"
- ATTR{queues/tx-0/byte_queue_limits/limit_min}=="0"
- ATTR{queues/tx-0/tx_timeout}=="0"
- ATTR{queues/tx-0/xps_cpus}=="0"
- ATTR{speed}=="100"
- ATTR{statistics/collisions}=="0"
- ATTR{statistics/multicast}=="0"
- ATTR{statistics/rx_bytes}=="217282"
- ATTR{statistics/rx_compressed}=="0"
- ATTR{statistics/rx_crc_errors}=="0"
- ATTR{statistics/rx_dropped}=="7"
- ATTR{statistics/rx_errors}=="0"
- ATTR{statistics/rx_fifo_errors}=="0"
- ATTR{statistics/rx_frame_errors}=="0"
- ATTR{statistics/rx_length_errors}=="0"
- ATTR{statistics/rx_missed_errors}=="0"
- ATTR{statistics/rx_over_errors}=="0"
- ATTR{statistics/rx_packets}=="1981"
- ATTR{statistics/tx_aborted_errors}=="0"
- ATTR{statistics/tx_bytes}=="46857"
- ATTR{statistics/tx_carrier_errors}=="0"
- ATTR{statistics/tx_compressed}=="0"
- ATTR{statistics/tx_dropped}=="0"
- ATTR{statistics/tx_errors}=="0"
- ATTR{statistics/tx_fifo_errors}=="0"
- ATTR{statistics/tx_heartbeat_errors}=="0"
- ATTR{statistics/tx_packets}=="328"
- ATTR{statistics/tx_window_errors}=="0"
- ATTR{tx_queue_len}=="1000"
- ATTR{type}=="1"
-
- looking at parent device '/devices/soc/emac0':
- KERNELS=="emac0"
- SUBSYSTEMS=="platform"
- DRIVERS=="sun4i-emac"
- ATTRS{power/async}=="disabled"
- ATTRS{power/control}=="auto"
- ATTRS{power/runtime_active_kids}=="0"
- ATTRS{power/runtime_active_time}=="0"
- ATTRS{power/runtime_enabled}=="disabled"
- ATTRS{power/runtime_status}=="unsupported"
- ATTRS{power/runtime_suspended_time}=="0"
- ATTRS{power/runtime_usage}=="0"
-
- looking at parent device '/devices/soc':
- KERNELS=="soc"
- SUBSYSTEMS=="platform"
- DRIVERS==""
- ATTRS{power/async}=="disabled"
- ATTRS{power/control}=="auto"
- ATTRS{power/runtime_active_kids}=="0"
- ATTRS{power/runtime_active_time}=="0"
- ATTRS{power/runtime_enabled}=="disabled"
- ATTRS{power/runtime_status}=="unsupported"
- ATTRS{power/runtime_suspended_time}=="0"
- ATTRS{power/runtime_usage}=="0"
注意其中的匹配键:KERNELS=="emac0"
- Udevadm info starts with the device specified by the devpath and then
- walks up the chain of parent devices. It prints for every device
- found, all possible attributes in the udev rules key format.
- A rule to match, can be composed by the attributes of the device
- and the attributes from one single parent device.
-
- looking at device '/devices/soc/gmac0/net/FE1':
- KERNEL=="FE1"
- SUBSYSTEM=="net"
- DRIVER==""
- ATTR{addr_assign_type}=="0"
- ATTR{addr_len}=="6"
- ATTR{address}=="36:c9:e3:f1:b8:05"
- ATTR{broadcast}=="ff:ff:ff:ff:ff:ff"
- ATTR{dev_id}=="0x0"
- ATTR{flags}=="0x1002"
- ATTR{ifalias}==""
- ATTR{ifindex}=="32"
- ATTR{iflink}=="32"
- ATTR{link_mode}=="0"
- ATTR{mtu}=="1500"
- ATTR{netdev_group}=="0"
- ATTR{operstate}=="down"
- ATTR{power/async}=="disabled"
- ATTR{power/control}=="auto"
- ATTR{power/runtime_active_kids}=="0"
- ATTR{power/runtime_active_time}=="0"
- ATTR{power/runtime_enabled}=="disabled"
- ATTR{power/runtime_status}=="unsupported"
- ATTR{power/runtime_suspended_time}=="0"
- ATTR{power/runtime_usage}=="0"
- ATTR{queues/rx-0/rps_cpus}=="0"
- ATTR{queues/rx-0/rps_flow_cnt}=="0"
- ATTR{queues/tx-0/byte_queue_limits/hold_time}=="1000"
- ATTR{queues/tx-0/byte_queue_limits/inflight}=="0"
- ATTR{queues/tx-0/byte_queue_limits/limit}=="0"
- ATTR{queues/tx-0/byte_queue_limits/limit_max}=="1879048192"
- ATTR{queues/tx-0/byte_queue_limits/limit_min}=="0"
- ATTR{queues/tx-0/tx_timeout}=="0"
- ATTR{queues/tx-0/xps_cpus}=="0"
- ATTR{statistics/collisions}=="0"
- ATTR{statistics/multicast}=="0"
- ATTR{statistics/rx_bytes}=="0"
- ATTR{statistics/rx_compressed}=="0"
- ATTR{statistics/rx_crc_errors}=="0"
- ATTR{statistics/rx_dropped}=="0"
- ATTR{statistics/rx_errors}=="0"
- ATTR{statistics/rx_fifo_errors}=="0"
- ATTR{statistics/rx_frame_errors}=="0"
- ATTR{statistics/rx_length_errors}=="0"
- ATTR{statistics/rx_missed_errors}=="0"
- ATTR{statistics/rx_over_errors}=="0"
- ATTR{statistics/rx_packets}=="0"
- ATTR{statistics/tx_aborted_errors}=="0"
- ATTR{statistics/tx_bytes}=="0"
- ATTR{statistics/tx_carrier_errors}=="0"
- ATTR{statistics/tx_compressed}=="0"
- ATTR{statistics/tx_dropped}=="0"
- ATTR{statistics/tx_errors}=="0"
- ATTR{statistics/tx_fifo_errors}=="0"
- ATTR{statistics/tx_heartbeat_errors}=="0"
- ATTR{statistics/tx_packets}=="0"
- ATTR{statistics/tx_window_errors}=="0"
- ATTR{tx_queue_len}=="1000"
- ATTR{type}=="1"
-
- looking at parent device '/devices/soc/gmac0':
- KERNELS=="gmac0"
- SUBSYSTEMS=="platform"
- DRIVERS=="sunxi-gmac"
- ATTRS{power/async}=="enabled"
- ATTRS{power/control}=="auto"
- ATTRS{power/runtime_active_kids}=="0"
- ATTRS{power/runtime_active_time}=="0"
- ATTRS{power/runtime_enabled}=="disabled"
- ATTRS{power/runtime_status}=="unsupported"
- ATTRS{power/runtime_suspended_time}=="0"
- ATTRS{power/runtime_usage}=="0"
-
- looking at parent device '/devices/soc':
- KERNELS=="soc"
- SUBSYSTEMS=="platform"
- DRIVERS==""
- ATTRS{power/async}=="disabled"
- ATTRS{power/control}=="auto"
- ATTRS{power/runtime_active_kids}=="0"
- ATTRS{power/runtime_active_time}=="0"
- ATTRS{power/runtime_enabled}=="disabled"
- ATTRS{power/runtime_status}=="unsupported"
- ATTRS{power/runtime_suspended_time}=="0"
- ATTRS{power/runtime_usage}=="0"
注意其中的匹配键:KERNELS=="gmac0"
所以,分别把以上两条键值添加到规则表中
- KERNELS=="emac0", SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{dev_id}=="0x0", ATTR{type}=="1", KERNEL=="eth*", NAME="FE0"
- KERNELS=="gmac0", SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{dev_id}=="0x0", ATTR{type}=="1", KERNEL=="eth*", NAME="FE1"
常用匹配键:
* KERNEL - 匹配设备在内核中的命名
* SUBSYSTEM - 匹配设备(在sysfs中)的subsystem名
* DRIVER - 匹配设备对应的驱动名
* ATTR - 匹配设备在sysfs中属性
* KERNELS - 匹配设备及其父亲在内核中的命名
* SUBSYSTEMS - 匹配设备及其父亲(在sysfs中)的subsystem名
* DRIVERS - 匹配设备及其父亲对应的驱动名
* ATTRS - 匹配设备及其父亲在sysfs中属性
注:父亲表示直到最上层的所有祖先
至此,两张相同的网卡emac、gmac同时加载,通过udev规则实现了匹配。

三、其它
/usr/lib/udev/rules.d/70-persistent-net.rules 和 /etc/udev/udev.d/70-persistent-net.rules的区别,前者为系统,后者为用户添加规则,用户添加的规则比系统的优先级要高。