diff --git a/pppd/plugins/pppoe/discovery.c b/pppd/plugins/pppoe/discovery.c index ccb88b2d..c1df4ffa 100644 --- a/pppd/plugins/pppoe/discovery.c +++ b/pppd/plugins/pppoe/discovery.c @@ -158,6 +158,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; @@ -379,7 +383,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; @@ -480,7 +484,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); } /*********************************************************************** @@ -668,7 +672,7 @@ 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; @@ -683,7 +687,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); diff --git a/pppd/plugins/pppoe/plugin.c b/pppd/plugins/pppoe/plugin.c index 7d4709ec..00e68d54 100644 --- a/pppd/plugins/pppoe/plugin.c +++ b/pppd/plugins/pppoe/plugin.c @@ -128,8 +128,6 @@ PPPOEInitDevice(void) conn->ifName = devnam; conn->discoverySocket = -1; conn->sessionSocket = -1; - conn->discoveryTimeout = pppoe_padi_timeout; - conn->discoveryAttempts = pppoe_padi_attempts; return 1; } @@ -217,7 +215,7 @@ PPPOEConnectDevice(void) error("Failed to create PPPoE discovery socket: %m"); goto errout; } - discovery1(conn); + discovery1(conn, 0); /* discovery1() may update conn->mtu and conn->mru */ lcp_allowoptions[0].mru = conn->mtu; lcp_wantoptions[0].mru = conn->mru; @@ -256,6 +254,8 @@ PPPOEConnectDevice(void) ppp_set_remote_number(remote_number); ppp_script_setenv("MACREMOTE", remote_number, 0); + if (conn->actualACname) + ppp_script_setenv("ACNAME", conn->actualACname, 0); if (connect(conn->sessionSocket, (struct sockaddr *) &sp, sizeof(struct sockaddr_pppox)) < 0) { @@ -317,6 +317,8 @@ PPPOEDisconnectDevice(void) sendPADT(conn, NULL); close(conn->discoverySocket); } + free(conn->actualACname); + conn->actualACname = NULL; } static void @@ -471,6 +473,9 @@ void pppoe_check_options(void) ccp_allowoptions[0].bsd_compress = 0; ccp_wantoptions[0].bsd_compress = 0; + + conn->discoveryTimeout = pppoe_padi_timeout; + conn->discoveryAttempts = pppoe_padi_attempts; } struct channel pppoe_channel = { diff --git a/pppd/plugins/pppoe/pppoe-discovery.c b/pppd/plugins/pppoe/pppoe-discovery.c index 5b1b2dc0..79ad805c 100644 --- a/pppd/plugins/pppoe/pppoe-discovery.c +++ b/pppd/plugins/pppoe/pppoe-discovery.c @@ -258,7 +258,7 @@ int main(int argc, char *argv[]) exit(1); } - discovery1(conn); + discovery1(conn, 1); if (!conn->numPADOs) exit(1); diff --git a/pppd/plugins/pppoe/pppoe.h b/pppd/plugins/pppoe/pppoe.h index 9360eddf..2eb97bd1 100644 --- a/pppd/plugins/pppoe/pppoe.h +++ b/pppd/plugins/pppoe/pppoe.h @@ -242,6 +242,7 @@ typedef struct PPPoEConnectionStruct { int storedmru; /* Stored MRU */ int mtu; int mru; + char *actualACname; /* Name of AC we connected to */ } PPPoEConnection; /* Structure used to determine acceptable PADO or PADS packet */ @@ -272,7 +273,7 @@ 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 discovery1(PPPoEConnection *conn); +void discovery1(PPPoEConnection *conn, int waitWholeTimeoutForPADO); void discovery2(PPPoEConnection *conn); unsigned char *findTag(PPPoEPacket *packet, UINT16_t tagType, PPPoETag *tag); diff --git a/pppd/pppd.8 b/pppd/pppd.8 index 37650418..317549b2 100644 --- a/pppd/pppd.8 +++ b/pppd/pppd.8 @@ -1823,6 +1823,11 @@ first WINS server address supplied. .B WINS2 If the peer supplies WINS server addresses, this variable is set to the second WINS server address supplied. +.TP +.B ACNAME +If the pppoe plugin is used to establish a connection to an access +concentrator (AC), this variable is set to the name of the AC, as +supplied by the AC. .P .P Pppd invokes the following scripts, if they exist. It is not an error