]> git.ozlabs.org Git - ppp.git/blobdiff - pppd/plugins/rp-pppoe/pppoe-discovery.c
pppoe-discovery: add options to tune discovery timeout and attempts
[ppp.git] / pppd / plugins / rp-pppoe / pppoe-discovery.c
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"