From: Michael Tremer Date: Sun, 27 Apr 2025 16:30:59 +0000 (+0200) Subject: wireguard: Add a custom routing table for peers X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=43867c1e070fc96420a666b0bb21182eff16787b;p=people%2Fstevee%2Fipfire-2.x.git wireguard: Add a custom routing table for peers This is a dirty hack to make connections to VPN providers actually work. We mark all WG packets after encryption and use a secondary routing table to look up any routes to the peers. That way, we can replace the default route in the main routing table without having to care about the special routes there. Signed-off-by: Michael Tremer --- diff --git a/config/rootfiles/core/195/filelists/files b/config/rootfiles/core/195/filelists/files index 75d499f35..d8f95ae6c 100644 --- a/config/rootfiles/core/195/filelists/files +++ b/config/rootfiles/core/195/filelists/files @@ -1,4 +1,5 @@ etc/fcron.cyclic/wg-dynamic +etc/iproute2/rt_tables etc/rc.d/init.d/firewall etc/rc.d/init.d/networking/functions.network etc/rc.d/init.d/wireguard diff --git a/lfs/iproute2 b/lfs/iproute2 index 6dd3d4c3b..2c813382d 100644 --- a/lfs/iproute2 +++ b/lfs/iproute2 @@ -78,6 +78,7 @@ $(TARGET) : $(patsubst %,$(DIR_DL)/%,$(objects)) # Add table for static routing echo "200 static" >> /etc/iproute2/rt_tables + echo "201 wg" >> /etc/iproute2/rt_tables @rm -rf $(DIR_APP) @$(POSTBUILD) diff --git a/src/initscripts/system/wireguard b/src/initscripts/system/wireguard index ac7438a24..7decce223 100644 --- a/src/initscripts/system/wireguard +++ b/src/initscripts/system/wireguard @@ -25,6 +25,9 @@ eval $(/usr/local/bin/readhash /var/ipfire/wireguard/settings) +# Mark all packets coming out of the WireGuard interfaces +WG_MARK="0x00800000" + interfaces() { local id local enabled @@ -218,6 +221,7 @@ generate_config() { fi echo "[Interface]" + echo "FwMark = ${WG_MARK}" if [ -n "${privkey}" ]; then echo "PrivateKey = ${privkey}" @@ -267,6 +271,12 @@ generate_config() { ip route add "${args[@]}" done + + # Add a direct host route to the endpoint + if [ -s "/var/ipfire/red/remote-ipaddress" ]; then + ip route add table wg \ + "${endpoint_addr}" via "$(/dev/null + + # Ensure that the table is being looked up + if ! ip rule | grep -q "lookup wg"; then + ip rule add table wg fwmark "${WG_MARK}" + fi } wg_start() {