/[baselayout]/trunk/net.Linux/arping.sh
Gentoo

Contents of /trunk/net.Linux/arping.sh

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2670 - (show annotations) (download) (as text)
Mon Apr 30 13:19:26 2007 UTC (7 years, 2 months ago) by uberlord
File MIME type: text/x-sh
File size: 2424 byte(s)
Stop using the [ -z "$@" ] test, use [ $# = 0 ] instead, #176554.
1 # Copyright 2004-2007 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
3
4 arping_depend() {
5 program /sbin/arping
6 before interface
7 }
8
9 arping_address() {
10 local ip=${1%%/*} mac="$2" foundmac= i= w= opts=
11
12 # We only handle IPv4 addresses
13 case "${ip}" in
14 0.0.0.0|0) return 1 ;;
15 *.*.*.*) ;;
16 *) return 1 ;;
17 esac
18
19 # We need to bring the interface up to test
20 _exists "${iface}" || return 1
21 _up "${iface}"
22
23 eval w=\$arping_wait_${IFVAR}
24 [ -z "${w}" ] && w=${arping_wait:-5}
25
26 [ -z "$(_get_inet_address)" ] && opts="${opts} -D"
27
28 foundmac="$(arping -w "${w}" ${opts} -f -I "${IFACE}" "${ip}" 2>/dev/null | \
29 sed -n -e 'y/abcdef/ABCDEF/' -e 's/.*\[\([^]]*\)\].*/\1/p')"
30 [ -z "${foundmac}" ] && return 1
31
32 if [ -n "${mac}" ] ; then
33 if [ "${mac}" != "${foundmac}" ] ; then
34 vewarn "Found ${ip} but MAC ${foundmac} does not match"
35 return 1
36 fi
37 fi
38
39 return 0
40 }
41
42 arping_start() {
43 local gateways= x= conf= i=
44 einfo "Pinging gateways on ${IFACE} for configuration"
45
46 eval $(_get_array "gateways_${IFVAR}")
47 if [ $# = 0 ] ; then
48 eerror "No gateways have been defined (gateways_${IFVAR}=\"...\")"
49 return 1
50 fi
51
52 eindent
53
54 for x in "$@"; do
55 eval set -- "${x}"
56 local ip=$1 mac=$2 extra=
57
58 if [ -n "${mac}" ] ; then
59 mac="$(echo "${mac}" | tr '[:lower:]' '[:upper:]')"
60 extra="(MAC ${mac})"
61 fi
62
63 vebegin "${ip} ${extra}"
64 if arping_address "${ip}" "${mac}" ; then
65 local OIFS=$IFS SIFS=${IFS-y}
66 IFS=.
67 for i in ${ip} ; do
68 if [ "${#i}" = "2" ] ; then
69 conf="${conf}0${i}"
70 elif [ "${#i}" = "1" ] ; then
71 conf="${conf}00${i}"
72 else
73 conf="${conf}${i}"
74 fi
75 done
76 if [ "${SIFS}" = "y" ] ; then
77 IFS=$OFIS
78 else
79 unset IFS
80 fi
81 [ -n "${mac}" ] && conf="${conf}_$(echo "${mac}" | sed -e 's/://g')"
82
83 veend 0
84 eoutdent
85 veinfo "Configuring ${IFACE} for ${ip} ${extra}"
86 _configure_variables "${conf}"
87
88 # Call the system module as we've aleady passed it by ....
89 # And it *has* to be pre_start for other things to work correctly
90 system_pre_start
91
92 # Ensure that we have a valid config - ie arping is no longer there
93 eval $(_get_array "config_${IFVAR}")
94 for i in "$@" ; do
95 if [ "${i}" = "arping" ] ; then
96 veend 1 "No config found for ${ip} (config_${conf}=\"...\")"
97 continue 2
98 fi
99 done
100
101 _load_config
102 return 0
103 fi
104 veend 1
105 done
106
107 eoutdent
108 return 1
109 }
110
111 # vim: set ts=4 :

  ViewVC Help
Powered by ViewVC 1.1.20