Skip to content

Commit 1bcfa47

Browse files
dumbbellmichaelklishin
authored andcommitted
rabbit_peer_discovery: Pass inetrc config file to temporary hidden node
[Why] As shown in #10728, in an IPv6-only environment, `kernel` name resolution must be configured through an inetrc file. The temporary hidden node must be configured exactly like the main node (and all nodes in the cluster in fact) to allow communication. Thus we must pass the same inetrc file to that temporary hidden node. This wasn’t the case before this patch. [How] We query the main node’s kernel to see if there is any inetrc file set and we use the same on the temporary hidden node’s command line. While here, extract the handling of the `proto_dist` module from the TLS code. This parameter may be used outside of TLS like this IPv6-only environment. Fixes #10728.
1 parent 524d688 commit 1bcfa47

File tree

1 file changed

+42
-27
lines changed

1 file changed

+42
-27
lines changed

deps/rabbit/src/rabbit_peer_discovery.erl

+42-27
Original file line numberDiff line numberDiff line change
@@ -388,16 +388,18 @@ query_node_props(Nodes) when Nodes =/= [] ->
388388
_ ->
389389
VMArgs1
390390
end,
391-
VMArgs3 = maybe_add_tls_arguments(VMArgs2),
391+
VMArgs3 = maybe_add_proto_dist_arguments(VMArgs2),
392+
VMArgs4 = maybe_add_inetrc_arguments(VMArgs3),
393+
VMArgs5 = maybe_add_tls_arguments(VMArgs4),
392394
PeerStartArg = case Context of
393395
#{nodename_type := longnames} ->
394396
#{name => PeerName,
395397
host => Suffix,
396398
longnames => true,
397-
args => VMArgs3};
399+
args => VMArgs5};
398400
_ ->
399401
#{name => PeerName,
400-
args => VMArgs3}
402+
args => VMArgs5}
401403
end,
402404
?LOG_DEBUG("Peer discovery: peer node arguments: ~tp",
403405
[PeerStartArg]),
@@ -423,27 +425,40 @@ query_node_props(Nodes) when Nodes =/= [] ->
423425
query_node_props([]) ->
424426
[].
425427

426-
maybe_add_tls_arguments(VMArgs0) ->
428+
maybe_add_proto_dist_arguments(VMArgs) ->
427429
case init:get_argument(proto_dist) of
428-
{ok, [["inet_tls"]]} ->
429-
add_tls_arguments(inet_tls, VMArgs0);
430-
{ok, [["inet6_tls"]]} ->
431-
add_tls_arguments(inet6_tls, VMArgs0);
430+
{ok, [[Val]]} ->
431+
%% See net_kernel.erl / protocol_childspecs/1
432+
Mod = list_to_existing_atom(Val ++ "_dist"),
433+
ModDir = filename:dirname(code:which(Mod)),
434+
["-proto_dist", Val, "-pa", ModDir | VMArgs];
432435
_ ->
433-
VMArgs0
436+
VMArgs
434437
end.
435438

436-
add_tls_arguments(InetDistModule, VMArgs0) ->
437-
VMArgs1 = case InetDistModule of
438-
inet_tls ->
439-
ProtoDistArg = ["-proto_dist", "inet_tls" | VMArgs0],
440-
["-pa", filename:dirname(code:which(inet_tls_dist))
441-
| ProtoDistArg];
442-
inet6_tls ->
443-
ProtoDistArg = ["-proto_dist", "inet6_tls" | VMArgs0],
444-
["-pa", filename:dirname(code:which(inet6_tls_dist))
445-
| ProtoDistArg]
446-
end,
439+
maybe_add_inetrc_arguments(VMArgs) ->
440+
%% If an inetrc file is configured, we need to use it for the temporary
441+
%% hidden node too.
442+
case application:get_env(kernel, inetrc) of
443+
{ok, Val} when is_list(Val) ->
444+
maybe_add_inetrc_arguments1(VMArgs, Val);
445+
undefined ->
446+
case os:getenv("ERL_INETRC") of
447+
Val when is_list(Val) ->
448+
maybe_add_inetrc_arguments1(VMArgs, Val);
449+
false ->
450+
VMArgs
451+
end
452+
end.
453+
454+
maybe_add_inetrc_arguments1(VMArgs, Val) ->
455+
%% The filename argument must be passed as a quoted string so that the
456+
%% command line is correctly parsed as an Erlang string by the temporary
457+
%% hidden node.
458+
ValString = rabbit_misc:format("~0p", [Val]),
459+
["-kernel", "inetrc", ValString | VMArgs].
460+
461+
maybe_add_tls_arguments(VMArgs) ->
447462
%% In the next case, RabbitMQ has been configured with additional Erlang VM
448463
%% arguments such as this:
449464
%%
@@ -494,14 +509,14 @@ add_tls_arguments(InetDistModule, VMArgs0) ->
494509
%% "/usr/local/lib/erlang/lib/ssl-11.0.3/ebin",
495510
%% "-proto_dist","inet_tls","-boot",
496511
%% "no_dot_erlang","-hidden"],
497-
VMArgs2 = case init:get_argument(ssl_dist_opt) of
512+
VMArgs1 = case init:get_argument(ssl_dist_opt) of
498513
{ok, SslDistOpts0} ->
499514
SslDistOpts1 = [["-ssl_dist_opt" | SslDistOpt]
500515
|| SslDistOpt <- SslDistOpts0],
501516
SslDistOpts2 = lists:concat(SslDistOpts1),
502-
SslDistOpts2 ++ VMArgs1;
517+
SslDistOpts2 ++ VMArgs;
503518
_ ->
504-
VMArgs1
519+
VMArgs
505520
end,
506521
%% In the next case, RabbitMQ has been configured with additional Erlang VM
507522
%% arguments such as this:
@@ -511,13 +526,13 @@ add_tls_arguments(InetDistModule, VMArgs0) ->
511526
%%
512527
%% This code adds the `ssl_dist_optfile' argument to the peer node's
513528
%% argument list.
514-
VMArgs3 = case init:get_argument(ssl_dist_optfile) of
529+
VMArgs2 = case init:get_argument(ssl_dist_optfile) of
515530
{ok, [[SslDistOptfileArg]]} ->
516-
["-ssl_dist_optfile", SslDistOptfileArg | VMArgs2];
531+
["-ssl_dist_optfile", SslDistOptfileArg | VMArgs1];
517532
_ ->
518-
VMArgs2
533+
VMArgs1
519534
end,
520-
VMArgs3.
535+
VMArgs2.
521536

522537
do_query_node_props(Nodes) when Nodes =/= [] ->
523538
%% Make sure all log messages are forwarded from this temporary hidden

0 commit comments

Comments
 (0)