3 [ -x /usr/sbin/xl2tpd ] || exit 0
5 [ -n "$INCLUDE_ONLY" ] || {
11 proto_l2tp_init_config() {
12 proto_config_add_string "username"
13 proto_config_add_string "password"
14 proto_config_add_string "keepalive"
15 proto_config_add_string "pppd_options"
16 proto_config_add_boolean "ipv6"
17 proto_config_add_int "demand"
18 proto_config_add_int "mtu"
19 proto_config_add_int "checkup_interval"
20 proto_config_add_string "server"
24 teardown_on_l3_link_down=1
29 local optfile="/tmp/l2tp/options.${interface}"
30 local ip serv_addr server host
32 json_get_var server server
34 for ip in $(resolveip -t 5 "$host"); do
35 ( proto_add_host_dependency "$interface" "$ip" )
38 [ -n "$serv_addr" ] || {
39 echo "Could not resolve server address" >&2
41 proto_setup_failed "$interface"
45 # Start and wait for xl2tpd
46 if [ ! -p /var/run/xl2tpd/l2tp-control -o -z "$(pidof xl2tpd)" ]; then
47 /etc/init.d/xl2tpd restart
50 while [ ! -p /var/run/xl2tpd/l2tp-control ]; do
51 wait_timeout=$(($wait_timeout + 1))
52 [ "$wait_timeout" -gt 5 ] && {
53 echo "Cannot find xl2tpd control file." >&2
54 proto_setup_failed "$interface"
61 local ipv6 demand keepalive username password pppd_options mtu
62 json_get_vars ipv6 demand keepalive username password pppd_options mtu
63 [ "$ipv6" = 1 ] || ipv6=""
64 if [ "${demand:-0}" -gt 0 ]; then
65 demand="precompiled-active-filter /etc/ppp/filter demand idle $demand"
70 local interval="${keepalive##*[, ]}"
71 [ "$interval" != "$keepalive" ] || interval=5
73 keepalive="${keepalive:+lcp-echo-interval $interval lcp-echo-failure ${keepalive%%[, ]*}}"
74 username="${username:+user \"$username\" password \"$password\"}"
76 mtu="${mtu:+mtu $mtu mru $mtu}"
83 ifname "l2tp-$interface"
84 ip-up-script /lib/netifd/ppp-up
85 ipv6-up-script /lib/netifd/ppp-up
86 ip-down-script /lib/netifd/ppp-down
87 ipv6-down-script /lib/netifd/ppp-down
88 # Don't wait for LCP term responses; exit immediately when killed.
97 xl2tpd-control add l2tp-${interface} pppoptfile=${optfile} lns=${server} || {
98 echo "xl2tpd-control: Add l2tp-$interface failed" >&2
99 proto_setup_failed "$interface"
102 xl2tpd-control connect l2tp-${interface} || {
103 echo "xl2tpd-control: Connect l2tp-$interface failed" >&2
104 proto_setup_failed "$interface"
109 proto_l2tp_teardown() {
111 local optfile="/tmp/l2tp/options.${interface}"
114 if [ -p /var/run/xl2tpd/l2tp-control ]; then
115 xl2tpd-control remove l2tp-${interface} || {
116 echo "xl2tpd-control: Remove l2tp-$interface failed" >&2
119 # Wait for interface to go down
120 while [ -d /sys/class/net/l2tp-${interface} ]; do
125 [ -n "$INCLUDE_ONLY" ] || {