Simple - scripted - automated failover pppoe-wan - 3G modem

@trendy

mwan3 and the whole configuration I found complicated for such a simple feature. Honestly.

Well, I got some inspiration from this older post:

And managed to make my simple script functional. Functional from the OpenWRT/UCI system PoV, but wrong from the PoV of the nested if statements, I'll need to inspect them again. Check if there are some limitations in -ash or if I did some mistakes (syntax) on my own.
Here is the functional but "illogical" script:

#!/bin/sh

PPPOE=`/bin/grep "pppoe-wan" /proc/net/dev`
3G-UMTS=`/bin/grep "3g-UMTS" /proc/net/dev`
if  [ -n "$PPPOE" ] ; then
  if [ -n "$3G-UMTS" ] ; then
   /bin/ubus call network.interface.UMTS down
   #cycle wan to get back the ppoe-wan default route
   /sbin/ifdown wan
   /sbin/ifup wan
   /usr/bin/logger -t FAILOVER PPPoE up - disabling 3G uplink
  fi
 else
  if [ -c "/dev/ttyUSB2" ] ; then
   /bin/ubus call network.interface.UMTS up
   /usr/bin/logger -t FAILOVER PPPoE down - enabling 3G uplink
  fi
fi
unset PPPOE
unset 3G-UMTS

Actual "logical" behavior on every execution:

  • if wan is disconnected then it connects the 3G - every time!
  • if wan is connected it disconnects the 3G and reconnects the wan - every time!

P.S. An observation: If you follow the OpenWRT docs, then the 3G interface will be called wwan and not UMTS. UMTS is the name I used when I defined it. For instance, the actual:
/bin/ubus call network.interface.UMTS up
will be:
/bin/ubus call network.interface.wwan up
The exact name is to be found in /etc/config/network In my case is it was:

config interface 'UMTS'
        option proto '3g'
        option device '/dev/ttyUSB2'
        option service 'umts_only'