Browse Source

Merge pull request #325 from switch-iot/feature_sn_mgmt_port

add management port command option to supernode
pull/329/head
Luca Deri 4 years ago
committed by GitHub
parent
commit
1284e5662c
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      include/n2n.h
  2. 19
      src/sn.c
  3. 1
      src/sn_utils.c

1
include/n2n.h

@ -361,6 +361,7 @@ typedef struct n2n_sn
sn_stats_t stats; sn_stats_t stats;
int daemon; /* If non-zero then daemonise. */ int daemon; /* If non-zero then daemonise. */
uint16_t lport; /* Local UDP port to bind to. */ uint16_t lport; /* Local UDP port to bind to. */
uint16_t mport; /* Management UDP port to bind to. */
int sock; /* Main socket for UDP traffic with edges. */ int sock; /* Main socket for UDP traffic with edges. */
int mgmt_sock; /* management socket. */ int mgmt_sock; /* management socket. */
int lock_communities; /* If true, only loaded communities can be used. */ int lock_communities; /* If true, only loaded communities can be used. */

19
src/sn.c

@ -104,19 +104,21 @@ static void help() {
"or\n" "or\n"
); );
printf("supernode "); printf("supernode ");
printf("-l <lport> "); printf("-l <local port> ");
printf("-c <path> "); printf("-c <path> ");
#if defined(N2N_HAVE_DAEMON) #if defined(N2N_HAVE_DAEMON)
printf("[-f] "); printf("[-f] ");
#endif #endif
printf("[-t <mgmt port>] ");
printf("[-v] "); printf("[-v] ");
printf("\n\n"); printf("\n\n");
printf("-l <lport>\tSet UDP main listen port to <lport>\n"); printf("-l <port>\tSet UDP main listen port to <port>\n");
printf("-c <path>\tFile containing the allowed communities.\n"); printf("-c <path>\tFile containing the allowed communities.\n");
#if defined(N2N_HAVE_DAEMON) #if defined(N2N_HAVE_DAEMON)
printf("-f \tRun in foreground.\n"); printf("-f \tRun in foreground.\n");
#endif /* #if defined(N2N_HAVE_DAEMON) */ #endif /* #if defined(N2N_HAVE_DAEMON) */
printf("-t <port>\tManagement UDP Port (for multiple supernodes on a machine).\n");
printf("-v \tIncrease verbosity. Can be used multiple times.\n"); printf("-v \tIncrease verbosity. Can be used multiple times.\n");
printf("-h \tThis help message.\n"); printf("-h \tThis help message.\n");
printf("\n"); printf("\n");
@ -135,6 +137,10 @@ static int setOption(int optkey, char *_optarg, n2n_sn_t *sss) {
sss->lport = atoi(_optarg); sss->lport = atoi(_optarg);
break; break;
case 't': /* mgmt-port */
sss->mport = atoi(_optarg);
break;
case 'c': /* community file */ case 'c': /* community file */
load_allowed_sn_community(sss, _optarg); load_allowed_sn_community(sss, _optarg);
break; break;
@ -165,9 +171,10 @@ static const struct option long_options[] = {
{ "communities", required_argument, NULL, 'c' }, { "communities", required_argument, NULL, 'c' },
{ "foreground", no_argument, NULL, 'f' }, { "foreground", no_argument, NULL, 'f' },
{ "local-port", required_argument, NULL, 'l' }, { "local-port", required_argument, NULL, 'l' },
{ "mgmt-port", required_argument, NULL, 't' },
{ "help" , no_argument, NULL, 'h' }, { "help" , no_argument, NULL, 'h' },
{ "verbose", no_argument, NULL, 'v' }, { "verbose", no_argument, NULL, 'v' },
{ NULL, 0, NULL, 0 } { NULL, 0, NULL, 0 }
}; };
/* *************************************************** */ /* *************************************************** */
@ -176,7 +183,7 @@ static const struct option long_options[] = {
static int loadFromCLI(int argc, char * const argv[], n2n_sn_t *sss) { static int loadFromCLI(int argc, char * const argv[], n2n_sn_t *sss) {
u_char c; u_char c;
while((c = getopt_long(argc, argv, "fl:c:vh", while((c = getopt_long(argc, argv, "fl:t:c:vh",
long_options, NULL)) != '?') { long_options, NULL)) != '?') {
if(c == 255) break; if(c == 255) break;
setOption(c, optarg, sss); setOption(c, optarg, sss);
@ -380,12 +387,12 @@ int main(int argc, char * const argv[]) {
traceEvent(TRACE_NORMAL, "supernode is listening on UDP %u (main)", sss_node.lport); traceEvent(TRACE_NORMAL, "supernode is listening on UDP %u (main)", sss_node.lport);
} }
sss_node.mgmt_sock = open_socket(N2N_SN_MGMT_PORT, 0 /* bind LOOPBACK */); sss_node.mgmt_sock = open_socket(sss_node.mport, 0 /* bind LOOPBACK */);
if(-1 == sss_node.mgmt_sock) { if(-1 == sss_node.mgmt_sock) {
traceEvent(TRACE_ERROR, "Failed to open management socket. %s", strerror(errno)); traceEvent(TRACE_ERROR, "Failed to open management socket. %s", strerror(errno));
exit(-2); exit(-2);
} else } else
traceEvent(TRACE_NORMAL, "supernode is listening on UDP %u (management)", N2N_SN_MGMT_PORT); traceEvent(TRACE_NORMAL, "supernode is listening on UDP %u (management)", sss_node.mport);
traceEvent(TRACE_NORMAL, "supernode started"); traceEvent(TRACE_NORMAL, "supernode started");

1
src/sn_utils.c

@ -193,6 +193,7 @@ int sn_init(n2n_sn_t *sss)
sss->daemon = 1; /* By defult run as a daemon. */ sss->daemon = 1; /* By defult run as a daemon. */
sss->lport = N2N_SN_LPORT_DEFAULT; sss->lport = N2N_SN_LPORT_DEFAULT;
sss->mport = N2N_SN_MGMT_PORT;
sss->sock = -1; sss->sock = -1;
sss->mgmt_sock = -1; sss->mgmt_sock = -1;

Loading…
Cancel
Save