Ticket #2057: write_all_net_rules

File write_all_net_rules, 1.7 KB (added by bryan@linuxfromscratch.org, 17 years ago)

Possible script to call write_net_rules for each NIC (should work with current udev git)

Line 
1#!/bin/bash
2
3for link in /sys/class/net/* ; do
4 export DEVPATH=${link#/sys}
5 export INTERFACE=${DEVPATH#/class/net/}
6
7 # whenever udev updates, this whitelist should be copied from
8 # /etc/udev/rules.d/75-persistent-net-generator.rules:
9 case "$INTERFACE" in
10 eth*|ath*|wlan*[0-9]|msh*|ra*|sta*|ctc*|lcs*|hsi*)
11 ;;
12 *)
13 continue
14 ;;
15 esac
16
17 # read "address" and "type" attributes
18 export MATCHADDR=$(< $link/address)
19 export MATCHIFTYPE=$(< $link/type)
20
21 # do not use locally administered or empty (all-zeros) MAC addresses
22 case "$MATCHADDR" in
23 ?[2367abef]:*|00:00:00:00:00:00)
24 continue
25 ;;
26 esac
27
28 # ensure there's a driver
29 [ -L $link/device/driver ] || continue
30 export MATCHDRV=$(basename $(readlink $link/device/driver))
31
32 # figure out what type of device this is
33 tgt=$(readlink $link/device)
34 case "$tgt" in
35 *pcmcia*)
36 card_id=$(< $link/device/card_id)
37 manf_id=$(< $link/device/manf_id)
38 export COMMENT="PCMCIA device ${card_id}:${manf_id} (${MATCHDRV})"
39 ;;
40 *ieee1394*)
41 host_id=$(< $link/device/host_id)
42 export COMMENT="Firewire device ${host_id} (${MATCHDRV})"
43 ;;
44 *usb*)
45 # PCMCIA devices might, possibly, hang off a USB bus
46 # (not likely, but it doesn't hurt)
47 vnd=$(< $link/device/idVendor)
48 prd=$(< $link/device/idProduct)
49 export COMMENT="USB device 0x${vnd}:0x${prd} (${MATCHDRV})"
50 ;;
51 *pci*)
52 # must be last: other types hang off the PCI bus too
53 vnd=$(< $link/device/vendor)
54 dev=$(< $link/device/device)
55 export COMMENT="PCI device ${vnd}:${dev} (${MATCHDRV})"
56 ;;
57 *)
58 export COMMENT="Unknown-subsystem device (${MATCHDRV})"
59 ;;
60 esac
61
62 # don't worry about normal output, only errors
63 /lib/udev/write_net_rules >/dev/null
64done