Shell PPPoE watcher script

Since ppp program does not restart once remote echo requests stop, and we can not send our own echo requests, because the provider does reply with bongled ones, we need a script to watch PPP(oE):

/root/bin/watch_ppp.sh

Code:
#!/bin/sh

export dslif=epair1b
export dslpkts=0
export dslfails=0
export pppstatus=""

watch_dsl_line() {
  old_dslpkts=$dslpkts
  dslpkts=`netstat -f link -I $dslif | cut -w -f 5 | tail -n 1`
  if [ $dslpkts -le $old_dslpkts  ]
  then \
    dslfails=`expr $dslfails \+ 1`
    if [ $dslfails -gt 1 ]
    then \
      echo "`date`: ERROR DSL Line inactive, stopping"
      service ppp stop
    fi
  else \
    echo "`date`: WARNING DSL Line catched up"
    dslfails=0
  fi
}

start_dsl_line() {
  dslfails=0
  echo "`date`: WARNING PPP was not running, starting"
  service ppp start
}

while true
do \
  sleep 30
  pppstatus="`service ppp status`"
  case "$pppstatus" in
    "ppp is not running."       ) start_dsl_line ;;
    "ppp is running as pid"*    ) watch_dsl_line ;;
  esac
done

/etc/rc.d/watch_ppp_service

Code:
#!/bin/sh

# PROVIDE: watch_ppp_service
# REQUIRE: NETWORKING

. /etc/rc.subr

name="watch_ppp"
rcvar="watch_ppp_enable"
start_cmd="start_watch_ppp"

start_watch_ppp() {
  /usr/sbin/daemon -o /var/log/watch_ppp.log /root/bin/watch_ppp.sh
}

load_rc_config $name
run_rc_command "$1"
 
Since ppp program does not restart once remote echo requests stop, and we can not send our own echo requests, because the provider does reply with bongled ones, we need a script to watch PPP(oE):
If your ppp(8) is operating in -ddial mode, it should not be necessary to fully restart it. Sending SIGINT to the ppp process or using pppctl close should be sufficient to force a reconnect. Also you might want to consider migrating to net/mpd5.
 
Very good. I work that ideas in. mpd5 I did not know of, thanks for that tip as well.
 
And what about running ppp(8) in auto mode? Doesn't that work for you?
The auto mode in ppp(8) is for dial-on-demand scenarios, where the link goes down after being idle and is brought back up once new traffic arrives. Unless your ISP charges you per connected time, what you want is ddial mode, which keeps the link up at all times regardless of traffic. The real problem here is that on PPPoE links you will usually not have a hardware carrier detect signal available, or it just states that the ethernet link between your ethernet interface and the external DSL modem is up, which is likely the case at all times. So you have to rely on some other mechanism to detect a link down event. There are two such mechanisms supported by ppp(8): Link quality reporting (LQR) and LCP ECHO requests. LQR requires support from the peer (which doesn't seem widely deployed), whereas the peer is required to answer to LCP ECHO requests. You can safely enable both using enable lqr echo in /etc/ppp/ppp.conf. If the peer doesn't support LQR it will be rejected and ppp(8) will fall back to using LCP ECHO instead. But that is not of much use if the peer sends back bongled replies (whatever that means exactly), as the OP stated. Ultimately the ISP is at fault here, if it doesn't adhere to the standards.
 
Back
Top