From 16f3fba3e576534e2b805bbbd10c787ecde0d3d8 Mon Sep 17 00:00:00 2001 From: "Kristof Ringleff, Fooman" Date: Thu, 2 Mar 2023 21:34:58 +1300 Subject: [PATCH] Adding support for Table setting Setting is explained here https://man7.org/linux/man-pages/man8/wg-quick.8.html --- README.md | 1 + src/config.js | 1 + src/lib/WireGuard.js | 6 ++++++ 3 files changed, 8 insertions(+) diff --git a/README.md b/README.md index 6daca1b2..c30c1d09 100644 --- a/README.md +++ b/README.md @@ -85,6 +85,7 @@ These options can be configured by setting environment variables using `-e KEY=" | `WG_HOST` | - | `vpn.myserver.com` | The public hostname of your VPN server. | | `WG_PORT` | `51820` | `12345` | The public UDP port of your VPN server. WireGuard will always listen on `51820` inside the Docker container. | | `WG_MTU` | `null` | `1420` | The MTU the clients will use. Server uses default WG MTU. | +| `WG_TABLE` | `null` | `1234` | Controls the routing table to which routes are added. There are two special values: `off` disables the creation of routes altogether, and `auto` adds routes to the default table and enables special handling of default routes. | | `WG_PERSISTENT_KEEPALIVE` | `0` | `25` | Value in seconds to keep the "connection" open. If this value is 0, then connections won't be kept alive. | | `WG_DEFAULT_ADDRESS` | `10.8.0.x` | `10.6.0.x` | Clients IP address range. | | `WG_DEFAULT_DNS` | `1.1.1.1` | `8.8.8.8, 8.8.4.4` | DNS server clients will use. | diff --git a/src/config.js b/src/config.js index 28c9fc5a..3347163a 100644 --- a/src/config.js +++ b/src/config.js @@ -9,6 +9,7 @@ module.exports.WG_PATH = process.env.WG_PATH || '/etc/wireguard/'; module.exports.WG_HOST = process.env.WG_HOST; module.exports.WG_PORT = process.env.WG_PORT || 51820; module.exports.WG_MTU = process.env.WG_MTU || null; +module.exports.WG_TABLE = process.env.WG_TABLE || null; module.exports.WG_PERSISTENT_KEEPALIVE = process.env.WG_PERSISTENT_KEEPALIVE || 0; module.exports.WG_DEFAULT_ADDRESS = process.env.WG_DEFAULT_ADDRESS || '10.8.0.x'; module.exports.WG_DEFAULT_DNS = typeof process.env.WG_DEFAULT_DNS === 'string' diff --git a/src/lib/WireGuard.js b/src/lib/WireGuard.js index 7886ac91..f6beda24 100644 --- a/src/lib/WireGuard.js +++ b/src/lib/WireGuard.js @@ -15,6 +15,7 @@ const { WG_HOST, WG_PORT, WG_MTU, + WG_TABLE, WG_DEFAULT_DNS, WG_DEFAULT_ADDRESS, WG_PERSISTENT_KEEPALIVE, @@ -102,6 +103,11 @@ PreDown = ${WG_PRE_DOWN} PostDown = ${WG_POST_DOWN} `; + if (WG_TABLE) { + result += ` +Table = ${WG_TABLE} +`; + } for (const [clientId, client] of Object.entries(config.clients)) { if (!client.enabled) continue;