X-Git-Url: http://git.sameswireless.fr/l2tpns.git/blobdiff_plain/c5e4c2cfc092317c1e3ceb0f654f880f6a8573f4..11627344e7bbceb18bb9c06b3707a6e04610265e:/cluster_slave.c diff --git a/cluster_slave.c b/cluster_slave.c index 71e2eac..1ed03b0 100644 --- a/cluster_slave.c +++ b/cluster_slave.c @@ -1,5 +1,5 @@ // L2TPNS Cluster Master -// $Id: cluster_slave.c,v 1.1 2003-12-16 07:07:39 fred_nerk Exp $ +// $Id: cluster_slave.c,v 1.4 2004-05-24 04:12:48 fred_nerk Exp $ #include #include @@ -19,16 +19,13 @@ #include "ll.h" #include "util.h" +// vim: sw=4 ts=8 + extern int cluster_sockfd; -extern tunnelt *tunnel; -extern sessiont *session; -extern uint32_t cluster_address; extern char hostname[1000]; -extern int debug; extern ippoolt *ip_address_pool; extern uint32_t vip_address; -extern tunnelidt tunnelfree; -extern sessionidt sessionfree; +extern struct configt *config; int handle_tunnel(char *buf, int l); int handle_session(char *buf, int l); @@ -78,6 +75,13 @@ int handle_tunnel(char *buf, int l) { int t; + // Ignore tunnel message if NOSTATEFILE exists + if (config->ignore_cluster_updates) + { + log(1, 0, 0, 0, "Discarding tunnel message from cluster master.\n"); + return 0; + } + t = *(int *)buf; log(1, 0, 0, t, "Receiving tunnel %d from cluster master (%d bytes)\n", t, l); buf += sizeof(int); l -= sizeof(int); @@ -94,16 +98,6 @@ int handle_tunnel(char *buf, int l) return 0; } - if (t > 1) - { - tunnel[t-1].next = tunnel[t].next; - } - - if (tunnelfree == t) - { - tunnelfree = tunnel[t].next; - } - memcpy(&tunnel[t], buf, l); log(3, 0, 0, t, "Cluster master sent tunnel for %s\n", tunnel[t].hostname); @@ -117,6 +111,13 @@ int handle_session(char *buf, int l) { int s; + // Ignore tunnel message if NOSTATEFILE exists + if (config->ignore_cluster_updates) + { + log(1, 0, 0, 0, "Discarding session message from cluster master.\n"); + return 0; + } + s = *(int *)buf; log(1, 0, s, 0, "Receiving session %d from cluster master (%d bytes)\n", s, l); buf += sizeof(int); l -= sizeof(int); @@ -214,7 +215,7 @@ int cluster_send_session(int s) memcpy((char *)(packet + len), &session[s], sizeof(sessiont)); len += sizeof(sessiont); - cluster_send_message(cluster_address, vip_address, C_SESSION, packet, len); + cluster_send_message(config->cluster_address, vip_address, C_SESSION, packet, len); free(packet); return 1; @@ -241,7 +242,27 @@ int cluster_send_tunnel(int t) memcpy((char *)(packet + len), &tunnel[t], sizeof(tunnelt)); len += sizeof(tunnelt); - cluster_send_message(cluster_address, vip_address, C_TUNNEL, packet, len); + cluster_send_message(config->cluster_address, vip_address, C_TUNNEL, packet, len); + free(packet); + + return 1; +} + +int cluster_send_goodbye() +{ + char *packet; + int len = 0; + + packet = malloc(4096); + + log(2, 0, 0, 0, "Sending goodbye to cluster master\n"); + // Hostname + len = strlen(hostname); + *(char *)packet = len; + memcpy((char *)(packet + 1), hostname, len); + len++; + + cluster_send_message(config->cluster_address, vip_address, C_GOODBYE, packet, len); free(packet); return 1;