Lines 27-53
Link Here
|
27 |
# If neither arping (net-misc/iputils) or arping2 (net-analyzer/arping) |
27 |
# If neither arping (net-misc/iputils) or arping2 (net-analyzer/arping) |
28 |
# is installed then we return 1 |
28 |
# is installed then we return 1 |
29 |
arping_address_exists() { |
29 |
arping_address_exists() { |
30 |
local iface="$1" address="${2%%/*}" i |
30 |
local iface="$1" ip="${2%%/*}" mac="$3" i found_mac |
31 |
|
31 |
|
32 |
# We only handle IPv4 addresses |
32 |
# We only handle IPv4 addresses |
33 |
[[ ${address} != *.*.*.* ]] && return 1 |
33 |
[[ ${ip} != *.*.*.* && ${ip} != *.*.*.*\[*:*:*:*:*:*\] ]] && return 1 |
34 |
|
34 |
|
35 |
# 0.0.0.0 isn't a valid address - and some lusers have configured this |
35 |
# 0.0.0.0 isn't a valid address - and some lusers have configured this |
36 |
[[ ${address} == "0.0.0.0" || ${address} == "0" ]] && return 1 |
36 |
[[ ${ip} == "0.0.0.0" || ${ip} == "0" ]] && return 1 |
37 |
|
37 |
|
38 |
# We need to bring the interface up to test |
38 |
# We need to bring the interface up to test |
39 |
interface_exists "${iface}" || return 1 |
39 |
interface_exists "${iface}" || return 1 |
40 |
interface_up "${iface}" |
40 |
interface_up "${iface}" |
41 |
|
41 |
|
42 |
if [[ -x /sbin/arping ]] ; then |
42 |
if [[ -x /sbin/arping ]] ; then |
43 |
/sbin/arping -q -c 2 -w 3 -D -f -I "${iface}" "${address}" \ |
43 |
if [[ -n ${mac} ]] ; then |
44 |
&>/dev/null || return 0 |
44 |
found_mac="`\ |
|
|
45 |
/sbin/arping -c 2 -w 3 -D -f \ |
46 |
-I "${iface}" "${ip}" \ |
47 |
2>/dev/null | \ |
48 |
/bin/sed -n 's/.*\\[\\([^]]*\\)\\].*/\\1/p' | \ |
49 |
/bin/tr [:lower:] [:upper:]`" |
50 |
[[ ${found_mac} == ${mac} ]] && return 0 |
51 |
else |
52 |
/sbin/arping -q -c 2 -w 3 -D -f -I "${iface}" "${ip}" \ |
53 |
&>/dev/null || return 0 |
54 |
fi |
45 |
elif [[ -x /usr/sbin/arping2 ]] ; then |
55 |
elif [[ -x /usr/sbin/arping2 ]] ; then |
46 |
for (( i=0; i<3; i++ )) ; do |
56 |
if [[ -n ${mac} ]]; then |
47 |
/usr/sbin/arping2 -0 -c 1 -i "${iface}" "${address}" \ |
57 |
for (( i=0; i<3; i++ )) ; do |
48 |
&>/dev/null && return 0 |
58 |
found_mac="`\ |
49 |
done |
59 |
/usr/sbin/arping2 -r -0 -c 1 -i "${iface}" "${ip}" \ |
|
|
60 |
2>/dev/null`" |
61 |
if [[ $? == 0 ]]; then |
62 |
found_mac=$(echo ${found_mac} | \ |
63 |
/bin/tr [:lower:] [:upper:]) |
64 |
[[ ${found_mac} == ${mac} ]] && return 0 |
65 |
break |
66 |
fi |
67 |
done |
68 |
else |
69 |
for (( i=0; i<3; i++ )) ; do |
70 |
/usr/sbin/arping2 -0 -c 1 -i "${iface}" "${ip}" \ |
71 |
&>/dev/null && return 0 |
72 |
done |
73 |
fi |
50 |
fi |
74 |
fi |
|
|
75 |
|
76 |
if [[ -n ${mac} && -n ${found_mac} ]] ; then |
77 |
vewarn "Found ${ip}, but MAC ${found_mac} doesn't match" |
78 |
fi |
79 |
|
51 |
return 1 |
80 |
return 1 |
52 |
} |
81 |
} |
53 |
|
82 |
|
Lines 56-62
Link Here
|
56 |
# arpings a list of gateways |
85 |
# arpings a list of gateways |
57 |
# If one is foung then apply it's configuration |
86 |
# If one is foung then apply it's configuration |
58 |
arping_start() { |
87 |
arping_start() { |
59 |
local iface="$1" gateways x conf i |
88 |
local iface="$1" gateways x ip mac conf i |
60 |
|
89 |
|
61 |
interface_exists "${iface}" true || return 1 |
90 |
interface_exists "${iface}" true || return 1 |
62 |
|
91 |
|
Lines 71-79
Link Here
|
71 |
eindent |
100 |
eindent |
72 |
|
101 |
|
73 |
for x in ${!gateways}; do |
102 |
for x in ${!gateways}; do |
74 |
vebegin "${x}" |
103 |
|
75 |
if arping_address_exists "${iface}" "${x}" ; then |
104 |
# Separate ip address and MAC address |
76 |
for i in ${x//./ } ; do |
105 |
ip="${x%%\[*\]}" |
|
|
106 |
mac="${x}[" |
107 |
mac="${mac#*\[}" |
108 |
mac="${mac%\[}" |
109 |
mac="${mac%\]}" |
110 |
|
111 |
if [ -n ${mac} ]; then |
112 |
vebegin "${ip} (MAC $mac)" |
113 |
else |
114 |
vebegin "${ip}" |
115 |
fi |
116 |
|
117 |
if arping_address_exists "${iface}" "${ip}" "${mac}"; then |
118 |
for i in ${ip//./ } ; do |
77 |
if [[ ${#i} == "2" ]] ; then |
119 |
if [[ ${#i} == "2" ]] ; then |
78 |
conf="${conf}0${i}" |
120 |
conf="${conf}0${i}" |
79 |
elif [[ ${#i} == "1" ]] ; then |
121 |
elif [[ ${#i} == "1" ]] ; then |
Lines 82-90
Link Here
|
82 |
conf="${conf}${i}" |
124 |
conf="${conf}${i}" |
83 |
fi |
125 |
fi |
84 |
done |
126 |
done |
|
|
127 |
if [[ -n ${mac} ]]; then |
128 |
conf="${conf}_" |
129 |
for i in ${mac//:/ } ; do |
130 |
conf="${conf}${i}" |
131 |
done |
132 |
conf=$(echo ${conf} | tr [:lower:] [:upper:]) |
133 |
fi |
85 |
veend 0 |
134 |
veend 0 |
86 |
eoutdent |
135 |
eoutdent |
87 |
veinfo "Configuring ${iface} for ${x}" |
136 |
if [ -n ${mac} ]; then |
|
|
137 |
veinfo "Configuring ${iface} for ${ip} (MAC ${mac})" |
138 |
else |
139 |
veinfo "Configuring ${iface} for ${ip}" |
140 |
fi |
88 |
configure_variables "${iface}" "${conf}" |
141 |
configure_variables "${iface}" "${conf}" |
89 |
|
142 |
|
90 |
# Call the system module as we've aleady passed it by .... |
143 |
# Call the system module as we've aleady passed it by .... |