first version of the LAC functionality
[l2tpns.git] / ppp.c
diff --git a/ppp.c b/ppp.c
index 7251e94..518f6ec 100644 (file)
--- a/ppp.c
+++ b/ppp.c
@@ -1,5 +1,7 @@
 // L2TPNS PPP Stuff
 
 // L2TPNS PPP Stuff
 
+//#define LAC
+
 #include <stdio.h>
 #include <string.h>
 #include <unistd.h>
 #include <stdio.h>
 #include <string.h>
 #include <unistd.h>
 #include "tbf.h"
 #include "cluster.h"
 
 #include "tbf.h"
 #include "cluster.h"
 
+#ifdef LAC
+#include "l2tplac.h"
+#endif
+
 extern tunnelt *tunnel;
 extern bundlet *bundle;
 extern fragmentationt *frag;
 extern tunnelt *tunnel;
 extern bundlet *bundle;
 extern fragmentationt *frag;
@@ -100,6 +106,14 @@ void processpap(sessionidt s, tunnelidt t, uint8_t *p, uint16_t l)
                LOG(3, s, t, "PAP login %s/%s\n", user, pass);
        }
 
                LOG(3, s, t, "PAP login %s/%s\n", user, pass);
        }
 
+#ifdef LAC
+       if (forwardtolns(s, user))
+       {
+               LOG(3, s, t, "Forwarding login for %s to other LNS\n", user);
+               return;
+       }
+#endif
+
        if (session[s].ip || !(r = radiusnew(s)))
        {
                // respond now, either no RADIUS available or already authenticated
        if (session[s].ip || !(r = radiusnew(s)))
        {
                // respond now, either no RADIUS available or already authenticated
@@ -251,6 +265,17 @@ void processchap(sessionidt s, tunnelidt t, uint8_t *p, uint16_t l)
                packet.username = calloc(l + 1, 1);
                memcpy(packet.username, p, l);
 
                packet.username = calloc(l + 1, 1);
                memcpy(packet.username, p, l);
 
+#ifdef LAC
+               if (forwardtolns(s, packet.username))
+               {
+                       LOG(3, s, t, "Forwarding login for %s to other LNS\n", packet.username);
+
+                       free(packet.username);
+                       free(packet.password);
+                       return;
+               }
+#endif
+
                run_plugins(PLUGIN_PRE_AUTH, &packet);
                if (!packet.continue_auth)
                {
                run_plugins(PLUGIN_PRE_AUTH, &packet);
                if (!packet.continue_auth)
                {
@@ -1879,9 +1904,12 @@ void processmpin(sessionidt s, tunnelidt t, uint8_t *p, uint16_t l)
 
        // calculate the jitter average
        uint32_t ljitter = time_now_ms - sess_local[s].prev_time;
 
        // calculate the jitter average
        uint32_t ljitter = time_now_ms - sess_local[s].prev_time;
-       sess_local[s].jitteravg = (sess_local[s].jitteravg + ljitter)>>1;
-       sess_local[s].prev_time = time_now_ms;
-       
+       if (ljitter > 0)
+       {
+               sess_local[s].jitteravg = (sess_local[s].jitteravg + ljitter)>>1;
+               sess_local[s].prev_time = time_now_ms;
+       }
+
        uint32_t Mmin;
 
        if (seq_num < this_fragmentation->M)
        uint32_t Mmin;
 
        if (seq_num < this_fragmentation->M)
@@ -2084,7 +2112,7 @@ find_frame:
        }
 
 assembling_frame:
        }
 
 assembling_frame:
-       // try to assemble the frame that has the received fragment as a member         
+       // try to assemble the frame that has the received fragment as a member
        // get the beginning of this frame
        begin_index = end_index = this_fragmentation->start_index;
        if (this_fragmentation->fragment[begin_index].length)
        // get the beginning of this frame
        begin_index = end_index = this_fragmentation->start_index;
        if (this_fragmentation->fragment[begin_index].length)