From 42edf25751babaa4e597787f77db45f2fd6a2505 Mon Sep 17 00:00:00 2001 From: Jordan Potter Date: Sat, 6 Mar 2021 21:22:10 -0600 Subject: [PATCH] Add support for LOCAL_NETWORK environment variable --- entrypoint.sh | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/entrypoint.sh b/entrypoint.sh index 7e8548e..08d5bd5 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -2,6 +2,12 @@ set -e +default_route_ip=$(ip route | grep default | awk '{print $3}') +if [[ -z "$default_route_ip" ]]; then + echo "No default route configured" >&2 + exit 1 +fi + configs=`find /etc/wireguard -type f -printf "%f\n"` if [[ -z "$configs" ]]; then echo "No configuration files found in /etc/wireguard" >&2 @@ -31,6 +37,11 @@ else ip6tables -I OUTPUT ! -o $interface -m mark ! --mark $(wg show $interface fwmark) -m addrtype ! --dst-type LOCAL $docker6_network_rule -j REJECT fi +if [[ "$LOCAL_NETWORK" ]]; then + ip route add $LOCAL_NETWORK via $default_route_ip + iptables -I OUTPUT -d $LOCAL_NETWORK -j ACCEPT +fi + shutdown () { wg-quick down $interface exit 0