Allow a port to be specified in BindToAddress statements.
authorGuus Sliepen <guus@tinc-vpn.org>
Wed, 21 Mar 2012 12:20:15 +0000 (13:20 +0100)
committerGuus Sliepen <guus@tinc-vpn.org>
Wed, 21 Mar 2012 12:20:15 +0000 (13:20 +0100)
This can be used to let tinc listen on multiple ports for incoming connections.

doc/tinc.conf.5.in
doc/tinc.texi
src/net_setup.c

index a6ae4f5ac3ee8d4355fff4d7814138506a908c1f..1d2f17f99459415c8c3862c1552176dad8e26e7b 100644 (file)
@@ -129,7 +129,7 @@ If
 is selected, then depending on the operating system both IPv4 and IPv6 or just
 IPv6 listening sockets will be created.
 
 is selected, then depending on the operating system both IPv4 and IPv6 or just
 IPv6 listening sockets will be created.
 
-.It Va BindToAddress Li = Ar address Bq experimental
+.It Va BindToAddress Li = Ar address Oo Ar port Oc Bq experimental
 If your computer has more than one IPv4 or IPv6 address,
 .Nm tinc
 will by default listen on all of them for incoming connections.
 If your computer has more than one IPv4 or IPv6 address,
 .Nm tinc
 will by default listen on all of them for incoming connections.
@@ -137,7 +137,16 @@ Multiple
 .Va BindToAddress
 variables may be specified,
 in which case listening sockets for each specified address are made.
 .Va BindToAddress
 variables may be specified,
 in which case listening sockets for each specified address are made.
-
+.Pp
+If no
+.Ar port
+is specified, the socket will be bound to the port specified by the
+.Va Port
+option, or to port 655 if neither is given.
+To only bind to a specific port but not to a specific address, use
+.Li *
+for the
+.Ar address .
 .Pp
 This option may not work on all platforms.
 
 .Pp
 This option may not work on all platforms.
 
@@ -452,7 +461,7 @@ Since host configuration files only contain public keys,
 no secrets are revealed by sending out this information.
 .Bl -tag -width indent
 
 no secrets are revealed by sending out this information.
 .Bl -tag -width indent
 
-.It Va Address Li = Ar address Oo port Oc Bq recommended
+.It Va Address Li = Ar address Oo Ar port Oc Bq recommended
 The IP address or hostname of this tinc daemon on the real network.
 This will only be used when trying to make an outgoing connection to this tinc daemon.
 Optionally, a port can be specified to use for this address.
 The IP address or hostname of this tinc daemon on the real network.
 This will only be used when trying to make an outgoing connection to this tinc daemon.
 Optionally, a port can be specified to use for this address.
index aedde3f84d6a1da1a3e0fdeb3847e3ee2d5c9bdf..8bf0a6f5d2ea978f924008ba522f2df67417a3c2 100644 (file)
@@ -756,12 +756,16 @@ If any is selected, then depending on the operating system
 both IPv4 and IPv6 or just IPv6 listening sockets will be created.
 
 @cindex BindToAddress
 both IPv4 and IPv6 or just IPv6 listening sockets will be created.
 
 @cindex BindToAddress
-@item BindToAddress = <@var{address}> [experimental]
+@item BindToAddress = <@var{address}> [<@var{port}>] [experimental]
 If your computer has more than one IPv4 or IPv6 address, tinc
 will by default listen on all of them for incoming connections.
 Multiple BindToAddress variables may be specified,
 in which case listening sockets for each specified address are made.
 
 If your computer has more than one IPv4 or IPv6 address, tinc
 will by default listen on all of them for incoming connections.
 Multiple BindToAddress variables may be specified,
 in which case listening sockets for each specified address are made.
 
+If no @var{port} is specified, the socket will be bound to the port specified by the Port option,
+or to port 655 if neither is given.
+To only bind to a specific port but not to a specific address, use "*" for the @var{address}.
+
 This option may not work on all platforms.
 
 @cindex BindToInterface
 This option may not work on all platforms.
 
 @cindex BindToInterface
index 2684514392dac017d4b3faeba8f8b4aa510bce69..29d4952a42e114827658bc5115e36cbea079ecf9 100644 (file)
@@ -587,12 +587,25 @@ static bool setup_myself(void) {
                if(cfg)
                        cfg = lookup_config_next(config_tree, cfg);
 
                if(cfg)
                        cfg = lookup_config_next(config_tree, cfg);
 
+               char *port = myport;
+
+               if(address) {
+                       char *space = strchr(address, ' ');
+                       if(space) {
+                               *space++ = 0;
+                               port = space;
+                       }
+
+                       if(!strcmp(address, "*"))
+                               *address = 0;
+               }
+
                hint.ai_family = addressfamily;
                hint.ai_socktype = SOCK_STREAM;
                hint.ai_protocol = IPPROTO_TCP;
                hint.ai_flags = AI_PASSIVE;
 
                hint.ai_family = addressfamily;
                hint.ai_socktype = SOCK_STREAM;
                hint.ai_protocol = IPPROTO_TCP;
                hint.ai_flags = AI_PASSIVE;
 
-               err = getaddrinfo(address, myport, &hint, &ai);
+               err = getaddrinfo(address && *address ? address : NULL, port, &hint, &ai);
                free(address);
 
                if(err || !ai) {
                free(address);
 
                if(err || !ai) {