Add backslash
[vsys.git] / factory / setup-link
index 52ec656..cc800ce 100755 (executable)
@@ -1,46 +1,93 @@
 #!/bin/sh +x
 
-IP=/sbin/ip
-
 SLICE=$1
 SLICEID=`id -u $SLICE`
-read LINKNUM
-LINK=${SLICEID}$LINKNUM
+read INDEX
 read REMOTE
 read KEY
 
+LINK=${KEY}if${INDEX}
+
 modprobe ip_gre
-modprobe etun
 
 ### Setup EGRE tunnel
-EGRE=egre$LINK
-$IP tunnel add $EGRE  mode gre/eth remote $REMOTE key $KEY
-$IP link set $EGRE up
+EGRE=d$LINK
+ip tunnel add $EGRE  mode gre type eth remote $REMOTE key $KEY ttl 64
+ip link set $EGRE up
 
 ### Setup etun
-ETUN0=veth$LINK
-ETUN1=etun$LINK
-echo $ETUN0,$ETUN1 > /sys/module/etun/parameters/newif
-ifconfig $ETUN0 up
+ETUN0=a$LINK
+ETUN1=b$LINK
+ip link add name $ETUN0 type veth peer name $ETUN1
+ifconfig $ETUN0 mtu 1458 up
 ifconfig $ETUN1 up
 
 ### Setup bridge
-BRIDGE=br$LINK
+BRIDGE=c$LINK
 brctl addbr $BRIDGE
 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
+GRAB=/vsys/local_grab-$ETUN0
+echo $SLICE > $GRAB.acl 
+rm -f $GRAB
 cat > $GRAB <<EOF
 #!/bin/sh
 
 read PID
 
-chcontext --ctx 1 -- echo \$PID > /sys/class/net/$ETUN0/new_ns_pid 
+ip link set $ETUN0 netns \$PID
 EOF
 chmod +x $GRAB
-echo $SLICE > $GRAB.acl 
 
+### Create script for setting link rate
+BIND=/vsys/local_rate-$ETUN0
+echo $SLICE > $BIND.acl 
+rm -f $BIND
+cat > $BIND <<EOF
+#!/bin/sh
+
+read rt
+
+tc qdisc add dev $EGRE root handle 1: htb default 10
+tc class add dev $EGRE parent 1: classid 1:10 htb rate \$rt ceil \$rt
 
+rm -rf $BIND.acl 
+touch $BIND.acl 
+
+EOF
+chmod +x $BIND
+
+### Create "delete link" script
+DELETE=/vsys/local_delete-$ETUN0
+echo $SLICE > $DELETE.acl 
+rm -f $DELETE
+cat > $DELETE <<EOF
+#!/bin/sh
+
+read NULL
+
+# 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
+ip link delete dev $ETUN1 
+
+# Get rid of bridge
+ifconfig $BRIDGE down
+brctl delbr $BRIDGE
+
+# Get rid of EGRE tunnel
+ip tunnel del $EGRE
+
+# Clean up files
+rm -f $GRAB $GRAB.acl
+rm -f $DELETE $DELETE.acl
+rm -f $BIND $BIND.acl
+EOF
+chmod +x $DELETE