Merge pull request #11662 from thalesmg/port-scan-check-proto-dist-m-20230922

chore: check ekka proto dist module type when resolving node address
This commit is contained in:
Thales Macedo Garitezi 2023-09-25 17:01:43 -03:00 committed by GitHub
commit 17206f8c75
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 28 additions and 8 deletions

View File

@ -195,7 +195,8 @@ do_check({Node, #{resolved_ips := [IP | _]} = Plan}) ->
node_to_ips(Node) -> node_to_ips(Node) ->
NodeBin0 = atom_to_binary(Node), NodeBin0 = atom_to_binary(Node),
HostOrIP = re:replace(NodeBin0, <<"^.+@">>, <<"">>, [{return, list}]), HostOrIP = re:replace(NodeBin0, <<"^.+@">>, <<"">>, [{return, list}]),
case inet:gethostbyname(HostOrIP, inet) of AddressType = resolve_dist_address_type(),
case inet:gethostbyname(HostOrIP, AddressType) of
{ok, #hostent{h_addr_list = AddrList}} -> {ok, #hostent{h_addr_list = AddrList}} ->
AddrList; AddrList;
_ -> _ ->
@ -210,3 +211,18 @@ is_tcp_port_open(IP, Port) ->
_ -> _ ->
false false
end. end.
resolve_dist_address_type() ->
ProtoDistStr = os:getenv("EKKA_PROTO_DIST_MOD", "inet_tcp"),
case ProtoDistStr of
"inet_tcp" ->
inet;
"inet6_tcp" ->
inet6;
"inet_tls" ->
inet;
"inet6_tls" ->
inet6;
_ ->
inet
end.

View File

@ -152,6 +152,7 @@ t_open_ports_check(Config) ->
ok = emqx_cth_cluster:stop_node(Core2), ok = emqx_cth_cluster:stop_node(Core2),
?assertEqual(ok, erpc:call(Replicant, emqx_machine, open_ports_check, [])), ?assertEqual(ok, erpc:call(Replicant, emqx_machine, open_ports_check, [])),
Results = erpc:call(Core1, emqx_machine, open_ports_check, []),
?assertMatch( ?assertMatch(
#{ #{
msg := "some ports are unreachable", msg := "some ports are unreachable",
@ -159,18 +160,21 @@ t_open_ports_check(Config) ->
#{ #{
Core2 := Core2 :=
#{ #{
open_ports := #{ open_ports := #{},
GenRPCPort := _,
EkkaPort := _
},
ports_to_check := [_, _], ports_to_check := [_, _],
resolved_ips := [_], resolved_ips := [_],
status := bad_ports status := bad_ports
} }
} }
}, },
erpc:call(Core1, emqx_machine, open_ports_check, []), Results,
#{core2 => Core2} #{core2 => Core2, gen_rpc_port => GenRPCPort, ekka_port => EkkaPort}
),
%% 2 ports to check; we don't assert the exact ekka port because, when running
%% multiple nodes on the same machine as we do in tests, the order of returned ports
%% might change between invocations.
NumPorts = 2,
?assertEqual(
NumPorts, map_size(emqx_utils_maps:deep_get([results, Core2, open_ports], Results))
), ),
ok. ok.