#!/bin/sh +x IP=/sbin/ip SLICE=$1 SLICEID=`id -u $SLICE` NODEID=$2 REMOTE=$3 KEY=$4 RATE=$5 VIRTIP=$6 VIRTNET=$7 SUBNET=`expr match "$VIRTNET" '.*\(/[0-9]*\)'` LINK=${KEY}x${NODEID} modprobe ip_gre ### Setup EGRE tunnel 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=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=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 ### Put a process in the vserver so we can move the interface there su $SLICE -c "sleep 30 &" PID=`su $SLICE -c "pgrep -n sleep"` $IP link set $ETUN0 netns $PID naddress --add --nid $SLICEID --ip ${VIRTIP}${SUBNET} su $SLICE -c "sudo /sbin/ifconfig $ETUN0 ${VIRTIP}${SUBNET} up; sudo /sbin/route add -net $VIRTNET dev $ETUN0" ### Set rate tc qdisc add dev $EGRE root handle 1: htb default 10 tc class add dev $EGRE parent 1: classid 1:10 htb rate $RATE ceil $RATE