Skip to content

Commit

Permalink
finally made nat working
Browse files Browse the repository at this point in the history
  • Loading branch information
Jamesits committed May 10, 2020
1 parent c850e50 commit eecc50e
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions scripts/netnsinit
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/bash

set -e

set -x
display_usage() {
echo "Auto configuration for systemd-named-netns."
echo -e "\nUsage:\n\t$0 network-type ns-name [optional params] [up|down] [inside|outside]\n"
Expand All @@ -26,9 +26,10 @@ autoconfigure_tunnel_up_outside() {
ip -n ${NSNAME} link set ${DEVNAME_INSIDE} up

# add ipv4 address at global end
# let this fail silently if IPADDR_OUTSIDE is undefined
! ip address add ${IPADDR_OUTSIDE} dev ${DEVNAME_OUTSIDE}

if [ ! -z "${IPADDR_OUTSIDE}" ]; then
ip address add ${IPADDR_OUTSIDE} dev ${DEVNAME_OUTSIDE}
fi

return 0 # additional precation against "set -e" in case of future mods of this function
}

Expand All @@ -40,7 +41,7 @@ autoconfigure_tunnel_up_inside() {

# setup default route
if [ ! -z "${GATEWAY}" ]; then
ip route add default via ${GATEWAY%%/*} onlink
ip route add default via ${GATEWAY%%/*} dev ${DEVNAME_INSIDE} onlink
fi

# if DHCP is configured
Expand Down Expand Up @@ -107,7 +108,7 @@ autoconfigure_nat_up_inside() {

# add default route if gateway undefined
if [ -z "${GATEWAY}" -a -n "${IPADDR_OUTSIDE}" ]; then
ip route add default via ${IPADDR_OUTSIDE%%/*}
GATEWAY="${IPADDR_OUTSIDE}"
fi

return 0 # additional precation against "set -e" in case of future mods of this function
Expand Down Expand Up @@ -167,8 +168,8 @@ autoconfigure() {
! source "/etc/default/netns-${NSNAME}" # for compatibility, see https://github.com/Jamesits/systemd-named-netns/pull/21
! source "/etc/default/netns-${NSTYPE}-${NSNAME}"

if type -t autoconfigure_${NSTYPE}_${INOUT}_${UPDOWN} >/dev/null ; then
autoconfigure_${NSTYPE}_${INOUT}_${UPDOWN} "$@"
if type -t autoconfigure_${NSTYPE}_${UPDOWN}_${INOUT} >/dev/null ; then
autoconfigure_${NSTYPE}_${UPDOWN}_${INOUT} "$@"
echo "Autoconfiguration finished."
else
echo "No configuration required."
Expand Down

0 comments on commit eecc50e

Please sign in to comment.