Skip to content
This repository was archived by the owner on Nov 17, 2020. It is now read-only.

Commit 560b58c

Browse files
committed
Use the built-in Ranch PROXY protocol support
1 parent e6b3d1f commit 560b58c

File tree

3 files changed

+9
-35
lines changed

3 files changed

+9
-35
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ define PROJECT_APP_EXTRA_KEYS
2020
endef
2121

2222
LOCAL_DEPS = compiler syntax_tools xmerl
23-
DEPS = lager jsx ranch ranch_proxy_protocol recon
23+
DEPS = lager jsx ranch recon
2424

2525
# FIXME: Use erlang.mk patched for RabbitMQ, while waiting for PRs to be
2626
# reviewed and merged.

mk/rabbitmq-components.mk

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,6 @@ dep_jsx = hex 2.9.0
116116
dep_lager = hex 3.6.5
117117
dep_ra = git https://github.com/rabbitmq/ra.git master
118118
dep_ranch = hex 1.7.1
119-
dep_ranch_proxy_protocol = hex 2.1.1
120119
dep_recon = hex 2.3.6
121120

122121
dep_sockjs = git https://github.com/rabbitmq/sockjs-erlang.git 405990ea62353d98d36dbf5e1e64942d9b0a1daf

src/rabbit_net.erl

Lines changed: 8 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -232,15 +232,12 @@ socket_ends(Sock, Direction) when ?IS_SSL(Sock);
232232
{_, {error, _Reason} = Error} ->
233233
Error
234234
end;
235-
socket_ends(Sock, Direction = inbound) when is_tuple(Sock) ->
236-
%% proxy protocol support
237-
%% hack: we have to check the record type
238-
{ok, {{FromAddress, FromPort}, {_, _}}} = case element(1, Sock) of
239-
proxy_socket -> ranch_proxy_protocol:proxyname(undefined, Sock);
240-
ssl_socket -> ranch_proxy_ssl:proxyname(Sock)
241-
end,
235+
socket_ends({rabbit_proxy_socket, CSocket, ProxyInfo}, Direction = inbound) ->
236+
#{
237+
src_address := FromAddress,
238+
src_port := FromPort
239+
} = ProxyInfo,
242240
{_From, To} = sock_funs(Direction),
243-
CSocket = unwrap_socket(Sock),
244241
case To(CSocket) of
245242
{ok, {ToAddress, ToPort}} ->
246243
{ok, {rdns(FromAddress), FromPort,
@@ -294,34 +291,12 @@ is_loopback(_) -> false.
294291

295292
ipv4(AB, CD) -> {AB bsr 8, AB band 255, CD bsr 8, CD band 255}.
296293

297-
unwrap_socket(Sock) when ?IS_SSL(Sock);
298-
is_port(Sock) ->
294+
unwrap_socket({rabbit_proxy_socket, Sock, _}) ->
299295
Sock;
300-
unwrap_socket(Sock) when is_tuple(Sock) ->
301-
%% proxy protocol support
302-
%% hack: we have to check the record type
303-
case element(1, Sock) of
304-
proxy_socket ->
305-
ranch_proxy_protocol:get_csocket(Sock);
306-
ssl_socket ->
307-
ranch_proxy_ssl:get_csocket(Sock)
308-
end;
309296
unwrap_socket(Sock) ->
310297
Sock.
311298

312-
maybe_get_proxy_socket(Sock) when ?IS_SSL(Sock);
313-
is_port(Sock) ->
314-
undefined;
315-
maybe_get_proxy_socket(Sock) when is_tuple(Sock) ->
316-
%% proxy protocol support
317-
%% hack: we have to check the record type
318-
case element(1, Sock) of
319-
proxy_socket ->
320-
Sock;
321-
ssl_socket ->
322-
Sock;
323-
_ ->
324-
undefined
325-
end;
299+
maybe_get_proxy_socket(Sock={rabbit_proxy_socket, _, _}) ->
300+
Sock;
326301
maybe_get_proxy_socket(_Sock) ->
327302
undefined.

0 commit comments

Comments
 (0)