blob: 1c947f96d82557e61e950affb2729913c2dc7146 [file] [log] [blame]
Zack Williams3db3b962016-03-01 21:59:25 -07001#!/bin/sh
2
3SHELL="/bin/bash"
4
5NIC=$( route|grep default|awk '{print $NF}' )
6PORTAL=$( dig +short portal.opencloud.us | tail -1 )
7
8NAME="${1}"
9OP="${2}"
10SUBOP="${3}"
11ARGS="${4}"
12
13add_rule() {
14 CHAIN=$1
15 ARGS=$2
16 iptables -C $CHAIN $ARGS
17 if [ "$?" -ne 0 ]
18 then
19 iptables -I $CHAIN 1 $ARGS
20 fi
21}
22
23add_local_access_rules() {
24 SUBNET=$( ip addr show $NIC|grep "inet "|awk '{print $2}' )
25 PRIVATENET=$( ip addr show virbr0|grep "inet "|awk '{print $2}' )
26 add_rule "FORWARD" "-s $SUBNET -j ACCEPT"
27 # Don't NAT traffic from service VMs destined to the local subnet
28 add_rule "POSTROUTING" "-t nat -s $PRIVATENET -d $SUBNET -j RETURN"
29}
30
31add_portal_access_rules() {
32 add_rule "FORWARD" "-s $PORTAL -j ACCEPT"
33}
34
35add_web_access_rules() {
36 add_rule "FORWARD" "-p tcp --dport 80 -j ACCEPT"
37}
38
39if [ "$OP" = "start" ]
40then
41 add_local_access_rules
42 add_portal_access_rules
43 add_web_access_rules
44fi