4
4
5
5
display_usage () {
6
6
echo " Auto configuration for systemd-named-netns."
7
- echo -e " \nUsage:\n\t$0 network-type ns-name \n"
7
+ echo -e " \nUsage:\n\t$0 network-type ns-name [optional params] \n"
8
8
echo " Note: you may need root privileges for this."
9
9
}
10
10
@@ -27,19 +27,39 @@ autoconfigure_tunnel() {
27
27
}
28
28
29
29
autoconfigure_nat () {
30
+
30
31
# add default route if gateway undefined
31
32
if [ -z " ${GATEWAY} " -a -n " ${IPADDR_OUTSIDE} " ]; then
32
33
/bin/ip route add default via ${IPADDR_OUTSIDE%%/* }
33
34
fi
35
+
34
36
return 0 # additional precation against "set -e" in case of future mods of this function
35
37
}
36
38
39
+ autoconfigure_nat-access () {
40
+
41
+ if [ " ${NAT_ACCEPT_TRAFFIC} " != " 1" ]; then
42
+ return 0
43
+ fi
44
+ if [ " $3 " == " up" ]; then
45
+ # Accept related traffic
46
+ iptables -I INPUT -i ${DEVNAME_OUTSIDE} -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT
47
+
48
+ elif [ " $3 " == " down" ]; then
49
+ iptables -D INPUT -i ${DEVNAME_OUTSIDE} -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT
50
+ fi
51
+
52
+
53
+ return 0 # additional precation against "set -e" in case of future mods of this function
54
+ }
37
55
autoconfigure () {
38
56
local NSTYPE=$1
39
57
local NSNAME=$2
40
58
41
59
echo " Starting autoconfigure for $NSTYPE ${NSNAME} "
42
60
DEVNAME_INSIDE=vn-${NSNAME} 1
61
+ DEVNAME_OUTSIDE=vn-${NSNAME} 0
62
+
43
63
source /etc/default/netns
44
64
! source " /etc/default/netns-${NSNAME} "
45
65
@@ -60,7 +80,7 @@ case "$1" in
60
80
display_usage
61
81
exit 0
62
82
;;
63
- " tunnel" |" bridge" |" nat" )
83
+ " tunnel" |" bridge" |" nat" | " nat-access " )
64
84
autoconfigure " $@ "
65
85
exit 0
66
86
;;
0 commit comments