/[baselayout]/branches/baselayout-1_12/net-scripts/net/arping.sh
Gentoo

Contents of /branches/baselayout-1_12/net-scripts/net/arping.sh

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2050 - (show annotations) (download) (as text)
Fri Jun 2 20:02:40 2006 UTC (8 years, 4 months ago) by uberlord
File MIME type: text/x-sh
File size: 4177 byte(s)
    Allow LC_* and LANG vars through to runscript.sh by default.

    net.lo now comes after bootmisc, #135118 thanks to Oldrich Jedlicka.

    arping.sh now has MAC address support, #134253 thanks to Oldrich Jedlicka.

    pppd.sh now updates secret files with a blank password, #134337

    Remove swapon call from /sbin/rc as localmount already calls it,
    partial fix for #134489
1 # Copyright (c) 2004-2006 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
3 # Contributed by Roy Marples (uberlord@gentoo.org)
4
5 # void arping_depend(void)
6 #
7 # Sets up the dependancies for the module
8 arping_depend() {
9 functions interface_exists interface_up
10 }
11
12 # bool arping_check_installed(void)
13 #
14 # Returns 0 if arping or arping2 is installed, otherwise 1
15 arping_check_installed() {
16 [[ -x /sbin/arping || -x /usr/sbin/arping2 ]] && return 0
17 if ${1:-false}; then
18 eerror "For arping support emerge net-misc/iputils or net-analyzer/arping"
19 fi
20 return 1
21 }
22
23 # void arping_sleep(char *interface)
24 #
25 # Allows the interface to settle on the LAN - normally takes around 3 seconds
26 # This requires the use of a global variable, ARPING_SLEPT
27 arping_sleep() {
28 local iface="$1"
29 [[ ${ARPING_SLEPT} == "1" ]] && return
30
31 local ifvar="$(bash_variable "${iface}")"
32 local s="arping_sleep_${ifvar}"
33 s="${!s}"
34 if [[ -z ${s} ]] ; then
35 s="${arping_sleep}"
36 s="${s:-1}"
37 fi
38 sleep "${s}"
39 ARPING_SLEPT="1"
40 }
41
42 # bool arping_address_exists(char *interface, char *address)
43 #
44 # Returns 0 if the address on the interface responds to an arping
45 # 1 if not - packets defaults to 1
46 # If neither arping (net-misc/iputils) or arping2 (net-analyzer/arping)
47 # is installed then we return 1
48 arping_address_exists() {
49 local iface="$1" ip="${2%%/*}" mac="$3" foundmac= i= w=
50
51 # We only handle IPv4 addresses
52 [[ ${ip} != *.*.*.* ]] && return 1
53
54 # 0.0.0.0 isn't a valid address - and some lusers have configured this
55 [[ ${ip} == "0.0.0.0" || ${ip} == "0" ]] && return 1
56
57 # We need to bring the interface up to test
58 interface_exists "${iface}" || return 1
59 interface_up "${iface}"
60
61 arping_sleep
62
63 local ifvar="$(bash_variable "${iface}")"
64 w="arping_wait_${ifvar}"
65 w="${!w}"
66 [[ -z ${w} ]] && w="${arping_wait:-3}"
67
68 if [[ -x /sbin/arping ]] ; then
69 foundmac="$(arping -c 2 -w "${w}" -D -f -I "${iface}" \
70 "${ip}" 2>/dev/null \
71 | sed -n 's/.*\[\([^]]*\)\].*/\U\1/p')"
72 elif [[ -x /usr/sbin/arping2 ]] ; then
73 for (( i=0; i<w; i++ )) ; do
74 foundmac="$(arping2 -r -0 -c 1 -i "${iface}" \
75 "${ip}" 2>/dev/null)"
76 if [[ $? == "0" ]] ; then
77 foundmac="$(echo "${foundmac}" \
78 | tr '[:lower:]' '[:upper:]')"
79 break
80 fi
81 foundmac=
82 done
83 fi
84
85 [[ -z ${foundmac} ]] && return 1
86
87 if [[ -n ${mac} ]] ; then
88 if [[ ${mac} != "${foundmac}" ]] ; then
89 vewarn "Found ${ip} but MAC ${foundmac} does not match"
90 return 1
91 fi
92 fi
93
94 return 0
95 }
96
97 # bool arping_start(char *iface)
98 #
99 # arpings a list of gateways
100 # If one is foung then apply it's configuration
101 arping_start() {
102 local iface="$1" gateways x conf i
103 local ifvar="$(bash_variable "${iface}")"
104
105 einfo "Pinging gateways on ${iface} for configuration"
106
107 gateways="gateways_${ifvar}[@]"
108 if [[ -z "${!gateways}" ]] ; then
109 eerror "No gateways have been defined (gateways_${ifvar}=( \"...\"))"
110 return 1
111 fi
112
113 eindent
114
115 for x in ${!gateways}; do
116 local -a a=( ${x//,/ } )
117 local ip="${a[0]}" mac="${a[1]}" extra=
118 if [[ -n ${mac} ]] ; then
119 mac="$(echo "${mac}" | tr '[:lower:]' '[:upper:]')"
120 extra="(MAC ${mac})"
121 fi
122
123 vebegin "${ip} ${extra}"
124 if arping_address_exists "${iface}" "${ip}" "${mac}" ; then
125 for i in ${ip//./ } ; do
126 if [[ ${#i} == "2" ]] ; then
127 conf="${conf}0${i}"
128 elif [[ ${#i} == "1" ]] ; then
129 conf="${conf}00${i}"
130 else
131 conf="${conf}${i}"
132 fi
133 done
134 [[ -n ${mac} ]] && conf="${conf}_${mac//:/}"
135
136 veend 0
137 eoutdent
138 veinfo "Configuring ${iface} for ${ip} ${extra}"
139 configure_variables "${iface}" "${conf}"
140
141 # Call the system module as we've aleady passed it by ....
142 # And it *has* to be pre_start for other things to work correctly
143 system_pre_start "${iface}"
144
145 t="config_${ifvar}[@]"
146
147 # Only return if we HAVE a config that doesn't include
148 # arping to avoid infinite recursion.
149 if [[ " ${!t} " != *" arping "* ]] ; then
150 config=( "${!t}" )
151 t="fallback_config_${ifvar}[@]"
152 fallback_config=( "${!t}" )
153 t="fallback_route_${ifvar}[@]"
154 fallback_route=( "${!t}" )
155 config_counter=-1
156 return 0
157 fi
158 fi
159 veend 1
160 done
161
162 eoutdent
163 return 1
164 }
165
166 # vim: set ts=4 :

  ViewVC Help
Powered by ViewVC 1.1.20