Skip to contentSkip to conversation

float is broken when source port changes

Openvpn-devel Kosta Welke 3 participants 6 messages Mar 6, 2006 – Mar 10, 2006 1 message not in the archive

lore
Share & tools
lore
#0 lore raw

Hi!

I really enjoy openvpn. I also found a bug :)

Consider this network layout, float is enabled:
(client and server are the openvpn client and server)

client -- box1 -- NAT --- server

       \- box2 -/

The client has an instable connection to both boxes. If a connection breaks, it simply uses the other one. openvpn client does this without any problem. However, the server fails to update to the new client port. Here's what tcpdump on the server says:

04:25:40.379210 IP client.1042 > server.1194: UDP, length 53 04:25:50.641933 IP server.1194 > client.1042: UDP, length 53 [connection breaks -> client has same IP thanks to NAT, but other port] 04:25:50.949669 IP client.39630 > server.1194: UDP, length 53 04:26:00.774602 IP server.1194 > client.1042: UDP, length 53 04:26:10.390386 IP client.39630 > server.1194: UDP, length 53 04:26:20.239776 IP server.1194 > client.1042: UDP, length 53

the server should have sent those last two packets to client.39630, of course. As it does not, I have to wait for a connection timeout.

I tried finding the bug myself, however, wherever i looked, both ip address and port number were compared, or sockaddr_in was compared, which essentially is the same. Any hints how to fix it?

Yours,
Kosta

#1 lore raw
Quoted 23 lines · Kosta Welke

Hi!

I really enjoy openvpn. I also found a bug :)

Consider this network layout, float is enabled:
(client and server are the openvpn client and server)

client -- box1 -- NAT --- server

        \- box2 -/

The client has an instable connection to both boxes. If a connection breaks, it simply uses the other one. openvpn client does this without any problem. However, the server fails to update to the new client port. Here's what tcpdump on the server says:

04:25:40.379210 IP client.1042 > server.1194: UDP, length 53 04:25:50.641933 IP server.1194 > client.1042: UDP, length 53 [connection breaks -> client has same IP thanks to NAT, but other port] 04:25:50.949669 IP client.39630 > server.1194: UDP, length 53 04:26:00.774602 IP server.1194 > client.1042: UDP, length 53 04:26:10.390386 IP client.39630 > server.1194: UDP, length 53 04:26:20.239776 IP server.1194 > client.1042: UDP, length 53

Quoted 7 lines

the server should have sent those last two packets to client.39630, of course. As it does not, I have to wait for a connection timeout.

I tried finding the bug myself, however, wherever i looked, both ip address and port number were compared, or sockaddr_in was compared, which essentially is the same. Any hints how to fix it?

OK none of the developers have answered yet so here goes.

UDP is connectionless so there can be overlap where one side has determined there is a dropped connection and the other has not. Which would cause the type of results shown by tcpdump.

Additionally if you are using static keys or allowing duplicate certificates IIUC there is no mechanism for the server to determine a UDP connection has been closed/discarded by the client. TCP on the other hand is connection oriented and the server will realize the connection is dropped. HTH

--
Leonard Isham, CISSP
Ostendo non ostento.

#2 lore raw
Quoted 9 lines · Leonard Isham
Quoted 7 lines · Kosta Welke

04:25:40.379210 IP client.1042 > server.1194: UDP, length 53 04:25:50.641933 IP server.1194 > client.1042: UDP, length 53 [connection breaks -> client has same IP thanks to NAT, but other port] 04:25:50.949669 IP client.39630 > server.1194: UDP, length 53 04:26:00.774602 IP server.1194 > client.1042: UDP, length 53 04:26:10.390386 IP client.39630 > server.1194: UDP, length 53 04:26:20.239776 IP server.1194 > client.1042: UDP, length 53

Quoted 6 lines
Quoted 2 lines

the server should have sent those last two packets to client.39630, of course. As it does not, I have to wait for a connection timeout.

UDP is connectionless so there can be overlap where one side has determined there is a dropped connection and the other has not. Which would cause the type of results shown by tcpdump.

I should not detect a connection drop, it should detect an address change. Here is an extract from the man page:

"--float when specified with --remote allows an OpenVPN session to initially connect to a peer at a known address, however if packets arrive from a new address and pass all authentication tests, the new address will take control of the session. Essentially, --float tells OpenVPN to accept authenticated packets from any address, not only the address which was specified in the --remote option."

(Note that I'm using --float on the server and --remote on the client)

This is exactly what I want. Based on my understanding, it should also apply to any combination of ip address and port number changes. Sadly it does not. :(

Yours,
Kosta

A message that is not in the archive (sent off-list or not yet received): [email protected]...

#4 lore raw
Quoted 1 line · James Yonan

No, --float only applies to the IP address, not the port.

Sadly, yes.

Quoted 1 line

You can't really float on the port efficiently because a UDP socket needs to bind to some port number (either static or dynamic). To do port floating, you would need to bind to every possible port that a packet might come in on -- fairly impractical.

No. Using the same logic the openvpn server would need to listen on all 4,294,967,296 IP addresses.
It is the *client* port that changes, which can be detect just as easily as a change in the client IP address. The only problem is that it is not checked. Please re-visit my original post to see under what circumstances the IP address can stay the same while the client port number changes *from the servers point of view*.

I think I found the potions of the code that would need modification:

- In mroute.h, struct mroute_addr would need an unsigned short port to store the port number. Also, mroute_addr_equal() would need to return false if the port numbers dont match

- In mroute.c, mroute_extract_addr_from_packet() would need to get the port number from the packet. This is the part where I'm not too sure. Is it safe to assume that the UDP header starts just after the IP header? To be honest, I never understood the concept of IP header options... :)

HTH,
Kosta

#5 lore raw
Quoted 14 lines · Kosta Welke
Quoted 1 line · James Yonan

No, --float only applies to the IP address, not the port.

Sadly, yes.

Quoted 1 line

You can't really float on the port efficiently because a UDP socket needs to bind to some port number (either static or dynamic). To do port floating, you would need to bind to every possible port that a packet might come in on -- fairly impractical.

No. Using the same logic the openvpn server would need to listen on all 4,294,967,296 IP addresses.
It is the *client* port that changes, which can be detect just as easily as a change in the client IP address. The only problem is that it is not checked. Please re-visit my original post to see under what circumstances the IP address can stay the same while the client port number changes *from the servers point of view*.

I think I found the potions of the code that would need modification:

Quoted 8 lines

- In mroute.h, struct mroute_addr would need an unsigned short port to
store the port number. Also, mroute_addr_equal() would need to return false if the port numbers dont match

- In mroute.c, mroute_extract_addr_from_packet() would need to get the
port number from the packet. This is the part where I'm not too sure. Is it safe to assume that the UDP header starts just after the IP header? To be honest, I never understood the concept of IP header options... :)

HTH,
Kosta

Okay, I understand what you are asking for -- If you were using static key mode (which is stateless), you would get the behavior you are looking for. In TLS mode, however, OpenVPN doesn't allow a port or IP change within a given TLS session (for security/DoS reasons). The behavior you should be seeing is that the new port and IP address is only accepted by the server after a fresh TLS renegotiation.

James

#6 lore raw
Quoted 1 line · James Yonan

Okay, I understand what you are asking for -- If you were using static key mode (which is stateless), you would get the behavior you are looking for. In TLS mode, however, OpenVPN doesn't allow a port or IP change within a given TLS session (for security/DoS reasons). The behavior you should be seeing is that the new port and IP address is only accepted by the server after a fresh TLS renegotiation.

Okai, I found out the the --float option allows for IP changes only after a timeout, so the port changes are handled like IP changes and everythings foine.

Sorry for the static :)

Kosta