summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon MacMullen <simon@rabbitmq.com>2012-11-05 14:48:24 +0000
committerSimon MacMullen <simon@rabbitmq.com>2012-11-05 14:48:24 +0000
commit00e46395333b40cd2b686e418c7e29d34f9d4d41 (patch)
tree297e765fbcdeafd190a807df8237b69b5c05d4b0
parentbd2bd07fd063e6ce2b0d7e8c1589fff7ac1cd2ae (diff)
parentfbe7832f5486a155cff5ddab2eea3fadcd039cf4 (diff)
downloadrabbitmq-server-00e46395333b40cd2b686e418c7e29d34f9d4d41.tar.gz
Merge bug25268
-rw-r--r--codegen.py2
-rw-r--r--docs/rabbitmqctl.1.xml18
-rw-r--r--ebin/rabbit_app.in1
-rw-r--r--src/rabbit_control_main.erl2
-rw-r--r--src/rabbit_net.erl42
-rw-r--r--src/rabbit_networking.erl2
-rw-r--r--src/rabbit_reader.erl45
7 files changed, 72 insertions, 40 deletions
diff --git a/codegen.py b/codegen.py
index 68f530c2..1d873d34 100644
--- a/codegen.py
+++ b/codegen.py
@@ -237,7 +237,7 @@ def genErl(spec):
'R' + i, 'L' + i, 'S' + i, 'X' + i))
if len(c.fields) == 0:
- print "decode_properties(%d, _) ->" % (c.index,)
+ print "decode_properties(%d, <<>>) ->" % (c.index,)
else:
print ("decode_properties(%d, %s) ->" %
(c.index, presentBin(c.fields)))
diff --git a/docs/rabbitmqctl.1.xml b/docs/rabbitmqctl.1.xml
index 3082fe14..34947b66 100644
--- a/docs/rabbitmqctl.1.xml
+++ b/docs/rabbitmqctl.1.xml
@@ -1282,22 +1282,26 @@
<listitem><para>Readable name for the connection.</para></listitem>
</varlistentry>
<varlistentry>
- <term>address</term>
- <listitem><para>Server IP address.</para></listitem>
- </varlistentry>
- <varlistentry>
<term>port</term>
<listitem><para>Server port.</para></listitem>
</varlistentry>
<varlistentry>
- <term>peer_address</term>
- <listitem><para>Peer address.</para></listitem>
+ <term>host</term>
+ <listitem><para>Server hostname obtained via reverse
+ DNS, or its IP address if reverse DNS failed or was
+ not enabled.</para></listitem>
</varlistentry>
<varlistentry>
<term>peer_port</term>
<listitem><para>Peer port.</para></listitem>
</varlistentry>
<varlistentry>
+ <term>peer_host</term>
+ <listitem><para>Peer hostname obtained via reverse
+ DNS, or its IP address if reverse DNS failed or was
+ not enabled.</para></listitem>
+ </varlistentry>
+ <varlistentry>
<term>ssl</term>
<listitem><para>Boolean indicating whether the
connection is secured with SSL.</para></listitem>
@@ -1414,7 +1418,7 @@
</variablelist>
<para>
If no <command>connectioninfoitem</command>s are
- specified then user, peer address, peer port, time since
+ specified then user, peer host, peer port, time since
flow control and memory block state are displayed.
</para>
diff --git a/ebin/rabbit_app.in b/ebin/rabbit_app.in
index 9b1ff8bd..16dfd196 100644
--- a/ebin/rabbit_app.in
+++ b/ebin/rabbit_app.in
@@ -43,6 +43,7 @@
{trace_vhosts, []},
{log_levels, [{connection, info}]},
{ssl_cert_login_from, distinguished_name},
+ {reverse_dns_lookups, false},
{tcp_listen_options, [binary,
{packet, raw},
{reuseaddr, true},
diff --git a/src/rabbit_control_main.erl b/src/rabbit_control_main.erl
index 1b42a847..669a0787 100644
--- a/src/rabbit_control_main.erl
+++ b/src/rabbit_control_main.erl
@@ -386,7 +386,7 @@ action(list_bindings, Node, Args, Opts, Inform) ->
action(list_connections, Node, Args, _Opts, Inform) ->
Inform("Listing connections", []),
- ArgAtoms = default_if_empty(Args, [user, peer_address, peer_port, state]),
+ ArgAtoms = default_if_empty(Args, [user, peer_host, peer_port, state]),
display_info_list(rpc_call(Node, rabbit_networking, connection_info_all,
[ArgAtoms]),
ArgAtoms);
diff --git a/src/rabbit_net.erl b/src/rabbit_net.erl
index 038154c3..562fc197 100644
--- a/src/rabbit_net.erl
+++ b/src/rabbit_net.erl
@@ -20,7 +20,7 @@
-export([is_ssl/1, ssl_info/1, controlling_process/2, getstat/2,
recv/1, async_recv/3, port_command/2, getopts/2, setopts/2, send/2,
close/1, fast_close/1, sockname/1, peername/1, peercert/1,
- tune_buffer_size/1, connection_string/2]).
+ tune_buffer_size/1, connection_string/2, socket_ends/2]).
%%---------------------------------------------------------------------------
@@ -36,7 +36,7 @@
-type(socket() :: port() | #ssl_socket{}).
-type(opts() :: [{atom(), any()} |
{raw, non_neg_integer(), non_neg_integer(), binary()}]).
-
+-type(host_or_ip() :: binary() | inet:ip_address()).
-spec(is_ssl/1 :: (socket()) -> boolean()).
-spec(ssl_info/1 :: (socket())
-> 'nossl' | ok_val_or_error(
@@ -72,6 +72,10 @@
-spec(tune_buffer_size/1 :: (socket()) -> ok_or_any_error()).
-spec(connection_string/2 ::
(socket(), 'inbound' | 'outbound') -> ok_val_or_error(string())).
+-spec(socket_ends/2 ::
+ (socket(), 'inbound' | 'outbound')
+ -> ok_val_or_error({host_or_ip(), rabbit_networking:ip_port(),
+ host_or_ip(), rabbit_networking:ip_port()})).
-endif.
@@ -193,17 +197,37 @@ tune_buffer_size(Sock) ->
end.
connection_string(Sock, Direction) ->
- {From, To} = case Direction of
- inbound -> {fun peername/1, fun sockname/1};
- outbound -> {fun sockname/1, fun peername/1}
- end,
+ case socket_ends(Sock, Direction) of
+ {ok, {FromAddress, FromPort, ToAddress, ToPort}} ->
+ {ok, rabbit_misc:format(
+ "~s:~p -> ~s:~p",
+ [maybe_ntoab(FromAddress), FromPort,
+ maybe_ntoab(ToAddress), ToPort])};
+ Error ->
+ Error
+ end.
+
+socket_ends(Sock, Direction) ->
+ {From, To} = sock_funs(Direction),
case {From(Sock), To(Sock)} of
{{ok, {FromAddress, FromPort}}, {ok, {ToAddress, ToPort}}} ->
- {ok, rabbit_misc:format("~s:~p -> ~s:~p",
- [rabbit_misc:ntoab(FromAddress), FromPort,
- rabbit_misc:ntoab(ToAddress), ToPort])};
+ {ok, {rdns(FromAddress), FromPort,
+ rdns(ToAddress), ToPort}};
{{error, _Reason} = Error, _} ->
Error;
{_, {error, _Reason} = Error} ->
Error
end.
+
+maybe_ntoab(Addr) when is_tuple(Addr) -> rabbit_misc:ntoab(Addr);
+maybe_ntoab(Host) -> Host.
+
+rdns(Addr) ->
+ {ok, Lookup} = application:get_env(rabbit, reverse_dns_lookups),
+ case Lookup of
+ true -> list_to_binary(rabbit_networking:tcp_host(Addr));
+ _ -> Addr
+ end.
+
+sock_funs(inbound) -> {fun peername/1, fun sockname/1};
+sock_funs(outbound) -> {fun sockname/1, fun peername/1}.
diff --git a/src/rabbit_networking.erl b/src/rabbit_networking.erl
index 5cf8d1ae..31eeef73 100644
--- a/src/rabbit_networking.erl
+++ b/src/rabbit_networking.erl
@@ -21,7 +21,7 @@
node_listeners/1, connections/0, connection_info_keys/0,
connection_info/1, connection_info/2,
connection_info_all/0, connection_info_all/1,
- close_connection/2, force_connection_event_refresh/0]).
+ close_connection/2, force_connection_event_refresh/0, tcp_host/1]).
%%used by TCP-based transports, e.g. STOMP adapter
-export([tcp_listener_addresses/1, tcp_listener_spec/6,
diff --git a/src/rabbit_reader.erl b/src/rabbit_reader.erl
index 829e9e52..928786e9 100644
--- a/src/rabbit_reader.erl
+++ b/src/rabbit_reader.erl
@@ -39,19 +39,19 @@
connection_state, queue_collector, heartbeater, stats_timer,
channel_sup_sup_pid, start_heartbeat_fun, buf, buf_len,
auth_mechanism, auth_state, conserve_resources,
- last_blocked_by, last_blocked_at}).
+ last_blocked_by, last_blocked_at, host, peer_host,
+ port, peer_port}).
-define(STATISTICS_KEYS, [pid, recv_oct, recv_cnt, send_oct, send_cnt,
send_pend, state, last_blocked_by, last_blocked_age,
channels]).
--define(CREATION_EVENT_KEYS, [pid, name, address, port, peer_address, peer_port,
- ssl, peer_cert_subject, peer_cert_issuer,
- peer_cert_validity, auth_mechanism,
- ssl_protocol, ssl_key_exchange,
- ssl_cipher, ssl_hash,
- protocol, user, vhost, timeout, frame_max,
- client_properties]).
+-define(CREATION_EVENT_KEYS,
+ [pid, name, port, peer_port, host,
+ peer_host, ssl, peer_cert_subject, peer_cert_issuer,
+ peer_cert_validity, auth_mechanism, ssl_protocol,
+ ssl_key_exchange, ssl_cipher, ssl_hash, protocol, user, vhost,
+ timeout, frame_max, client_properties]).
-define(INFO_KEYS, ?CREATION_EVENT_KEYS ++ ?STATISTICS_KEYS -- [pid]).
@@ -192,17 +192,20 @@ socket_op(Sock, Fun) ->
name(Sock) ->
socket_op(Sock, fun (S) -> rabbit_net:connection_string(S, inbound) end).
+socket_ends(Sock) ->
+ socket_op(Sock, fun (S) -> rabbit_net:socket_ends(S, inbound) end).
+
start_connection(Parent, ChannelSupSupPid, Collector, StartHeartbeatFun, Deb,
Sock, SockTransform) ->
process_flag(trap_exit, true),
Name = name(Sock),
log(info, "accepting AMQP connection ~p (~s)~n", [self(), Name]),
ClientSock = socket_op(Sock, SockTransform),
- erlang:send_after(?HANDSHAKE_TIMEOUT * 1000, self(),
- handshake_timeout),
+ erlang:send_after(?HANDSHAKE_TIMEOUT * 1000, self(), handshake_timeout),
+ {PeerHost, PeerPort, Host, Port} = socket_ends(Sock),
State = #v1{parent = Parent,
sock = ClientSock,
- name = Name,
+ name = list_to_binary(Name),
connection = #connection{
protocol = none,
user = none,
@@ -225,7 +228,11 @@ start_connection(Parent, ChannelSupSupPid, Collector, StartHeartbeatFun, Deb,
auth_state = none,
conserve_resources = false,
last_blocked_by = none,
- last_blocked_at = never},
+ last_blocked_at = never,
+ host = Host,
+ peer_host = PeerHost,
+ port = Port,
+ peer_port = PeerPort},
try
ok = inet_op(fun () -> rabbit_net:tune_buffer_size(ClientSock) end),
recvloop(Deb, switch_callback(rabbit_event:init_stats_timer(
@@ -894,15 +901,11 @@ auth_phase(Response,
infos(Items, State) -> [{Item, i(Item, State)} || Item <- Items].
i(pid, #v1{}) -> self();
-i(name, #v1{name = Name}) -> list_to_binary(Name);
-i(address, S) -> socket_info(fun rabbit_net:sockname/1,
- fun ({A, _}) -> A end, S);
-i(port, S) -> socket_info(fun rabbit_net:sockname/1,
- fun ({_, P}) -> P end, S);
-i(peer_address, S) -> socket_info(fun rabbit_net:peername/1,
- fun ({A, _}) -> A end, S);
-i(peer_port, S) -> socket_info(fun rabbit_net:peername/1,
- fun ({_, P}) -> P end, S);
+i(name, #v1{name = Name}) -> Name;
+i(host, #v1{host = Host}) -> Host;
+i(peer_host, #v1{peer_host = PeerHost}) -> PeerHost;
+i(port, #v1{port = Port}) -> Port;
+i(peer_port, #v1{peer_port = PeerPort}) -> PeerPort;
i(SockStat, S) when SockStat =:= recv_oct;
SockStat =:= recv_cnt;
SockStat =:= send_oct;