Set mtu at setup time, remove iptables rule at teardown
[vsys.git] / factory / setup-link
index 52ec656..be8c949 100755 (executable)
@@ -4,11 +4,12 @@ IP=/sbin/ip
 
 SLICE=$1
 SLICEID=`id -u $SLICE`
-read LINKNUM
-LINK=${SLICEID}$LINKNUM
+read LABEL
 read REMOTE
 read KEY
 
+LINK=${LABEL}k$KEY
+
 modprobe ip_gre
 modprobe etun
 
@@ -18,10 +19,10 @@ $IP tunnel add $EGRE  mode gre/eth remote $REMOTE key $KEY
 $IP link set $EGRE up
 
 ### Setup etun
-ETUN0=veth$LINK
+ETUN0=v$LINK
 ETUN1=etun$LINK
 echo $ETUN0,$ETUN1 > /sys/module/etun/parameters/newif
-ifconfig $ETUN0 up
+ifconfig $ETUN0 mtu 1458 up
 ifconfig $ETUN1 up
 
 ### Setup bridge
@@ -31,6 +32,9 @@ brctl addif $BRIDGE $EGRE
 brctl addif $BRIDGE $ETUN1
 ifconfig $BRIDGE up
 
+### Setup iptables so that packets are visible in the vserver
+iptables -t mangle -A FORWARD -o $BRIDGE -j MARK --set-mark $SLICEID
+
 ### Create "grab link" script
 GRAB=/vsys/grab-$ETUN0
 cat > $GRAB <<EOF
@@ -43,4 +47,30 @@ EOF
 chmod +x $GRAB
 echo $SLICE > $GRAB.acl 
 
+### Create "delete link" script
+DELETE=/vsys/delete-$ETUN0
+cat > $DELETE <<EOF
+#!/bin/sh
+
+# Remove iptables rule
+iptables -t mangle -D FORWARD -o $BRIDGE -j MARK --set-mark $SLICEID
+
+# Get rid of etun devices, only need name of one of them
+echo $ETUN1 > /sys/module/etun/parameters/delif
+
+# Get rid of bridge
+ifconfig $BRIDGE down
+brctl delbr $BRIDGE
+
+# Get rid of EGRE tunnel
+ip tunnel del $EGRE
+
+# Clean up files
+rm $GRAB
+rm $DELETE
+
+EOF
+chmod +x $DELETE
+echo $SLICE > $DELETE.acl 
+