diff options
author | Matthias Radestock <matthias@rabbitmq.com> | 2012-10-29 19:08:20 +0000 |
---|---|---|
committer | Matthias Radestock <matthias@rabbitmq.com> | 2012-10-29 19:08:20 +0000 |
commit | 67aaa1237373589da658bcb5c7f8bcb921fda663 (patch) | |
tree | 79a1c671aaa10c1764076a525ddc5005b2ec4c86 | |
parent | 410b72f56fa88256196ac5420ebc6868476ea9f3 (diff) | |
parent | d075a60988ba89a5302ab9724caeae4ac80d14f8 (diff) | |
download | rabbitmq-server-67aaa1237373589da658bcb5c7f8bcb921fda663.tar.gz |
merge default into bug23935
-rw-r--r-- | docs/rabbitmqctl.1.xml | 8 | ||||
-rw-r--r-- | ebin/rabbit_app.in | 1 | ||||
-rw-r--r-- | src/rabbit_net.erl | 40 | ||||
-rw-r--r-- | src/rabbit_networking.erl | 2 | ||||
-rw-r--r-- | src/rabbit_reader.erl | 25 |
5 files changed, 56 insertions, 20 deletions
diff --git a/docs/rabbitmqctl.1.xml b/docs/rabbitmqctl.1.xml index 3082fe14..ce3ae7d6 100644 --- a/docs/rabbitmqctl.1.xml +++ b/docs/rabbitmqctl.1.xml @@ -1290,6 +1290,10 @@ <listitem><para>Server port.</para></listitem> </varlistentry> <varlistentry> + <term>host</term> + <listitem><para>Server DNS host.</para></listitem> + </varlistentry> + <varlistentry> <term>peer_address</term> <listitem><para>Peer address.</para></listitem> </varlistentry> @@ -1298,6 +1302,10 @@ <listitem><para>Peer port.</para></listitem> </varlistentry> <varlistentry> + <term>peer_host</term> + <listitem><para>Peer DNS host.</para></listitem> + </varlistentry> + <varlistentry> <term>ssl</term> <listitem><para>Boolean indicating whether the connection is secured with SSL.</para></listitem> 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_net.erl b/src/rabbit_net.erl index 038154c3..24843aa0 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, rdns/2]). %%--------------------------------------------------------------------------- @@ -72,6 +72,9 @@ -spec(tune_buffer_size/1 :: (socket()) -> ok_or_any_error()). -spec(connection_string/2 :: (socket(), 'inbound' | 'outbound') -> ok_val_or_error(string())). +-spec(rdns/2 :: + (socket(), 'inbound' | 'outbound') -> {string() | 'unknown', + string() | 'unknown'}). -endif. @@ -193,17 +196,38 @@ 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, + {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, rabbit_misc:format( + "~s:~p -> ~s:~p", + [maybe_rdns(FromAddress, Sock, From), FromPort, + maybe_rdns(ToAddress, Sock, To), ToPort])}; {{error, _Reason} = Error, _} -> Error; {_, {error, _Reason} = Error} -> Error end. + +rdns(Sock, Direction) -> + {From, To} = sock_funs(Direction), + {rdns_lookup(Sock, From), rdns_lookup(Sock, To)}. + +maybe_rdns(Addr, Sock, Fun) -> + case rdns_lookup(Sock, Fun) of + unknown -> rabbit_misc:ntoab(Addr); + Host -> Host + end. + +rdns_lookup(Sock, Fun) -> + {ok, Lookup} = application:get_env(rabbit, reverse_dns_lookups), + case Lookup of + true -> case Fun(Sock) of + {ok, {IP, _Port}} -> rabbit_networking:tcp_host(IP); + _ -> unknown + end; + _ -> unknown + 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 2c1eeb91..50ad2bf8 100644 --- a/src/rabbit_reader.erl +++ b/src/rabbit_reader.erl @@ -39,19 +39,18 @@ 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}). -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, address, port, peer_address, 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]). @@ -198,8 +197,8 @@ start_connection(Parent, ChannelSupSupPid, Collector, StartHeartbeatFun, Deb, 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), + {Host, PeerHost} = rabbit_net:rdns(Sock, inbound), State = #v1{parent = Parent, sock = ClientSock, name = Name, @@ -225,7 +224,9 @@ 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}, try ok = inet_op(fun () -> rabbit_net:tune_buffer_size(ClientSock) end), recvloop(Deb, switch_callback(rabbit_event:init_stats_timer( @@ -893,6 +894,8 @@ infos(Items, State) -> [{Item, i(Item, State)} || Item <- Items]. i(pid, #v1{}) -> self(); i(name, #v1{name = Name}) -> list_to_binary(Name); +i(host, #v1{host = Host}) -> list_to_binary(Host); +i(peer_host, #v1{peer_host = PeerHost}) -> list_to_binary(PeerHost); 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, |