summaryrefslogtreecommitdiff
path: root/pppd
diff options
context:
space:
mode:
authorPali Rohár <pali@kernel.org>2021-01-01 16:30:19 +0100
committerPali Rohár <pali@kernel.org>2021-01-05 00:43:56 +0100
commitaf622602ca55d368c03b0ea912479dc84ad543c0 (patch)
treee9211250f1edd689f746c936ba191854a8040c5c /pppd
parenta37b5cf877d2fe21370958d5a44e61c621c1adb7 (diff)
downloadppp-af622602ca55d368c03b0ea912479dc84ad543c0.tar.gz
pppoe: Do not use lcp_allowoptions[] and lcp_wantoptions[] in discovery.c code
Signed-off-by: Pali Rohár <pali@kernel.org>
Diffstat (limited to 'pppd')
-rw-r--r--pppd/plugins/pppoe/discovery.c32
-rw-r--r--pppd/plugins/pppoe/plugin.c18
-rw-r--r--pppd/plugins/pppoe/pppoe.h6
3 files changed, 32 insertions, 24 deletions
diff --git a/pppd/plugins/pppoe/discovery.c b/pppd/plugins/pppoe/discovery.c
index 1c55b36..1d3d12b 100644
--- a/pppd/plugins/pppoe/discovery.c
+++ b/pppd/plugins/pppoe/discovery.c
@@ -168,10 +168,10 @@ parsePADOTags(UINT16_t type, UINT16_t len, unsigned char *data,
memcpy(&mru, data, sizeof(mru));
mru = ntohs(mru);
if (mru >= ETH_PPPOE_MTU) {
- if (lcp_allowoptions[0].mru > mru)
- lcp_allowoptions[0].mru = mru;
- if (lcp_wantoptions[0].mru > mru)
- lcp_wantoptions[0].mru = mru;
+ if (conn->mtu > mru)
+ conn->mtu = mru;
+ if (conn->mru > mru)
+ conn->mru = mru;
conn->seenMaxPayload = 1;
}
}
@@ -218,10 +218,10 @@ parsePADSTags(UINT16_t type, UINT16_t len, unsigned char *data,
memcpy(&mru, data, sizeof(mru));
mru = ntohs(mru);
if (mru >= ETH_PPPOE_MTU) {
- if (lcp_allowoptions[0].mru > mru)
- lcp_allowoptions[0].mru = mru;
- if (lcp_wantoptions[0].mru > mru)
- lcp_wantoptions[0].mru = mru;
+ if (conn->mtu > mru)
+ conn->mtu = mru;
+ if (conn->mru > mru)
+ conn->mru = mru;
conn->seenMaxPayload = 1;
}
}
@@ -306,9 +306,9 @@ sendPADI(PPPoEConnection *conn)
}
/* Add our maximum MTU/MRU */
- if (MIN(lcp_allowoptions[0].mru, lcp_wantoptions[0].mru) > ETH_PPPOE_MTU) {
+ if (MIN(conn->mtu, conn->mru) > ETH_PPPOE_MTU) {
PPPoETag maxPayload;
- UINT16_t mru = htons(MIN(lcp_allowoptions[0].mru, lcp_wantoptions[0].mru));
+ UINT16_t mru = htons(MIN(conn->mtu, conn->mru));
maxPayload.type = htons(TAG_PPP_MAX_PAYLOAD);
maxPayload.length = htons(sizeof(mru));
memcpy(maxPayload.payload, &mru, sizeof(mru));
@@ -479,9 +479,9 @@ sendPADR(PPPoEConnection *conn)
}
/* Add our maximum MTU/MRU */
- if (MIN(lcp_allowoptions[0].mru, lcp_wantoptions[0].mru) > ETH_PPPOE_MTU) {
+ if (MIN(conn->mtu, conn->mru) > ETH_PPPOE_MTU) {
PPPoETag maxPayload;
- UINT16_t mru = htons(MIN(lcp_allowoptions[0].mru, lcp_wantoptions[0].mru));
+ UINT16_t mru = htons(MIN(conn->mtu, conn->mru));
maxPayload.type = htons(TAG_PPP_MAX_PAYLOAD);
maxPayload.length = htons(sizeof(mru));
memcpy(maxPayload.payload, &mru, sizeof(mru));
@@ -666,10 +666,10 @@ discovery2(PPPoEConnection *conn)
if (!conn->seenMaxPayload) {
/* RFC 4638: MUST limit MTU/MRU to 1492 */
- if (lcp_allowoptions[0].mru > ETH_PPPOE_MTU)
- lcp_allowoptions[0].mru = ETH_PPPOE_MTU;
- if (lcp_wantoptions[0].mru > ETH_PPPOE_MTU)
- lcp_wantoptions[0].mru = ETH_PPPOE_MTU;
+ if (conn->mtu > ETH_PPPOE_MTU)
+ conn->mtu = ETH_PPPOE_MTU;
+ if (conn->mru > ETH_PPPOE_MTU)
+ conn->mru = ETH_PPPOE_MTU;
}
/* We're done. */
diff --git a/pppd/plugins/pppoe/plugin.c b/pppd/plugins/pppoe/plugin.c
index 5732460..e9353eb 100644
--- a/pppd/plugins/pppoe/plugin.c
+++ b/pppd/plugins/pppoe/plugin.c
@@ -161,8 +161,8 @@ PPPOEConnectDevice(void)
}
/* Restore configuration */
- lcp_allowoptions[0].mru = conn->mtu;
- lcp_wantoptions[0].mru = conn->mru;
+ lcp_allowoptions[0].mru = conn->mtu = conn->storedmtu;
+ lcp_wantoptions[0].mru = conn->mru = conn->storedmru;
/* Update maximum MRU */
s = socket(AF_INET, SOCK_DGRAM, 0);
@@ -179,9 +179,9 @@ PPPOEConnectDevice(void)
close(s);
if (lcp_allowoptions[0].mru > ifr.ifr_mtu - TOTAL_OVERHEAD)
- lcp_allowoptions[0].mru = ifr.ifr_mtu - TOTAL_OVERHEAD;
+ lcp_allowoptions[0].mru = conn->mtu = ifr.ifr_mtu - TOTAL_OVERHEAD;
if (lcp_wantoptions[0].mru > ifr.ifr_mtu - TOTAL_OVERHEAD)
- lcp_wantoptions[0].mru = ifr.ifr_mtu - TOTAL_OVERHEAD;
+ lcp_wantoptions[0].mru = conn->mru = ifr.ifr_mtu - TOTAL_OVERHEAD;
if (pppoe_host_uniq) {
if (!parseHostUniq(pppoe_host_uniq, &conn->hostUniq))
@@ -217,11 +217,17 @@ PPPOEConnectDevice(void)
goto errout;
}
discovery1(conn);
+ /* discovery1() may update conn->mtu and conn->mru */
+ lcp_allowoptions[0].mru = conn->mtu;
+ lcp_wantoptions[0].mru = conn->mru;
if (conn->discoveryState != STATE_RECEIVED_PADO) {
error("Unable to complete PPPoE Discovery phase 1");
goto errout;
}
discovery2(conn);
+ /* discovery2() may update conn->mtu and conn->mru */
+ lcp_allowoptions[0].mru = conn->mtu;
+ lcp_wantoptions[0].mru = conn->mru;
if (conn->discoveryState != STATE_SESSION) {
error("Unable to complete PPPoE Discovery phase 2");
goto errout;
@@ -452,8 +458,8 @@ void pppoe_check_options(void)
lcp_wantoptions[0].mru = MAX_PPPOE_MTU;
/* Save configuration */
- conn->mtu = lcp_allowoptions[0].mru;
- conn->mru = lcp_wantoptions[0].mru;
+ conn->storedmtu = lcp_allowoptions[0].mru;
+ conn->storedmru = lcp_wantoptions[0].mru;
ccp_allowoptions[0].deflate = 0;
ccp_wantoptions[0].deflate = 0;
diff --git a/pppd/plugins/pppoe/pppoe.h b/pppd/plugins/pppoe/pppoe.h
index a72454e..60c4f5e 100644
--- a/pppd/plugins/pppoe/pppoe.h
+++ b/pppd/plugins/pppoe/pppoe.h
@@ -242,8 +242,10 @@ typedef struct PPPoEConnectionStruct {
int discoveryTimeout; /* Timeout for discovery packets */
int discoveryAttempts; /* Number of discovery attempts */
int seenMaxPayload;
- int mtu; /* Stored MTU */
- int mru; /* Stored MRU */
+ int storedmtu; /* Stored MTU */
+ int storedmru; /* Stored MRU */
+ int mtu;
+ int mru;
} PPPoEConnection;
/* Structure used to determine acceptable PADO or PADS packet */