Handle UDP packets from different and ports than advertised.
Previously, tinc used a fixed address and port for each node for UDP packet exchange. The port was the one advertised by that node as its listening port. However, due to NAT the port might be different. Now, tinc sends a different session key to each node. This way, the sending node can be determined from incoming packets by checking the MAC against all session keys. If a match is found, the address and port for that node are updated.
This commit is contained in:
parent
43fa7283ac
commit
3308d13e7e
9 changed files with 242 additions and 149 deletions
33
src/netutl.c
33
src/netutl.c
|
|
@ -144,6 +144,39 @@ char *sockaddr2hostname(const sockaddr_t *sa)
|
|||
return str;
|
||||
}
|
||||
|
||||
int sockaddrcmp_noport(const sockaddr_t *a, const sockaddr_t *b)
|
||||
{
|
||||
int result;
|
||||
|
||||
cp();
|
||||
|
||||
result = a->sa.sa_family - b->sa.sa_family;
|
||||
|
||||
if(result)
|
||||
return result;
|
||||
|
||||
switch (a->sa.sa_family) {
|
||||
case AF_UNSPEC:
|
||||
return 0;
|
||||
|
||||
case AF_UNKNOWN:
|
||||
return strcmp(a->unknown.address, b->unknown.address);
|
||||
|
||||
case AF_INET:
|
||||
return memcmp(&a->in.sin_addr, &b->in.sin_addr, sizeof(a->in.sin_addr));
|
||||
|
||||
case AF_INET6:
|
||||
return memcmp(&a->in6.sin6_addr, &b->in6.sin6_addr, sizeof(a->in6.sin6_addr));
|
||||
|
||||
default:
|
||||
logger(LOG_ERR, _("sockaddrcmp() was called with unknown address family %d, exitting!"),
|
||||
a->sa.sa_family);
|
||||
cp_trace();
|
||||
raise(SIGFPE);
|
||||
exit(0);
|
||||
}
|
||||
}
|
||||
|
||||
int sockaddrcmp(const sockaddr_t *a, const sockaddr_t *b)
|
||||
{
|
||||
int result;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue