Browse Source

fix supernode coredump when accessing management socket

pull/320/head
switch_st 4 years ago
parent
commit
37bc520db2
  1. 54
      src/sn_utils.c

54
src/sn_utils.c

@ -15,6 +15,11 @@ static ssize_t sendto_sock(n2n_sn_t *sss,
const uint8_t *pktbuf, const uint8_t *pktbuf,
size_t pktsize); size_t pktsize);
static int sendto_mgmt(n2n_sn_t *sss,
const struct sockaddr_in *sender_sock,
const uint8_t *mgmt_buf,
size_t mgmt_size);
static int try_broadcast(n2n_sn_t * sss, static int try_broadcast(n2n_sn_t * sss,
const struct sn_community *comm, const struct sn_community *comm,
const n2n_common_t * cmn, const n2n_common_t * cmn,
@ -295,10 +300,11 @@ static int process_mgmt(n2n_sn_t *sss,
char resbuf[N2N_SN_PKTBUF_SIZE]; char resbuf[N2N_SN_PKTBUF_SIZE];
size_t ressize = 0; size_t ressize = 0;
uint32_t num_edges = 0; uint32_t num_edges = 0;
ssize_t r; uint32_t num = 0;
struct sn_community *community, *tmp; struct sn_community *community, *tmp;
struct peer_info * peer, *tmpPeer; struct peer_info * peer, *tmpPeer;
macstr_t mac_buf; macstr_t mac_buf;
n2n_sock_str_t sockbuf;
traceEvent(TRACE_DEBUG, "process_mgmt"); traceEvent(TRACE_DEBUG, "process_mgmt");
@ -346,30 +352,46 @@ static int process_mgmt(n2n_sn_t *sss,
(long unsigned int)(now - sss->stats.last_reg_super)); (long unsigned int)(now - sss->stats.last_reg_super));
ressize += snprintf(resbuf+ressize, N2N_SN_PKTBUF_SIZE-ressize, ressize += snprintf(resbuf+ressize, N2N_SN_PKTBUF_SIZE-ressize,
"cur_cmnts"); "cur_cmnts %u\n", HASH_COUNT(sss->communities));
HASH_ITER(hh, sss->communities, community, tmp) { HASH_ITER(hh, sss->communities, community, tmp) {
ressize += snprintf(resbuf+ressize, N2N_SN_PKTBUF_SIZE-ressize, ressize += snprintf(resbuf + ressize, N2N_SN_PKTBUF_SIZE - ressize,
" [%s]", "community: %s\n", community->community);
community->community); sendto_mgmt(sss, sender_sock, resbuf, ressize);
ressize = 0;
num = 0;
HASH_ITER(hh, community->edges, peer, tmpPeer) { HASH_ITER(hh, community->edges, peer, tmpPeer) {
ressize += snprintf(resbuf+ressize, N2N_SN_PKTBUF_SIZE-ressize, ressize += snprintf(resbuf + ressize, N2N_SN_PKTBUF_SIZE - ressize,
" {%s}", "\t[id: %u][MAC: %s][edge: %s][last seen: %lu sec ago]\n",
macaddr_str(mac_buf, peer->mac_addr)); ++num, macaddr_str(mac_buf, peer->mac_addr),
sock_to_cstr(sockbuf, &(peer->sock)), now-peer->last_seen);
sendto_mgmt(sss, sender_sock, resbuf, ressize);
ressize = 0;
} }
} }
ressize += snprintf(resbuf+ressize, N2N_SN_PKTBUF_SIZE-ressize, ressize += snprintf(resbuf+ressize, N2N_SN_PKTBUF_SIZE-ressize,
"\n"); "\n");
sendto_mgmt(sss, sender_sock, resbuf, ressize);
r = sendto(sss->mgmt_sock, resbuf, ressize, 0 /*flags*/, return 0;
(struct sockaddr *)sender_sock, sizeof(struct sockaddr_in)); }
if (r <= 0) static int sendto_mgmt(n2n_sn_t *sss,
{ const struct sockaddr_in *sender_sock,
++(sss->stats.errors); const uint8_t *mgmt_buf,
traceEvent(TRACE_ERROR, "process_mgmt : sendto failed. %s", strerror(errno)); size_t mgmt_size)
} {
ssize_t r = sendto(sss->mgmt_sock, mgmt_buf, mgmt_size, 0 /*flags*/,
(struct sockaddr *)sender_sock, sizeof (struct sockaddr_in));
return 0; if (r <= 0) {
++(sss->stats.errors);
traceEvent (TRACE_ERROR, "process_mgmt : sendto failed. %s", strerror (errno));
return -1;
}
return 0;
} }
/** Examine a datagram and determine what to do with it. /** Examine a datagram and determine what to do with it.

Loading…
Cancel
Save