sed "s/ip_tag/ip_tag\naccess-list private permit $1\/32/g" $RIPDCONF > $RIPDCONF.tmp
cp $RIPDCONF.tmp $RIPDCONF
}
del_ip() {
echo del_ip $1
sed "/$1/d" $RIPDCONF > $RIPDCONF.tmp
cp $RIPDCONF.tmp $RIPDCONF
if $GREP "access-list private permit" $RIPDCONF>/dev/null
then
echo some other IP is running
reload_config
else
stop_quagga
echo remove $RIPDCONF
rm $RIPDCONF
fi
}
add_nic() {
echo add_nic $1
if $GREP "network $1" $RIPDCONF >/dev/null
then
echo the nic is already in the config file
else
sed "s/nic_tag/nic_tag\n no passive-interface $1\n network $1\n distribute-list private out $1\n distribute-list private in $1/g" $RIPDCONF > $RIPDCONF.tmp
cp $RIPDCONF.tmp $RIPDCONF
fi
}
reload_config() {
echo reload_config
echo $RIPDCONF:
cat $RIPDCONF
echo killall -SIGHUP ripd
killall -SIGHUP ripd
}
start_quagga() {
echo start_quagga
echo $RIPDCONF:
cat $RIPDCONF
echo $ZEBRA -d
$ZEBRA -d
echo $RIPD -d -f $RIPDCONF
$RIPD -d -f $RIPDCONF
}
stop_quagga() {
echo stop_quagga
echo $RIPDCONF:
cat $RIPDCONF
echo killall -SIGTERM ripd
killall -SIGTERM ripd
echo killall -SIGTERM zebra
killall -SIGTERM zebra
}
start_rip_ip() {
echo start_rip_ip
check_params
if [ x"$OCF_RESKEY_nic" = x ]
then
echo OCF_RESKEY_nic is null, set to ${OCF_RESKEY_nic_default}
OCF_RESKEY_nic="${OCF_RESKEY_nic_default}"
fi
status_rip_ip
case $? in
$OCF_SUCCESS)
ocf_log info "already running"
exit $OCF_SUCCESS
;;
$OCF_NOT_RUNNING)
;;
*)
ocf_log info "state undefined, stopping first"
stop_rip_ip
;;
esac
$IP2UTIL addr add $OCF_RESKEY_ip/32 dev lo
if [ -f "$RIPDCONF" ]
then
# there is a config file, add new data(IP,nic,metric)
# to the existing config file.
add_ip $OCF_RESKEY_ip
add_nic $OCF_RESKEY_nic
set_metric 1
reload_config
echo sleep 3
sleep 3
set_metric 3
reload_config
else
new_config_file $OCF_RESKEY_ip $OCF_RESKEY_nic 1
start_quagga
echo sleep 3
sleep 3
set_metric 3
reload_config
fi
return $OCF_SUCCESS
}
stop_rip_ip() {
echo stop_rip_ip
check_params
status_rip_ip
if [ $? = $OCF_NOT_RUNNING ]
then
exit $OCF_SUCCESS
fi
$IP2UTIL addr del $OCF_RESKEY_ip dev lo
echo sleep 2
sleep 2
del_ip $OCF_RESKEY_ip
return $OCF_SUCCESS
}
status_rip_ip() {
check_params
if $IP2UTIL addr | $GREP $OCF_RESKEY_ip >/dev/null