openrc/net.Linux/arping.sh
Roy Marples 5af58b4514 Rewrite the core parts in C. We now provide librc so other programs can
query runlevels, services and state without using bash. We also provide
libeinfo so other programs can easily use our informational functions.

As such, we have dropped the requirement of using bash as the init script
shell. We now use /bin/sh and have strived to make the scripts as portable
as possible. Shells that work are bash and dash. busybox works provided
you disable s-s-d. If you have WIPE_TMP set to yes in conf.d/bootmisc you
should disable find too.
zsh and ksh do not work at this time.

Networking support is currently being re-vamped also as it was heavily bash
array based. As such, a new config format is available like so
config_eth0="1.2.3.4/24 5.6.7.8/16"
or like so
config_eth0="'1.2.3.4 netmask 255.255.255.0' '5.6.7.8 netmask 255.255.0.0'"

We will still support the old bash array format provided that /bin/sh IS
a link it bash.

ChangeLog for baselayout-1 can be found in our SVN repo.
2007-04-05 11:18:42 +00:00

112 lines
2.4 KiB
Bash

# Copyright 2004-2007 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
arping_depend() {
program /sbin/arping
before interface
}
arping_address() {
local ip=${1%%/*} mac="$2" foundmac= i= w= opts=
# We only handle IPv4 addresses
case "${ip}" in
0.0.0.0|0) return 1 ;;
*.*.*.*) ;;
*) return 1 ;;
esac
# We need to bring the interface up to test
_exists "${iface}" || return 1
_up "${iface}"
eval w=\$arping_wait_${IFVAR}
[ -z "${w}" ] && w=${arping_wait:-5}
[ -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')"
[ -z "${foundmac}" ] && return 1
if [ -n "${mac}" ] ; then
if [ "${mac}" != "${foundmac}" ] ; then
vewarn "Found ${ip} but MAC ${foundmac} does not match"
return 1
fi
fi
return 0
}
arping_start() {
local gateways= x= conf= i=
einfo "Pinging gateways on ${IFACE} for configuration"
eval $(_get_array "gateways_${IFVAR}")
if [ -z "$@" ] ; then
eerror "No gateways have been defined (gateways_${IFVAR}=\"...\")"
return 1
fi
eindent
for x in "$@"; do
eval set -- "${x}"
local ip=$1 mac=$2 extra=
if [ -n "${mac}" ] ; then
mac="$(echo "${mac}" | tr '[:lower:]' '[:upper:]')"
extra="(MAC ${mac})"
fi
vebegin "${ip} ${extra}"
if arping_address "${ip}" "${mac}" ; then
local OIFS=$IFS SIFS=${IFS-y}
IFS=.
for i in ${ip} ; do
if [ "${#i}" = "2" ] ; then
conf="${conf}0${i}"
elif [ "${#i}" = "1" ] ; then
conf="${conf}00${i}"
else
conf="${conf}${i}"
fi
done
if [ "${SIFS}" = "y" ] ; then
IFS=$OFIS
else
unset IFS
fi
[ -n "${mac}" ] && conf="${conf}_$(echo "${mac}" | sed -e 's/://g')"
veend 0
eoutdent
veinfo "Configuring ${IFACE} for ${ip} ${extra}"
_configure_variables "${conf}"
# 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
eval $(_get_array "config_${IFVAR}")
for i in "$@" ; do
if [ "${i}" = "arping" ] ; then
veend 1 "No config found for ${ip} (config_${conf}=\"...\")"
continue 2
fi
done
_load_config
return 0
fi
veend 1
done
eoutdent
return 1
}
# vim: set ts=4 :