You are not logged in.

#1 2017-08-13 19:19:42

markuzo
Member
Registered: 2015-09-17
Posts: 10

[solved] udev rule not reacting to KERNEL tag

I have a USB ethernet which whenever unplugged, kills the netctl-ifplugd service running for that interface. I found out that I can just write a udev rule which restarts the service, but I'm not managing to write the rule properly.

Rule:

 
SUBSYSTEM=="net", KERNEL=="enp0s20f0u2u1", ACTION=="add", ATTR{address}=="00:0e:c6:c4:c4:8c", RUN+="/home/markuzo/tmp/udev-output-on.sh"

I got this information using udevadm info. Here's the output:

  looking at device '/devices/pci0000:00/0000:00:14.0/usb2/2-2/2-2.1/2-2.1:1.0/net/enp0s20f0u2u1':
    KERNEL=="enp0s20f0u2u1"
    SUBSYSTEM=="net"
    DRIVER==""
    ATTR{addr_assign_type}=="0"
    ATTR{addr_len}=="6"
    ATTR{address}=="00:0e:c6:c4:c4:8c"
    ATTR{broadcast}=="ff:ff:ff:ff:ff:ff"

In the rule, if I remove the KERNEL tag, then script is called, however, I need to have the name of the device, as I have to call a different command depending on the USB in which it's plugged.

Journalctl doesn't report any errors when loading the udev rules. Could it have something to do with the KERNEL name changing when the device is plugged in?

Last edited by markuzo (2017-08-14 01:09:53)

Offline

#2 2017-08-13 20:21:06

R00KIE
Forum Fellow
From: Between a computer and a chair
Registered: 2008-09-14
Posts: 4,734

Re: [solved] udev rule not reacting to KERNEL tag

Given that it is a usb device, have you checked that the persistent name is always the same when you plug the adapter again?


R00KIE
Tm90aGluZyB0byBzZWUgaGVyZSwgbW92ZSBhbG9uZy4K

Offline

#3 2017-08-13 21:46:55

seth
Member
Registered: 2012-09-03
Posts: 51,017

Re: [solved] udev rule not reacting to KERNEL tag

"unplugged" the rj45 or the usb?

Offline

#4 2017-08-13 22:24:28

markuzo
Member
Registered: 2015-09-17
Posts: 10

Re: [solved] udev rule not reacting to KERNEL tag

The persistent name for the ethernet changes only depending on the USB port, so that's why I would like to listen to the ethernet on a particular USB, and when that event happens, start the netctl-ifplugd with that interface name.

The network interface disappears when I unplug the USB, and therefore the netctl-ifplugd for that interface exits. You have to manually restart it (or start it via udev which is what I'm hoping smile )

Offline

#5 2017-08-14 01:09:19

markuzo
Member
Registered: 2015-09-17
Posts: 10

Re: [solved] udev rule not reacting to KERNEL tag

I managed to do what I originally wanted to do. Even though the interface is being renamed (journalctl shows it), I just force the rename with the udev rule and then just use that name for starting the netctl-ifplugd.

If someone reading this knows how I could use the KERNEL parameter, then I'd still be happy to know. I don't want to rely on my current method of renaming the network interfaces.

For completeness, here's the line:

SUBSYSTEM=="net", ACTION=="add", ATTR{address}=="00:0e:c6:c4:c4:8c", NAME="ethusbugreen", RUN+="/sbin/ip link set ethusbugreen up", RUN+="/usr/bin/systemctl --no-block start netctl-ifplugd@ethusbugreen.service"

Offline

#6 2017-08-14 01:21:24

R00KIE
Forum Fellow
From: Between a computer and a chair
Registered: 2008-09-14
Posts: 4,734

Re: [solved] udev rule not reacting to KERNEL tag

It looks to me you are going about this the wrong way, but I may be misunderstanding it because I've never used netctl. If you want to start netctl-ifplugd when you plug that adapter maybe you should match only on the mac address and maybe some other attributes that (almost) uniquely identify that adapter, matching on a specific persistent name looks a bit too restrictive, what you probably want is to pass that as a parameter to your script.

The second part of the problem is that you might want to match on three different actions (add, change, remove) and do the right thing for each case.


R00KIE
Tm90aGluZyB0byBzZWUgaGVyZSwgbW92ZSBhbG9uZy4K

Offline

#7 2017-08-14 05:59:24

seth
Member
Registered: 2012-09-03
Posts: 51,017

Re: [solved] udev rule not reacting to KERNEL tag

I'd rather say he wanted to handle the usb device, not the ethernet one - ie. start the ifplugd whenever the USB adapther is plugged into the USB hub.

The network interface disappears when I unplug the USB, and therefore the netctl-ifplugd for that interface exits. You have to manually restart it (or start it via udev which is what I'm hoping)

Offline

Board footer

Powered by FluxBB