]> git.ozlabs.org Git - ppp.git/commitdiff
pppoe-discovery: add options to tune discovery timeout and attempts
authorMartin Schiller <ms@dev.tdt.de>
Thu, 7 Dec 2017 08:30:40 +0000 (09:30 +0100)
committerMartin Schiller <ms@dev.tdt.de>
Mon, 11 Dec 2017 12:51:39 +0000 (13:51 +0100)
Signed-off-by: Martin Schiller <ms@dev.tdt.de>
pppd/plugins/rp-pppoe/pppoe-discovery.c
pppd/plugins/rp-pppoe/pppoe.h

index 7f3659ef7ea1cb4df882a91ad45536c5f16488e6..bce71fce04f459b02053cba4c4d95b10a0206f4b 100644 (file)
@@ -635,14 +635,14 @@ void
 discovery(PPPoEConnection *conn)
 {
     int padiAttempts = 0;
-    int timeout = PADI_TIMEOUT;
+    int timeout = conn->discoveryTimeout;
 
     conn->discoverySocket =
        openInterface(conn->ifName, Eth_PPPOE_Discovery, conn->myEth);
 
     do {
        padiAttempts++;
-       if (padiAttempts > MAX_PADI_ATTEMPTS) {
+       if (padiAttempts > conn->discoveryAttempts) {
            fprintf(stderr, "Timeout waiting for PADO packets\n");
            close(conn->discoverySocket);
            conn->discoverySocket = -1;
@@ -666,8 +666,10 @@ int main(int argc, char *argv[])
     memset(conn, 0, sizeof(PPPoEConnection));
 
     conn->printACNames = 1;
+    conn->discoveryTimeout = PADI_TIMEOUT;
+    conn->discoveryAttempts = MAX_PADI_ATTEMPTS;
 
-    while ((opt = getopt(argc, argv, "I:D:VUQS:C:h")) > 0) {
+    while ((opt = getopt(argc, argv, "I:D:VUQS:C:t:a:h")) > 0) {
        switch(opt) {
        case 'S':
            conn->serviceName = xstrdup(optarg);
@@ -675,6 +677,24 @@ int main(int argc, char *argv[])
        case 'C':
            conn->acName = xstrdup(optarg);
            break;
+       case 't':
+           if (sscanf(optarg, "%d", &conn->discoveryTimeout) != 1) {
+               fprintf(stderr, "Illegal argument to -t: Should be -t timeout\n");
+               exit(EXIT_FAILURE);
+           }
+           if (conn->discoveryTimeout < 1) {
+               conn->discoveryTimeout = 1;
+           }
+           break;
+       case 'a':
+           if (sscanf(optarg, "%d", &conn->discoveryAttempts) != 1) {
+               fprintf(stderr, "Illegal argument to -a: Should be -a attempts\n");
+               exit(EXIT_FAILURE);
+           }
+           if (conn->discoveryAttempts < 1) {
+               conn->discoveryAttempts = 1;
+           }
+           break;
        case 'U':
            conn->useHostUniq = 1;
            break;
@@ -750,6 +770,8 @@ void usage(void)
     fprintf(stderr, "   -I if_name     -- Specify interface (default eth0)\n");
     fprintf(stderr, "   -D filename    -- Log debugging information in filename.\n");
     fprintf(stderr,
+           "   -t timeout     -- Initial timeout for discovery packets in seconds\n"
+           "   -a attempts    -- Number of discovery attempts\n"
            "   -V             -- Print version and exit.\n"
            "   -Q             -- Quit Mode: Do not print access concentrator names\n"
            "   -S name        -- Set desired service name.\n"
index c4aaa6e68856e8506643a6c30c86177070af1fd7..813dcf368cf3369ff48a94db10b5e5b028716175 100644 (file)
@@ -245,6 +245,7 @@ typedef struct PPPoEConnectionStruct {
     int error;                 /* Error packet received */
     int debug;                 /* Set to log packets sent and received */
     int discoveryTimeout;       /* Timeout for discovery packets */
+    int discoveryAttempts;      /* Number of discovery attempts */
     int seenMaxPayload;
     int mtu;                   /* Stored MTU */
     int mru;                   /* Stored MRU */