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"
#include "system.h"
avl_tree_t *connection_tree; /* Meta connections */
+connection_t *broadcast;
int connection_compare(connection_t *a, connection_t *b)
{
{
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
}
{
cp
avl_delete_tree(connection_tree);
+cp
+ free_connection(broadcast);
cp
}
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__
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 */
} connection_t;
extern avl_tree_t *connection_tree;
+extern connection_t *broadcast;
extern void init_connections(void);
extern void exit_connections(void);
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"
if(reqlen)
{
+ c->reqlen = reqlen;
if(receive_request(c))
return -1;
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"
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"));
{
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);
}
{
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);
}
*/
void terminate_connection(connection_t *c, int report)
{
- avl_node_t *node;
- connection_t *other;
cp
if(c->status.remove)
return;
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);
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;
}
}
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"
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)
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__
/* 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 *);
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"
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)
{
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);
+ }
}
}
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)
{
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();
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 */
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"
int add_edge_h(connection_t *c)
{
- connection_t *other;
edge_t *e;
node_t *from, *to;
char from_name[MAX_STRING_SIZE];
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)
/* 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? */
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)
{
/* 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 */
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"
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)
/* 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;
}
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"
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)
{
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;
}
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)
{
}
/* 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. */