O Udev não renomeia o dispositivo usb ethernet

0

Estou usando o Arch Linux, o Udev v234, o SystemD v234.11-8.

Eu tenho um laptop que roda o Arch Linux e um telefone Android Nexus 5 que captura o sinal WiFi melhor do que o meu laptop. Quero que meu laptop conecte-se automaticamente à Internet quando conecto o telefone por meio de tethering USB. Para que isso funcione eu tentei algumas coisas:

  1. Eu criei esta (e a única) regra do udev em /etc/udev/rules.d/99-nexus-plugged.rules :

    #!/bin/sh
    ACTION=="add", ATTRS{idVendor}=="18d1", ATTRS{idProduct}=="4ee2", IMPORT="/lib/udev/rename_netiface %k hello", RUN+="/home/babken/test/adb-enable-tethering"
    

    Espero que o udev renomeie meu dispositivo para hello , mas ele ainda cria um nome aleatório. O que estou fazendo errado?

    Eu sei que esta regra é compatível porque meu script é executado.

  2. Eu criei duas regras do udev. O primeiro é para ativar o tethering USB, remotamente no meu telefone e permitindo tethering:

    #!/bin/sh
    SUBSYSTEM=="usb", ATTRS{idVendor}=="18d1", ATTRS{idProduct}=="4ee*",  RUN+="/home/babken/test/adb-enable-tethering"
    

    A segunda regra deve renomear o nome da ethernet do nome aleatório de enp0setc para hello :

    #!/bin/sh
    SUBSYSTEM=="net", ACTION=="add", KERNEL=="enp0s29u1u2", ATTR{address}=="6a:e7:28:13:45:f7", NAME="hello", RUN+="/bin/touch /tmp/hello"
    

    Esta segunda regra nem sequer é acionada, não cria o arquivo /tmp/hello .

    Curiosamente, se eu executar udevadm test /sys/class/net/enp0s29u1u2 , esta segunda regra será acionada e meu dispositivo mudará o nome para hello . Mas não quando eu desconectar / reconectar meu telefone. Por que esta regra não desencadeia então?

Sempre recarrego as regras do udev executando sudo udevadm control --reload depois de fazer alterações nas regras do udev.

Aqui estão os meus logs do journalctl quando eu conecto o dispositivo:

Aug 25 15:41:44 lenovo-laptop kernel: usb 2-1.2: new high-speed USB device number 38 using ehci-pci
Aug 25 15:41:49 lenovo-laptop kernel: usb 2-1.2: USB disconnect, device number 38
Aug 25 15:41:49 lenovo-laptop kernel: usb 2-1.2: new high-speed USB device number 39 using ehci-pci
Aug 25 15:41:49 lenovo-laptop kernel: rndis_host 2-1.2:1.0 usb0: register 'rndis_host' at usb-0000:00:1d.0-1.2, RNDIS device, c6:d5:df:ba:ba:4d
Aug 25 15:41:50 lenovo-laptop systemd-udevd[20464]: Process '/home/babken/test/adb-enable-tethering' failed with exit code 1.
Aug 25 15:41:50 lenovo-laptop systemd-udevd[20710]: Process '/home/babken/test/adb-enable-tethering' failed with exit code 1.
Aug 25 15:41:50 lenovo-laptop mtp-probe[20778]: checking bus 2, device 39: "/sys/devices/pci0000:00/0000:00:1d.0/usb2/2-1/2-1.2"
Aug 25 15:41:50 lenovo-laptop mtp-probe[20778]: bus: 2, device: 39 was not an MTP device
Aug 25 15:41:50 lenovo-laptop systemd-udevd[20464]: link_config: autonegotiation is unset or enabled, the speed and duplex are not writable.
Aug 25 15:41:50 lenovo-laptop kernel: rndis_host 2-1.2:1.0 enp0s29u1u2: renamed from usb0
Aug 25 15:41:50 lenovo-laptop dhcpcd[3516]: enp0s29u1u2: waiting for carrier
Aug 25 15:41:50 lenovo-laptop dhcpcd[3516]: enp0s29u1u2: waiting for carrier
Aug 25 15:41:50 lenovo-laptop dhcpcd[3516]: enp0s29u1u2: carrier acquired
Aug 25 15:41:50 lenovo-laptop dhcpcd[3516]: enp0s29u1u2: IAID 28:13:45:f7
Aug 25 15:41:50 lenovo-laptop dhcpcd[3516]: enp0s29u1u2: adding address fe80::5f59:ada0:7eae:987b
Aug 25 15:41:50 lenovo-laptop dhcpcd[3516]: enp0s29u1u2: soliciting an IPv6 router
Aug 25 15:41:50 lenovo-laptop ifplugd(enp0s29u1u2)[12486]: Link beat detected.
Aug 25 15:41:50 lenovo-laptop dhcpcd[3516]: enp0s29u1u2: rebinding lease of 192.168.42.150
Aug 25 15:41:50 lenovo-laptop dhcpcd[3516]: enp0s29u1u2: probing address 192.168.42.150/24
Aug 25 15:41:51 lenovo-laptop ifplugd(enp0s29u1u2)[12486]: Executing '/etc/ifplugd/ifplugd.action enp0s29u1u2 up'.
Aug 25 15:41:51 lenovo-laptop ifplugd(enp0s29u1u2)[12486]: Program executed successfully.
Aug 25 15:41:56 lenovo-laptop dhcpcd[3516]: enp0s29u1u2: leased 192.168.42.150 for 3600 seconds
Aug 25 15:41:56 lenovo-laptop dhcpcd[3516]: enp0s29u1u2: adding route to 192.168.42.0/24
Aug 25 15:41:56 lenovo-laptop dhcpcd[3516]: enp0s29u1u2: adding default route via 192.168.42.129
Aug 25 15:42:03 lenovo-laptop dhcpcd[3516]: enp0s29u1u2: no IPv6 Routers available

Saída de udevadm info -a /sys/class/net/enp0s29u1u2 :

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/pci0000:00/0000:00:1d.0/usb2/2-1/2-1.2/2-1.2:1.0/net/enp0s29u1u2':
    KERNEL=="enp0s29u1u2"
    SUBSYSTEM=="net"
    DRIVER==""
    ATTR{addr_assign_type}=="3"
    ATTR{addr_len}=="6"
    ATTR{address}=="6a:e7:28:13:45:f7"
    ATTR{broadcast}=="ff:ff:ff:ff:ff:ff"
    ATTR{carrier}=="1"
    ATTR{carrier_changes}=="0"
    ATTR{dev_id}=="0x0"
    ATTR{dev_port}=="0"
    ATTR{dormant}=="0"
    ATTR{flags}=="0x1003"
    ATTR{gro_flush_timeout}=="0"
    ATTR{ifalias}==""
    ATTR{ifindex}=="36"
    ATTR{iflink}=="36"
    ATTR{link_mode}=="0"
    ATTR{mtu}=="1500"
    ATTR{name_assign_type}=="4"
    ATTR{netdev_group}=="0"
    ATTR{operstate}=="unknown"
    ATTR{proto_down}=="0"
    ATTR{tx_queue_len}=="1000"
    ATTR{type}=="1"

  looking at parent device '/devices/pci0000:00/0000:00:1d.0/usb2/2-1/2-1.2/2-1.2:1.0':
    KERNELS=="2-1.2:1.0"
    SUBSYSTEMS=="usb"
    DRIVERS=="rndis_host"
    ATTRS{authorized}=="1"
    ATTRS{bAlternateSetting}==" 0"
    ATTRS{bInterfaceClass}=="e0"
    ATTRS{bInterfaceNumber}=="00"
    ATTRS{bInterfaceProtocol}=="03"
    ATTRS{bInterfaceSubClass}=="01"
    ATTRS{bNumEndpoints}=="01"
    ATTRS{iad_bFirstInterface}=="00"
    ATTRS{iad_bFunctionClass}=="e0"
    ATTRS{iad_bFunctionProtocol}=="03"
    ATTRS{iad_bFunctionSubClass}=="01"
    ATTRS{iad_bInterfaceCount}=="02"
    ATTRS{interface}=="RNDIS Communications Control"
    ATTRS{supports_autosuspend}=="1"

  looking at parent device '/devices/pci0000:00/0000:00:1d.0/usb2/2-1/2-1.2':
    KERNELS=="2-1.2"
    SUBSYSTEMS=="usb"
    DRIVERS=="usb"
    ATTRS{authorized}=="1"
    ATTRS{avoid_reset_quirk}=="0"
    ATTRS{bConfigurationValue}=="1"
    ATTRS{bDeviceClass}=="ef"
    ATTRS{bDeviceProtocol}=="01"
    ATTRS{bDeviceSubClass}=="02"
    ATTRS{bMaxPacketSize0}=="64"
    ATTRS{bMaxPower}=="500mA"
    ATTRS{bNumConfigurations}=="1"
    ATTRS{bNumInterfaces}==" 3"
    ATTRS{bcdDevice}=="0232"
    ATTRS{bmAttributes}=="80"
    ATTRS{busnum}=="2"
    ATTRS{configuration}==""
    ATTRS{devnum}=="68"
    ATTRS{devpath}=="1.2"
    ATTRS{idProduct}=="4ee4"
    ATTRS{idVendor}=="18d1"
    ATTRS{ltm_capable}=="no"
    ATTRS{manufacturer}=="LGE"
    ATTRS{maxchild}=="0"
    ATTRS{product}=="Nexus 5"
    ATTRS{quirks}=="0x0"
    ATTRS{removable}=="removable"
    ATTRS{serial}=="0831bd3b21320609"
    ATTRS{speed}=="480"
    ATTRS{urbnum}=="685"
    ATTRS{version}==" 2.00"

  looking at parent device '/devices/pci0000:00/0000:00:1d.0/usb2/2-1':
    KERNELS=="2-1"
    SUBSYSTEMS=="usb"
    DRIVERS=="usb"
    ATTRS{authorized}=="1"
    ATTRS{avoid_reset_quirk}=="0"
    ATTRS{bConfigurationValue}=="1"
    ATTRS{bDeviceClass}=="09"
    ATTRS{bDeviceProtocol}=="01"
    ATTRS{bDeviceSubClass}=="00"
    ATTRS{bMaxPacketSize0}=="64"
    ATTRS{bMaxPower}=="0mA"
    ATTRS{bNumConfigurations}=="1"
    ATTRS{bNumInterfaces}==" 1"
    ATTRS{bcdDevice}=="0000"
    ATTRS{bmAttributes}=="e0"
    ATTRS{busnum}=="2"
    ATTRS{configuration}==""
    ATTRS{devnum}=="2"
    ATTRS{devpath}=="1"
    ATTRS{idProduct}=="0024"
    ATTRS{idVendor}=="8087"
    ATTRS{ltm_capable}=="no"
    ATTRS{maxchild}=="6"
    ATTRS{quirks}=="0x0"
    ATTRS{removable}=="fixed"
    ATTRS{speed}=="480"
    ATTRS{urbnum}=="152578"
    ATTRS{version}==" 2.00"

  looking at parent device '/devices/pci0000:00/0000:00:1d.0/usb2':
    KERNELS=="usb2"
    SUBSYSTEMS=="usb"
    DRIVERS=="usb"
    ATTRS{authorized}=="1"
    ATTRS{authorized_default}=="1"
    ATTRS{avoid_reset_quirk}=="0"
    ATTRS{bConfigurationValue}=="1"
    ATTRS{bDeviceClass}=="09"
    ATTRS{bDeviceProtocol}=="00"
    ATTRS{bDeviceSubClass}=="00"
    ATTRS{bMaxPacketSize0}=="64"
    ATTRS{bMaxPower}=="0mA"
    ATTRS{bNumConfigurations}=="1"
    ATTRS{bNumInterfaces}==" 1"
    ATTRS{bcdDevice}=="0412"
    ATTRS{bmAttributes}=="e0"
    ATTRS{busnum}=="2"
    ATTRS{configuration}==""
    ATTRS{devnum}=="1"
    ATTRS{devpath}=="0"
    ATTRS{idProduct}=="0002"
    ATTRS{idVendor}=="1d6b"
    ATTRS{interface_authorized_default}=="1"
    ATTRS{ltm_capable}=="no"
    ATTRS{manufacturer}=="Linux 4.12.8-2-ARCH ehci_hcd"
    ATTRS{maxchild}=="2"
    ATTRS{product}=="EHCI Host Controller"
    ATTRS{quirks}=="0x0"
    ATTRS{removable}=="unknown"
    ATTRS{serial}=="0000:00:1d.0"
    ATTRS{speed}=="480"
    ATTRS{urbnum}=="27919"
    ATTRS{version}==" 2.00"

  looking at parent device '/devices/pci0000:00/0000:00:1d.0':
    KERNELS=="0000:00:1d.0"
    SUBSYSTEMS=="pci"
    DRIVERS=="ehci-pci"
    ATTRS{broken_parity_status}=="0"
    ATTRS{class}=="0x0c0320"
    ATTRS{companion}==""
    ATTRS{consistent_dma_mask_bits}=="32"
    ATTRS{d3cold_allowed}=="1"
    ATTRS{device}=="0x1c26"
    ATTRS{dma_mask_bits}=="32"
    ATTRS{driver_override}=="(null)"
    ATTRS{enable}=="1"
    ATTRS{irq}=="23"
    ATTRS{local_cpulist}=="0-3"
    ATTRS{local_cpus}=="0f"
    ATTRS{msi_bus}=="1"
    ATTRS{numa_node}=="-1"
    ATTRS{revision}=="0x05"
    ATTRS{subsystem_device}=="0x3975"
    ATTRS{subsystem_vendor}=="0x17aa"
    ATTRS{uframe_periodic_max}=="100"
    ATTRS{vendor}=="0x8086"

  looking at parent device '/devices/pci0000:00':
    KERNELS=="pci0000:00"
    SUBSYSTEMS==""
    DRIVERS==""
    
por Babken Vardanyan 25.08.2017 / 13:36

2 respostas

2

Tente a regra a seguir para fazer a parte de renomeação. Sinta-se à vontade para modificar as coisas para que seus scripts sejam executados:

SUBSYSTEM=="net", ACTION=="add", ATTRS{idVendor}=="18d1", ATTRS{idProduct}=="4ee2", NAME="hallo"

Esta regra é derivada de aquela .

Se isso não funcionar, você deve ficar atento às regras do udev que foram criadas pelo seu sistema automaticamente. Por exemplo, meu sistema Debian usa a seguinte regra para gerenciar a interface wifi (a regra citada aqui está um pouco ajustada, veja abaixo):

SUBSYSTEM=="net", ACTION=="add", ATTR{address}=="c0:f8:da:03:c1:a8", NAME="wlan2"

Anote o endereço MAC c0:f8:da:03:c1:a8 que foi inserido. Talvez algo semelhante ajude você a criar sua regra personalizada que renomeie seu dispositivo de acordo.

Editar: A segunda regra fornecida acima é essencialmente cortada para a mencionada aqui (como também observado por Tom Yan nos comentários).

    
por 25.08.2017 / 15:46
1

Observe que essa resposta não resolve o problema de a regra do Udev não ser acionada. No entanto, como meu objetivo original era obter um nome de dispositivo Ethernet consistente ao conectá-lo a portas diferentes, essa solução faz o trabalho dele.

Acontece que o Udev anula minha configuração, então eu simplesmente desabilitei as regras de rede:

 # ln -s /dev/null /etc/udev/rules.d/80-net-setup-link.rules

Agora, meu dispositivo é chamado de usb0 o tempo todo. Consulte Reverter para os nomes de dispositivos tradicionais .

    
por 26.08.2017 / 14:50