1
0
mirror of https://github.com/systemd/systemd.git synced 2024-12-25 01:34:28 +03:00

test: add testcases of filtering on dumping addresses

This commit is contained in:
Yu Watanabe 2021-05-25 08:15:36 +09:00
parent 6a28b78f2e
commit 922a653090

View File

@ -15,35 +15,67 @@ static void print_local_addresses(struct local_address *a, unsigned n) {
_cleanup_free_ char *b = NULL;
assert_se(in_addr_to_string(a[i].family, &a[i].address, &b) >= 0);
printf("%s if%i scope=%i metric=%u address=%s\n", af_to_name(a[i].family), a[i].ifindex, a[i].scope, a[i].metric, b);
log_debug("%s if%i scope=%i metric=%u address=%s", af_to_name(a[i].family), a[i].ifindex, a[i].scope, a[i].metric, b);
}
}
int main(int argc, char *argv[]) {
struct local_address *a;
int n;
struct local_address *a = NULL;
int n, n_ipv4, n_ipv6;
test_setup_logging(LOG_DEBUG);
a = NULL;
n = local_addresses(NULL, 0, AF_UNSPEC, &a);
n = local_addresses(NULL, 0, AF_INET, &a);
assert_se(n >= 0);
printf("Local Addresses:\n");
log_debug("/* Local Addresses(ifindex:0, AF_INET) */");
print_local_addresses(a, (unsigned) n);
a = mfree(a);
n_ipv4 = n;
n = local_addresses(NULL, 0, AF_INET6, &a);
assert_se(n >= 0);
log_debug("/* Local Addresses(ifindex:0, AF_INET6) */");
print_local_addresses(a, (unsigned) n);
a = mfree(a);
n_ipv6 = n;
n = local_addresses(NULL, 0, AF_UNSPEC, &a);
assert_se(n >= 0);
log_debug("/* Local Addresses(ifindex:0, AF_UNSPEC) */");
print_local_addresses(a, (unsigned) n);
a = mfree(a);
assert_se(n == n_ipv4 + n_ipv6);
n = local_addresses(NULL, 1, AF_INET, &a);
assert_se(n >= 0);
log_debug("/* Local Addresses(ifindex:1, AF_INET) */");
print_local_addresses(a, (unsigned) n);
a = mfree(a);
n_ipv4 = n;
n = local_addresses(NULL, 1, AF_INET6, &a);
assert_se(n >= 0);
log_debug("/* Local Addresses(ifindex:1, AF_INET6) */");
print_local_addresses(a, (unsigned) n);
a = mfree(a);
n_ipv6 = n;
n = local_addresses(NULL, 1, AF_UNSPEC, &a);
assert_se(n >= 0);
log_debug("/* Local Addresses(ifindex:1, AF_UNSPEC) */");
print_local_addresses(a, (unsigned) n);
a = mfree(a);
assert_se(n == n_ipv4 + n_ipv6);
n = local_gateways(NULL, 0, AF_UNSPEC, &a);
assert_se(n >= 0);
printf("Local Gateways:\n");
log_debug("/* Local Gateways */");
print_local_addresses(a, (unsigned) n);
free(a);
a = mfree(a);
n = local_outbounds(NULL, 0, AF_UNSPEC, &a);
assert_se(n >= 0);
printf("Local Outbounds:\n");
log_debug("/* Local Outbounds */");
print_local_addresses(a, (unsigned) n);
free(a);