From: Pali Rohár Date: Fri, 1 Jan 2021 15:28:22 +0000 (+0100) Subject: pppoe: Split function discovery() into phases discovery1() and discovery2() X-Git-Tag: ppp-2.5.0~50^2~7 X-Git-Url: https://git.ozlabs.org/?p=ppp.git;a=commitdiff_plain;h=a37b5cf877d2fe21370958d5a44e61c621c1adb7 pppoe: Split function discovery() into phases discovery1() and discovery2() pppoe-discovery.c needs to call only the first phase of discovery. Signed-off-by: Pali Rohár --- 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);