ppp: support adaptive LCP echos

Port Debians adaptive LCP echo patch to pppd, make it configurable with UCI
and enable it by default.

When adaptive LCP echo is enabled, LCP echo requests are only sent if the
link is idle, this avoids the common situation where a congested PPP link
(e.g. during torrenting) is falsely detected as disconnected because the
LCP replies are not received in time.

Also bump the copyright year in the Makefile, remove a redundant maintainer
entry and fix the shell processing of the keepalive option when the two-
value syntax is used.

Signed-off-by: Jo-Philipp Wich <jow@openwrt.org>

SVN-Revision: 43143
This commit is contained in:
Jo-Philipp Wich 2014-11-01 12:37:03 +00:00
parent e30531cd67
commit bc356cef82
4 changed files with 68 additions and 9 deletions

View File

@ -1,5 +1,5 @@
#
# Copyright (C) 2006-2012 OpenWrt.org
# Copyright (C) 2006-2014 OpenWrt.org
#
# This is free software, licensed under the GNU General Public License v2.
# See /LICENSE for more information.
@ -10,7 +10,7 @@ include $(INCLUDE_DIR)/kernel.mk
PKG_NAME:=ppp
PKG_VERSION:=2.4.7
PKG_RELEASE:=3
PKG_RELEASE:=4
PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz
PKG_SOURCE_URL:=ftp://ftp.samba.org/pub/ppp/
@ -29,7 +29,6 @@ include $(INCLUDE_DIR)/package.mk
define Package/ppp/Default
SECTION:=net
CATEGORY:=Network
MAINTAINER:=Jo-Philipp Wich <xm@subsignal.org>
URL:=http://ppp.samba.org/
endef

View File

@ -12,6 +12,7 @@ ppp_generic_init_config() {
proto_config_add_string username
proto_config_add_string password
proto_config_add_string keepalive
proto_config_add_boolean keepalive_adaptive
proto_config_add_int demand
proto_config_add_string pppd_options
proto_config_add_string 'connect:file'
@ -25,7 +26,7 @@ ppp_generic_init_config() {
ppp_generic_setup() {
local config="$1"; shift
json_get_vars ipv6 demand keepalive username password pppd_options pppname
json_get_vars ipv6 demand keepalive keepalive_adaptive username password pppd_options pppname
if [ "$ipv6" = 0 ]; then
ipv6=""
elif [ -z "$ipv6" -o "$ipv6" = auto ]; then
@ -38,19 +39,22 @@ ppp_generic_setup() {
else
demand="persist"
fi
[ "${keepalive:-0}" -lt 1 ] && keepalive=""
[ -n "$mtu" ] || json_get_var mtu mtu
[ -n "$pppname" ] || pppname="${proto:-ppp}-$config"
local interval="${keepalive##*[, ]}"
[ "$interval" != "$keepalive" ] || interval=5
local lcp_failure="${keepalive%%[, ]*}"
local lcp_interval="${keepalive##*[, ]}"
local lcp_adaptive="lcp-echo-adaptive"
[ "${lcp_failure:-0}" -lt 1 ] && lcp_failure=""
[ "$lcp_interval" != "$keepalive" ] || lcp_interval=5
[ "${keepalive_adaptive:-1}" -lt 1 ] && lcp_adaptive=""
[ -n "$connect" ] || json_get_var connect connect
[ -n "$disconnect" ] || json_get_var disconnect disconnect
proto_run_command "$config" /usr/sbin/pppd \
nodetach ipparam "$config" \
ifname "$pppname" \
${keepalive:+lcp-echo-interval $interval lcp-echo-failure ${keepalive%%[, ]*}} \
${lcp_failure:+lcp-echo-interval $lcp_interval lcp-echo-failure $lcp_failure $lcp_adaptive} \
${ipv6:++ipv6} \
nodefaultroute \
usepeerdns \

View File

@ -0,0 +1,56 @@
--- a/pppd/lcp.c
+++ b/pppd/lcp.c
@@ -73,6 +73,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 */
@@ -151,6 +152,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,
@@ -2331,6 +2334,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
@@ -563,6 +563,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

View File

@ -8,7 +8,7 @@ Signed-off-by: Jo-Philipp Wich <jow@openwrt.org>
--- a/pppd/lcp.c
+++ b/pppd/lcp.c
@@ -1914,12 +1914,12 @@ lcp_up(f)
@@ -1917,12 +1917,12 @@ lcp_up(f)
* the interface MTU is set to the lowest of that, the
* MTU we want to use, and our link MRU.
*/