X-Git-Url: http://git.sameswireless.fr/l2tpns.git/blobdiff_plain/e9111645af13262ae2bcdd92601f3b672ee0a00d..5ff54415c95f70115272ea65263e1a4a654da57e:/cluster.c diff --git a/cluster.c b/cluster.c index 6f72394..48c2059 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.6 2005/05/21 13:05:36 bodea Exp $"; +char const *cvs_id_cluster = "$Id: cluster.c,v 1.26.2.9 2005/05/23 12:48:17 bodea Exp $"; #include #include @@ -903,11 +903,10 @@ static int cluster_catchup_slave(int seq, in_addr_t slave) LOG(1, 0, 0, "Slave %s sent LASTSEEN with seq %d\n", fmtaddr(slave, 0), seq); if (!config->cluster_iam_master) { - LOG(1, 0, 0, "Got LASTSEEN but I'm not a master! Sending a null PING.\n"); - // Send a ping to the stray slave saying that we're a master that's - // just shutdown. This should force the slave to listen for the real - // master. - peer_send_message(slave, C_PING, 0, NULL, 0); + LOG(1, 0, 0, "Got LASTSEEN but I'm not a master! Redirecting it to %s.\n", + fmtaddr(config->cluster_master_address, 0)); + + peer_send_message(slave, C_MASTER, config->cluster_master_address, NULL, 0); return 0; } @@ -978,8 +977,10 @@ static int cluster_add_peer(in_addr_t peer, time_t basetime, pingt *pp, int size } // Is this the master shutting down?? - if (peer == config->cluster_master_address && !basetime) { - LOG(3, 0, 0, "Master %s shutting down...\n", fmtaddr(config->cluster_master_address, 0)); + if (peer == config->cluster_master_address) { + LOG(3, 0, 0, "Master %s %s\n", fmtaddr(config->cluster_master_address, 0), + basetime ? "has restarted!" : "shutting down..."); + config->cluster_master_address = 0; config->cluster_last_hb = 0; // Force an election. cluster_check_master(); @@ -1020,6 +1021,20 @@ static int cluster_add_peer(in_addr_t peer, time_t basetime, pingt *pp, int size return 1; } +// A slave responds with C_MASTER when it gets a message which should have gone to a master. +static int cluster_set_master(in_addr_t peer, in_addr_t master) +{ + if (config->cluster_iam_master) // Sanity... + return 0; + + LOG(3, 0, 0, "Peer %s set the master to %s...\n", fmtaddr(peer, 0), + fmtaddr(master, 1)); + + config->cluster_master_address = master; + cluster_check_master(); + return 0; +} + /* Handle the slave updating the byte counters for the master. */ // // Note that we don't mark the session as dirty; We rely on @@ -1394,10 +1409,13 @@ int processcluster(char *data, int size, in_addr_t addr) s -= sizeof(uint32_t); switch (type) { - case C_PING: // Update the peers table. + case C_PING: // Update the peers table. return cluster_add_peer(addr, more, (pingt *) p, s); - case C_LASTSEEN: // Catch up a slave (slave missed a packet). + case C_MASTER: // Our master is wrong + return cluster_set_master(addr, more); + + case C_LASTSEEN: // Catch up a slave (slave missed a packet). return cluster_catchup_slave(more, addr); case C_FORWARD: { // Forwarded control packet. pass off to processudp. @@ -1438,6 +1456,11 @@ int processcluster(char *data, int size, in_addr_t addr) return 0; case C_BYTES: + if (!config->cluster_iam_master) { + LOG(0, 0, 0, "I'm not the master, but I got a C_BYTES from %s?\n", fmtaddr(addr, 0)); + return -1; + } + return cluster_handle_bytes(p, s); case C_KILL: // The master asked us to die!? (usually because we're too out of date).