-
-int req_key_h(conn_list_t *cl, unsigned char *d, int len)
-{
- key_req_t *tmp = (key_req_t*)d;
- conn_list_t *fw;
-cp
- if(debug_lvl > 2)
- syslog(LOG_DEBUG, "got REQ_KEY from " IP_ADDR_S " for " IP_ADDR_S,
- IP_ADDR_V(tmp->from), IP_ADDR_V(tmp->to));
-
- if((tmp->to & myself->vpn_mask) == (myself->vpn_ip & myself->vpn_mask))
- { /* hey! they want something from ME! :) */
- send_key_answer(cl, tmp->from);
- return 0;
- }
-
- fw = lookup_conn(tmp->to);
-
- if(!fw)
- {
- syslog(LOG_ERR, "Attempting to forward key request to " IP_ADDR_S ", which does not exist?",
- IP_ADDR_V(tmp->to));
- return -1;
- }
-
- if(debug_lvl > 3)
- syslog(LOG_DEBUG, "Forwarding request for public key to " IP_ADDR_S,
- IP_ADDR_V(fw->nexthop->vpn_ip));
- if(write(fw->nexthop->meta_socket, tmp, sizeof(*tmp)) < 0)
- {
- syslog(LOG_ERR, "send failed: %s:%d: %m", __FILE__, __LINE__);
- return -1;
- }
-cp
- return 0;
-}
-
-void set_keys(conn_list_t *cl, key_req_t *k)
-{
- char *ek;
-cp
- if(!cl->public_key)
- {
- cl->public_key = xmalloc(sizeof(*cl->key));
- cl->public_key->key = NULL;
- }
- if(cl->public_key->key)
- free(cl->public_key->key);
- cl->public_key->length = k->len;
- cl->public_key->expiry = k->expiry;
- cl->public_key->key = xmalloc(k->len + 1);
- strcpy(cl->public_key->key, &(k->key));
-
- ek = make_shared_key(&(k->key));
- if(!cl->key)
- {
- cl->key = xmalloc(sizeof(*cl->key));
- cl->key->key = NULL;
- }
- if(cl->key->key)
- free(cl->key->key);
- cl->key->length = strlen(ek);
- cl->key->expiry = k->expiry;
- cl->key->key = xmalloc(strlen(ek) + 1);
- strcpy(cl->key->key, ek);
-cp
-}
-
-int ans_key_h(conn_list_t *cl, unsigned char *d, int len)
-{
- key_req_t *tmp = (key_req_t*)d;
- conn_list_t *fw, *gk;
-cp
- if(debug_lvl > 3)
- syslog(LOG_DEBUG, "got ANS_KEY from " IP_ADDR_S " for " IP_ADDR_S,
- IP_ADDR_V(tmp->from), IP_ADDR_V(tmp->to));
-
- if(tmp->to == myself->vpn_ip)
- { /* hey! that key's for ME! :) */
- if(debug_lvl > 2)
- syslog(LOG_DEBUG, "Yeah! key arrived. Now do something with it.");
- gk = lookup_conn(tmp->from);
-
- if(!gk)
- {
- syslog(LOG_ERR, "Receiving key from " IP_ADDR_S ", which does not exist?",
- IP_ADDR_V(tmp->from));
- return -1;
- }
-
- set_keys(gk, tmp);
- gk->status.validkey = 1;
- gk->status.waitingforkey = 0;
- flush_queues(gk);
- return 0;
- }
-
- fw = lookup_conn(tmp->to);
-
- if(!fw)
- {
- syslog(LOG_ERR, "Attempting to forward key to " IP_ADDR_S ", which does not exist?",
- IP_ADDR_V(tmp->to));
- return -1;
- }
-
- if(debug_lvl > 2)
- syslog(LOG_DEBUG, "Forwarding public key to " IP_ADDR_S,
- IP_ADDR_V(fw->nexthop->vpn_ip));
- if(write(fw->nexthop->meta_socket, tmp, sizeof(*tmp)+tmp->len) < 0)
- {
- syslog(LOG_ERR, "send failed: %s:%d: %m", __FILE__, __LINE__);
- return -1;
- }
-cp
- return 0;
-}
-
-int key_changed_h(conn_list_t *cl, unsigned char *d, int len)
-{
- key_changed_t *tmp = (key_changed_t*)d;
- conn_list_t *ik;
-cp
- if(debug_lvl > 2)
- syslog(LOG_DEBUG, "got KEY_CHANGED from " IP_ADDR_S,
- IP_ADDR_V(tmp->from));
-
- ik = lookup_conn(tmp->from);
-
- if(!ik)
- {
- syslog(LOG_ERR, "Got changed key from " IP_ADDR_S ", which does not exist?",
- IP_ADDR_V(tmp->from));
- return -1;
- }
-
- ik->status.validkey = 0;
- ik->status.waitingforkey = 0;
-
- if(debug_lvl > 3)
- syslog(LOG_DEBUG, "Forwarding key invalidation request");
-
- notify_others(cl, ik, send_key_changed);
-cp
- return 0;
-}
-
-int (*request_handlers[256])(conn_list_t*, unsigned char*, int) = {
- 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
-};