Skip to content

Commit 14cd8b8

Browse files
committed
MB-48940: Try both address family while connecting to LDAP host
Change-Id: I3d98e5f8537266993b180e56016a88d11bb27fb9 Reviewed-on: http://review.couchbase.org/c/ns_server/+/163699 Reviewed-by: Timofey Barmin <[email protected]> Tested-by: Build Bot <[email protected]> Well-Formed: Restriction Checker
1 parent d8904b3 commit 14cd8b8

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

src/ldap_util.erl

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,11 +112,32 @@ open_ldap_connection([Host|Hosts], Port, SSL, Timeout, Settings) ->
112112
end,
113113
%% Note: timeout option sets not only connect timeout but a timeout for any
114114
%% request to ldap server
115-
case eldap:open([Host], [{port, Port}, {timeout, Timeout} | SSLOpts]) of
115+
Opts = [{port, Port}, {timeout, Timeout} | SSLOpts],
116+
case do_open_ldap_connection(Host, Opts) of
116117
{ok, Handle} -> {ok, Handle, Host};
117118
{error, _} -> open_ldap_connection(Hosts, Port, SSL, Timeout, Settings)
118119
end.
119120

121+
do_open_ldap_connection(Host, Opts) ->
122+
ToTry = case {misc:is_raw_ip(Host), misc:is_raw_ipv6(Host)} of
123+
{_, true} ->
124+
[inet6];
125+
{true, _} ->
126+
[inet];
127+
_ ->
128+
case misc:get_net_family() of
129+
inet ->
130+
[inet, inet6];
131+
inet6 ->
132+
[inet6, inet]
133+
end
134+
end,
135+
lists:foldl(fun (_Afamily, {ok, Handle}) ->
136+
{ok, Handle};
137+
(Afamily, _) ->
138+
eldap:open([Host], [{tcpopts, [Afamily]} | Opts])
139+
end, undefined, ToTry).
140+
120141
with_connection(Settings, Fun) ->
121142
Hosts = proplists:get_value(hosts, Settings),
122143
Port = proplists:get_value(port, Settings),

0 commit comments

Comments
 (0)