-
-int ans_key_h(conn_list_t *cl)
-{
- ip_t to;
- ip_t from;
- int expiry;
- char *key;
- conn_list_t *fw, *gk;
-cp
- if(!cl->status.active)
- {
- syslog(LOG_ERR, _("Got unauthorized ANS_KEY from " IP_ADDR_S " (%s)"),
- IP_ADDR_V(cl->vpn_ip), cl->hostname);
- return -1;
- }
-
- if(sscanf(cl->buffer, "%*d %lx %lx %d %as", &to, &from, &expiry, &key) != 4)
- {
- syslog(LOG_ERR, _("Got bad ANS_KEY from " IP_ADDR_S " (%s)"),
- IP_ADDR_V(cl->vpn_ip), cl->hostname);
- return -1;
- }
-
- if(debug_lvl > 1)
- syslog(LOG_DEBUG, _("Got ANS_KEY origin " IP_ADDR_S " destination " IP_ADDR_S " from " IP_ADDR_S " (%s)"),
- IP_ADDR_V(from), IP_ADDR_V(to), IP_ADDR_V(cl->vpn_ip), cl->hostname);
-
- if(to == myself->vpn_ip)
- { /* hey! that key's for ME! :) */
- gk = lookup_conn(from);
-
- if(!gk)
- {
- syslog(LOG_ERR, _("Receiving ANS_KEY from " IP_ADDR_S ", which does not exist?"),
- IP_ADDR_V(from));
- return -1;
- }
-
- set_keys(gk, expiry, key);
- gk->status.validkey = 1;
- gk->status.waitingforkey = 0;
- flush_queues(gk);
- return 0;
- }
-
- fw = lookup_conn(to);
-
- if(!fw)
- {
- syslog(LOG_ERR, _("Attempting to forward ANS_KEY to " IP_ADDR_S ", which does not exist?"),
- IP_ADDR_V(to));
- return -1;
- }
-
- if(debug_lvl > 1)
- syslog(LOG_DEBUG, _("Forwarding ANS_KEY to " IP_ADDR_S " (%s)"),
- IP_ADDR_V(fw->nexthop->vpn_ip), fw->nexthop->hostname);
-
- cl->buffer[cl->reqlen-1] = '\n';
-
- if((write(fw->nexthop->meta_socket, cl->buffer, cl->reqlen)) < 0)
- {
- syslog(LOG_ERR, _("Send failed: %s:%d: %m"), __FILE__, __LINE__);
- return -1;
- }
-cp
- return 0;
-}
-
-int key_changed_h(conn_list_t *cl)
-{
- ip_t from;
- conn_list_t *ik;
-cp
- if(!cl->status.active)
- {
- syslog(LOG_ERR, _("Got unauthorized KEY_CHANGED from " IP_ADDR_S " (%s)"),
- IP_ADDR_V(cl->vpn_ip), cl->hostname);
- return -1;
- }
-
- if(sscanf(cl->buffer, "%*d %lx", &from) != 1)
- {
- syslog(LOG_ERR, _("Got bad KEY_CHANGED from " IP_ADDR_S " (%s)"),
- IP_ADDR_V(cl->vpn_ip), cl->hostname);
- return -1;
- }
-
- if(debug_lvl > 1)
- syslog(LOG_DEBUG, _("Got KEY_CHANGED origin " IP_ADDR_S " from " IP_ADDR_S " (%s)"),
- IP_ADDR_V(from), IP_ADDR_V(cl->vpn_ip), cl->hostname);
-
- ik = lookup_conn(from);
-
- if(!ik)
- {
- syslog(LOG_ERR, _("Got KEY_CHANGED from " IP_ADDR_S ", which does not exist?"),
- IP_ADDR_V(from));
- return -1;
- }
-
- ik->status.validkey = 0;
- ik->status.waitingforkey = 0;
-
- notify_others(cl, ik, send_key_changed);
-cp
- return 0;
-}
-
-int (*request_handlers[256])(conn_list_t*) = {
- 0, ack_h, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- termreq_h, timeout_h, del_host_h, 0, 0, 0, 0, 0, 0, 0,
- ping_h, pong_h, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- add_host_h, basic_info_h, passphrase_h, public_key_h, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- req_key_h, ans_key_h, key_changed_h, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
-};