| 1 |
/* SPDX-License-Identifier: LGPL-2.1-or-later */ |
| 2 |
|
| 3 |
#include <sched.h> |
| 4 |
#include <stdlib.h> |
| 5 |
|
| 6 |
#include "errno-util.h" |
| 7 |
#include "log.h" |
| 8 |
#include "loopback-setup.h" |
| 9 |
#include "tests.h" |
| 10 |
|
| 11 |
TEST_RET(loopback_setup) { |
| 12 |
int r; |
| 13 |
|
| 14 |
if (unshare(CLONE_NEWUSER | CLONE_NEWNET) < 0) { |
| 15 |
if (ERRNO_IS_PRIVILEGE(errno) || ERRNO_IS_NOT_SUPPORTED(errno)) |
| 16 |
return log_tests_skipped("lacking privileges or namespaces not supported"); |
| 17 |
return log_error_errno(errno, "Failed to create user+network namespace: %m"); |
| 18 |
} |
| 19 |
|
| 20 |
r = loopback_setup(); |
| 21 |
if (ERRNO_IS_NEG_PRIVILEGE(r)) |
| 22 |
return log_tests_skipped("lacking privileges"); |
| 23 |
if (r < 0) |
| 24 |
return log_error_errno(r, "loopback: %m"); |
| 25 |
|
| 26 |
log_info("> ipv6 main"); |
| 27 |
/* <0 → fork error, ==0 → success, >0 → error in child */ |
| 28 |
assert_se(system("ip -6 route show table main") >= 0); |
| 29 |
|
| 30 |
log_info("> ipv6 local"); |
| 31 |
assert_se(system("ip -6 route show table local") >=0); |
| 32 |
|
| 33 |
log_info("> ipv4 main"); |
| 34 |
assert_se(system("ip -4 route show table main") >= 0); |
| 35 |
|
| 36 |
log_info("> ipv4 local"); |
| 37 |
assert_se(system("ip -4 route show table local") >= 0); |
| 38 |
|
| 39 |
return EXIT_SUCCESS; |
| 40 |
} |
| 41 |
|
| 42 |
static int intro(void) { |
| 43 |
log_show_color(true); |
| 44 |
return EXIT_SUCCESS; |
| 45 |
} |
| 46 |
|
| 47 |
DEFINE_TEST_MAIN_WITH_INTRO(LOG_INFO, intro); |