cleanup clash between timeout and session_timout
authorBrendan O'Dea <bod@optus.net>
Wed, 2 Aug 2006 13:35:39 +0000 (13:35 +0000)
committerBrendan O'Dea <bod@optus.net>
Wed, 2 Aug 2006 13:35:39 +0000 (13:35 +0000)
cli.c
l2tpns.c
l2tpns.h
ppp.c
radius.c

diff --git a/cli.c b/cli.c
index f01a0ae..d7a487e 100644 (file)
--- a/cli.c
+++ b/cli.c
@@ -2,7 +2,7 @@
 // vim: sw=8 ts=8
 
 char const *cvs_name = "$Name:  $";
-char const *cvs_id_cli = "$Id: cli.c,v 1.74 2006-06-11 12:46:18 bodea Exp $";
+char const *cvs_id_cli = "$Id: cli.c,v 1.75 2006-08-02 13:35:39 bodea Exp $";
 
 #include <stdio.h>
 #include <stddef.h>
@@ -427,19 +427,18 @@ static int cmd_show_session(struct cli_def *cli, char *command, char **argv, int
                        cli_print(cli, "\tOpened:\t\t%u seconds", session[s].opened ? abs(time_now - session[s].opened) : 0);
                        cli_print(cli, "\tIdle time:\t%u seconds", session[s].last_packet ? abs(time_now - session[s].last_packet) : 0);
                        if (session[s].session_timeout)
-                               cli_print(cli, "\tSess Timeout:\t%u seconds", session[s].session_timeout - (session[s].opened ? abs(time_now - session[s].opened) : 0));
+                       {
+                               clockt opened = session[s].opened;
+                               if (session[s].bundle && bundle[session[s].bundle].num_of_links > 1)
+                                       opened = bundle[session[s].bundle].online_time;
+
+                               cli_print(cli, "\tSess Timeout:\t%u seconds", session[s].session_timeout - (opened ? abs(time_now - opened) : 0));
+                       }
+
                        if (session[s].idle_timeout)
                                cli_print(cli, "\tIdle Timeout:\t%u seconds", session[s].idle_timeout - (session[s].last_data ? abs(time_now - session[s].last_data) : 0));
 
                        cli_print(cli, "\tBytes In/Out:\t%u/%u", session[s].cout, session[s].cin);
-                       if (session[s].timeout)
-                       {
-                               cli_print(cli, "\tRemaing time:\t%u",
-                                       (session[s].bundle && bundle[session[s].bundle].num_of_links > 1)
-                                       ? (unsigned) (session[s].timeout - bundle[session[s].bundle].online_time)
-                                       : (unsigned) (session[s].timeout - (time_now - session[s].opened)));
-                       }
-
                        cli_print(cli, "\tPkts In/Out:\t%u/%u", session[s].pout, session[s].pin);
                        cli_print(cli, "\tMRU:\t\t%d", session[s].mru);
                        cli_print(cli, "\tRx Speed:\t%u", session[s].rx_connect_speed);
@@ -506,7 +505,7 @@ static int cmd_show_session(struct cli_def *cli, char *command, char **argv, int
        }
 
        // Show Summary
-       cli_print(cli, "%5s %4s %-32s %-15s %s %s %s %s %10s %10s %10s %4s %10s %-15s %s",
+       cli_print(cli, "%5s %4s %-32s %-15s %s %s %s %s %10s %10s %10s %4s %-15s %s",
                        "SID",
                        "TID",
                        "Username",
@@ -519,20 +518,13 @@ static int cmd_show_session(struct cli_def *cli, char *command, char **argv, int
                        "downloaded",
                        "uploaded",
                        "idle",
-                       "Rem.Time",
                        "LAC",
                        "CLI");
 
        for (i = 1; i < MAXSESSION; i++)
        {
-               uint32_t rem_time;
                if (!session[i].opened) continue;
-               if (session[i].bundle && bundle[session[i].bundle].num_of_links > 1)
-                       rem_time = session[i].timeout ? (session[i].timeout - bundle[session[i].bundle].online_time) : 0;
-               else
-                       rem_time = session[i].timeout ? (session[i].timeout - (time_now-session[i].opened)) : 0;
-
-               cli_print(cli, "%5d %4d %-32s %-15s %s %s %s %s %10u %10lu %10lu %4u %10lu %-15s %s",
+               cli_print(cli, "%5d %4d %-32s %-15s %s %s %s %s %10u %10lu %10lu %4u %-15s %s",
                                i,
                                session[i].tunnel,
                                session[i].user[0] ? session[i].user : "*",
@@ -545,7 +537,6 @@ static int cmd_show_session(struct cli_def *cli, char *command, char **argv, int
                                (unsigned long)session[i].cout,
                                (unsigned long)session[i].cin,
                                abs(time_now - (session[i].last_packet ? session[i].last_packet : time_now)),
-                               (unsigned long)(rem_time),
                                fmtaddr(htonl(tunnel[ session[i].tunnel ].ip), 1),
                                session[i].calling[0] ? session[i].calling : "*");
        }
index 659a87d..454f79b 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.170 2006-07-01 14:07:35 bodea Exp $";
+char const *cvs_id_l2tpns = "$Id: l2tpns.c,v 1.171 2006-08-02 13:35:39 bodea Exp $";
 
 #include <arpa/inet.h>
 #include <assert.h>
@@ -3053,37 +3053,6 @@ static void regular_cleanups(double period)
                        continue;
                }
 
-               // check for timed out sessions
-               if (session[s].timeout)
-               {
-                       bundleidt bid = session[s].bundle;
-                       if (bid)
-                       {
-                               clockt curr_time = time_now;
-                               if (curr_time - bundle[bid].last_check >= 1)
-                               {
-                                       bundle[bid].online_time += (curr_time-bundle[bid].last_check)*bundle[bid].num_of_links;
-                                       bundle[bid].last_check = curr_time;
-                                       if (bundle[bid].online_time >= session[s].timeout)
-                                       {
-                                               int ses;
-                                               for (ses = bundle[bid].num_of_links - 1; ses >= 0; ses--)
-                                               {
-                                                       sessionshutdown(bundle[bid].members[ses], "Session timeout", CDN_ADMIN_DISC, TERM_SESSION_TIMEOUT);
-                                                       s_actions++;
-                                                       continue;
-                                               }
-                                       }
-                               }
-                       }
-                       else if (session[s].timeout <= time_now - session[s].opened)
-                       {
-                               sessionshutdown(s, "Session timeout", CDN_ADMIN_DISC, TERM_SESSION_TIMEOUT);
-                               s_actions++;
-                               continue;
-                       }
-               }
-
                // PPP timeouts
                if (sess_local[s].lcp.restart <= time_now)
                {
@@ -3226,12 +3195,33 @@ static void regular_cleanups(double period)
                }
 
                // Drop sessions who have reached session_timeout seconds
-               if (session[s].session_timeout && (time_now - session[s].opened >= session[s].session_timeout))
+               if (session[s].session_timeout)
                {
-                       sessionshutdown(s, "Session Timeout Reached", CDN_ADMIN_DISC, TERM_SESSION_TIMEOUT);
-                       STAT(session_timeout);
-                       s_actions++;
-                       continue;
+                       bundleidt bid = session[s].bundle;
+                       if (bid)
+                       {
+                               if (time_now - bundle[bid].last_check >= 1)
+                               {
+                                       bundle[bid].online_time += (time_now - bundle[bid].last_check) * bundle[bid].num_of_links;
+                                       bundle[bid].last_check = time_now;
+                                       if (bundle[bid].online_time >= session[s].session_timeout)
+                                       {
+                                               int ses;
+                                               for (ses = bundle[bid].num_of_links - 1; ses >= 0; ses--)
+                                               {
+                                                       sessionshutdown(bundle[bid].members[ses], "Session timeout", CDN_ADMIN_DISC, TERM_SESSION_TIMEOUT);
+                                                       s_actions++;
+                                                       continue;
+                                               }
+                                       }
+                               }
+                       }
+                       else if (time_now - session[s].opened >= session[s].session_timeout)
+                       {
+                               sessionshutdown(s, "Session timeout", CDN_ADMIN_DISC, TERM_SESSION_TIMEOUT);
+                               s_actions++;
+                               continue;
+                       }
                }
 
                // Drop sessions who have reached idle_timeout seconds
index 29f0710..21ec6fd 100644 (file)
--- a/l2tpns.h
+++ b/l2tpns.h
@@ -1,5 +1,5 @@
 // L2TPNS Global Stuff
-// $Id: l2tpns.h,v 1.118 2006-07-01 12:40:17 bodea Exp $
+// $Id: l2tpns.h,v 1.119 2006-08-02 13:35:39 bodea Exp $
 
 #ifndef __L2TPNS_H__
 #define __L2TPNS_H__
@@ -299,7 +299,6 @@ typedef struct
        char calling[MAXTEL];           // calling number
        uint32_t tx_connect_speed;
        uint32_t rx_connect_speed;
-       clockt timeout;                 // Session timeout
        uint32_t mrru;                  // Multilink Max-Receive-Reconstructed-Unit
        uint8_t mssf;                   // Multilink Short Sequence Number Header Format
        epdist epdis;                   // Multilink Endpoint Discriminator
diff --git a/ppp.c b/ppp.c
index 8c1c9a3..a1ad56a 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.101 2006-06-03 08:16:46 bodea Exp $";
+char const *cvs_id_ppp = "$Id: ppp.c,v 1.102 2006-08-02 13:35:39 bodea Exp $";
 
 #include <stdio.h>
 #include <string.h>
@@ -373,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
index d35a3f9..c167cbe 100644 (file)
--- a/radius.c
+++ b/radius.c
@@ -1,6 +1,6 @@
 // L2TPNS Radius Stuff
 
-char const *cvs_id_radius = "$Id: radius.c,v 1.53 2006-08-02 12:54:45 bodea Exp $";
+char const *cvs_id_radius = "$Id: radius.c,v 1.54 2006-08-02 13:35:39 bodea Exp $";
 
 #include <time.h>
 #include <stdio.h>
@@ -655,19 +655,6 @@ void processrad(uint8_t *buf, int len, char socket_index)
                                                LOG(3, s, session[s].tunnel, "   Radius reply contains primary DNS address %s\n",
                                                        fmtaddr(htonl(session[s].dns1), 0));
                                        }
-                                       else if (*p == 27)
-                                       {
-                                               // Session timeout
-                                               if (p[1] < 6) {
-                                                       LOG(2, s, session[s].tunnel, "Error: Received Session timeout with length %d < 6\n", p[1]);
-                                                       continue;
-                                               }
-
-                                               session[s].timeout = ntohl(*(uint32_t *) (p + 2));
-                                               LOG(3, s, session[s].tunnel, "   Radius reply contains Session timeout %d\n", session[s].timeout);
-                                               if (!session[s].timeout)
-                                                       sessionshutdown(s, "Session timeout is zero", CDN_ADMIN_DISC, TERM_SESSION_TIMEOUT);
-                                       }
                                        else if (*p == 136)
                                        {
                                                // DNS address
@@ -764,24 +751,16 @@ void processrad(uint8_t *buf, int len, char socket_index)
                                        else if (*p == 27)
                                        {
                                                // Session-Timeout
-                                               uint32_t to = ntohl(*(uint32_t *)(p + 2));
-
-                                               LOG(3, s, session[s].tunnel, "   Radius reply contains Session-Timeout = %u\n", to);
-                                               if (to > 0)
-                                               {
-                                                       session[s].session_timeout = to;
-                                               }
+                                               if (p[1] < 6) continue;
+                                               session[s].session_timeout = ntohl(*(uint32_t *)(p + 2));
+                                               LOG(3, s, session[s].tunnel, "   Radius reply contains Session-Timeout = %u\n", session[s].session_timeout);
                                        }
                                        else if (*p == 28)
                                        {
                                                // Idle-Timeout
-                                               uint32_t to = ntohl(*(uint32_t *)(p + 2));
-
-                                               LOG(3, s, session[s].tunnel, "   Radius reply contains Idle-Timeout = %u\n", to);
-                                               if (to > 0)
-                                               {
-                                                       session[s].idle_timeout = to;
-                                               }
+                                               if (p[1] < 6) continue;
+                                               session[s].idle_timeout = ntohl(*(uint32_t *)(p + 2));
+                                               LOG(3, s, session[s].tunnel, "   Radius reply contains Idle-Timeout = %u\n", session[s].idle_timeout);
                                        }
                                        else if (*p == 26 && p[1] >= 7)
                                        {