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