simplify throttle logic
[l2tpns.git] / ppp.c
diff --git a/ppp.c b/ppp.c
index afacd90..f70bdf2 100644 (file)
--- a/ppp.c
+++ b/ppp.c
@@ -1,6 +1,6 @@
 // L2TPNS PPP Stuff
 
-char const *cvs_id_ppp = "$Id: ppp.c,v 1.100 2006/04/27 09:53:50 bodea Exp $";
+char const *cvs_id_ppp = "$Id: ppp.c,v 1.103 2007/01/25 12:36:48 bodea Exp $";
 
 #include <stdio.h>
 #include <string.h>
@@ -179,16 +179,24 @@ void processchap(sessionidt s, tunnelidt t, uint8_t *p, uint16_t l)
                return;
        }
 
-       r = sess_local[s].radius;
-       if (!r)
+       if (session[s].ppp.phase != Authenticate)
        {
-               LOG(3, s, t, "Unexpected CHAP message\n");
+               LOG(2, s, t, "CHAP ignored in %s phase\n", ppp_phase(session[s].ppp.phase));
                return;
        }
 
-       if (session[s].ppp.phase != Authenticate)
+       r = sess_local[s].radius;
+       if (!r)
        {
-               LOG(2, s, t, "CHAP ignored in %s phase\n", ppp_phase(session[s].ppp.phase));
+               LOG(3, s, t, "Unexpected CHAP message\n");
+
+               // Some modems (Netgear DM602, possibly others) persist in using CHAP even
+               // after ACKing our ConfigReq for PAP.
+               if (sess_local[s].lcp_authtype == AUTHPAP && config->radius_authtypes & AUTHCHAP)
+               {
+                       sess_local[s].lcp_authtype = AUTHCHAP;
+                       sendchap(s, t);
+               }
                return;
        }
 
@@ -365,7 +373,7 @@ void lcp_open(sessionidt s, tunnelidt t)
                        session[s].ip = session[first_ses].ip;
                        session[s].dns1 = session[first_ses].dns1;
                        session[s].dns2 = session[first_ses].dns2;
-                       session[s].timeout = session[first_ses].timeout;
+                       session[s].session_timeout = session[first_ses].session_timeout;
                        ipcp_open(s, t);
                }
                else
@@ -1695,17 +1703,13 @@ void processipin(sessionidt s, tunnelidt t, uint8_t *p, uint16_t l)
        *(uint32_t *) p = htonl(PKTIP);
        l += 4;
 
-       // Are we throttled and a slave?
-       if (session[s].tbf_in && !config->cluster_iam_master) {
-               // Pass it to the master for handling.
-               master_throttle_packet(session[s].tbf_in, p, l);
-               return;
-       }
-
-       // Are we throttled and a master??
-       if (session[s].tbf_in && config->cluster_iam_master) {
-               // Actually handle the throttled packets.
-               tbf_queue_packet(session[s].tbf_in, p, l);
+       if (session[s].tbf_in)
+       {
+               // Are we throttling this session?
+               if (config->cluster_iam_master)
+                       tbf_queue_packet(session[s].tbf_in, p, l);
+               else
+                       master_throttle_packet(session[s].tbf_in, p, l);
                return;
        }