blob: 464be32f027247909a12efe36899512fe0d86346 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
|
#!/bin/bash
set -e
LOCAL=2001:db8:dead::
EXTERNAL=2001:db8:beef::
EXTERNAL_NET=${EXTERNAL}/48
EXTERNAL_NH=${LOCAL}beef
LEARN=2001:db8:feed::
LEARN_NET=${LEARN}/48
LEARN_NH=${LOCAL}feed
IFACE=bird-test-dummy
IFACE_EXISTS=false
BIRD_RUNNING=false
D=$(mktemp -d)
pushd ${D} >/dev/null
stop_bird() {
birdc -l down >/dev/null
sleep 1
grep -q "<FATAL> Shutdown completed" bird.log
[ ! -e bird.pid ]
[ ! -e bird.ctl ]
}
cleanup() {
if ${BIRD_RUNNING}; then
stop_bird
if [ -e bird.pid ]; then
kill -9 $(<bird.pid)
fi
fi
if ${IFACE_EXISTS}; then
ip link del ${IFACE}
fi
popd > /dev/null
rm -rf ${D}
}
failed() {
cleanup
exit 1
}
trap failed ERR
trap failed INT
trap failed HUP
ip link add ${IFACE} type dummy
IFACE_EXISTS=true
ip link set ${IFACE} up
ip -6 addr add ${LOCAL}/64 dev bird-test-dummy
ip -6 route add ${LEARN_NET} via ${LEARN_NH}
cat >bird.conf <<EOF
log "bird.log" all;
protocol device {}
protocol kernel {
ipv6 { import all; export all; };
learn;
}
protocol static {
ipv6;
route ${EXTERNAL_NET} via ${EXTERNAL_NH};
}
EOF
bird -l -P bird.pid
if [ ! -S bird.ctl ] || [ ! -f bird.pid ] || [ ! -f bird.log ]; then
failed
fi
BIRD_RUNNING=true
ROUTE_INSERTED=false
for _ in $(seq 10); do
if ip -6 route show ${EXTERNAL_NET} | egrep -q "${EXTERNAL_NET} via ${EXTERNAL_NH} dev ${IFACE} proto bird metric [0-9]+ pref medium"; then
ROUTE_INSERTED=true
break
fi
sleep 1
done
$ROUTE_INSERTED || failed
if birdc -l show route "${LEARN_NET}" | egrep -q "Network not found"; then
failed
fi
cleanup
exit 0
|