merged edge's '-b' into '-p' command line option (#772)

This commit is contained in:
Logan oos Even 2021-09-09 12:44:23 +05:45 committed by GitHub
parent 4cba2b5582
commit 05e6579038
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 40 additions and 33 deletions

12
edge.8
View File

@ -28,10 +28,14 @@ truncated to take the first 16 bytes.
sets the n2n supernode IP address and port to register to. Multiple supernodes
can be specified.
.TP
\fB\-p \fR<\fIlocal port\fR>
\fB\-p \fR[<\fIlocal_ip_address\fR>:]<\fIlocal_port\fR>
binds edge to the given UDP port. Useful for keeping the same external socket
across restarts of edge. This allows peer edges which know the edge socket to
continue p2p operation without going back to the supernode.
continue p2p operation without going back to the supernode. Also, home router's
port forwarding feature can refer to that fixed port.
Optionally, the edge can bind to the provided local ip address only. This is
useful in case restriction to a certain LAN or WiFi interface is desired.
By default, the edge binds to any interface.
.TP
\fB\-T \fR<\fItos\fR>
TOS for packets, e.g. 0x48 for SSH like priority
@ -40,10 +44,6 @@ TOS for packets, e.g. 0x48 for SSH like priority
enable PMTU discovery, it can reduce fragmentation but
causes connections to stall if not properly supported
.TP
\fB\-b \fR<\fIbind ip\fR>
binds edge to the provided local IP address only, defaults to 'any' ip address
if not provided
.TP
\fB\-S1\fR ... \fB\-S2\fR
do not connect p2p, always use the supernode,
\-S1 = via UDP, \-S2 = via TCP

View File

@ -160,7 +160,9 @@ static void help (int level) {
" -c <community name>"
" -l <supernode host:port>"
"\n "
"[-p <local port>] "
"[-p [<local bind ip address>:]<local port>] "
"\n "
#ifdef __linux__
"[-T <type of service>] "
#endif
@ -168,15 +170,15 @@ static void help (int level) {
"[-D] "
#endif
"\n options for under- "
"[-i <registration interval>]"
"[-L <registration ttl>]"
"[-i <registration interval>] "
"[-L <registration ttl>] "
"\n lying connection "
"[-k <key>] "
"[-A<cipher>] "
"[-H] "
"[-z<compression>]"
"[-z<compression>] "
"\n "
"[-b <bind IP address>][-S<level of solitude>]"
"[-S<level of solitude>] "
"\n\n tap device and "
"[-a [static:|dhcp:]<tap IP address>[/<cidr suffix>]] "
"\n overlay network "
@ -206,8 +208,8 @@ static void help (int level) {
"[-n <cidr:gateway>] "
#ifndef WIN32
"\n "
"[-u <numerical user id>]"
"[-g <numerical group id>]"
"[-u <numerical user id>] "
"[-g <numerical group id>] "
#endif
"\n\n environment "
"N2N_KEY instead of [-k <key>]"
@ -243,7 +245,8 @@ static void help (int level) {
printf (" ---------------------------------------------\n\n");
printf(" -c <community> | n2n community name the edge belongs to\n");
printf(" -l <host:port> | supernode ip address or name, and port\n");
printf(" -p <local port> | fixed local UDP port\n");
printf(" -p [<ip>:]<port> | fixed local UDP port and optionally bind to the\n"
" | sepcified local IP address only (any by default)\n");
#ifdef __linux__
printf(" -T <tos> | TOS for packets, e.g. 0x48 for SSH like priority\n");
#endif
@ -251,8 +254,6 @@ static void help (int level) {
printf(" -D | enable PMTU discovery, it can reduce fragmentation but\n"
" | causes connections to stall if not properly supported\n");
#endif
printf(" -b <bind ip> | bind the edge to the provided local IP address only,\n"
" | defaults to 'any' ip address if not provided\n");
printf(" -S1 ... -S2 | do not connect p2p, always use the supernode,\n"
" | -S1 = via UDP"
@ -580,27 +581,34 @@ static int setOption (int optkey, char *optargument, n2n_tuntap_priv_config_t *e
}
case 'p': {
conf->local_port = atoi(optargument);
if(conf->local_port == 0) {
traceEvent(TRACE_WARNING, "bad local port format, using OS assigned port");
break;
}
break;
}
case 'b': {
if(optargument) {
char* colon = strpbrk(optargument, ":");
if(colon) { /*ip address:port */
*colon = 0;
conf->bind_address = ntohl(inet_addr(optargument));
conf->local_port = atoi(++colon);
if(conf->bind_address == INADDR_NONE) {
traceEvent(TRACE_WARNING, "Bad address to bind to, binding to any IP address.");
traceEvent(TRACE_WARNING, "bad address to bind to, binding to any IP address");
conf->bind_address = INADDR_ANY;
break;
}
if(conf->local_port == 0) {
traceEvent(TRACE_WARNING, "bad local port format, using OS assigned port");
}
} else { /* ip address or port only */
char* dot = strpbrk(optargument, ".");
if(dot) { /* ip address only */
conf->bind_address = ntohl(inet_addr(optargument));
if(conf->bind_address == INADDR_NONE) {
traceEvent(TRACE_WARNING, "bad address to bind to, binding to any IP address");
conf->bind_address = INADDR_ANY;
}
} else { /* port only */
conf->local_port = atoi(optargument);
if(conf->local_port == 0) {
traceEvent(TRACE_WARNING, "bad local port format, using OS assigned port");
}
}
}
break;
}
@ -726,7 +734,6 @@ static const struct option long_options[] =
{ "tap-device", required_argument, NULL, 'd' },
{ "euid", required_argument, NULL, 'u' },
{ "egid", required_argument, NULL, 'g' },
{ "bind", required_argument, NULL, 'b' },
{ "help" , no_argument, NULL, '@' }, /* special character '@' to identify long help case */
{ "verbose", no_argument, NULL, 'v' },
{ NULL, 0, NULL, 0 }
@ -740,7 +747,7 @@ static int loadFromCLI (int argc, char *argv[], n2n_edge_conf_t *conf, n2n_tunta
u_char c;
while ((c = getopt_long(argc, argv,
"k:a:b:c:Eu:g:m:M:s:d:l:p:fvhrt:i:I:J:P:S::DL:z::A::Hn:R:"
"k:a:c:Eu:g:m:M:s:d:l:p:fvhrt:i:I:J:P:S::DL:z::A::Hn:R:"
#ifdef __linux__
"T:"
#endif