X-Git-Url: http://git.sameswireless.fr/l2tpns.git/blobdiff_plain/3aa4eda8b1e0c4abc04439affe850d33648c7472..b5fc98195ba4cbe922bf51dff6911113f205df97:/cluster_master.c?ds=sidebyside diff --git a/cluster_master.c b/cluster_master.c index c2bc501..31e9332 100644 --- a/cluster_master.c +++ b/cluster_master.c @@ -1,5 +1,5 @@ // L2TPNS Cluster Master -// $Id: cluster_master.c,v 1.1 2003/12/16 07:07:39 fred_nerk Exp $ +// $Id: cluster_master.c,v 1.3 2004/05/24 04:12:34 fred_nerk Exp $ #include #include @@ -51,12 +51,13 @@ int handle_hello(char *buf, int l, struct sockaddr_in *src_addr, uint32_t addr); int handle_tunnel(char *buf, int l, uint32_t addr); int handle_session(char *buf, int l, uint32_t addr); int handle_ping(char *buf, int l, uint32_t addr); +int handle_goodbye(char *buf, int l, uint32_t addr); int backup_up(slave *s); int backup_down(slave *s); int return_state(slave *s); slave *find_slave(uint32_t address); #define log _log -void _log(int level, const char *format, ...); +void _log(int level, const char *format, ...) __attribute__((format (printf, 2, 3))); void log_hex(int level, const char *title, const char *data, int maxsize); /* Catch our forked processes exiting */ @@ -91,7 +92,7 @@ int main(int argc, char *argv[]) signal(SIGCHLD, sigchild_handler); - log(0, "Cluster Manager $Id: cluster_master.c,v 1.1 2003/12/16 07:07:39 fred_nerk Exp $ starting\n"); + log(0, "Cluster Manager $Id: cluster_master.c,v 1.3 2004/05/24 04:12:34 fred_nerk Exp $ starting\n"); to.tv_sec = 1; to.tv_usec = 0; @@ -156,6 +157,7 @@ int main(int argc, char *argv[]) int processmsg(char *buf, int l, struct sockaddr_in *src_addr) { + slave *s; char mtype; uint32_t addr; @@ -168,6 +170,16 @@ int processmsg(char *buf, int l, struct sockaddr_in *src_addr) mtype = *buf; buf++; l--; + if (mtype != C_GOODBYE && (s = find_slave(addr)) && s->down) + { + char *hostname; + hostname = calloc(l + 1, 1); + memcpy(hostname, buf, l); + log(1, "Slave \"%s\" (for %s) has come back.\n", hostname, inet_toa(s->ip_address)); + backup_down(s); + free(hostname); + } + switch (mtype) { case C_HELLO: @@ -187,6 +199,10 @@ int processmsg(char *buf, int l, struct sockaddr_in *src_addr) if (!find_slave(addr)) handle_hello((char *)(buf + 1), *(char *)buf, src_addr, addr); handle_session(buf, l, addr); break; + case C_GOODBYE: + if (!find_slave(addr)) break; + handle_goodbye(buf, l, addr); + break; } return mtype; } @@ -478,3 +494,24 @@ int backup_down(slave *s) return 0; } +int handle_goodbye(char *buf, int l, uint32_t addr) +{ + int i; + slave *s; + + // Is this a slave we have state information for? + if ((s = find_slave(addr))) + { + log(0, "Received goodbye for slave %s\n", s->hostname); + ll_delete(slaves, s); + for (i = 0; i < s->num_tunnels; i++) + if (s->tunnels[i]) free(s->tunnels[i]); + for (i = 0; i < s->num_sessions; i++) + if (s->sessions[i]) free(s->sessions[i]); + if (s->hostname) free(s->hostname); + free(s); + } + + return 0; +} +