From a378c558d64867008f4344490e3df4706e965fa7 Mon Sep 17 00:00:00 2001 From: Alistair Strachan Date: Tue, 28 May 2019 17:18:36 -0700 Subject: Try OPNS/OLAC before PPTP/L2TP When the PPTP/L2TP path was introduced, support for the features was determined simply by opening a socket with the appropriate upstream socket protocol types. However, it was later found that older kernels had bugs in their PPTP implementation which silently broke Android's use of the ppp tunnel, and must not be used. Unfortunately, some devices ship with CONFIG_PPTP or CONFIG_L2TP enabled *in addition* to the CONFIG_PPPOPNS or CONFIG_PPPOLAC Android extensions, but lacked the upstream fixes to PPTP/L2TP. This meant that mtpd would prefer the broken PPTP/L2TP features over the working OPNS/OLAC features. On newer kernels, which do not have broken PPTP/L2TP implementations, we have explicitly removed the Android OPNS/OLAC changes. This means even if we "prefer" the deprecated method, it will never be used, and PPTP/L2TP will always be used instead, which is what we want. This change maximizes compatibility with older broken kernels without sacrificing use of the modern path on kernels without the bugs. Bug: 116424816 Change-Id: Ic64426c76135b717a1da7013bc03501c03d19a6b Merged-In: Ic64426c76135b717a1da7013bc03501c03d19a6b (cherry picked from commit 1b5fc73ae98d5e3b7d2c1f10d9dcbc2749355d3e) --- l2tp.c | 11 ++++++----- pptp.c | 11 ++++++----- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/l2tp.c b/l2tp.c index 1d6171e..ae6088d 100644 --- a/l2tp.c +++ b/l2tp.c @@ -354,19 +354,20 @@ static int l2tp_connect(char **arguments) } /** - * Check if upstream kernel implementation is enabled. + * Check if upstream kernel implementation of L2TP should be used. * - * @return true if upstream L2TP is enabled in kernel and false otherwise + * @return true If upstream L2TP should be used, which is the case if + * the obsolete OLAC feature is not available. */ static bool check_ol2tp(void) { - int fd = socket(AF_PPPOX, SOCK_DGRAM, PX_PROTO_OL2TP); + int fd = socket(AF_PPPOX, SOCK_DGRAM, PX_PROTO_OLAC); if (fd < 0) { - return false; + return true; } else { close(fd); - return true; + return false; } } diff --git a/pptp.c b/pptp.c index 80eb24a..7a58a27 100644 --- a/pptp.c +++ b/pptp.c @@ -237,19 +237,20 @@ static int pptp_connect(char **arguments) } /** - * Check if upstream kernel implementation is enabled. + * Check if upstream kernel implementation of PPTP should be used. * - * @return true if upstream PPTP is enabled in kernel and false otherwise + * @return true If upstream PPTP should be used, which is the case if + * the obsolete OPNS feature is not available. */ static bool check_pptp(void) { - int fd = socket(AF_PPPOX, SOCK_DGRAM, PX_PROTO_PPTP); + int fd = socket(AF_PPPOX, SOCK_DGRAM, PX_PROTO_OPNS); if (fd < 0) { - return false; + return true; } else { close(fd); - return true; + return false; } } -- cgit v1.2.3