From 12e55935c2389de49e0cd2bad9c00844746beb1b Mon Sep 17 00:00:00 2001 From: Logan oos Even <46396513+Logan007@users.noreply.github.com> Date: Sun, 7 Feb 2021 19:00:58 +0545 Subject: [PATCH] adjusted supernode management port output (#628) --- src/edge_utils.c | 2 +- src/sn_utils.c | 27 ++++++++++++++++++++------- 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/src/edge_utils.c b/src/edge_utils.c index d96ca66..55e3a72 100644 --- a/src/edge_utils.c +++ b/src/edge_utils.c @@ -1487,7 +1487,7 @@ static void readFromMgmtSocket (n2n_edge_t *eee, int *keep_running) { msg_len += snprintf((char *) (udp_buf + msg_len), (N2N_PKT_BUF_SIZE - msg_len), "COMMUNITY '%s'\n\n", eee->conf.community_name); - msg_len += snprintf((char *) (udp_buf + msg_len), (N2N_PKT_BUF_SIZE - msg_len), + msg_len += snprintf((char *) (udp_buf + msg_len), (N2N_PKT_BUF_SIZE - msg_len), " ### | TAP | MAC | EDGE | HINT | LAST SEEN\n"); msg_len += snprintf((char *) (udp_buf + msg_len), (N2N_PKT_BUF_SIZE - msg_len), "================================================================================================\n"); diff --git a/src/sn_utils.c b/src/sn_utils.c index c180afa..e341e6a 100644 --- a/src/sn_utils.c +++ b/src/sn_utils.c @@ -835,42 +835,55 @@ static int process_mgmt (n2n_sn_t *sss, char resbuf[N2N_SN_PKTBUF_SIZE]; size_t ressize = 0; uint32_t num_edges = 0; + uint32_t num_comm = 0; uint32_t num = 0; struct sn_community *community, *tmp; struct peer_info *peer, *tmpPeer; macstr_t mac_buf; n2n_sock_str_t sockbuf; + char time_buf[10]; /* 9 digits + 1 terminating zero */ dec_ip_bit_str_t ip_bit_str = {'\0'}; traceEvent(TRACE_DEBUG, "process_mgmt"); ressize += snprintf(resbuf + ressize, N2N_SN_PKTBUF_SIZE - ressize, - " id tun_tap MAC edge hint last_seen\n"); + " ### | TAP | MAC | EDGE | HINT | LAST SEEN\n"); ressize += snprintf(resbuf + ressize, N2N_SN_PKTBUF_SIZE - ressize, - "-------------------------------------------------------------------------------------------------\n"); + "====================================================================================================\n"); HASH_ITER(hh, sss->communities, community, tmp) { + if(num_comm) + ressize += snprintf(resbuf + ressize, N2N_SN_PKTBUF_SIZE - ressize, + "----------------------------------------------------------------------------------------------------\n"); + num_comm++; num_edges += HASH_COUNT(community->edges); + ressize += snprintf(resbuf + ressize, N2N_SN_PKTBUF_SIZE - ressize, - "community: %s\n", community->community); + "%s '%s'\n", + (community->is_federation) ? "FEDERATION" : + ((community->purgeable == COMMUNITY_UNPURGEABLE) ? "FIXED NAME COMMUNITY" : "COMMUNITY"), + community->community); sendto_mgmt(sss, sender_sock, (const uint8_t *) resbuf, ressize); ressize = 0; num = 0; HASH_ITER(hh, community->edges, peer, tmpPeer) { + sprintf (time_buf, "%9u", now - peer->last_seen); ressize += snprintf(resbuf + ressize, N2N_SN_PKTBUF_SIZE - ressize, - " %-4u %-18s %-17s %-21s %-15s %lu\n", - ++num, ip_subnet_to_str(ip_bit_str, &peer->dev_addr), + "%4u | %-19s | %-17s | %-21s | %-15s | %9s\n", + ++num, + (peer->dev_addr.net_addr == 0) ? ((peer->purgeable == SN_UNPURGEABLE) ? "-l" : "") : + ip_subnet_to_str(ip_bit_str, &peer->dev_addr), macaddr_str(mac_buf, peer->mac_addr), sock_to_cstr(sockbuf, &(peer->sock)), peer->dev_desc, - now - peer->last_seen); + (peer->last_seen) ? time_buf : ""); sendto_mgmt(sss, sender_sock, (const uint8_t *) resbuf, ressize); ressize = 0; } } ressize += snprintf(resbuf + ressize, N2N_SN_PKTBUF_SIZE - ressize, - "----------------------------------------------------------------------------------------------------\n"); + "====================================================================================================\n"); ressize += snprintf(resbuf + ressize, N2N_SN_PKTBUF_SIZE - ressize, "uptime %lu | ", (now - sss->start_time));