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