From 59f33d2aa7da968294ee1ccdd1336dd7d7d76837 Mon Sep 17 00:00:00 2001 From: Yousong Zhou Date: Wed, 29 Apr 2015 21:11:16 +0800 Subject: [PATCH] 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 - 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 --- net/xl2tpd/Makefile | 8 +- net/xl2tpd/files/l2tp.sh | 51 +++++--- net/xl2tpd/files/xl2tpd.init | 25 ++-- ...eck-end-of-file-when-reading-pipe-t.patch} | 15 ++- ...fine-_GNU_SOURCE-to-use-fmemopen-an.patch} | 13 +- ...l-open-control-file-with-O_NONBLOCK.patch} | 11 +- ...d-control-cleaup-result-file-atexit.patch} | 29 +++-- ...ontrol-enhance-output-of-print_error.patch | 58 +++++++++ ...ypo-in-reporting-available-lns-count.patch | 34 +++++ ...ble-buffer-overflow-when-filling-str.patch | 22 ---- ...-place-opts-after-plugin-pppol2tp.s.patch} | 29 +++-- ...log-prefix-that-will-duplicate-with-.patch | 21 ---- ...-new-option-l-for-using-syslog-as-th.patch | 104 +++++++++++++++ ...sult-file-to-prevent-leftover-a-regu.patch | 26 ++++ .../209-xl2tpd-ignore-SIGPIPE-signal.patch | 32 +++++ ...-show-all-available-commands-in-help.patch | 119 ++++++++++++++++++ ...0-xl2tpd-control-atexit-needs-stdlib.patch | 12 -- 17 files changed, 495 insertions(+), 114 deletions(-) rename net/xl2tpd/patches/{201-xl2tpd-control-check-end-of-file-when-reading-pipe-t.patch => 200-xl2tpd-control-check-end-of-file-when-reading-pipe-t.patch} (70%) rename net/xl2tpd/patches/{202-xl2tpd-control-define-_GNU_SOURCE-to-use-fmemopen-an.patch => 201-xl2tpd-control-define-_GNU_SOURCE-to-use-fmemopen-an.patch} (50%) rename net/xl2tpd/patches/{203-xl2tpd-control-open-control-file-with-O_NONBLOCK.patch => 202-xl2tpd-control-open-control-file-with-O_NONBLOCK.patch} (80%) rename net/xl2tpd/patches/{205-xl2tpd-control-cleaup-result-file-atexit.patch => 203-xl2tpd-control-cleaup-result-file-atexit.patch} (66%) create mode 100644 net/xl2tpd/patches/204-xl2tpd-control-enhance-output-of-print_error.patch create mode 100644 net/xl2tpd/patches/205-xl2tpd-fix-typo-in-reporting-available-lns-count.patch delete mode 100644 net/xl2tpd/patches/206-xl2tpd-fix-possible-buffer-overflow-when-filling-str.patch rename net/xl2tpd/patches/{204-start_pppd-place-opts-after-plugin-pppol2tp.so.patch => 206-xl2tpd-start_pppd-place-opts-after-plugin-pppol2tp.s.patch} (59%) delete mode 100644 net/xl2tpd/patches/207-l2tp_log-remove-log-prefix-that-will-duplicate-with-.patch create mode 100644 net/xl2tpd/patches/207-xl2tpd-introduce-new-option-l-for-using-syslog-as-th.patch create mode 100644 net/xl2tpd/patches/208-xl2tpd-unlink-result-file-to-prevent-leftover-a-regu.patch create mode 100644 net/xl2tpd/patches/209-xl2tpd-ignore-SIGPIPE-signal.patch create mode 100644 net/xl2tpd/patches/210-xl2tpd-control-show-all-available-commands-in-help.patch delete mode 100644 net/xl2tpd/patches/250-xl2tpd-control-atexit-needs-stdlib.patch diff --git a/net/xl2tpd/Makefile b/net/xl2tpd/Makefile index 29107f085..c3582bef7 100644 --- a/net/xl2tpd/Makefile +++ b/net/xl2tpd/Makefile @@ -1,5 +1,5 @@ # -# Copyright (C) 2006-2014 OpenWrt.org +# Copyright (C) 2006-2015 OpenWrt.org # # This is free software, licensed under the GNU General Public License v2. # See /LICENSE for more information. @@ -8,14 +8,12 @@ include $(TOPDIR)/rules.mk PKG_NAME:=xl2tpd -PKG_VERSION:=1.3.7pre20141126 +PKG_VERSION:=1.3.7pre20150524 PKG_RELEASE:=1 PKG_MAINTAINER:=Daniel Golle PKG_LICENSE:=GPL-2.0 PKG_LICENSE_FILES:=LICENSE -PKG_RELEASE=$(PKG_SOURCE_VERSION) - PKG_SOURCE_PROTO:=git PKG_SOURCE_URL:=https://github.com/xelerance/xl2tpd.git PKG_SOURCE_SUBDIR:=$(PKG_NAME)-$(PKG_VERSION) @@ -32,7 +30,7 @@ define Package/xl2tpd TITLE:=An L2TP (Layer 2 Tunneling Protocol) daemon URL:=http://www.xelerance.com/software/xl2tpd/ SUBMENU:=VPN - DEPENDS:=+ppp-mod-pppol2tp +ip +resolveip + DEPENDS:=+ppp-mod-pppol2tp +resolveip endef define Package/xl2tpd/description 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" } diff --git a/net/xl2tpd/patches/201-xl2tpd-control-check-end-of-file-when-reading-pipe-t.patch b/net/xl2tpd/patches/200-xl2tpd-control-check-end-of-file-when-reading-pipe-t.patch similarity index 70% rename from net/xl2tpd/patches/201-xl2tpd-control-check-end-of-file-when-reading-pipe-t.patch rename to net/xl2tpd/patches/200-xl2tpd-control-check-end-of-file-when-reading-pipe-t.patch index 52f8332cd..811f9affe 100644 --- a/net/xl2tpd/patches/201-xl2tpd-control-check-end-of-file-when-reading-pipe-t.patch +++ b/net/xl2tpd/patches/200-xl2tpd-control-check-end-of-file-when-reading-pipe-t.patch @@ -1,16 +1,18 @@ -From 8c5853b8e22f34bc1c1acba278f7850ab7946894 Mon Sep 17 00:00:00 2001 +From 7973d45a0e1716ddc6bfb6caf600f826f59a7932 Mon Sep 17 00:00:00 2001 From: Yousong Zhou Date: Tue, 28 Apr 2015 21:26:15 +0800 -Subject: [PATCH 1/7] xl2tpd-control: check end-of-file when reading pipe to - avoid dead loop. +Subject: [PATCH 200/210] xl2tpd-control: check end-of-file when reading pipe + to avoid dead loop. --- - xl2tpd-control.c | 11 +++++++---- + xl2tpd-control.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) +diff --git a/xl2tpd-control.c b/xl2tpd-control.c +index feafe10..e5904d8 100644 --- a/xl2tpd-control.c +++ b/xl2tpd-control.c -@@ -306,17 +306,20 @@ int read_result(int result_fd, char* buf +@@ -306,17 +306,20 @@ int read_result(int result_fd, char* buf, ssize_t size) /*FIXME: there is a chance to hang up reading. Should I create watching thread with timeout? */ @@ -35,3 +37,6 @@ Subject: [PATCH 1/7] xl2tpd-control: check end-of-file when reading pipe to buf[readed] = '\0'; /* scan result code */ +-- +1.7.10.4 + diff --git a/net/xl2tpd/patches/202-xl2tpd-control-define-_GNU_SOURCE-to-use-fmemopen-an.patch b/net/xl2tpd/patches/201-xl2tpd-control-define-_GNU_SOURCE-to-use-fmemopen-an.patch similarity index 50% rename from net/xl2tpd/patches/202-xl2tpd-control-define-_GNU_SOURCE-to-use-fmemopen-an.patch rename to net/xl2tpd/patches/201-xl2tpd-control-define-_GNU_SOURCE-to-use-fmemopen-an.patch index d75010f9a..a4f704aa3 100644 --- a/net/xl2tpd/patches/202-xl2tpd-control-define-_GNU_SOURCE-to-use-fmemopen-an.patch +++ b/net/xl2tpd/patches/201-xl2tpd-control-define-_GNU_SOURCE-to-use-fmemopen-an.patch @@ -1,13 +1,15 @@ -From 76f444d284c0b0a351a488954e0d39b72a0ce211 Mon Sep 17 00:00:00 2001 +From efa0a18b5dfd827792b07acdcb35101229ccf612 Mon Sep 17 00:00:00 2001 From: Yousong Zhou Date: Wed, 29 Apr 2015 10:32:37 +0800 -Subject: [PATCH 2/7] xl2tpd-control: define _GNU_SOURCE to use fmemopen() and - friends. +Subject: [PATCH 201/210] xl2tpd-control: define _GNU_SOURCE to use fmemopen() + and friends. --- - xl2tpd-control.c | 2 ++ + xl2tpd-control.c | 2 ++ 1 file changed, 2 insertions(+) +diff --git a/xl2tpd-control.c b/xl2tpd-control.c +index e5904d8..9b6235d 100644 --- a/xl2tpd-control.c +++ b/xl2tpd-control.c @@ -10,6 +10,8 @@ @@ -19,3 +21,6 @@ Subject: [PATCH 2/7] xl2tpd-control: define _GNU_SOURCE to use fmemopen() and #include #include #include +-- +1.7.10.4 + diff --git a/net/xl2tpd/patches/203-xl2tpd-control-open-control-file-with-O_NONBLOCK.patch b/net/xl2tpd/patches/202-xl2tpd-control-open-control-file-with-O_NONBLOCK.patch similarity index 80% rename from net/xl2tpd/patches/203-xl2tpd-control-open-control-file-with-O_NONBLOCK.patch rename to net/xl2tpd/patches/202-xl2tpd-control-open-control-file-with-O_NONBLOCK.patch index aef1f7c15..17721f278 100644 --- a/net/xl2tpd/patches/203-xl2tpd-control-open-control-file-with-O_NONBLOCK.patch +++ b/net/xl2tpd/patches/202-xl2tpd-control-open-control-file-with-O_NONBLOCK.patch @@ -1,14 +1,16 @@ -From f7cfd36b8a93afd326c0d9378e99576c616bd3fc Mon Sep 17 00:00:00 2001 +From fedfd6685e5f81f0460beb4c448a30e7a6cfbd31 Mon Sep 17 00:00:00 2001 From: Yousong Zhou Date: Wed, 29 Apr 2015 14:21:12 +0800 -Subject: [PATCH 3/7] xl2tpd-control: open control file with O_NONBLOCK. +Subject: [PATCH 202/210] xl2tpd-control: open control file with O_NONBLOCK. Otherwise xl2tpd-control would block indefinitely in case xl2tpd is not running. --- - xl2tpd-control.c | 10 +++++++++- + xl2tpd-control.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) +diff --git a/xl2tpd-control.c b/xl2tpd-control.c +index 9b6235d..973ee87 100644 --- a/xl2tpd-control.c +++ b/xl2tpd-control.c @@ -246,7 +246,7 @@ int main (int argc, char *argv[]) @@ -35,3 +37,6 @@ not running. /* pass command to control pipe */ if (write (control_fd, buf, ftell (mesf)) < 0) +-- +1.7.10.4 + diff --git a/net/xl2tpd/patches/205-xl2tpd-control-cleaup-result-file-atexit.patch b/net/xl2tpd/patches/203-xl2tpd-control-cleaup-result-file-atexit.patch similarity index 66% rename from net/xl2tpd/patches/205-xl2tpd-control-cleaup-result-file-atexit.patch rename to net/xl2tpd/patches/203-xl2tpd-control-cleaup-result-file-atexit.patch index bfd01a2b6..66eee642f 100644 --- a/net/xl2tpd/patches/205-xl2tpd-control-cleaup-result-file-atexit.patch +++ b/net/xl2tpd/patches/203-xl2tpd-control-cleaup-result-file-atexit.patch @@ -1,15 +1,25 @@ -From d4a484db1684cce15966bb722644416f90253ea7 Mon Sep 17 00:00:00 2001 +From 07e522cd7e223517389582a8eb647a4a6a8a5cf8 Mon Sep 17 00:00:00 2001 From: Yousong Zhou Date: Thu, 30 Apr 2015 13:53:11 +0800 -Subject: [PATCH 5/7] xl2tpd-control: cleaup result file atexit(). +Subject: [PATCH 203/210] xl2tpd-control: cleaup result file atexit(). --- - xl2tpd-control.c | 20 +++++++++++++------- - 1 file changed, 13 insertions(+), 7 deletions(-) + xl2tpd-control.c | 21 ++++++++++++++------- + 1 file changed, 14 insertions(+), 7 deletions(-) +diff --git a/xl2tpd-control.c b/xl2tpd-control.c +index 973ee87..abc0324 100644 --- a/xl2tpd-control.c +++ b/xl2tpd-control.c -@@ -35,6 +35,9 @@ +@@ -12,6 +12,7 @@ + + #define _GNU_SOURCE + ++#include + #include + #include + #include +@@ -35,6 +36,9 @@ #define TUNNEL_REQUIRED 1 #define TUNNEL_NOT_REQUIRED 0 @@ -19,7 +29,7 @@ Subject: [PATCH 5/7] xl2tpd-control: cleaup result file atexit(). int log_level = ERROR_LEVEL; void print_error (int level, const char *fmt, ...); -@@ -117,6 +120,14 @@ void help() +@@ -117,6 +121,14 @@ void help() ); } @@ -34,7 +44,7 @@ Subject: [PATCH 5/7] xl2tpd-control: cleaup result file atexit(). int main (int argc, char *argv[]) { char* control_filename = NULL; -@@ -195,11 +206,11 @@ int main (int argc, char *argv[]) +@@ -195,11 +207,11 @@ int main (int argc, char *argv[]) FILE* mesf = fmemopen (buf, CONTROL_PIPE_MESSAGE_SIZE, "w"); /* create result pipe for reading */ @@ -48,7 +58,7 @@ Subject: [PATCH 5/7] xl2tpd-control: cleaup result file atexit(). if (result_fd < 0) { print_error (ERROR_LEVEL, -@@ -293,11 +304,6 @@ int main (int argc, char *argv[]) +@@ -293,11 +305,6 @@ int main (int argc, char *argv[]) ); printf ("%s", rbuf); @@ -60,3 +70,6 @@ Subject: [PATCH 5/7] xl2tpd-control: cleaup result file atexit(). return command_result_code; } +-- +1.7.10.4 + diff --git a/net/xl2tpd/patches/204-xl2tpd-control-enhance-output-of-print_error.patch b/net/xl2tpd/patches/204-xl2tpd-control-enhance-output-of-print_error.patch new file mode 100644 index 000000000..4e575078a --- /dev/null +++ b/net/xl2tpd/patches/204-xl2tpd-control-enhance-output-of-print_error.patch @@ -0,0 +1,58 @@ +From f6eaaabb0b2fab12cf597b8c1d12d470a13e581f Mon Sep 17 00:00:00 2001 +From: Yousong Zhou +Date: Thu, 14 May 2015 14:58:10 +0800 +Subject: [PATCH 204/210] xl2tpd-control: enhance output of print_error(). + + - Add prefix "xl2tpd-control: " to print_error() output. + - Output response from xl2tpd only when -d is enabled as result of + control command can be retrieved from exit code. + - Remove some redundant and not that useful verbose output. +--- + xl2tpd-control.c | 10 ++++------ + 1 file changed, 4 insertions(+), 6 deletions(-) + +diff --git a/xl2tpd-control.c b/xl2tpd-control.c +index abc0324..6b08850 100644 +--- a/xl2tpd-control.c ++++ b/xl2tpd-control.c +@@ -164,7 +164,6 @@ int main (int argc, char *argv[]) + { + control_filename = strdup (CONTROL_PIPE); + } +- print_error (DEBUG_LEVEL, "set control filename to %s\n", control_filename); + + /* parse command name */ + for (command = commands; command->name; command++) +@@ -176,10 +175,7 @@ int main (int argc, char *argv[]) + } + } + +- if (command->name) +- { +- print_error (DEBUG_LEVEL, "get command %s\n", command->name); +- } else { ++ if (!command->name) { + print_error (ERROR_LEVEL, "error: no such command %s\n", argv[i]); + return -1; + } +@@ -303,7 +299,8 @@ int main (int argc, char *argv[]) + int command_result_code = read_result ( + result_fd, rbuf, CONTROL_PIPE_MESSAGE_SIZE + ); +- printf ("%s", rbuf); ++ /* rbuf contains a newline, make it double to form a boundary. */ ++ print_error (DEBUG_LEVEL, "command response: \n%s\n", rbuf); + + return command_result_code; + } +@@ -313,6 +310,7 @@ void print_error (int level, const char *fmt, ...) + if (level > log_level) return; + va_list args; + va_start (args, fmt); ++ fprintf (stderr, "xl2tpd-control: "); + vfprintf (stderr, fmt, args); + va_end (args); + } +-- +1.7.10.4 + diff --git a/net/xl2tpd/patches/205-xl2tpd-fix-typo-in-reporting-available-lns-count.patch b/net/xl2tpd/patches/205-xl2tpd-fix-typo-in-reporting-available-lns-count.patch new file mode 100644 index 000000000..b25e82be4 --- /dev/null +++ b/net/xl2tpd/patches/205-xl2tpd-fix-typo-in-reporting-available-lns-count.patch @@ -0,0 +1,34 @@ +From 1c148f6645f43bf5abd8a9b8f0708a598b357d97 Mon Sep 17 00:00:00 2001 +From: Yousong Zhou +Date: Thu, 14 May 2015 19:56:39 +0800 +Subject: [PATCH 205/210] xl2tpd: fix typo in reporting available lns count. + +--- + xl2tpd.c | 4 ++-- + 1 file changed, 2 insertions(+), 2 deletions(-) + +diff --git a/xl2tpd.c b/xl2tpd.c +index c9b7579..6c945fc 100644 +--- a/xl2tpd.c ++++ b/xl2tpd.c +@@ -1039,7 +1039,7 @@ int control_handle_available(FILE* resf, char* bufp){ + lns_count++; + } + +- write_res (resf, "%02i AVAILABLE lns.cout=%d\n", 0, lns_count); ++ write_res (resf, "%02i AVAILABLE lns.count=%d\n", 0, lns_count); + + lac = laclist; + int lac_count = 0; +@@ -1053,7 +1053,7 @@ int control_handle_available(FILE* resf, char* bufp){ + if(deflac){ + write_res (resf, "%02i AVAILABLE lac.%d.name=%s\n", 0, lac_count, deflac->entname); + lac_count++; +- } ++ } + + write_res (resf, "%02i AVAILABLE lac.count=%d\n", 0, lac_count); + return 1; +-- +1.7.10.4 + diff --git a/net/xl2tpd/patches/206-xl2tpd-fix-possible-buffer-overflow-when-filling-str.patch b/net/xl2tpd/patches/206-xl2tpd-fix-possible-buffer-overflow-when-filling-str.patch deleted file mode 100644 index 6110b0c5b..000000000 --- a/net/xl2tpd/patches/206-xl2tpd-fix-possible-buffer-overflow-when-filling-str.patch +++ /dev/null @@ -1,22 +0,0 @@ -From 1e8b82388578a622c5caf8fa04c238fdd7808ecc Mon Sep 17 00:00:00 2001 -From: Yousong Zhou -Date: Thu, 30 Apr 2015 13:53:40 +0800 -Subject: [PATCH 6/7] xl2tpd: fix possible buffer overflow when filling - stropt[]. - ---- - xl2tpd.c | 3 ++- - 1 file changed, 2 insertions(+), 1 deletion(-) - ---- a/xl2tpd.c -+++ b/xl2tpd.c -@@ -490,7 +490,8 @@ int start_pppd (struct call *c, struct p - - { - struct ppp_opts *p = opts; -- while (p) -+ int maxn_opts = sizeof(stropt) / sizeof(stropt[0]) - 1; -+ while (p && pos < maxn_opts) - { - stropt[pos] = strdup (p->option); - pos++; diff --git a/net/xl2tpd/patches/204-start_pppd-place-opts-after-plugin-pppol2tp.so.patch b/net/xl2tpd/patches/206-xl2tpd-start_pppd-place-opts-after-plugin-pppol2tp.s.patch similarity index 59% rename from net/xl2tpd/patches/204-start_pppd-place-opts-after-plugin-pppol2tp.so.patch rename to net/xl2tpd/patches/206-xl2tpd-start_pppd-place-opts-after-plugin-pppol2tp.s.patch index 1d50eaa25..60d8b84db 100644 --- a/net/xl2tpd/patches/204-start_pppd-place-opts-after-plugin-pppol2tp.so.patch +++ b/net/xl2tpd/patches/206-xl2tpd-start_pppd-place-opts-after-plugin-pppol2tp.s.patch @@ -1,16 +1,21 @@ -From 7a343f7b79b70a8e7e04b2bd465d344ad0ef4c49 Mon Sep 17 00:00:00 2001 +From 18fdf802d31354c62a27cc5a63b196780a0d486e Mon Sep 17 00:00:00 2001 From: Yousong Zhou Date: Wed, 29 Apr 2015 16:30:17 +0800 -Subject: [PATCH 4/7] start_pppd: place opts after "plugin pppol2tp.so". +Subject: [PATCH 206/210] xl2tpd: start_pppd: place opts after "plugin + pppol2tp.so". -so that plugin options like pppol2tp_debug_mark can be recognized by pppd. +so that plugin options like pppol2tp_debug_mark can be recognized by +pppd. While doing this also add bound check to prevent potential buffer +overflow problem. --- - xl2tpd.c | 21 ++++++++++----------- - 1 file changed, 10 insertions(+), 11 deletions(-) + xl2tpd.c | 22 +++++++++++----------- + 1 file changed, 11 insertions(+), 11 deletions(-) +diff --git a/xl2tpd.c b/xl2tpd.c +index 6c945fc..017adfd 100644 --- a/xl2tpd.c +++ b/xl2tpd.c -@@ -382,7 +382,6 @@ int start_pppd (struct call *c, struct p +@@ -382,7 +382,6 @@ int start_pppd (struct call *c, struct ppp_opts *opts) /* char a, b; */ char tty[512]; char *stropt[80]; @@ -18,7 +23,7 @@ so that plugin options like pppol2tp_debug_mark can be recognized by pppd. #ifdef USE_KERNEL struct sockaddr_pppol2tp sax; int flags; -@@ -396,16 +395,7 @@ int start_pppd (struct call *c, struct p +@@ -396,16 +395,7 @@ int start_pppd (struct call *c, struct ppp_opts *opts) struct call *sc; struct tunnel *st; @@ -35,7 +40,7 @@ so that plugin options like pppol2tp_debug_mark can be recognized by pppd. if (c->pppd > 0) { l2tp_log(LOG_WARNING, "%s: PPP already started on call!\n", __FUNCTION__); -@@ -467,7 +457,6 @@ int start_pppd (struct call *c, struct p +@@ -467,7 +457,6 @@ int start_pppd (struct call *c, struct ppp_opts *opts) snprintf (stropt[pos], 10, "%d", c->ourcid); pos++; } @@ -43,7 +48,7 @@ so that plugin options like pppol2tp_debug_mark can be recognized by pppd. } else #endif -@@ -497,6 +486,16 @@ int start_pppd (struct call *c, struct p +@@ -497,6 +486,17 @@ int start_pppd (struct call *c, struct ppp_opts *opts) return -EINVAL; } stropt[pos++] = strdup(tty); @@ -51,7 +56,8 @@ so that plugin options like pppol2tp_debug_mark can be recognized by pppd. + + { + struct ppp_opts *p = opts; -+ while (p) ++ int maxn_opts = sizeof(stropt) / sizeof(stropt[0]) - 1; ++ while (p && pos < maxn_opts) + { + stropt[pos] = strdup (p->option); + pos++; @@ -60,3 +66,6 @@ so that plugin options like pppol2tp_debug_mark can be recognized by pppd. stropt[pos] = NULL; } +-- +1.7.10.4 + diff --git a/net/xl2tpd/patches/207-l2tp_log-remove-log-prefix-that-will-duplicate-with-.patch b/net/xl2tpd/patches/207-l2tp_log-remove-log-prefix-that-will-duplicate-with-.patch deleted file mode 100644 index d513a5820..000000000 --- a/net/xl2tpd/patches/207-l2tp_log-remove-log-prefix-that-will-duplicate-with-.patch +++ /dev/null @@ -1,21 +0,0 @@ -From 44ced2bbf1d6b39bb36c3cb8be6e40c8764e2e8a Mon Sep 17 00:00:00 2001 -From: Yousong Zhou -Date: Thu, 30 Apr 2015 13:57:36 +0800 -Subject: [PATCH 7/7] l2tp_log: remove log prefix that will duplicate with - procd. - ---- - misc.c | 2 +- - 1 file changed, 1 insertion(+), 1 deletion(-) - ---- a/misc.c -+++ b/misc.c -@@ -61,7 +61,7 @@ void l2tp_log (int level, const char *fm - init_log(); - SYSLOG_CALL( syslog (level, "%s", buf) ); - } else { -- fprintf(stderr, "xl2tpd[%d]: %s", getpid(), buf); -+ fprintf(stderr, "%s", buf); - } - } - diff --git a/net/xl2tpd/patches/207-xl2tpd-introduce-new-option-l-for-using-syslog-as-th.patch b/net/xl2tpd/patches/207-xl2tpd-introduce-new-option-l-for-using-syslog-as-th.patch new file mode 100644 index 000000000..5ab94cb05 --- /dev/null +++ b/net/xl2tpd/patches/207-xl2tpd-introduce-new-option-l-for-using-syslog-as-th.patch @@ -0,0 +1,104 @@ +From b3402a68a4d29e9b1ae4e012e39a7bcb14fea3cf Mon Sep 17 00:00:00 2001 +From: Yousong Zhou +Date: Thu, 30 Apr 2015 13:57:36 +0800 +Subject: [PATCH 207/210] xl2tpd: introduce new option -l for using syslog as + the logging facility. + +Defaults to old behaviour if no -l option was specified. Also update +manual doc to reflect this change. +--- + doc/xl2tpd.8 | 5 +++++ + file.h | 1 + + misc.c | 2 +- + xl2tpd.c | 13 ++++++++++++- + 4 files changed, 19 insertions(+), 2 deletions(-) + +diff --git a/doc/xl2tpd.8 b/doc/xl2tpd.8 +index 915b247..7afccac 100644 +--- a/doc/xl2tpd.8 ++++ b/doc/xl2tpd.8 +@@ -20,6 +20,11 @@ This option prevents xl2tpd from detaching from the terminal and + daemonizing. + + .TP ++.B -l ++This option tells xl2tpd to use syslog for logging even when \fB\-D\fR ++was specified. ++ ++.TP + .B -c + Tells xl2tpd to use an alternate config file. Default is + /etc/xl2tpd/xl2tpd.conf. Fallback configuration file is +diff --git a/file.h b/file.h +index 89987ae..92df046 100644 +--- a/file.h ++++ b/file.h +@@ -151,6 +151,7 @@ struct global + char pidfile[STRLEN]; /* File containing the pid number*/ + char controlfile[STRLEN]; /* Control file name (named pipe) */ + int daemon; /* Use daemon mode? */ ++ int syslog; /* Use syslog for logging? */ + int accesscontrol; /* Use access control? */ + int forceuserspace; /* Force userspace? */ + int packet_dump; /* Dump (print) all packets? */ +diff --git a/misc.c b/misc.c +index 3092401..cccf4ca 100644 +--- a/misc.c ++++ b/misc.c +@@ -57,7 +57,7 @@ void l2tp_log (int level, const char *fmt, ...) + vsnprintf (buf, sizeof (buf), fmt, args); + va_end (args); + +- if(gconfig.daemon) { ++ if(gconfig.syslog) { + init_log(); + SYSLOG_CALL( syslog (level, "%s", buf) ); + } else { +diff --git a/xl2tpd.c b/xl2tpd.c +index 017adfd..1937690 100644 +--- a/xl2tpd.c ++++ b/xl2tpd.c +@@ -1594,7 +1594,7 @@ void do_control () + void usage(void) { + printf("\nxl2tpd version: %s\n", SERVER_VERSION); + printf("Usage: xl2tpd [-c ] [-s ] [-p ]\n" +- " [-C ] [-D]\n" ++ " [-C ] [-D] [-l]\n" + " [-v, --version]\n"); + printf("\n"); + exit(1); +@@ -1605,6 +1605,7 @@ void init_args(int argc, char *argv[]) + int i=0; + + gconfig.daemon=1; ++ gconfig.syslog=-1; + memset(gconfig.altauthfile,0,STRLEN); + memset(gconfig.altconfigfile,0,STRLEN); + memset(gconfig.authfile,0,STRLEN); +@@ -1642,6 +1643,9 @@ void init_args(int argc, char *argv[]) + else if (! strncmp(argv[i],"-D",2)) { + gconfig.daemon=0; + } ++ else if (! strncmp(argv[i],"-l",2)) { ++ gconfig.syslog=1; ++ } + else if (! strncmp(argv[i],"-s",2)) { + if(++i == argc) + usage(); +@@ -1667,6 +1671,13 @@ void init_args(int argc, char *argv[]) + usage(); + } + } ++ ++ /* ++ * defaults to syslog if no log facility was explicitly ++ * specified and we are about to daemonize ++ */ ++ if (gconfig.syslog < 0) ++ gconfig.syslog = gconfig.daemon; + } + + +-- +1.7.10.4 + diff --git a/net/xl2tpd/patches/208-xl2tpd-unlink-result-file-to-prevent-leftover-a-regu.patch b/net/xl2tpd/patches/208-xl2tpd-unlink-result-file-to-prevent-leftover-a-regu.patch new file mode 100644 index 000000000..90694f228 --- /dev/null +++ b/net/xl2tpd/patches/208-xl2tpd-unlink-result-file-to-prevent-leftover-a-regu.patch @@ -0,0 +1,26 @@ +From a2b163a65a2d4fbca57c3aa82b526cf8fbc8e449 Mon Sep 17 00:00:00 2001 +From: Yousong Zhou +Date: Fri, 15 May 2015 10:56:23 +0800 +Subject: [PATCH 208/210] xl2tpd: unlink result file to prevent leftover a + regular file. + +--- + xl2tpd.c | 2 ++ + 1 file changed, 2 insertions(+) + +diff --git a/xl2tpd.c b/xl2tpd.c +index 1937690..c11fe66 100644 +--- a/xl2tpd.c ++++ b/xl2tpd.c +@@ -1582,6 +1582,8 @@ void do_control () + if (resf) + { + fclose (resf); ++ /* unlink it anyway to prevent leftover a regular file. */ ++ unlink(res_filename); + } + } + +-- +1.7.10.4 + diff --git a/net/xl2tpd/patches/209-xl2tpd-ignore-SIGPIPE-signal.patch b/net/xl2tpd/patches/209-xl2tpd-ignore-SIGPIPE-signal.patch new file mode 100644 index 000000000..a0d88bd34 --- /dev/null +++ b/net/xl2tpd/patches/209-xl2tpd-ignore-SIGPIPE-signal.patch @@ -0,0 +1,32 @@ +From 2d0eff7f56936823d784425d2171be295ba11027 Mon Sep 17 00:00:00 2001 +From: Yousong Zhou +Date: Fri, 15 May 2015 15:55:10 +0800 +Subject: [PATCH 209/210] xl2tpd: ignore SIGPIPE signal. + +--- + xl2tpd.c | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/xl2tpd.c b/xl2tpd.c +index c11fe66..58ed868 100644 +--- a/xl2tpd.c ++++ b/xl2tpd.c +@@ -1551,7 +1551,6 @@ void do_control () + /*FIXME: check quotes to allow filenames with spaces? + (do not forget quotes escaping to allow filenames with quotes)*/ + +- /*FIXME: write to res_filename may cause SIGPIPE, need to catch it*/ + resf = fopen (res_filename, "w"); + if (!resf) { + l2tp_log (LOG_DEBUG, "%s: Can't open result file %s\n", +@@ -1811,6 +1810,7 @@ void init (int argc,char *argv[]) + signal (SIGCHLD, &sigchld_handler); + signal (SIGUSR1, &sigusr1_handler); + signal (SIGHUP, &sighup_handler); ++ signal (SIGPIPE, SIG_IGN); + init_scheduler (); + + unlink(gconfig.controlfile); +-- +1.7.10.4 + diff --git a/net/xl2tpd/patches/210-xl2tpd-control-show-all-available-commands-in-help.patch b/net/xl2tpd/patches/210-xl2tpd-control-show-all-available-commands-in-help.patch new file mode 100644 index 000000000..8eccffa58 --- /dev/null +++ b/net/xl2tpd/patches/210-xl2tpd-control-show-all-available-commands-in-help.patch @@ -0,0 +1,119 @@ +From 26b77b7cdc70beddc68507f74372a4e2815720f0 Mon Sep 17 00:00:00 2001 +From: Yousong Zhou +Date: Sun, 17 May 2015 10:53:44 +0800 +Subject: [PATCH 210/210] xl2tpd-control: show all available commands in + --help. + +--- + xl2tpd-control.c | 63 ++++++++++++++++++++++++++++++++++++++---------------- + 1 file changed, 44 insertions(+), 19 deletions(-) + +diff --git a/xl2tpd-control.c b/xl2tpd-control.c +index 6b08850..b98ff24 100644 +--- a/xl2tpd-control.c ++++ b/xl2tpd-control.c +@@ -51,6 +51,7 @@ struct command_t + char *name; + int (*handler) (FILE*, char* tunnel, int optc, char *optv[]); + int requires_tunnel; ++ char *help; + }; + + int command_add_lac (FILE*, char* tunnel, int optc, char *optv[]); +@@ -65,13 +66,29 @@ int command_available (FILE*, char* tunnel, int optc, char *optv[]); + + struct command_t commands[] = { + /* Keep this command mapping for backwards compat */ +- {"add", &command_add_lac, TUNNEL_REQUIRED}, +- {"connect", &command_connect_lac, TUNNEL_REQUIRED}, +- {"disconnect", &command_disconnect_lac, TUNNEL_REQUIRED}, +- {"remove", &command_remove_lac, TUNNEL_REQUIRED}, ++ {"add", &command_add_lac, TUNNEL_REQUIRED, ++ "\tadd\tadds new or modify existing lac configuration.\n" ++ "\t\tConfiguration must be specified as command options in\n" ++ "\t\t= pairs format.\n" ++ "\t\tSee available options in xl2tpd.conf(5)\n" ++ }, ++ {"connect", &command_connect_lac, TUNNEL_REQUIRED, ++ "\tconnect\ttries to activate the tunnel.\n" ++ "\t\tUsername and secret for the tunnel can be passed as\n" ++ "\t\tcommand options.\n" ++ }, ++ {"disconnect", &command_disconnect_lac, TUNNEL_REQUIRED, ++ "\tdisconnect\tdisconnects the tunnel.\n" ++ }, ++ {"remove", &command_remove_lac, TUNNEL_REQUIRED, ++ "\tremove\tremoves lac configuration from xl2tpd.\n" ++ "\t\txl2tpd disconnects the tunnel before removing.\n" ++ }, + + /* LAC commands */ +- {"add-lac", &command_add_lac, TUNNEL_REQUIRED}, ++ {"add-lac", &command_add_lac, TUNNEL_REQUIRED, ++ "\tadd-lns\tadds new or modify existing lns configuration.\n" ++ }, + {"connect-lac", &command_connect_lac, TUNNEL_REQUIRED}, + {"disconnect-lac", &command_disconnect_lac, TUNNEL_REQUIRED}, + {"remove-lac", &command_remove_lac, TUNNEL_REQUIRED}, +@@ -89,36 +106,44 @@ struct command_t commands[] = { + + void usage() + { ++ int i; ++ + printf ("\nxl2tpd server version %s\n", SERVER_VERSION); + printf ("Usage: xl2tpd-control [-c ] []\n" + "\n" + " -c\tspecifies xl2tpd control file\n" + " -d\tspecify xl2tpd-control to run in debug mode\n" + "--help\tshows extended help\n" +- "Available commands: add, connect, disconnect, remove, add-lns\n" + ); ++ ++ printf ("Available commands: "); ++ for (i = 0; commands[i].name; i++) { ++ struct command_t *command = &commands[i]; ++ int last = command[1].name == NULL; ++ ++ printf ("%s%s", command->name, !last ? ", " : "\n"); ++ } + } + + void help() + { ++ int i; ++ + usage(); + printf ( + "\n" + "Commands help:\n" +- "\tadd\tadds new or modify existing lac configuration.\n" +- "\t\tConfiguration must be specified as command options in\n" +- "\t\t= pairs format.\n" +- "\t\tSee available options in xl2tpd.conf(5)\n" +- "\tconnect\ttries to activate the tunnel.\n" +- "\t\tUsername and secret for the tunnel can be passed as\n" +- "\t\tcommand options.\n" +- "\tdisconnect\tdisconnects the tunnel.\n" +- "\tremove\tremoves lac configuration from xl2tpd.\n" +- "\t\txl2tpd disconnects the tunnel before removing.\n" +- "\n" +- "\tadd-lns\tadds new or modify existing lns configuration.\n" +- "See xl2tpd-control man page for more help\n" + ); ++ ++ for (i = 0; commands[i].name; i++) { ++ struct command_t *command = &commands[i]; ++ ++ if (!command->help) ++ continue; ++ printf ("%s", command->help); ++ } ++ /*FIXME Ha! there is currently no manpage for xl2tpd-control */ ++ printf ("See xl2tpd-control man page for more help\n"); + } + + void cleanup(void) +-- +1.7.10.4 + diff --git a/net/xl2tpd/patches/250-xl2tpd-control-atexit-needs-stdlib.patch b/net/xl2tpd/patches/250-xl2tpd-control-atexit-needs-stdlib.patch deleted file mode 100644 index e4dad8e8d..000000000 --- a/net/xl2tpd/patches/250-xl2tpd-control-atexit-needs-stdlib.patch +++ /dev/null @@ -1,12 +0,0 @@ -Index: xl2tpd-1.3.7pre20141126/xl2tpd-control.c -=================================================================== ---- xl2tpd-1.3.7pre20141126.orig/xl2tpd-control.c -+++ xl2tpd-1.3.7pre20141126/xl2tpd-control.c -@@ -12,6 +12,7 @@ - - #define _GNU_SOURCE - -+#include - #include - #include - #include