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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
|
// SPDX-License-Identifier: GPL-2.0+
/*
* Copyright (C) 2013 Red Hat, Inc.
*/
#include "nm-default.h"
#include <arpa/inet.h>
#include "dnsmasq/nm-dnsmasq-utils.h"
#include "nm-test-utils-core.h"
static void
test_address_ranges (void)
{
#define _test_address_range(addr, plen, expected_first, expected_last) \
G_STMT_START { \
char *_error_desc = NULL; \
char _first[INET_ADDRSTRLEN]; \
char _last[INET_ADDRSTRLEN]; \
\
if (!nm_dnsmasq_utils_get_range (nmtst_platform_ip4_address ((addr""), NULL, (plen)), \
_first, _last, &_error_desc)) \
g_assert_not_reached (); \
g_assert (!_error_desc); \
g_assert_cmpstr (_first, ==, (expected_first"")); \
g_assert_cmpstr (_last, ==, (expected_last"")); \
g_assert_cmpint ((ntohl (nmtst_inet4_from_string (_last)) - ntohl (nmtst_inet4_from_string (_first))), <=, 244); \
} G_STMT_END
#define _test_address_range_fail(addr, plen) \
G_STMT_START { \
char *_error_desc = NULL; \
char _first[INET_ADDRSTRLEN]; \
char _last[INET_ADDRSTRLEN]; \
\
if (nm_dnsmasq_utils_get_range (nmtst_platform_ip4_address ((addr""), NULL, (plen)), \
_first, _last, &_error_desc)) \
g_assert_not_reached (); \
g_assert (_error_desc); \
g_free (_error_desc); \
} G_STMT_END
_test_address_range_fail ("1.2.3.1", 31);
_test_address_range ("0.0.0.0", 30, "0.0.0.2", "0.0.0.2");
_test_address_range ("0.0.0.1", 30, "0.0.0.2", "0.0.0.2");
_test_address_range ("0.0.0.2", 30, "0.0.0.1", "0.0.0.1");
_test_address_range ("0.0.0.3", 30, "0.0.0.1", "0.0.0.1");
_test_address_range ("1.2.3.0", 30, "1.2.3.2", "1.2.3.2");
_test_address_range ("1.2.3.1", 30, "1.2.3.2", "1.2.3.2");
_test_address_range ("1.2.3.2", 30, "1.2.3.1", "1.2.3.1");
_test_address_range ("1.2.3.3", 30, "1.2.3.1", "1.2.3.1");
_test_address_range ("1.2.3.4", 30, "1.2.3.6", "1.2.3.6");
_test_address_range ("1.2.3.5", 30, "1.2.3.6", "1.2.3.6");
_test_address_range ("1.2.3.6", 30, "1.2.3.5", "1.2.3.5");
_test_address_range ("1.2.3.7", 30, "1.2.3.5", "1.2.3.5");
_test_address_range ("1.2.3.8", 30, "1.2.3.10", "1.2.3.10");
_test_address_range ("1.2.3.9", 30, "1.2.3.10", "1.2.3.10");
_test_address_range ("255.255.255.0", 30, "255.255.255.2", "255.255.255.2");
_test_address_range ("255.255.255.1", 30, "255.255.255.2", "255.255.255.2");
_test_address_range ("255.255.255.2", 30, "255.255.255.1", "255.255.255.1");
_test_address_range ("255.255.255.3", 30, "255.255.255.1", "255.255.255.1");
_test_address_range ("255.255.255.248", 30, "255.255.255.250", "255.255.255.250");
_test_address_range ("255.255.255.249", 30, "255.255.255.250", "255.255.255.250");
_test_address_range ("255.255.255.250", 30, "255.255.255.249", "255.255.255.249");
_test_address_range ("255.255.255.251", 30, "255.255.255.249", "255.255.255.249");
_test_address_range ("255.255.255.252", 30, "255.255.255.254", "255.255.255.254");
_test_address_range ("255.255.255.253", 30, "255.255.255.254", "255.255.255.254");
_test_address_range ("255.255.255.254", 30, "255.255.255.253", "255.255.255.253");
_test_address_range ("255.255.255.255", 30, "255.255.255.253", "255.255.255.253");
_test_address_range ("0.0.0.0", 29, "0.0.0.2", "0.0.0.6");
_test_address_range ("0.0.0.1", 29, "0.0.0.2", "0.0.0.6");
_test_address_range ("0.0.0.2", 29, "0.0.0.3", "0.0.0.6");
_test_address_range ("0.0.0.3", 29, "0.0.0.4", "0.0.0.6");
_test_address_range ("0.0.0.4", 29, "0.0.0.1", "0.0.0.3");
_test_address_range ("0.0.0.5", 29, "0.0.0.1", "0.0.0.4");
_test_address_range ("0.0.0.6", 29, "0.0.0.1", "0.0.0.5");
_test_address_range ("0.0.0.7", 29, "0.0.0.1", "0.0.0.5");
_test_address_range ("0.0.0.8", 29, "0.0.0.10", "0.0.0.14");
_test_address_range ("0.0.0.9", 29, "0.0.0.10", "0.0.0.14");
_test_address_range ("1.2.3.0", 29, "1.2.3.2", "1.2.3.6");
_test_address_range ("1.2.3.1", 29, "1.2.3.2", "1.2.3.6");
_test_address_range ("1.2.3.2", 29, "1.2.3.3", "1.2.3.6");
_test_address_range ("1.2.3.3", 29, "1.2.3.4", "1.2.3.6");
_test_address_range ("1.2.3.4", 29, "1.2.3.1", "1.2.3.3");
_test_address_range ("1.2.3.5", 29, "1.2.3.1", "1.2.3.4");
_test_address_range ("1.2.3.6", 29, "1.2.3.1", "1.2.3.5");
_test_address_range ("1.2.3.7", 29, "1.2.3.1", "1.2.3.5");
_test_address_range ("1.2.3.8", 29, "1.2.3.10", "1.2.3.14");
_test_address_range ("1.2.3.9", 29, "1.2.3.10", "1.2.3.14");
_test_address_range ("255.255.255.248", 29, "255.255.255.250", "255.255.255.254");
_test_address_range ("255.255.255.249", 29, "255.255.255.250", "255.255.255.254");
_test_address_range ("255.255.255.250", 29, "255.255.255.251", "255.255.255.254");
_test_address_range ("255.255.255.251", 29, "255.255.255.252", "255.255.255.254");
_test_address_range ("255.255.255.252", 29, "255.255.255.249", "255.255.255.251");
_test_address_range ("255.255.255.253", 29, "255.255.255.249", "255.255.255.252");
_test_address_range ("255.255.255.254", 29, "255.255.255.249", "255.255.255.253");
_test_address_range ("255.255.255.255", 29, "255.255.255.249", "255.255.255.253");
_test_address_range ("1.2.3.1", 29, "1.2.3.2", "1.2.3.6");
_test_address_range ("1.2.3.1", 28, "1.2.3.3", "1.2.3.14");
_test_address_range ("1.2.3.1", 26, "1.2.3.8", "1.2.3.62");
_test_address_range ("192.167.255.255", 24, "192.167.255.1", "192.167.255.245");
_test_address_range ("192.168.0.0", 24, "192.168.0.10", "192.168.0.254");
_test_address_range ("192.168.0.1", 24, "192.168.0.10", "192.168.0.254");
_test_address_range ("192.168.0.2", 24, "192.168.0.11", "192.168.0.254");
_test_address_range ("192.168.0.99", 24, "192.168.0.108", "192.168.0.254");
_test_address_range ("192.168.0.126", 24, "192.168.0.135", "192.168.0.254");
_test_address_range ("192.168.0.127", 24, "192.168.0.136", "192.168.0.254");
_test_address_range ("192.168.0.128", 24, "192.168.0.1", "192.168.0.119");
_test_address_range ("192.168.0.129", 24, "192.168.0.1", "192.168.0.120");
_test_address_range ("192.168.0.130", 24, "192.168.0.1", "192.168.0.121");
_test_address_range ("192.168.0.254", 24, "192.168.0.1", "192.168.0.245");
_test_address_range ("192.168.0.255", 24, "192.168.0.1", "192.168.0.245");
_test_address_range ("192.168.1.0", 24, "192.168.1.10", "192.168.1.254");
_test_address_range ("192.168.1.1", 24, "192.168.1.10", "192.168.1.254");
_test_address_range ("192.168.1.2", 24, "192.168.1.11", "192.168.1.254");
_test_address_range ("192.168.1.10", 24, "192.168.1.19", "192.168.1.254");
_test_address_range ("192.168.15.253", 24, "192.168.15.1", "192.168.15.244");
_test_address_range ("192.168.15.254", 24, "192.168.15.1", "192.168.15.245");
_test_address_range ("192.168.15.255", 24, "192.168.15.1", "192.168.15.245");
_test_address_range ("192.168.16.0", 24, "192.168.16.10", "192.168.16.254");
_test_address_range ("192.168.16.1", 24, "192.168.16.10", "192.168.16.254");
_test_address_range ("192.167.255.255", 20, "192.167.255.1", "192.167.255.245");
_test_address_range ("192.168.0.0", 20, "192.168.0.10", "192.168.0.254");
_test_address_range ("192.168.0.1", 20, "192.168.0.10", "192.168.0.254");
_test_address_range ("192.168.0.2", 20, "192.168.0.11", "192.168.0.254");
_test_address_range ("192.168.0.126", 20, "192.168.0.135", "192.168.0.254");
_test_address_range ("192.168.0.127", 20, "192.168.0.136", "192.168.0.254");
_test_address_range ("192.168.0.128", 20, "192.168.0.1", "192.168.0.119");
_test_address_range ("192.168.0.129", 20, "192.168.0.1", "192.168.0.120");
_test_address_range ("192.168.0.130", 20, "192.168.0.1", "192.168.0.121");
_test_address_range ("192.168.0.254", 20, "192.168.0.1", "192.168.0.245");
_test_address_range ("192.168.0.255", 20, "192.168.0.1", "192.168.0.245");
_test_address_range ("192.168.1.0", 20, "192.168.1.10", "192.168.1.254");
_test_address_range ("192.168.1.1", 20, "192.168.1.10", "192.168.1.254");
_test_address_range ("192.168.1.2", 20, "192.168.1.11", "192.168.1.254");
_test_address_range ("192.168.1.10", 20, "192.168.1.19", "192.168.1.254");
_test_address_range ("192.168.15.253", 20, "192.168.15.1", "192.168.15.244");
_test_address_range ("192.168.15.254", 20, "192.168.15.1", "192.168.15.245");
_test_address_range ("192.168.15.255", 20, "192.168.15.1", "192.168.15.245");
_test_address_range ("192.168.16.0", 20, "192.168.16.10", "192.168.16.254");
_test_address_range ("192.168.16.1", 20, "192.168.16.10", "192.168.16.254");
}
/*****************************************************************************/
NMTST_DEFINE ();
int
main (int argc, char **argv)
{
nmtst_init_assert_logging (&argc, &argv, "INFO", "DEFAULT");
g_test_add_func ("/dnsmasq/address-ranges", test_address_ranges);
return g_test_run ();
}
|