source: udev-lfs/init-net-rules.sh@ b2b1e1a

10.0 10.0-rc1 10.1 10.1-rc1 11.0 11.0-rc1 11.0-rc2 11.0-rc3 11.1 11.1-rc1 11.2 11.2-rc1 11.3 11.3-rc1 12.0 12.0-rc1 12.1 12.1-rc1 7.3 7.4 7.5 7.5-systemd 7.6 7.6-systemd 7.7 7.7-systemd 7.8 7.8-systemd 7.9 7.9-systemd 8.0 8.1 8.2 8.3 8.4 9.0 9.1 arm bdubbs/gcc13 ml-11.0 multilib renodr/libudev-from-systemd s6-init trunk xry111/arm64 xry111/arm64-12.0 xry111/clfs-ng xry111/lfs-next xry111/loongarch xry111/loongarch-12.0 xry111/loongarch-12.1 xry111/mips64el xry111/pip3 xry111/rust-wip-20221008 xry111/update-glibc
Last change on this file since b2b1e1a was b2b1e1a, checked in by Bruce Dubbs <bdubbs@…>, 12 years ago

Move directory to make build easier

git-svn-id: http://svn.linuxfromscratch.org/LFS/trunk/BOOK@9973 4aa44e1e-78dd-0310-a6d2-fbcd4c07a689

  • Property mode set to 100644
File size: 3.5 KB
Line 
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
6RULES=/etc/udev/rules.d/70-persistent-net.rules
7DEVICES=$(eval echo /sys/class/net/{eth*,ath*,wlan*[0-9],msh*,ra*,sta*,ctc*,lcs*,hsi*})
8
9function 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
17declare -A VENDORS_IGNORED
18VENDORS_IGNORED['52:54:00:']="kvm"
19VENDORS_IGNORED['00:0c:29:']="vmware"
20VENDORS_IGNORED['00:50:56:']="vmware"
21VENDORS_IGNORED['00:15:5d:']="hyper-v"
22VENDORS_IGNORED['00:00:00:']="invalid"
23
24declare -A VENDORS
25VENDORS['02:07:01:']="Interlan, DEC, etc"
26VENDORS['02:60:60:']="3com"
27VENDORS['02:60:8c:']="3Com IBM PC; Imagen. etc"
28VENDORS['02:a0:c9:']="intel"
29VENDORS['02:aa:3c:']="Olivetti"
30VENDORS['02:cf:1f:']="Masscomp, Silicon Graphics, etc"
31VENDORS['02:e0:3b:']="Gigabit"
32VENDORS['02:e6:d3:']="BTI"
33VENDORS['52:54:00:']="Realtek"
34VENDORS['52:54:4c:']="Novell"
35VENDORS['52:54:ab:']="Realtek"
36VENDORS['e2:0c:0f:']="Kingston"
37VENDORS['00:16:3e:']="Xensource"
38
39function 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
50function 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
81if ! mountpoint -q /sys; then
82 msg="/sys mut be mounted"
83 usage
84fi
85
86if ! mountpoint -q /proc; then
87 msg="/proc mut be mounted"
88 usage
89fi
90
91if [ -e $RULES ]; then
92 msg="The rules file already exists"
93 usage
94fi
95
96# Ignore Xen virtual interfaces
97if [ -e /proc/xen ]; then
98 msg="The rules file should not be created in the Xen environment"
99 usage
100fi
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
112for 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
127done
128
Note: See TracBrowser for help on using the repository browser.