1 |
#!/bin/bash |
2 |
|
3 |
# Sample if-up |
4 |
|
5 |
# Some environment variables will be set: |
6 |
# |
7 |
# CONFBASE=/etc/vpe # the configuration directory prefix |
8 |
# IFNAME=vpn0 # the network interface (ifname) |
9 |
# MAC=fe:fd:80:00:00:01 # the mac-address to use for the interface |
10 |
# NODENAME=cerebro # the selected nodename (-n switch) |
11 |
# NODEID=1 # the numerical node id |
12 |
# MTU=1436 # the tunnel packet overhead (set mtu to 1500-$OVERHEAD) |
13 |
|
14 |
# with the --fw switch, outputs mac/net pairs for your firewall use: |
15 |
# if-up --fw | while read mac net; do |
16 |
# iptables -t filter -A INPUT -i vpn0 -p all -m mac --mac-source \! $mac -s $net -j DROP |
17 |
# done |
18 |
|
19 |
ipn() { |
20 |
local id="$1"; shift |
21 |
local mac=fe:fd:80:00:00:$(printf "%02x" $id) |
22 |
if [ -n "$FW" ]; then |
23 |
for net in "$@"; do |
24 |
echo "$mac $net" |
25 |
done |
26 |
else |
27 |
local ip="$1"; shift |
28 |
if [ "$id" == $NODEID ]; then |
29 |
[ -n "$ADDR_ONLY" ] && ip addr add $ip broadcast 10.255.255.255 dev $IFNAME |
30 |
elif [ -z "$ADDR_ONLY" ]; then |
31 |
ip neighbour add $ip lladdr $mac nud permanent dev $IFNAME |
32 |
for route in "$@"; do |
33 |
ip route add $route via $ip dev vpn0 |
34 |
done |
35 |
fi |
36 |
fi |
37 |
} |
38 |
|
39 |
ipns() { |
40 |
ipn 1 10.0.0.20 |
41 |
ipn 2 10.0.0.5 10.0.0.0/28 129.13.162.92 129.13.162.93 213.69.218.222 |
42 |
ipn 3 10.0.0.17 |
43 |
ipn 4 10.0.0.18 |
44 |
ipn 5 10.0.0.19 |
45 |
ipn 6 10.0.0.21 10.0.2.0/26 129.13.162.17 |
46 |
ipn 7 10.0.0.22 10.1.2.0/24 |
47 |
ipn 8 10.0.0.23 |
48 |
ipn 9 10.0.0.24 10.13.0.0/16 |
49 |
ipn 10 10.0.0.25 |
50 |
ipn 11 10.0.0.26 |
51 |
ipn 12 10.0.0.27 10.0.2.64/26 |
52 |
ipn 13 10.0.0.28 |
53 |
ipn 14 10.0.0.29 10.1.1.0/24 |
54 |
} |
55 |
|
56 |
if [ "$1" == "--fw" ]; then |
57 |
FW=1 |
58 |
|
59 |
ipns |
60 |
else |
61 |
exec >/var/log/vpe.if-up 2>&1 |
62 |
set -x |
63 |
|
64 |
[ $NODENAME = "ruth" ] && ip link set $IFNAME down # hack |
65 |
|
66 |
ip link set $IFNAME address $MAC mtu $MTU up |
67 |
ADDR_ONLY=1 ipns # set addr only |
68 |
|
69 |
ip route add 10.0.0.0/8 dev $IFNAME |
70 |
ip route add 10.0.0.0/27 dev $IFNAME |
71 |
|
72 |
ipns # set routes |
73 |
|
74 |
echo 0 >/proc/sys/net/ipv4/conf/vpn0/proxy_arp |
75 |
|
76 |
if [ $NODENAME = doom ]; then |
77 |
ip addr add 129.13.162.92 dev $IFNAME |
78 |
ip route add 129.13.0.0/16 via 10.0.0.17 dev $IFNAME |
79 |
ip route flush table 101 |
80 |
ip route add table 101 default src 129.13.162.92 via 10.0.0.17 |
81 |
|
82 |
ip addr add 213.69.218.222 dev $IFNAME |
83 |
ip route add 213.69.218.192/27 via 10.0.0.19 dev $IFNAME |
84 |
ip route flush table 103 |
85 |
ip route add table 103 default src 213.69.218.222 via 10.0.0.19 |
86 |
|
87 |
elif [ $NODENAME = marco ]; then |
88 |
ip addr add 129.13.162.17 dev $IFNAME |
89 |
ip route add 129.13.162.95 dev ppp0 |
90 |
ip route add 129.13.76.0/23 dev ppp0 |
91 |
ip route add src 129.13.162.17 129.13.0.0/16 via 10.0.0.17 dev $IFNAME |
92 |
|
93 |
fi |
94 |
|
95 |
[ $NODENAME != fwkw ] && ip route add 10.0.0.0/24 via 10.0.0.29 dev $IFNAME |
96 |
fi |
97 |
|
98 |
|