2009-05-01 19:41:40 +05:30
|
|
|
# Copyright (c) 2007-2008 Roy Marples <roy@marples.name>
|
2008-01-11 21:01:10 +05:30
|
|
|
# All rights reserved. Released under the 2-clause BSD license.
|
2007-11-14 20:52:04 +05:30
|
|
|
|
2008-01-11 20:38:57 +05:30
|
|
|
arping_depend()
|
|
|
|
{
|
2007-10-30 17:09:19 +05:30
|
|
|
program /sbin/arping /usr/sbin/arping2
|
2007-04-05 16:48:42 +05:30
|
|
|
before interface
|
|
|
|
}
|
|
|
|
|
2008-01-11 20:38:57 +05:30
|
|
|
arping_address()
|
|
|
|
{
|
2007-10-30 17:09:19 +05:30
|
|
|
local ip=${1%%/*} mac="$2" spoof="$3" foundmac= i= w= opts=
|
2007-04-05 16:48:42 +05:30
|
|
|
|
|
|
|
# We only handle IPv4 addresses
|
|
|
|
case "${ip}" in
|
2007-11-28 21:15:03 +05:30
|
|
|
0.0.0.0|0) return 1;;
|
|
|
|
*.*.*.*);;
|
|
|
|
*) return 1;;
|
2007-04-05 16:48:42 +05:30
|
|
|
esac
|
|
|
|
|
|
|
|
# We need to bring the interface up to test
|
2011-01-17 15:19:07 +05:30
|
|
|
_exists "${iface}" || return 1
|
2007-04-05 16:48:42 +05:30
|
|
|
_up "${iface}"
|
|
|
|
|
|
|
|
eval w=\$arping_wait_${IFVAR}
|
|
|
|
[ -z "${w}" ] && w=${arping_wait:-5}
|
|
|
|
|
2007-10-30 17:09:19 +05:30
|
|
|
if type arping2 >/dev/null 2>&1; then
|
2007-11-01 21:23:52 +05:30
|
|
|
if [ -n "${spoof}" ]; then
|
|
|
|
opts="${opts} -S ${spoof}"
|
|
|
|
else
|
|
|
|
[ -z "$(_get_inet_address)" ] && opts="${opts} -0"
|
|
|
|
fi
|
2007-10-30 17:09:19 +05:30
|
|
|
while [ ${w} -gt 0 -a -z "${foundmac}" ]; do
|
2007-11-01 21:23:52 +05:30
|
|
|
foundmac="$(arping2 ${opts} -r -c 1 -i "${IFACE}" "${ip}" 2>/dev/null | \
|
2007-10-30 17:09:19 +05:30
|
|
|
sed -e 'y/abcdef/ABCDEF/')"
|
|
|
|
w=$((${w} - 1))
|
|
|
|
done
|
|
|
|
else
|
|
|
|
[ -z "$(_get_inet_address)" ] && opts="${opts} -D"
|
|
|
|
|
|
|
|
foundmac="$(arping -w "${w}" ${opts} -f -I "${IFACE}" "${ip}" 2>/dev/null | \
|
|
|
|
sed -n -e 'y/abcdef/ABCDEF/' -e 's/.*\[\([^]]*\)\].*/\1/p')"
|
|
|
|
fi
|
2007-04-05 16:48:42 +05:30
|
|
|
[ -z "${foundmac}" ] && return 1
|
2011-01-17 15:19:07 +05:30
|
|
|
|
2007-11-28 21:15:03 +05:30
|
|
|
if [ -n "${mac}" ]; then
|
|
|
|
if [ "${mac}" != "${foundmac}" ]; then
|
2007-04-05 16:48:42 +05:30
|
|
|
vewarn "Found ${ip} but MAC ${foundmac} does not match"
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
2008-01-11 20:38:57 +05:30
|
|
|
_arping_in_config()
|
|
|
|
{
|
2007-10-29 15:15:49 +05:30
|
|
|
_get_array "config_${IFVAR}" | while read i; do
|
2007-10-30 17:09:19 +05:30
|
|
|
[ "${i}" = "arping" ] && return 1
|
2007-10-29 15:15:49 +05:30
|
|
|
done
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
|
2008-01-11 20:38:57 +05:30
|
|
|
arping_start()
|
|
|
|
{
|
2007-04-05 16:48:42 +05:30
|
|
|
local gateways= x= conf= i=
|
|
|
|
einfo "Pinging gateways on ${IFACE} for configuration"
|
|
|
|
|
2007-10-29 15:15:49 +05:30
|
|
|
eval gateways=\$gateways_${IFVAR}
|
2007-11-28 21:15:03 +05:30
|
|
|
if [ -z "${gateways}" ]; then
|
2007-04-05 16:48:42 +05:30
|
|
|
eerror "No gateways have been defined (gateways_${IFVAR}=\"...\")"
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
eindent
|
2011-01-17 15:19:07 +05:30
|
|
|
|
2007-10-29 15:15:49 +05:30
|
|
|
for x in ${gateways}; do
|
|
|
|
local IFS=,
|
|
|
|
set -- ${x}
|
2007-10-30 17:09:19 +05:30
|
|
|
local ip=$1 mac=$2 spoof=$3 extra=
|
2007-10-29 15:15:49 +05:30
|
|
|
unset IFS
|
2007-04-05 16:48:42 +05:30
|
|
|
|
2007-11-28 21:15:03 +05:30
|
|
|
if [ -n "${mac}" ]; then
|
2007-04-05 16:48:42 +05:30
|
|
|
mac="$(echo "${mac}" | tr '[:lower:]' '[:upper:]')"
|
|
|
|
extra="(MAC ${mac})"
|
|
|
|
fi
|
|
|
|
|
|
|
|
vebegin "${ip} ${extra}"
|
2007-11-28 21:15:03 +05:30
|
|
|
if arping_address "${ip}" "${mac}" "${spoof}"; then
|
2007-10-30 17:09:19 +05:30
|
|
|
local IFS=.
|
2007-11-28 21:15:03 +05:30
|
|
|
for i in ${ip}; do
|
|
|
|
if [ "${#i}" = "2" ]; then
|
2007-04-05 16:48:42 +05:30
|
|
|
conf="${conf}0${i}"
|
2007-11-28 21:15:03 +05:30
|
|
|
elif [ "${#i}" = "1" ]; then
|
2007-04-05 16:48:42 +05:30
|
|
|
conf="${conf}00${i}"
|
|
|
|
else
|
|
|
|
conf="${conf}${i}"
|
|
|
|
fi
|
|
|
|
done
|
2007-10-30 17:09:19 +05:30
|
|
|
unset IFS
|
2007-04-05 16:48:42 +05:30
|
|
|
[ -n "${mac}" ] && conf="${conf}_$(echo "${mac}" | sed -e 's/://g')"
|
|
|
|
|
2007-10-30 17:09:19 +05:30
|
|
|
eend 0
|
2007-04-05 16:48:42 +05:30
|
|
|
eoutdent
|
|
|
|
veinfo "Configuring ${IFACE} for ${ip} ${extra}"
|
2007-10-30 17:09:19 +05:30
|
|
|
_configure_variables ${conf}
|
2007-04-05 16:48:42 +05:30
|
|
|
|
|
|
|
# Call the system module as we've aleady passed it by ....
|
|
|
|
# And it *has* to be pre_start for other things to work correctly
|
|
|
|
system_pre_start
|
|
|
|
|
|
|
|
# Ensure that we have a valid config - ie arping is no longer there
|
2007-10-30 17:09:19 +05:30
|
|
|
local IFS="$__IFS"
|
|
|
|
for i in $(_get_array "config_${IFVAR}"); do
|
|
|
|
if [ "${i}" = "arping" ]; then
|
|
|
|
eend 1 "No config found for ${ip} (config_${conf}=\"...\")"
|
|
|
|
continue 2
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
unset IFS
|
2011-01-17 15:19:07 +05:30
|
|
|
|
2007-04-05 16:48:42 +05:30
|
|
|
_load_config
|
|
|
|
return 0
|
|
|
|
fi
|
|
|
|
veend 1
|
|
|
|
done
|
|
|
|
|
|
|
|
eoutdent
|
|
|
|
return 1
|
|
|
|
}
|