[b2b1e1a] | 1 | #! /bin/bash
|
---|
| 2 |
|
---|
| 3 | # This script generates rules for persistent network device naming
|
---|
| 4 | # Data from udev-182 75-persistent-net-generator.rules
|
---|
[872a378] | 5 | # Updated for udev-197 (DEVICES=en*)
|
---|
[b2b1e1a] | 6 |
|
---|
[3781c69] | 7 | RULES=/etc/udev/rules.d/70-persistent-net.rules
|
---|
[cdd87ad] | 8 | DEVICES=$(eval echo /sys/class/net/{en*,eth*,ath*,wlan*[0-9],msh*,ra*,sta*,ctc*,lcs*,hsi*})
|
---|
[b2b1e1a] | 9 |
|
---|
| 10 | function usage
|
---|
| 11 | {
|
---|
| 12 | echo $msg
|
---|
| 13 | echo "init-net-rules.sh is an LFS-specific script to initialize"
|
---|
| 14 | echo "$RULES"
|
---|
| 15 | exit 1
|
---|
| 16 | }
|
---|
| 17 |
|
---|
| 18 | declare -A VENDORS_IGNORED
|
---|
| 19 | VENDORS_IGNORED['52:54:00:']="kvm"
|
---|
| 20 | VENDORS_IGNORED['00:0c:29:']="vmware"
|
---|
| 21 | VENDORS_IGNORED['00:50:56:']="vmware"
|
---|
| 22 | VENDORS_IGNORED['00:15:5d:']="hyper-v"
|
---|
| 23 | VENDORS_IGNORED['00:00:00:']="invalid"
|
---|
| 24 |
|
---|
| 25 | declare -A VENDORS
|
---|
| 26 | VENDORS['02:07:01:']="Interlan, DEC, etc"
|
---|
| 27 | VENDORS['02:60:60:']="3com"
|
---|
| 28 | VENDORS['02:60:8c:']="3Com IBM PC; Imagen. etc"
|
---|
| 29 | VENDORS['02:a0:c9:']="intel"
|
---|
| 30 | VENDORS['02:aa:3c:']="Olivetti"
|
---|
| 31 | VENDORS['02:cf:1f:']="Masscomp, Silicon Graphics, etc"
|
---|
| 32 | VENDORS['02:e0:3b:']="Gigabit"
|
---|
| 33 | VENDORS['02:e6:d3:']="BTI"
|
---|
| 34 | VENDORS['52:54:00:']="Realtek"
|
---|
| 35 | VENDORS['52:54:4c:']="Novell"
|
---|
| 36 | VENDORS['52:54:ab:']="Realtek"
|
---|
| 37 | VENDORS['e2:0c:0f:']="Kingston"
|
---|
| 38 | VENDORS['00:16:3e:']="Xensource"
|
---|
| 39 |
|
---|
| 40 | function ignore_if
|
---|
| 41 | {
|
---|
| 42 | if [[ "${VENDORS_IGNORED[$VENDOR]}" != "" ]]; then return 0; fi
|
---|
| 43 | if [[ "${VENDORS[$VENDOR]}" != "" ]]; then return 1; fi
|
---|
| 44 |
|
---|
| 45 | byte2=$(echo $VENDOR | cut -c2)
|
---|
| 46 | if echo $byte2 | grep -q "[2367abef]"; then return 0; fi
|
---|
| 47 |
|
---|
| 48 | return 1 # Default is to not ignore
|
---|
| 49 | }
|
---|
| 50 |
|
---|
| 51 | function comment
|
---|
| 52 | {
|
---|
| 53 | # Not implemented
|
---|
| 54 | # SUBSYSTEMS=="pci"
|
---|
| 55 | # export COMMENT="PCI device $attr{vendor}:$attr{device} ($driver)"
|
---|
| 56 |
|
---|
| 57 | # SUBSYSTEMS=="usb", ATTRS{idVendor}=="?*"
|
---|
| 58 | # export COMMENT="USB device 0x$attr{idVendor}:0x$attr{idProduct} ($driver)"
|
---|
| 59 |
|
---|
| 60 | # SUBSYSTEMS=="pcmcia",
|
---|
| 61 | # export COMMENT="PCMCIA device $attr{card_id}:$attr{manf_id} ($driver)"
|
---|
| 62 |
|
---|
| 63 | # SUBSYSTEMS=="ieee1394",
|
---|
| 64 | # export COMMENT="Firewire device $attr{host_id})"
|
---|
| 65 |
|
---|
| 66 | # ibmveth likes to use "locally administered" MAC addresses
|
---|
| 67 | # DRIVERS=="ibmveth",
|
---|
| 68 | # export COMMENT="ibmveth ($id)"
|
---|
| 69 |
|
---|
| 70 | # S/390 uses id matches only, do not use MAC address match
|
---|
[3781c69] | 71 | # SUBSYSTEMS=="ccwgroup",
|
---|
| 72 | # export COMMENT="S/390 $driver device at $id",
|
---|
| 73 | # export MATCHID="$id"
|
---|
[b2b1e1a] | 74 | # export MATCHDRV="$driver"
|
---|
| 75 | # export MATCHADDR=""
|
---|
| 76 |
|
---|
| 77 | # Default
|
---|
| 78 | driver=$(basename $(readlink -f $NIC/device/driver/module))
|
---|
| 79 | export COMMENT="net device ${driver}"
|
---|
| 80 | }
|
---|
| 81 |
|
---|
| 82 | if ! mountpoint -q /sys; then
|
---|
[947141c] | 83 | msg="/sys must be mounted"
|
---|
[b2b1e1a] | 84 | usage
|
---|
| 85 | fi
|
---|
| 86 |
|
---|
| 87 | if ! mountpoint -q /proc; then
|
---|
[947141c] | 88 | msg="/proc must be mounted"
|
---|
[b2b1e1a] | 89 | usage
|
---|
| 90 | fi
|
---|
| 91 |
|
---|
| 92 | if [ -e $RULES ]; then
|
---|
| 93 | msg="The rules file already exists"
|
---|
| 94 | usage
|
---|
| 95 | fi
|
---|
| 96 |
|
---|
| 97 | # Ignore Xen virtual interfaces
|
---|
| 98 | if [ -e /proc/xen ]; then
|
---|
| 99 | msg="The rules file should not be created in the Xen environment"
|
---|
| 100 | usage
|
---|
[3781c69] | 101 | fi
|
---|
[b2b1e1a] | 102 |
|
---|
| 103 | # Variables used to communicate with write_net_rules:
|
---|
[3781c69] | 104 | # INTERFACE simple interface name
|
---|
[b2b1e1a] | 105 | # MATCHADDR MAC address used for the match
|
---|
| 106 | # MATCHID bus_id used for the match
|
---|
| 107 | # MATCHDRV driver name used for the match
|
---|
| 108 | # MATCHIFTYPE interface type match
|
---|
| 109 | # COMMENT comment to add to the generated rule
|
---|
| 110 | # INTERFACE_NAME requested name supplied by external tool
|
---|
| 111 | # INTERFACE_NEW new interface name returned by rule writer
|
---|
| 112 |
|
---|
| 113 | for NIC in $DEVICES; do
|
---|
| 114 | IF=${NIC##*/}
|
---|
| 115 | if echo $NIC | grep -q '*' ; then continue; fi
|
---|
| 116 |
|
---|
| 117 | export INTERFACE=${NIC##*/} # Simple interface name
|
---|
| 118 | export MATCHADDR="$(cat $NIC/address)" # Read MAC address
|
---|
| 119 |
|
---|
| 120 | VENDOR=$(echo $MATCHADDR | cut -c-9)
|
---|
| 121 | if ignore_if; then continue; fi
|
---|
| 122 |
|
---|
| 123 | export MATCHDEVID="$(cat $NIC/dev_id)"
|
---|
| 124 | export MATCHIFTYPE="$(cat $NIC/type)" # Read interface type
|
---|
| 125 | comment
|
---|
| 126 |
|
---|
[3781c69] | 127 | /lib/udev/write_net_rules
|
---|
[b2b1e1a] | 128 | done
|
---|
| 129 |
|
---|