From bbf1ddb1f41d615c43008461970b62dcdda914e7 Mon Sep 17 00:00:00 2001 From: Patric Stout Date: Wed, 5 Jul 2023 13:09:28 +0200 Subject: [PATCH] Fix 4ca1fb4b: properly fix not assuming proxy-protocol for SOCKS traffic (#282) --- master_server/application/master_server_query.py | 2 +- master_server/openttd/udp.py | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/master_server/application/master_server_query.py b/master_server/application/master_server_query.py index aba139c..04829b7 100644 --- a/master_server/application/master_server_query.py +++ b/master_server/application/master_server_query.py @@ -34,7 +34,7 @@ async def send_via_socks(): transport, _ = await request try: data = await response - protocol.datagram_received(data, server_addr) + protocol.datagram_received(data, server_addr, is_socks=True) finally: transport.close() diff --git a/master_server/openttd/udp.py b/master_server/openttd/udp.py index 4b9ef6f..145bbc2 100644 --- a/master_server/openttd/udp.py +++ b/master_server/openttd/udp.py @@ -49,8 +49,8 @@ def connection_made(self, transport): else: self.is_ipv6 = False - def _detect_source_ip_port(self, socket_addr, data): - if not self.proxy_protocol or self.socks_proxy: + def _detect_source_ip_port(self, socket_addr, data, is_socks=False): + if not self.proxy_protocol or is_socks: source = Source(self, socket_addr, socket_addr[0], socket_addr[1]) return source, data @@ -81,9 +81,9 @@ async def guard(self, coro): except Exception: log.exception("Error while processing packet") - def datagram_received(self, data, socket_addr): + def datagram_received(self, data, socket_addr, is_socks=False): try: - source, data = self._detect_source_ip_port(socket_addr, data) + source, data = self._detect_source_ip_port(socket_addr, data, is_socks=is_socks) except Exception as err: log.exception("Error detecting PROXY protocol %r: %r", socket_addr, err) return