ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/gvpe/doc/complex-example/if-up
Revision: 1.2
Committed: Thu Oct 16 21:12:43 2003 UTC (20 years, 8 months ago) by pcg
Branch: MAIN
CVS Tags: rel-1_9, rel-1_8, rel-2_01, poll-based-iom, rel-3_0, VPE_1_2, rel-2_2, rel-2_0, VPE_1_4, VPE_1_6, rel-1_7, VPE-1_6_1, rel-2_21, rel-2_22, rel-2_25, HEAD
Changes since 1.1: +21 -9 lines
Log Message:
*** empty log message ***

File Contents

# User Rev Content
1 pcg 1.1 #!/bin/bash
2    
3     # Some environment variables will be set:
4     #
5     # CONFBASE=/etc/vpe # the configuration directory prefix
6     # IFNAME=vpn0 # the network interface (ifname)
7     # MAC=fe:fd:80:00:00:01 # the mac-address to use for the interface
8     # NODENAME=cerebro # the selected nodename (-n switch)
9     # NODEID=1 # the numerical node id
10     # MTU=1436 # the tunnel packet overhead (set mtu to 1500-$OVERHEAD)
11    
12     # this if-up script is rather full-featured, and is used to
13     # generate a fully-routed (no arp traffic) vpn. the main portion
14     # consists of "ipn" calls (see below).
15    
16     # some hosts require additional specific configuration, this is handled
17     # using if statements near the end of the script.
18    
19     # with the --fw switch, outputs mac/net pairs for your firewall use:
20     # if-up --fw | while read mac net; do
21     # iptables -t filter -A INPUT -i vpn0 -p all -m mac --mac-source \! $mac -s $net -j DROP
22     # done
23    
24     ipn() {
25     local id="$1"; shift
26     local mac=fe:fd:80:00:00:$(printf "%02x" $id)
27     if [ -n "$FW" ]; then
28     for net in "$@"; do
29     echo "$mac $net"
30     done
31     else
32     local ip="$1"; shift
33     if [ "$id" == $NODEID ]; then
34     [ -n "$ADDR_ONLY" ] && ip addr add $ip broadcast 10.255.255.255 dev $IFNAME
35     elif [ -z "$ADDR_ONLY" ]; then
36     ip neighbour add $ip lladdr $mac nud permanent dev $IFNAME
37     for route in "$@"; do
38     ip route add $route via $ip dev vpn0
39     done
40     fi
41     fi
42     }
43    
44     ipns() {
45     # this contains the generic routing information for the vpn
46     # each call to ipn has the following parameters:
47     # ipn <node-id> <gateway-ip> [<route> ...]
48     # the second line (ipn 2) means:
49     # the second node (doom in the config file) has the ip address 10.0.0.5,
50     # which is the gateway for the 10.0/28 network and three additional ip
51     # addresses
52    
53     ipn 1 10.0.0.20
54 pcg 1.2 ipn 2 10.0.0.5 10.0.0.0/28 #200.100.162.92 200.100.162.93 100.99.218.222
55 pcg 1.1 ipn 3 10.0.0.17
56     ipn 4 10.0.0.18
57 pcg 1.2 ipn 5 10.0.0.19 10.3.0.0/16
58     ipn 6 10.0.0.21 10.0.2.0/26 #200.100.162.17
59     ipn 7 10.0.0.22 10.1.2.0/24 # wappla, off
60     ipn 8 10.0.0.23 # stefan, off
61 pcg 1.1 ipn 9 10.0.0.24 10.13.0.0/16
62     ipn 10 10.0.0.25
63     ipn 11 10.0.0.26
64     ipn 12 10.0.0.27 10.0.2.64/26
65     ipn 13 10.0.0.28 10.0.3.0/24
66 pcg 1.2 ipn 14 10.0.0.29 10.1.1.0/24 # fwkw, off
67 pcg 1.1 # mind the gateway ip gap
68     ipn 15 10.9.0.30 10.0.4.0/24
69     ipn 16 10.9.0.31
70 pcg 1.2 ipn 17 10.9.0.32 10.42.0.0/16
71     ipn 18 10.9.0.33
72     ipn 19 10.9.0.34
73     #ipn 20 10.9.0.35
74 pcg 1.1 }
75    
76     if [ "$1" == "--fw" ]; then
77     FW=1
78    
79     ipns
80     else
81     exec >/var/log/vpe.if-up 2>&1
82     set -x
83    
84     [ $NODENAME = "ruth" ] && ip link set $IFNAME down # hack
85    
86     # first set the link up and initialize the interface ip
87     # address.
88 pcg 1.2 ip link set $IFNAME address $MAC
89     ip link set $IFNAME mtu $MTU up
90 pcg 1.1 ADDR_ONLY=1 ipns # set addr only
91    
92     # now initialize the main vpn routes (10.0/8)
93     # the second route is a hack to to reach some funnily-connected
94     # machines.
95     ip route add 10.0.0.0/8 dev $IFNAME
96     ip route add 10.0.0.0/27 dev $IFNAME
97    
98     ipns # set the interface routes
99    
100     # now for something completely different, ehr, something not
101     # easily doable with ipn, namely some extra specific highly complicated
102     # and non-regular setups for some machines.
103     if [ $NODENAME = doom ]; then
104     ip addr add 200.100.162.92 dev $IFNAME
105     ip route add 200.100.0.0/16 via 10.0.0.17 dev $IFNAME
106     ip route flush table 101
107     ip route add table 101 default src 200.100.162.92 via 10.0.0.17 dev $IFNAME
108    
109     ip addr add 100.99.218.222 dev $IFNAME
110     ip route add 100.99.218.192/27 via 10.0.0.19 dev $IFNAME
111     ip route flush table 103
112     ip route add table 103 default src 100.99.218.222 via 10.0.0.19
113    
114     elif [ $NODENAME = marco ]; then
115     ip addr add 200.100.162.17 dev $IFNAME
116 pcg 1.2
117     for addr in 79 89 90 91 92 93 94 95; do
118     ip route add 200.100.162.$addr dev ppp0
119     done
120 pcg 1.1 ip route add 200.100.76.0/23 dev ppp0
121     ip route add src 200.100.162.17 200.100.0.0/16 via 10.0.0.17 dev $IFNAME
122 pcg 1.2
123     elif [ $NODENAME = ruth ]; then
124     ip route add 200.100.162.17 via 10.0.0.21 dev vpn0
125     ip route add 200.100.162.92 via 10.0.0.5 dev vpn0
126     ip route add 200.100.162.93 via 10.0.0.5 dev vpn0
127 pcg 1.1
128     fi
129    
130     # and this is the second part of the 10.0/27 hack. don't ask.
131     [ $NODENAME != fwkw ] && ip route add 10.0.0.0/24 via 10.0.0.29 dev $IFNAME
132     fi
133    
134