Skip to content

Commit 98738bc

Browse files
authored
edge, supernode: allow -t 0 to disable the management UDP port (#1242)
* supernode: allow -t 0 to disable the management port * supernode: skip mgmt-socket fd_set/fd_isset when disabled * edge: allow -t 0 to disable the management port * edge: skip mgmt-socket fd_set/fd_isset when disabled * docs: document -t 0 to disable the management port
1 parent 829fcd3 commit 98738bc

6 files changed

Lines changed: 29 additions & 23 deletions

File tree

edge.8

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ do not fork and run as a daemon, rather run in foreground
189189
\fB\-t \fR<\fIport\fR>
190190
binds the edge management system to the given UDP port. Default 5644. Use this
191191
if you need to run multiple instance of edge; or something is bound to that
192-
port.
192+
port. A value of 0 disables the management API entirely (no UDP socket is bound).
193193
.TP
194194
\fB\-\-management-password \fR<\fIpassword\fR>
195195
sets the password for access to JSON API at the management port, defaults to 'n2n'. The password

src/edge.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,7 @@ static void help (int level) {
361361
printf(" -f | do not fork and run as a daemon, rather run in foreground\n");
362362
#endif
363363
printf(" -t <port> | management UDP port, for multiple edges on a machine,\n"
364-
" | defaults to %u\n", N2N_EDGE_MGMT_PORT);
364+
" | defaults to %u; 0 disables the management API\n", N2N_EDGE_MGMT_PORT);
365365
printf(" --management_... | management port password, defaults to '%s'\n"
366366
" ...password <pw> | \n", N2N_MGMT_PASSWORD);
367367
printf(" -v | make more verbose, repeat as required\n");

src/edge_utils.c

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2913,7 +2913,8 @@ int run_edge_loop (n2n_edge_t *eee) {
29132913

29142914
FD_ZERO(&socket_mask);
29152915

2916-
FD_SET(eee->udp_mgmt_sock, &socket_mask);
2916+
if(eee->udp_mgmt_sock >= 0)
2917+
FD_SET(eee->udp_mgmt_sock, &socket_mask);
29172918
max_sock = eee->udp_mgmt_sock;
29182919

29192920
if(eee->sock >= 0) {
@@ -2980,7 +2981,7 @@ int run_edge_loop (n2n_edge_t *eee) {
29802981
}
29812982
#endif
29822983

2983-
if(FD_ISSET(eee->udp_mgmt_sock, &socket_mask)) {
2984+
if(eee->udp_mgmt_sock >= 0 && FD_ISSET(eee->udp_mgmt_sock, &socket_mask)) {
29842985
// read from the management port socket
29852986
readFromMgmtSocket(eee);
29862987

@@ -3122,10 +3123,14 @@ static int edge_init_sockets (n2n_edge_t *eee) {
31223123
closesocket(eee->udp_multicast_sock);
31233124
#endif
31243125

3125-
eee->udp_mgmt_sock = open_socket(eee->conf.mgmt_port, INADDR_LOOPBACK, 0 /* UDP */);
3126-
if(eee->udp_mgmt_sock < 0) {
3127-
traceEvent(TRACE_ERROR, "failed to bind management UDP port %u", eee->conf.mgmt_port);
3128-
return(-2);
3126+
if(eee->conf.mgmt_port == 0) {
3127+
traceEvent(TRACE_NORMAL, "management port disabled");
3128+
} else {
3129+
eee->udp_mgmt_sock = open_socket(eee->conf.mgmt_port, INADDR_LOOPBACK, 0 /* UDP */);
3130+
if(eee->udp_mgmt_sock < 0) {
3131+
traceEvent(TRACE_ERROR, "failed to bind management UDP port %u", eee->conf.mgmt_port);
3132+
return(-2);
3133+
}
31293134
}
31303135

31313136
#ifndef SKIP_MULTICAST_PEERS_DISCOVERY

src/sn_utils.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2609,7 +2609,8 @@ int run_sn_loop (n2n_sn_t *sss) {
26092609
#ifdef N2N_HAVE_TCP
26102610
FD_SET(sss->tcp_sock, &socket_mask);
26112611
#endif
2612-
FD_SET(sss->mgmt_sock, &socket_mask);
2612+
if(sss->mgmt_sock >= 0)
2613+
FD_SET(sss->mgmt_sock, &socket_mask);
26132614

26142615
max_sock = MAX(MAX(sss->sock, sss->mgmt_sock), sss->tcp_sock);
26152616

@@ -2761,7 +2762,7 @@ int run_sn_loop (n2n_sn_t *sss) {
27612762
#endif /* N2N_HAVE_TCP */
27622763

27632764
// handle management port input
2764-
if(FD_ISSET(sss->mgmt_sock, &socket_mask)) {
2765+
if(sss->mgmt_sock >= 0 && FD_ISSET(sss->mgmt_sock, &socket_mask)) {
27652766
struct sockaddr_storage sas;
27662767
struct sockaddr *sender_sock = (struct sockaddr*)&sas;
27672768
socklen_t ss_size = sizeof(sas);

src/supernode.c

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ static void help (int level) {
163163
printf(" -f | do not fork and run as a daemon, rather run in foreground\n");
164164
#endif
165165
printf(" -t <port> | management UDP port, for multiple supernodes on a machine,\n"
166-
" | defaults to %u\n", N2N_SN_MGMT_PORT);
166+
" | defaults to %u; 0 disables the management API\n", N2N_SN_MGMT_PORT);
167167
printf(" --management_... | management port password, defaults to '%s'\n"
168168
" ...password <pw> | \n", N2N_MGMT_PASSWORD);
169169
printf(" -v | make more verbose, repeat as required\n");
@@ -225,13 +225,8 @@ static int setOption (int optkey, char *_optarg, n2n_sn_t *sss) {
225225
break;
226226
}
227227

228-
case 't': /* mgmt-port */
228+
case 't': /* mgmt-port; 0 disables the management API */
229229
sss->mport = atoi(_optarg);
230-
231-
if(sss->mport == 0)
232-
traceEvent(TRACE_WARNING, "bad management port format, defaulting to %u", N2N_SN_MGMT_PORT);
233-
// default is made sure in sn_init()
234-
235230
break;
236231

237232
case 'l': { /* supernode:port */
@@ -677,12 +672,16 @@ int main (int argc, char * const argv[]) {
677672
}
678673
#endif
679674

680-
sss_node.mgmt_sock = open_socket(sss_node.mport, INADDR_LOOPBACK, 0 /* UDP */);
681-
if(-1 == sss_node.mgmt_sock) {
682-
traceEvent(TRACE_ERROR, "failed to open management socket, %s", strerror(errno));
683-
exit(-2);
675+
if(sss_node.mport == 0) {
676+
traceEvent(TRACE_NORMAL, "management port disabled");
684677
} else {
685-
traceEvent(TRACE_NORMAL, "supernode is listening on UDP %u (management)", sss_node.mport);
678+
sss_node.mgmt_sock = open_socket(sss_node.mport, INADDR_LOOPBACK, 0 /* UDP */);
679+
if(-1 == sss_node.mgmt_sock) {
680+
traceEvent(TRACE_ERROR, "failed to open management socket, %s", strerror(errno));
681+
exit(-2);
682+
} else {
683+
traceEvent(TRACE_NORMAL, "supernode is listening on UDP %u (management)", sss_node.mport);
684+
}
686685
}
687686

688687
HASH_ITER(hh, sss_node.federation->edges, scan, tmp)

supernode.1

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,8 @@ defaults to '10.128.255.0-10.255.255.0/24'
6666
disable daemon mode (UNIX) and run in foreground.
6767
.TP
6868
\fB\-t \fR<\fIport\fR>, \fB\-\-mgmt-port\fR=<\fIport\fR>
69-
management UDP port, for multiple supernodes on a machine, defaults to 5645
69+
management UDP port, for multiple supernodes on a machine, defaults to 5645.
70+
A value of 0 disables the management API entirely (no UDP socket is bound).
7071
.TP
7172
\fB\-\-management-password \fR<\fIpassword\fR>
7273
sets the password for access to JSON API at the management port, defaults to 'n2n'. The password

0 commit comments

Comments
 (0)