Browse Source

Improve log messages

pull/128/head
emanuele-f 6 years ago
parent
commit
623a9e480c
  1. 49
      edge_utils.c

49
edge_utils.c

@ -350,7 +350,7 @@ static void supernode2addr(n2n_sock_t * sn, const n2n_sn_name_t addrIn) {
static void register_with_local_peers(n2n_edge_t * eee) { static void register_with_local_peers(n2n_edge_t * eee) {
/* no send registration to the local multicast group */ /* no send registration to the local multicast group */
traceEvent(TRACE_INFO, "Registering with multicast group %s:%u", traceEvent(TRACE_INFO, "Registering with multicast group %s:%u",
N2N_MULTICAST_GROUP, N2N_MULTICAST_PORT); N2N_MULTICAST_GROUP, N2N_MULTICAST_PORT);
send_register(eee, &(eee->multicast_peer), NULL); send_register(eee, &(eee->multicast_peer), NULL);
} }
@ -414,7 +414,7 @@ static void check_peer_registration_needed(n2n_edge_t * eee,
const n2n_mac_t mac, const n2n_mac_t mac,
const n2n_sock_t * peer) { const n2n_sock_t * peer) {
struct peer_info * scan = find_peer_by_mac(eee->known_peers, mac); struct peer_info * scan = find_peer_by_mac(eee->known_peers, mac);
if(scan == NULL) { if(scan == NULL) {
/* Not in known_peers - start the REGISTER process. */ /* Not in known_peers - start the REGISTER process. */
register_with_new_peer(eee, from_supernode, mac, peer); register_with_new_peer(eee, from_supernode, mac, peer);
@ -443,10 +443,6 @@ static void peer_set_p2p_confirmed(n2n_edge_t * eee,
macstr_t mac_buf; macstr_t mac_buf;
n2n_sock_str_t sockbuf; n2n_sock_str_t sockbuf;
traceEvent(TRACE_NORMAL, "P2P TX connection enstablished: %s [%s]",
macaddr_str(mac_buf, mac),
sock_to_cstr(sockbuf, peer));
scan=eee->pending_peers; scan=eee->pending_peers;
while (NULL != scan) while (NULL != scan)
@ -480,6 +476,10 @@ static void peer_set_p2p_confirmed(n2n_edge_t * eee,
scan->sock = *peer; scan->sock = *peer;
traceEvent(TRACE_NORMAL, "P2P connection enstablished: %s [%s]",
macaddr_str(mac_buf, mac),
sock_to_cstr(sockbuf, peer));
traceEvent(TRACE_DEBUG, "=== new peer %s -> %s", traceEvent(TRACE_DEBUG, "=== new peer %s -> %s",
macaddr_str(mac_buf, scan->mac_addr), macaddr_str(mac_buf, scan->mac_addr),
sock_to_cstr(sockbuf, &(scan->sock))); sock_to_cstr(sockbuf, &(scan->sock)));
@ -730,7 +730,7 @@ static void send_register_ack(n2n_edge_t * eee,
*/ */
static void update_supernode_reg(n2n_edge_t * eee, time_t nowTime) { static void update_supernode_reg(n2n_edge_t * eee, time_t nowTime) {
u_int sn_idx; u_int sn_idx;
if(eee->sn_wait && (nowTime > (eee->last_register_req + (eee->conf.register_interval/10)))) { if(eee->sn_wait && (nowTime > (eee->last_register_req + (eee->conf.register_interval/10)))) {
/* fall through */ /* fall through */
traceEvent(TRACE_DEBUG, "update_supernode_reg: doing fast retry."); traceEvent(TRACE_DEBUG, "update_supernode_reg: doing fast retry.");
@ -756,16 +756,16 @@ static void update_supernode_reg(n2n_edge_t * eee, time_t nowTime) {
for(sn_idx=0; sn_idx<eee->conf.sn_num; sn_idx++) { for(sn_idx=0; sn_idx<eee->conf.sn_num; sn_idx++) {
supernode2addr(&(eee->supernode), eee->conf.sn_ip_array[sn_idx]); supernode2addr(&(eee->supernode), eee->conf.sn_ip_array[sn_idx]);
traceEvent(TRACE_INFO, "Registering with supernode [id: %u/%u][%s][attempts left %u]", traceEvent(TRACE_INFO, "Registering with supernode [id: %u/%u][%s][attempts left %u]",
sn_idx+1, eee->conf.sn_num, sn_idx+1, eee->conf.sn_num,
supernode_ip(eee), (unsigned int)eee->sup_attempts); supernode_ip(eee), (unsigned int)eee->sup_attempts);
send_register_super(eee, &(eee->supernode)); send_register_super(eee, &(eee->supernode));
} }
register_with_local_peers(eee); register_with_local_peers(eee);
eee->sn_wait=1; eee->sn_wait=1;
/* REVISIT: turn-on gratuitous ARP with config option. */ /* REVISIT: turn-on gratuitous ARP with config option. */
@ -1032,11 +1032,11 @@ static int is_ip6_discovery(const void * buf, size_t bufsize) {
if(bufsize >= sizeof(ether_hdr_t)) { if(bufsize >= sizeof(ether_hdr_t)) {
/* copy to aligned memory */ /* copy to aligned memory */
ether_hdr_t eh; ether_hdr_t eh;
memcpy(&eh, buf, sizeof(ether_hdr_t)); memcpy(&eh, buf, sizeof(ether_hdr_t));
if((0x33 == eh.dhost[0]) && (0x33 == eh.dhost[1])) if((0x33 == eh.dhost[0]) && (0x33 == eh.dhost[1]))
retval = 1; /* This is an IPv6 multicast packet [RFC2464]. */ retval = 1; /* This is an IPv6 multicast packet [RFC2464]. */
} }
return retval; return retval;
} }
@ -1338,7 +1338,7 @@ static void readFromIPSocket(n2n_edge_t * eee, int in_sock) {
traceEvent(TRACE_ERROR, "WSAGetLastError(): %u", WSAGetLastError()); traceEvent(TRACE_ERROR, "WSAGetLastError(): %u", WSAGetLastError());
#endif #endif
} }
return; /* failed to receive data from UDP */ return; /* failed to receive data from UDP */
} }
@ -1395,7 +1395,7 @@ static void readFromIPSocket(n2n_edge_t * eee, int in_sock) {
n2n_REGISTER_t reg; n2n_REGISTER_t reg;
n2n_mac_t null_mac = { '\0' }; n2n_mac_t null_mac = { '\0' };
int skip_register = 0; int skip_register = 0;
decode_REGISTER(&reg, &cmn, udp_buf, &rem, &idx); decode_REGISTER(&reg, &cmn, udp_buf, &rem, &idx);
if(is_valid_peer_sock(&reg.sock)) if(is_valid_peer_sock(&reg.sock))
@ -1539,7 +1539,7 @@ int run_edge_loop(n2n_edge_t * eee, int *keep_running) {
*keep_running = 1; *keep_running = 1;
update_supernode_reg(eee, time(NULL)); update_supernode_reg(eee, time(NULL));
/* Main loop /* Main loop
* *
* select() is used to wait for input on either the TAP fd or the UDP/TCP * select() is used to wait for input on either the TAP fd or the UDP/TCP
@ -1559,7 +1559,7 @@ int run_edge_loop(n2n_edge_t * eee, int *keep_running) {
max_sock = max(eee->udp_sock, eee->udp_mgmt_sock); max_sock = max(eee->udp_sock, eee->udp_mgmt_sock);
FD_SET(eee->udp_multicast_sock, &socket_mask); FD_SET(eee->udp_multicast_sock, &socket_mask);
max_sock = max(eee->udp_sock, eee->udp_multicast_sock); max_sock = max(eee->udp_sock, eee->udp_multicast_sock);
#ifndef WIN32 #ifndef WIN32
FD_SET(eee->device.fd, &socket_mask); FD_SET(eee->device.fd, &socket_mask);
max_sock = max(max_sock, eee->device.fd); max_sock = max(max_sock, eee->device.fd);
@ -1576,7 +1576,7 @@ int run_edge_loop(n2n_edge_t * eee, int *keep_running) {
eee->transop.tick(&eee->transop, nowTime); eee->transop.tick(&eee->transop, nowTime);
} }
if(rc > 0) { if(rc > 0) {
/* Any or all of the FDs could have input; check them all. */ /* Any or all of the FDs could have input; check them all. */
@ -1622,7 +1622,8 @@ int run_edge_loop(n2n_edge_t * eee, int *keep_running) {
numPurged += purge_expired_registrations(&(eee->pending_peers), &last_purge_pending); numPurged += purge_expired_registrations(&(eee->pending_peers), &last_purge_pending);
if(numPurged > 0) { if(numPurged > 0) {
traceEvent(TRACE_NORMAL, "Peer removed: pending=%u, operational=%u", traceEvent(TRACE_INFO, "%u peers removed. now: pending=%u, operational=%u",
numPurged,
(unsigned int)peer_list_size(eee->pending_peers), (unsigned int)peer_list_size(eee->pending_peers),
(unsigned int)peer_list_size(eee->known_peers)); (unsigned int)peer_list_size(eee->known_peers));
} }
@ -1655,12 +1656,12 @@ int run_edge_loop(n2n_edge_t * eee, int *keep_running) {
void edge_term(n2n_edge_t * eee) { void edge_term(n2n_edge_t * eee) {
if(eee->udp_sock >= 0) if(eee->udp_sock >= 0)
closesocket(eee->udp_sock); closesocket(eee->udp_sock);
if(eee->udp_mgmt_sock >= 0) if(eee->udp_mgmt_sock >= 0)
closesocket(eee->udp_mgmt_sock); closesocket(eee->udp_mgmt_sock);
if(eee->udp_multicast_sock >= 0) if(eee->udp_multicast_sock >= 0)
closesocket(eee->udp_multicast_sock); closesocket(eee->udp_multicast_sock);
clear_peer_list(&(eee->pending_peers)); clear_peer_list(&(eee->pending_peers));
clear_peer_list(&(eee->known_peers)); clear_peer_list(&(eee->known_peers));
@ -1702,7 +1703,7 @@ static int edge_init_sockets(n2n_edge_t *eee, int udp_local_port, int mgmt_port)
/* Bind eee->udp_multicast_sock to multicast group */ /* Bind eee->udp_multicast_sock to multicast group */
struct ip_mreq mreq; struct ip_mreq mreq;
u_int enable_reuse = 1; u_int enable_reuse = 1;
/* allow multiple sockets to use the same PORT number */ /* allow multiple sockets to use the same PORT number */
setsockopt(eee->udp_multicast_sock, SOL_SOCKET, SO_REUSEADDR, (char *)&enable_reuse, sizeof(enable_reuse)); setsockopt(eee->udp_multicast_sock, SOL_SOCKET, SO_REUSEADDR, (char *)&enable_reuse, sizeof(enable_reuse));
#ifdef SO_REUSEPORT /* no SO_REUSEPORT in Windows / old linux versions */ #ifdef SO_REUSEPORT /* no SO_REUSEPORT in Windows / old linux versions */
@ -1719,7 +1720,7 @@ static int edge_init_sockets(n2n_edge_t *eee, int udp_local_port, int mgmt_port)
traceEvent(TRACE_ERROR, "WSAGetLastError(): %u", WSAGetLastError()); traceEvent(TRACE_ERROR, "WSAGetLastError(): %u", WSAGetLastError());
#endif #endif
return(-4); return(-4);
} }
} }
return(0); return(0);

Loading…
Cancel
Save