| 1 |
/* SPDX-License-Identifier: LGPL-2.1-or-later */ |
| 2 |
|
| 3 |
#include <net/if.h> |
| 4 |
|
| 5 |
#include "sd-varlink.h" |
| 6 |
|
| 7 |
#include "errno-util.h" |
| 8 |
#include "fd-util.h" |
| 9 |
#include "namespace-util.h" |
| 10 |
#include "nsresource.h" |
| 11 |
#include "tests.h" |
| 12 |
|
| 13 |
TEST(delegatetap) { |
| 14 |
int r; |
| 15 |
|
| 16 |
_cleanup_close_ int userns_fd = userns_acquire_self_root(); |
| 17 |
if (ERRNO_IS_NEG_PRIVILEGE(userns_fd) || ERRNO_IS_NEG_NOT_SUPPORTED(userns_fd)) |
| 18 |
return (void) log_tests_skipped_errno(userns_fd, "User namespaces not available"); |
| 19 |
ASSERT_OK(userns_fd); |
| 20 |
|
| 21 |
_cleanup_(sd_varlink_unrefp) sd_varlink *link = NULL; |
| 22 |
r = nsresource_connect(&link); |
| 23 |
if (ERRNO_IS_NEG_DISCONNECT(r) || r == -ENOENT || ERRNO_IS_NEG_NOT_SUPPORTED(r)) |
| 24 |
return (void) log_tests_skipped_errno(r, "systemd-nsresourced cannot be reached"); |
| 25 |
|
| 26 |
r = nsresource_register_userns(link, "foobar", userns_fd); |
| 27 |
if (ERRNO_IS_NEG_NOT_SUPPORTED(r)) |
| 28 |
return (void) log_tests_skipped_errno(r, "systemd-nsresourced does not work"); |
| 29 |
ASSERT_OK(r); |
| 30 |
|
| 31 |
_cleanup_free_ char *ifname = NULL; |
| 32 |
_cleanup_close_ int tap_fd = nsresource_add_netif_tap(link, userns_fd, &ifname); |
| 33 |
if (ERRNO_IS_NEG_NOT_SUPPORTED(tap_fd)) |
| 34 |
return (void) log_tests_skipped_errno(tap_fd, "tap device support not available"); |
| 35 |
ASSERT_OK(tap_fd); |
| 36 |
|
| 37 |
ASSERT_GE(if_nametoindex(ifname), 2U); |
| 38 |
} |
| 39 |
|
| 40 |
DEFINE_TEST_MAIN(LOG_DEBUG); |