sanity check that cluster_send_session is not called from a child process
authorBrendan O'Dea <bod@optus.net>
Mon, 20 Dec 2004 07:23:41 +0000 (07:23 +0000)
committerBrendan O'Dea <bod@optus.net>
Mon, 20 Dec 2004 07:23:41 +0000 (07:23 +0000)
throttle outgoing LASTSEEN packets to at most one per second for a given seq#

Changes
cluster.c
l2tpns.spec
util.c

diff --git a/Changes b/Changes
index 2431686..9eaca00 100644 (file)
--- a/Changes
+++ b/Changes
@@ -1,5 +1,9 @@
-* Sat Dec 18 2004 Brendan O'Dea <bod@optusnet.com.au> 2.1.0
+* Mon Dec 20 2004 Brendan O'Dea <bod@optusnet.com.au> 2.1.0
 - Add IPv6 support from Jonathan McDowell (work in progress).
+- Sanity check that cluster_send_session is not called from a child
+  process.
+- Throttle outgoing LASTSEEN packets to at most one per second for a
+  given seq#.
 
 * Fri Dec 17 2004 Brendan O'Dea <bod@optusnet.com.au> 2.0.13
 - Better cluster master collision resolution: keep a counter of state
index a452144..eab0485 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.26 2004-12-16 23:40:31 bodea Exp $";
+char const *cvs_id_cluster = "$Id: cluster.c,v 1.27 2004-12-20 07:23:42 bodea Exp $";
 
 #include <stdio.h>
 #include <stdlib.h>
@@ -38,11 +38,12 @@ char const *cvs_id_cluster = "$Id: cluster.c,v 1.26 2004-12-16 23:40:31 bodea Ex
  */
 
 // Module variables.
-int cluster_sockfd = 0;                // The filedescriptor for the cluster communications port.
+int cluster_sockfd = 0;                        // The filedescriptor for the cluster communications port.
 
 in_addr_t my_address = 0;              // The network address of my ethernet port.
 static int walk_session_number = 0;    // The next session to send when doing the slow table walk.
 static int walk_tunnel_number = 0;     // The next tunnel to send when doing the slow table walk.
+int forked = 0;                                // Sanity check: CLI must not diddle with heartbeat table
 
 #define MAX_HEART_SIZE (8192)  // Maximum size of heartbeat packet. Must be less than max IP packet size :)
 #define MAX_CHANGES  (MAX_HEART_SIZE/(sizeof(sessiont) + sizeof(int) ) - 2)    // Assumes a session is the biggest type!
@@ -866,6 +867,11 @@ int cluster_send_session(int sid)
                return -1;
        }
 
+       if (forked) {
+               LOG(0, sid, 0, "cluster_send_session called from child process!"\n");
+               return -1;
+       }
+
        return type_changed(C_CSESSION, sid);
 }
 
@@ -1177,9 +1183,22 @@ static int cluster_process_heartbeat(uint8_t *data, int size, int more, uint8_t
        config->cluster_last_hb = TIME; // Reset to ensure that we don't become master!!
 
        if (config->cluster_seq_number != h->seq) {     // Out of sequence heartbeat!
-               LOG(1, 0, 0, "HB: Got seq# %d but was expecting %d. asking for resend.\n", h->seq, config->cluster_seq_number);
+               static int lastseen_seq = 0;
+               static time_t lastseen_time = 0;
+
+               // limit to once per second for a particular seq#
+               int ask = (config->cluster_seq_number != lastseen_seq || time_now != lastseen_time);
 
-               peer_send_message(addr, C_LASTSEEN, config->cluster_seq_number, NULL, 0);
+               LOG(1, 0, 0, "HB: Got seq# %d but was expecting %d.  %s.\n",
+                       h->seq, config->cluster_seq_number,
+                       ask ? "Asking for resend" : "Ignoring");
+
+               if (ask)
+               {
+                       lastseen_seq = config->cluster_seq_number;
+                       lastseen_time = time_now;
+                       peer_send_message(addr, C_LASTSEEN, config->cluster_seq_number, NULL, 0);
+               }
 
                config->cluster_last_hb = TIME; // Reset to ensure that we don't become master!!
 
index dd382cb..424fd52 100644 (file)
@@ -43,5 +43,5 @@ rm -rf %{buildroot}
 %attr(644,root,root) /usr/share/man/man[58]/*
 
 %changelog
-* Sat Dec 18 2004 Brendan O'Dea <bod@optusnet.com.au> 2.1.0-1
+* Mon Dec 20 2004 Brendan O'Dea <bod@optusnet.com.au> 2.1.0-1
 - 2.1.0 release, see /usr/share/doc/l2tpns-2.1.0/Changes
diff --git a/util.c b/util.c
index 2e6046a..3db4edd 100644 (file)
--- a/util.c
+++ b/util.c
@@ -1,6 +1,6 @@
 /* Misc util functions */
 
-char const *cvs_id_util = "$Id: util.c,v 1.8 2004-12-16 08:49:53 bodea Exp $";
+char const *cvs_id_util = "$Id: util.c,v 1.9 2004-12-20 07:23:53 bodea Exp $";
 
 #include <unistd.h>
 #include <errno.h>
@@ -39,6 +39,7 @@ void *shared_malloc(unsigned int size)
        return p;
 }
 
+extern int forked;
 extern int udpfd, controlfd, tunfd, snoopfd, ifrfd, cluster_sockfd;
 extern int *radfds;
 
@@ -50,6 +51,7 @@ pid_t fork_and_close()
        if (pid)
                return pid;
 
+       forked++;
        if (config->scheduler_fifo)
        {
                struct sched_param params = {0};