a little more verbose error message to point out the issue if vsys fails to execute...
[vsys.git] / factory / setup-link
1 #!/bin/sh +x
2
3 SLICE=$1
4 SLICEID=`id -u $SLICE`
5 read INDEX
6 read REMOTE
7 read KEY
8
9 LINK=${KEY}if${INDEX}
10
11 modprobe ip_gre
12
13 ### Setup EGRE tunnel
14 EGRE=d$LINK
15 ip tunnel add $EGRE  mode gre type eth remote $REMOTE key $KEY ttl 64
16 ip link set $EGRE up
17
18 ### Setup etun
19 ETUN0=a$LINK
20 ETUN1=b$LINK
21 ip link add name $ETUN0 type veth peer name $ETUN1
22 ifconfig $ETUN0 mtu 1458 up
23 ifconfig $ETUN1 up
24
25 ### Setup bridge
26 BRIDGE=c$LINK
27 brctl addbr $BRIDGE
28 brctl addif $BRIDGE $EGRE 
29 brctl addif $BRIDGE $ETUN1
30 ifconfig $BRIDGE up
31
32 ### Setup iptables so that packets are visible in the vserver
33 iptables -t mangle -A FORWARD -o $BRIDGE -j MARK --set-mark $SLICEID
34
35 ### Create "grab link" script
36 GRAB=/vsys/local_grab-$ETUN0
37 echo $SLICE > $GRAB.acl 
38 rm -f $GRAB
39 cat > $GRAB <<EOF
40 #!/bin/sh
41
42 read PID
43
44 ip link set $ETUN0 netns \$PID
45 EOF
46 chmod +x $GRAB
47
48 ### Create script for setting link rate
49 BIND=/vsys/local_rate-$ETUN0
50 echo $SLICE > $BIND.acl 
51 rm -f $BIND
52 cat > $BIND <<EOF
53 #!/bin/sh
54
55 read rt
56
57 tc qdisc add dev $EGRE root handle 1: htb default 10
58 tc class add dev $EGRE parent 1: classid 1:10 htb rate \$rt ceil \$rt
59
60 rm -rf $BIND.acl 
61 touch $BIND.acl 
62
63 EOF
64 chmod +x $BIND
65
66 ### Create "delete link" script
67 DELETE=/vsys/local_delete-$ETUN0
68 echo $SLICE > $DELETE.acl 
69 rm -f $DELETE
70 cat > $DELETE <<EOF
71 #!/bin/sh
72
73 read NULL
74
75 # Remove iptables rule
76 iptables -t mangle -D FORWARD -o $BRIDGE -j MARK --set-mark $SLICEID
77
78 # Get rid of etun devices, only need name of one of them
79 ip link delete dev $ETUN1 
80
81 # Get rid of bridge
82 ifconfig $BRIDGE down
83 brctl delbr $BRIDGE
84
85 # Get rid of EGRE tunnel
86 ip tunnel del $EGRE
87
88 # Clean up files
89 rm -f $GRAB $GRAB.acl
90 rm -f $DELETE $DELETE.acl
91 rm -f $BIND $BIND.acl
92 EOF
93 chmod +x $DELETE