aboutsummaryrefslogtreecommitdiffstats
path: root/udev-lfs/init-net-rules.sh
diff options
context:
space:
mode:
authorBruce Dubbs <bdubbs@linuxfromscratch.org>2012-09-01 02:31:13 +0000
committerBruce Dubbs <bdubbs@linuxfromscratch.org>2012-09-01 02:31:13 +0000
commitb2b1e1aa5fe437877a7ec9f7d861e215c956ebb9 (patch)
treee79563b34728d0e475dbf5d73da4e5cd1a278de6 /udev-lfs/init-net-rules.sh
parent166497f2c69435a594f9992ad55857112eb44127 (diff)
Move directory to make build easier
git-svn-id: http://svn.linuxfromscratch.org/LFS/trunk/BOOK@9973 4aa44e1e-78dd-0310-a6d2-fbcd4c07a689
Diffstat (limited to 'udev-lfs/init-net-rules.sh')
-rw-r--r--udev-lfs/init-net-rules.sh128
1 files changed, 128 insertions, 0 deletions
diff --git a/udev-lfs/init-net-rules.sh b/udev-lfs/init-net-rules.sh
new file mode 100644
index 000000000..1e65794ab
--- /dev/null
+++ b/udev-lfs/init-net-rules.sh
@@ -0,0 +1,128 @@
+#! /bin/bash
+
+# This script generates rules for persistent network device naming
+# Data from udev-182 75-persistent-net-generator.rules
+
+RULES=/etc/udev/rules.d/70-persistent-net.rules
+DEVICES=$(eval echo /sys/class/net/{eth*,ath*,wlan*[0-9],msh*,ra*,sta*,ctc*,lcs*,hsi*})
+
+function usage
+{
+ echo $msg
+ echo "init-net-rules.sh is an LFS-specific script to initialize"
+ echo "$RULES"
+ exit 1
+}
+
+declare -A VENDORS_IGNORED
+VENDORS_IGNORED['52:54:00:']="kvm"
+VENDORS_IGNORED['00:0c:29:']="vmware"
+VENDORS_IGNORED['00:50:56:']="vmware"
+VENDORS_IGNORED['00:15:5d:']="hyper-v"
+VENDORS_IGNORED['00:00:00:']="invalid"
+
+declare -A VENDORS
+VENDORS['02:07:01:']="Interlan, DEC, etc"
+VENDORS['02:60:60:']="3com"
+VENDORS['02:60:8c:']="3Com IBM PC; Imagen. etc"
+VENDORS['02:a0:c9:']="intel"
+VENDORS['02:aa:3c:']="Olivetti"
+VENDORS['02:cf:1f:']="Masscomp, Silicon Graphics, etc"
+VENDORS['02:e0:3b:']="Gigabit"
+VENDORS['02:e6:d3:']="BTI"
+VENDORS['52:54:00:']="Realtek"
+VENDORS['52:54:4c:']="Novell"
+VENDORS['52:54:ab:']="Realtek"
+VENDORS['e2:0c:0f:']="Kingston"
+VENDORS['00:16:3e:']="Xensource"
+
+function ignore_if
+{
+ if [[ "${VENDORS_IGNORED[$VENDOR]}" != "" ]]; then return 0; fi
+ if [[ "${VENDORS[$VENDOR]}" != "" ]]; then return 1; fi
+
+ byte2=$(echo $VENDOR | cut -c2)
+ if echo $byte2 | grep -q "[2367abef]"; then return 0; fi
+
+ return 1 # Default is to not ignore
+}
+
+function comment
+{
+ # Not implemented
+ # SUBSYSTEMS=="pci"
+ # export COMMENT="PCI device $attr{vendor}:$attr{device} ($driver)"
+
+ # SUBSYSTEMS=="usb", ATTRS{idVendor}=="?*"
+ # export COMMENT="USB device 0x$attr{idVendor}:0x$attr{idProduct} ($driver)"
+
+ # SUBSYSTEMS=="pcmcia",
+ # export COMMENT="PCMCIA device $attr{card_id}:$attr{manf_id} ($driver)"
+
+ # SUBSYSTEMS=="ieee1394",
+ # export COMMENT="Firewire device $attr{host_id})"
+
+ # ibmveth likes to use "locally administered" MAC addresses
+ # DRIVERS=="ibmveth",
+ # export COMMENT="ibmveth ($id)"
+
+ # S/390 uses id matches only, do not use MAC address match
+ # SUBSYSTEMS=="ccwgroup",
+ # export COMMENT="S/390 $driver device at $id",
+ # export MATCHID="$id"
+ # export MATCHDRV="$driver"
+ # export MATCHADDR=""
+
+ # Default
+ driver=$(basename $(readlink -f $NIC/device/driver/module))
+ export COMMENT="net device ${driver}"
+}
+
+if ! mountpoint -q /sys; then
+ msg="/sys mut be mounted"
+ usage
+fi
+
+if ! mountpoint -q /proc; then
+ msg="/proc mut be mounted"
+ usage
+fi
+
+if [ -e $RULES ]; then
+ msg="The rules file already exists"
+ usage
+fi
+
+# Ignore Xen virtual interfaces
+if [ -e /proc/xen ]; then
+ msg="The rules file should not be created in the Xen environment"
+ usage
+fi
+
+# Variables used to communicate with write_net_rules:
+# INTERFACE simple interface name
+# MATCHADDR MAC address used for the match
+# MATCHID bus_id used for the match
+# MATCHDRV driver name used for the match
+# MATCHIFTYPE interface type match
+# COMMENT comment to add to the generated rule
+# INTERFACE_NAME requested name supplied by external tool
+# INTERFACE_NEW new interface name returned by rule writer
+
+for NIC in $DEVICES; do
+ IF=${NIC##*/}
+ if echo $NIC | grep -q '*' ; then continue; fi
+
+ export INTERFACE=${NIC##*/} # Simple interface name
+ export MATCHADDR="$(cat $NIC/address)" # Read MAC address
+
+ VENDOR=$(echo $MATCHADDR | cut -c-9)
+ if ignore_if; then continue; fi
+
+ export MATCHDEVID="$(cat $NIC/dev_id)"
+ export MATCHIFTYPE="$(cat $NIC/type)" # Read interface type
+ comment
+
+ /lib/udev/write_net_rules
+done
+