SRV record support
Hello,
I would like to ask some help, I'm looking at the OpenVPN source tree from GitHub as I would like to see how much effort would it be me to add SRV record support, as it has increasing demand these days (and really makes sense, especially for enterprises).
So, the question is, what would be the best place to hook up the support for SRV records?
SRV record mechanism/requirements are the following:
- It's protocol-specific, so at lookup time it has to be known whether
it's for UDP or TCP
- The SRV records supply the service port, so in this case it's not
taken from the configuration file.
- Basically for a service it's one or more DNS records in the
following format:
_service._proto.name. TTL class SRV priority weight port target. I guess _service should be _openvpn, _proto is either _tcp or _udp.
port is obvious, and target is the target host to connect to using the previously specified port.
If there are multiple records, then priority makes sense, first the
hosts with the lowest values have to be tried, then rest increasingly
If there are multiple hosts with the same priority then weight kicks
in, a host to be chosen is determined by the weight factors. Attempts to a different priority can be made after all hosts from this priority are exhausted.
So, basically first there has to be a lookup against the server's SRV record, once that lookup returned results, and the priority/weight algorithm returns the first candidate, the existing connection mechanism can be used to check it. If it succeeds, life goes on as it is currently, if it fails, then the prio/weight algorithm's next target has to be tried.
So, where should I be looking at the source that would probably be a good place to hook this up?
Thanks in advance,
Gergely
PS: Please see the wikipedia article on SRV records:
https://en.wikipedia.org/wiki/SRV_record
Am 11.08.15 um 16:42 schrieb Gergely Czuczy:
Quoted 7 lines
Hello,
I would like to ask some help, I'm looking at the OpenVPN source tree from GitHub as I would like to see how much effort would it be me to add SRV record support, as it has increasing demand these days (and really makes sense, especially for enterprises).
Quoted 5 lines
So, the question is, what would be the best place to hook up the support for SRV records?
SRV record mechanism/requirements are the following:
- It's protocol-specific, so at lookup time it has to be known whether
it's for UDP or TCP
If proto were optional that would fit OpenVPN better. But SRV records seem not support that.
Quoted 6 lines
- The SRV records supply the service port, so in this case it's not
taken from the configuration file.
- Basically for a service it's one or more DNS records in the
following format:
_service._proto.name. TTL class SRV priority weight port target. I guess_serviceshould be_openvpn,_protois either_tcpor_udp.
Quoted 8 lines
port is obvious, and target is the target host to connect to using the previously specified port.
If there are multiple records, then priority makes sense, first the
hosts with the lowest values have to be tried, then rest increasingly
If there are multiple hosts with the same priority then weight kicks
in, a host to be chosen is determined by the weight factors. Attempts to a different priority can be made after all hosts from this priority are exhausted.
Multiple records are difficult. At the moment we have a list of connection entries in the config which may expand into multiple addresses (from getaddrinfo). The question if we do a dns lookup at the start for SRV enabled connection entries and mutate these entries into multiple entries or this should be done as part of the normal resolve process for each entry, introducing the concept of subconnections or something like this.
Doing a one reordering after priority and doing a weighted randomizing between connections with same priority should not be a problem.
Quoted 11 lines
So, basically first there has to be a lookup against the server's SRV record, once that lookup returned results, and the priority/weight algorithm returns the first candidate, the existing connection mechanism can be used to check it. If it succeeds, life goes on as it is currently, if it fails, then the prio/weight algorithm's next target has to be tried.
So, where should I be looking at the source that would probably be a good place to hook this up?
We should have a design idea before doing that and a fair warning the connnection connect logic is not for the faint hearted. In init.c is the next_connection method that iterates through the server. Almost all resolv related functions call openvpn_getaddrinfo, so going back from there is also a good starting point.
And if you modify anything use -master and not 2.3 as starting point. The code in question has changed a lot between releases (dual stack client patches).
Arne
Hi,
Quoted 4 lines · Gergely Czuczy
I would like to ask some help, I'm looking at the OpenVPN source tree from GitHub as I would like to see how much effort would it be me to add SRV record support, as it has increasing demand these days (and really makes sense, especially for enterprises).
Can you elaborate a bit more on why SRV makes sense? To my naive thinking, the amount of stuff you have to put into the client profile anyway is so large (like CA cert etc) that the remaining gain is fairly small...
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]...Hi,
Quoted 5 lines · Arne Schwabe
Quoted 3 lines
SRV record mechanism/requirements are the following:
- It's protocol-specific, so at lookup time it has to be known whether
it's for UDP or TCPIf proto were optional that would fit OpenVPN better. But SRV records seem not support that.
Well, one could just do two lookups, one for _tcp and one for _udp, and use that to fill pseudo-<remote>-entries, not only with port info but also with protocol info..
But it's not totally trivial.
[..]
Quoted 3 lines
And if you modify anything use -master and not 2.3 as starting point. The code in question has changed a lot between releases (dual stack client patches).
Yes, what Arne said. And this will not go into 2.3 as it will be too much of a change to be added into a release fairly late in its maintenance cycle... so "master it is".
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]...Quoted 9 lines · Arne Schwabe
Am 11.08.15 um 16:42 schrieb Gergely Czuczy:
Quoted 7 lines
Hello,
I would like to ask some help, I'm looking at the OpenVPN source tree from GitHub as I would like to see how much effort would it be me to add SRV record support, as it has increasing demand these days (and really makes sense, especially for enterprises).
Quoted 7 lines
Quoted 5 lines
So, the question is, what would be the best place to hook up the support for SRV records?
SRV record mechanism/requirements are the following:
- It's protocol-specific, so at lookup time it has to be known whether
it's for UDP or TCPIf proto were optional that would fit OpenVPN better. But SRV records seem not support that.
As Gert already pointed out, this is not that hard. To his comments I would like to add mine. Personally I think that it's fairly rare when someone has the same OpenVPN service on both UDP and TCP active (AFAIK this kind of configuration is not even supported by the config). Therefore the mechanism can check the existence of both kind of SRV records, for-just-in-case define a priority order for the protocols, then handle the found SRV record by that.
Quoted 22 lines
Quoted 6 lines
- The SRV records supply the service port, so in this case it's not
taken from the configuration file.
- Basically for a service it's one or more DNS records in the
following format:
_service._proto.name. TTL class SRV priority weight port target. I guess_serviceshould be_openvpn,_protois either_tcpor_udp.Quoted 8 lines
port is obvious, and target is the target host to connect to using the previously specified port.
If there are multiple records, then priority makes sense, first the
hosts with the lowest values have to be tried, then rest increasingly
If there are multiple hosts with the same priority then weight kicks
in, a host to be chosen is determined by the weight factors. Attempts to a different priority can be made after all hosts from this priority are exhausted.Multiple records are difficult. At the moment we have a list of connection entries in the config which may expand into multiple addresses (from getaddrinfo). The question if we do a dns lookup at the start for SRV enabled connection entries and mutate these entries into multiple entries or this should be done as part of the normal resolve process for each entry, introducing the concept of subconnections or something like this.
Quoted 2 lines
Doing a one reordering after priority and doing a weighted randomizing between connections with same priority should not be a problem.
Personally I'm thinking about having the SRV record mechanism up a level of the normal connection lookup mechanism. The current way you've describe makes total sense, and that kind of functionality is still totally valid for every address produced by the SRV mechanism.
So I'm thinking along the lines a good place to hook it would be where the current connection mechanism is called, and replace that call with the SRV lookups mechanism. So, instead of just connecting to the address in the configuration file, check for SRV records, if they exist then do the SRV logic, if there's no SRV record found, then proceed as it's currently being done.
With pseudo-code (without actually quoting the source, so naming convention doesn't match):
Instead of:
ovpn_connect(args)
Do:
srv = get_srv_records(host, proto)
if ( srv ) {
// the weight-prio algorithm calling ovpn_connect(srv_specific_args)
for each of its targets
} else {
ovpn_connect(args); // same as before
}
Quoted 16 lines
Quoted 10 lines
So, basically first there has to be a lookup against the server's SRV record, once that lookup returned results, and the priority/weight algorithm returns the first candidate, the existing connection mechanism can be used to check it. If it succeeds, life goes on as it is currently, if it fails, then the prio/weight algorithm's next target has to be tried.
So, where should I be looking at the source that would probably be a good place to hook this up?
We should have a design idea before doing that and a fair warning the connnection connect logic is not for the faint hearted. In
init.cis thenext_connectionmethod that iterates through the server. Almost all resolv related functions callopenvpn_getaddrinfo, so going back from there is also a good starting point.
Quoted 3 lines
And if you modify anything use -master and not 2.3 as starting point. The code in question has changed a lot between releases (dual stack client patches).
Definitely I'm going to use master, as I've read that's the main branch for development. Personally I think implementing a new feature in a release branch and then forward-porting it is the wrong approach.
Regards,
-czg
Quoted 10 lines · Gert Doering
Hi,
Quoted 4 lines · Gergely Czuczy
I would like to ask some help, I'm looking at the OpenVPN source tree from GitHub as I would like to see how much effort would it be me to add SRV record support, as it has increasing demand these days (and really makes sense, especially for enterprises).
Can you elaborate a bit more on why SRV makes sense? To my naive thinking, the amount of stuff you have to put into the client profile anyway is so large (like CA cert etc) that the remaining gain is fairly small...
Sure thing. With a buzzwordish approach, I would say it enables more enterprise-level configurations, regarding redundancy, connection optimization and such things.
Technically speaking, with SRV records you are able to centrally manage a set of servers where your clients will be connecting to, including the order in which the clients should try them. Including, but not limited to, this opens the door for the following things:
- Connection preferences are centrally set, without having to have
access to client configuration files. So changes can
be made centrally, and in case of high number of clients (like 100+ or so) you can just adjust your DNS records, and everyone's connection configuration will be adjusted to the changes. Good for managing a huge number of road warriors.
- It enables you to define the redundancy of the OpenVPN endpoints
centrally, change the number of your servers in your
OpenVPN clusters, without having to touch the client configuration files. Therefore you can centrally define the load balancing of your OpenVPN servers (weight field), and in case of that site being down, clients will be able to automatically fall back to your backup location (priority field).
Let me give a real world example, that's actually what I would like to implement by this. Imagine having a not so big firm, but with a global presence, meaning datacenters on many continents connected to each other, like North America, Europe, and Asia regions, and also having offices at these locations. Add GeoDNS to the mix.
By OpenSRV records, and GeoDNS support, the following can be achieved:
- Every user on each continent is getting a geographically optimized
set of SRV records, for example:
In NA, the order of DCs (per continent) is: NA, EU, APAC (Asia and Pacifics)
In EU: EU, NA, APAC
In APAC: APAC, NA, EU
- Each SRV priority level weights the OpenVPN endpoints by their
capacity.
- By these things, every user is connecting to the nearest openvpn
server to his or her location, therefore
reducing the network latency added by longer distance VPN connections.
- Client configurations require no local modification for adjustments,
since it's done centrally on the DNS server by
changing the SRV records
- If any of the servers are down, clients are redirected automatically
to the next server in the region. If the region's VPN
servers are all experiencing issues, they are going for the second best region's server, and so on.
Therefore with this setup a truely redundant, reliable and robust setup is possible, along with minimizing the maintenance costs by being able to adjust the client connection preferences centrally through DNS. The only time a client's config needs to be touched is at certificate renewal time.
Regarding CAs and certs, personally I do not think that is an issue, since all the servers listed for an SRV record set belong to the same cluster, therefore they share the same CA path.
I hope this explanation was clear, and the idea behind makes more sense now. Please let me know if I should elaborate on some parts.
Regards,
-czg
Hi,
I'm not a OpenVPN developer but the support of SRV records is a good idea. A client configuration works without a predefined VPN server and port and whenever you move your VPN server to another location or network. Only a domain must defined that contain the right service record. I think it sound's very good or?!
-Markus
Quoted 26 lines · Gergely Czuczy
Quoted 10 lines · Gert Doering
Hi,
Quoted 4 lines · Gergely Czuczy
I would like to ask some help, I'm looking at the OpenVPN source tree from GitHub as I would like to see how much effort would it be me to add SRV record support, as it has increasing demand these days (and really makes sense, especially for enterprises).
Can you elaborate a bit more on why SRV makes sense? To my naive thinking, the amount of stuff you have to put into the client profile anyway is so large (like CA cert etc) that the remaining gain is fairly small...
Sure thing. With a buzzwordish approach, I would say it enables more enterprise-level configurations,
regarding redundancy, connection optimization and such things. Technically speaking, with SRV records you are able to centrally manage a set of servers where your clients
will be connecting to, including the order in which the clients shouldSignature · 5 lines
Best regards, Markus PGP-Key: http://freebsduser.eu/allgemein/pgp-public-key/ PGP-Fingerprint: 949F 0510 E0C3 3B95 27A8 2EA2 38D9 56DE 2BA3 A0BA
Am 12.08.15 um 10:32 schrieb Gergely Czuczy:
Quoted 22 lines · Arne Schwabe
Quoted 17 lines
Am 11.08.15 um 16:42 schrieb Gergely Czuczy:
Quoted 8 lines
Hello,
I would like to ask some help, I'm looking at the OpenVPN source tree from GitHub as I would like to see how much effort would it be me to add
SRV record support, as it has increasing demand these days (and really makes sense, especially for enterprises).Quoted 7 lines
So, the question is, what would be the best place to hook up the support
for SRV records?
SRV record mechanism/requirements are the following:
- It's protocol-specific, so at lookup time it has to be known
whether
it's for UDP or TCPQuoted 2 lines
If proto were optional that would fit OpenVPN better. But SRV records seem not support that.
Quoted 9 lines
As Gert already pointed out, this is not that hard. To his comments I would like to add mine.
Personally I think that it's fairly rare when someone has the same OpenVPN service on both UDP and TCP
active (AFAIK this kind of configuration is not even supported by the config). Therefore the mechanism can
check the existence of both kind of SRV records, for-just-in-case define a priority order for the protocols,
then handle the found SRV record by that.
It is often used in this way:
remote foo.bar 1194 udp
remote foo.bar 53 udp
remote foo.bar 1194 tcp
remote foo.bar 443 tcp
Quoted 18 lines
Quoted 2 lines
Doing a one reordering after priority and doing a weighted randomizing between connections with same priority should not be a problem.
Personally I'm thinking about having the SRV record mechanism up a level of the normal
connection lookup mechanism. The current way you've describe makes total sense, and that
kind of functionality is still totally valid for every address produced by the SRV mechanism.So I'm thinking along the lines a good place to hook it would be where the current connection
mechanism is called, and replace that call with the SRV lookups mechanism. So, instead of just
connecting to the address in the configuration file, check for SRV records, if they exist then do
the SRV logic, if there's no SRV record found, then proceed as it's currently being done.
Quoted 12 lines
With pseudo-code (without actually quoting the source, so naming convention doesn't match):
Instead of:
ovpn_connect(args)
Do:
srv =get_srv_records(host, proto)
if ( srv ) {
// the weight-prio algorithm callingovpn_connect(srv_specific_args)
for each of its targets
} else {
ovpn_connect(args); // same as before
}
That's cute. I think you vastly underestimate the complexity of the state machine here. Take a look at next_connection_entry in init.c for the actual code. Part of the problem is that currently in that stage we do not resolve and have no real way of dealing with errors. So without complete refactoring, the only way to realize this is to have special SRV connections that only resolve and then add new temporary connections in the list after their own entry.
Arne
Am 12.08.15 um 11:00 schrieb Markus Grundmann:
Quoted 9 lines
Hi,
I'm not a OpenVPN developer but the support of SRV records is a good idea. A client configuration works without a predefined VPN server and port and whenever you move your VPN server to another location or network. Only a domain must defined that contain the right service record. I think it sound's very good or?!
-
Yes but changing AAAA/A of opnvpn.company.com or IN SRV of openvpn.company.com is not such a big difference.
At the moment a config with just
client
remote openvpn.company.com
does not work (you need at least specificy a ca and an authentification method etc...), so the main advantage of SRV records, which is just specify your domain and the software will automatically figure out server etc. does not
apply here.
Arne
Hi,
Quoted 2 lines · Arne Schwabe
Yes but changing AAAA/A of opnvpn.company.com or IN SRV of openvpn.company.com is not such a big difference.
This was my thought as well, but SRV does have merits - especially the priority thing is something you can't properly do with "traditional" DNS entries (if you have multiple A/AAAA records, you just get load sharing).
It's not a killer feature, as "most of it" could be achieved by having
remote openvpn-pri1.company.com
remote openvpn-pri2.company.com
remote openvpn-pri3.company.com
in your configs, and DNS/GeoDNS can steer this to the proper hosts - but SRV makes it more convenient to the user (and much work for the implementor... :) )
So - I wouldn't *implement* this myself, but if it were there, I'd propably *use* it. Example: I have rolled out quite a number of .ovpn client profiles that prefer TCP before UDP today. Given the nice new tls-float feature, I'd actually love to have them try UDP first... without rolling out new .ovpns...
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]...