]> git.ozlabs.org Git - ppp.git/commitdiff
pppoe: Do not use lcp_allowoptions[] and lcp_wantoptions[] in discovery.c code
authorPali Rohár <pali@kernel.org>
Fri, 1 Jan 2021 15:30:19 +0000 (16:30 +0100)
committerPali Rohár <pali@kernel.org>
Mon, 4 Jan 2021 23:43:56 +0000 (00:43 +0100)
Signed-off-by: Pali Rohár <pali@kernel.org>
pppd/plugins/pppoe/discovery.c
pppd/plugins/pppoe/plugin.c
pppd/plugins/pppoe/pppoe.h

index 1c55b3680521e6501e25caf2db967cb173e7bedf..1d3d12ba5884ad39099dcddc4c70c3e478b90951 100644 (file)
@@ -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. */
index 57324607d9e9acc7226a802b8d019544602c2f90..e9353eb009b4a63dabdb22a2845d5c6960090f7c 100644 (file)
@@ -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;
index a72454e532943aba9384cbda106e5c97e275077f..60c4f5e7e4481c691de3aefcbd70fb04223cff52 100644 (file)
@@ -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 */