X-Git-Url: http://git.sameswireless.fr/l2tpns.git/blobdiff_plain/4e0597cd50268bc57fa118f1362360a2db2ec23a..a5da286a96eeddee654861fd1da18735d26b9bf7:/cluster.c diff --git a/cluster.c b/cluster.c index ca9b241..f15127d 100644 --- a/cluster.c +++ b/cluster.c @@ -1,6 +1,6 @@ // 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 #include @@ -67,8 +67,8 @@ static struct { } 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 @@ -147,7 +147,7 @@ int cluster_init() // address ). // -int cluster_send_data(void *data, int datalen) +static int cluster_send_data(void *data, int datalen) { struct sockaddr_in addr = {0}; @@ -188,7 +188,19 @@ static void add_type(char ** p, int type, int more, char * data, int size) } } -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; @@ -199,21 +211,14 @@ void cluster_uptodate(void) 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}; @@ -241,7 +246,7 @@ int peer_send_data(u32 peer, char * data, int size) // // 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; @@ -456,11 +461,9 @@ void cluster_check_slaves(void) } #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 */ } @@ -610,6 +613,9 @@ void cluster_check_master(void) 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. @@ -675,7 +681,7 @@ static void cluster_check_sessions(int highsession, int freesession_ptr, int hig 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. @@ -825,7 +831,7 @@ void cluster_heartbeat() // // 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; @@ -873,7 +879,7 @@ int cluster_send_tunnel(int tid) // 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; @@ -908,7 +914,7 @@ int cluster_catchup_slave(int seq, u32 slave) // 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; @@ -992,7 +998,7 @@ int cluster_add_peer(u32 peer, time_t basetime, pingt *pp, int size) // 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; @@ -1445,7 +1451,7 @@ int cmd_show_cluster(struct cli_def *cli, char *command, char **argv, int argc) // // 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; @@ -1491,7 +1497,7 @@ int rle_compress(u8 ** src_p, int ssize, u8 *dst, int 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;