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 "mtu"
18 proto_config_add_string "server"
26 local optfile="/tmp/l2tp/options.${config}"
28 local ip serv_addr server
29 json_get_var server server && {
30 for ip in $(resolveip -t 5 "$server"); do
31 ( proto_add_host_dependency "$config" "$ip" )
35 [ -n "$serv_addr" ] || {
36 echo "Could not resolve server address"
38 proto_setup_failed "$config"
42 if [ ! -p /var/run/xl2tpd/l2tp-control ]; then
43 /etc/init.d/xl2tpd start
46 json_get_vars ipv6 demand keepalive username password pppd_options
47 [ "$ipv6" = 1 ] || ipv6=""
48 if [ "${demand:-0}" -gt 0 ]; then
49 demand="precompiled-active-filter /etc/ppp/filter demand idle $demand"
54 [ -n "$mtu" ] || json_get_var mtu mtu
56 local interval="${keepalive##*[, ]}"
57 [ "$interval" != "$keepalive" ] || interval=5
61 echo "${keepalive:+lcp-echo-interval $interval lcp-echo-failure ${keepalive%%[, ]*}}" > "${optfile}"
62 echo "usepeerdns" >> "${optfile}"
63 echo "nodefaultroute" >> "${optfile}"
64 echo "${username:+user \"$username\" password \"$password\"}" >> "${optfile}"
65 echo "ipparam \"$config\"" >> "${optfile}"
66 echo "ifname \"l2tp-$config\"" >> "${optfile}"
67 echo "ip-up-script /lib/netifd/ppp-up" >> "${optfile}"
68 echo "ipv6-up-script /lib/netifd/ppp-up" >> "${optfile}"
69 echo "ip-down-script /lib/netifd/ppp-down" >> "${optfile}"
70 echo "ipv6-down-script /lib/netifd/ppp-down" >> "${optfile}"
71 # Don't wait for LCP term responses; exit immediately when killed.
72 echo "lcp-max-terminate 0" >> "${optfile}"
73 echo "${ipv6:++ipv6} ${pppd_options}" >> "${optfile}"
74 echo "${mtu:+mtu $mtu mru $mtu}" >> "${optfile}"
76 xl2tpd-control add l2tp-${config} pppoptfile=${optfile} lns=${server} redial=yes redial timeout=20
77 xl2tpd-control connect l2tp-${config}
80 proto_l2tp_teardown() {
82 local optfile="/tmp/l2tp/options.${interface}"
86 proto_notify_error "$interface" AUTH_FAILED
87 proto_block_restart "$interface"
90 proto_notify_error "$interface" INVALID_OPTIONS
91 proto_block_restart "$interface"
95 xl2tpd-control disconnect l2tp-${interface}
96 # Wait for interface to go down
97 while [ -d /sys/class/net/l2tp-${interface} ]; do
101 xl2tpd-control remove l2tp-${interface}
105 [ -n "$INCLUDE_ONLY" ] || {