From 964edd830b12884df476f9abb001478754506660 Mon Sep 17 00:00:00 2001 From: Daniel Golle Date: Wed, 13 May 2015 13:20:06 +0200 Subject: [PATCH] xl2tpd: update source, import some useful patches Yousong Zhou made a couple of useful fixes mostly for the xl2tpd-control tool which was broken. imported them (patches/2*) here. Signed-off-by: Daniel Golle --- net/xl2tpd/Makefile | 4 +- .../patches/100-makefile_opt_flags.patch | 2 +- .../patches/110-makefile_dont_build_pfc.patch | 6 +- .../patches/120-no-bsd-signal-in-musl.patch | 6 +- ...heck-end-of-file-when-reading-pipe-t.patch | 37 +++++++++++ ...efine-_GNU_SOURCE-to-use-fmemopen-an.patch | 21 +++++++ ...ol-open-control-file-with-O_NONBLOCK.patch | 37 +++++++++++ ...-place-opts-after-plugin-pppol2tp.so.patch | 62 +++++++++++++++++++ ...pd-control-cleaup-result-file-atexit.patch | 62 +++++++++++++++++++ ...ble-buffer-overflow-when-filling-str.patch | 22 +++++++ ...log-prefix-that-will-duplicate-with-.patch | 21 +++++++ 11 files changed, 270 insertions(+), 10 deletions(-) create mode 100644 net/xl2tpd/patches/201-xl2tpd-control-check-end-of-file-when-reading-pipe-t.patch create mode 100644 net/xl2tpd/patches/202-xl2tpd-control-define-_GNU_SOURCE-to-use-fmemopen-an.patch create mode 100644 net/xl2tpd/patches/203-xl2tpd-control-open-control-file-with-O_NONBLOCK.patch create mode 100644 net/xl2tpd/patches/204-start_pppd-place-opts-after-plugin-pppol2tp.so.patch create mode 100644 net/xl2tpd/patches/205-xl2tpd-control-cleaup-result-file-atexit.patch create mode 100644 net/xl2tpd/patches/206-xl2tpd-fix-possible-buffer-overflow-when-filling-str.patch create mode 100644 net/xl2tpd/patches/207-l2tp_log-remove-log-prefix-that-will-duplicate-with-.patch diff --git a/net/xl2tpd/Makefile b/net/xl2tpd/Makefile index 2a1c4a5df..29107f085 100644 --- a/net/xl2tpd/Makefile +++ b/net/xl2tpd/Makefile @@ -8,7 +8,7 @@ include $(TOPDIR)/rules.mk PKG_NAME:=xl2tpd -PKG_VERSION:=1.3.6 +PKG_VERSION:=1.3.7pre20141126 PKG_RELEASE:=1 PKG_MAINTAINER:=Daniel Golle PKG_LICENSE:=GPL-2.0 @@ -19,7 +19,7 @@ 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) -PKG_SOURCE_VERSION:=5619e1771048e74b729804e8602f409af0f3faea +PKG_SOURCE_VERSION:=1cda2a266e2e957b81019d63a8902b28304a0ac4 PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz PKG_INSTALL:=1 diff --git a/net/xl2tpd/patches/100-makefile_opt_flags.patch b/net/xl2tpd/patches/100-makefile_opt_flags.patch index 82e875d70..1af416f96 100644 --- a/net/xl2tpd/patches/100-makefile_opt_flags.patch +++ b/net/xl2tpd/patches/100-makefile_opt_flags.patch @@ -1,6 +1,6 @@ --- a/Makefile +++ b/Makefile -@@ -91,7 +91,8 @@ OSFLAGS+= -DUSE_KERNEL +@@ -97,7 +97,8 @@ OSFLAGS+= -DUSE_KERNEL IPFLAGS?= -DIP_ALLOCATION diff --git a/net/xl2tpd/patches/110-makefile_dont_build_pfc.patch b/net/xl2tpd/patches/110-makefile_dont_build_pfc.patch index 460a0f15d..f76364fa8 100644 --- a/net/xl2tpd/patches/110-makefile_dont_build_pfc.patch +++ b/net/xl2tpd/patches/110-makefile_dont_build_pfc.patch @@ -1,6 +1,6 @@ --- a/Makefile +++ b/Makefile -@@ -107,10 +107,10 @@ BINDIR?=$(DESTDIR)${PREFIX}/bin +@@ -113,10 +113,10 @@ BINDIR?=$(DESTDIR)${PREFIX}/bin MANDIR?=$(DESTDIR)${PREFIX}/share/man @@ -13,7 +13,7 @@ $(EXEC): $(OBJS) $(HDRS) $(CC) $(LDFLAGS) -o $@ $(OBJS) $(LDLIBS) -@@ -118,14 +118,10 @@ $(EXEC): $(OBJS) $(HDRS) +@@ -124,14 +124,10 @@ $(EXEC): $(OBJS) $(HDRS) $(CONTROL_EXEC): $(CONTROL_SRCS) $(CC) $(CFLAGS) $(LDFLAGS) $(CONTROL_SRCS) -o $@ @@ -29,7 +29,7 @@ install -d -m 0755 ${SBINDIR} install -m 0755 $(EXEC) ${SBINDIR}/$(EXEC) install -d -m 0755 ${MANDIR}/man5 -@@ -133,11 +129,6 @@ install: ${EXEC} pfc ${CONTROL_EXEC} +@@ -139,11 +135,6 @@ install: ${EXEC} pfc ${CONTROL_EXEC} install -m 0644 doc/xl2tpd.8 ${MANDIR}/man8/ install -m 0644 doc/xl2tpd.conf.5 doc/l2tp-secrets.5 \ ${MANDIR}/man5/ diff --git a/net/xl2tpd/patches/120-no-bsd-signal-in-musl.patch b/net/xl2tpd/patches/120-no-bsd-signal-in-musl.patch index dba544c0e..c8c4a7dd6 100644 --- a/net/xl2tpd/patches/120-no-bsd-signal-in-musl.patch +++ b/net/xl2tpd/patches/120-no-bsd-signal-in-musl.patch @@ -1,7 +1,5 @@ -Index: xl2tpd-1.3.6/xl2tpd.c -=================================================================== ---- xl2tpd-1.3.6.orig/xl2tpd.c -+++ xl2tpd-1.3.6/xl2tpd.c +--- a/xl2tpd.c ++++ b/xl2tpd.c @@ -30,7 +30,7 @@ #include #include diff --git a/net/xl2tpd/patches/201-xl2tpd-control-check-end-of-file-when-reading-pipe-t.patch b/net/xl2tpd/patches/201-xl2tpd-control-check-end-of-file-when-reading-pipe-t.patch new file mode 100644 index 000000000..52f8332cd --- /dev/null +++ b/net/xl2tpd/patches/201-xl2tpd-control-check-end-of-file-when-reading-pipe-t.patch @@ -0,0 +1,37 @@ +From 8c5853b8e22f34bc1c1acba278f7850ab7946894 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. + +--- + xl2tpd-control.c | 11 +++++++---- + 1 file changed, 7 insertions(+), 4 deletions(-) + +--- a/xl2tpd-control.c ++++ b/xl2tpd-control.c +@@ -306,17 +306,20 @@ int read_result(int result_fd, char* buf + /*FIXME: there is a chance to hang up reading. + Should I create watching thread with timeout? + */ +- ssize_t readed; ++ ssize_t readed = 0; ++ ssize_t len; ++ + do + { +- readed = read (result_fd, buf, size); +- if (readed < 0) ++ len = read (result_fd, buf + readed, size - readed); ++ if (len < 0) + { + print_error (ERROR_LEVEL, + "error: can't read command result: %s\n", strerror (errno)); + break; + } +- } while (readed == 0); ++ readed += len; ++ } while (len > 0 && (size - readed) > 0); + buf[readed] = '\0'; + + /* scan result code */ diff --git a/net/xl2tpd/patches/202-xl2tpd-control-define-_GNU_SOURCE-to-use-fmemopen-an.patch b/net/xl2tpd/patches/202-xl2tpd-control-define-_GNU_SOURCE-to-use-fmemopen-an.patch new file mode 100644 index 000000000..d75010f9a --- /dev/null +++ b/net/xl2tpd/patches/202-xl2tpd-control-define-_GNU_SOURCE-to-use-fmemopen-an.patch @@ -0,0 +1,21 @@ +From 76f444d284c0b0a351a488954e0d39b72a0ce211 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. + +--- + xl2tpd-control.c | 2 ++ + 1 file changed, 2 insertions(+) + +--- a/xl2tpd-control.c ++++ b/xl2tpd-control.c +@@ -10,6 +10,8 @@ + * + */ + ++#define _GNU_SOURCE ++ + #include + #include + #include diff --git a/net/xl2tpd/patches/203-xl2tpd-control-open-control-file-with-O_NONBLOCK.patch b/net/xl2tpd/patches/203-xl2tpd-control-open-control-file-with-O_NONBLOCK.patch new file mode 100644 index 000000000..aef1f7c15 --- /dev/null +++ b/net/xl2tpd/patches/203-xl2tpd-control-open-control-file-with-O_NONBLOCK.patch @@ -0,0 +1,37 @@ +From f7cfd36b8a93afd326c0d9378e99576c616bd3fc 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. + +Otherwise xl2tpd-control would block indefinitely in case xl2tpd is +not running. +--- + xl2tpd-control.c | 10 +++++++++- + 1 file changed, 9 insertions(+), 1 deletion(-) + +--- a/xl2tpd-control.c ++++ b/xl2tpd-control.c +@@ -246,7 +246,7 @@ int main (int argc, char *argv[]) + print_error (DEBUG_LEVEL, "command to be passed:\n%s\n", buf); + + /* try to open control file for writing */ +- int control_fd = open (control_filename, O_WRONLY, 0600); ++ int control_fd = open (control_filename, O_WRONLY | O_NONBLOCK, 0600); + if (control_fd < 0) + { + int errorno = errno; +@@ -265,6 +265,14 @@ int main (int argc, char *argv[]) + } + return -1; + } ++ ++ /* turn off O_NONBLOCK */ ++ if (fcntl (control_fd, F_SETFL, O_WRONLY) == -1) { ++ print_error (ERROR_LEVEL, ++ "Can not turn off nonblocking mode for control_fd: %s\n", ++ strerror(errno)); ++ return -2; ++ } + + /* pass command to control pipe */ + if (write (control_fd, buf, ftell (mesf)) < 0) diff --git a/net/xl2tpd/patches/204-start_pppd-place-opts-after-plugin-pppol2tp.so.patch b/net/xl2tpd/patches/204-start_pppd-place-opts-after-plugin-pppol2tp.so.patch new file mode 100644 index 000000000..1d50eaa25 --- /dev/null +++ b/net/xl2tpd/patches/204-start_pppd-place-opts-after-plugin-pppol2tp.so.patch @@ -0,0 +1,62 @@ +From 7a343f7b79b70a8e7e04b2bd465d344ad0ef4c49 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". + +so that plugin options like pppol2tp_debug_mark can be recognized by pppd. +--- + xl2tpd.c | 21 ++++++++++----------- + 1 file changed, 10 insertions(+), 11 deletions(-) + +--- a/xl2tpd.c ++++ b/xl2tpd.c +@@ -382,7 +382,6 @@ int start_pppd (struct call *c, struct p + /* char a, b; */ + char tty[512]; + char *stropt[80]; +- struct ppp_opts *p; + #ifdef USE_KERNEL + struct sockaddr_pppol2tp sax; + int flags; +@@ -396,16 +395,7 @@ int start_pppd (struct call *c, struct p + struct call *sc; + struct tunnel *st; + +- p = opts; + stropt[0] = strdup (PPPD); +- while (p) +- { +- stropt[pos] = (char *) malloc (strlen (p->option) + 1); +- strncpy (stropt[pos], p->option, strlen (p->option) + 1); +- pos++; +- p = p->next; +- } +- stropt[pos] = NULL; + 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 + snprintf (stropt[pos], 10, "%d", c->ourcid); + pos++; + } +- stropt[pos] = NULL; + } + else + #endif +@@ -497,6 +486,16 @@ int start_pppd (struct call *c, struct p + return -EINVAL; + } + stropt[pos++] = strdup(tty); ++ } ++ ++ { ++ struct ppp_opts *p = opts; ++ while (p) ++ { ++ stropt[pos] = strdup (p->option); ++ pos++; ++ p = p->next; ++ } + stropt[pos] = NULL; + } + diff --git a/net/xl2tpd/patches/205-xl2tpd-control-cleaup-result-file-atexit.patch b/net/xl2tpd/patches/205-xl2tpd-control-cleaup-result-file-atexit.patch new file mode 100644 index 000000000..bfd01a2b6 --- /dev/null +++ b/net/xl2tpd/patches/205-xl2tpd-control-cleaup-result-file-atexit.patch @@ -0,0 +1,62 @@ +From d4a484db1684cce15966bb722644416f90253ea7 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(). + +--- + xl2tpd-control.c | 20 +++++++++++++------- + 1 file changed, 13 insertions(+), 7 deletions(-) + +--- a/xl2tpd-control.c ++++ b/xl2tpd-control.c +@@ -35,6 +35,9 @@ + #define TUNNEL_REQUIRED 1 + #define TUNNEL_NOT_REQUIRED 0 + ++char result_filename[128]; ++int result_fd = -1; ++ + int log_level = ERROR_LEVEL; + + void print_error (int level, const char *fmt, ...); +@@ -117,6 +120,14 @@ void help() + ); + } + ++void cleanup(void) ++{ ++ /* cleaning up */ ++ if (result_fd >= 0) ++ close (result_fd); ++ unlink (result_filename); ++} ++ + int main (int argc, char *argv[]) + { + char* control_filename = NULL; +@@ -195,11 +206,11 @@ int main (int argc, char *argv[]) + FILE* mesf = fmemopen (buf, CONTROL_PIPE_MESSAGE_SIZE, "w"); + + /* create result pipe for reading */ +- char result_filename[128]; + snprintf (result_filename, 128, RESULT_FILENAME_FORMAT, getpid()); + unlink (result_filename); + mkfifo (result_filename, 0600); +- int result_fd = open (result_filename, O_RDONLY | O_NONBLOCK, 0600); ++ atexit(cleanup); ++ result_fd = open (result_filename, O_RDONLY | O_NONBLOCK, 0600); + if (result_fd < 0) + { + print_error (ERROR_LEVEL, +@@ -293,11 +304,6 @@ int main (int argc, char *argv[]) + ); + printf ("%s", rbuf); + +- /* cleaning up */ +- +- close (result_fd); +- unlink (result_filename); +- + return command_result_code; + } + 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 new file mode 100644 index 000000000..6110b0c5b --- /dev/null +++ b/net/xl2tpd/patches/206-xl2tpd-fix-possible-buffer-overflow-when-filling-str.patch @@ -0,0 +1,22 @@ +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/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 new file mode 100644 index 000000000..d513a5820 --- /dev/null +++ b/net/xl2tpd/patches/207-l2tp_log-remove-log-prefix-that-will-duplicate-with-.patch @@ -0,0 +1,21 @@ +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); + } + } +