1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
|
#! /bin/bash
# This script generates rules for persistent network device naming
# Data from udev-182 75-persistent-net-generator.rules
# Updated fof udev-197 (DEVICES=en*)
RULES=/etc/udev/rules.d/70-persistent-net.rules
DEVICES=$(eval echo /sys/class/net/{en*,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 must be mounted"
usage
fi
if ! mountpoint -q /proc; then
msg="/proc must 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
|