From: Guus Sliepen Date: Wed, 4 Sep 2002 16:26:45 +0000 (+0000) Subject: Generalized request broadcasting/forwarding. X-Git-Tag: release-1.0pre8~30 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=8b2b67e26c5b971761f5015764d5e188f6343bc4;p=oweals%2Ftinc.git Generalized request broadcasting/forwarding. --- diff --git a/src/connection.c b/src/connection.c index e8a53ec..642bfac 100644 --- a/src/connection.c +++ b/src/connection.c @@ -17,7 +17,7 @@ along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - $Id: connection.c,v 1.1.2.30 2002/06/21 10:11:12 guus Exp $ + $Id: connection.c,v 1.1.2.31 2002/09/04 16:26:44 guus Exp $ */ #include "config.h" @@ -41,6 +41,7 @@ #include "system.h" avl_tree_t *connection_tree; /* Meta connections */ +connection_t *broadcast; int connection_compare(connection_t *a, connection_t *b) { @@ -51,6 +52,10 @@ void init_connections(void) { cp connection_tree = avl_alloc_tree((avl_compare_t)connection_compare, NULL); +cp + broadcast = new_connection(); + broadcast->name = xstrdup(_("everyone")); + broadcast->hostname = xstrdup(_("BROADCAST")); cp } @@ -58,6 +63,8 @@ void exit_connections(void) { cp avl_delete_tree(connection_tree); +cp + free_connection(broadcast); cp } diff --git a/src/connection.h b/src/connection.h index a6d8c58..4d2ea2d 100644 --- a/src/connection.h +++ b/src/connection.h @@ -17,7 +17,7 @@ along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - $Id: connection.h,v 1.1.2.29 2002/09/04 13:48:51 guus Exp $ + $Id: connection.h,v 1.1.2.30 2002/09/04 16:26:44 guus Exp $ */ #ifndef __TINC_CONNECTION_H__ @@ -99,6 +99,7 @@ typedef struct connection_t { char buffer[MAXBUFSIZE]; /* metadata input buffer */ int buflen; /* bytes read into buffer */ + int reqlen; /* length of incoming request */ int tcplen; /* length of incoming TCPpacket */ int allow_request; /* defined if there's only one request possible */ @@ -108,6 +109,7 @@ typedef struct connection_t { } connection_t; extern avl_tree_t *connection_tree; +extern connection_t *broadcast; extern void init_connections(void); extern void exit_connections(void); diff --git a/src/meta.c b/src/meta.c index 8d6b0a8..c3d4f82 100644 --- a/src/meta.c +++ b/src/meta.c @@ -17,7 +17,7 @@ along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - $Id: meta.c,v 1.1.2.26 2002/06/21 10:11:12 guus Exp $ + $Id: meta.c,v 1.1.2.27 2002/09/04 16:26:44 guus Exp $ */ #include "config.h" @@ -182,6 +182,7 @@ cp if(reqlen) { + c->reqlen = reqlen; if(receive_request(c)) return -1; diff --git a/src/net.c b/src/net.c index 4a5c4b9..13933d9 100644 --- a/src/net.c +++ b/src/net.c @@ -17,7 +17,7 @@ along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - $Id: net.c,v 1.35.4.176 2002/09/04 13:48:51 guus Exp $ + $Id: net.c,v 1.35.4.177 2002/09/04 16:26:44 guus Exp $ */ #include "config.h" @@ -87,11 +87,10 @@ time_t now = 0; void purge(void) { - avl_node_t *nnode, *nnext, *enode, *enext, *snode, *snext, *cnode; + avl_node_t *nnode, *nnext, *enode, *enext, *snode, *snext; node_t *n; edge_t *e; subnet_t *s; - connection_t *c; cp if(debug_lvl >= DEBUG_PROTOCOL) syslog(LOG_DEBUG, _("Purging unreachable nodes")); @@ -110,14 +109,7 @@ cp { snext = snode->next; s = (subnet_t *)snode->data; - - for(cnode = connection_tree->head; cnode; cnode = cnode->next) - { - c = (connection_t *)cnode->data; - if(c->status.active) - send_del_subnet(c, s); - } - + send_del_subnet(broadcast, s); subnet_del(n, s); } @@ -125,14 +117,7 @@ cp { enext = enode->next; e = (edge_t *)enode->data; - - for(cnode = connection_tree->head; cnode; cnode = cnode->next) - { - c = (connection_t *)cnode->data; - if(c->status.active) - send_del_edge(c, e); - } - + send_del_edge(broadcast, e); edge_del(e); } @@ -188,8 +173,6 @@ cp */ void terminate_connection(connection_t *c, int report) { - avl_node_t *node; - connection_t *other; cp if(c->status.remove) return; @@ -210,14 +193,7 @@ cp if(c->edge) { if(report) - { - for(node = connection_tree->head; node; node = node->next) - { - other = (connection_t *)node->data; - if(other->status.active && other != c) - send_del_edge(other, c->edge); - } - } + send_del_edge(broadcast, c->edge); edge_del(c->edge); @@ -407,7 +383,7 @@ cp syslog(LOG_INFO, _("Regenerating symmetric key")); RAND_pseudo_bytes(myself->key, myself->keylength); - send_key_changed(myself->connection, myself); + send_key_changed(broadcast, myself); keyexpires = now + keylifetime; } } diff --git a/src/protocol.c b/src/protocol.c index 644e89e..4127f51 100644 --- a/src/protocol.c +++ b/src/protocol.c @@ -17,7 +17,7 @@ along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - $Id: protocol.c,v 1.28.4.132 2002/09/04 13:48:52 guus Exp $ + $Id: protocol.c,v 1.28.4.133 2002/09/04 16:26:44 guus Exp $ */ #include "config.h" @@ -89,7 +89,28 @@ cp buffer[len++] = '\n'; cp - return send_meta(c, buffer, len); + if(c == broadcast) + return broadcast_meta(NULL, buffer, len); + else + return send_meta(c, buffer, len); +} + +int forward_request(connection_t *from) +{ + int request; +cp + if(debug_lvl >= DEBUG_PROTOCOL) + { + sscanf(from->buffer, "%d", &request); + if(debug_lvl >= DEBUG_META) + syslog(LOG_DEBUG, _("Broadcasting %s from %s (%s): %s"), request_name[request], from->name, from->hostname, from->buffer); + else + syslog(LOG_DEBUG, _("Broadcasting %s from %s (%s)"), request_name[request], from->name, from->hostname); + } + + from->buffer[from->reqlen - 1] = '\n'; +cp + return broadcast_meta(from, from->buffer, from->reqlen); } int receive_request(connection_t *c) diff --git a/src/protocol.h b/src/protocol.h index a021f4f..47f772c 100644 --- a/src/protocol.h +++ b/src/protocol.h @@ -17,7 +17,7 @@ along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - $Id: protocol.h,v 1.5.4.33 2002/09/04 13:48:52 guus Exp $ + $Id: protocol.h,v 1.5.4.34 2002/09/04 16:26:45 guus Exp $ */ #ifndef __TINC_PROTOCOL_H__ @@ -62,6 +62,7 @@ typedef struct past_request_t { /* Basic functions */ extern int send_request(connection_t*, const char*, ...); +extern int forward_request(connection_t *); extern int receive_request(connection_t *); extern int check_id(char *); diff --git a/src/protocol_auth.c b/src/protocol_auth.c index 42d35e9..4456ea5 100644 --- a/src/protocol_auth.c +++ b/src/protocol_auth.c @@ -17,7 +17,7 @@ along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - $Id: protocol_auth.c,v 1.1.4.13 2002/09/04 14:17:28 guus Exp $ + $Id: protocol_auth.c,v 1.1.4.14 2002/09/04 16:26:45 guus Exp $ */ #include "config.h" @@ -483,7 +483,7 @@ void send_everything(connection_t *c) subnet_t *s; edge_t *e; - /* Send all known subnets */ + /* Send all known subnets and edges */ for(node = node_tree->head; node; node = node->next) { @@ -494,15 +494,12 @@ void send_everything(connection_t *c) s = (subnet_t *)node2->data; send_add_subnet(c, s); } - } - - /* Send all known edges */ - for(node = edge_tree->head; node; node = node->next) - { - e = (edge_t *)node->data; - - send_add_edge(c, e); + for(node2 = n->edge_tree->head; node2; node2 = node2->next) + { + e = (edge_t *)node2->data; + send_add_edge(c, e); + } } } @@ -513,8 +510,6 @@ int ack_h(connection_t *c) int weight; long int options; node_t *n; - connection_t *other; - avl_node_t *node; cp if(sscanf(c->buffer, "%*d "MAX_STRING" %d %lx", hisport, &weight, &options) != 3) { @@ -541,14 +536,24 @@ cp syslog(LOG_DEBUG, _("Established a second connection with %s (%s), closing old connection"), n->name, n->hostname); terminate_connection(n->connection, 0); } - - /* FIXME: check if information in existing node matches that of the other end of this connection */ } n->connection = c; c->node = n; c->options |= options; + /* Activate this connection */ + + c->allow_request = ALL; + c->status.active = 1; + + if(debug_lvl >= DEBUG_CONNECTIONS) + syslog(LOG_NOTICE, _("Connection with %s (%s) activated"), c->name, c->hostname); + + /* Send him everything we know */ + + send_everything(c); + /* Create an edge_t for this connection */ c->edge = new_edge(); @@ -565,28 +570,10 @@ cp cp edge_add(c->edge); - /* Activate this connection */ - - c->allow_request = ALL; - c->status.active = 1; - - if(debug_lvl >= DEBUG_CONNECTIONS) - syslog(LOG_NOTICE, _("Connection with %s (%s) activated"), c->name, c->hostname); - cp - /* Send him everything we know */ - - send_everything(c); + /* Notify everyone of the new edge */ - /* Notify others of this connection */ - - for(node = connection_tree->head; node; node = node->next) - { - other = (connection_t *)node->data; - - if(other->status.active && other != c) - send_add_edge(other, c->edge); - } + send_add_edge(broadcast, c->edge); /* Run MST and SSSP algorithms */ diff --git a/src/protocol_edge.c b/src/protocol_edge.c index 9b35a9f..7663a46 100644 --- a/src/protocol_edge.c +++ b/src/protocol_edge.c @@ -17,7 +17,7 @@ along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - $Id: protocol_edge.c,v 1.1.4.9 2002/09/04 13:48:52 guus Exp $ + $Id: protocol_edge.c,v 1.1.4.10 2002/09/04 16:26:45 guus Exp $ */ #include "config.h" @@ -62,7 +62,6 @@ cp int add_edge_h(connection_t *c) { - connection_t *other; edge_t *e; node_t *from, *to; char from_name[MAX_STRING_SIZE]; @@ -72,7 +71,6 @@ int add_edge_h(connection_t *c) sockaddr_t address; long int options; int weight; - avl_node_t *node; cp if(sscanf(c->buffer, "%*d %*x "MAX_STRING" "MAX_STRING" "MAX_STRING" "MAX_STRING" %lx %d", from_name, to_name, to_address, to_port, &options, &weight) != 6) @@ -169,12 +167,7 @@ cp /* Tell the rest about the new edge */ - for(node = connection_tree->head; node; node = node->next) - { - other = (connection_t *)node->data; - if(other->status.active && other != c) - send_request(other, "%s", c->buffer); - } + forward_request(c); /* Run MST before or after we tell the rest? */ @@ -196,8 +189,6 @@ int del_edge_h(connection_t *c) char from_name[MAX_STRING_SIZE]; char to_name[MAX_STRING_SIZE]; node_t *from, *to; - connection_t *other; - avl_node_t *node; cp if(sscanf(c->buffer, "%*d %*x "MAX_STRING" "MAX_STRING"", from_name, to_name) != 2) { @@ -264,12 +255,7 @@ cp /* Tell the rest about the deleted edge */ - for(node = connection_tree->head; node; node = node->next) - { - other = (connection_t *)node->data; - if(other->status.active && other != c) - send_request(other, "%s", c->buffer); - } + forward_request(c); /* Delete the edge */ diff --git a/src/protocol_key.c b/src/protocol_key.c index 0f14cd6..029b41a 100644 --- a/src/protocol_key.c +++ b/src/protocol_key.c @@ -17,7 +17,7 @@ along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - $Id: protocol_key.c,v 1.1.4.9 2002/09/04 08:02:33 guus Exp $ + $Id: protocol_key.c,v 1.1.4.10 2002/09/04 16:26:45 guus Exp $ */ #include "config.h" @@ -54,17 +54,13 @@ cp if(n == myself && !mykeyused) return 0; - - send_request(NULL, "%d %lx %s", KEY_CHANGED, random(), n->name); cp - return 0; + return send_request(c, "%d %lx %s", KEY_CHANGED, random(), n->name); } int key_changed_h(connection_t *c) { char name[MAX_STRING_SIZE]; - avl_node_t *node; - connection_t *other; node_t *n; cp if(sscanf(c->buffer, "%*d %*x "MAX_STRING, name) != 1) @@ -91,12 +87,7 @@ cp /* Tell the others */ - for(node = connection_tree->head; node; node = node->next) - { - other = (connection_t *)node->data; - if(other->status.active && other != c) - send_request(other, "%s", c->buffer); - } + forward_request(c); cp return 0; } diff --git a/src/protocol_subnet.c b/src/protocol_subnet.c index e510307..a7344d7 100644 --- a/src/protocol_subnet.c +++ b/src/protocol_subnet.c @@ -17,7 +17,7 @@ along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - $Id: protocol_subnet.c,v 1.1.4.5 2002/09/03 20:43:26 guus Exp $ + $Id: protocol_subnet.c,v 1.1.4.6 2002/09/04 16:26:45 guus Exp $ */ #include "config.h" @@ -60,9 +60,7 @@ int add_subnet_h(connection_t *c) char subnetstr[MAX_STRING_SIZE]; char name[MAX_STRING_SIZE]; node_t *owner; - connection_t *other; subnet_t *s; - avl_node_t *node; cp if(sscanf(c->buffer, "%*d %*x "MAX_STRING" "MAX_STRING, name, subnetstr) != 2) { @@ -124,13 +122,8 @@ cp subnet_add(owner, s); /* Tell the rest */ - - for(node = connection_tree->head; node; node = node->next) - { - other = (connection_t *)node->data; - if(other->status.active && other != c) - send_request(other, "%s", c->buffer); - } + + forward_request(c); cp return 0; } @@ -152,9 +145,7 @@ int del_subnet_h(connection_t *c) char subnetstr[MAX_STRING_SIZE]; char name[MAX_STRING_SIZE]; node_t *owner; - connection_t *other; subnet_t *s, *find; - avl_node_t *node; cp if(sscanf(c->buffer, "%*d %*x "MAX_STRING" "MAX_STRING, name, subnetstr) != 2) { @@ -218,13 +209,8 @@ cp } /* Tell the rest */ - - for(node = connection_tree->head; node; node = node->next) - { - other = (connection_t *)node->data; - if(other->status.active && other != c) - send_request(other, "%s", c->buffer); - } + + forward_request(c); /* Finally, delete it. */