-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathipv6-conversion-tests.sh
More file actions
119 lines (105 loc) · 3.65 KB
/
Copy pathipv6-conversion-tests.sh
File metadata and controls
119 lines (105 loc) · 3.65 KB
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#!/bin/sh
# tests ipv6 addresses expansion and compression
#### Initial setup
export LC_ALL=C
me=$(basename "$0")
script_dir=$(CDPATH='' cd -- "$(dirname -- "$0")" && pwd -P)
. "$script_dir/shell-ip-tools.sh" || { printf '%s\n' "$me: Error: Can't source '$script_dir/shell-ip-tools.sh'." >&2; exit 1; }
test_exp_comp_ipv6() {
cat <<EOF |
2001:4567:1212:00b2:0000:0000:0000:0000 2001:4567:1212:b2::
2001:4567:1111:56ff:0000:0000:0000:0000 2001:4567:1111:56ff::
2001:4567:1111:56ff:0000:0000:0000:0001 2001:4567:1111:56ff::1
ff02:0000:0000:0000:0000:0000:0000:0001 ff02::1
ff05:0000:0000:0000:0000:0000:0001:0003 ff05::1:3
ff02:0000:0000:0000:0000:0001:ff00:0001 ff02::1:ff00:1
ff02:0000:0000:0000:0000:0001:ffce:4ee3 ff02::1:ffce:4ee3
fe80:0000:0000:0000:021b:2bff:fece:4ee3 fe80::21b:2bff:fece:4ee3
fd0e:2146:5cf5:4560:0000:0000:0000:0001 fd0e:2146:5cf5:4560::1
2001:0db8:0000:0000:0000:0000:0002:0001 2001:db8::2:1
2001:0db8:0000:0001:0001:0001:0001:0001 2001:db8:0:1:1:1:1:1
2001:0db8:0000:0000:0001:0000:0000:0001 2001:db8::1:0:0:1
2001:0db8:0000:0000:0000:0000:0000:0001 2001:db8::1
0000:0000:0000:0000:0000:0000:0000:0000 ::
0000:0000:0000:0000:0000:0000:0000:0001 ::1
0001:0000:0000:0000:0000:0000:0000:0000 1::
0000:0001:0000:0000:0000:0000:0000:0000 0:1::
0000:0000:0001:0000:0000:0000:0000:0000 0:0:1::
0000:0000:0000:0001:0000:0000:0000:0000 0:0:0:1::
0000:0000:0000:0000:0001:0000:0000:0000 ::1:0:0:0
0000:0000:0000:0000:0000:0001:0000:0000 ::1:0:0
0000:0000:0000:0000:0000:0000:0001:0000 ::1:0
2001:067c:02e8:0025::c100:0b18 2001:67c:2e8:25::c100:b18
2001:067c:02e8:0025:0000:0000:c100:0b18 2001:67c:2e8:25::c100:b18
0000:0000:0000:0000:0000:0000:0001:0000 ::1:0
0000:0000:0000:0000:0000:0001:0000:0000 ::1:0:0
0000:0000:0000:0000:0001:0000:0000:0000 ::1:0:0:0
0000:0000:0000:0001:0000:0000:0000:0000 0:0:0:1::
0000:0000:0001:0000:0000:0000:0000:0000 0:0:1::
0001:0000:0000:0000:0000:0000:0000:0001 1::1
0001:0000:0000:0000:0000:0000:0001:0000 1::1:0
0001:0001:0000:0000:0000:0000:0000:0000 1:1::
0000:0000:0001:0000:0001:0000:0000:0000 0:0:1:0:1::
0000:0001:0000:0001:0000:0000:0000:0000 0:1:0:1::
0001:0000:0000:0001:0000:0000:0000:0000 1:0:0:1::
0001:0000:0000:0001:0000:0001:0000:0000 1::1:0:1:0:0
:: ::
::1 ::1
1:: 1::
::1:0 ::1:0
::1:0:0 ::1:0:0
0:0:0:0:0:1:: ::1:0:0
::1:0:0:0 ::1:0:0:0
::1:0:0:0:0 0:0:0:1::
0:0:0:1:: 0:0:0:1::
0:0:1:: 0:0:1::
0:1:: 0:1::
1::1 1::1
1::1:0 1::1:0
1:1:: 1:1::
0:0:1:0:1:: 0:0:1:0:1::
0:1:0:1:: 0:1:0:1::
1:0:0:1:: 1:0:0:1::
1::1:0:1:0:0: 1::1:0:1:0:0
2001:4567:1212:b2:: 2001:4567:1212:b2::
2001:4567:1111:56ff:: 2001:4567:1111:56ff::
2001:4567:1111:56ff::1 2001:4567:1111:56ff::1
ff02::1 ff02::1
ff05::1:3 ff05::1:3
ff02::1:ff00:1 ff02::1:ff00:1
ff02::1:ffce:4ee3 ff02::1:ffce:4ee3
fd0e:2146:5cf5:4560::1 fd0e:2146:5cf5:4560::1
2001:db8::2:1 2001:db8::2:1
2001:db8:0:1:1:1:1:1 2001:db8:0:1:1:1:1:1
2001:db8::1:0:0:1 2001:db8::1:0:0:1
2001:db8::1 2001:db8::1
2001:67c:2e8:25::c100:b18 2001:67c:2e8:25::c100:b18
EOF
# remove extra spaces and tabs
awk '{$1=$1};1' |
{
test_status=0
tests_done=0
while read -r line; do
in_ip="${line%% *}"
out_ip="${line#* }"
if [ -n "$in_ip" ] && [ -n "$out_ip" ]; then
printf %s "."
# convert to hex and back, compare result
result="$(printf '%s\n' "$in_ip" | aggregate_subnets inet6)"
if [ "${result%/128}" != "$out_ip" ]; then
printf '%s\n' "Error with input '$in_ip'. Expected '$out_ip', got '${result%/128}'." >&2
test_status=1
fi
tests_done=$((tests_done+1))
fi
done
printf '\n%s\n' "Tests done: $tests_done"
exit $test_status
}
return $?
}
test_exp_comp_ipv6
status=$?
[ "$status" = 0 ] && noprob=" No problems detected."
printf '%s\n' "Test status: $status.$noprob"