roll in Michael's "limp along" fix for when a slave drops temporarily from the mcast...
[l2tpns.git] / cluster.c
index 4c4efde..d9c619e 100644 (file)
--- a/cluster.c
+++ b/cluster.c
@@ -1,6 +1,6 @@
 // L2TPNS Clustering Stuff
 
 // L2TPNS Clustering Stuff
 
-char const *cvs_id_cluster = "$Id: cluster.c,v 1.4 2004-06-28 02:43:13 fred_nerk Exp $";
+char const *cvs_id_cluster = "$Id: cluster.c,v 1.6 2004-07-05 06:54:01 bodea Exp $";
 
 #include <stdio.h>
 #include <sys/file.h>
 
 #include <stdio.h>
 #include <sys/file.h>
@@ -343,6 +343,7 @@ static void send_heartbeat(int seq, char * data, int size)
     if (size > sizeof(past_hearts[0].data)) {
        log(0,0,0,0, "Tried to heartbeat something larger than the maximum packet!\n");
        kill(0, SIGTERM);
     if (size > sizeof(past_hearts[0].data)) {
        log(0,0,0,0, "Tried to heartbeat something larger than the maximum packet!\n");
        kill(0, SIGTERM);
+       exit(1);
     }
     i = seq % HB_HISTORY_SIZE;
     past_hearts[i].seq = seq;
     }
     i = seq % HB_HISTORY_SIZE;
     past_hearts[i].seq = seq;
@@ -437,6 +438,20 @@ void cluster_check_master(void)
        int last_free = 0;
        int had_peers = have_peers;
        clockt t = TIME;
        int last_free = 0;
        int had_peers = have_peers;
        clockt t = TIME;
+       static int probed = 0;
+
+               // Is the master late? If so, try probing it...
+       if (TIME > (config->cluster_last_hb + config->cluster_hb_timeout/8 + 11)) {
+               if (!probed) {
+                       if (config->cluster_master_address) {
+                               peer_send_message(config->cluster_master_address,
+                                       C_LASTSEEN, config->cluster_seq_number, NULL, 0);
+                               probed = 1;
+                       }
+               }
+       } else {        // We got a recent heartbeat; reset the probe flag.
+               probed = 0;
+       }
 
        if (TIME < (config->cluster_last_hb + config->cluster_hb_timeout) )
                return;         // Everything's ok. return.
 
        if (TIME < (config->cluster_last_hb + config->cluster_hb_timeout) )
                return;         // Everything's ok. return.
@@ -770,8 +785,8 @@ void cluster_heartbeat(int highsession, int freesession, int hightunnel)
                kill(0, SIGTERM);
        }
 
                kill(0, SIGTERM);
        }
 
-       log(3,0,0,0, "Sending heartbeat with %d changes (%d x-sess, %d x-tunnels, %d highsess, %d hightun size %d)\n",
-                       config->cluster_num_changes, count, tcount, config->cluster_highest_sessionid,
+       log(3,0,0,0, "Sending heartbeat #%d with %d changes (%d x-sess, %d x-tunnels, %d highsess, %d hightun size %d)\n",
+                       h.seq, config->cluster_num_changes, count, tcount, config->cluster_highest_sessionid,
                        config->cluster_highest_tunnelid, (p-buff));
 
        config->cluster_num_changes = 0;
                        config->cluster_highest_tunnelid, (p-buff));
 
        config->cluster_num_changes = 0;
@@ -1068,16 +1083,18 @@ static int cluster_process_heartbeat_v2(u8 * data, int size, int more, u8 * p, u
 
                log(0,0,0,0, "I just got a packet claiming to be from a master but _I_ am the master!\n");
                if (!h->basetime) {
 
                log(0,0,0,0, "I just got a packet claiming to be from a master but _I_ am the master!\n");
                if (!h->basetime) {
-                       log(0,0,0,0, "Heartbeat from addr %s with zero basetime!\n", inet_toa(htonl(addr)) );
+                       log(0,0,0,0, "Heartbeat from addr %s with zero basetime!\n", inet_toa(addr) );
                        return -1; // Skip it.
                }
                if (basetime > h->basetime) {
                        return -1; // Skip it.
                }
                if (basetime > h->basetime) {
-                       log(0,0,0,0, "They're (%s) an older master than me so I'm gone!\n", inet_toa(htonl(addr)));
+                       log(0,0,0,0, "They're (%s) an older master than me so I'm gone!\n", inet_toa(addr));
                        kill(0, SIGTERM);
                        kill(0, SIGTERM);
+                       exit(1);
                }
                if (basetime == h->basetime && my_address < addr) { // Tie breaker.
                        log(0,0,0,0, "They're a higher IP address than me, so I'm gone!\n");
                        kill(0, SIGTERM);
                }
                if (basetime == h->basetime && my_address < addr) { // Tie breaker.
                        log(0,0,0,0, "They're a higher IP address than me, so I'm gone!\n");
                        kill(0, SIGTERM);
+                       exit(1);
                }
                return -1; // Skip it.
        }
                }
                return -1; // Skip it.
        }