hotplug support for USB DSL modems
This script automatically starts a network connection when an USB DSL modem is plugged and initialized.
I do not think it's worth distributing it with udev, but I am posting it in the hope that other distributions will finally provide decent support for these devices.
SUBSYSTEM=="atm", RUN+="dsl-modem.agent"
# from the Debian hotplug.functions:
wait_for_file() {
local file=$1
local timeout=$2
[ "$timeout" ] || timeout=120 local count=$timeout
while [ $count != 0 ]; do
[ -e "$file" ] && return 0
sleep 1
count=$(($count - 1))
done mesg "$file did not appear before the timeout!"
exit 1
}
Signature · 2 lines
ciao, Marco
#!/bin/sh -e
#
# Copyright 2008 Marco d'Itri <[email protected]>
#
# This script automatically starts networking when a DSL modem is connected
# and its ATM interface is ready. # # # For PPPoE you can set PROTOCOL=2684bridged and then add something like # this to /etc/network/interfaces: # # allow-hotplug nas0 # iface nas0 inet manual # pre-up ip link set up $IFACE # up pppd persist call dsl-provider # # # Support for CLIP (Classical IP over ATM, RFC 1577) may be incomplete. #
# defaults [ "$IP_INTERFACE" ] || IP_INTERFACE='nas0' [ "$VP" ] || VP='8' [ "$VC" ] || VC='35'
if [ -e /etc/default/dsl-modem.agent ]; then
. /etc/default/dsl-modem.agent
fi
# just exit unless a protocol is configured [ "$PROTOCOL" ] || exit 0
##############################################################################wait_and_run_pppd() {
# this guarantees that everything pppd needs to work is ready wait_for_file /dev/log
exec pppd persist call ${PPP_PEER:-dsl-provider}
}
wait_and_run_br2684ctl() {
wait_for_file /dev/log
exec br2684ctl $BR2684_ARGS -b -c ${IP_INTERFACE#nas} \
-a ${ATM_INTERFACE}.${VP}.${VC}
}wait_and_run_atmarp() {
wait_for_file /var/run/atmarpd.table
# create the IP interface
atmarp -c ${IP_INTERFACE:-atm0}
# setup the VC
# atmarp -s 192.0.2.254 ${ATM_INTERFACE}.${VP}.${VC}
exec ifup ${IP_INTERFACE:-atm0} # XXX
}##############################################################################
ATM_DRIVER=${NAME%%[0-9]*}
ATM_INTERFACE=${NAME##$ATM_DRIVER}
# is this a DSL modem? case "$ATM_DRIVER" in cxacru|speedtch|ueagle-atm|xusbatm|UNICORN) ;; *) exit 0 ;; esac
cd /lib/udev/
. ./hotplug.functions
##############################################################################
case "$ACTION" in
add)
case "$PROTOCOL" in
pppoa) wait_and_run_pppd & ;;
2684bridged) wait_and_run_br2684ctl & ;;
clip) wait_and_run_atmarp & ;;
esac
;;
remove)
case "$PROTOCOL" in
pppoa)
# pppd will terminate automatically
;;
2684bridged)
PIDFILE="/var/run/$IP_INTERFACE.pid"
if [ -e $PIDFILE ]; then
kill $(cat $PIDFILE)
rm -f $PIDFILE
fi
;;
clip)
ifdown ${IP_INTERFACE:-atm0} # XXX
# atmarp -d 192.0.2.254
;;
esac
;;
esacexit 0