blob: 451cdda20d7779b03db61090c605c7ccb6be1559 [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
36 add_port_fwd_rule 80 $XOS 80
37 fi
38 add_rule "filter" "FORWARD" "-p tcp --dport 80 -j ACCEPT"
39fi
40