140{
141 struct acl permitallv4 = {
"0.0.0.0/0",
"permit" };
142 struct acl denyallv4 = {
"0.0.0.0/0",
"deny" };
143 struct acl permitallv6 = {
"::/0",
"permit" };
144 struct acl denyallv6 = {
"::/0",
"deny" };
145
146 struct acl acl1[] = {
147 { "0.0.0.0/0.0.0.0", "deny" },
148 { "10.0.0.0/255.0.0.0", "permit" },
149 { "192.168.0.0/255.255.255.0", "permit" },
150 };
151
152 struct acl acl2[] = {
153 { "10.0.0.0/8", "deny" },
154 { "10.0.0.0/8", "permit" },
155 { "10.0.0.0/16", "deny" },
156 { "10.0.0.0/24", "permit" },
157 };
158
159 struct acl acl3[] = {
160 { "::/0", "deny" },
161 { "fe80::/64", "permit" },
162 };
163
164 struct acl acl4[] = {
165 { "::/0", "deny" },
166 { "fe80::/64", "permit" },
167 { "fe80::ffff:0:0:0/80", "deny" },
168 { "fe80::ffff:0:ffff:0/112", "permit" },
169 };
170
171 struct acl acl5[] = {
172 { "0.0.0.0/0.0.0.0", "deny" },
173 { "10.0.0.0/255.0.0.0,192.168.0.0/255.255.255.0", "permit" },
174 };
175
176 struct acl acl6[] = {
177 { "10.0.0.0/8", "deny" },
178 { "10.0.0.0/8", "permit" },
179 { "10.0.0.0/16,!10.0.0.0/24", "deny" },
180 };
181
182 struct acl acl7[] = {
183 { "::/0,!fe80::/64", "deny" },
184 { "fe80::ffff:0:0:0/80", "deny" },
185 { "fe80::ffff:0:ffff:0/112", "permit" },
186 };
187
188 struct {
189 const char *test_address;
190 int v4_permitall_result;
191 int v4_denyall_result;
192 int v6_permitall_result;
193 int v6_denyall_result;
194 int acl1_result;
195 int acl2_result;
196 int acl3_result;
197 int acl4_result;
198 int acl5_result;
199 int acl6_result;
200 int acl7_result;
201 } acl_tests[] = {
202 {
"10.1.1.5",
TACL_A,
TACL_D,
TACL_A,
TACL_A,
TACL_A,
TACL_A,
TACL_A,
TACL_A,
TACL_A,
TACL_A,
TACL_A },
203 {
"192.168.0.5",
TACL_A,
TACL_D,
TACL_A,
TACL_A,
TACL_A,
TACL_A,
TACL_A,
TACL_A,
TACL_A,
TACL_A,
TACL_A },
204 {
"192.168.1.5",
TACL_A,
TACL_D,
TACL_A,
TACL_A,
TACL_D,
TACL_A,
TACL_A,
TACL_A,
TACL_D,
TACL_A,
TACL_A },
205 {
"10.0.0.1",
TACL_A,
TACL_D,
TACL_A,
TACL_A,
TACL_A,
TACL_A,
TACL_A,
TACL_A,
TACL_A,
TACL_A,
TACL_A },
206 {
"10.0.10.10",
TACL_A,
TACL_D,
TACL_A,
TACL_A,
TACL_A,
TACL_D,
TACL_A,
TACL_A,
TACL_A,
TACL_D,
TACL_A },
207 {
"172.16.0.1",
TACL_A,
TACL_D,
TACL_A,
TACL_A,
TACL_D,
TACL_A,
TACL_A,
TACL_A,
TACL_D,
TACL_A,
TACL_A },
208 {
"fe80::1234",
TACL_A,
TACL_A,
TACL_A,
TACL_D,
TACL_A,
TACL_A,
TACL_A,
TACL_A,
TACL_A,
TACL_A,
TACL_A },
209 {
"fe80::ffff:1213:dead:beef",
TACL_A,
TACL_A,
TACL_A,
TACL_D,
TACL_A,
TACL_A,
TACL_A,
TACL_D,
TACL_A,
TACL_A,
TACL_D },
210 {
"fe80::ffff:0:ffff:ABCD",
TACL_A,
TACL_A,
TACL_A,
TACL_D,
TACL_A,
TACL_A,
TACL_A,
TACL_A,
TACL_A,
TACL_A,
TACL_A },
211 };
212
225 int err = 0;
226 int i;
227
228
229 switch (cmd) {
232 info->category =
"/main/acl/";
233 info->summary =
"ACL unit test";
235 "Tests that hosts are properly permitted or denied";
238 break;
239 }
240
244 goto acl_cleanup;
245 }
246
250 goto acl_cleanup;
251 }
252
256 goto acl_cleanup;
257 }
258
262 goto acl_cleanup;
263 }
264
266 goto acl_cleanup;
267 }
268
270 goto acl_cleanup;
271 }
272
274 goto acl_cleanup;
275 }
276
278 goto acl_cleanup;
279 }
280
282 goto acl_cleanup;
283 }
284
286 goto acl_cleanup;
287 }
288
290 goto acl_cleanup;
291 }
292
293 for (i = 0; i <
ARRAY_LEN(acl_tests); ++i) {
295 int permit_resv4;
296 int permit_resv6;
297 int deny_resv4;
298 int deny_resv6;
299 int acl1_res;
300 int acl2_res;
301 int acl3_res;
302 int acl4_res;
303 int acl5_res;
304 int acl6_res;
305 int acl7_res;
306
308
320
321 if (permit_resv4 != acl_tests[i].v4_permitall_result) {
323 "got %d instead\n", acl_tests[i].test_address, acl_tests[i].v4_permitall_result, permit_resv4);
325 goto acl_cleanup;
326 }
327
328 if (deny_resv4 != acl_tests[i].v4_denyall_result) {
330 "got %d instead\n", acl_tests[i].test_address, acl_tests[i].v4_denyall_result, deny_resv4);
332 goto acl_cleanup;
333 }
334
335 if (permit_resv6 != acl_tests[i].v6_permitall_result) {
337 "got %d instead\n", acl_tests[i].test_address, acl_tests[i].v6_permitall_result, permit_resv6);
339 goto acl_cleanup;
340 }
341
342 if (deny_resv6 != acl_tests[i].v6_denyall_result) {
344 "got %d instead\n", acl_tests[i].test_address, acl_tests[i].v6_denyall_result, deny_resv6);
346 goto acl_cleanup;
347 }
348
349 if (acl1_res != acl_tests[i].acl1_result) {
351 "got %d instead\n", acl_tests[i].test_address, acl_tests[i].acl1_result, acl1_res);
353 goto acl_cleanup;
354 }
355
356 if (acl2_res != acl_tests[i].acl2_result) {
358 "got %d instead\n", acl_tests[i].test_address, acl_tests[i].acl2_result, acl2_res);
360 goto acl_cleanup;
361 }
362
363 if (acl3_res != acl_tests[i].acl3_result) {
365 "got %d instead\n", acl_tests[i].test_address, acl_tests[i].acl3_result, acl3_res);
367 goto acl_cleanup;
368 }
369
370 if (acl4_res != acl_tests[i].acl4_result) {
372 "got %d instead\n", acl_tests[i].test_address, acl_tests[i].acl4_result, acl4_res);
374 goto acl_cleanup;
375 }
376
377 if (acl5_res != acl_tests[i].acl5_result) {
379 "got %d instead\n", acl_tests[i].test_address, acl_tests[i].acl5_result, acl5_res);
381 goto acl_cleanup;
382 }
383
384 if (acl6_res != acl_tests[i].acl6_result) {
386 "got %d instead\n", acl_tests[i].test_address, acl_tests[i].acl6_result, acl6_res);
388 goto acl_cleanup;
389 }
390
391 if (acl7_res != acl_tests[i].acl7_result) {
393 "got %d instead\n", acl_tests[i].test_address, acl_tests[i].acl7_result, acl7_res);
395 goto acl_cleanup;
396 }
397 }
398
399acl_cleanup:
400 if (permit_hav4) {
402 }
403 if (deny_hav4) {
405 }
406 if (permit_hav6) {
408 }
409 if (deny_hav6) {
411 }
412 if (ha1) {
414 }
415 if (ha2) {
417 }
418 if (ha3) {
420 }
421 if (ha4) {
423 }
424 if (ha5) {
426 }
427 if (ha6) {
429 }
430 if (ha7) {
432 }
433 return res;
434}
void ast_free_ha(struct ast_ha *ha)
Free a list of HAs.
enum ast_acl_sense ast_apply_ha(const struct ast_ha *ha, const struct ast_sockaddr *addr)
Apply a set of rules to a given IP address.
struct ast_ha * ast_append_ha(const char *sense, const char *stuff, struct ast_ha *path, int *error)
Add a new rule to a list of HAs.
int ast_sockaddr_parse(struct ast_sockaddr *addr, const char *str, int flags)
Parse an IPv4 or IPv6 address string.
internal representation of ACL entries In principle user applications would have no need for this,...
Socket address structure.
#define ast_test_status_update(a, b, c...)
static int build_ha(const struct acl *acl, size_t len, struct ast_ha **ha, const char *acl_name, int *err, struct ast_test *test, enum ast_test_result_state *res)