diff --git a/edge.8 b/edge.8 index 2554a57..3ea09ae 100644 --- a/edge.8 +++ b/edge.8 @@ -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 diff --git a/src/edge.c b/src/edge.c index 9e5b4f9..43486b6 100644 --- a/src/edge.c +++ b/src/edge.c @@ -160,7 +160,9 @@ static void help (int level) { " -c " " -l " "\n " - "[-p ] " + "[-p [:]] " + "\n " + #ifdef __linux__ "[-T ] " #endif @@ -168,15 +170,15 @@ static void help (int level) { "[-D] " #endif "\n options for under- " - "[-i ]" - "[-L ]" + "[-i ] " + "[-L ] " "\n lying connection " "[-k ] " "[-A] " "[-H] " - "[-z]" + "[-z] " "\n " - "[-b ][-S]" + "[-S] " "\n\n tap device and " "[-a [static:|dhcp:][/]] " "\n overlay network " @@ -206,8 +208,8 @@ static void help (int level) { "[-n ] " #ifndef WIN32 "\n " - "[-u ]" - "[-g ]" + "[-u ] " + "[-g ] " #endif "\n\n environment " "N2N_KEY instead of [-k ]" @@ -243,7 +245,8 @@ static void help (int level) { printf (" ---------------------------------------------\n\n"); printf(" -c | n2n community name the edge belongs to\n"); printf(" -l | supernode ip address or name, and port\n"); - printf(" -p | fixed local UDP port\n"); + printf(" -p [:] | fixed local UDP port and optionally bind to the\n" + " | sepcified local IP address only (any by default)\n"); #ifdef __linux__ printf(" -T | 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 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