Changes for 2.6.32 kernel
[nodemanager-topo.git] / setup-nat
1 #!/bin/sh +x
2
3 SLICE=$1
4 SLICEID=`id -u $SLICE`
5 NODEID=$2
6 KEY=$3
7
8 #
9 # OpenVPN uses addresses in 10.<nodeid>/16 block.  Avoid collisions with
10 # this block.  NAT interface is not advertised and so does not require
11 # unique address throughout the topology.  But the address of each slice's
12 # NAT interface must be unique on a single node.
13 #
14 BASE="10.0.$KEY"
15 EXTIP=$BASE.1
16 EXTNET=$EXTIP/24
17 INTIP=$BASE.2
18 INTNET=$INTIP/24
19 BASENET=$BASE.0/24
20
21 ### Setup etun
22 ETUN0=nat$KEY
23 ETUN1=natx$KEY
24 ip link add name $ETUN0 type veth peer name $ETUN1
25 ifconfig $ETUN1 $EXTNET up
26
27 ### Put a process in the vserver so we can move the interface there
28 su $SLICE -c "sleep 30 &"
29 PID=`su $SLICE -c "pgrep -n sleep"`
30 ip link set $ETUN0 netns $PID
31 naddress --add --nid $SLICEID --ip $INTNET
32 sleep 1
33
34 su $SLICE -c "sudo /sbin/ifconfig $ETUN0 $INTNET up; \
35  sudo /sbin/route add default gw $EXTIP; \
36  sudo /sbin/ifconfig lo 127.0.0.1/8 up"
37
38 ip rule add dev eth0 fwmark $KEY table $KEY
39 ip route add table $KEY default via $INTIP
40 iptables -t mangle -A PREROUTING -i $ETUN1 -j CONNMARK --set-mark $KEY