- Reset restart counters correctly.
authorBrendan O'Dea <bod@optus.net>
Fri, 4 Nov 2005 14:41:50 +0000 (14:41 +0000)
committerBrendan O'Dea <bod@optus.net>
Fri, 4 Nov 2005 14:41:50 +0000 (14:41 +0000)
- Reset timers on sending ConfigReq.
- Only send one RADIUS Start record, even if IPCP is restarted.

Changes
cluster.c
l2tpns.c
l2tpns.h
l2tpns.spec
ppp.c

diff --git a/Changes b/Changes
index 0a0e445..a975f5b 100644 (file)
--- a/Changes
+++ b/Changes
@@ -1,7 +1,10 @@
-* Wed Oct 19 2005 Brendan O'Dea <bod@optus.net> 2.1.10
+* Sat Nov 5 2005 Brendan O'Dea <bod@optus.net> 2.1.10
 - Add scripts/l2tpns-capture.
 - Fix LCP Echo frequency.
 - Add Framed-Route entries to RADIUS records.
+- Reset restart counters correctly.
+- Reset timers on sending ConfigReq.
+- Only send one RADIUS Start record, even if IPCP is restarted.
 
 * Tue Oct 11 2005 Brendan O'Dea <bod@optus.net> 2.1.9
 - Fix Calling-Station-Id in RADIUS accounting records (Slobodan Tomic).
index 12e7c08..3dd9ed0 100644 (file)
--- a/cluster.c
+++ b/cluster.c
@@ -1,6 +1,6 @@
 // L2TPNS Clustering Stuff
 
-char const *cvs_id_cluster = "$Id: cluster.c,v 1.46 2005-09-02 23:59:56 bodea Exp $";
+char const *cvs_id_cluster = "$Id: cluster.c,v 1.47 2005-11-04 14:41:50 bodea Exp $";
 
 #include <stdio.h>
 #include <stdlib.h>
@@ -1268,7 +1268,7 @@ static uint8_t *convert_session(struct oldsession *old)
        new.next = old->next;
        new.far = old->far;
        new.tunnel = old->tunnel;
-       new.l2tp_flags = old->l2tp_flags;
+       new.flags = old->l2tp_flags;
        new.ip = old->ip;
        new.ip_pool_index = old->ip_pool_index;
        new.unique_id = old->unique_id;
index 994116f..0c0921c 100644 (file)
--- a/l2tpns.c
+++ b/l2tpns.c
@@ -4,7 +4,7 @@
 // Copyright (c) 2002 FireBrick (Andrews & Arnold Ltd / Watchfront Ltd) - GPL licenced
 // vim: sw=8 ts=8
 
-char const *cvs_id_l2tpns = "$Id: l2tpns.c,v 1.145 2005-10-18 07:19:28 bodea Exp $";
+char const *cvs_id_l2tpns = "$Id: l2tpns.c,v 1.146 2005-11-04 14:41:50 bodea Exp $";
 
 #include <arpa/inet.h>
 #include <assert.h>
@@ -1682,6 +1682,7 @@ void sendipcp(sessionidt s, tunnelidt t)
                                 my_address; // send my IP
 
        tunnelsend(buf, 10 + (q - buf), t); // send it
+       restart_timer(s, ipcp);
 }
 
 void sendipv6cp(sessionidt s, tunnelidt t)
@@ -1707,6 +1708,7 @@ void sendipv6cp(sessionidt s, tunnelidt t)
        q[13] = 1;
 
        tunnelsend(buf, 14 + (q - buf), t);     // send it
+       restart_timer(s, ipv6cp);
 }
 
 static void sessionclear(sessionidt s)
@@ -2327,9 +2329,9 @@ void processudp(uint8_t *buf, int len, struct sockaddr_in *addr)
                                                        if (*p == 5 && p[1] == 6) // Magic-Number
                                                                amagic = ntohl(*(uint32_t *) (p + 2));
                                                        else if (*p == 7) // Protocol-Field-Compression
-                                                               aflags |= SESSIONPFC;
+                                                               aflags |= SESSION_PFC;
                                                        else if (*p == 8) // Address-and-Control-Field-Compression
-                                                               aflags |= SESSIONACFC;
+                                                               aflags |= SESSION_ACFC;
                                                        p += p[1];
                                                }
                                        }
@@ -2456,20 +2458,17 @@ void processudp(uint8_t *buf, int len, struct sockaddr_in *addr)
                                case 12:      // ICCN
                                        if (amagic == 0) amagic = time_now;
                                        session[s].magic = amagic; // set magic number
-                                       session[s].l2tp_flags = aflags; // set flags received
+                                       session[s].flags = aflags; // set flags received
                                        session[s].mru = PPPMTU; // default
                                        controlnull(t); // ack
 
                                        // start LCP
-                                       sess_local[s].lcp.restart = time_now + config->ppp_restart_time;
-                                       sess_local[s].lcp.conf_sent = 1;
-                                       sess_local[s].lcp.nak_sent = 0;
                                        sess_local[s].lcp_authtype = config->radius_authprefer;
                                        sess_local[s].ppp_mru = MRU;
-                                       session[s].ppp.lcp = RequestSent;
                                        sendlcp(s, t);
-
+                                       change_state(s, lcp, RequestSent);
                                        break;
+
                                case 14:      // CDN
                                        controlnull(t); // ack
                                        sessionshutdown(s, "Closed (Received CDN).", 0, 0);
@@ -2817,8 +2816,6 @@ static void regular_cleanups(double period)
                                if (sess_local[s].lcp.conf_sent < config->ppp_max_configure)
                                {
                                        LOG(3, s, session[s].tunnel, "No ACK for LCP ConfigReq... resending\n");
-                                       sess_local[s].lcp.restart = time_now + config->ppp_restart_time;
-                                       sess_local[s].lcp.conf_sent++;
                                        sendlcp(s, session[s].tunnel);
                                        change_state(s, lcp, next_state);
                                }
@@ -2848,8 +2845,6 @@ static void regular_cleanups(double period)
                                if (sess_local[s].ipcp.conf_sent < config->ppp_max_configure)
                                {
                                        LOG(3, s, session[s].tunnel, "No ACK for IPCP ConfigReq... resending\n");
-                                       sess_local[s].ipcp.restart = time_now + config->ppp_restart_time;
-                                       sess_local[s].ipcp.conf_sent++;
                                        sendipcp(s, session[s].tunnel);
                                        change_state(s, ipcp, next_state);
                                }
@@ -2879,8 +2874,6 @@ static void regular_cleanups(double period)
                                if (sess_local[s].ipv6cp.conf_sent < config->ppp_max_configure)
                                {
                                        LOG(3, s, session[s].tunnel, "No ACK for IPV6CP ConfigReq... resending\n");
-                                       sess_local[s].ipv6cp.restart = time_now + config->ppp_restart_time;
-                                       sess_local[s].ipv6cp.conf_sent++;
                                        sendipv6cp(s, session[s].tunnel);
                                        change_state(s, ipv6cp, next_state);
                                }
@@ -2907,8 +2900,6 @@ static void regular_cleanups(double period)
                                if (sess_local[s].ccp.conf_sent < config->ppp_max_configure)
                                {
                                        LOG(3, s, session[s].tunnel, "No ACK for CCP ConfigReq... resending\n");
-                                       sess_local[s].ccp.restart = time_now + config->ppp_restart_time;
-                                       sess_local[s].ccp.conf_sent++;
                                        sendccp(s, session[s].tunnel);
                                        change_state(s, ccp, next_state);
                                }
index 79f1c85..e1d2d0d 100644 (file)
--- a/l2tpns.h
+++ b/l2tpns.h
@@ -1,5 +1,5 @@
 // L2TPNS Global Stuff
-// $Id: l2tpns.h,v 1.96 2005-10-18 07:19:29 bodea Exp $
+// $Id: l2tpns.h,v 1.97 2005-11-04 14:41:50 bodea Exp $
 
 #ifndef __L2TPNS_H__
 #define __L2TPNS_H__
@@ -148,7 +148,14 @@ enum {
 
 // reset state machine counters
 #define initialise_restart_count(_s, _fsm)                     \
-       sess_local[_s]._fsm.conf_sent = sess_local[_s]._fsm.nak_sent
+       sess_local[_s]._fsm.conf_sent = sess_local[_s]._fsm.nak_sent = 0
+
+// increment ConfReq counter and reset timer
+#define restart_timer(_s, _fsm) ({                             \
+       sess_local[_s]._fsm.conf_sent++;                        \
+       sess_local[_s]._fsm.restart =                           \
+               time_now + config->ppp_restart_time;            \
+})
 
 // stop timer on change to state where timer does not run
 #define change_state(_s, _fsm, _new) ({                                \
@@ -221,7 +228,7 @@ typedef struct
        sessionidt next;                // next session in linked list
        sessionidt far;                 // far end session ID
        tunnelidt tunnel;               // near end tunnel ID
-       uint8_t l2tp_flags;             // various bit flags from the ICCN on the l2tp tunnel.
+       uint8_t flags;                  // session flags: see SESSION_*
        struct {
                uint8_t phase;          // PPP phase
                uint8_t lcp:4;          //   LCP    state
@@ -312,8 +319,10 @@ typedef struct
        time_t last_echo;
 } sessionlocalt;
 
-#define        SESSIONPFC      1       // PFC negotiated flags
-#define        SESSIONACFC     2       // ACFC negotiated flags
+// session flags
+#define        SESSION_PFC     (1 << 0)        // use Protocol-Field-Compression
+#define        SESSION_ACFC    (1 << 1)        // use Address-and-Control-Field-Compression
+#define SESSION_STARTED        (1 << 2)        // RADIUS Start record sent
 
 // 168 bytes per tunnel
 typedef struct
index 53cd8c5..434f222 100644 (file)
@@ -43,5 +43,5 @@ rm -rf %{buildroot}
 %attr(644,root,root) /usr/share/man/man[58]/*
 
 %changelog
-* Wed Oct 19 2005 Brendan O'Dea <bod@optus.net> 2.1.10-1
+* Sat Nov 5 2005 Brendan O'Dea <bod@optus.net> 2.1.10-1
 - 2.1.10 release, see /usr/share/doc/l2tpns-2.1.10/Changes
diff --git a/ppp.c b/ppp.c
index 4215cb8..358b90b 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.84 2005-09-16 13:20:39 bodea Exp $";
+char const *cvs_id_ppp = "$Id: ppp.c,v 1.85 2005-11-04 14:41:50 bodea Exp $";
 
 #include <stdio.h>
 #include <string.h>
@@ -903,11 +903,17 @@ static void ipcp_open(sessionidt s, tunnelidt t)
 
        change_state(s, ipcp, Opened);
 
-       if (!session[s].walled_garden)
+       if (!(session[s].walled_garden || session[s].flags & SESSION_STARTED))
        {
                uint16_t r = radiusnew(s);
                if (r)
+               {
                        radiussend(r, RADIUSSTART); // send radius start
+
+                       // don't send further Start records if IPCP is restarted
+                       session[s].flags |= SESSION_STARTED;
+                       cluster_send_session(s);
+               }
        }
 
        // start IPv6 if configured and still in passive state
@@ -1747,12 +1753,12 @@ uint8_t *makeppp(uint8_t *b, int size, uint8_t *p, int l, sessionidt s, tunnelid
        *(uint16_t *) (b + 2) = htons(tunnel[t].far); // tunnel
        *(uint16_t *) (b + 4) = htons(session[s].far); // session
        b += 6;
-       if (mtype == PPPLCP || !(session[s].l2tp_flags & SESSIONACFC))
+       if (mtype == PPPLCP || !(session[s].flags & SESSION_ACFC))
        {
                *(uint16_t *) b = htons(0xFF03); // HDLC header
                b += 2;
        }
-       if (mtype < 0x100 && session[s].l2tp_flags & SESSIONPFC)
+       if (mtype < 0x100 && session[s].flags & SESSION_PFC)
                *b++ = mtype;
        else
        {
@@ -1839,6 +1845,7 @@ void sendlcp(sessionidt s, tunnelidt t)
        if (config->debug > 3) dumplcp(q, l - q);
 
        tunnelsend(b, (l - b), t);
+       restart_timer(s, lcp);
 }
 
 // Send CCP request for no compression
@@ -1857,4 +1864,5 @@ void sendccp(sessionidt s, tunnelidt t)
 
        LOG_HEX(5, "PPPCCP", q, 4);
        tunnelsend(b, (q - b) + 4 , t);
+       restart_timer(s, ccp);
 }