Skip to content

Commit

Permalink
Merge pull request #492 from ppp-project/pppoe
Browse files Browse the repository at this point in the history
PPPoE fixes and improvements
  • Loading branch information
paulusmack committed May 18, 2024
2 parents cc12c3d + c8d842b commit 04e6b8d
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 9 deletions.
12 changes: 8 additions & 4 deletions pppd/plugins/pppoe/discovery.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}

/***********************************************************************
Expand Down Expand Up @@ -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;
Expand All @@ -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);
Expand Down
11 changes: 8 additions & 3 deletions pppd/plugins/pppoe/plugin.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -317,6 +317,8 @@ PPPOEDisconnectDevice(void)
sendPADT(conn, NULL);
close(conn->discoverySocket);
}
free(conn->actualACname);
conn->actualACname = NULL;
}

static void
Expand Down Expand Up @@ -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 = {
Expand Down
2 changes: 1 addition & 1 deletion pppd/plugins/pppoe/pppoe-discovery.c
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ int main(int argc, char *argv[])
exit(1);
}

discovery1(conn);
discovery1(conn, 1);

if (!conn->numPADOs)
exit(1);
Expand Down
3 changes: 2 additions & 1 deletion pppd/plugins/pppoe/pppoe.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down Expand Up @@ -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);
Expand Down
5 changes: 5 additions & 0 deletions pppd/pppd.8
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 04e6b8d

Please sign in to comment.