Hello,

Thanks for you bug report.

On Tue, Jun 24, 2025 at 02:37:53PM +0200, Christopher Bock wrote:
> Package: auto-apt-proxy
> Version: 16.8
> Severity: important
> X-Debbugs-Cc: [email protected]
> 
> 
> Hi Antonio,
> 
> i see there was a change[1] of the lookups in favor of the gateway
> instead of the nameserver records.
> In my case this slows down auto-apt-proxy by 20 seconds as shown in the
> attached log file. On my gateway (an opnsense) there are no services running
> on the tested ports nor is there any firewall rule that would forward any of
> these requests as my apt-cacher-ng is running in a jail on my nas and i only
> have configured an "apt-proxy" A entry which worked pretty well so
> far.

Ouch. The issue is that resolving names might also slow things down, and
I wanted to avoid that. I think I got a simple enough parser for
/etc/that that should work, so we can resolve `apt-proxy` statically
without going outside for DNS.

Can you test the attached patch?
From 86611afa44e30971076d651947987ce857712543 Mon Sep 17 00:00:00 2001
From: Antonio Terceiro <[email protected]>
Date: Tue, 24 Jun 2025 15:15:12 -0300
Subject: [PATCH] Try apt-proxy from /etc/hosts before default gateway
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

The network default gateway might be restrictive with regards to
accepting (or immediately REJECTing) connections to arbitrary ports.
Setting apt-proxy in /etc/hosts was a way of working around that, but
that got broken by 56b604cd2 ("Try options that require resolving names
last"). Simply reverting that would bring back an issues where name
resolution might take too long, so that is not an option.

This introduces a simplified /etc/hosts parser that seems to do The
Right Thing™, and will resolve `apt-proxy` statically, based on what's
defined there, without going into remote -- and potentially slow -- DNS
calls.

Closes: #1108265
---
 README.md      |  4 ++--
 auto-apt-proxy | 10 ++++++++++
 2 files changed, 12 insertions(+), 2 deletions(-)

diff --git a/README.md b/README.md
index 4d3347e..fe0be87 100644
--- a/README.md
+++ b/README.md
@@ -65,9 +65,9 @@ not change which proxy is used if multiple mDNS provided proxies are available.
 
 - A locally running proxy on 127.0.0.1
 - A locally running proxy on other local addresses
+- A proxy running on the host `apt-proxy`, according to /etc/hosts.
 - A proxy on the network default gateway
-- A proxy running on the `apt-proxy` on DNS or local hostname resolution
-  (`/etc/hosts`).
+- A proxy running on the host `apt-proxy`, according to DNS.
 - A proxy running in the host and port declared in the `_apt_proxy_` SRV DNS
   record
 - A proxy running and announced via mDNS (avahi).
diff --git a/auto-apt-proxy b/auto-apt-proxy
index a38a2ac..1b5b3d2 100755
--- a/auto-apt-proxy
+++ b/auto-apt-proxy
@@ -290,6 +290,10 @@ v6_gateway() {
   echo "${ret}"
 }
 
+v4_explicit_proxy_etc_hosts() {
+  awk '/^[0-9.]+[[:blank:]]/ { for (i=1;i<=NF;i++) { if($i == "apt-proxy") {print($1); exit} } }' /etc/hosts
+}
+
 v4_explicit_proxy() {
   local ret
   ret=$(resolve_getent ahostsv4 apt-proxy)
@@ -297,6 +301,10 @@ v4_explicit_proxy() {
   echo "${ret}"
 }
 
+v6_explicit_proxy_etc_hosts() {
+  awk '/^[0-9a-f:]+[[:blank:]]/ { for (i=1;i<=NF;i++) { if($i == "apt-proxy") {print($1); exit} } }' /etc/hosts
+}
+
 v6_explicit_proxy() {
   local ret
   ret=$(resolve_getent ahostsv6 apt-proxy)
@@ -324,8 +332,10 @@ __detect__() {
   sources="
     v4_localhost
     v4_addresses
+    v4_explicit_proxy_etc_hosts
     v4_gateway
     v6_localhost
+    v6_explicit_proxy_etc_hosts
     v6_gateway
     v4_explicit_proxy
     v6_explicit_proxy
-- 
2.47.2

Attachment: signature.asc
Description: PGP signature

Reply via email to