X-Git-Url: http://git.sameswireless.fr/l2tpns.git/blobdiff_plain/5ff54415c95f70115272ea65263e1a4a654da57e..aa77d4f89aa291e851c9be8a64ecfdb1434e83c9:/cluster.c diff --git a/cluster.c b/cluster.c index 48c2059..8f9c01e 100644 --- a/cluster.c +++ b/cluster.c @@ -1,6 +1,6 @@ // L2TPNS Clustering Stuff -char const *cvs_id_cluster = "$Id: cluster.c,v 1.26.2.9 2005/05/23 12:48:17 bodea Exp $"; +char const *cvs_id_cluster = "$Id: cluster.c,v 1.26.2.12 2005/07/03 02:58:06 bodea Exp $"; #include #include @@ -192,7 +192,7 @@ static void add_type(char **p, int type, int more, char *data, int size) } // advertise our presence via BGP or gratuitous ARP -static void advertise(void) +static void advertise_routes(void) { #ifdef BGP if (bgp_configured) @@ -203,6 +203,15 @@ static void advertise(void) send_garp(config->bind_address); // Start taking traffic. } +// withdraw our routes (BGP only) +static void withdraw_routes(void) +{ +#ifdef BGP + if (bgp_configured) + bgp_enable_routing(0); +#endif /* BGP */ +} + static void cluster_uptodate(void) { if (config->cluster_iam_uptodate) @@ -214,7 +223,7 @@ static void cluster_uptodate(void) config->cluster_iam_uptodate = 1; LOG(0, 0, 0, "Now uptodate with master.\n"); - advertise(); + advertise_routes(); } // @@ -456,17 +465,22 @@ void cluster_check_slaves(void) continue; // Shutdown peer! Skip them. if (peers[i].uptodate) - have_peers = 1; - - if (!peers[i].uptodate) + have_peers++; + else config->cluster_iam_uptodate = 0; // Start fast heartbeats } -#ifdef BGP - // in a cluster, withdraw/add routes when we get a peer/lose all peers - if (bgp_configured && have_peers != had_peers) - bgp_enable_routing(!have_peers); -#endif /* BGP */ + // in a cluster, withdraw/add routes when we get a peer/lose peers + if (have_peers != had_peers) + { + if (had_peers < config->cluster_master_min_adv && + have_peers >= config->cluster_master_min_adv) + withdraw_routes(); + + else if (had_peers >= config->cluster_master_min_adv && + have_peers < config->cluster_master_min_adv) + advertise_routes(); + } } // @@ -479,6 +493,7 @@ void cluster_check_master(void) int last_free = 0; clockt t = TIME; static int probed = 0; + int have_peers; if (config->cluster_iam_master) return; // Only runs on the slaves... @@ -508,10 +523,15 @@ void cluster_check_master(void) return; // Everything's ok! config->cluster_last_hb = TIME + 1; // Just the one election thanks. + config->cluster_master_address = 0; LOG(0, 0, 0, "Master timed out! Holding election...\n"); - for (i = 0; i < num_peers; i++) + // In the process of shutting down, can't be master + if (main_quit) + return; + + for (i = have_peers = 0; i < num_peers; i++) { if ((peers[i].timestamp + config->cluster_hb_timeout) < t) continue; // Stale peer! Skip them. @@ -529,6 +549,9 @@ void cluster_check_master(void) LOG(1, 0, 0, "Expecting %s to become master\n", fmtaddr(peers[i].peer, 0)); return; // They'll win the election. Wait for them to come up. } + + if (peers[i].uptodate) + have_peers++; } // Wow. it's been ages since I last heard a heartbeat @@ -536,10 +559,14 @@ void cluster_check_master(void) // to become a master!!! config->cluster_iam_master = 1; - config->cluster_master_address = 0; LOG(0, 0, 0, "I am declaring myself the master!\n"); + if (have_peers < config->cluster_master_min_adv) + advertise_routes(); + else + withdraw_routes(); + if (config->cluster_seq_number == -1) config->cluster_seq_number = 0; @@ -620,14 +647,6 @@ void cluster_check_master(void) config->cluster_undefined_tunnels = 0; config->cluster_iam_uptodate = 1; // assume all peers are up-to-date - if (!num_peers) // lone master - advertise(); -#ifdef BGP - else if (bgp_configured) - bgp_enable_routing(0); -#endif /* BGP */ - - // FIXME. We need to fix up the tunnel control message // queue here! There's a number of other variables we // should also update. @@ -1224,8 +1243,7 @@ static int cluster_process_heartbeat(uint8_t *data, int size, int more, uint8_t // Note that after a clean failover, the cluster_master_address // is cleared, so this doesn't run. // - if (config->cluster_master_address && addr != config->cluster_master_address - && (config->cluster_last_hb + config->cluster_hb_timeout - 11) > TIME) { + if (config->cluster_master_address && addr != config->cluster_master_address) { LOG(0, 0, 0, "Ignoring stray heartbeat from %s, current master %s has not yet timed out (last heartbeat %.1f seconds ago).\n", fmtaddr(addr, 0), fmtaddr(config->cluster_master_address, 1), 0.1 * (TIME - config->cluster_last_hb));