Logan oos Even
3 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with
15 additions and
16 deletions
-
src/edge.c
-
src/edge_utils.c
|
|
@ -626,8 +626,9 @@ static int setOption (int optkey, char *optargument, n2n_tuntap_priv_config_t *e |
|
|
|
break; |
|
|
|
} else { |
|
|
|
conf->preferred_sock.family = AF_INET; |
|
|
|
// port is set after parsing all cli parameters
|
|
|
|
// port is set after parsing all cli parameters during supernode_connect()
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
break; |
|
|
@ -1063,18 +1064,6 @@ int main (int argc, char* argv[]) { |
|
|
|
if(conf.encrypt_key && !strcmp((char*)conf.community_name, conf.encrypt_key)) |
|
|
|
traceEvent(TRACE_WARNING, "community and encryption key must differ, otherwise security will be compromised"); |
|
|
|
|
|
|
|
// so far, preferred local sock (-e) only works with a fixed port provided (-p)
|
|
|
|
if(conf.preferred_sock.family != AF_INVALID) { |
|
|
|
conf.preferred_sock.port = conf.local_port; |
|
|
|
if(conf.local_port == 0) { |
|
|
|
traceEvent(TRACE_WARNING, "preferred local socket requires a port to be provided (-p), skipping"); |
|
|
|
conf.preferred_sock.family = AF_INVALID; |
|
|
|
in_addr_t address_tmp = INADDR_NONE; |
|
|
|
memcpy(&(conf.preferred_sock.addr.v4), &(address_tmp), IPV4_SIZE); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if((eee = edge_init(&conf, &rc)) == NULL) { |
|
|
|
traceEvent(TRACE_ERROR, "failed in edge_init"); |
|
|
|
exit(1); |
|
|
|
|
|
@ -203,6 +203,8 @@ void reset_sup_attempts (n2n_edge_t *eee) { |
|
|
|
int supernode_connect(n2n_edge_t *eee) { |
|
|
|
|
|
|
|
int sockopt; |
|
|
|
struct sockaddr_in sock; |
|
|
|
int sock_len = sizeof(sock); |
|
|
|
|
|
|
|
if((eee->conf.connect_tcp) && (eee->sock >= 0)) { |
|
|
|
closesocket(eee->sock); |
|
|
@ -225,10 +227,15 @@ int supernode_connect(n2n_edge_t *eee) { |
|
|
|
return -1; |
|
|
|
} |
|
|
|
|
|
|
|
if(eee->cb.sock_opened) |
|
|
|
eee->cb.sock_opened(eee); |
|
|
|
// detetct local port, even/especially if chosen by OS...
|
|
|
|
if((getsockname(eee->sock, (struct sockaddr *)&sock, &sock_len) == 0) |
|
|
|
&& (sock.sin_family == AF_INET) |
|
|
|
&& (sock_len == sizeof(sock))) { |
|
|
|
// ... and write to local preferred socket -- no matter if used or not
|
|
|
|
eee->conf.preferred_sock.port = ntohs(sock.sin_port); |
|
|
|
} |
|
|
|
|
|
|
|
struct sockaddr_in sock; |
|
|
|
// variable 'sock' gets re-used from here on (for sn)
|
|
|
|
sock.sin_family = eee->curr_sn->sock.family; |
|
|
|
sock.sin_port = htons(eee->curr_sn->sock.port); |
|
|
|
memcpy(&(sock.sin_addr.s_addr), &(eee->curr_sn->sock.addr.v4), IPV4_SIZE); |
|
|
@ -267,6 +274,9 @@ int supernode_connect(n2n_edge_t *eee) { |
|
|
|
else |
|
|
|
traceEvent(TRACE_INFO, "PMTU discovery %s", (eee->conf.disable_pmtu_discovery) ? "disabled" : "enabled"); |
|
|
|
#endif |
|
|
|
|
|
|
|
if(eee->cb.sock_opened) |
|
|
|
eee->cb.sock_opened(eee); |
|
|
|
} |
|
|
|
|
|
|
|
return 0; |
|
|
|