Allow 'lport 0' setup for random port binding
PATCH 1/1 Allow 'lport 0' setup for random port binding
From: Enrico Scholz <[email protected]...>
I am running a multihomed host where 'local <extip>' must be specified for proper operation. Unfortunately, this implies 'lport 1194' or another static port.
This causes problems with stateful firewalls which register the host/port pairs in the internal connection tracking table. On ungraceful reconnects, the new TCP connection will have same the host/port pairs but unexpected sequence numbers. The new connection will be assumed as invalid hence and be dropped.
It would be nice when local port can be configured to be bound to a random port number. After reading code,
| else if (streq (p[0], "lport") && p[1])
| ...
| port = atoi (p[1]);
|- if (!legal_ipv4_port (port))
|+ if (port != 0 && !legal_ipv4_port (port))
| {in options.c seems to be the only required change.
This has been discussed here:
<http://thread.gmane.org/gmane.network.openvpn.user/28622>
--- options.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
options.c +1 -1
@@ -4072,7 +4072,7 @@ add_option (struct options *options,VERIFY_PERMISSION (OPT_P_GENERAL |OPT_P_CONNECTION ); port =atoi (p[1 ]); -if (!legal_ipv4_port (port)) +if ((port !=0 ) && !legal_ipv4_port (port)) {msg (msglevel,"Bad local port number: %s" , p[1 ]); goto err;
Signature · 1 line
1.6.6.1
Hi,
Quoted 4 lines · David Sommerseth
I am running a multihomed host where 'local <extip>' must be specified for proper operation. Unfortunately, this implies 'lport 1194' or another static port.
Quoted 8 lines
This causes problems with stateful firewalls which register the host/port pairs in the internal connection tracking table. On ungraceful reconnects, the new TCP connection will have same the host/port pairs but unexpected sequence numbers. The new connection will be assumed as invalid hence and be dropped.
It would be nice when local port can be configured to be bound to a random port number. After reading code,
I have not found a reference anywhere that documents that bind() can be used with port=0 to tell the system "bind to the IP address, but still use a random port". It seems to work though, and the code elsewhere does not seem to make any assumptions about "port != 0" (it is effectively just passed to bind(), and if bind() doesn't like it, an error exit occurs).
Since it fixes a real-world problem, there is obvious need for it.
-> ACK.
gert
Signature · 4 lines
USENET is *not* the non-clickable part of WWW!
//www.muc.de/~gert/
Gert Doering - Munich, Germany [email protected]...
fax: +49-89-35655025 [email protected]...A message that is not in the archive (sent off-list or not yet received): [email protected]...
Quoted 4 lines · Till Maas
Quoted 2 lines
|- if (!legal_ipv4_port (port)) |+ if (port != 0 && !legal_ipv4_port (port))I am pretty sure that it is possible to listen on port 0,
not on linux; e.g. see in net/ipv4/inet_connection_sock.c the implementation of
| /* Obtain a reference to a local port for the given sock, | * if snum is zero it means select any available local port. | */ | int inet_csk_get_port(struct sock *sk, unsigned short snum)
and its caller. Windoze seems to have a similar mechanism accordingly
http://msdn.microsoft.com/en-us/library/ms737550%28VS.85%29.aspx
| Binding to a specific port number other than port 0 is discouraged for | client applications since there is a danger of conflicting with | another socket already using that port number on the local computer.
RFC 768 states
| Source Port is an optional field ... If not used, a value of zero is | inserted.
which implies that port 0 is something special which is not to be used for normal communication.
Enrico
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Quoted 24 lines · David Sommerseth
From: Enrico Scholz <[email protected]...>
I am running a multihomed host where 'local <extip>' must be specified for proper operation. Unfortunately, this implies 'lport 1194' or another static port.
This causes problems with stateful firewalls which register the host/port pairs in the internal connection tracking table. On ungraceful reconnects, the new TCP connection will have same the host/port pairs but unexpected sequence numbers. The new connection will be assumed as invalid hence and be dropped.
It would be nice when local port can be configured to be bound to a random port number. After reading code,
| else if (streq (p[0], "lport") && p[1]) | ... | port = atoi (p[1]); |- if (!legal_ipv4_port (port)) |+ if (port != 0 && !legal_ipv4_port (port)) | {in
options.cseems to be the only required change.
Quoted 8 lines
This has been discussed here:
<http://thread.gmane.org/gmane.network.openvpn.user/28622>Signed-off-by David Sommerseth <[email protected]...>--- options.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
This patch has been applied to the bugfix2.1 branch commit 9bd1cd1b0014041ebff2c2bc9d5614d0bec5f6db
It will be merged into the allmerged branch when we get in a few more patches which are in the pipe now.
kind regards,
David Sommerseth
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (GNU/Linux)
Comment: Using GnuPG with Fedora - http://enigmail.mozdev.org/
iEYEARECAAYFAkuMR/8ACgkQDC186MBRfrosfwCfbo0XMqE6qshPUyNXA1FnbeKr /BEAoJbPyBsGnfs8kDHrY4uIN5l9OHPj
=Ojpb
-----END PGP SIGNATURE-----