From a37b5cf877d2fe21370958d5a44e61c621c1adb7 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Pali=20Roh=C3=A1r?= Date: Fri, 1 Jan 2021 16:28:22 +0100 Subject: [PATCH] pppoe: Split function discovery() into phases discovery1() and discovery2() MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit pppoe-discovery.c needs to call only the first phase of discovery. Signed-off-by: Pali Rohár --- pppd/plugins/pppoe/discovery.c | 24 +++++++++++++++++++----- pppd/plugins/pppoe/plugin.c | 9 +++++++-- pppd/plugins/pppoe/pppoe.h | 3 ++- 3 files changed, 28 insertions(+), 8 deletions(-) diff --git a/pppd/plugins/pppoe/discovery.c b/pppd/plugins/pppoe/discovery.c index 5569f3e..1c55b36 100644 --- a/pppd/plugins/pppoe/discovery.c +++ b/pppd/plugins/pppoe/discovery.c @@ -605,19 +605,18 @@ waitForPADS(PPPoEConnection *conn, int timeout) } /********************************************************************** -*%FUNCTION: discovery +*%FUNCTION: discovery1 *%ARGUMENTS: * conn -- PPPoE connection info structure *%RETURNS: * Nothing *%DESCRIPTION: -* Performs the PPPoE discovery phase +* Performs the PPPoE discovery phase 1 ***********************************************************************/ void -discovery(PPPoEConnection *conn) +discovery1(PPPoEConnection *conn) { int padiAttempts = 0; - int padrAttempts = 0; int timeout = conn->discoveryTimeout; do { @@ -634,8 +633,23 @@ discovery(PPPoEConnection *conn) timeout *= 2; } while (conn->discoveryState == STATE_SENT_PADI); +} + +/********************************************************************** +*%FUNCTION: discovery2 +*%ARGUMENTS: +* conn -- PPPoE connection info structure +*%RETURNS: +* Nothing +*%DESCRIPTION: +* Performs the PPPoE discovery phase 2 +***********************************************************************/ +void +discovery2(PPPoEConnection *conn) +{ + int padrAttempts = 0; + int timeout = conn->discoveryTimeout; - timeout = conn->discoveryTimeout; do { padrAttempts++; if (got_sigterm || padrAttempts > conn->discoveryAttempts) { diff --git a/pppd/plugins/pppoe/plugin.c b/pppd/plugins/pppoe/plugin.c index d7c5be1..5732460 100644 --- a/pppd/plugins/pppoe/plugin.c +++ b/pppd/plugins/pppoe/plugin.c @@ -216,9 +216,14 @@ PPPOEConnectDevice(void) error("Failed to create PPPoE discovery socket: %m"); goto errout; } - discovery(conn); + discovery1(conn); + if (conn->discoveryState != STATE_RECEIVED_PADO) { + error("Unable to complete PPPoE Discovery phase 1"); + goto errout; + } + discovery2(conn); if (conn->discoveryState != STATE_SESSION) { - error("Unable to complete PPPoE Discovery"); + error("Unable to complete PPPoE Discovery phase 2"); goto errout; } } diff --git a/pppd/plugins/pppoe/pppoe.h b/pppd/plugins/pppoe/pppoe.h index 82ae01d..a72454e 100644 --- a/pppd/plugins/pppoe/pppoe.h +++ b/pppd/plugins/pppoe/pppoe.h @@ -277,7 +277,8 @@ void initPPP(void); void clampMSS(PPPoEPacket *packet, char const *dir, int clampMss); UINT16_t computeTCPChecksum(unsigned char *ipHdr, unsigned char *tcpHdr); UINT16_t pppFCS16(UINT16_t fcs, unsigned char *cp, int len); -void discovery(PPPoEConnection *conn); +void discovery1(PPPoEConnection *conn); +void discovery2(PPPoEConnection *conn); unsigned char *findTag(PPPoEPacket *packet, UINT16_t tagType, PPPoETag *tag); -- 2.39.2