#!/bin/sh +x IP=/sbin/ip SLICE=$1 SLICEID=`id -u $SLICE` read LABEL read REMOTE read KEY LINK=${LABEL}k$KEY 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 ### Setup etun ETUN0=v$LINK ETUN1=etun$LINK echo $ETUN0,$ETUN1 > /sys/module/etun/parameters/newif ifconfig $ETUN0 mtu 1458 up ifconfig $ETUN1 up ### Setup bridge BRIDGE=br$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 echo $SLICE > $GRAB.acl rm -f $GRAB cat > $GRAB < /sys/class/net/$ETUN0/new_ns_pid EOF chmod +x $GRAB ### Create "delete link" script DELETE=/vsys/delete-$ETUN0 echo $SLICE > $DELETE.acl rm -f $DELETE cat > $DELETE < /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 -f $GRAB $GRAB.acl rm -f $DELETE $DELETE.acl EOF chmod +x $DELETE