Sort and shuffle SRV record by priority and weight

On multiple occasions, SRV query answers were not properly sorted by
priority. Records with same priority weren't randomized and shuffled.
This caused FreeIPA to contact the same remote peer instead of
distributing the load across all available servers.

Two new helper functions now take care of SRV queries. sort_prio_weight()
sorts SRV and URI records. query_srv() combines SRV lookup with
sort_prio_weight().

Fixes: https://pagure.io/freeipa/issue/7475
Signed-off-by: Christian Heimes <cheimes@redhat.com>
Reviewed-By: Rob Crittenden <rcritten@redhat.com>
This commit is contained in:
Christian Heimes committed 2018-06-19 08:56:46 +02:00
1 parent eda831dba1
commit f90e137a17
7 files changed
+217 -30

No files matched your search

+4 -4
View File
@@ -26,7 +26,6 @@ from copy import copy
import socket
import functools
from dns import resolver, rdatatype
from dns.exception import DNSException
import dns.name
# pylint: disable=import-error
@@ -36,6 +35,7 @@ from six.moves.urllib.parse import urlsplit
from ipaplatform.paths import paths
from ipapython.dn import DN
from ipapython.dnsutil import query_srv
from ipapython.ipautil import CheckedIPAddress, CheckedIPAddressLoopback
@@ -210,7 +210,7 @@ def __discover_config(discover_server = True):
name = "_ldap._tcp." + domain
try:
servers = resolver.query(name, rdatatype.SRV)
servers = query_srv(name)
except DNSException:
# try cycling on domain components of FQDN
try:
@@ -225,7 +225,7 @@ def __discover_config(discover_server = True):
return False
name = "_ldap._tcp.%s" % domain
try:
servers = resolver.query(name, rdatatype.SRV)
servers = query_srv(name)
break
except DNSException:
pass
@@ -236,7 +236,7 @@ def __discover_config(discover_server = True):
if not servers:
name = "_ldap._tcp.%s." % config.default_domain
try:
servers = resolver.query(name, rdatatype.SRV)
servers = query_srv(name)
except DNSException:
pass