X-Git-Url: https://tinc-vpn.org/git/browse?a=blobdiff_plain;f=src%2Fprotocol_edge.c;h=35776116ee929c0cf33fcffd8bd29910c9b28d2d;hb=5a132550deb58473285e5f91705d286aef47be71;hp=8f4d0e144ba1db0811bc24041a8d3ad19aff2104;hpb=df3220a1549f992cbf4a9b6e67c1e67b69896c7d;p=tinc diff --git a/src/protocol_edge.c b/src/protocol_edge.c index 8f4d0e14..35776116 100644 --- a/src/protocol_edge.c +++ b/src/protocol_edge.c @@ -1,7 +1,7 @@ /* protocol_edge.c -- handle the meta-protocol, edges - Copyright (C) 1999-2005 Ivo Timmermans , - 2000-2005 Guus Sliepen + Copyright (C) 1999-2005 Ivo Timmermans, + 2000-2006 Guus Sliepen This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -22,7 +22,7 @@ #include "system.h" -#include "avl_tree.h" +#include "splay_tree.h" #include "conf.h" #include "connection.h" #include "edge.h" @@ -36,8 +36,7 @@ #include "utils.h" #include "xalloc.h" -bool send_add_edge(connection_t *c, const edge_t *e) -{ +bool send_add_edge(connection_t *c, const edge_t *e) { bool x; char *address, *port; @@ -54,8 +53,7 @@ bool send_add_edge(connection_t *c, const edge_t *e) return x; } -bool add_edge_h(connection_t *c) -{ +bool add_edge_h(connection_t *c, char *request) { edge_t *e; node_t *from, *to; char from_name[MAX_STRING_SIZE]; @@ -68,7 +66,7 @@ bool add_edge_h(connection_t *c) cp(); - if(sscanf(c->buffer, "%*d %*x "MAX_STRING" "MAX_STRING" "MAX_STRING" "MAX_STRING" %lx %d", + if(sscanf(request, "%*d %*x "MAX_STRING" "MAX_STRING" "MAX_STRING" "MAX_STRING" %lx %d", from_name, to_name, to_address, to_port, &options, &weight) != 6) { logger(LOG_ERR, _("Got bad %s from %s (%s)"), "ADD_EDGE", c->name, c->hostname); @@ -89,12 +87,23 @@ bool add_edge_h(connection_t *c) return false; } - if(seen_request(c->buffer)) + if(seen_request(request)) return true; /* Lookup nodes */ from = lookup_node(from_name); + to = lookup_node(to_name); + + if(tunnelserver && + from != myself && from != c->node && + to != myself && to != c->node) { + /* ignore indirect edge registrations for tunnelserver */ + ifdebug(PROTOCOL) logger(LOG_WARNING, + _("Ignoring indirect %s from %s (%s)"), + "ADD_EDGE", c->name, c->hostname); + return true; + } if(!from) { from = new_node(); @@ -102,16 +111,12 @@ bool add_edge_h(connection_t *c) node_add(from); } - to = lookup_node(to_name); - if(!to) { to = new_node(); to->name = xstrdup(to_name); node_add(to); } - if(tunnelserver && from != myself && from != c->node && to != myself && to != c->node) - return false; /* Convert addresses */ @@ -158,7 +163,7 @@ bool add_edge_h(connection_t *c) /* Tell the rest about the new edge */ if(!tunnelserver) - forward_request(c); + forward_request(c, request); /* Run MST before or after we tell the rest? */ @@ -167,16 +172,14 @@ bool add_edge_h(connection_t *c) return true; } -bool send_del_edge(connection_t *c, const edge_t *e) -{ +bool send_del_edge(connection_t *c, const edge_t *e) { cp(); return send_request(c, "%d %lx %s %s", DEL_EDGE, random(), e->from->name, e->to->name); } -bool del_edge_h(connection_t *c) -{ +bool del_edge_h(connection_t *c, char *request) { edge_t *e; char from_name[MAX_STRING_SIZE]; char to_name[MAX_STRING_SIZE]; @@ -184,7 +187,7 @@ bool del_edge_h(connection_t *c) cp(); - if(sscanf(c->buffer, "%*d %*x "MAX_STRING" "MAX_STRING, from_name, to_name) != 2) { + if(sscanf(request, "%*d %*x "MAX_STRING" "MAX_STRING, from_name, to_name) != 2) { logger(LOG_ERR, _("Got bad %s from %s (%s)"), "DEL_EDGE", c->name, c->hostname); return false; @@ -204,12 +207,23 @@ bool del_edge_h(connection_t *c) return false; } - if(seen_request(c->buffer)) + if(seen_request(request)) return true; /* Lookup nodes */ from = lookup_node(from_name); + to = lookup_node(to_name); + + if(tunnelserver && + from != myself && from != c->node && + to != myself && to != c->node) { + /* ignore indirect edge registrations for tunnelserver */ + ifdebug(PROTOCOL) logger(LOG_WARNING, + _("Ignoring indirect %s from %s (%s)"), + "DEL_EDGE", c->name, c->hostname); + return true; + } if(!from) { ifdebug(PROTOCOL) logger(LOG_ERR, _("Got %s from %s (%s) which does not appear in the edge tree"), @@ -217,17 +231,12 @@ bool del_edge_h(connection_t *c) return true; } - to = lookup_node(to_name); - if(!to) { ifdebug(PROTOCOL) logger(LOG_ERR, _("Got %s from %s (%s) which does not appear in the edge tree"), "DEL_EDGE", c->name, c->hostname); return true; } - if(tunnelserver && from != myself && from != c->node && to != myself && to != c->node) - return false; - /* Check if edge exists */ e = lookup_edge(from, to); @@ -248,7 +257,7 @@ bool del_edge_h(connection_t *c) /* Tell the rest about the deleted edge */ if(!tunnelserver) - forward_request(c); + forward_request(c, request); /* Delete the edge */