]> git.ozlabs.org Git - ppp.git/blobdiff - pppd/plugins/pppoe/discovery.c
config: Include some extra files in the tarball
[ppp.git] / pppd / plugins / pppoe / discovery.c
index b32b0c891dcd89c5fb46ebe402adc698f9a0611f..86bda611b2d11022213777c8c69ed847b297ca88 100644 (file)
@@ -8,18 +8,15 @@
 *
 ***********************************************************************/
 
-static char const RCSID[] =
-"$Id: discovery.c,v 1.6 2008/06/15 04:35:50 paulus Exp $";
-
 #ifdef HAVE_CONFIG_H
-#include <config.h>
+#include "config.h"
 #endif
 
 #define _GNU_SOURCE 1
 #include "pppoe.h"
-#include "pppd/pppd.h"
-#include "pppd/fsm.h"
-#include "pppd/lcp.h"
+#include <pppd/pppd.h>
+#include <pppd/fsm.h>
+#include <pppd/lcp.h>
 
 #include <string.h>
 #include <stdlib.h>
@@ -44,6 +41,15 @@ static char const RCSID[] =
 
 #include <signal.h>
 
+#ifdef PLUGIN
+#define signaled(x) ppp_signaled(x)
+#define get_time(x) ppp_get_time(x)
+#else
+int signaled(int signal);
+int get_time(struct timeval *tv);
+
+#endif
+
 /* Calculate time remaining until *exp, return 0 if now >= *exp */
 static int time_left(struct timeval *diff, struct timeval *exp)
 {
@@ -149,6 +155,10 @@ parsePADOTags(UINT16_t type, UINT16_t len, unsigned char *data,
            !strncmp((char *) data, conn->acName, len)) {
            pc->acNameOK = 1;
        }
+       /* save a copy of the AC name if we can */
+       conn->actualACname = realloc(conn->actualACname, len + 1);
+       if (conn->actualACname)
+           strlcpy(conn->actualACname, (char *) data, len + 1);
        break;
     case TAG_SERVICE_NAME:
        pc->seenServiceName = 1;
@@ -370,7 +380,7 @@ sendPADI(PPPoEConnection *conn)
 * Waits for a PADO packet and copies useful information
 ***********************************************************************/
 void
-waitForPADO(PPPoEConnection *conn, int timeout)
+waitForPADO(PPPoEConnection *conn, int timeout, int waitWholeTimeoutForPADO)
 {
     fd_set readable;
     int r;
@@ -404,7 +414,7 @@ waitForPADO(PPPoEConnection *conn, int timeout)
 
            while(1) {
                r = select(conn->discoverySocket+1, &readable, NULL, NULL, &tv);
-               if (r >= 0 || errno != EINTR || got_sigterm) break;
+               if (r >= 0 || errno != EINTR || signaled(SIGTERM)) break;
            }
            if (r < 0) {
                error("select (waitForPADO): %m");
@@ -471,7 +481,7 @@ waitForPADO(PPPoEConnection *conn, int timeout)
                conn->discoveryState = STATE_RECEIVED_PADO;
            }
        }
-    } while (pppoe_verbose >= 1 || conn->discoveryState != STATE_RECEIVED_PADO);
+    } while (waitWholeTimeoutForPADO || conn->discoveryState != STATE_RECEIVED_PADO);
 }
 
 /***********************************************************************
@@ -595,7 +605,7 @@ waitForPADS(PPPoEConnection *conn, int timeout)
 
            while(1) {
                r = select(conn->discoverySocket+1, &readable, NULL, NULL, &tv);
-               if (r >= 0 || errno != EINTR || got_sigterm) break;
+               if (r >= 0 || errno != EINTR || signaled(SIGTERM)) break;
            }
            if (r < 0) {
                error("select (waitForPADS): %m");
@@ -659,14 +669,14 @@ waitForPADS(PPPoEConnection *conn, int timeout)
 * Performs the PPPoE discovery phase 1
 ***********************************************************************/
 void
-discovery1(PPPoEConnection *conn)
+discovery1(PPPoEConnection *conn, int waitWholeTimeoutForPADO)
 {
     int padiAttempts = 0;
     int timeout = conn->discoveryTimeout;
 
     do {
        padiAttempts++;
-       if (got_sigterm || padiAttempts > conn->discoveryAttempts) {
+       if (signaled(SIGTERM) || padiAttempts > conn->discoveryAttempts) {
            warn("Timeout waiting for PADO packets");
            close(conn->discoverySocket);
            conn->discoverySocket = -1;
@@ -674,7 +684,7 @@ discovery1(PPPoEConnection *conn)
        }
        sendPADI(conn);
        conn->discoveryState = STATE_SENT_PADI;
-       waitForPADO(conn, timeout);
+       waitForPADO(conn, timeout, waitWholeTimeoutForPADO);
 
        timeout *= 2;
     } while (conn->discoveryState == STATE_SENT_PADI);
@@ -697,7 +707,7 @@ discovery2(PPPoEConnection *conn)
 
     do {
        padrAttempts++;
-       if (got_sigterm || padrAttempts > conn->discoveryAttempts) {
+       if (signaled(SIGTERM) || padrAttempts > conn->discoveryAttempts) {
            warn("Timeout waiting for PADS packets");
            close(conn->discoverySocket);
            conn->discoverySocket = -1;