X-Git-Url: http://git.ozlabs.org/?p=ppp.git;a=blobdiff_plain;f=pppd%2Fplugins%2Frp-pppoe%2Fpppoe-discovery.c;h=7f3659ef7ea1cb4df882a91ad45536c5f16488e6;hp=318f8583f98b246d99482330e7e33e3429c3f416;hb=8e62a6d886edeecc52391db3216c026db6c0e7d9;hpb=427e3d851c86e35655e14f1dfa9c831a8fab94d9 diff --git a/pppd/plugins/rp-pppoe/pppoe-discovery.c b/pppd/plugins/rp-pppoe/pppoe-discovery.c index 318f858..7f3659e 100644 --- a/pppd/plugins/rp-pppoe/pppoe-discovery.c +++ b/pppd/plugins/rp-pppoe/pppoe-discovery.c @@ -9,6 +9,7 @@ * */ +#include #include #include #include @@ -55,6 +56,14 @@ void die(int status) exit(status); } +void error(char *fmt, ...) +{ + va_list pvar; + va_start(pvar, fmt); + vfprintf(stderr, fmt, pvar); + va_end(pvar); +} + /* Initialize frame types to RFC 2516 values. Some broken peers apparently use different frame types... sigh... */ @@ -277,7 +286,7 @@ parsePacket(PPPoEPacket *packet, ParseFunc *func, void *extra) } /* Do some sanity checks on packet */ - if (len > ETH_DATA_LEN - 6) { /* 6-byte overhead for PPPoE header */ + if (len > ETH_JUMBO_LEN - PPPOE_OVERHEAD) { /* 6-byte overhead for PPPoE header */ fprintf(stderr, "Invalid PPPoE packet length (%u)\n", len); return -1; } @@ -378,7 +387,9 @@ parsePADOTags(UINT16_t type, UINT16_t len, unsigned char *data, switch(type) { case TAG_AC_NAME: pc->seenACName = 1; - printf("Access-Concentrator: %.*s\n", (int) len, data); + if (conn->printACNames) { + printf("Access-Concentrator: %.*s\n", (int) len, data); + } if (conn->acName && len == strlen(conn->acName) && !strncmp((char *) data, conn->acName, len)) { pc->acNameOK = 1; @@ -386,7 +397,7 @@ parsePADOTags(UINT16_t type, UINT16_t len, unsigned char *data, break; case TAG_SERVICE_NAME: pc->seenServiceName = 1; - if (len > 0) { + if (conn->printACNames && len > 0) { printf(" Service-Name: %.*s\n", (int) len, data); } if (conn->serviceName && len == strlen(conn->serviceName) && @@ -395,37 +406,47 @@ parsePADOTags(UINT16_t type, UINT16_t len, unsigned char *data, } break; case TAG_AC_COOKIE: - printf("Got a cookie:"); - /* Print first 20 bytes of cookie */ - for (i=0; iprintACNames) { + printf("Got a cookie:"); + /* Print first 20 bytes of cookie */ + for (i=0; icookie.type = htons(type); conn->cookie.length = htons(len); memcpy(conn->cookie.payload, data, len); break; case TAG_RELAY_SESSION_ID: - printf("Got a Relay-ID:"); - /* Print first 20 bytes of relay ID */ - for (i=0; iprintACNames) { + printf("Got a Relay-ID:"); + /* Print first 20 bytes of relay ID */ + for (i=0; irelayId.type = htons(type); conn->relayId.length = htons(len); memcpy(conn->relayId.payload, data, len); break; case TAG_SERVICE_NAME_ERROR: - printf("Got a Service-Name-Error tag: %.*s\n", (int) len, data); + if (conn->printACNames) { + printf("Got a Service-Name-Error tag: %.*s\n", (int) len, data); + } break; case TAG_AC_SYSTEM_ERROR: - printf("Got a System-Error tag: %.*s\n", (int) len, data); + if (conn->printACNames) { + printf("Got a System-Error tag: %.*s\n", (int) len, data); + } break; case TAG_GENERIC_ERROR: - printf("Got a Generic-Error tag: %.*s\n", (int) len, data); + if (conn->printACNames) { + printf("Got a Generic-Error tag: %.*s\n", (int) len, data); + } break; } } @@ -581,7 +602,6 @@ waitForPADO(PPPoEConnection *conn, int timeout) continue; } conn->numPADOs++; - printf("--------------------------------------------------\n"); if (pc.acNameOK && pc.serviceNameOK) { memcpy(conn->peerEth, packet.ethHdr.h_source, ETH_ALEN); if (conn->printACNames) { @@ -592,6 +612,7 @@ waitForPADO(PPPoEConnection *conn, int timeout) (unsigned) conn->peerEth[3], (unsigned) conn->peerEth[4], (unsigned) conn->peerEth[5]); + printf("--------------------------------------------------\n"); continue; } conn->discoveryState = STATE_RECEIVED_PADO; @@ -644,7 +665,9 @@ int main(int argc, char *argv[]) memset(conn, 0, sizeof(PPPoEConnection)); - while ((opt = getopt(argc, argv, "I:D:VUAS:C:h")) > 0) { + conn->printACNames = 1; + + while ((opt = getopt(argc, argv, "I:D:VUQS:C:h")) > 0) { switch(opt) { case 'S': conn->serviceName = xstrdup(optarg); @@ -667,8 +690,8 @@ int main(int argc, char *argv[]) case 'I': conn->ifName = xstrdup(optarg); break; - case 'A': - /* this is the default */ + case 'Q': + conn->printACNames = 0; break; case 'V': case 'h': @@ -686,10 +709,13 @@ int main(int argc, char *argv[]) conn->discoverySocket = -1; conn->sessionSocket = -1; - conn->printACNames = 1; discovery(conn); - exit(0); + + if (!conn->numPADOs) + exit(1); + else + exit(0); } void rp_fatal(char const *str) @@ -720,5 +746,15 @@ char *xstrdup(const char *s) void usage(void) { fprintf(stderr, "Usage: pppoe-discovery [options]\n"); + fprintf(stderr, "Options:\n"); + fprintf(stderr, " -I if_name -- Specify interface (default eth0)\n"); + fprintf(stderr, " -D filename -- Log debugging information in filename.\n"); + fprintf(stderr, + " -V -- Print version and exit.\n" + " -Q -- Quit Mode: Do not print access concentrator names\n" + " -S name -- Set desired service name.\n" + " -C name -- Set desired access concentrator name.\n" + " -U -- Use Host-Unique to allow multiple PPPoE sessions.\n" + " -h -- Print usage information.\n"); fprintf(stderr, "\nVersion " RP_VERSION "\n"); }