int str_hex_to_bin(unsigned char *bin, unsigned char *hex)
{
int i = 0, j = 0, l = strlen(hex);
-
+cp
if(l&1)
{
i = j = 1;
}
for(; i < l; i+=2, j++)
bin[j] = (char_hex_to_bin(hex[i]) << 4) + char_hex_to_bin(hex[i+1]);
-
+cp
return j&1?j+1:j;
}
int size;
extern char *confbase;
char *pp;
-
+cp
if((cfg = get_config_val(passphrasesdir)) == NULL)
{
filename = xmalloc(strlen(confbase)+13+strlen(which));
fclose(f);
*out = xmalloc(size);
+cp
return str_hex_to_bin(*out, pp);
}
int read_my_passphrase(void)
{
+cp
if((mypassphraselen = read_passphrase("local", &mypassphrase)) < 0)
return -1;
-
+cp
return 0;
}
int i;
char *s;
config_t const *cfg;
-
+cp
if((cfg = get_config_val(keyexpire)) == NULL)
my_key_expiry = (time_t)(time(NULL) + 3600);
else
s[2 * PRIVATE_KEY_LENGTH] = '\0';
mpz_set_str(my_private_key, s, 16);
-
+cp
return 0;
}
void calculate_public_key(void)
{
+cp
mpz_powm(my_public_key, generator, my_private_key, shared_prime);
my_public_key_base36 = mpz_get_str(NULL, 36, my_public_key);
+cp
}
unsigned char static_key[] = { 0x9c, 0xbf, 0x36, 0xa9, 0xce, 0x20, 0x1b, 0x8b, 0x67, 0x56, 0x21, 0x5d, 0x27, 0x1b, 0xd8, 0x7a };
int security_init(void)
{
+cp
mpz_init(my_private_key);
mpz_init(my_public_key);
mpz_init_set_str(shared_prime, ENCR_PRIME, 0);
return -1;
calculate_public_key();
-
+cp
return 0;
}
char *tmp;
int len;
mpz_t ak, our_shared_key;
-
+cp
mpz_init_set_str(ak, almost_key, 36);
mpz_init(our_shared_key);
mpz_powm(our_shared_key, ak, my_private_key, shared_prime);
free(tmp);
mpz_clear(ak);
mpz_clear(our_shared_key);
+cp
}
char tmp[1000];
int len;
BF_KEY bf_key;
-
+cp
mpz_get_str(&tmp[0], 16, my_public_key);
len = str_hex_to_bin(key, tmp);
if(key_inited)
cipher_set_key(&encryption_key, encryption_keylen, &text_key[0]);
+cp
}
int verify_passphrase(conn_list_t *cl, unsigned char *his_pubkey)
BF_KEY bf_key;
char which[sizeof("123.123.123.123")+1];
char *meuk;
-
+cp
mpz_init_set_str(pk, his_pubkey, 36);
mpz_get_str(&tmp[0], 16, pk);
len = str_hex_to_bin(key, tmp);
if(memcmp(meuk, out, len))
return -1;
-
+cp
return 0;
}
{
mpz_t tmp, res;
char *r;
-
+cp
mpz_init_set_str(tmp, pk, 36);
mpz_init(res);
mpz_powm(res, tmp, my_private_key, shared_prime);
mpz_clear(res);
mpz_clear(tmp);
-
+cp
return r;
}
*/
void free_key(enc_key_t *k)
{
+cp
if(!k)
return;
if(k->key)
free(k->key);
}
free(k);
+cp
}
void recalculate_encryption_keys(void)
{
conn_list_t *p;
char *ek;
-
+cp
for(p = conn_list; p != NULL; p = p->next)
{
if(!p->public_key || !p->public_key->key)
p->key->key = xmalloc(strlen(ek) + 1);
strcpy(p->key->key, ek);
}
+cp
}
void regenerate_keys(void)
{
+cp
generate_private_key();
calculate_public_key();
send_key_changed2();
recalculate_encryption_keys();
+cp
}
void strip_mac_addresses(vpn_packet_t *p)
{
unsigned char tmp[MAXSIZE];
-
+cp
memcpy(tmp, p->data, p->len);
p->len -= 12;
memcpy(p->data, &tmp[12], p->len);
+cp
}
/*
void add_mac_addresses(vpn_packet_t *p)
{
unsigned char tmp[MAXSIZE];
-
+cp
memcpy(&tmp[12], p->data, p->len);
p->len += 12;
tmp[0] = tmp[6] = 0xfe;
*((ip_t*)(&tmp[2])) = (ip_t)(htonl(myself->vpn_ip));
*((ip_t*)(&tmp[8])) = *((ip_t*)(&tmp[26]));
memcpy(p->data, &tmp[0], p->len);
+cp
}
int xsend(conn_list_t *cl, void *packet)
{
int r;
real_packet_t rp;
-
+cp
do_encrypt((vpn_packet_t*)packet, &rp, cl->key);
rp.from = myself->vpn_ip;
}
total_socket_out += r;
-
+cp
return 0;
}
int write_n(int fd, void *buf, size_t len)
{
int r, done = 0;
-
+cp
do
{
if((r = write(fd, buf, len)) < 0)
} while(len > 0);
return done;
+cp
}
int xrecv(conn_list_t *cl, void *packet)
{
vpn_packet_t vp;
int lenin;
-
+cp
do_decrypt((real_packet_t*)packet, &vp, cl->key);
add_mac_addresses(&vp);
syslog(LOG_ERR, "Can't write to tap device: %m");
else
total_tap_out += lenin;
-
+cp
return 0;
}
void add_queue(packet_queue_t **q, void *packet, size_t s)
{
queue_element_t *e, *p;
-
+cp
if(debug_lvl > 3)
syslog(LOG_DEBUG, "packet to queue: %d", s);
if((*q)->head == NULL)
(*q)->head = e;
+cp
}
/*
int (*function)(conn_list_t*,void*))
{
queue_element_t *p, *prev = NULL, *next = NULL;
-
+cp
for(p = pq->head; p != NULL; )
{
next = p->next;
-cp
if(!function(cl, p->packet))
{
if(prev)
else
pq->head = next;
-cp
free(p->packet);
-cp
free(p);
-cp
}
else
prev = p;
-cp
p = next;
}
if(debug_lvl > 3)
syslog(LOG_DEBUG, "queue flushed");
+cp
}
/*
IP_ADDR_V(cl->vpn_ip));
flush_queue(cl, cl->sq, xsend);
}
-cp
if(cl->rq)
{
int send_packet(ip_t to, vpn_packet_t *packet)
{
conn_list_t *cl;
-
+cp
if((cl = lookup_conn(to)) == NULL)
{
if(debug_lvl > 2)
}
}
-cp
if(my_key_expiry <= time(NULL))
regenerate_keys();
-cp
if(!cl->status.dataopen)
if(setup_vpn_connection(cl) < 0)
return -1;
-cp
if(!cl->status.validkey)
{
return 0;
}
-cp
if(!cl->status.active)
{
add_queue(&(cl->sq), packet, packet->len + 2);
int send_broadcast(conn_list_t *cl, vpn_packet_t *packet)
{
conn_list_t *p;
-
+cp
for(p = cl; p != NULL; p = p->next)
if(send_packet(p->real_ip, packet) < 0)
{
p->vpn_ip, p->real_ip);
break; /* FIXME: should retry later, and send a ping over the metaconnection. */
}
-
+cp
return 0;
}
int nfd;
const char *tapfname;
config_t const *cfg;
-
+cp
if((cfg = get_config_val(tapdevice)) == NULL)
tapfname = "/dev/tap0";
else
}
tap_fd = nfd;
+cp
return 0;
}
int nfd, flags;
struct sockaddr_in a;
const int one = 1;
-
+cp
if((nfd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0)
{
syslog(LOG_ERR, "Creating metasocket failed: %m");
syslog(LOG_ERR, "listen: %m");
return -1;
}
-
+cp
return nfd;
}
int nfd, flags;
struct sockaddr_in a;
const int one = 1;
-
+cp
if((nfd = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)) < 0)
{
syslog(LOG_ERR, "Creating socket failed: %m");
syslog(LOG_ERR, "Can't bind to port %hd/udp: %m", port);
return -1;
}
-
+cp
return nfd;
}
int flags;
struct sockaddr_in a;
config_t const *cfg;
-
+cp
if((cfg = get_config_val(upstreamport)) == NULL)
cl->port = 655;
else
cl->hostname = hostlookup(htonl(cl->real_ip));
syslog(LOG_INFO, "Connected to %s:%hd" , cl->hostname, cl->port);
-
+cp
return 0;
}
int setup_outgoing_connection(ip_t ip)
{
conn_list_t *ncn;
-
+cp
ncn = new_conn_list();
ncn->real_ip = ip;
ncn->status.outgoing = 1;
ncn->next = conn_list;
conn_list = ncn;
-
+cp
return 0;
}
int setup_myself(void)
{
config_t const *cfg;
-
+cp
myself = new_conn_list();
if(!(cfg = get_config_val(myvpnip)))
myself->status.active = 1;
syslog(LOG_NOTICE, "Ready: listening on port %d.", myself->port);
-
+cp
return 0;
}
int setup_network_connections(void)
{
config_t const *cfg;
-
+cp
if((cfg = get_config_val(pingtimeout)) == NULL)
timeout = 10;
else
if(setup_outgoing_connection(cfg->data.ip->ip))
return -1;
-
+cp
return 0;
}
{
config_t const *cfg;
static int seconds_till_retry;
-
+cp
cfg = get_config_val(upstreamip);
if(!setup_outgoing_connection(cfg->data.ip->ip))
syslog(LOG_ERR, "Still failed to connect to other. Will retry in %d seconds.",
seconds_till_retry);
}
+cp
}
/*
void close_network_connections(void)
{
conn_list_t *p;
-
+cp
for(p = conn_list; p != NULL; p = p->next)
{
if(p->status.dataopen)
destroy_conn_list();
syslog(LOG_NOTICE, "Terminating.");
+cp
return;
}
{
int nfd, flags;
struct sockaddr_in a;
-
+cp
if(debug_lvl > 1)
syslog(LOG_DEBUG, "Opening UDP socket to " IP_ADDR_S, IP_ADDR_V(cl->real_ip));
cl->socket = nfd;
cl->status.dataopen = 1;
-
+cp
return 0;
}
conn_list_t *p;
struct sockaddr_in ci;
int len = sizeof(ci);
-
+cp
p = new_conn_list();
if(getpeername(sfd, &ci, &len) < 0)
free(p);
return NULL;
}
-
+cp
return p;
}
void build_fdset(fd_set *fs)
{
conn_list_t *p;
-
+cp
FD_ZERO(fs);
for(p = conn_list; p != NULL; p = p->next)
FD_SET(myself->meta_socket, fs);
FD_SET(myself->socket, fs);
FD_SET(tap_fd, fs);
+cp
}
/*
int lenin;
int x, l = sizeof(x);
conn_list_t *f;
-
+cp
if(getsockopt(cl->socket, SOL_SOCKET, SO_ERROR, &x, &l) < 0)
{
syslog(LOG_ERR, "This is a bug: %s:%d: %d:%m", __FILE__, __LINE__, cl->socket);
if(my_key_expiry <= time(NULL))
regenerate_keys();
}
-
+cp
return 0;
}
*/
void terminate_connection(conn_list_t *cl)
{
+cp
if(cl->status.remove)
return;
}
cl->status.remove = 1;
+cp
}
/*
int send_broadcast_ping(void)
{
conn_list_t *p;
-
+cp
for(p = conn_list; p != NULL; p = p->next)
{
if(p->status.remove)
}
last_ping_time = time(NULL);
-
+cp
return 0;
}
int check_dead_connections(void)
{
conn_list_t *p;
-
+cp
for(p = conn_list; p != NULL; p = p->next)
{
if(p->status.remove)
terminate_connection(p);
}
}
-
+cp
return 0;
}
conn_list_t *ncn;
struct sockaddr client;
int nfd, len = sizeof(struct sockaddr);
-
+cp
if((nfd = accept(cl->meta_socket, &client, &len)) < 0)
{
syslog(LOG_ERR, "Accepting a new connection failed: %m");
ncn->status.meta = 1;
ncn->next = conn_list;
conn_list = ncn;
-
+cp
return 0;
}
int x, l = sizeof(x), lenin;
unsigned char tmp[1600];
int request;
-
+cp
if(getsockopt(cl->meta_socket, SOL_SOCKET, SO_ERROR, &x, &l) < 0)
{
syslog(LOG_ERR, "This is a bug: %s:%d: %d:%m", __FILE__, __LINE__, cl->meta_socket);
else
if(request_handlers[request](cl, tmp, lenin) < 0)
return -1;
-
+cp
return 0;
}
{
conn_list_t *p;
int x, l = sizeof(x);
-
+cp
for(p = conn_list; p != NULL; p = p->next)
{
if(p->status.remove)
continue;
-cp
+
if(p->status.active)
if(FD_ISSET(p->socket, f))
{
terminate_connection(p);
return;
}
-cp
+
if(p->status.meta)
if(FD_ISSET(p->meta_socket, f))
if(handle_incoming_meta_data(p) < 0)
terminate_connection(p);
return;
}
-cp
}
-cp
if(FD_ISSET(myself->socket, f))
handle_incoming_vpn_data(myself);
-cp
+
if(FD_ISSET(myself->meta_socket, f))
handle_new_meta_connection(myself);
cp
vpn_packet_t vp;
ip_t from, to;
int ether_type, lenin;
-
+cp
memset(&vp, 0, sizeof(vp));
if((lenin = read(tap_fd, &vp, MTU)) <= 0)
{
MAC_ADDR_V(vp.data[0]), MAC_ADDR_V(vp.data[6]));
vp.len = (length_t)lenin - 2;
-cp
+
strip_mac_addresses(&vp);
-cp
+
send_packet(to, &vp);
cp
}
fd_set fset;
struct timeval tv;
int r;
-
+cp
last_ping_time = time(NULL);
for(;;)
tv.tv_sec = timeout;
tv.tv_usec = 0;
-cp
prune_conn_list();
-cp
build_fdset(&fset);
-cp
if((r = select(FD_SETSIZE, &fset, NULL, NULL, &tv)) < 0)
{
syslog(LOG_ERR, "Error while waiting for input: %m");
return;
}
-cp
if(r == 0 || last_ping_time + timeout < time(NULL))
/* Timeout... hm... something might be wrong. */
continue;
}
-cp
check_network_activity(&fset);
-cp
/* local tap data */
if(FD_ISSET(tap_fd, &fset))
handle_tap_input();
-cp
}
+cp
}
conn_list_t *lookup_conn(ip_t ip)
{
conn_list_t *p = conn_list;
-
+cp
/* Exact match suggested by James B. MacLean */
for(p = conn_list; p != NULL; p = p->next)
if(ip == p->vpn_ip)
for(p = conn_list; p != NULL; p = p->next)
if((ip & p->vpn_mask) == (p->vpn_ip & p->vpn_mask))
return p;
-
+cp
return NULL;
}
void destroy_queue(packet_queue_t *pq)
{
queue_element_t *p, *q;
-
+cp
for(p = pq->head; p != NULL; p = q)
{
q = p->next;
}
free(pq);
+cp
}
/*
*/
void free_conn_element(conn_list_t *p)
{
+cp
if(p->hostname)
free(p->hostname);
if(p->pp)
free_key(p->public_key);
free_key(p->key);
free(p);
+cp
}
/*
void prune_conn_list(void)
{
conn_list_t *p, *prev = NULL, *next = NULL;
-
+cp
for(p = conn_list; p != NULL; )
{
next = p->next;
p = next;
}
+cp
}
/*
conn_list_t *new_conn_list(void)
{
conn_list_t *p = xmalloc(sizeof(conn_list_t));
-
+cp
/* initialise all those stupid pointers at once */
memset(p, '\0', sizeof(conn_list_t));
p->nexthop = p;
+cp
return p;
}
{
conn_list_t *p, *next;
cp
-
for(p = conn_list; p != NULL; )
{
next = p->next;
free_conn_element(p);
p = next;
}
-cp
conn_list = NULL;
+cp
}
/*
char *name;
struct hostent *host = NULL;
struct in_addr in;
-
+cp
in.s_addr = addr;
host = gethostbyaddr((char *)&in, sizeof(in), AF_INET);
name = xmalloc(20);
sprintf(name, "%s", inet_ntoa(in));
}
-
+cp
return name;
}
int masker;
char *q, *p;
struct hostent *h;
-
+cp
p = str;
if((q = strchr(p, '/')))
{
ip->ip = ntohl(*((ip_t*)(h->h_addr_list[0])));
ip->mask = masker ? ~((1 << (32 - masker)) - 1) : 0;
-
+cp
return ip;
}
void dump_conn_list(void)
{
conn_list_t *p;
-
+cp
syslog(LOG_DEBUG, "Connection list:");
for(p = conn_list; p != NULL; p = p->next)
IP_ADDR_V(p->vpn_ip), IP_ADDR_V(p->vpn_mask), p->status,
p->socket, p->meta_socket);
}
+cp
}
int send_ack(conn_list_t *cl)
{
unsigned char tmp = ACK;
-
+cp
if(debug_lvl > 2)
syslog(LOG_DEBUG, "Send ACK to %s", cl->hostname);
syslog(LOG_ERR, "send failed: %d:%d: %m", __FILE__, __LINE__);
return -1;
}
-
+cp
return 0;
}
int send_termreq(conn_list_t *cl)
{
termreq_t tmp;
-
+cp
tmp.type = TERMREQ;
tmp.vpn_ip = myself->vpn_ip;
syslog(LOG_ERR, "send failed: %s:%d: %m", __FILE__, __LINE__);
return -1;
}
-
+cp
return 0;
}
int send_timeout(conn_list_t *cl)
{
termreq_t tmp;
-
+cp
tmp.type = PINGTIMEOUT;
tmp.vpn_ip = myself->vpn_ip;
syslog(LOG_ERR, "send failed: %s:%d: %m", __FILE__, __LINE__);
return -1;
}
-
+cp
return 0;
}
int send_del_host(conn_list_t *cl, conn_list_t *new_host)
{
del_host_t tmp;
-
+cp
tmp.type = DEL_HOST;
tmp.vpn_ip = new_host->vpn_ip;
syslog(LOG_ERR, "send failed: %s:%d: %m", __FILE__, __LINE__);
return -1;
}
-
+cp
return 0;
}
int send_ping(conn_list_t *cl)
{
unsigned char tmp = PING;
-
+cp
if(debug_lvl > 3)
syslog(LOG_DEBUG, "pinging " IP_ADDR_S, IP_ADDR_V(cl->vpn_ip));
syslog(LOG_ERR, "send failed: %s:%d: %m", __FILE__, __LINE__);
return -1;
}
-
+cp
return 0;
}
int send_pong(conn_list_t *cl)
{
unsigned char tmp = PONG;
-
+cp
if((send(cl->meta_socket, &tmp, sizeof(tmp), 0)) < 0)
{
syslog(LOG_ERR, "send failed: %s:%d: %m", __FILE__, __LINE__);
return -1;
}
-
+cp
return 0;
}
int send_add_host(conn_list_t *cl, conn_list_t *new_host)
{
add_host_t tmp;
-
+cp
tmp.type = ADD_HOST;
tmp.real_ip = new_host->real_ip;
tmp.vpn_ip = new_host->vpn_ip;
syslog(LOG_ERR, "send failed: %s:%d: %m", __FILE__, __LINE__);
return -1;
}
-
+cp
return 0;
}
int send_key_changed(conn_list_t *cl, conn_list_t *src)
{
key_changed_t tmp;
-
+cp
tmp.type = KEY_CHANGED;
tmp.from = src->vpn_ip;
syslog(LOG_ERR, "send failed: %s:%d: %m", __FILE__, __LINE__);
return -1;
}
-
+cp
return 0;
}
void send_key_changed2(void)
{
conn_list_t *p;
-
+cp
for(p = conn_list; p != NULL; p = p->next)
if(p->status.meta && p->protocol_version > PROT_3)
send_key_changed(p, myself);
+cp
}
int send_basic_info(conn_list_t *cl)
{
basic_info_t tmp;
-
+cp
tmp.type = BASIC_INFO;
tmp.protocol = PROT_CURRENT;
syslog(LOG_ERR, "send failed: %s:%d: %m", __FILE__, __LINE__);
return -1;
}
-
+cp
return 0;
}
int send_passphrase(conn_list_t *cl)
{
passphrase_t tmp;
-
+cp
tmp.type = PASSPHRASE;
encrypt_passphrase(&tmp);
syslog(LOG_ERR, "send failed: %s:%d: %m", __FILE__, __LINE__);
return -1;
}
-
+cp
return 0;
}
int send_public_key(conn_list_t *cl)
{
public_key_t *tmp;
-
+cp
tmp = (public_key_t*)xmalloc(strlen(my_public_key_base36)+sizeof(public_key_t));
tmp->type = PUBLIC_KEY;
tmp->len = strlen(my_public_key_base36);
syslog(LOG_ERR, "send failed: %s:%d: %m", __FILE__, __LINE__);
return -1;
}
-
+cp
return 0;
}
int send_calculate(conn_list_t *cl, char *k)
{
calculate_t *tmp;
-
+cp
tmp = xmalloc(strlen(k)+sizeof(calculate_t));
tmp->type = CALCULATE;
tmp->len = strlen(k);
syslog(LOG_ERR, "send failed: %s:%d: %m", __FILE__, __LINE__);
return -1;
}
-
+cp
return 0;
}
{
key_req_t *tmp;
conn_list_t *fw;
-
+cp
tmp = xmalloc(sizeof(key_req_t));
tmp->type = REQ_KEY;
tmp->to = to;
return -1;
}
fw->status.waitingforkey = 1;
-
+cp
return 0;
}
{
key_req_t *tmp;
conn_list_t *fw;
-
+cp
tmp = xmalloc(sizeof(key_req_t)+strlen(my_public_key_base36));
tmp->type = ANS_KEY;
tmp->to = to;
syslog(LOG_ERR, "send failed: %s:%d: %m", __FILE__, __LINE__);
return -1;
}
-
+cp
return 0;
}
int (*function)(conn_list_t*, conn_list_t*))
{
conn_list_t *p;
-
+cp
for(p = conn_list; p != NULL; p = p->next)
if(p != new && p != source && p->status.meta && p->protocol_version > PROT_3)
function(p, new);
-
+cp
return 0;
}
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->protocol_version > PROT_3)
send_add_host(new, p);
-
+cp
return 0;
}
int basic_info_h(conn_list_t *cl, unsigned char *d, int len)
{
basic_info_t *tmp = (basic_info_t*)d;
-
+cp
cl->protocol_version = tmp->protocol;
cl->port = tmp->portnr;
cl->vpn_ip = tmp->vpn_ip;
}
cl->status.active = 0;
-
+cp
return 0;
}
int passphrase_h(conn_list_t *cl, unsigned char *d, int len)
{
passphrase_t *tmp = (passphrase_t*)d;
-
+cp
cl->pp = xmalloc(tmp->len+3);
memcpy(cl->pp, tmp, tmp->len+3);
send_passphrase(cl);
else
send_public_key(cl);
-
+cp
return 0;
}
{
char *g_n;
public_key_t *tmp = (public_key_t*)d;
-
+cp
if(debug_lvl > 2)
syslog(LOG_DEBUG, "got PUBLIC_KEY(%hd,%s)", tmp->len, &tmp->key);
cl->status.active = 1;
notify_others(cl, NULL, send_add_host);
notify_one(cl);
-
+cp
return 0;
}
int ack_h(conn_list_t *cl, unsigned char *d, int len)
{
+cp
if(debug_lvl > 2)
syslog(LOG_DEBUG, "got ACK");
syslog(LOG_NOTICE, "Connection with %s activated.", cl->hostname);
/*
+ === FIXME ===
Now I'm going to cheat. The meta protocol is actually
a stream of requests, that may come in in the same TCP
packet. This is the only place that it will happen,
if(request_handlers[d[1]](cl, d + 1, len - 1) < 0)
return -1;
}
-
+cp
return 0;
}
int termreq_h(conn_list_t *cl, unsigned char *d, int len)
{
+cp
syslog(LOG_NOTICE, IP_ADDR_S " wants to quit", IP_ADDR_V(cl->vpn_ip));
cl->status.termreq = 1;
terminate_connection(cl);
notify_others(cl, NULL, send_del_host);
-
+cp
return 0;
}
int timeout_h(conn_list_t *cl, unsigned char *d, int len)
{
+cp
syslog(LOG_NOTICE, IP_ADDR_S " says it's gotten a timeout from us", IP_ADDR_V(cl->vpn_ip));
cl->status.termreq = 1;
terminate_connection(cl);
-
+cp
return 0;
}
{
del_host_t *tmp = (del_host_t*)d;
conn_list_t *fw;
-
+cp
if(debug_lvl > 2)
syslog(LOG_DEBUG, "got DEL_HOST for " IP_ADDR_S,
IP_ADDR_V(tmp->vpn_ip));
fw->status.termreq = 1;
terminate_connection(fw);
-
+cp
return 0;
}
int ping_h(conn_list_t *cl, unsigned char *d, int len)
{
+cp
if(debug_lvl > 3)
syslog(LOG_DEBUG, "responding to ping from " IP_ADDR_S, IP_ADDR_V(cl->vpn_ip));
cl->status.pinged = 0;
cl->status.got_pong = 1;
send_pong(cl);
-
+cp
return 0;
}
int pong_h(conn_list_t *cl, unsigned char *d, int len)
{
+cp
if(debug_lvl > 3)
syslog(LOG_DEBUG, "ok, got pong from " IP_ADDR_S, IP_ADDR_V(cl->vpn_ip));
cl->status.got_pong = 1;
-
+cp
return 0;
}
{
add_host_t *tmp = (add_host_t*)d;
conn_list_t *ncn, *fw;
-
+cp
if(debug_lvl > 2)
syslog(LOG_DEBUG, "Add host request from " IP_ADDR_S, IP_ADDR_V(cl->vpn_ip));
if(debug_lvl > 3)
if(request_handlers[d[sizeof(add_host_t)]](cl, d + sizeof(add_host_t), len - sizeof(add_host_t)) < 0)
return -1;
}
-
+cp
return 0;
}
{
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));
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(enc_key_t));
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));
syslog(LOG_ERR, "send failed: %s:%d: %m", __FILE__, __LINE__);
return -1;
}
-
+cp
return 0;
}
{
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));
syslog(LOG_DEBUG, "Forwarding key invalidation request");
notify_others(cl, ik, send_key_changed);
-
+cp
return 0;
}
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
};
-