// 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.3 2004/03/05 00:22:06 fred_nerk Exp $
#include <stdio.h>
#include <netinet/in.h>
#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);
{
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", l, sizeof(tunnelt));
+ 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);
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);
{
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", l, sizeof(tunnelt));
+ 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);
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;
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;