fix(listener): support listen on ipv6 address
This commit is contained in:
parent
7ad0dc7c73
commit
e0b33dc258
|
@ -2113,9 +2113,13 @@ to_comma_separated_atoms(Str) ->
|
||||||
to_bar_separated_list(Str) ->
|
to_bar_separated_list(Str) ->
|
||||||
{ok, string:tokens(Str, "| ")}.
|
{ok, string:tokens(Str, "| ")}.
|
||||||
|
|
||||||
|
%% @doc support the following format:
|
||||||
|
%% - 127.0.0.1:1883
|
||||||
|
%% - ::1:1883
|
||||||
|
%% - [::1]:1883
|
||||||
to_ip_port(Str) ->
|
to_ip_port(Str) ->
|
||||||
case string:tokens(Str, ": ") of
|
case split_ip_port(Str) of
|
||||||
[Ip, Port] ->
|
{Ip, Port} ->
|
||||||
PortVal = list_to_integer(Port),
|
PortVal = list_to_integer(Port),
|
||||||
case inet:parse_address(Ip) of
|
case inet:parse_address(Ip) of
|
||||||
{ok, R} ->
|
{ok, R} ->
|
||||||
|
@ -2133,6 +2137,25 @@ to_ip_port(Str) ->
|
||||||
{error, Str}
|
{error, Str}
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
split_ip_port(Str) ->
|
||||||
|
case lists:split(string:rchr(Str, $:), Str) of
|
||||||
|
%% no port
|
||||||
|
{[], Str} ->
|
||||||
|
error;
|
||||||
|
{IpPlusColon, PortString} ->
|
||||||
|
IpStr0 = lists:droplast(IpPlusColon),
|
||||||
|
case IpStr0 of
|
||||||
|
%% dropp head/tail brackets
|
||||||
|
[$[ | S] ->
|
||||||
|
case lists:last(S) of
|
||||||
|
$] -> {lists:droplast(S), PortString};
|
||||||
|
_ -> error
|
||||||
|
end;
|
||||||
|
_ ->
|
||||||
|
{IpStr0, PortString}
|
||||||
|
end
|
||||||
|
end.
|
||||||
|
|
||||||
to_erl_cipher_suite(Str) ->
|
to_erl_cipher_suite(Str) ->
|
||||||
case ssl:str_to_suite(Str) of
|
case ssl:str_to_suite(Str) of
|
||||||
{error, Reason} -> error({invalid_cipher, Reason});
|
{error, Reason} -> error({invalid_cipher, Reason});
|
||||||
|
|
|
@ -566,23 +566,23 @@ trace_type(_, _) -> error.
|
||||||
listeners([]) ->
|
listeners([]) ->
|
||||||
lists:foreach(
|
lists:foreach(
|
||||||
fun({ID, Conf}) ->
|
fun({ID, Conf}) ->
|
||||||
{Host, Port} = maps:get(bind, Conf),
|
Bind = maps:get(bind, Conf),
|
||||||
Acceptors = maps:get(acceptors, Conf),
|
Acceptors = maps:get(acceptors, Conf),
|
||||||
ProxyProtocol = maps:get(proxy_protocol, Conf, undefined),
|
ProxyProtocol = maps:get(proxy_protocol, Conf, undefined),
|
||||||
Running = maps:get(running, Conf),
|
Running = maps:get(running, Conf),
|
||||||
CurrentConns =
|
CurrentConns =
|
||||||
case emqx_listeners:current_conns(ID, {Host, Port}) of
|
case emqx_listeners:current_conns(ID, Bind) of
|
||||||
{error, _} -> [];
|
{error, _} -> [];
|
||||||
CC -> [{current_conn, CC}]
|
CC -> [{current_conn, CC}]
|
||||||
end,
|
end,
|
||||||
MaxConn =
|
MaxConn =
|
||||||
case emqx_listeners:max_conns(ID, {Host, Port}) of
|
case emqx_listeners:max_conns(ID, Bind) of
|
||||||
{error, _} -> [];
|
{error, _} -> [];
|
||||||
MC -> [{max_conns, MC}]
|
MC -> [{max_conns, MC}]
|
||||||
end,
|
end,
|
||||||
Info =
|
Info =
|
||||||
[
|
[
|
||||||
{listen_on, {string, format_listen_on(Port)}},
|
{listen_on, {string, format_listen_on(Bind)}},
|
||||||
{acceptors, Acceptors},
|
{acceptors, Acceptors},
|
||||||
{proxy_protocol, ProxyProtocol},
|
{proxy_protocol, ProxyProtocol},
|
||||||
{running, Running}
|
{running, Running}
|
||||||
|
@ -806,8 +806,10 @@ format_listen_on(Port) when is_integer(Port) ->
|
||||||
io_lib:format("0.0.0.0:~w", [Port]);
|
io_lib:format("0.0.0.0:~w", [Port]);
|
||||||
format_listen_on({Addr, Port}) when is_list(Addr) ->
|
format_listen_on({Addr, Port}) when is_list(Addr) ->
|
||||||
io_lib:format("~ts:~w", [Addr, Port]);
|
io_lib:format("~ts:~w", [Addr, Port]);
|
||||||
format_listen_on({Addr, Port}) when is_tuple(Addr) ->
|
format_listen_on({Addr, Port}) when is_tuple(Addr) andalso tuple_size(Addr) == 4 ->
|
||||||
io_lib:format("~ts:~w", [inet:ntoa(Addr), Port]).
|
io_lib:format("~ts:~w", [inet:ntoa(Addr), Port]);
|
||||||
|
format_listen_on({Addr, Port}) when is_tuple(Addr) andalso tuple_size(Addr) == 8 ->
|
||||||
|
io_lib:format("[~ts]:~w", [inet:ntoa(Addr), Port]).
|
||||||
|
|
||||||
name(Filter) ->
|
name(Filter) ->
|
||||||
iolist_to_binary(["CLI-", Filter]).
|
iolist_to_binary(["CLI-", Filter]).
|
||||||
|
|
Loading…
Reference in New Issue