X-Git-Url: http://git.sameswireless.fr/l2tpns.git/blobdiff_plain/12f5781dc3df401e4dfe574dd12c0583349fd140..cd4f292462c2be94ec825ee1cfbb4abe09f73b96:/cluster.c?ds=sidebyside diff --git a/cluster.c b/cluster.c index 28b878e..4497f69 100644 --- a/cluster.c +++ b/cluster.c @@ -1,6 +1,6 @@ // L2TPNS Clustering Stuff -char const *cvs_id_cluster = "$Id: cluster.c,v 1.20 2004/12/03 06:40:02 bodea Exp $"; +char const *cvs_id_cluster = "$Id: cluster.c,v 1.24 2004/12/15 02:56:38 bodea Exp $"; #include #include @@ -81,7 +81,7 @@ int cluster_init() struct sockaddr_in interface_addr; struct ip_mreq mreq; struct ifreq ifr; - int opt = 0; + int opt; config->cluster_undefined_sessions = MAXSESSION-1; config->cluster_undefined_tunnels = MAXTUNNEL-1; @@ -99,6 +99,9 @@ int cluster_init() addr.sin_addr.s_addr = INADDR_ANY; setsockopt(cluster_sockfd, SOL_SOCKET, SO_REUSEADDR, &addr, sizeof(addr)); + opt = fcntl(cluster_sockfd, F_GETFL, 0); + fcntl(cluster_sockfd, F_SETFL, opt | O_NONBLOCK); + if (bind(cluster_sockfd, (void *) &addr, sizeof(addr)) < 0) { LOG(0, 0, 0, "Failed to bind cluster socket: %s\n", strerror(errno)); @@ -129,7 +132,7 @@ int cluster_init() return -1; } - if (setsockopt (cluster_sockfd, IPPROTO_IP, IP_MULTICAST_IF, &interface_addr, sizeof(interface_addr)) < 0) + if (setsockopt(cluster_sockfd, IPPROTO_IP, IP_MULTICAST_IF, &interface_addr, sizeof(interface_addr)) < 0) { LOG(0, 0, 0, "Failed to setsockopt (set mcast interface): %s\n", strerror(errno)); return -1; @@ -896,7 +899,7 @@ static int cluster_catchup_slave(int seq, u32 slave) diff += HB_MAX_SEQ; if (diff >= HB_HISTORY_SIZE) { // Ouch. We don't have the packet to send it! - LOG(0, 0, 0, "A slaved asked for message %d when our seq number is %d. Killing it.\n", + LOG(0, 0, 0, "A slave asked for message %d when our seq number is %d. Killing it.\n", seq, config->cluster_seq_number); return peer_send_message(slave, C_KILL, seq, NULL, 0);// Kill the slave. Nothing else to do. } @@ -1138,23 +1141,34 @@ static int cluster_process_heartbeat(u8 * data, int size, int more, u8 * p, u32 LOG(0, 0, 0, "Heartbeat with zero basetime! Ignoring\n"); return -1; // Skip it. } - if (more >= 4 && h->table_version > config->cluster_table_version) { - LOG(0, 0, 0, "They've seen more state changes (%llu vs my %llu) so I'm gone!\n", - h->table_version, config->cluster_table_version); - kill(0, SIGTERM); - exit(1); + if (more >= 4) { + if (h->table_version > config->cluster_table_version) { + LOG(0, 0, 0, "They've seen more state changes (%llu vs my %llu) so I'm gone!\n", + h->table_version, config->cluster_table_version); + + kill(0, SIGTERM); + exit(1); + } + if (h->table_version < config->cluster_table_version) + return -1; } + if (basetime > h->basetime) { LOG(0, 0, 0, "They're an older master than me so I'm gone!\n"); kill(0, SIGTERM); exit(1); } - if (basetime == h->basetime && my_address < addr) { // Tie breaker. + + if (basetime < h->basetime) + return -1; + + if (my_address < addr) { // Tie breaker. LOG(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. }