-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->name, &new->real_ip, &new->port, &options) != 4)
- {
- syslog(LOG_ERR, _("Got bad ADD_HOST from %s (%s)"), cl->name, 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->name, cl->hostname);
- return -1;
- }
-
- /* Check if identity is a valid name */
-
- if(!check_id(new->name))
- {
- syslog(LOG_ERR, _("Got bad ADD_HOST from %s (%s): invalid identity name"), cl->name, cl->hostname);
- return -1;
- }
-
- /* Check if somebody tries to add ourself */
-
- if(!strcmp(new->name, myself->name))
- {
- syslog(LOG_ERR, _("Warning: got ADD_HOST from %s (%s) for ourself, restarting"), cl->name, cl->hostname);
- sighup = 1;
- return 0;
- }
-
- /* Fill in more of the new conn_list structure */
-
- new->hostname = hostlookup(htonl(new->real_ip));
-
- /* Check if the new host already exists in the connnection list */
-
- if((old = lookup_id(new->name)))
- {
- if((new->real_ip == old->real_ip) && (new->port == old->port))
- {
- if(debug_lvl > DEBUG_CONNECTIONS)
- syslog(LOG_NOTICE, _("Got duplicate ADD_HOST for %s (%s) from %s (%s)"),
- old->name, old->hostname, new->name, new->hostname);
- return 0;
- }
- else
- {
- if(debug_lvl > DEBUG_CONNECTIONS)
- syslog(LOG_NOTICE, _("Removing old entry for %s (%s)"),
- old->name, old->hostname);
- old->status.active = 0;
- terminate_connection(old);
- }
- }
-
- /* Fill in rest of conn_list structure */
-
- new->nexthop = cl;
- new->status.active = 1;
-
- /* Hook it up into the conn_list */
-
- conn_list_add(conn_list, new);
-
- /* Tell the rest about the new host */
-
- notify_others(new, cl, send_add_host);
-
-cp
- return 0;
-}
-
-int send_del_host(conn_list_t *cl, conn_list_t *other)
-{
-cp
- return send_request(cl, "%d %s %lx:%d", DEL_HOST,
- other->name, other->real_ip, other->port);
-}
-
-int del_host_h(conn_list_t *cl)
-{
- char *id;
- ip_t address;
- port_t port;
- conn_list_t *old;
-
-cp
- if(sscanf(cl->buffer, "%*d %as %lx:%d", &id, &address, &port) != 3)
- {
- syslog(LOG_ERR, _("Got bad DEL_HOST from %s (%s)"),
- cl->name, cl->hostname);
- return -1;
- }
-
- /* Check if somebody tries to delete ourself */
-
- if(!strcmp(id, myself->name))
- {
- syslog(LOG_ERR, _("Warning: got DEL_HOST from %s (%s) for ourself, restarting"),
- cl->name, cl->hostname);
- sighup = 1;
- return 0;
- }
-
- /* Check if the new host already exists in the connnection list */
-
- if((old = lookup_id(id)))
- {
- if((address == old->real_ip) && (port == old->port))
- {
- notify_others(old, cl, send_del_host);
-
- old->status.termreq = 1;
- old->status.active = 0;
-
- terminate_connection(old);
-cp
- return 0;
- }
- }
-
- if(debug_lvl > DEBUG_CONNECTIONS)
- {
- syslog(LOG_NOTICE, _("Got DEL_HOST for %s from %s (%s) which is not in our connection list"),
- id, cl->name, cl->hostname);
- }
-cp
- return 0;
-}