Remove .acl files
[vsys.git] / factory / setup-link
1 #!/bin/sh +x
2
3 IP=/sbin/ip
4
5 SLICE=$1
6 SLICEID=`id -u $SLICE`
7 read LABEL
8 read REMOTE
9 read KEY
10
11 LINK=${LABEL}k$KEY
12
13 modprobe ip_gre
14 modprobe etun
15
16 ### Setup EGRE tunnel
17 EGRE=egre$LINK
18 $IP tunnel add $EGRE  mode gre/eth remote $REMOTE key $KEY
19 $IP link set $EGRE up
20
21 ### Setup etun
22 ETUN0=v$LINK
23 ETUN1=etun$LINK
24 echo $ETUN0,$ETUN1 > /sys/module/etun/parameters/newif
25 ifconfig $ETUN0 mtu 1458 up
26 ifconfig $ETUN1 up
27
28 ### Setup bridge
29 BRIDGE=br$LINK
30 brctl addbr $BRIDGE
31 brctl addif $BRIDGE $EGRE 
32 brctl addif $BRIDGE $ETUN1
33 ifconfig $BRIDGE up
34
35 ### Setup iptables so that packets are visible in the vserver
36 iptables -t mangle -A FORWARD -o $BRIDGE -j MARK --set-mark $SLICEID
37
38 ### Create "grab link" script
39 GRAB=/vsys/grab-$ETUN0
40 rm -f $GRAB $GRAB.acl
41 cat > $GRAB <<EOF
42 #!/bin/sh
43
44 read PID
45
46 chcontext --ctx 1 -- echo \$PID > /sys/class/net/$ETUN0/new_ns_pid 
47 EOF
48 chmod +x $GRAB
49 sleep 1
50 echo $SLICE > $GRAB.acl 
51
52 ### Create "delete link" script
53 DELETE=/vsys/delete-$ETUN0
54 rm -f $DELETE $DELETE.acl
55 cat > $DELETE <<EOF
56 #!/bin/sh
57
58 read NULL
59
60 # Remove iptables rule
61 iptables -t mangle -D FORWARD -o $BRIDGE -j MARK --set-mark $SLICEID
62
63 # Get rid of etun devices, only need name of one of them
64 echo $ETUN1 > /sys/module/etun/parameters/delif
65
66 # Get rid of bridge
67 ifconfig $BRIDGE down
68 brctl delbr $BRIDGE
69
70 # Get rid of EGRE tunnel
71 ip tunnel del $EGRE
72
73 # Clean up files
74 rm -f $GRAB $GRAB.acl
75 rm -f $DELETE $DELETE.acl
76
77 EOF
78 chmod +x $DELETE
79 sleep 1
80 echo $SLICE > $DELETE.acl 
81
82