aboutsummaryrefslogtreecommitdiff
path: root/net/xl2tpd/files
diff options
context:
space:
mode:
authorYousong Zhou <yszhou4tech@gmail.com>2015-04-29 21:11:16 +0800
committerDaniel Golle <daniel@makrotopia.org>2015-05-24 12:18:38 +0200
commit59f33d2aa7da968294ee1ccdd1336dd7d7d76837 (patch)
treeaab9c8fd0abcc09a445b43d531463ef88cf7818c /net/xl2tpd/files
parent15f744bb53b889b201834764f02710a6e817012c (diff)
xl2tpd: refactor for more resilience.
- Use netifd no_proto_task for notifying that xl2tpd does not have a protocol task running. - Use procd for xl2tpd service management. - Refreshed 2xx patches to - Prevent leftover regular type control result file. - Allow xl2tpd run as foreground process while logging via syslog. Signed-off-by: Yousong Zhou <yszhou4tech@gmail.com> - bumped version - removed dependency on `ip` package as routes are setup by netifd if iproute2 is actually required, please depend on `@(PACKAGE_ip||PACKAGE_ip-full)` instead of `ip` Signed-off-by: Daniel Golle <daniel@makrotopia.org>
Diffstat (limited to 'net/xl2tpd/files')
-rw-r--r--net/xl2tpd/files/l2tp.sh51
-rw-r--r--net/xl2tpd/files/xl2tpd.init25
2 files changed, 52 insertions, 24 deletions
diff --git a/net/xl2tpd/files/l2tp.sh b/net/xl2tpd/files/l2tp.sh
index 867234dbe..0748654a7 100644
--- a/net/xl2tpd/files/l2tp.sh
+++ b/net/xl2tpd/files/l2tp.sh
@@ -18,31 +18,43 @@ proto_l2tp_init_config() {
proto_config_add_string "server"
available=1
no_device=1
+ no_proto_task=1
}
proto_l2tp_setup() {
- local config="$1"
- local iface="$2"
- local optfile="/tmp/l2tp/options.${config}"
+ local interface="$1"
+ local optfile="/tmp/l2tp/options.${interface}"
local ip serv_addr server
json_get_var server server && {
for ip in $(resolveip -t 5 "$server"); do
- ( proto_add_host_dependency "$config" "$ip" )
+ ( proto_add_host_dependency "$interface" "$ip" )
serv_addr=1
done
}
[ -n "$serv_addr" ] || {
- echo "Could not resolve server address"
+ echo "Could not resolve server address" >&2
sleep 5
- proto_setup_failed "$config"
+ proto_setup_failed "$interface"
exit 1
}
if [ ! -p /var/run/xl2tpd/l2tp-control ]; then
/etc/init.d/xl2tpd start
+
+ local wait_timeout=0
+ while [ ! -p /var/run/xl2tpd/l2tp-control ]; do
+ wait_timeout=$(($wait_timeout + 1))
+ [ "$wait_timeout" -gt 5 ] && {
+ echo "Cannot find xl2tpd control file." >&2
+ proto_setup_failed "$interface"
+ exit 1
+ }
+ sleep 1
+ done
fi
+ local ipv6 demand keepalive username password pppd_options
json_get_vars ipv6 demand keepalive username password pppd_options
[ "$ipv6" = 1 ] || ipv6=""
if [ "${demand:-0}" -gt 0 ]; then
@@ -51,6 +63,7 @@ proto_l2tp_setup() {
demand="persist"
fi
+ local mtu
[ -n "$mtu" ] || json_get_var mtu mtu
local interval="${keepalive##*[, ]}"
@@ -62,8 +75,8 @@ proto_l2tp_setup() {
echo "usepeerdns" >> "${optfile}"
echo "nodefaultroute" >> "${optfile}"
echo "${username:+user \"$username\" password \"$password\"}" >> "${optfile}"
- echo "ipparam \"$config\"" >> "${optfile}"
- echo "ifname \"l2tp-$config\"" >> "${optfile}"
+ echo "ipparam \"$interface\"" >> "${optfile}"
+ echo "ifname \"l2tp-$interface\"" >> "${optfile}"
echo "ip-up-script /lib/netifd/ppp-up" >> "${optfile}"
echo "ipv6-up-script /lib/netifd/ppp-up" >> "${optfile}"
echo "ip-down-script /lib/netifd/ppp-down" >> "${optfile}"
@@ -73,14 +86,23 @@ proto_l2tp_setup() {
echo "${ipv6:++ipv6} ${pppd_options}" >> "${optfile}"
echo "${mtu:+mtu $mtu mru $mtu}" >> "${optfile}"
- xl2tpd-control add l2tp-${config} pppoptfile=${optfile} lns=${server} redial=yes redial timeout=20
- xl2tpd-control connect l2tp-${config}
+ xl2tpd-control add l2tp-${interface} pppoptfile=${optfile} lns=${server} redial=yes redial timeout=20 || {
+ echo "xl2tpd-control: Add l2tp-$interface failed" >&2
+ proto_setup_failed "$interface"
+ exit 1
+ }
+ xl2tpd-control connect l2tp-${interface} || {
+ echo "xl2tpd-control: Connect l2tp-$interface failed" >&2
+ proto_setup_failed "$interface"
+ exit 1
+ }
}
proto_l2tp_teardown() {
local interface="$1"
local optfile="/tmp/l2tp/options.${interface}"
+ rm -f ${optfile}
case "$ERROR" in
11|19)
proto_notify_error "$interface" AUTH_FAILED
@@ -92,14 +114,15 @@ proto_l2tp_teardown() {
;;
esac
- xl2tpd-control disconnect l2tp-${interface}
+ if [ -p /var/run/xl2tpd/l2tp-control ]; then
+ xl2tpd-control remove l2tp-${interface} || {
+ echo "xl2tpd-control: Remove l2tp-$interface failed" >&2
+ }
+ fi
# Wait for interface to go down
while [ -d /sys/class/net/l2tp-${interface} ]; do
sleep 1
done
-
- xl2tpd-control remove l2tp-${interface}
- rm -f ${optfile}
}
[ -n "$INCLUDE_ONLY" ] || {
diff --git a/net/xl2tpd/files/xl2tpd.init b/net/xl2tpd/files/xl2tpd.init
index 22e845901..86098603e 100644
--- a/net/xl2tpd/files/xl2tpd.init
+++ b/net/xl2tpd/files/xl2tpd.init
@@ -1,18 +1,23 @@
#!/bin/sh /etc/rc.common
-# Copyright (C) 2006-2010 OpenWrt.org
+# Copyright (C) 2006-2015 OpenWrt.org
START=60
+USE_PROCD=1
+
BIN=xl2tpd
-DEFAULT=/etc/default/$BIN
-RUN_D=/var/run
-PID_F=$RUN_D/$BIN.pid
+RUN_D="/var/run/xl2tpd"
+PID_F="/var/run/xl2tpd.pid"
+
+start_service() {
+ rm -rf "$RUN_D"
+ mkdir -p "$RUN_D"
-start() {
- mkdir -p $RUN_D/$BIN
- [ -f $DEFAULT ] && . $DEFAULT
- $BIN $OPTIONS
+ procd_open_instance
+ procd_set_param command $BIN -D -l -p "$PID_F"
+ procd_close_instance
}
-stop() {
- [ -f $PID_F ] && kill $(cat $PID_F)
+stop_service() {
+ rm -rf "$RUN_D"
+ rm -rf "$PID_F"
}