- if(debug_lvl > DEBUG_CONNECTIONS)
- syslog(LOG_NOTICE, _("Removing old entry for %s at %s in favour of new connection from %s"),
- cl->id, old->hostname, cl->hostname);
- old->status.active = 0;
- terminate_connection(old);
- }
-
- /* Activate this connection */
-
- cl->allow_request = ALL;
- cl->status.active = 1;
-
- if(debug_lvl > DEBUG_CONNECTIONS)
- syslog(LOG_NOTICE, _("Connection with %s (%s) activated"), cl->id, cl->hostname);
-
- /* Exchange information about other tinc daemons */
-
- notify_others(cl, NULL, send_add_host);
- notify_one(cl);
-
- upstreamindex = 0;
-
-cp
- if(cl->status.outgoing)
- return 0;
- else
- return send_ack(cl);
-}
-
-/* Address and subnet information exchange */
-
-int send_add_subnet(conn_list_t *cl, conn_list_t *other, subnet_t *subnet)
-{
-cp
- return send_request(cl, "%d %s %d %s", ADD_SUBNET, other->id, subnet->type, net2str(subnet));
-}
-
-int add_subnet_h(conn_list_t *cl)
-{
-}
-
-int send_del_subnet(conn_list_t *cl, conn_list_t *other, subnet_t *subnet)
-{
-cp
- return send_request(cl, "%d %s %d %s", DEL_SUBNET, other->id, subnet->type, net2str(subnet));
-}
-
-int del_subnet_h(conn_list_t *cl)
-{
-}
-
-/* New and closed connections notification */
-
-int send_add_host(conn_list_t *cl, conn_list_t *other)
-{
-cp
- return send_request(cl, "%d %s %lx:%d %s", ADD_HOST, other->id, other->address, other->port, opt2str(other->options));
-}
-
-int add_host_h(conn_list_t *cl)
-{
- char *options;
- conn_list_t *old, *new;
-cp
- new = new_conn_list();
-
- if(sscanf(cl->buffer, "%*d %as %lx:%d %as", &new->id, &new->address, &new->port, &options) != 4)
- {
- syslog(LOG_ERR, _("Got bad ADD_HOST from %s (%s)"), cl->id, cl->hostname);
- return -1;
- }
-
- /* Check if option string is valid */
-
- if((new->options = str2opt(options) == -1)
- {
- syslog(LOG_ERR, _("Got bad ADD_HOST from %s (%s): invalid option string"), cl->hostname);
- return -1;
- }
-
- /* Check if identity is a valid name */
-
- if(!check_id(new->id))
- {
- syslog(LOG_ERR, _("Got bad ADD_HOST from %s (%s): invalid identity name"), cl->id, cl->hostname);
- return -1;
- }
-
- /* Check if somebody tries to add ourself */
-
- if(!strcmp(new->id, myself->id))
- {
- syslog(LOG_ERR, _("Warning: got ADD_HOST from %s (%s) for ourself, restarting"), cl->id, cl->hostname);
- sighup = 1;
- return 0;
- }
-
- /* Fill in more of the new conn_list structure */
-
- new->hostname = hostlookup(htonl(new->address));
-
- /* Check if the new host already exists in the connnection list */
-
- if((old = lookup_id(id))
- {
- if((new->address == old->address) && (new->port == old->port))