- connection_t *other;
- node_t *n, *prevhop, *via;
- char name[MAX_STRING_SIZE];
- char address[MAX_STRING_SIZE];
- char port[MAX_STRING_SIZE];
- char prevhopname[MAX_STRING_SIZE];
- char vianame[MAX_STRING_SIZE];
- long int options;
- int distance;
- avl_node_t *node;
- cp();
- if(sscanf(c->buffer, "%*d "MAX_STRING" "MAX_STRING" "MAX_STRING" %lx %d "MAX_STRING" "MAX_STRING,
- name, address, port, &options, &distance, prevhopname, vianame) != 7)
- {
- syslog(LOG_ERR, _("Got bad %s from %s (%s)"), "ADD_NODE", c->name, c->hostname);
- return -1;
- }
-
- /* Check if names are valid */
-
- if(check_id(name))
- {
- syslog(LOG_ERR, _("Got bad %s from %s (%s): %s"), "ADD_NODE", c->name, c->hostname, _("invalid name"));
- return -1;
- }
-
- /* This node is indirect if it's nexthop is as well */
-
- if(c->node->options & OPTION_INDIRECT)
- options |= OPTION_INDIRECT;
-
- /* Lookup nodes */
-
- prevhop = lookup_node(prevhopname);
-
- if(!prevhop)
- {
- prevhop = new_node();
- prevhop->name = xstrdup(prevhopname);
- node_add(prevhop);
- }
-
- via = lookup_node(vianame);
-
- if(!via)
- {
- via = new_node();
- via->name = xstrdup(vianame);
- node_add(via);
- }
-
- n = lookup_node(name);
-
- if(!n)
- {
- // It's a new node. Add it and tell the others.
- n = new_node();
- n->name = xstrdup(name);
- n->address = str2sockaddr(address, port);
- n->hostname = sockaddr2hostname(&n->address);
- n->options = options;
- n->distance = distance;
- n->nexthop = c->node;
- n->prevhop = prevhop;
- n->via = via;
- node_add(n);
- if(prevhop == myself)
- {
- syslog(LOG_WARNING, _("Got ADD_NODE %s prevhop %s via %s from %s, sending back a DEL_NODE!"), name, prevhopname, vianame, c->name);
- // send_del_node(c, n);
- return 0;
- }
- n->status.reachable = 1;
- }
- else
- {
- // If this ADD_NODE is closer or more direct, use it instead of the old one.
- if(!n->status.reachable || ((n->options & OPTION_INDIRECT) && !(options & OPTION_INDIRECT)) || n->distance > distance)
- {
- if(prevhop == myself)
- {
- syslog(LOG_WARNING, _("Got ADD_NODE %s prevhop %s via %s from %s!"), name, prevhopname, vianame, c->name);
- // send_del_node(c, n);
- return 0;
- }
- node = avl_unlink(node_udp_tree, n);
- n->address = str2sockaddr(address, port);
- avl_insert_node(node_udp_tree, node);
- if(n->hostname)
- free(n->hostname);
- n->hostname = sockaddr2hostname(&n->address);
- n->options = options;
- n->distance = distance;
- n->via = n->nexthop = c->node;
- n->status.reachable = 1;
- n->status.validkey = 0;
- n->status.waitingforkey = 0;
- }
- else
- // Otherwise, just ignore it.
- return 0;
- }
-
- /* Tell the rest about the new node */
-
- for(node = connection_tree->head; node; node = node->next)
- {
- other = (connection_t *)node->data;
- if(other->status.active && other != c)
- send_add_node(other, n);
- }
-
- cp();
- return 0;
+ connection_t *other;
+ node_t *n, *prevhop, *via;
+ char name[MAX_STRING_SIZE];
+ char address[MAX_STRING_SIZE];
+ char port[MAX_STRING_SIZE];
+ char prevhopname[MAX_STRING_SIZE];
+ char vianame[MAX_STRING_SIZE];
+ long int options;
+ int distance;
+ avl_node_t *node;
+ cp();
+ if(sscanf
+ (c->buffer,
+ "%*d " MAX_STRING " " MAX_STRING " " MAX_STRING " %lx %d " MAX_STRING
+ " " MAX_STRING, name, address, port, &options, &distance, prevhopname,
+ vianame) != 7) {
+ syslog(LOG_ERR, _("Got bad %s from %s (%s)"), "ADD_NODE", c->name,
+ c->hostname);
+ return -1;
+ }
+
+ /* Check if names are valid */
+
+ if(check_id(name)) {
+ syslog(LOG_ERR, _("Got bad %s from %s (%s): %s"), "ADD_NODE", c->name,
+ c->hostname, _("invalid name"));
+ return -1;
+ }
+
+ /* This node is indirect if it's nexthop is as well */
+
+ if(c->node->options & OPTION_INDIRECT)
+ options |= OPTION_INDIRECT;
+
+ /* Lookup nodes */
+
+ prevhop = lookup_node(prevhopname);
+
+ if(!prevhop) {
+ prevhop = new_node();
+ prevhop->name = xstrdup(prevhopname);
+ node_add(prevhop);
+ }
+
+ via = lookup_node(vianame);
+
+ if(!via) {
+ via = new_node();
+ via->name = xstrdup(vianame);
+ node_add(via);
+ }
+
+ n = lookup_node(name);
+
+ if(!n) {
+ // It's a new node. Add it and tell the others.
+ n = new_node();
+ n->name = xstrdup(name);
+ n->address = str2sockaddr(address, port);
+ n->hostname = sockaddr2hostname(&n->address);
+ n->options = options;
+ n->distance = distance;
+ n->nexthop = c->node;
+ n->prevhop = prevhop;
+ n->via = via;
+ node_add(n);
+ if(prevhop == myself) {
+ syslog(LOG_WARNING,
+ _
+ ("Got ADD_NODE %s prevhop %s via %s from %s, sending back a DEL_NODE!"),
+ name, prevhopname, vianame, c->name);
+ // send_del_node(c, n);
+ return 0;
+ }
+ n->status.reachable = 1;
+ } else {
+ // If this ADD_NODE is closer or more direct, use it instead of the old one.
+ if(!n->status.reachable
+ || ((n->options & OPTION_INDIRECT) && !(options & OPTION_INDIRECT))
+ || n->distance > distance) {
+ if(prevhop == myself) {
+ syslog(LOG_WARNING,
+ _("Got ADD_NODE %s prevhop %s via %s from %s!"), name,
+ prevhopname, vianame, c->name);
+ // send_del_node(c, n);
+ return 0;
+ }
+ node = avl_unlink(node_udp_tree, n);
+ n->address = str2sockaddr(address, port);
+ avl_insert_node(node_udp_tree, node);
+ if(n->hostname)
+ free(n->hostname);
+ n->hostname = sockaddr2hostname(&n->address);
+ n->options = options;
+ n->distance = distance;
+ n->via = n->nexthop = c->node;
+ n->status.reachable = 1;
+ n->status.validkey = 0;
+ n->status.waitingforkey = 0;
+ } else
+ // Otherwise, just ignore it.
+ return 0;
+ }
+
+ /* Tell the rest about the new node */
+
+ for(node = connection_tree->head; node; node = node->next) {
+ other = (connection_t *) node->data;
+ if(other->status.active && other != c)
+ send_add_node(other, n);
+ }
+
+ cp();
+ return 0;