Skip to contentSkip to conversation

OpenVPN session synchronization

Openvpn-devel Magne J. Andreassen 3 participants 4 messages Oct 7, 2005 – Aug 6, 2007

lore
Share & tools
lore
#0 lore raw

Hi,

(This is a re-post from the -users list, thought it might be more appropriate here)

Exactly what kind of information does OpenVPN keep track of for active VPN sessions? (after the authentication process is finished)

Reason for asking;

OpenVPN supports load-balancing trough the use of round-robin. Be it DNS round-robin or just by specifying multiple servers in the client config file.

OpenVPN does not, however, support dynamic failover to another daemon running on another server. By dynamic failover, I mean that the client sessions are not interfered by the server going down or in other ways being inaccessible. (They don't have to re-establish the tunnel)

There was a thread on this list some time ago discussing clustering of OpenVPN, but not so much details was given.

OpenBSD has a dynamic failover / loadbalancing protocol called CARP that some of you might be familiar with. It is ported to FreeBSD and Linux.

PF (Packetfilter) and isakmpd uses some small synchronization daemons to utilize the power of CARP and thereby offering dynamic failover for these services.

I think, without knowing much about the OpenVPN design, that it would be possible to synchronize VPN client sessions in the same way and thereby offering high-availability to OpenVPN clients.

Why would I want this, you might ask? OpenVPN already supports load-balancing trough the previous mentioned methods. Well, it's not so much I don't trust these methods or my hardware. Rather, it's a major strength when it comes to maintenance. I can have service windows in office hours without users noticing the main VPN server goes down. This saves time and money. And, clients currently connected to a failing server, won't notice that they are "moved" to the backup server.

Updating, patching and other maintenance could easily be done without VPN service downtime.

The strength in using CARP is obviously that OpenVPN don't have to implement the redundancy protocol itself.

So, the problems(?);

The OpenVPN daemons mush listen on the same server ip-address. Actually, it must utilize the CARP interface, so no changes to OpenVPN should be necessary here. Using the '--local host' parameter and listening on the CARP interface should be sufficient.

OpenVPN should optionally use an external DHCP service to serve addresses to the clients. If i remember correctly, someone on this list mentioned that this could be done with a script?

CARP and OpenVPN should be able to interact in some way, so that CARP could adjust it's adskew (advertising interval deciding which server is the master) if the OpenVPN daemon is unresponsive.

As far as I can figure, the only thing that is required, is the OpenVPN daemons to speak to each other and update client session information on connect and disconnect.

Depending on various parameters, the failover process takes about 1-5 seconds. The clients might notice a stall in connectivity during this time. Other than that, everything should be transparent to the user.

More problems;

First I started to look at the possibility of writing a simple plugin to take care of the synchronization and interaction with the various OpenVPN daemons. But the problem is that the plugin API only offers callbacks. In other words I don't think it's possible to "manually" add a VPN session from a plugin.

After skimming trough the various source files for OpenVPN, I think that the problem might be a bit more complex than first assumed.

Any comments on this? Any ideas on where the hooks should be placed in OpenVPN to actually be able to sync sessions?

Magne Andreassen

#1 lore raw
Quoted 7 lines · Magne J. Andreassen

Hi,

(This is a re-post from the -users list, thought it might be more appropriate here)

Exactly what kind of information does OpenVPN keep track of for active VPN sessions? (after the authentication process is finished)

See struct context in openvpn.h -- this is the master object that denotes a VPN session.

Quoted 73 lines

Reason for asking;

OpenVPN supports load-balancing trough the use of round-robin. Be it DNS round-robin or just by specifying multiple servers in the client config file.

OpenVPN does not, however, support dynamic failover to another daemon running on another server. By dynamic failover, I mean that the client sessions are not interfered by the server going down or in other ways being inaccessible. (They don't have to re-establish the tunnel)

There was a thread on this list some time ago discussing clustering of OpenVPN, but not so much details was given.

OpenBSD has a dynamic failover / loadbalancing protocol called CARP that some of you might be familiar with. It is ported to FreeBSD and Linux.

PF (Packetfilter) and isakmpd uses some small synchronization daemons to utilize the power of CARP and thereby offering dynamic failover for these services.

I think, without knowing much about the OpenVPN design, that it would be possible to synchronize VPN client sessions in the same way and thereby offering high-availability to OpenVPN clients.

Why would I want this, you might ask? OpenVPN already supports load-balancing trough the previous mentioned methods. Well, it's not so much I don't trust these methods or my hardware. Rather, it's a major strength when it comes to maintenance. I can have service windows in office hours without users noticing the main VPN server goes down. This saves time and money. And, clients currently connected to a failing server, won't notice that they are "moved" to the backup server.

Updating, patching and other maintenance could easily be done without VPN service downtime.

The strength in using CARP is obviously that OpenVPN don't have to implement the redundancy protocol itself.

So, the problems(?);

The OpenVPN daemons mush listen on the same server ip-address. Actually, it must utilize the CARP interface, so no changes to OpenVPN should be necessary here. Using the '--local host' parameter and listening on the CARP interface should be sufficient.

OpenVPN should optionally use an external DHCP service to serve addresses to the clients. If i remember correctly, someone on this list mentioned that this could be done with a script?

CARP and OpenVPN should be able to interact in some way, so that CARP could adjust it's adskew (advertising interval deciding which server is the master) if the OpenVPN daemon is unresponsive.

As far as I can figure, the only thing that is required, is the OpenVPN daemons to speak to each other and update client session information on connect and disconnect.

Depending on various parameters, the failover process takes about 1-5 seconds. The clients might notice a stall in connectivity during this time. Other than that, everything should be transparent to the user.

More problems;

First I started to look at the possibility of writing a simple plugin to take care of the synchronization and interaction with the various OpenVPN daemons. But the problem is that the plugin API only offers callbacks. In other words I don't think it's possible to "manually" add a VPN session from a plugin.

Quoted 5 lines

After skimming trough the various source files for OpenVPN, I think that the problem might be a bit more complex than first assumed.

Any comments on this? Any ideas on where the hooks should be placed in OpenVPN to actually be able to sync sessions?

The major issue to deal with when doing transparent, seamless failover is making sure that the new server inherits the precise state from the old server so that the switchover is invisible to the client. This is a complicated undertaking -- there's a lot of data that makes up a client instance object on the server.

In a lot of respects, the problem of doing OpenVPN transparent failover is more akin to the problem of doing transparent failover for routers, than it is for doing failover for conventional "services" like SMTP or HTTP.

So unless CARP supports router failover, it's probably not going to be a drop-in solution for OpenVPN.

Longer term I would like to design a clustering feature for OpenVPN, that would also support seamless failover in under 5 seconds.

However if you really want to do seamless failover now, without waiting for future development, you could probably do it this way:

(1) Set up primary and backup OpenVPN servers.

(2) Set up clients to always connect to both servers.

(3) Set up VPN client <-> server routing through both primary and backup servers with the primary having a lower metric.

(4) Have a server/up down sensor such as CARP dynamically change the routing metrics based on which server is available. This could be done by having CARP run a script every time there is a change in server/up down status -- the script would need to multicast a RIP2 or OSPF notification through the VPN to change the routing metric to prefer the currently alive server (I'm not sure if there's a command line tool to multicast dynamic routing updates).

When we implement the clustering feature, the goal will be to automate the above steps. I will probably make plugin callbacks for (a) the server/up down sensor and (b) multicast of dynamic routing updates, so that these functions could be carried out outside of the OpenVPN core.

James

#2 lore raw
Quoted 8 lines · James Yonan
Quoted 2 lines · Magne J. Andreassen

Exactly what kind of information does OpenVPN keep track of for active VPN sessions? (after the authentication process is finished)

See struct context in openvpn.h -- this is the master object that denotes a VPN session.

Thanks!

[...]

Quoted 10 lines
Quoted 3 lines

Any comments on this? Any ideas on where the hooks should be placed in OpenVPN to actually be able to sync sessions?

The major issue to deal with when doing transparent, seamless failover is making sure that the new server inherits the precise state from the old server so that the switchover is invisible to the client. This is a complicated undertaking -- there's a lot of data that makes up a client instance object on the server.

Yes, I understand. Would it be easier to "simulate" the events (connect, disconnect and so on) on the backup server than to actually synchronize the data?

Quoted 7 lines

In a lot of respects, the problem of doing OpenVPN transparent failover is more akin to the problem of doing transparent failover for routers, than it is for doing failover for conventional "services" like SMTP or HTTP.

So unless CARP supports router failover, it's probably not going to be a drop-in solution for OpenVPN.

CARP operates at layer 2 and 3 in the OSI model, let me take some time to detail the solution.

Let's forget about OpenVPN for a second and talk about CARP.

We have 2 servers with 1 physical interface each. They also have a pseudo CARP interface, configured with the same ip-address, say 192.168.0.10. Now, CARP can be configured in two ways, either master / slave, or "load-balancing" mode. The latter kinda works like a simple round-robin algorithm, but not suitable for this setup (I'll explain this later). In master / slave mode, CARP sends advertisements at a given interval, and the machine advertising at the highest frequency, is considered the master. The master will reply for the arp requests and the ip-address, while the slave is considered a "hot-standby". If the master fails, the slave will have the highest advertisement frequency, and thereby start answering for the arp request and the (common) ip-adress.

The "load-balancing" mode (called arp-balancing) uses the source ip-address to compute witch of the hosts should answer the request. Because arp don't traverse routers, this setup only works on the local network segment.

Anyway, when a client connects to the ip-address 192.168.0.10, regardless the protocol or service, it is connected to the current master.

----------------
| 192.168.0.10 |
----------------

   |          |
|------|   |------|
| VPN1 |   | VPN2 |
|------|   |------|

If we installed OpenVPN (as of today) on these two boxes, we would gain redundancy, but the users would have to re-authenticate to the backup server if the master fails.

You could of course, as you mentioned, use some sort of duplicating mechanism so that clients are always connected to both servers (don't know if this would work). Packetfilter has a dup-to keyword that will duplicate all traffic to another destination.

But if these two OpenVPN daemons where able to do two-way synchronization of session information, it would not matter which server the clients where connected to.

Here is an example server configuration(just interesting params):

#Serving we are...
mode server
#OpenVPN listens on the CARP interface, NOT the #ip-address of the physical interface.
local 192.168.0.10
#Device
dev tun0
#The OpenVPN server takes the address 10.8.0.1 itself, #and this is common for daemons on both servers! server 10.8.0.0 255.255.255.0
#This file would be consistent on both servers assuming that #session information is synchronized. ifconfig-pool-persist /tmp/ipp.txt

Both OpenVPN daemons could use the exact same configuration (including ip-address and client address scope.)

So, the OpenVPN daemon running at the slave server, shares the session information with the master, including routing tables, but there is really no traffic from or to the clients. This probably yields some sort of new directive for OpenVPN (like e.g. --sync-sessions-if <interface>) and have this parameter make OpenVPN hold the session information regardless of traffic flowing or not. And of course listen / send session data on this interface.

The best way to sync session data would probably be to add a second interface to the servers and broadcast(!) the synchronization there.

|------|                            |------|
| VPN1 |.1----192.168.100.0/xx----.2| VPN2 |
|------|                            |------|

Ok, so exactly what OpenVPN session data is necessary to sync? As far as I can figure, the context and context_1 structs are interesting. Session keys, remote address list, status output, user / password, ++

I don't know exactly, but it seems that context_2 is mostly temporary data? (statistics, sequence numbers and so on). A comment is saying that this is wiped across SIGUSR1 and SIGHUP restarts. This probably means that also this data is necessary to sync?

Quoted 3 lines

Longer term I would like to design a clustering feature for OpenVPN, that would also support seamless failover in under 5 seconds.

Sounds like a plan :) I'm guessing you are planning to implement this as a OpenVPN internal feature, not using external services like CARP?

Quoted 3 lines

However if you really want to do seamless failover now, without waiting for future development, you could probably do it this way:

You are right, it's an option. But making the clients connect to both servers probably means a special client config is needed. I think this i a server side setup, thus there should be no need for doing client reconfiguration.

Quoted 15 lines

(1) Set up primary and backup OpenVPN servers.

(2) Set up clients to always connect to both servers.

(3) Set up VPN client <-> server routing through both primary and backup servers with the primary having a lower metric.

(4) Have a server/up down sensor such as CARP dynamically change the routing metrics based on which server is available. This could be done by having CARP run a script every time there is a change in server/up down status -- the script would need to multicast a RIP2 or OSPF notification through the VPN to change the routing metric to prefer the currently alive server (I'm not sure if there's a command line tool to multicast dynamic routing updates).

Quoted 5 lines

When we implement the clustering feature, the goal will be to automate the above steps. I will probably make plugin callbacks for (a) the server/up down sensor and (b) multicast of dynamic routing updates, so that these functions could be carried out outside of the OpenVPN core.

With CARP, you would not need to multicast a RIP2 or OSPF notify to clients.

One last question; is clustering a high prioritized feature?

Magne

Here is some more info on CARP:

http://www.openbsd.org/cgi-bin/man.cgi?query=carp&apropos=0&sektion=0&manpath=OpenBSD+Current&arch=i386&format=html

http://www.countersiege.com/doc/pfsync-carp/

http://kerneltrap.org/node/view/1021

#3 lore raw

[Openvpn-devel] OpenVPN GUI

In reply to James Yonan

Hi everybody

I used to tailor the 2.0.x OpenVPN GUI for Windows distribution for my installations. Mathias Sundman's distribution appears not to be up to date anymore, but the GUI showed up in the 2.1rc4.

Is this now the _official_ GUI distribution and will the installer source be kept on this base? I would like to be able to base my work on a stable thread.

Thanks

Erich