Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # cat /etc/conf.d/net
- L2TP_BACKEND="xl2tpd"
- L2TP_TIMEOUT=20
- DEPEND="lan"
- L2TP="ppp0"
- ROUTES="
- 195.14.50.0/27
- 78.106.0.0/15
- 224.0.0.0/4
- "
- config_lan="dhclient"
- dhclient_lan="-nw"
- config_ppp0="null"
- #mtu_lan=1500
- #config_lan="dhcp"
- modules_wifi="!iwconfig !wpa_supplicant"
- config_wifi="192.168.2.1 netmask 255.255.255.0 broadcast 192.168.2.255"
- depend_ppp0() {
- need net.${DEPEND}
- }
- check_module () {
- if ! [[ -f /proc/net/pppol2tp ]]; then
- ebegin "Loading l2tp module"
- # try both new and old module names
- modprobe l2tp_ppp 2>/dev/null || modprobe pppol2tp 2>/dev/null
- eend $?.
- fi
- }
- checkconfig() {
- if [ "${L2TP_BACKEND}" = "xl2tpd" ]; then
- if [[ ! -f /etc/xl2tpd/xl2tpd.conf ]] ; then
- eerror "Missing /etc/xl2tpd/xl2tpd.conf configuration file!"
- eerror "Example configuration file could be found in doc directory."
- return 1
- fi
- if [ ! -d /var/run/xl2tpd ] ; then
- checkpath -d -m 755 /var/run/xl2tpd
- fi
- fi
- return 0
- }
- preup() {
- if [ -z "${L2TP_BACKEND}" ]; then
- L2TP_BACKEND="xl2tpd"
- fi
- checkconfig || return 1
- if [ x"${IFACE}" = x"${L2TP}" ]; then
- if [ "${L2TP_BACKEND}" = "xl2tpd" ]; then
- start-stop-daemon --start --quiet --exec /usr/sbin/xl2tpd
- else
- check_module
- start-stop-daemon --start --quiet --exec /usr/sbin/openl2tpd
- fi
- iface_timer=0
- while [ $iface_timer -lt $L2TP_TIMEOUT ]; do
- if [ -n "$(ifconfig | grep ${IFACE})" ]; then
- eend 0
- return 0
- else
- if [ ${iface_timer} -eq 0 ]; then
- einfo "Waiting for l2tp..."
- fi
- sleep 1
- ((iface_timer++))
- fi
- done
- cleanup_l2tp
- eend 1
- return 1
- fi
- return 0
- }
- postup() {
- if [ x"${IFACE}" = x"${L2TP}" ]; then
- gw=`route -n | awk "{ if (\\$1 == \"0.0.0.0\" && \\$8 == \"${DEPEND}\") print \\$2 }" | perl -e 'print split("\n", <>, 1)'`
- vpn=`ifconfig | grep -A1 ${IFACE} | grep -i p-t-p | awk '{ print $3 }' | sed 's/p-t-p://gi'`
- echo "TRY: route add ${vpn} gw ${gw}"
- route add ${vpn} gw ${gw}
- for i in ${ROUTES}; do
- echo "TRY: route add -net ${i} gw ${gw}"
- route add -net ${i} gw ${gw}
- done
- fi
- return 0
- }
- predown() {
- if [ -z "${L2TP_BACKEND}" ]; then
- L2TP_BACKEND="xl2tpd"
- fi
- if [ x"${IFACE}" = x"${L2TP}" ]; then
- gw=`route -n | awk "{ if (\\$1 == \"0.0.0.0\" && \\$8 == \"${DEPEND}\") print \\$2 }" | perl -e 'print split("\n", <>, 1)'`
- vpn=`ifconfig | grep -A1 ${IFACE} | grep -i p-t-p | awk '{ print $3 }' | sed 's/p-t-p://gi'`
- # vpn=`ifconfig | grep -A1 ${IFACE} | grep -i dest | awk '{ print $6 }'`
- echo "GW: ${gw}" > 1111;
- cleanup_l2tp
- if [ -n ${gw} ]; then
- route del ${vpn} gw ${gw}
- for i in ${ROUTES}; do
- route del -net ${i} gw ${gw}
- done
- fi
- fi
- return 0
- }
- cleanup_l2tp() {
- if [ "${L2TP_BACKEND}" = "xl2tpd" ]; then
- start-stop-daemon --stop --quiet --pidfile /var/run/xl2tpd.pid
- if [ -n "$(pidof xl2tpd)" ]; then
- killall -9 xl2tpd > /dev/null 2>&1
- fi
- if [ -e /var/run/xl2tpd.pid ]; then
- rm -f /var/run/xl2tpd.pid
- fi
- else
- start-stop-daemon --stop --quiet --pidfile /var/run/openl2tpd.pid
- if [ -n "$(pidof openl2tpd)" ]; then
- killall -9 openl2tpd > /dev/null 2>&1
- fi
- if [ -e /var/run/openl2tpd.pid ]; then
- rm -f /var/run/openl2tpd.pid
- fi
- fi
- killall pppd > /dev/null 2>&1
- if [ -n "$(pidof pppd)" ]; then
- killall -9 pppd > /dev/null 2>&1
- fi
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement