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

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

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

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

Legend:
Removed from v.3074  
changed lines
  Added in v.3075

  ViewVC Help
Powered by ViewVC 1.1.20