Init changes.

This commit is contained in:
Steven Bakker 2005-10-19 21:49:55 +00:00
parent cbc2c1f186
commit 47746078db
5 changed files with 175 additions and 54 deletions

View File

@ -1,5 +1,17 @@
@(#)$Id$
3.8 - 19.oct.2005 - steven
* Updated init script to move away from $SPONGE_OPTS and have a
more flexible set-up using separate variables which can be
overridden in the individual interface files.
This breaks the old syntax! Instead of a single string
in /etc/default/arpsponge/ethX (namely the network/prefix),
we need to define "NETWORK=network/prefix". It is also possible
to override the device "ethX" by setting "DEVICE".
* Added POD documentation for the new init set-up.
3.7 - 30.sep.2005 - steven
* Fixed the f*cking call to f*cking Net::ARP::get_mac($dev, $mac).
It never wanted a reference as the second parameter, which

6
debian/changelog vendored
View File

@ -1,3 +1,9 @@
arpsponge (3.8) unstable; urgency=low
* See upstream Changelog.
-- Steven Bakker <sb@ams-ix.net> Wed, 19 Oct 2005 23:25:00 +0200
arpsponge (3.7) unstable; urgency=low
* See upstream Changelog.

View File

@ -13,42 +13,91 @@ PROG=arpsponge
SPONGE_VAR=@SPONGE_VAR@
SPONGE_OPTIONS="@SPONGE_OPTIONS@"
# Program defaults
export DUMMY_MODE INIT_MODE SPONGE_NETWORK LEARNING
export QUEUE_DEPTH RATE PENDING SWEEP GRATUITOUS AGE
# Defaults for all sponges.
if test -f /etc/default/${PROG}/defaults ; then
. /etc/default/${PROG}/defaults
fi
start() {
[ "X$1" = "Xre-init" ] && re_init=true || re_init=false
eval_bool() {
var=$1
case $var in
[1-9]*|0[1-9]*|y|yes|true|on|Y|YES|TRUE|ON)
true
return;;
*)
false
return;;
esac
}
start_sponge() {
file=$1
export file
(
DEVICE=$(basename $file)
unset NETWORK
. $file
opts=''
eval_bool ${DUMMY_MODE} && opts="$opts --dummy"
eval_bool ${SPONGE_NETWORK} && opts="$opts --sponge-network"
eval_bool ${GRATUITOUS} && opts="$opts --gratuitous"
[ -n "${INIT_MODE}" ] && opts="$opts --init=${INIT_MODE}"
[ -n "${LEARNING}" ] && opts="$opts --learning=${LEARNING}"
[ -n "${QUEUE_DEPTH}" ] && opts="$opts --queuedepth=${QUEUE_DEPTH}"
[ -n "${RATE}" ] && opts="$opts --queuedepth=${RATE}"
[ -n "${PENDING}" ] && opts="$opts --pending=${PENDING}"
[ -n "${SWEEP}" ] && opts="$opts --sweep=${SWEEP}"
[ -n "${AGE}" ] && opts="$opts --age=${AGE}"
if [ ! -n "${DEVICE}" ]
then
echo "** arpsponge init error: $file: no device specified">&2
exit 1
fi
if [ ! -n "${NETWORK}" ]
then
echo "** arpsponge init error: $file ($DEVICE): no network specified">&2
exit 1
fi
notify="${SPONGE_VAR}/${DEVICE}/notify"
status="${SPONGE_VAR}/${DEVICE}/status"
pidfile="${SPONGE_VAR}/${DEVICE}/pid"
if eval_bool $SPONGE_DEBUG
then
echo @BINDIR@/${PROG} ${opts} --daemon="${pidfile}" \
--notify="${notify}" --statusfile="${status}" \
${NETWORK} dev "${DEVICE}"
else
mkdir -p "${SPONGE_VAR}/${DEVICE}"
# Create notification FIFO...
[ -p "${notify}" ] || /usr/bin/mkfifo --mode=644 "${notify}"
printf " %-10s " "${DEVICE}"
echo @BINDIR@/${PROG} ${opts} --daemon="${pidfile}" \
--notify="${notify}" --statusfile="${status}" \
${NETWORK} dev "${DEVICE}" 2>/dev/null
[ $? -eq 0 ] && echo "[Ok]" || echo "[FAILED]"
fi
)
}
start() {
SPONGES=`/bin/ls -1 /etc/default/${PROG}/eth* 2>/dev/null`
if [ -n "${SPONGES}" ]
then
echo "Starting ${PROG}(s):"
for file in ${SPONGES}
do
if=$(basename "${file}")
mkdir -p "${SPONGE_VAR}/${if}"
notify="${SPONGE_VAR}/${if}/notify"
status="${SPONGE_VAR}/${if}/status"
pidfile="${SPONGE_VAR}/${if}/pid"
# Create notification FIFO...
[ -p "${notify}" ] || /usr/bin/mkfifo --mode=644 "${notify}"
printf " %-10s " "${if}"
if ${re_init} && [ -f ${status} ]
then
init_arg="--re-init=${status}"
else
init_arg=''
fi
@BINDIR@/${PROG} ${SPONGE_OPTIONS} --daemon="${pidfile}" \
--notify="${notify}" --statusfile="${status}" \
${init_arg} \
$(/bin/cat "/etc/default/${PROG}/${if}") \
dev "${if}" 2>/dev/null \
&& echo "[Ok]" || echo "[FAILED]"
start_sponge ${file}
done
fi
}

View File

@ -10,7 +10,7 @@ default : all
RM = /bin/rm -f
MV = /bin/mv
RELEASE = 3.7
RELEASE = 3.8
NAME = arpsponge
PACKAGE = $(NAME)-$(RELEASE)
TOOLDIR = $(TOPDIR)/tools

View File

@ -1168,19 +1168,19 @@ Now F</tmp/sponge.out> should contain something like:
started: 2005-04-30 23:26:39 [1114896399]
<STATE>
# IP State Queries Rate (q/min) Updated
193.194.136.129 ALIVE 0 0.000 2005-05-01 10:15:58
193.194.136.130 DEAD 6 0.012 2005-05-01 09:56:40
193.194.136.131 ALIVE 1 0.000 2005-05-01 09:41:40
193.194.136.135 ALIVE 0 0.000 2005-05-01 10:16:12
193.194.136.139 ALIVE 0 0.000 2005-05-01 10:06:28
193.194.136.140 DEAD 5 0.018 2005-05-01 09:41:40
193.194.136.143 DEAD 5 0.021 2005-05-01 10:11:40
193.194.136.146 ALIVE 0 0.000 2005-05-01 09:41:40
193.194.136.147 DEAD 6 0.013 2005-05-01 09:26:40
193.194.136.148 ALIVE 0 0.000 2005-05-01 10:12:38
193.194.136.185 PENDING(3) 3 0.019 2005-05-01 09:43:16
193.194.136.205 PENDING(4) 4 0.012 2005-05-01 09:43:16
# IP State Queries Rate (q/min) Updated
193.194.136.129 ALIVE 0 0.000 2005-05-01 10:15:58
193.194.136.130 DEAD 6 0.012 2005-05-01 09:56:40
193.194.136.131 ALIVE 1 0.000 2005-05-01 09:41:40
193.194.136.135 ALIVE 0 0.000 2005-05-01 10:16:12
193.194.136.139 ALIVE 0 0.000 2005-05-01 10:06:28
193.194.136.140 DEAD 5 0.018 2005-05-01 09:41:40
193.194.136.143 DEAD 5 0.021 2005-05-01 10:11:40
193.194.136.146 ALIVE 0 0.000 2005-05-01 09:41:40
193.194.136.147 DEAD 6 0.013 2005-05-01 09:26:40
193.194.136.148 ALIVE 0 0.000 2005-05-01 10:12:38
193.194.136.185 PENDING(3) 3 0.019 2005-05-01 09:43:16
193.194.136.205 PENDING(4) 4 0.012 2005-05-01 09:43:16
</STATE>
<ARP-TABLE>
@ -1204,7 +1204,23 @@ F</etc/init.d/@NAME@>. This script looks for the following files:
=item F</etc/default/@NAME@/defaults>
Contains default options for every sponge instance. The options are
specified as L<sh(1)|sh> shell variables. The options recognised are:
specified as L<sh(1)|sh> shell variables.
=item F</etc/default/@NAME@/ethX>
Contains a network definition for the sponge on I<ethX>.
=back
For every I<ethX> file the script finds, it starts a sponge daemon on
the I<ethX> interface. The sponge daemon will write its status file to
F<$SPONGE_VAR/ethX/status> and the notifications to the
F<$SPONGE_VAR/ethX/notify> FIFO.
=head2 Init Variables
For boolean variables, "true", "yes", "on" and positive integers evaluate
to "true", other values are "false".
=over 4
@ -1213,27 +1229,63 @@ specified as L<sh(1)|sh> shell variables. The options recognised are:
Directory root that holds state information for the various sponge
instances. The script will create the directory if it doesn't exist yet.
=item I<$SPONGE_OPTIONS> (default: C<@SPONGE_OPTIONS@>)
=item I<DUMMY_MODE> (boolean)
Other command line options to give to the B<@NAME@> daemon. Please note
that the script already provides appropriate C<--notify>, C<--statusfile>
and C<--daemon> options.
Use C<--dummy> on the sponge.
=item I<INIT_MODE>
Specify the C<--init> state.
=item I<SPONGE_NETWORK> (boolean)
Use C<--sponge-network>
=item I<LEARNING> (integer)
How many seconds to spend in learning mode.
=item I<QUEUE_DEPTH> (integer)
The argument to C<--queuedepth>.
=item I<RATE> (integer)
The argument to C<--rate>.
=item I<PENDING>
The argument to C<--pending>.
=item I<SWEEP>
The argument to C<--sweep>.
=item I<GRATUITOUS> (boolean)
Whether or not to send gratuitous ARPs (C<--gratuitous>).
=item I<AGE> (integer)
The argument to C<--age>.
=back
=item F</etc/default/@NAME@/ethX>
The I<ethX> files can override each of the above and can also specify:
Contains a network/prefixlen for the sponge on I<ethX>. N.B.: The
I<only> thing in this file should be a line of the form
"I<aaa.bbb.ccc.ddd/len>"!
=over 4
=item I<NETWORK> (mandatory)
This specifies the network for which to sponge.
=item I<DEVICE> (optional)
By default, the init script will use I<ethX> as the device name, but this
can be overridden with the I<DEVICE> variable.
=back
For every I<ethX> file the script finds, it starts a sponge daemon on
the I<ethX> interface. The sponge daemon will write its status file to
F<$SPONGE_VAR/ethX/status> and the notifications to the
F<$SPONGE_VAR/ethX/notify> FIFO.
=head1 FILES
=over 4
@ -1248,7 +1300,9 @@ Contains default options for the sponge's L<init(1)|init> script.
=item F</etc/default/@NAME@/ethX>
Contains a network/prefixlen for the sponge on I<ethX>.
Contains a interface specific options for the sponge on I<ethX>.
This I<must> define the C<NETWORK> variable.
This is used by the sponge's L<init(1)|init> script.
=item F<@SPONGE_VAR@/ethX/status>