-
-/*
- Notify one connection of everything
- I have connected
-*/
-
-int notify_one(conn_list_t *new)
-{
- conn_list_t *p;
-cp
- for(p = conn_list; p != NULL; p = p->next)
- if(p != new && p->status.active)
- send_add_host(new, p);
-cp
- return 0;
-}
-
-/*
- The incoming request handlers
-*/
-
-int tcppacket_h(conn_list_t *cl)
-{
- int len;
-cp
- if(!cl->status.active)
- {
- syslog(LOG_ERR, _("Got unauthorized PACKET from %s (%s)"),
- cl->vpn_hostname, cl->real_hostname);
- return -1;
- }
-
- if(sscanf(cl->buffer, "%*d %d", &len) != 1)
- {
- syslog(LOG_ERR, _("Got bad PACKET from %s (%s)"),
- cl->vpn_hostname, cl->real_hostname);
- return -1;
- }
-
- if(len > MTU)
- {
- syslog(LOG_ERR, _("Got too big PACKET from %s (%s)"),
- cl->vpn_hostname, cl->real_hostname);
- return -1;
- }
-
- if(debug_lvl > 3)
- syslog(LOG_DEBUG, _("Got PACKET length %d from %s (%s)"), len,
- cl->vpn_hostname, cl->real_hostname);
-
- cl->tcppacket=len;
-cp
- return 0;
-}
-
-void set_keys(conn_list_t *cl, int expiry, char *key)
-{
- 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 = strlen(key);
- cl->public_key->expiry = expiry;
- cl->public_key->key = xmalloc(cl->public_key->length + 1);
- strcpy(cl->public_key->key, key);
-
- ek = make_shared_key(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 = expiry;
- cl->key->key = xmalloc(cl->key->length + 1);
- strcpy(cl->key->key, ek);
-cp
-}
-
-
-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 %s (%s)"),
- cl->vpn_hostname, cl->real_hostname);
- return -1;
- }
-
- if(sscanf(cl->buffer, "%*d %lx", &from) != 1)
- {
- syslog(LOG_ERR, _("Got bad KEY_CHANGED from %s (%s)"),
- cl->vpn_hostname, cl->real_hostname);
- return -1;
- }
-
- ik = lookup_conn(from);
-
- if(!ik)
- {
- syslog(LOG_ERR, _("Got KEY_CHANGED origin %d.%d.%d.%d from %s (%s), which does not exist?"),
- IP_ADDR_V(from), cl->vpn_hostname, cl->real_hostname);
- return -1;
- }
-
- if(debug_lvl > 1)
- syslog(LOG_DEBUG, _("Got KEY_CHANGED origin %s from %s (%s)"),
- ik->vpn_hostname, cl->vpn_hostname, cl->real_hostname);
-
- ik->status.validkey = 0;
- ik->status.waitingforkey = 0;
-
- notify_others(ik, cl, send_key_changed);
-cp
- return 0;
-}
-
-/* "Complete overhaul". */
-
-int (*request_handlers[])(conn_list_t*) = {
- id_h, challenge_h, chal_reply_h, ack_h,
- status_h, error_h, termreq_h,
- ping_h, pong_h,
- add_host_h, del_host_h,
- add_subnet_h, del_subnet_h,
- key_changed_h, req_key_h, ans_key_h,
-};
-
-char (*request_name[]) = {
- "ID", "CHALLENGE", "CHAL_REPLY", "ACK",
- "STATUS", "ERROR", "TERMREQ",
- "PING", "PONG",
- "ADD_HOST", "DEL_HOST",
- "ADD_SUBNET", "DEL_SUBNET",
- "KEY_CHANGED", "REQ_KEY", "ANS_KEY",
-};