Statistics
| Branch: | Tag: | Revision:

root / connect-network @ cf51ea5b

History | View | Annotate | Download (2.3 kB)

1
#!/bin/bash
2

    
3
DIR=/var/lib/snf-network
4
NETWORK=$1
5
NODEGROUP=$2
6
MODE=$3
7
LINK=$4
8

    
9
source /etc/default/snf-network
10

    
11
if [ $# -ne 4 ]; then
12
  echo "$0 <network> <nodegroup> <mode> <link>"
13
  exit 1
14
fi
15

    
16
NETWORK_FILE=$DIR/networks/$NETWORK
17
NODEGROUP_FILE=$DIR/nodegoups/$NODEGROUP
18
INTERFACES=$DIR/interfaces/$NETWORK-$NODEGROUP
19

    
20
source $NETWORK_FILE
21
source $NODEGROUP_FILE
22

    
23
if [ $MODE == "routed" ]; then 
24
  VLAN=$LINK
25
  if [ $TYPE == "public" ]; then
26
    APR_IP=$(ipcalc $SUBNET | grep HostMax | awk '{print $2}')
27
    cat > $INTERFACES<<EOF
28
# $VLAN $MODE
29
auto $VLAN
30
iface $VLAN inet manual
31
#    ip-routing-table rt_$NETWORK
32
#    ip-routes $SUBNET
33
#    ip-gateway $GATEWAY
34
#    ip-forwarding 1
35
#    ip-proxy-arp 1
36
#    arp-ip $ARP_IP
37
EOF 
38
    ifup -i $INTERFACES $VLAN
39
    ip link set $VLAN up
40

    
41
    ip rule add iif $VLAN table rt_$NAME
42

    
43
    ip route add $SUBNET dev $VLAN table main 
44

    
45
    ip route add $SUBNET dev $VLAN table rt_$NAME
46
    ip route add default via $GATEWAY dev $VLAN table rt_$NAME
47
    
48
    echo 1 > /proc/sys/net/ipv4/conf/all/forwarding
49

    
50
    arptables -A OUTPUT -o $VLAN --opcode request -j mangle --mangle-ip-s  $ARP_IP 
51
  fi
52
fi
53

    
54

    
55

    
56
if [ $MODE == "bridged" ]; then
57
  BRIDGE=$LINK
58
  echo 1 > /proc/sys/net/ipv4/ip_forward
59
  if [ $TYPE == "public" ]; then
60
    VLAN=$INTERFACE.$PUBLIC_VLAN_ID
61
  elif [ $TYPE == "private" ]; then
62
    VLAN_ID=${PRIVATE_VLAN_IDS%% *}
63
    VLAN_IDS=${PRIVATE_VLAN_IDS#* }
64
    sed -i 's/PRIVATE_VLAN_IDS/ s/=.*/='"VLAN_IDS"'/' $NODEGROUP_FILE
65
    #set -- $PRIVATE_VLAN_IDS
66
    #VLAN=$1
67
    #shift
68
    #VLANS=$@
69
    VLAN=$INTERFACE.$VLAN_ID
70
  fi
71
  cat > $INTERFACES <<EOF
72
# $VLAN $MODE $BRIDGE
73
auto $VLAN
74
iface $VLAN inet manual
75

    
76
auto $BRIDGE
77
iface $BRIDGE inet manual
78
  bridge_ports $VLAN
79
  bridge_stp off
80
  bridge_fd 2
81
EOF
82
  ifup -i $INTERFACES $BRIDGE
83
  ip link set $VLAN up
84
  ip route add $SUBNET dev $BRIDGE table main
85

    
86
  ip route add $SUBNET dev $BRIDGE table rt_$NETWORK
87
  if [ ! -z $GATEWAY ]; then
88
    ip route add default via  dev $BRIDGE table rt_$NETWORK
89
    if [ $TYPE == "private" ]; then 
90
      if [ ! -z $ROUTER ]; then 
91
        if [ $(hostname) == $ROUTER ]; then
92
          NETMASK=$(ipcalc $SUBNET | grep Netmask | awk '{print $4}')
93
          ip addr add $GATEWAY/$NETMASK dev $BRIDGE
94
          iptables -t nat -A POSTROUTING -s $SUBNET \! -d $SUBNET -j MASQUERADE
95
        fi  
96
      fi
97
    fi
98
  fi
99
fi