- ip_t real_ip;
- ip_t vpn_ip;
- ip_t vpn_mask;
- unsigned short port;
- int flags;
- conn_list_t *ncn, *old;
-cp
- if(!cl->status.active)
- {
- syslog(LOG_ERR, _("Got unauthorized ADD_HOST from %s (%s)"),
- cl->vpn_hostname, cl->real_hostname);
- return -1;
- }
-
- if(sscanf(cl->buffer, "%*d %lx %lx/%lx:%hx %d", &real_ip, &vpn_ip, &vpn_mask, &port, &flags) != 5)
- {
- syslog(LOG_ERR, _("Got bad ADD_HOST from %s (%s)"),
- cl->vpn_hostname, cl->real_hostname);
- return -1;
- }
-
- if((old = lookup_conn(vpn_ip)))
- {
- if((real_ip==old->real_ip) && (vpn_mask==old->vpn_mask) && (port==old->port))
- {
- if(debug_lvl>1)
- syslog(LOG_NOTICE, _("Got duplicate ADD_HOST for %s (%s) from %s (%s)"),
- old->vpn_hostname, old->real_hostname, cl->vpn_hostname, cl->real_hostname);
- goto skip_add_host; /* One goto a day keeps the deeply nested if constructions away. */
- }
- else
- {
- if(debug_lvl>1)
- syslog(LOG_NOTICE, _("Removing old entry for %s (%s)"),
- old->vpn_hostname, old->real_hostname);
- old->status.active = 0;
- terminate_connection(old);
- }
- }
-
- /* Connections lists are really messed up if this happens */
- if(vpn_ip == myself->vpn_ip)
- {
- syslog(LOG_ERR, _("Warning: got ADD_HOST from %s (%s) for ourself, restarting"),
- cl->vpn_hostname, cl->real_hostname);
- sighup = 1;
- return 0;
- }
-
- ncn = new_conn_list();
- ncn->real_ip = real_ip;
- ncn->real_hostname = hostlookup(htonl(real_ip));
- ncn->vpn_ip = vpn_ip;
- ncn->vpn_mask = vpn_mask;
- ncn->vpn_hostname = hostlookup(htonl(vpn_ip));
- ncn->port = port;
- ncn->flags = flags;
- ncn->nexthop = cl;
- ncn->next = conn_list;
- conn_list = ncn;
- ncn->status.active = 1;
-
- if(debug_lvl > 1)
- syslog(LOG_DEBUG, _("Got ADD_HOST for %s (%s) from %s (%s)"),
- ncn->vpn_hostname, ncn->real_hostname, cl->vpn_hostname, cl->real_hostname);
-
- notify_others(ncn, cl, send_add_host);
-
-skip_add_host: