blob: 824816f0d704705eb0195a9c830f37aef0afd325 [file] [log] [blame]
Andy Bavier9d7c09e2016-07-19 20:37:58 -04001#!/bin/sh
2
3SHELL="/bin/bash"
4
5NIC=$( route|grep default|awk '{print $NF}' )
6
7NAME="${1}"
8OP="${2}"
9SUBOP="${3}"
10ARGS="${4}"
11
12add_rule() {
13 TABLE=$1
14 CHAIN=$2
15 ARGS=$3
16 iptables -t $TABLE -C $CHAIN $ARGS
17 if [ "$?" -ne 0 ]
18 then
19 iptables -t $TABLE -I $CHAIN 1 $ARGS
20 fi
21}
22
23add_port_fwd_rule() {
24 DPORT=$1
25 VMIP=$2
26 TOPORT=$3
27
28 add_rule "nat" "PREROUTING" "-p tcp -i $NIC --dport $DPORT -j DNAT --to-destination $VMIP:$TOPORT"
29}
30
31if [ "$OP" = "start" ]
32then
33 XOS=$( getent hosts xos | awk '{print $1}' )
34 if [ -n "$XOS" ]
35 then
Andy Baviera29aa032016-07-25 15:41:51 -040036 add_port_fwd_rule 8888 $XOS 80
Andy Bavier9d7c09e2016-07-19 20:37:58 -040037 fi
38 add_rule "filter" "FORWARD" "-p tcp --dport 80 -j ACCEPT"
39fi
40