Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
[udev-rules]How to match MAC address?
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Kernel & Hardware
View previous topic :: View next topic  
Author Message
riaqn
n00b
n00b


Joined: 06 Aug 2013
Posts: 5

PostPosted: Sat Dec 06, 2014 6:40 am    Post subject: [udev-rules]How to match MAC address? Reply with quote

Hi all. I 'm playing with udev. Since my network card is broken with some features(offload, tso, gso, etc) on. So I have to turn these features off with ethtool once this interface is loaded.(the driver of the network card is a module tg3) I heard that udev is used to do such things. I want to match the interface with MAC address, to be more accurate. So I write down:
Code:
ACTION=="add", ATTR{address}=="00:1b:24:d5:f4:38", RUN+="/usr/local/sbin/offload $env{INTERFACE} off"

the usr/local/sbin/offload is just a small script that call ethtool on the passed interface, to turn off these broken features, what's more, it will print the environments given by udev:
Code:

#!/bin/sh
env >> /tmp/offload
echo >> /tmp/offload
if [ $# -ne 2 ]; then
    echo "$0 <interface> <on|off>";
    exit 1;
fi
TOE_OPTIONS="rx tx sg tso ufo gso gro lro rxvlan txvlan rxhash"
#TOE_OPTIONS="rx tx sg tso gso gro"
for TOE_OPTION in $TOE_OPTIONS; do
    ethtool -K $1 ${TOE_OPTION} $2
done

This rules works fine. However, I found that there's an environment variable ID_NET_NAME_MAC also store the MAC address:
Code:

ID_PATH_TAG=pci-0000_04_00_0
ID_BUS=pci
SUBSYSTEM=net
ID_MODEL_FROM_DATABASE=NetLink BCM5906M Fast Ethernet PCI Express
ID_PCI_CLASS_FROM_DATABASE=Network controller
DEVPATH=/devices/pci0000:00/0000:00:1c.5/0000:04:00.0/net/enp4s0
ID_MODEL_ID=0x1713
ID_NET_NAME_MAC=enx001b24d5f438
ID_PCI_SUBCLASS_FROM_DATABASE=Ethernet controller
ID_OUI_FROM_DATABASE=Quanta Computer Inc.
ACTION=add
PWD=/
UDEV_LOG=7
USEC_INITIALIZED=73362876
ID_NET_LINK_FILE=/lib64/systemd/network/99-default.link
ID_VENDOR_ID=0x14e4
SHLVL=1
IFINDEX=14
INTERFACE=enp4s0
ID_NET_DRIVER=tg3
ID_VENDOR_FROM_DATABASE=Broadcom Corporation
ID_NET_NAME_PATH=enp4s0
SEQNUM=13462
ID_PATH=pci-0000:04:00.0
_=/usr/bin/env

As you can see, ID_NET_NAME_MAC=enx001b24d5f438. So I guess I can modify the rules to something like:
Code:
ACTION=="add", ENV{ID_NET_NAME_MAC}=="enx001b24d5f438", RUN+="/usr/local/sbin/offload $env{INTERFACE} off"

which, however, won't work. There is nothing appended to /tmp/offload, which means the external script is not called.
So, my question is, what I miss here? Any input is appreciated.
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Kernel & Hardware All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum