#!/bin/sh
# Clear NetBSD ADSL authentication failures
# Designed to be run from cron
# Author: Michael-John Turner <mj@turner.org.za>
#

IF_PPPOE=pppoe0
SLEEP=90

export PATH=/sbin:/bin:/usr/sbin:/usr/bin

# Check if the interface is down (0 == true, 1 == false)
#
if_down()
{
	eval ifname=${1}
	if ifconfig -ld | grep $ifname > /dev/null; then
		return 0
	else
		return 1
	fi
}

# If interface is down, wait SLEEP seconds. If it's
# still down, reset auth failures and up it
#
if if_down $IF_PPPOE; then
	sleep $SLEEP
	if if_down $IF_PPPOE; then
		logger -t $IF_PPPOE -p daemon.info "Interface $IF_PPPOE down - resetting auth failures and bringing up"
		pppoectl $IF_PPPOE clear-auth-failure
		ifconfig $IF_PPPOE up
	fi
fi



