mirror of
https://github.com/novatiq/packages.git
synced 2026-04-30 15:38:40 +01:00
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>
This commit is contained in:
committed by
Daniel Golle
parent
15f744bb53
commit
59f33d2aa7
+37
-14
@@ -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" ] || {
|
||||
|
||||
Reference in New Issue
Block a user