projects
/
tinc
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Merge branch 'master' into 1.1
[tinc]
/
src
/
protocol_key.c
diff --git
a/src/protocol_key.c
b/src/protocol_key.c
index
aae5516
..
069cfd5
100644
(file)
--- a/
src/protocol_key.c
+++ b/
src/protocol_key.c
@@
-1,7
+1,7
@@
/*
protocol_key.c -- handle the meta-protocol, key exchange
Copyright (C) 1999-2005 Ivo Timmermans,
/*
protocol_key.c -- handle the meta-protocol, key exchange
Copyright (C) 1999-2005 Ivo Timmermans,
- 2000-20
09
Guus Sliepen <guus@tinc-vpn.org>
+ 2000-20
10
Guus Sliepen <guus@tinc-vpn.org>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@
-34,15
+34,19
@@
static bool mykeyused = false;
static bool mykeyused = false;
-bool send_key_changed() {
- /* Only send this message if some other daemon requested our key previously.
- This reduces unnecessary key_changed broadcasts.
- */
+void send_key_changed() {
+ avl_node_t *node;
+ connection_t *c;
- if(!mykeyused)
- return true;
+ send_request(broadcast, "%d %x %s", KEY_CHANGED, rand(), myself->name);
+
+ /* Immediately send new keys to directly connected nodes to keep UDP mappings alive */
- return send_request(broadcast, "%d %x %s", KEY_CHANGED, rand(), myself->name);
+ for(node = connection_tree->head; node; node = node->next) {
+ c = node->data;
+ if(c->status.active && c->node && c->node->status.reachable)
+ send_ans_key(c->node);
+ }
}
bool key_changed_h(connection_t *c, char *request) {
}
bool key_changed_h(connection_t *c, char *request) {
@@
-63,11
+67,11
@@
bool key_changed_h(connection_t *c, char *request) {
if(!n) {
logger(LOG_ERR, "Got %s from %s (%s) origin %s which does not exist",
"KEY_CHANGED", c->name, c->hostname, name);
if(!n) {
logger(LOG_ERR, "Got %s from %s (%s) origin %s which does not exist",
"KEY_CHANGED", c->name, c->hostname, name);
- return
fals
e;
+ return
tru
e;
}
n->status.validkey = false;
}
n->status.validkey = false;
- n->
status.waitingforkey = false
;
+ n->
last_req_key = 0
;
/* Tell the others */
/* Tell the others */
@@
-92,12
+96,17
@@
bool req_key_h(connection_t *c, char *request) {
return false;
}
return false;
}
+ if(!check_id(from_name) || !check_id(to_name)) {
+ logger(LOG_ERR, "Got bad %s from %s (%s): %s", "REQ_KEY", c->name, c->hostname, "invalid name");
+ return false;
+ }
+
from = lookup_node(from_name);
if(!from) {
logger(LOG_ERR, "Got %s from %s (%s) origin %s which does not exist in our connection list",
"REQ_KEY", c->name, c->hostname, from_name);
from = lookup_node(from_name);
if(!from) {
logger(LOG_ERR, "Got %s from %s (%s) origin %s which does not exist in our connection list",
"REQ_KEY", c->name, c->hostname, from_name);
- return
fals
e;
+ return
tru
e;
}
to = lookup_node(to_name);
}
to = lookup_node(to_name);
@@
-105,7
+114,7
@@
bool req_key_h(connection_t *c, char *request) {
if(!to) {
logger(LOG_ERR, "Got %s from %s (%s) destination %s which does not exist in our connection list",
"REQ_KEY", c->name, c->hostname, to_name);
if(!to) {
logger(LOG_ERR, "Got %s from %s (%s) destination %s which does not exist in our connection list",
"REQ_KEY", c->name, c->hostname, to_name);
- return
fals
e;
+ return
tru
e;
}
/* Check if this key request is for us */
}
/* Check if this key request is for us */
@@
-115,7
+124,7
@@
bool req_key_h(connection_t *c, char *request) {
send_ans_key(from);
} else {
if(tunnelserver)
send_ans_key(from);
} else {
if(tunnelserver)
- return
fals
e;
+ return
tru
e;
if(!to->status.reachable) {
logger(LOG_WARNING, "Got %s from %s (%s) destination %s which is not reachable",
if(!to->status.reachable) {
logger(LOG_WARNING, "Got %s from %s (%s) destination %s which is not reachable",
@@
-139,6
+148,7
@@
bool send_ans_key(node_t *to) {
randomize(key, keylen);
cipher_set_key(&to->incipher, key, true);
randomize(key, keylen);
cipher_set_key(&to->incipher, key, true);
+ digest_set_key(&to->indigest, key, keylen);
bin2hex(key, key, keylen);
key[keylen * 2] = '\0';
bin2hex(key, key, keylen);
key[keylen * 2] = '\0';
@@
-160,23
+170,30
@@
bool ans_key_h(connection_t *c, char *request) {
char from_name[MAX_STRING_SIZE];
char to_name[MAX_STRING_SIZE];
char key[MAX_STRING_SIZE];
char from_name[MAX_STRING_SIZE];
char to_name[MAX_STRING_SIZE];
char key[MAX_STRING_SIZE];
- int cipher, digest, maclength, compression;
+ char address[MAX_STRING_SIZE] = "";
+ char port[MAX_STRING_SIZE] = "";
+ int cipher, digest, maclength, compression, keylen;
node_t *from, *to;
if(sscanf(request, "%*d "MAX_STRING" "MAX_STRING" "MAX_STRING" %d %d %d %d",
from_name, to_name, key, &cipher, &digest, &maclength,
node_t *from, *to;
if(sscanf(request, "%*d "MAX_STRING" "MAX_STRING" "MAX_STRING" %d %d %d %d",
from_name, to_name, key, &cipher, &digest, &maclength,
- &compression
) !=
7) {
+ &compression
, address, port) <
7) {
logger(LOG_ERR, "Got bad %s from %s (%s)", "ANS_KEY", c->name,
c->hostname);
return false;
}
logger(LOG_ERR, "Got bad %s from %s (%s)", "ANS_KEY", c->name,
c->hostname);
return false;
}
+ if(!check_id(from_name) || !check_id(to_name)) {
+ logger(LOG_ERR, "Got bad %s from %s (%s): %s", "ANS_KEY", c->name, c->hostname, "invalid name");
+ return false;
+ }
+
from = lookup_node(from_name);
if(!from) {
logger(LOG_ERR, "Got %s from %s (%s) origin %s which does not exist in our connection list",
"ANS_KEY", c->name, c->hostname, from_name);
from = lookup_node(from_name);
if(!from) {
logger(LOG_ERR, "Got %s from %s (%s) origin %s which does not exist in our connection list",
"ANS_KEY", c->name, c->hostname, from_name);
- return
fals
e;
+ return
tru
e;
}
to = lookup_node(to_name);
}
to = lookup_node(to_name);
@@
-184,14
+201,14
@@
bool ans_key_h(connection_t *c, char *request) {
if(!to) {
logger(LOG_ERR, "Got %s from %s (%s) destination %s which does not exist in our connection list",
"ANS_KEY", c->name, c->hostname, to_name);
if(!to) {
logger(LOG_ERR, "Got %s from %s (%s) destination %s which does not exist in our connection list",
"ANS_KEY", c->name, c->hostname, to_name);
- return
fals
e;
+ return
tru
e;
}
/* Forward it if necessary */
if(to != myself) {
if(tunnelserver)
}
/* Forward it if necessary */
if(to != myself) {
if(tunnelserver)
- return
fals
e;
+ return
tru
e;
if(!to->status.reachable) {
logger(LOG_WARNING, "Got %s from %s (%s) destination %s which is not reachable",
if(!to->status.reachable) {
logger(LOG_WARNING, "Got %s from %s (%s) destination %s which is not reachable",
@@
-209,7
+226,9
@@
bool ans_key_h(connection_t *c, char *request) {
return false;
}
return false;
}
- if(strlen(key) / 2 != cipher_keylength(&from->outcipher)) {
+ keylen = strlen(key) / 2;
+
+ if(keylen != cipher_keylength(&from->outcipher)) {
logger(LOG_ERR, "Node %s (%s) uses wrong keylength!", from->name, from->hostname);
return false;
}
logger(LOG_ERR, "Node %s (%s) uses wrong keylength!", from->name, from->hostname);
return false;
}
@@
-226,20
+245,27
@@
bool ans_key_h(connection_t *c, char *request) {
if(compression < 0 || compression > 11) {
logger(LOG_ERR, "Node %s (%s) uses bogus compression level!", from->name, from->hostname);
if(compression < 0 || compression > 11) {
logger(LOG_ERR, "Node %s (%s) uses bogus compression level!", from->name, from->hostname);
- return
fals
e;
+ return
tru
e;
}
from->outcompression = compression;
/* Update our copy of the origin's packet key */
}
from->outcompression = compression;
/* Update our copy of the origin's packet key */
- hex2bin(key, key,
cipher_keylength(&from->outcipher)
);
+ hex2bin(key, key,
keylen
);
cipher_set_key(&from->outcipher, key, false);
cipher_set_key(&from->outcipher, key, false);
+ digest_set_key(&from->outdigest, key, keylen);
from->status.validkey = true;
from->status.waitingforkey = false;
from->sent_seqno = 0;
from->status.validkey = true;
from->status.waitingforkey = false;
from->sent_seqno = 0;
+ if(*address && *port) {
+ ifdebug(PROTOCOL) logger(LOG_DEBUG, "Using reflexive UDP address from %s: %s port %s", from->name, address, port);
+ sockaddr_t sa = str2sockaddr(address, port);
+ update_node_udp(from, &sa);
+ }
+
if(from->options & OPTION_PMTU_DISCOVERY && !from->mtuprobes)
send_mtu_probe(from);
if(from->options & OPTION_PMTU_DISCOVERY && !from->mtuprobes)
send_mtu_probe(from);