Fix DNS resolution across Wi-Fi, cellular, USB tethering, and VPNs

- Add NetworkManager rc-manager=file with dnsmasq caching and baseline /etc/resolv.conf, isolate usb0 routes/DNS in USB_Networking.nmconnection, enable loopback in boot runlevel, and guard 90-nm-cloud-setup.sh for OpenRC.
- Rewrite 50-dns-filter.sh to handle dhcp4/dhcp6/dns events, drop BusyBox-invalid logger -i and blocking gateway sleeps, gate IPv6 AAAA filtering on global unicast addresses and accept_ra, and fall back to 1.1.1.1/9.9.9.9 when no upstream DNS is advertised.
- Fix bananarchy-privacy-ctl musl parallel-query leaks (omit 127.0.0.1 in VPN mode, add sync-dns recovery, replace pkill/pgrep), add usb-tether DNS DNAT, rebuild and verify all four a1120 target images and release zips, and add scripts/test-dns-resolution.py.
This commit is contained in:
Luxferre committed 2026-11-18 13:12:11 +02:00
1 parent 6cedcf980c
commit 63ef9299fc
15 files changed
+764 -105

No files matched your search

+69 -32
View File
@@ -4,10 +4,16 @@
# with zero background CPU/battery drain when services are turned off.
set -u
STATE_DIR="/tmp/bananarchy-privacy"
STATE_DIR="${BANANARCHY_PRIVACY_STATE_DIR:-/tmp/bananarchy-privacy}"
USER_HOME="/home/user"
CONF_DIR="$USER_HOME/.config/bananarchy"
CONF_FILE="$CONF_DIR/privacy.conf"
CONF_DIR="${BANANARCHY_PRIVACY_CONF_DIR:-$USER_HOME/.config/bananarchy}"
CONF_FILE="${BANANARCHY_PRIVACY_CONF:-$CONF_DIR/privacy.conf}"
RESOLV_CONF="${BANANARCHY_RESOLV_CONF:-/etc/resolv.conf}"
NM_RESOLV_CONF="${BANANARCHY_NM_RESOLV_CONF:-/run/NetworkManager/resolv.conf}"
NM_NOSTUB_RESOLV_CONF="${BANANARCHY_NM_NOSTUB_RESOLV_CONF:-/run/NetworkManager/no-stub-resolv.conf}"
DURESS_FILE="${BANANARCHY_DURESS_FILE:-/tmp/bananarchy_duress_mode}"
SCREEN_LOCKED_FILE="${BANANARCHY_SCREEN_LOCKED_FILE:-/tmp/bananarchy_screen_locked}"
PRIVACY_NO_ROOT="${BANANARCHY_PRIVACY_NO_ROOT:-0}"
DEFAULT_GSWARP_OVPN="$USER_HOME/.config/gs-warp/client.ovpn"
if [ ! -f "$DEFAULT_GSWARP_OVPN" ] && [ -f "/etc/gs-warp/client.ovpn" ]; then
DEFAULT_GSWARP_OVPN="/etc/gs-warp/client.ovpn"
@@ -16,15 +22,18 @@ fi
CMD="${1:-status}"
# Block all operations except stop-all when in duress mode or screen locked
if [ "$CMD" != "stop-all" ] && [ "$CMD" != "_ovpn_up" ] && [ "$CMD" != "_tor_up" ]; then
if [ -e "/tmp/bananarchy_duress_mode" ] || [ -e "/tmp/bananarchy_screen_locked" ]; then
# Allow sync-dns while screen-locked (unless in duress) so Wi-Fi roam keeps tunnel DNS pinned
if [ "$CMD" != "stop-all" ] && [ "$CMD" != "_ovpn_up" ] && [ "$CMD" != "_tor_up" ] && [ "$CMD" != "sync-dns" ]; then
if [ -e "$DURESS_FILE" ] || [ -e "$SCREEN_LOCKED_FILE" ]; then
echo "Error: Privacy Center is unavailable." >&2
exit 1
fi
elif [ "$CMD" = "sync-dns" ] && [ -e "$DURESS_FILE" ]; then
exit 0
fi
# Escalate to root via doas or bananarchy-engmenu-exec if invoked as normal user
if [ "$(id -u)" -ne 0 ]; then
if [ "$PRIVACY_NO_ROOT" != "1" ] && [ "$(id -u)" -ne 0 ]; then
if command -v doas >/dev/null 2>&1; then
exec doas -n /usr/bin/bananarchy-privacy-ctl "$@"
elif [ -x /usr/bin/bananarchy-engmenu-exec ]; then
@@ -38,7 +47,11 @@ if [ "$(id -u)" -ne 0 ]; then
exit 1
fi
export PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
if [ -n "${BANANARCHY_TEST_PATH_PREFIX:-}" ]; then
export PATH="${BANANARCHY_TEST_PATH_PREFIX}:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
else
export PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
fi
mkdir -p "$STATE_DIR" "$CONF_DIR"
# Default configuration values
@@ -159,7 +172,7 @@ is_tor_active() {
return 0
fi
fi
pgrep -x tor >/dev/null 2>&1
pidof tor >/dev/null 2>&1
}
is_gswarp_active() {
@@ -203,6 +216,27 @@ is_wg_active() {
}
# Remove an iptables chain from a table and all references from hook chains
find_proc_pids() {
_pat="$1"
for _pdir in /proc/[0-9]*; do
[ -r "$_pdir/cmdline" ] || continue
_pid="${_pdir#/proc/}"
[ "$_pid" = "$$" ] && continue
_cmd="$(tr '\0' ' ' < "$_pdir/cmdline" 2>/dev/null || true)"
case "$_cmd" in
*$_pat*)
printf '%s\n' "$_pid"
;;
esac
done
}
kill_proc_matches() {
for _pid in $(find_proc_pids "$1"); do
kill "$_pid" 2>/dev/null || true
done
}
flush_and_delete_chain() {
tbl="$1"
chain="$2"
@@ -276,30 +310,26 @@ sync_dns_resolv() {
fi
if [ -n "$active_dns" ]; then
if [ ! -f "$STATE_DIR/resolv.conf.orig" ] && [ -f /etc/resolv.conf ]; then
cp -f /etc/resolv.conf "$STATE_DIR/resolv.conf.orig" 2>/dev/null || true
fi
{
echo "# Managed by bananarchy-privacy-ctl (tunneled DNS)"
echo "nameserver $active_dns"
if [ "$active_dns" != "1.1.1.1" ]; then
if [ "$active_dns" != "127.0.0.1" ] && [ "$active_dns" != "1.1.1.1" ]; then
echo "nameserver 1.1.1.1"
fi
if [ "$active_dns" != "127.0.0.1" ]; then
echo "nameserver 127.0.0.1"
fi
} > "$STATE_DIR/resolv.conf.new"
cp -f "$STATE_DIR/resolv.conf.new" /etc/resolv.conf 2>/dev/null || true
cp -f "$STATE_DIR/resolv.conf.new" "$RESOLV_CONF" 2>/dev/null || true
else
if [ -f "$STATE_DIR/resolv.conf.orig" ]; then
cp -f "$STATE_DIR/resolv.conf.orig" /etc/resolv.conf 2>/dev/null || true
rm -f "$STATE_DIR/resolv.conf.orig"
fi
if ! grep -q '^nameserver ' /etc/resolv.conf 2>/dev/null; then
rm -f "$STATE_DIR/resolv.conf.orig" "$STATE_DIR/resolv.conf.new" 2>/dev/null || true
if grep -q '^nameserver ' "$NM_RESOLV_CONF" 2>/dev/null; then
cp -f "$NM_RESOLV_CONF" "$RESOLV_CONF" 2>/dev/null || true
elif grep -q '^nameserver ' "$NM_NOSTUB_RESOLV_CONF" 2>/dev/null; then
cp -f "$NM_NOSTUB_RESOLV_CONF" "$RESOLV_CONF" 2>/dev/null || true
else
{
echo "# Generated by NetworkManager"
echo "nameserver 127.0.0.1"
echo "nameserver 1.1.1.1"
} > /etc/resolv.conf 2>/dev/null || true
echo "options edns0 trust-ad"
} > "$RESOLV_CONF" 2>/dev/null || true
fi
fi
}
@@ -490,7 +520,7 @@ stop_tor() {
kill "$(cat "$STATE_DIR/tor.pid" 2>/dev/null)" 2>/dev/null || true
rm -f "$STATE_DIR/tor.pid"
fi
pkill -x tor 2>/dev/null || true
killall -q tor 2>/dev/null || true
sync_dns_resolv
}
@@ -627,7 +657,7 @@ start_gswarp() {
-D -p 1194 -s "$GSWARP_SECRET" 2>/dev/null || \
/usr/bin/gs-netcat -D -p 1194 -s "$GSWARP_SECRET" 2>/dev/null
sleep 0.2
gs_pid="$(pgrep -f "gs-netcat -D -p 1194" | head -n 1 || true)"
gs_pid="$(find_proc_pids "gs-netcat -D -p 1194" | head -n 1 || true)"
if [ -z "$gs_pid" ]; then
echo "Error: failed to start gs-netcat for GS-Warp." >&2
return 1
@@ -673,8 +703,8 @@ stop_gswarp() {
rm -f "$pidf"
fi
done
pkill -f "gs-netcat -D -p 1194" 2>/dev/null || true
pkill -f "openvpn.*tun_gswarp" 2>/dev/null || true
kill_proc_matches "gs-netcat -D -p 1194"
kill_proc_matches "openvpn*tun_gswarp"
ip link del dev tun_gswarp 2>/dev/null || true
sync_base_vpn_rules
sync_dns_resolv
@@ -730,7 +760,7 @@ stop_ovpn() {
kill "$(cat "$STATE_DIR/ovpn.pid" 2>/dev/null)" 2>/dev/null || true
rm -f "$STATE_DIR/ovpn.pid"
fi
pkill -f "openvpn.*tun_ovpn" 2>/dev/null || true
kill_proc_matches "openvpn*tun_ovpn"
ip link del dev tun_ovpn 2>/dev/null || true
sync_base_vpn_rules
sync_dns_resolv
@@ -816,13 +846,13 @@ start_gsocket() {
-D -l -s "$GSOCKET_SECRET" -d 127.0.0.1 -p "$GSOCKET_PORT" 2>/dev/null || \
/usr/bin/gs-netcat -D -l -s "$GSOCKET_SECRET" -d 127.0.0.1 -p "$GSOCKET_PORT" 2>/dev/null
sleep 0.2
gs_pid="$(pgrep -f "gs-netcat -D -l -s .* -p $GSOCKET_PORT" | head -n 1 || true)"
gs_pid="$(find_proc_pids "gs-netcat -D -l -s *-p $GSOCKET_PORT" | head -n 1 || true)"
else
start-stop-daemon -S -g openvpn -x /usr/bin/gs-netcat -- \
-D -s "$GSOCKET_SECRET" -p "$GSOCKET_PORT" 2>/dev/null || \
/usr/bin/gs-netcat -D -s "$GSOCKET_SECRET" -p "$GSOCKET_PORT" 2>/dev/null
sleep 0.2
gs_pid="$(pgrep -f "gs-netcat -D -s .* -p $GSOCKET_PORT" | head -n 1 || true)"
gs_pid="$(find_proc_pids "gs-netcat -D -s *-p $GSOCKET_PORT" | head -n 1 || true)"
fi
if [ -z "$gs_pid" ]; then
@@ -839,8 +869,8 @@ stop_gsocket() {
kill "$(cat "$STATE_DIR/gsocket-port.pid" 2>/dev/null)" 2>/dev/null || true
rm -f "$STATE_DIR/gsocket-port.pid"
fi
pkill -f "gs-netcat -D -s .* -p $GSOCKET_PORT" 2>/dev/null || true
pkill -f "gs-netcat -D -l -s .* -p $GSOCKET_PORT" 2>/dev/null || true
kill_proc_matches "gs-netcat -D -s *-p $GSOCKET_PORT"
kill_proc_matches "gs-netcat -D -l -s *-p $GSOCKET_PORT"
}
# ==============================================================================
@@ -1168,5 +1198,12 @@ case "$CMD" in
stop_gsocket
stop_wg
;;
sync-dns)
if is_tor_active || is_gswarp_active || is_ovpn_active || is_wg_active; then
sync_dns_resolv
elif grep -q '^# Managed by bananarchy-privacy-ctl' "$RESOLV_CONF" 2>/dev/null; then
sync_dns_resolv
fi
;;
esac
exit 0