https://bugs.kde.org/show_bug.cgi?id=519626

--- Comment #2 from altosch <[email protected]> ---
Update: root cause probably found – not a DNS/resolved issue

My original guess (systemd-resolved using the tunnel before it was ready) was
wrong. The degraded feature set messages were only a symptom.

What actually happens
===================

1. When NetworkManager activates the WireGuard connection, it moves the default
route into the tunnel (policy routing table).

2. Applications that already have open connections (browser, systemd-resolved,
desktop services) keep sending packets with their old source address, which is
the LAN IP. These packets now go into the tunnel.

3. The VPN server apparently uses the inner source address of the first packets
it sees and sends all replies to it. On a failed attempt, replies arrive inside
the tunnel addressed to the LAN IP instead of the tunnel IP.

4. Conntrack on the client cannot match these replies to any outgoing
connection, marks them INVALID, and the firewall (ufw: ct state invalid drop)
drops them. The handshake and encryption work fine, but no traffic gets
through.

This explains why it was random (it depends on which packet reaches the server
first) and why reconnecting after resume always worked (old connections had
already expired).

How to diagnose
==============

* wg show → handshake OK, the received counter is increasing

* tcpdump -ni wg0 icmp while pinging → requests leave with src <tunnel-ip>, but
replies come back with dst <LAN-IP>

* the firewall counter for ct state invalid drop increases

Fix
========

Only allow packets with the tunnel source address into the tunnel. A temporary
test with nftables:

nft add table inet wgguard
nft add chain inet wgguard out '{ type filter hook output priority -10; }'
nft add rule inet wgguard out oifname "wg0" ip saddr != <tunnel-ip> counter
drop

For a permanent fix with ufw, add this to /etc/ufw/before.rules, *before* the
RELATED,ESTABLISHED -j ACCEPT lines (otherwise the leaking packets of
established connections bypass it):

-A ufw-before-output -o wg0 ! -s <tunnel-ip>/32 -j DROP

After this change, the connection works reliably on the first attempt. No
dispatcher scripts or DNS workarounds are needed.

-- 
You are receiving this mail because:
You are watching all bug changes.

Reply via email to