Make Pivilion the exclusive dnsmasq owner

This commit is contained in:
v3d 2026-07-02 21:20:47 +02:00
parent 5a27dfeceb
commit 0238f3a531
3 changed files with 61 additions and 7 deletions

View file

@ -90,7 +90,7 @@ validate_ap_support() {
}
cleanup_hotspot() {
systemctl stop pivilion-dnsmasq.service pivilion-hostapd.service 2>/dev/null || true
systemctl stop dnsmasq.service pivilion-dnsmasq.service pivilion-hostapd.service 2>/dev/null || true
rm -f "$DNSMASQ_CONF" "$HOSTAPD_CONF"
nft delete table inet pivilion 2>/dev/null || true
if command -v nmcli >/dev/null 2>&1; then
@ -115,6 +115,41 @@ check_dns_conflict() {
fi
}
log_dnsmasq_failure() {
{
echo "Pivilion dnsmasq diagnostics:"
echo "-- TCP/UDP port 53 listeners --"
ss -H -lntup 'sport = :53' || true
echo "-- pivilion-dnsmasq.service status --"
systemctl status pivilion-dnsmasq.service --no-pager -l || true
echo "-- generic dnsmasq.service status --"
systemctl status dnsmasq.service --no-pager -l || true
echo "-- recent pivilion-dnsmasq.service journal --"
journalctl -u pivilion-dnsmasq.service -n 50 --no-pager || true
} >&2
}
start_pivilion_dnsmasq() {
local i stable=0
if ! systemctl start pivilion-dnsmasq.service; then
echo "Could not start pivilion-dnsmasq.service" >&2
log_dnsmasq_failure
return 1
fi
for i in $(seq 1 10); do
if systemctl is-active --quiet pivilion-dnsmasq.service; then
stable=$((stable + 1))
[ "$stable" -ge 3 ] && return 0
else
stable=0
fi
sleep 1
done
echo "pivilion-dnsmasq.service did not remain active" >&2
log_dnsmasq_failure
return 1
}
check_hostapd_conflict() {
if systemctl is-active --quiet hostapd.service 2>/dev/null; then
echo "The system hostapd service already owns a wireless interface." >&2
@ -225,6 +260,7 @@ start_hotspot() {
fi
if ! check_dns_conflict; then
pivilion_write_state none "$BACKEND" failed "Port 53 conflict"
log_dnsmasq_failure
refresh_login_banner
exit "$PIVILION_E_CONFLICT"
fi
@ -245,7 +281,7 @@ start_hotspot() {
ip link set "$IFACE" down; ip address flush dev "$IFACE"; ip address add 10.1.1.1/24 dev "$IFACE"; ip link set "$IFACE" up
systemctl restart pivilion-hostapd.service
fi
systemctl restart pivilion-dnsmasq.service
start_pivilion_dnsmasq
apply_firewall
if wait_for_diagnostics hotspot; then
pivilion_write_state hotspot "$BACKEND" healthy none
@ -264,6 +300,7 @@ start_onion() {
pivilion_write_state none "$BACKEND" activating none
if [ "$BACKEND" = networkmanager ]; then pivilion_nm_prepare_interface "$IFACE"; fi
cleanup_hotspot
systemctl stop pivilion-dnsmasq.service 2>/dev/null || true
rm -f "$CAPTIVE_LIVE"
if [ "$BACKEND" = networkmanager ]; then
nmcli connection up pivilion-onion >/dev/null 2>&1 || {