Skip to content

Commit

Permalink
ppp: add shellsync support
Browse files Browse the repository at this point in the history
  • Loading branch information
coolsnowwolf committed Jul 8, 2020
1 parent 170042c commit 37c63e9
Show file tree
Hide file tree
Showing 23 changed files with 668 additions and 37 deletions.
2 changes: 1 addition & 1 deletion feeds.conf.default
@@ -1,4 +1,4 @@
src-git packages https://git.openwrt.org/feed/packages.git
src-git packages https://github.com/coolsnowwolf/packages
src-git luci https://github.com/coolsnowwolf/luci
src-git routing https://git.openwrt.org/feed/routing.git
src-git telephony https://git.openwrt.org/feed/telephony.git
Expand Down
11 changes: 5 additions & 6 deletions package/network/services/ppp/Makefile
Expand Up @@ -9,19 +9,18 @@ include $(TOPDIR)/rules.mk
include $(INCLUDE_DIR)/kernel.mk

PKG_NAME:=ppp
PKG_RELEASE:=2
PKG_RELEASE:=5

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

PKG_RELEASE_VERSION:=2.4.8
PKG_VERSION:=$(PKG_RELEASE_VERSION).git-$(PKG_SOURCE_DATE)
PKG_VERSION:=$(PKG_RELEASE_VERSION)

PKG_BUILD_DEPENDS:=libpcap

Expand All @@ -39,7 +38,7 @@ endef

define Package/ppp
$(call Package/ppp/Default)
DEPENDS:=+kmod-ppp
DEPENDS:=+kmod-ppp +libpthread +shellsync +kmod-mppe
TITLE:=PPP daemon
VARIANT:=default
endef
Expand Down
19 changes: 13 additions & 6 deletions package/network/services/ppp/files/ppp.sh
Expand Up @@ -74,7 +74,7 @@ ppp_generic_init_config() {
proto_config_add_string pppd_options
proto_config_add_string 'connect:file'
proto_config_add_string 'disconnect:file'
[ -e /proc/sys/net/ipv6 ] && proto_config_add_string ipv6
proto_config_add_string ipv6
proto_config_add_boolean authfail
proto_config_add_int mtu
proto_config_add_string pppname
Expand All @@ -88,9 +88,7 @@ ppp_generic_setup() {
local config="$1"; shift
local localip

json_get_vars ip6table demand keepalive keepalive_adaptive username password pppd_options pppname unnumbered persist maxfail holdoff peerdns

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

if [ "$ipv6" = 0 ]; then
ipv6=""
Expand Down Expand Up @@ -151,9 +149,9 @@ ppp_generic_setup() {
${connect:+connect "$connect"} \
${disconnect:+disconnect "$disconnect"} \
ip-up-script /lib/netifd/ppp-up \
${ipv6:+ipv6-up-script /lib/netifd/ppp6-up} \
ipv6-up-script /lib/netifd/ppp6-up \
ip-down-script /lib/netifd/ppp-down \
${ipv6:+ipv6-down-script /lib/netifd/ppp-down} \
ipv6-down-script /lib/netifd/ppp-down \
${mtu:+mtu $mtu mru $mtu} \
"$@" $pppd_options
}
Expand Down Expand Up @@ -233,7 +231,16 @@ proto_pppoe_setup() {
json_get_var padi_attempts padi_attempts
json_get_var padi_timeout padi_timeout

#By 蝈蝈:并发拨号同步的前期准备
syncppp_option=""
[ "$(uci get syncdial.config.enabled)" -eq "1" ] && {
ppp_if_cnt=$(uci show network | grep -c "\.proto=\'pppoe\'$")
syncppp_option="syncppp $ppp_if_cnt"
shellsync $ppp_if_cnt 10
}

ppp_generic_setup "$config" \
$syncppp_option \
plugin rp-pppoe.so \
${ac:+rp_pppoe_ac "$ac"} \
${service:+rp_pppoe_service "$service"} \
Expand Down
Expand Up @@ -85,7 +85,7 @@ Signed-off-by: Jo-Philipp Wich <jo@mein.io>
"Enable multilink operation", OPT_PRIO | 1 },
--- a/pppd/pppd.h
+++ b/pppd/pppd.h
@@ -335,6 +335,8 @@ extern int connect_delay; /* Time to del
@@ -334,6 +334,8 @@ extern int connect_delay; /* Time to del
extern int max_data_rate; /* max bytes/sec through charshunt */
extern int req_unit; /* interface unit number to use */
extern char req_ifname[MAXIFNAMELEN]; /* interface name to use */
Expand Down
Expand Up @@ -161,7 +161,7 @@
} else {
--- a/pppd/pppd.h
+++ b/pppd/pppd.h
@@ -602,7 +602,7 @@ void demand_conf __P((void)); /* config
@@ -601,7 +601,7 @@ void demand_conf __P((void)); /* config
void demand_block __P((void)); /* set all NPs to queue up packets */
void demand_unblock __P((void)); /* set all NPs to pass packets */
void demand_discard __P((void)); /* set all NPs to discard packets */
Expand Down
Expand Up @@ -137,7 +137,7 @@ Signed-off-by: Jo-Philipp Wich <jo@mein.io>
.B disconnect \fIscript
Execute the command specified by \fIscript\fR, by passing it to a
shell, after
@@ -751,7 +756,12 @@ disable both forms of hardware flow cont
@@ -746,7 +751,12 @@ disable both forms of hardware flow cont
.TP
.B nodefaultroute
Disable the \fIdefaultroute\fR option. The system administrator who
Expand All @@ -153,7 +153,7 @@ Signed-off-by: Jo-Philipp Wich <jo@mein.io>
.B nodefaultroute6
--- a/pppd/pppd.h
+++ b/pppd/pppd.h
@@ -684,7 +684,7 @@ int sif6addr __P((int, eui64_t, eui64_t
@@ -683,7 +683,7 @@ int sif6addr __P((int, eui64_t, eui64_t
int cif6addr __P((int, eui64_t, eui64_t));
/* Remove an IPv6 address from i/f */
#endif
Expand Down Expand Up @@ -292,7 +292,7 @@ Signed-off-by: Jo-Philipp Wich <jo@mein.io>
}
--- a/pppd/sys-solaris.c
+++ b/pppd/sys-solaris.c
@@ -2120,12 +2120,18 @@ cifaddr(u, o, h)
@@ -2119,12 +2119,18 @@ cifaddr(u, o, h)
* sifdefaultroute - assign a default route through the address given.
*/
int
Expand Down
Expand Up @@ -84,7 +84,7 @@ Signed-off-by: Jo-Philipp Wich <jo@mein.io>
}
--- a/pppd/pppd.h
+++ b/pppd/pppd.h
@@ -337,6 +337,8 @@ extern int req_unit; /* interface unit n
@@ -336,6 +336,8 @@ extern int req_unit; /* interface unit n
extern char req_ifname[MAXIFNAMELEN]; /* interface name to use */
extern char path_ipup[MAXPATHLEN]; /* pathname of ip-up script */
extern char path_ipdown[MAXPATHLEN]; /* pathname of ip-down script */
Expand Down
@@ -0,0 +1,56 @@
--- a/pppd/lcp.c
+++ b/pppd/lcp.c
@@ -72,6 +72,7 @@ static void lcp_delayed_up __P((void *))
*/
int lcp_echo_interval = 0; /* Interval between LCP echo-requests */
int lcp_echo_fails = 0; /* Tolerance to unanswered echo-requests */
+bool lcp_echo_adaptive = 0; /* request echo only if the link was idle */
bool lax_recv = 0; /* accept control chars in asyncmap */
bool noendpoint = 0; /* don't send/accept endpoint discriminator */

@@ -150,6 +151,8 @@ static option_t lcp_option_list[] = {
OPT_PRIO },
{ "lcp-echo-interval", o_int, &lcp_echo_interval,
"Set time in seconds between LCP echo requests", OPT_PRIO },
+ { "lcp-echo-adaptive", o_bool, &lcp_echo_adaptive,
+ "Suppress LCP echo requests if traffic was received", 1 },
{ "lcp-restart", o_int, &lcp_fsm[0].timeouttime,
"Set time in seconds between LCP retransmissions", OPT_PRIO },
{ "lcp-max-terminate", o_int, &lcp_fsm[0].maxtermtransmits,
@@ -2330,6 +2333,22 @@ LcpSendEchoRequest (f)
}
}

+ /*
+ * If adaptive echos have been enabled, only send the echo request if
+ * no traffic was received since the last one.
+ */
+ if (lcp_echo_adaptive) {
+ static unsigned int last_pkts_in = 0;
+
+ update_link_stats(f->unit);
+ link_stats_valid = 0;
+
+ if (link_stats.pkts_in != last_pkts_in) {
+ last_pkts_in = link_stats.pkts_in;
+ return;
+ }
+ }
+
/*
* Make and send the echo request frame.
*/
--- a/pppd/pppd.8
+++ b/pppd/pppd.8
@@ -575,6 +575,11 @@ to 1) if the \fIproxyarp\fR option is us
dynamic IP address option (i.e. set /proc/sys/net/ipv4/ip_dynaddr to
1) in demand mode if the local address changes.
.TP
+.B lcp\-echo\-adaptive
+If this option is used with the \fIlcp\-echo\-failure\fR option then
+pppd will send LCP echo\-request frames only if no traffic was received
+from the peer since the last echo\-request was sent.
+.TP
.B lcp\-echo\-failure \fIn
If this option is given, pppd will presume the peer to be dead
if \fIn\fR LCP echo\-requests are sent without receiving a valid LCP
2 changes: 1 addition & 1 deletion package/network/services/ppp/patches/200-makefile.patch
Expand Up @@ -34,7 +34,7 @@ Signed-off-by: Jo-Philipp Wich <jo@mein.io>

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

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

Expand Down
4 changes: 2 additions & 2 deletions package/network/services/ppp/patches/202-no_strip.patch
Expand Up @@ -19,7 +19,7 @@ Signed-off-by: Jo-Philipp Wich <jo@mein.io>
clean:
--- a/pppd/Makefile.linux
+++ b/pppd/Makefile.linux
@@ -108,7 +108,7 @@ ifdef USE_SRP
@@ -107,7 +107,7 @@ ifdef USE_SRP
CFLAGS += -DUSE_SRP -DOPENSSL -I/usr/local/ssl/include
LIBS += -lsrp -L/usr/local/ssl/lib -lcrypto
TARGETS += srp-entry
Expand All @@ -28,7 +28,7 @@ Signed-off-by: Jo-Philipp Wich <jo@mein.io>
MANPAGES += srp-entry.8
EXTRACLEAN += srp-entry.o
NEEDDES=y
@@ -220,7 +220,7 @@ all: $(TARGETS)
@@ -219,7 +219,7 @@ all: $(TARGETS)
install: pppd
mkdir -p $(BINDIR) $(MANDIR)
$(EXTRAINSTALL)
Expand Down
@@ -0,0 +1,94 @@
pppd: Watch out for time warps

On many embedded systems there is no battery backed RTC and a proper system
time only becomes available through NTP after establishing a connection.

When the clock suddenly jumps forward, the internal accounting (connect time)
is confused resulting in unreliable data.

This patch implements periodic clock checking to look for time warps, if one
is detected, the internal counters are adjusted accordingly.

Signed-off-by: Jo-Philipp Wich <jo@mein.io>

--- a/pppd/main.c
+++ b/pppd/main.c
@@ -89,6 +89,7 @@
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
+#include <sys/sysinfo.h>

#include "pppd.h"
#include "magic.h"
@@ -226,6 +227,7 @@ static struct subprocess *children;

/* Prototypes for procedures local to this file. */

+static void check_time(void);
static void setup_signals __P((void));
static void create_pidfile __P((int pid));
static void create_linkpidfile __P((int pid));
@@ -525,6 +527,7 @@ main(argc, argv)
info("Starting link");
}

+ check_time();
gettimeofday(&start_time, NULL);
script_unsetenv("CONNECT_TIME");
script_unsetenv("BYTES_SENT");
@@ -1274,6 +1277,36 @@ struct callout {

static struct callout *callout = NULL; /* Callout list */
static struct timeval timenow; /* Current time */
+static long uptime_diff = 0;
+static int uptime_diff_set = 0;
+
+static void check_time(void)
+{
+ long new_diff;
+ struct timeval t;
+ struct sysinfo i;
+ struct callout *p;
+
+ gettimeofday(&t, NULL);
+ sysinfo(&i);
+ new_diff = t.tv_sec - i.uptime;
+
+ if (!uptime_diff_set) {
+ uptime_diff = new_diff;
+ uptime_diff_set = 1;
+ return;
+ }
+
+ if ((new_diff - 5 > uptime_diff) || (new_diff + 5 < uptime_diff)) {
+ /* system time has changed, update counters and timeouts */
+ info("System time change detected.");
+ start_time.tv_sec += new_diff - uptime_diff;
+
+ for (p = callout; p != NULL; p = p->c_next)
+ p->c_time.tv_sec += new_diff - uptime_diff;
+ }
+ uptime_diff = new_diff;
+}

/*
* timeout - Schedule a timeout.
@@ -1344,6 +1377,8 @@ calltimeout()
{
struct callout *p;

+ check_time();
+
while (callout != NULL) {
p = callout;

@@ -1371,6 +1406,8 @@ timeleft(tvp)
{
if (callout == NULL)
return NULL;
+
+ check_time();

gettimeofday(&timenow, NULL);
tvp->tv_sec = callout->c_time.tv_sec - timenow.tv_sec;
Expand Up @@ -12,7 +12,7 @@ Signed-off-by: Jo-Philipp Wich <jo@mein.io>

--- a/pppd/main.c
+++ b/pppd/main.c
@@ -1052,7 +1052,8 @@ get_input()
@@ -1055,7 +1055,8 @@ get_input()
}
notice("Modem hangup");
hungup = 1;
Expand Down
Expand Up @@ -7,7 +7,7 @@ Signed-off-by: Jo-Philipp Wich <jo@mein.io>

--- a/pppd/Makefile.linux
+++ b/pppd/Makefile.linux
@@ -190,8 +190,8 @@ endif
@@ -189,8 +189,8 @@ endif

ifdef FILTER
ifneq ($(wildcard /usr/include/pcap-bpf.h),)
Expand Down
Expand Up @@ -23,7 +23,7 @@ Signed-off-by: Jo-Philipp Wich <jo@mein.io>
# Uncomment the next line to enable multilink PPP (enabled by default)
# Linux distributions: Please leave multilink ENABLED in your builds
# of pppd!
@@ -195,6 +198,14 @@ CFLAGS += -DPPP_FILTER -I$(STAGING_DIR)
@@ -194,6 +197,14 @@ CFLAGS += -DPPP_FILTER -I$(STAGING_DIR)
endif
endif

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

Expand Down
Expand Up @@ -7,7 +7,7 @@ Signed-off-by: Jo-Philipp Wich <jo@mein.io>

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

0 comments on commit 37c63e9

Please sign in to comment.