[package] update miredo to 1.2.3, packaged miredo-privproc, add client-hook script...
[openwrt/svn-archive/archive.git] / ipv6 / miredo / files / client-hook
1 #! /bin/sh
2 #
3 # Miredo client hook script for Linux/iproute2
4 # Copyright © 2007 Rémi Denis-Courmont.
5 # Distributed under the terms of the GNU General Public License version 2.
6
7 # Linux iproute2 path:
8 IP="/usr/sbin/ip"
9
10 # Linux default route default metric is 1024
11 # (we put 1029 so that Teredo is used as a last resort):
12 METRIC=1029
13
14 # Linux routing table ID
15 # (possible values: 1-252 from /etc/iproute/rt_tables):
16 TABLE="teredo"
17
18 # Linux routing rule priority
19 # (possible values: 1-32765, lowest number is highest priority):
20 PRIO=32765
21
22 # MTU for the tunnel interface
23 # (default: specified by the Teredo server, or 1280)
24 #MTU=1400
25
26 if ! test -x "$IP"; then
27 echo "$0: iproute2 is required! Please install it." >&2
28 exit 1
29 fi
30
31 # Nothing to do with destroy event
32 if test "$STATE" = "destroy"; then exit 0; fi
33
34 # If the source routing table is not configured, ignore it.
35 if ! "$IP" route show table "$TABLE" >/dev/null 2>&1; then
36 unset TABLE
37 else
38 if test "$OLD_ADDRESS"; then
39 "$IP" -6 rule del from "$OLD_ADDRESS" \
40 prio "$PRIO" table "$TABLE" 2>/dev/null
41 fi
42 "$IP" -6 route flush table "$TABLE" 2>/dev/null
43 fi
44
45 "$IP" -6 route flush dev "$IFACE" 2>/dev/null
46 "$IP" -6 address flush dev "$IFACE" 2>/dev/null
47
48 "$IP" -6 link set dev "$IFACE" "$STATE"
49 if test "$MTU"; then
50 "$IP" link set dev "$IFACE" mtu "$MTU"
51 fi
52
53 case "$STATE" in
54 up)
55 "$IP" -6 address add "${LLADDRESS}/64" dev "$IFACE"
56 "$IP" -6 address add "${ADDRESS}/32" dev "$IFACE"
57 "$IP" -6 route add default dev "$IFACE" metric "$METRIC"
58
59 if test "$TABLE"; then
60 "$IP" -6 route add default dev "$IFACE" table "$TABLE"
61 "$IP" -6 rule add from "$ADDRESS" \
62 prio "$PRIO" table "$TABLE"
63 fi
64 esac
65
66 # This should be required when changing policy routing rules, but it
67 # seems to confuse certain kernels into removing our default route!
68 #"$IP" -6 route flush cache 2>/dev/null
69
70 exit 0