Skip to content

Commit a2adb59

Browse files
author
r0p0s3c
committed
move iptables/nat functionality to a function (setupIptablesAndRouting)
This allows iptables rule update to be overridden by creating/supplying that function in, for example, ovpn_env.sh
1 parent f4351bb commit a2adb59

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

bin/ovpn_run

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,18 @@ function addArg {
3535
fi
3636
}
3737

38+
function setupIptablesAndRouting {
39+
iptables -t nat -C POSTROUTING -s $OVPN_SERVER -o $OVPN_NATDEVICE -j MASQUERADE || {
40+
iptables -t nat -A POSTROUTING -s $OVPN_SERVER -o $OVPN_NATDEVICE -j MASQUERADE
41+
}
42+
for i in "${OVPN_ROUTES[@]}"; do
43+
iptables -t nat -C POSTROUTING -s "$i" -o $OVPN_NATDEVICE -j MASQUERADE || {
44+
iptables -t nat -A POSTROUTING -s "$i" -o $OVPN_NATDEVICE -j MASQUERADE
45+
}
46+
done
47+
}
48+
49+
3850
addArg "--config" "$OPENVPN/openvpn.conf"
3951

4052
source "$OPENVPN/ovpn_env.sh"
@@ -53,14 +65,7 @@ fi
5365

5466
# Setup NAT forwarding if requested
5567
if [ "$OVPN_DEFROUTE" != "0" ] || [ "$OVPN_NAT" == "1" ] ; then
56-
iptables -t nat -C POSTROUTING -s $OVPN_SERVER -o $OVPN_NATDEVICE -j MASQUERADE || {
57-
iptables -t nat -A POSTROUTING -s $OVPN_SERVER -o $OVPN_NATDEVICE -j MASQUERADE
58-
}
59-
for i in "${OVPN_ROUTES[@]}"; do
60-
iptables -t nat -C POSTROUTING -s "$i" -o $OVPN_NATDEVICE -j MASQUERADE || {
61-
iptables -t nat -A POSTROUTING -s "$i" -o $OVPN_NATDEVICE -j MASQUERADE
62-
}
63-
done
68+
setupIptablesAndRouting
6469
fi
6570

6671
# Use a hacky hardlink as the CRL Needs to be readable by the user/group
@@ -85,4 +90,3 @@ fi
8590

8691
echo "Running 'openvpn ${ARGS[@]} ${USER_ARGS[@]}'"
8792
exec openvpn ${ARGS[@]} ${USER_ARGS[@]}
88-

0 commit comments

Comments
 (0)