Skip to content

Commit 37c63e9

Browse files
committedJul 8, 2020
ppp: add shellsync support
1 parent 170042c commit 37c63e9

23 files changed

+668
-37
lines changed
 

‎feeds.conf.default

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
src-git packages https://git.openwrt.org/feed/packages.git
1+
src-git packages https://github.com/coolsnowwolf/packages
22
src-git luci https://github.com/coolsnowwolf/luci
33
src-git routing https://git.openwrt.org/feed/routing.git
44
src-git telephony https://git.openwrt.org/feed/telephony.git

‎package/network/services/ppp/Makefile

+5-6
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,18 @@ include $(TOPDIR)/rules.mk
99
include $(INCLUDE_DIR)/kernel.mk
1010

1111
PKG_NAME:=ppp
12-
PKG_RELEASE:=2
12+
PKG_RELEASE:=5
1313

1414
PKG_SOURCE_PROTO:=git
1515
PKG_SOURCE_URL:=https://github.com/paulusmack/ppp
16-
PKG_SOURCE_DATE:=2020-05-25
17-
PKG_SOURCE_VERSION:=ddd57c279f467e18c4fb3a661f21a069a5a37a1f
18-
PKG_MIRROR_HASH:=aac65e65dd25eaf8978a7a0b3258c863d90e29e247dd33d95276c0c189bcd424
16+
PKG_SOURCE_VERSION:=78cd384ce0f48bb5edb84e4fe9a574eab4a4ad14
17+
PKG_MIRROR_HASH:=cf284c312b0c90974d11f8aeece173bcac8475f5b810911f4feb2c5a4db263fe
1918
PKG_MAINTAINER:=Felix Fietkau <nbd@nbd.name>
2019
PKG_LICENSE:=BSD-4-Clause
2120
PKG_CPE_ID:=cpe:/a:samba:ppp
2221

2322
PKG_RELEASE_VERSION:=2.4.8
24-
PKG_VERSION:=$(PKG_RELEASE_VERSION).git-$(PKG_SOURCE_DATE)
23+
PKG_VERSION:=$(PKG_RELEASE_VERSION)
2524

2625
PKG_BUILD_DEPENDS:=libpcap
2726

@@ -39,7 +38,7 @@ endef
3938

4039
define Package/ppp
4140
$(call Package/ppp/Default)
42-
DEPENDS:=+kmod-ppp
41+
DEPENDS:=+kmod-ppp +libpthread +shellsync +kmod-mppe
4342
TITLE:=PPP daemon
4443
VARIANT:=default
4544
endef

‎package/network/services/ppp/files/ppp.sh

+13-6
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ ppp_generic_init_config() {
7474
proto_config_add_string pppd_options
7575
proto_config_add_string 'connect:file'
7676
proto_config_add_string 'disconnect:file'
77-
[ -e /proc/sys/net/ipv6 ] && proto_config_add_string ipv6
77+
proto_config_add_string ipv6
7878
proto_config_add_boolean authfail
7979
proto_config_add_int mtu
8080
proto_config_add_string pppname
@@ -88,9 +88,7 @@ ppp_generic_setup() {
8888
local config="$1"; shift
8989
local localip
9090

91-
json_get_vars ip6table demand keepalive keepalive_adaptive username password pppd_options pppname unnumbered persist maxfail holdoff peerdns
92-
93-
[ ! -e /proc/sys/net/ipv6 ] && ipv6=0 || json_get_var ipv6 ipv6
91+
json_get_vars ipv6 ip6table demand keepalive keepalive_adaptive username password pppd_options pppname unnumbered persist maxfail holdoff peerdns
9492

9593
if [ "$ipv6" = 0 ]; then
9694
ipv6=""
@@ -151,9 +149,9 @@ ppp_generic_setup() {
151149
${connect:+connect "$connect"} \
152150
${disconnect:+disconnect "$disconnect"} \
153151
ip-up-script /lib/netifd/ppp-up \
154-
${ipv6:+ipv6-up-script /lib/netifd/ppp6-up} \
152+
ipv6-up-script /lib/netifd/ppp6-up \
155153
ip-down-script /lib/netifd/ppp-down \
156-
${ipv6:+ipv6-down-script /lib/netifd/ppp-down} \
154+
ipv6-down-script /lib/netifd/ppp-down \
157155
${mtu:+mtu $mtu mru $mtu} \
158156
"$@" $pppd_options
159157
}
@@ -233,7 +231,16 @@ proto_pppoe_setup() {
233231
json_get_var padi_attempts padi_attempts
234232
json_get_var padi_timeout padi_timeout
235233

234+
#By 蝈蝈:并发拨号同步的前期准备
235+
syncppp_option=""
236+
[ "$(uci get syncdial.config.enabled)" -eq "1" ] && {
237+
ppp_if_cnt=$(uci show network | grep -c "\.proto=\'pppoe\'$")
238+
syncppp_option="syncppp $ppp_if_cnt"
239+
shellsync $ppp_if_cnt 10
240+
}
241+
236242
ppp_generic_setup "$config" \
243+
$syncppp_option \
237244
plugin rp-pppoe.so \
238245
${ac:+rp_pppoe_ac "$ac"} \
239246
${service:+rp_pppoe_service "$service"} \

‎package/network/services/ppp/patches/100-debian_ip-ip_option.patch

+1-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ Signed-off-by: Jo-Philipp Wich <jo@mein.io>
8585
"Enable multilink operation", OPT_PRIO | 1 },
8686
--- a/pppd/pppd.h
8787
+++ b/pppd/pppd.h
88-
@@ -335,6 +335,8 @@ extern int connect_delay; /* Time to del
88+
@@ -334,6 +334,8 @@ extern int connect_delay; /* Time to del
8989
extern int max_data_rate; /* max bytes/sec through charshunt */
9090
extern int req_unit; /* interface unit number to use */
9191
extern char req_ifname[MAXIFNAMELEN]; /* interface name to use */

‎package/network/services/ppp/patches/105-debian_demand.patch

+1-1
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@
161161
} else {
162162
--- a/pppd/pppd.h
163163
+++ b/pppd/pppd.h
164-
@@ -602,7 +602,7 @@ void demand_conf __P((void)); /* config
164+
@@ -601,7 +601,7 @@ void demand_conf __P((void)); /* config
165165
void demand_block __P((void)); /* set all NPs to queue up packets */
166166
void demand_unblock __P((void)); /* set all NPs to pass packets */
167167
void demand_discard __P((void)); /* set all NPs to discard packets */

‎package/network/services/ppp/patches/110-debian_defaultroute.patch

+3-3
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ Signed-off-by: Jo-Philipp Wich <jo@mein.io>
137137
.B disconnect \fIscript
138138
Execute the command specified by \fIscript\fR, by passing it to a
139139
shell, after
140-
@@ -751,7 +756,12 @@ disable both forms of hardware flow cont
140+
@@ -746,7 +751,12 @@ disable both forms of hardware flow cont
141141
.TP
142142
.B nodefaultroute
143143
Disable the \fIdefaultroute\fR option. The system administrator who
@@ -153,7 +153,7 @@ Signed-off-by: Jo-Philipp Wich <jo@mein.io>
153153
.B nodefaultroute6
154154
--- a/pppd/pppd.h
155155
+++ b/pppd/pppd.h
156-
@@ -684,7 +684,7 @@ int sif6addr __P((int, eui64_t, eui64_t
156+
@@ -683,7 +683,7 @@ int sif6addr __P((int, eui64_t, eui64_t
157157
int cif6addr __P((int, eui64_t, eui64_t));
158158
/* Remove an IPv6 address from i/f */
159159
#endif
@@ -292,7 +292,7 @@ Signed-off-by: Jo-Philipp Wich <jo@mein.io>
292292
}
293293
--- a/pppd/sys-solaris.c
294294
+++ b/pppd/sys-solaris.c
295-
@@ -2120,12 +2120,18 @@ cifaddr(u, o, h)
295+
@@ -2119,12 +2119,18 @@ cifaddr(u, o, h)
296296
* sifdefaultroute - assign a default route through the address given.
297297
*/
298298
int

‎package/network/services/ppp/patches/120-debian_ipv6_updown_option.patch

+1-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ Signed-off-by: Jo-Philipp Wich <jo@mein.io>
8484
}
8585
--- a/pppd/pppd.h
8686
+++ b/pppd/pppd.h
87-
@@ -337,6 +337,8 @@ extern int req_unit; /* interface unit n
87+
@@ -336,6 +336,8 @@ extern int req_unit; /* interface unit n
8888
extern char req_ifname[MAXIFNAMELEN]; /* interface name to use */
8989
extern char path_ipup[MAXPATHLEN]; /* pathname of ip-up script */
9090
extern char path_ipdown[MAXPATHLEN]; /* pathname of ip-down script */
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
--- a/pppd/lcp.c
2+
+++ b/pppd/lcp.c
3+
@@ -72,6 +72,7 @@ static void lcp_delayed_up __P((void *))
4+
*/
5+
int lcp_echo_interval = 0; /* Interval between LCP echo-requests */
6+
int lcp_echo_fails = 0; /* Tolerance to unanswered echo-requests */
7+
+bool lcp_echo_adaptive = 0; /* request echo only if the link was idle */
8+
bool lax_recv = 0; /* accept control chars in asyncmap */
9+
bool noendpoint = 0; /* don't send/accept endpoint discriminator */
10+
11+
@@ -150,6 +151,8 @@ static option_t lcp_option_list[] = {
12+
OPT_PRIO },
13+
{ "lcp-echo-interval", o_int, &lcp_echo_interval,
14+
"Set time in seconds between LCP echo requests", OPT_PRIO },
15+
+ { "lcp-echo-adaptive", o_bool, &lcp_echo_adaptive,
16+
+ "Suppress LCP echo requests if traffic was received", 1 },
17+
{ "lcp-restart", o_int, &lcp_fsm[0].timeouttime,
18+
"Set time in seconds between LCP retransmissions", OPT_PRIO },
19+
{ "lcp-max-terminate", o_int, &lcp_fsm[0].maxtermtransmits,
20+
@@ -2330,6 +2333,22 @@ LcpSendEchoRequest (f)
21+
}
22+
}
23+
24+
+ /*
25+
+ * If adaptive echos have been enabled, only send the echo request if
26+
+ * no traffic was received since the last one.
27+
+ */
28+
+ if (lcp_echo_adaptive) {
29+
+ static unsigned int last_pkts_in = 0;
30+
+
31+
+ update_link_stats(f->unit);
32+
+ link_stats_valid = 0;
33+
+
34+
+ if (link_stats.pkts_in != last_pkts_in) {
35+
+ last_pkts_in = link_stats.pkts_in;
36+
+ return;
37+
+ }
38+
+ }
39+
+
40+
/*
41+
* Make and send the echo request frame.
42+
*/
43+
--- a/pppd/pppd.8
44+
+++ b/pppd/pppd.8
45+
@@ -575,6 +575,11 @@ to 1) if the \fIproxyarp\fR option is us
46+
dynamic IP address option (i.e. set /proc/sys/net/ipv4/ip_dynaddr to
47+
1) in demand mode if the local address changes.
48+
.TP
49+
+.B lcp\-echo\-adaptive
50+
+If this option is used with the \fIlcp\-echo\-failure\fR option then
51+
+pppd will send LCP echo\-request frames only if no traffic was received
52+
+from the peer since the last echo\-request was sent.
53+
+.TP
54+
.B lcp\-echo\-failure \fIn
55+
If this option is given, pppd will presume the peer to be dead
56+
if \fIn\fR LCP echo\-requests are sent without receiving a valid LCP

‎package/network/services/ppp/patches/200-makefile.patch

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ Signed-off-by: Jo-Philipp Wich <jo@mein.io>
3434

3535
CFLAGS= $(COPTS) $(COMPILE_FLAGS) $(INCLUDE_DIRS) '-DDESTDIR="@DESTDIR@"'
3636

37-
@@ -126,10 +126,10 @@ CFLAGS += -DHAS_SHADOW
37+
@@ -125,10 +125,10 @@ CFLAGS += -DHAS_SHADOW
3838
#LIBS += -lshadow $(LIBS)
3939
endif
4040

‎package/network/services/ppp/patches/202-no_strip.patch

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ Signed-off-by: Jo-Philipp Wich <jo@mein.io>
1919
clean:
2020
--- a/pppd/Makefile.linux
2121
+++ b/pppd/Makefile.linux
22-
@@ -108,7 +108,7 @@ ifdef USE_SRP
22+
@@ -107,7 +107,7 @@ ifdef USE_SRP
2323
CFLAGS += -DUSE_SRP -DOPENSSL -I/usr/local/ssl/include
2424
LIBS += -lsrp -L/usr/local/ssl/lib -lcrypto
2525
TARGETS += srp-entry
@@ -28,7 +28,7 @@ Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2828
MANPAGES += srp-entry.8
2929
EXTRACLEAN += srp-entry.o
3030
NEEDDES=y
31-
@@ -220,7 +220,7 @@ all: $(TARGETS)
31+
@@ -219,7 +219,7 @@ all: $(TARGETS)
3232
install: pppd
3333
mkdir -p $(BINDIR) $(MANDIR)
3434
$(EXTRAINSTALL)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
pppd: Watch out for time warps
2+
3+
On many embedded systems there is no battery backed RTC and a proper system
4+
time only becomes available through NTP after establishing a connection.
5+
6+
When the clock suddenly jumps forward, the internal accounting (connect time)
7+
is confused resulting in unreliable data.
8+
9+
This patch implements periodic clock checking to look for time warps, if one
10+
is detected, the internal counters are adjusted accordingly.
11+
12+
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
13+
14+
--- a/pppd/main.c
15+
+++ b/pppd/main.c
16+
@@ -89,6 +89,7 @@
17+
#include <sys/socket.h>
18+
#include <netinet/in.h>
19+
#include <arpa/inet.h>
20+
+#include <sys/sysinfo.h>
21+
22+
#include "pppd.h"
23+
#include "magic.h"
24+
@@ -226,6 +227,7 @@ static struct subprocess *children;
25+
26+
/* Prototypes for procedures local to this file. */
27+
28+
+static void check_time(void);
29+
static void setup_signals __P((void));
30+
static void create_pidfile __P((int pid));
31+
static void create_linkpidfile __P((int pid));
32+
@@ -525,6 +527,7 @@ main(argc, argv)
33+
info("Starting link");
34+
}
35+
36+
+ check_time();
37+
gettimeofday(&start_time, NULL);
38+
script_unsetenv("CONNECT_TIME");
39+
script_unsetenv("BYTES_SENT");
40+
@@ -1274,6 +1277,36 @@ struct callout {
41+
42+
static struct callout *callout = NULL; /* Callout list */
43+
static struct timeval timenow; /* Current time */
44+
+static long uptime_diff = 0;
45+
+static int uptime_diff_set = 0;
46+
+
47+
+static void check_time(void)
48+
+{
49+
+ long new_diff;
50+
+ struct timeval t;
51+
+ struct sysinfo i;
52+
+ struct callout *p;
53+
+
54+
+ gettimeofday(&t, NULL);
55+
+ sysinfo(&i);
56+
+ new_diff = t.tv_sec - i.uptime;
57+
+
58+
+ if (!uptime_diff_set) {
59+
+ uptime_diff = new_diff;
60+
+ uptime_diff_set = 1;
61+
+ return;
62+
+ }
63+
+
64+
+ if ((new_diff - 5 > uptime_diff) || (new_diff + 5 < uptime_diff)) {
65+
+ /* system time has changed, update counters and timeouts */
66+
+ info("System time change detected.");
67+
+ start_time.tv_sec += new_diff - uptime_diff;
68+
+
69+
+ for (p = callout; p != NULL; p = p->c_next)
70+
+ p->c_time.tv_sec += new_diff - uptime_diff;
71+
+ }
72+
+ uptime_diff = new_diff;
73+
+}
74+
75+
/*
76+
* timeout - Schedule a timeout.
77+
@@ -1344,6 +1377,8 @@ calltimeout()
78+
{
79+
struct callout *p;
80+
81+
+ check_time();
82+
+
83+
while (callout != NULL) {
84+
p = callout;
85+
86+
@@ -1371,6 +1406,8 @@ timeleft(tvp)
87+
{
88+
if (callout == NULL)
89+
return NULL;
90+
+
91+
+ check_time();
92+
93+
gettimeofday(&timenow, NULL);
94+
tvp->tv_sec = callout->c_time.tv_sec - timenow.tv_sec;

‎package/network/services/ppp/patches/208-fix_status_code.patch

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Signed-off-by: Jo-Philipp Wich <jo@mein.io>
1212

1313
--- a/pppd/main.c
1414
+++ b/pppd/main.c
15-
@@ -1052,7 +1052,8 @@ get_input()
15+
@@ -1055,7 +1055,8 @@ get_input()
1616
}
1717
notice("Modem hangup");
1818
hungup = 1;

‎package/network/services/ppp/patches/300-filter-pcap-includes-lib.patch

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Signed-off-by: Jo-Philipp Wich <jo@mein.io>
77

88
--- a/pppd/Makefile.linux
99
+++ b/pppd/Makefile.linux
10-
@@ -190,8 +190,8 @@ endif
10+
@@ -189,8 +189,8 @@ endif
1111

1212
ifdef FILTER
1313
ifneq ($(wildcard /usr/include/pcap-bpf.h),)

‎package/network/services/ppp/patches/310-precompile_filter.patch

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2323
# Uncomment the next line to enable multilink PPP (enabled by default)
2424
# Linux distributions: Please leave multilink ENABLED in your builds
2525
# of pppd!
26-
@@ -195,6 +198,14 @@ CFLAGS += -DPPP_FILTER -I$(STAGING_DIR)
26+
@@ -194,6 +197,14 @@ CFLAGS += -DPPP_FILTER -I$(STAGING_DIR)
2727
endif
2828
endif
2929

@@ -77,7 +77,7 @@ Signed-off-by: Jo-Philipp Wich <jo@mein.io>
7777
#ifdef MAXOCTETS
7878
{ "maxoctets", o_int, &maxoctets,
7979
"Set connection traffic limit",
80-
@@ -1516,6 +1532,29 @@ callfile(argv)
80+
@@ -1511,6 +1527,29 @@ callfile(argv)
8181
return ok;
8282
}
8383

‎package/network/services/ppp/patches/401-no_record_file.patch

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Signed-off-by: Jo-Philipp Wich <jo@mein.io>
77

88
--- a/pppd/pppd.h
99
+++ b/pppd/pppd.h
10-
@@ -326,7 +326,6 @@ extern int holdoff; /* Dead time before
10+
@@ -325,7 +325,6 @@ extern int holdoff; /* Dead time before
1111
extern bool holdoff_specified; /* true if user gave a holdoff value */
1212
extern bool notty; /* Stdin/out is not a tty */
1313
extern char *pty_socket; /* Socket to connect to pty */

‎package/network/services/ppp/patches/404-remove_obsolete_protocol_names.patch

+8-8
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Signed-off-by: Jo-Philipp Wich <jo@mein.io>
77

88
--- a/pppd/main.c
99
+++ b/pppd/main.c
10-
@@ -883,14 +883,17 @@ struct protocol_list {
10+
@@ -886,14 +886,17 @@ struct protocol_list {
1111
const char *name;
1212
} protocol_list[] = {
1313
{ 0x21, "IP" },
@@ -25,7 +25,7 @@ Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2525
{ 0x33, "Stream Protocol ST-II" },
2626
{ 0x35, "Banyan Vines" },
2727
{ 0x39, "AppleTalk EDDP" },
28-
@@ -904,8 +907,11 @@ struct protocol_list {
28+
@@ -907,8 +910,11 @@ struct protocol_list {
2929
{ 0x49, "Serial Data Transport Protocol (PPP-SDTP)" },
3030
{ 0x4b, "SNA over 802.2" },
3131
{ 0x4d, "SNA" },
@@ -37,7 +37,7 @@ Signed-off-by: Jo-Philipp Wich <jo@mein.io>
3737
{ 0x53, "Encryption" },
3838
{ 0x55, "Individual Link Encryption" },
3939
{ 0x57, "IPv6" },
40-
@@ -916,12 +922,15 @@ struct protocol_list {
40+
@@ -919,12 +925,15 @@ struct protocol_list {
4141
{ 0x65, "RTP IPHC Compressed non-TCP" },
4242
{ 0x67, "RTP IPHC Compressed UDP 8" },
4343
{ 0x69, "RTP IPHC Compressed RTP 8" },
@@ -53,7 +53,7 @@ Signed-off-by: Jo-Philipp Wich <jo@mein.io>
5353
{ 0x0203, "IBM Source Routing BPDU" },
5454
{ 0x0205, "DEC LANBridge100 Spanning Tree" },
5555
{ 0x0207, "Cisco Discovery Protocol" },
56-
@@ -933,15 +942,19 @@ struct protocol_list {
56+
@@ -936,15 +945,19 @@ struct protocol_list {
5757
{ 0x0231, "Luxcom" },
5858
{ 0x0233, "Sigma Network Systems" },
5959
{ 0x0235, "Apple Client Server Protocol" },
@@ -73,7 +73,7 @@ Signed-off-by: Jo-Philipp Wich <jo@mein.io>
7373
{ 0x4001, "Cray Communications Control Protocol" },
7474
{ 0x4003, "CDPD Mobile Network Registration Protocol" },
7575
{ 0x4005, "Expand accelerator protocol" },
76-
@@ -952,8 +965,10 @@ struct protocol_list {
76+
@@ -955,8 +968,10 @@ struct protocol_list {
7777
{ 0x4023, "RefTek Protocol" },
7878
{ 0x4025, "Fibre Channel" },
7979
{ 0x4027, "EMIT Protocols" },
@@ -84,7 +84,7 @@ Signed-off-by: Jo-Philipp Wich <jo@mein.io>
8484
{ 0x8023, "OSI Network Layer Control Protocol" },
8585
{ 0x8025, "Xerox NS IDP Control Protocol" },
8686
{ 0x8027, "DECnet Phase IV Control Protocol" },
87-
@@ -962,7 +977,9 @@ struct protocol_list {
87+
@@ -965,7 +980,9 @@ struct protocol_list {
8888
{ 0x8031, "Bridging NCP" },
8989
{ 0x8033, "Stream Protocol Control Protocol" },
9090
{ 0x8035, "Banyan Vines Control Protocol" },
@@ -94,7 +94,7 @@ Signed-off-by: Jo-Philipp Wich <jo@mein.io>
9494
{ 0x803f, "NETBIOS Framing Control Protocol" },
9595
{ 0x8041, "Cisco Systems Control Protocol" },
9696
{ 0x8043, "Ascom Timeplex" },
97-
@@ -971,18 +988,24 @@ struct protocol_list {
97+
@@ -974,18 +991,24 @@ struct protocol_list {
9898
{ 0x8049, "Serial Data Control Protocol (PPP-SDCP)" },
9999
{ 0x804b, "SNA over 802.2 Control Protocol" },
100100
{ 0x804d, "SNA Control Protocol" },
@@ -119,7 +119,7 @@ Signed-off-by: Jo-Philipp Wich <jo@mein.io>
119119
{ 0x8207, "Cisco Discovery Protocol Control" },
120120
{ 0x8209, "Netcs Twin Routing" },
121121
{ 0x820b, "STP - Control Protocol" },
122-
@@ -991,24 +1014,29 @@ struct protocol_list {
122+
@@ -994,24 +1017,29 @@ struct protocol_list {
123123
{ 0x8281, "MPLSCP" },
124124
{ 0x8285, "IEEE p1284.4 standard - Protocol Control" },
125125
{ 0x8287, "ETSI TETRA TNP1 Control Protocol" },
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,207 @@
1+
--- a/pppd/chap-new.c
2+
+++ b/pppd/chap-new.c
3+
@@ -37,6 +37,8 @@
4+
#include "chap-new.h"
5+
#include "chap-md5.h"
6+
7+
+#include "syncppp.h"
8+
+
9+
#ifdef CHAPMS
10+
#include "chap_ms.h"
11+
#define MDTYPE_ALL (MDTYPE_MICROSOFT_V2 | MDTYPE_MICROSOFT | MDTYPE_MD5)
12+
@@ -492,6 +494,19 @@ chap_respond(struct chap_client_state *c
13+
p[2] = len >> 8;
14+
p[3] = len;
15+
16+
+ if (npppd > 1) {
17+
+ if (syncppp(npppd) < 0) {
18+
+ error("syncppp sync fail");
19+
+ sem_unlink(SEM_COUNT_NAME);
20+
+ sem_unlink(SEM_BLOCK_NAME);
21+
+ } else {
22+
+ info("syncppp sync succeeded");
23+
+ }
24+
+ } else {
25+
+ info("syncppp not active");
26+
+ }
27+
+
28+
+
29+
output(0, response, PPP_HDRLEN + len);
30+
}
31+
32+
--- a/pppd/Makefile.linux
33+
+++ b/pppd/Makefile.linux
34+
@@ -13,16 +13,16 @@ TARGETS = pppd
35+
36+
PPPDSRCS = main.c magic.c fsm.c lcp.c ipcp.c upap.c chap-new.c md5.c ccp.c \
37+
ecp.c ipxcp.c auth.c options.c sys-linux.c md4.c chap_ms.c \
38+
- demand.c utils.c tty.c eap.c chap-md5.c session.c
39+
+ demand.c utils.c tty.c eap.c chap-md5.c session.c syncppp.c
40+
41+
HEADERS = ccp.h session.h chap-new.h ecp.h fsm.h ipcp.h \
42+
ipxcp.h lcp.h magic.h md5.h patchlevel.h pathnames.h pppd.h \
43+
- upap.h eap.h
44+
+ upap.h eap.h syncppp.h
45+
46+
MANPAGES = pppd.8
47+
PPPDOBJS = main.o magic.o fsm.o lcp.o ipcp.o upap.o chap-new.o md5.o ccp.o \
48+
ecp.o auth.o options.o demand.o utils.o sys-linux.o ipxcp.o tty.o \
49+
- eap.o chap-md5.o session.o
50+
+ eap.o chap-md5.o session.o syncppp.o
51+
52+
#
53+
# include dependencies if present
54+
@@ -33,7 +33,7 @@ endif
55+
# CC = gcc
56+
#
57+
COPTS = -O2 -pipe -Wall -g
58+
-LIBS =
59+
+LIBS = -lpthread
60+
61+
# Uncomment the next line to include support for Microsoft's
62+
# MS-CHAP authentication protocol. Also, edit plugins/radius/Makefile.linux.
63+
--- a/pppd/options.c
64+
+++ b/pppd/options.c
65+
@@ -128,6 +128,7 @@ bool dump_options; /* print out option
66+
bool dryrun; /* print out option values and exit */
67+
char *domain; /* domain name set by domain option */
68+
int child_wait = 5; /* # seconds to wait for children at exit */
69+
+int npppd = 0; /* synchronize between multiple pppd */
70+
struct userenv *userenv_list; /* user environment variables */
71+
int dfl_route_metric = -1; /* metric of the default route to set over the PPP link */
72+
73+
@@ -342,6 +343,10 @@ option_t general_options[] = {
74+
"Set pathname of ipv6-down script",
75+
OPT_PRIV|OPT_STATIC, NULL, MAXPATHLEN },
76+
77+
+ { "syncppp", o_int, &npppd,
78+
+ "sync among multiple pppd when sending chap/pap respond", OPT_PRIO },
79+
+
80+
+
81+
#ifdef HAVE_MULTILINK
82+
{ "multilink", o_bool, &multilink,
83+
"Enable multilink operation", OPT_PRIO | 1 },
84+
--- a/pppd/pppd.h
85+
+++ b/pppd/pppd.h
86+
@@ -343,6 +343,7 @@ extern char *bundle_name; /* bundle name
87+
extern bool dump_options; /* print out option values */
88+
extern bool dryrun; /* check everything, print options, exit */
89+
extern int child_wait; /* # seconds to wait for children at end */
90+
+extern int npppd; /* synchronize between multiple pppd */
91+
92+
#ifdef MAXOCTETS
93+
extern unsigned int maxoctets; /* Maximum octetes per session (in bytes) */
94+
--- /dev/null
95+
+++ b/pppd/syncppp.c
96+
@@ -0,0 +1,75 @@
97+
+#include<stdio.h>
98+
+#include<semaphore.h>
99+
+#include<fcntl.h>
100+
+#include<stdlib.h>
101+
+#include<time.h>
102+
+#include<errno.h>
103+
+#include "pppd.h"
104+
+#include "syncppp.h"
105+
+
106+
+int syncppp(int nproc)
107+
+{
108+
+ int flags;
109+
+ int value;
110+
+ sem_t *block;
111+
+ sem_t *count;
112+
+ struct timespec ts;
113+
+
114+
+ if (nproc <= 1) {
115+
+ error("syncppp: number of pppd should be larger than 1");
116+
+ return -1;
117+
+ }
118+
+
119+
+ if (clock_gettime(CLOCK_REALTIME, &ts) == -1) {
120+
+ error("clock_gettime error");
121+
+ return -1;
122+
+ }
123+
+ ts.tv_sec += SYNCPPP_TIMEOUT;
124+
+
125+
+
126+
+ flags = O_RDWR | O_CREAT;
127+
+ block = sem_open(SEM_BLOCK_NAME, flags, 0644, 0);
128+
+ count = sem_open(SEM_COUNT_NAME, flags, 0644, 0);
129+
+ if (block == SEM_FAILED || count == SEM_FAILED) {
130+
+ error("syncppp: sem_open failed");
131+
+ return -1;
132+
+ }
133+
+
134+
+ if (sem_post(count) < 0) {
135+
+ error("syncppp: sem_post failed");
136+
+ return -1;
137+
+ }
138+
+ if (sem_getvalue(count, &value) < 0) {
139+
+ error("syncppp: sem_getvalue failed");
140+
+ return -1;
141+
+ }
142+
+ info("%d pppd have arrived, waiting for the left %d", value, nproc-value);
143+
+ if (value >= nproc) {
144+
+ while (nproc-1 > 0) {
145+
+ if (sem_post(block) < 0) {
146+
+ error("syncppp: sem_post failed");
147+
+ return -1;
148+
+ }
149+
+ nproc--;
150+
+ }
151+
+ } else {
152+
+ if (sem_timedwait(block, &ts) < 0) {
153+
+ if (errno == ETIMEDOUT) {
154+
+ error("syncppp: sem_timewait time out");
155+
+ } else {
156+
+ error("syncppp: sem_timewait error");
157+
+ }
158+
+ return -1;
159+
+ }
160+
+
161+
+ }
162+
+
163+
+ sem_close(count);
164+
+ sem_close(block);
165+
+
166+
+ sem_unlink(SEM_COUNT_NAME);
167+
+ sem_unlink(SEM_BLOCK_NAME);
168+
+
169+
+ return 0;
170+
+}
171+
+
172+
--- /dev/null
173+
+++ b/pppd/syncppp.h
174+
@@ -0,0 +1,3 @@
175+
+#define SEM_BLOCK_NAME "block"
176+
+#define SEM_COUNT_NAME "count"
177+
+#define SYNCPPP_TIMEOUT 5
178+
--- a/pppd/upap.c
179+
+++ b/pppd/upap.c
180+
@@ -52,6 +52,7 @@
181+
#include "pppd.h"
182+
#include "upap.h"
183+
184+
+#include "syncppp.h"
185+
186+
static bool hide_password = 1;
187+
188+
@@ -567,6 +568,18 @@ upap_sauthreq(u)
189+
PUTCHAR(u->us_passwdlen, outp);
190+
BCOPY(u->us_passwd, outp, u->us_passwdlen);
191+
192+
+ if (npppd > 1) {
193+
+ if (syncppp(npppd) < 0) {
194+
+ error("syncppp sync fail");
195+
+ sem_unlink(SEM_COUNT_NAME);
196+
+ sem_unlink(SEM_BLOCK_NAME);
197+
+ } else {
198+
+ info("syncppp sync succeeded");
199+
+ }
200+
+ } else {
201+
+ info("syncppp not active");
202+
+ }
203+
+
204+
output(u->us_unit, outpacket_buf, outlen + PPP_HDRLEN);
205+
206+
TIMEOUT(upap_timeout, u, u->us_timeouttime);
207+

‎package/network/services/ppp/patches/600-Revert-pppd-Use-openssl-for-the-DES-instead-of-the-l.patch

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ This reverts commit 3c7b86229f7bd2600d74db14b1fe5b3896be3875.
1717
+++ b/pppd/Makefile.linux
1818
@@ -35,10 +35,10 @@ endif
1919
COPTS = -O2 -pipe -Wall -g
20-
LIBS = -lrt
20+
LIBS =
2121

2222
-# Uncomment the next line to include support for Microsoft's
2323
+# Uncomment the next 2 lines to include support for Microsoft's
@@ -28,7 +28,7 @@ This reverts commit 3c7b86229f7bd2600d74db14b1fe5b3896be3875.
2828
# Don't use MSLANMAN unless you really know what you're doing.
2929
#MSLANMAN=y
3030
# Uncomment the next line to include support for MPPE. CHAPMS (above) must
31-
@@ -141,8 +141,7 @@ endif
31+
@@ -140,8 +140,7 @@ endif
3232

3333
ifdef NEEDDES
3434
ifndef USE_CRYPT
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
From 858976b1fc3107f1261aae337831959b511b83c2 Mon Sep 17 00:00:00 2001
2+
From: Paul Mackerras <paulus@ozlabs.org>
3+
Date: Sat, 4 Jan 2020 12:01:32 +1100
4+
Subject: [PATCH] radius: Prevent buffer overflow in rc_mksid()
5+
6+
On some systems getpid() can return a value greater than 65535.
7+
Increase the size of buf[] to allow for this, and use slprintf()
8+
to make sure we never overflow it.
9+
10+
Signed-off-by: Paul Mackerras <paulus@ozlabs.org>
11+
---
12+
pppd/plugins/radius/util.c | 4 ++--
13+
1 file changed, 2 insertions(+), 2 deletions(-)
14+
15+
diff --git a/pppd/plugins/radius/util.c b/pppd/plugins/radius/util.c
16+
index 6f976a712951..740131e8377c 100644
17+
--- a/pppd/plugins/radius/util.c
18+
+++ b/pppd/plugins/radius/util.c
19+
@@ -73,9 +73,9 @@ void rc_mdelay(int msecs)
20+
char *
21+
rc_mksid (void)
22+
{
23+
- static char buf[15];
24+
+ static char buf[32];
25+
static unsigned short int cnt = 0;
26+
- sprintf (buf, "%08lX%04X%02hX",
27+
+ slprintf(buf, sizeof(buf), "%08lX%04X%02hX",
28+
(unsigned long int) time (NULL),
29+
(unsigned int) getpid (),
30+
cnt & 0xFF);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
From 8d7970b8f3db727fe798b65f3377fe6787575426 Mon Sep 17 00:00:00 2001
2+
From: Paul Mackerras <paulus@ozlabs.org>
3+
Date: Mon, 3 Feb 2020 15:53:28 +1100
4+
Subject: [PATCH] pppd: Fix bounds check in EAP code
5+
6+
Given that we have just checked vallen < len, it can never be the case
7+
that vallen >= len + sizeof(rhostname). This fixes the check so we
8+
actually avoid overflowing the rhostname array.
9+
10+
Reported-by: Ilja Van Sprundel <ivansprundel@ioactive.com>
11+
Signed-off-by: Paul Mackerras <paulus@ozlabs.org>
12+
---
13+
pppd/eap.c | 4 ++--
14+
1 file changed, 2 insertions(+), 2 deletions(-)
15+
16+
diff --git a/pppd/eap.c b/pppd/eap.c
17+
index 94407f56a336..1b93db01aebd 100644
18+
--- a/pppd/eap.c
19+
+++ b/pppd/eap.c
20+
@@ -1420,7 +1420,7 @@ int len;
21+
}
22+
23+
/* Not so likely to happen. */
24+
- if (vallen >= len + sizeof (rhostname)) {
25+
+ if (len - vallen >= sizeof (rhostname)) {
26+
dbglog("EAP: trimming really long peer name down");
27+
BCOPY(inp + vallen, rhostname, sizeof (rhostname) - 1);
28+
rhostname[sizeof (rhostname) - 1] = '\0';
29+
@@ -1846,7 +1846,7 @@ int len;
30+
}
31+
32+
/* Not so likely to happen. */
33+
- if (vallen >= len + sizeof (rhostname)) {
34+
+ if (len - vallen >= sizeof (rhostname)) {
35+
dbglog("EAP: trimming really long peer name down");
36+
BCOPY(inp + vallen, rhostname, sizeof (rhostname) - 1);
37+
rhostname[sizeof (rhostname) - 1] = '\0';
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
From 8d45443bb5c9372b4c6a362ba2f443d41c5636af Mon Sep 17 00:00:00 2001
2+
From: Paul Mackerras <paulus@ozlabs.org>
3+
Date: Mon, 3 Feb 2020 16:31:42 +1100
4+
Subject: [PATCH] pppd: Ignore received EAP messages when not doing EAP
5+
6+
This adds some basic checks to the subroutines of eap_input to check
7+
that we have requested or agreed to doing EAP authentication before
8+
doing any processing on the received packet. The motivation is to
9+
make it harder for a malicious peer to disrupt the operation of pppd
10+
by sending unsolicited EAP packets. Note that eap_success() already
11+
has a check that the EAP client state is reasonable, and does nothing
12+
(apart from possibly printing a debug message) if not.
13+
14+
Signed-off-by: Paul Mackerras <paulus@ozlabs.org>
15+
---
16+
pppd/eap.c | 18 ++++++++++++++++++
17+
1 file changed, 18 insertions(+)
18+
19+
diff --git a/pppd/eap.c b/pppd/eap.c
20+
index 1b93db01aebd..082e95343120 100644
21+
--- a/pppd/eap.c
22+
+++ b/pppd/eap.c
23+
@@ -1328,6 +1328,12 @@ int len;
24+
int fd;
25+
#endif /* USE_SRP */
26+
27+
+ /*
28+
+ * Ignore requests if we're not open
29+
+ */
30+
+ if (esp->es_client.ea_state <= eapClosed)
31+
+ return;
32+
+
33+
/*
34+
* Note: we update es_client.ea_id *only if* a Response
35+
* message is being generated. Otherwise, we leave it the
36+
@@ -1736,6 +1742,12 @@ int len;
37+
u_char dig[SHA_DIGESTSIZE];
38+
#endif /* USE_SRP */
39+
40+
+ /*
41+
+ * Ignore responses if we're not open
42+
+ */
43+
+ if (esp->es_server.ea_state <= eapClosed)
44+
+ return;
45+
+
46+
if (esp->es_server.ea_id != id) {
47+
dbglog("EAP: discarding Response %d; expected ID %d", id,
48+
esp->es_server.ea_id);
49+
@@ -2047,6 +2059,12 @@ u_char *inp;
50+
int id;
51+
int len;
52+
{
53+
+ /*
54+
+ * Ignore failure messages if we're not open
55+
+ */
56+
+ if (esp->es_client.ea_state <= eapClosed)
57+
+ return;
58+
+
59+
if (!eap_client_active(esp)) {
60+
dbglog("EAP unexpected failure message in state %s (%d)",
61+
eap_state_name(esp->es_client.ea_state),
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
include $(TOPDIR)/rules.mk
2+
3+
PKG_NAME:=shellsync
4+
PKG_VERSION:=0.2
5+
PKG_RELEASE:=2
6+
7+
include $(INCLUDE_DIR)/package.mk
8+
9+
define Package/shellsync
10+
CATEGORY:=Utilities
11+
TITLE:=shellsync
12+
DEPENDS:=+libpthread +kmod-macvlan
13+
endef
14+
15+
define Build/Prepare
16+
mkdir -p $(PKG_BUILD_DIR)
17+
$(CP) ./src/* $(PKG_BUILD_DIR)/
18+
endef
19+
20+
define Package/shellsync/description
21+
A tool to sync different shell scripts.Based on syncppp patch by morfast.
22+
endef
23+
24+
define Build/Compile
25+
$(TARGET_CROSS)gcc -pthread -o $(PKG_BUILD_DIR)/shellsync $(PKG_BUILD_DIR)/shellsync.c
26+
endef
27+
28+
define Package/shellsync/install
29+
$(INSTALL_DIR) $(1)/usr/bin
30+
$(INSTALL_BIN) $(PKG_BUILD_DIR)/shellsync $(1)/usr/bin
31+
endef
32+
33+
34+
$(eval $(call BuildPackage,shellsync))
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
/*************************************************************************
2+
> File Name: shellsync.c
3+
> Author: GuoGuo
4+
> Mail: gch981213@gmail.com
5+
> Created Time: 2014年11月06日 星期四 19时15分30秒
6+
************************************************************************/
7+
#include<stdio.h>
8+
#include<semaphore.h>
9+
#include<fcntl.h>
10+
#include<stdlib.h>
11+
#include<time.h>
12+
#include<errno.h>
13+
#define SEM_BLOCK_NAME "SYNCSHELL_block"
14+
#define SEM_COUNT_NAME "SYNCSHELL_count"
15+
int wait_timeout;
16+
int sync_wait(int nproc)
17+
{
18+
int flags;
19+
int value;
20+
sem_t *block;
21+
sem_t *count;
22+
struct timespec ts;
23+
24+
if (nproc <= 1) {
25+
printf("sync_wait: number of processes should be larger than 1\n");
26+
return -1;
27+
}
28+
29+
if (clock_gettime(CLOCK_REALTIME, &ts) == -1) {
30+
printf("clock_gettime error\n");
31+
return -1;
32+
}
33+
ts.tv_sec += wait_timeout;
34+
35+
36+
flags = O_RDWR | O_CREAT;
37+
block = sem_open(SEM_BLOCK_NAME, flags, 0644, 0);
38+
count = sem_open(SEM_COUNT_NAME, flags, 0644, 0);
39+
if (block == SEM_FAILED || count == SEM_FAILED) {
40+
printf("sync_wait: sem_open failed\n");
41+
return -1;
42+
}
43+
44+
if (sem_post(count) < 0) {
45+
printf("sync_wait: sem_post failed\n");
46+
return -1;
47+
}
48+
if (sem_getvalue(count, &value) < 0) {
49+
printf("sync_wait: sem_getvalue failed\n");
50+
return -1;
51+
}
52+
printf("%d processes have arrived, waiting for the left %d\n", value, nproc-value);
53+
if (value >= nproc) {
54+
while (nproc-1 > 0) {
55+
if (sem_post(block) < 0) {
56+
printf("sync_wait: sem_post failed\n");
57+
return -1;
58+
}
59+
nproc--;
60+
}
61+
} else {
62+
if (sem_timedwait(block, &ts) < 0) {
63+
if (errno == ETIMEDOUT) {
64+
printf("sync_wait: sem_timewait time out\n");
65+
} else {
66+
printf("sync_wait: sem_timewait error\n");
67+
}
68+
return -1;
69+
}
70+
71+
}
72+
73+
sem_close(count);
74+
sem_close(block);
75+
76+
sem_unlink(SEM_COUNT_NAME);
77+
sem_unlink(SEM_BLOCK_NAME);
78+
79+
return 0;
80+
}
81+
82+
int main(int argc,char *argv[])
83+
{
84+
if(argc!=3)
85+
{
86+
printf("Usage: shellsync <process num> <wait_timeout>\n");
87+
}
88+
else
89+
{
90+
int proc_num;
91+
sscanf(argv[1],"%d",&proc_num);
92+
sscanf(argv[2],"%d",&wait_timeout);
93+
if(sync_wait(proc_num)<0)
94+
{
95+
printf("Processes sync failed.\n");
96+
sem_unlink(SEM_COUNT_NAME);
97+
sem_unlink(SEM_BLOCK_NAME);
98+
return 1;
99+
}
100+
else
101+
{
102+
printf("Processes sync succeed.\n");
103+
return 0;
104+
}
105+
}
106+
}

0 commit comments

Comments
 (0)
Please sign in to comment.