// L2TPNS Clustering Stuff
-char const *cvs_id_cluster = "$Id: cluster.c,v 1.16 2004-11-05 04:55:26 bodea Exp $";
+char const *cvs_id_cluster = "$Id: cluster.c,v 1.18 2004-11-16 07:54:32 bodea Exp $";
#include <stdio.h>
#include <sys/file.h>
} peers[CLUSTER_MAX_SIZE]; // List of all the peers we've heard from.
static int num_peers; // Number of peers in list.
-int rle_decompress(u8 ** src_p, int ssize, u8 *dst, int dsize);
-int rle_compress(u8 ** src_p, int ssize, u8 *dst, int dsize);
+static int rle_decompress(u8 ** src_p, int ssize, u8 *dst, int dsize);
+static int rle_compress(u8 ** src_p, int ssize, u8 *dst, int dsize);
//
// Create a listening socket
// address ).
//
-int cluster_send_data(void *data, int datalen)
+static int cluster_send_data(void *data, int datalen)
{
struct sockaddr_in addr = {0};
}
}
-void cluster_uptodate(void)
+// advertise our presence via BGP or gratuitous ARP
+static void advertise(void)
+{
+#ifdef BGP
+ if (bgp_configured)
+ bgp_enable_routing(1);
+ else
+#endif /* BGP */
+ if (config->send_garp)
+ send_garp(config->bind_address); // Start taking traffic.
+}
+
+static void cluster_uptodate(void)
{
if (config->cluster_iam_uptodate)
return;
config->cluster_iam_uptodate = 1;
LOG(0,0,0,0, "Now uptodate with master.\n");
-
-#ifdef BGP
- if (bgp_configured)
- bgp_enable_routing(1);
- else
-#endif /* BGP */
- if (config->send_garp)
- send_garp(config->bind_address); // Start taking traffic.
+ advertise();
}
//
// Send a unicast UDP packet to a peer with 'data' as the
// contents.
//
-int peer_send_data(u32 peer, char * data, int size)
+static int peer_send_data(u32 peer, char * data, int size)
{
struct sockaddr_in addr = {0};
//
// Send a structured message to a peer with a single element of type 'type'.
//
-int peer_send_message(u32 peer, int type, int more, char * data, int size)
+static int peer_send_message(u32 peer, int type, int more, char * data, int size)
{
char buf[65536]; // Vast overkill.
char * p = buf;
}
#ifdef BGP
- // master lost all slaves, need to handle traffic ourself
- if (bgp_configured && had_peers && !have_peers)
- bgp_enable_routing(1);
- else if (bgp_configured && !had_peers && have_peers)
- bgp_enable_routing(0);
+ // in a cluster, withdraw/add routes when we get a peer/lose all peers
+ if (bgp_configured && have_peers != had_peers)
+ bgp_enable_routing(!have_peers);
#endif /* BGP */
}
config->cluster_undefined_tunnels = 0;
config->cluster_iam_uptodate = 1; // assume all peers are up-to-date
+ if (!num_peers) // lone master
+ advertise();
+
// FIXME. We need to fix up the tunnel control message
// queue here! There's a number of other variables we
// should also update.
cluster_uptodate();
}
-int hb_add_type(char **p, int type, int id)
+static int hb_add_type(char **p, int type, int id)
{
switch (type) {
case C_CSESSION: { // Compressed C_SESSION.
//
// A structure of type 'type' has changed; Add it to the queue to send.
//
-int type_changed(int type, int id)
+static int type_changed(int type, int id)
{
int i;
// missed a packet. We'll resend it every packet since
// the last one it's seen.
//
-int cluster_catchup_slave(int seq, u32 slave)
+static int cluster_catchup_slave(int seq, u32 slave)
{
int s;
int diff;
// We've heard from another peer! Add it to the list
// that we select from at election time.
//
-int cluster_add_peer(u32 peer, time_t basetime, pingt *pp, int size)
+static int cluster_add_peer(u32 peer, time_t basetime, pingt *pp, int size)
{
int i;
u32 clusterid;
// Note that we don't mark the session as dirty; We rely on
// the slow table walk to propogate this back out to the slaves.
//
-int cluster_handle_bytes(char * data, int size)
+static int cluster_handle_bytes(char * data, int size)
{
bytest * b;
//
// Worst case is a 50% expansion in space required (trying to
// compress { 0x00, 0x01 } * N )
-int rle_compress(u8 ** src_p, int ssize, u8 *dst, int dsize)
+static int rle_compress(u8 ** src_p, int ssize, u8 *dst, int dsize)
{
int count;
int orig_dsize = dsize;
// Return the number of dst bytes used.
// Updates the 'src_p' pointer to point to the
// first un-used byte.
-int rle_decompress(u8 ** src_p, int ssize, u8 *dst, int dsize)
+static int rle_decompress(u8 ** src_p, int ssize, u8 *dst, int dsize)
{
int count;
int orig_dsize = dsize;