Allow definition of local address for outgoing s2s (EJAB-418)
This commit is contained in:
parent
5cb10cf9fa
commit
f70ebd6983
|
@ -803,6 +803,12 @@ Full path to the file containing the SSL certificate for a specific domain.
|
|||
Specify which address families to try, in what order, and connect timeout in milliseconds.
|
||||
By default it first tries connecting with IPv4, if that fails it tries using IPv6,
|
||||
with a timeout of 10000 milliseconds.
|
||||
</DD><DT CLASS="dt-description"><B><TT>{outgoing_s2s_local_address, IPaddress}</TT></B></DT><DD CLASS="dd-description">
|
||||
Specify which local IP address is desired for the outgoing S2S connections.
|
||||
This option is used only if the local and remote addresses
|
||||
are of the same IP version (either 4 or 6).
|
||||
If this option is not defined, and the <TT>ejabberd_s2s_in</TT>
|
||||
listener address is defined, then that one is used.
|
||||
</DD><DT CLASS="dt-description"><B><TT>{s2s_dns_options, [ {Property, Value}, ...]}</TT></B></DT><DD CLASS="dd-description">
|
||||
Define properties to use for DNS resolving.
|
||||
Allowed Properties are: <TT>timeout</TT> in seconds which default value is <TT>10</TT>
|
||||
|
|
|
@ -938,6 +938,12 @@ There are some additional global options that can be specified in the ejabberd c
|
|||
Specify which address families to try, in what order, and connect timeout in milliseconds.
|
||||
By default it first tries connecting with IPv4, if that fails it tries using IPv6,
|
||||
with a timeout of 10000 milliseconds.
|
||||
\titem{\{outgoing\_s2s\_local\_address, IPaddress\}} \ind{options!outgoing\_s2s\_local\_address}
|
||||
Specify which local IP address is desired for the outgoing S2S connections.
|
||||
This option is used only if the local and remote addresses
|
||||
are of the same IP version (either 4 or 6).
|
||||
If this option is not defined, and the \term{ejabberd\_s2s\_in}
|
||||
listener address is defined, then that one is used.
|
||||
\titem{\{s2s\_dns\_options, [ \{Property, Value\}, ...]\}}
|
||||
\ind{options!s2s\_dns\_options}Define properties to use for DNS resolving.
|
||||
Allowed Properties are: \term{timeout} in seconds which default value is \term{10}
|
||||
|
|
|
@ -394,6 +394,8 @@ process_term(Term, State) ->
|
|||
add_option(outgoing_s2s_port, Port, State);
|
||||
{outgoing_s2s_options, Methods, Timeout} ->
|
||||
add_option(outgoing_s2s_options, {Methods, Timeout}, State);
|
||||
{outgoing_s2s_local_address, Addr} ->
|
||||
add_option(outgoing_s2s_local_address, Addr, State);
|
||||
{s2s_dns_options, PropList} ->
|
||||
add_option(s2s_dns_options, PropList, State);
|
||||
{s2s_use_starttls, Port} ->
|
||||
|
|
|
@ -262,10 +262,11 @@ open_socket2(Type, Addr, Port) ->
|
|||
true -> [{send_timeout_close, true}];
|
||||
false -> []
|
||||
end,
|
||||
IpOpts = get_outgoing_local_address_opts(Type),
|
||||
case (catch ejabberd_socket:connect(Addr, Port,
|
||||
[binary, {packet, 0},
|
||||
{send_timeout, ?TCP_SEND_TIMEOUT},
|
||||
{active, false}, Type | SockOpts],
|
||||
{active, false}, Type | SockOpts]++IpOpts,
|
||||
Timeout)) of
|
||||
{ok, _Socket} = R -> R;
|
||||
{error, Reason} = R ->
|
||||
|
@ -276,6 +277,40 @@ open_socket2(Type, Addr, Port) ->
|
|||
{error, Reason}
|
||||
end.
|
||||
|
||||
get_outgoing_local_address_opts(DestType) ->
|
||||
ListenerIp = get_incoming_local_address(),
|
||||
OutLocalIp = case ejabberd_config:get_local_option(
|
||||
outgoing_s2s_local_address) of
|
||||
undefined -> undefined;
|
||||
T when is_tuple(T) ->
|
||||
T;
|
||||
S when is_list(S) ->
|
||||
[S2 | _] = string:tokens(S, "/"),
|
||||
{ok, T} = inet_parse:address(S2),
|
||||
T
|
||||
end,
|
||||
case {OutLocalIp, ListenerIp, DestType} of
|
||||
{{_, _, _, _}, _, inet} ->
|
||||
[{ip, OutLocalIp}];
|
||||
{{_, _, _, _, _, _, _, _}, _, inet6} ->
|
||||
[{ip, OutLocalIp}];
|
||||
{undefined, any, _} ->
|
||||
[];
|
||||
{undefined, _, _} ->
|
||||
[{ip, ListenerIp}];
|
||||
_ ->
|
||||
[]
|
||||
end.
|
||||
|
||||
get_incoming_local_address() ->
|
||||
Ports = ejabberd_config:get_local_option(listen),
|
||||
case [IP || {{_Port, IP, _Prot}, ejabberd_s2s_in, _Opts} <- Ports] of
|
||||
[{0, 0, 0, 0}] -> any;
|
||||
[{0, 0, 0, 0, 0, 0, 0, 0}] -> any;
|
||||
[IP] -> IP;
|
||||
_ -> any
|
||||
end.
|
||||
|
||||
%%----------------------------------------------------------------------
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue