Exemple #1
0
void prefix_free(Prefix *prefix) {
        if (!prefix)
                return;

        if (prefix->network) {
                LIST_REMOVE(prefixes, prefix->network->static_prefixes, prefix);
                assert(prefix->network->n_static_prefixes > 0);
                prefix->network->n_static_prefixes--;

                if (prefix->section)
                        hashmap_remove(prefix->network->prefixes_by_section,
                                       prefix->section);
        }

        prefix->radv_prefix = sd_radv_prefix_unref(prefix->radv_prefix);

        free(prefix);
}
Exemple #2
0
static void test_radv_prefix(void) {
        sd_radv_prefix *p;

        printf("* %s\n", __FUNCTION__);

        assert_se(sd_radv_prefix_new(&p) >= 0);

        assert_se(sd_radv_prefix_set_onlink(NULL, true) < 0);
        assert_se(sd_radv_prefix_set_onlink(p, true) >= 0);
        assert_se(sd_radv_prefix_set_onlink(p, false) >= 0);

        assert_se(sd_radv_prefix_set_address_autoconfiguration(NULL, true) < 0);
        assert_se(sd_radv_prefix_set_address_autoconfiguration(p, true) >= 0);
        assert_se(sd_radv_prefix_set_address_autoconfiguration(p, false) >= 0);

        assert_se(sd_radv_prefix_set_valid_lifetime(NULL, true) < 0);
        assert_se(sd_radv_prefix_set_valid_lifetime(p, ~0) >= 0);
        assert_se(sd_radv_prefix_set_valid_lifetime(p, 42) >= 0);
        assert_se(sd_radv_prefix_set_valid_lifetime(p, 0) >= 0);

        assert_se(sd_radv_prefix_set_preferred_lifetime(NULL, true) < 0);
        assert_se(sd_radv_prefix_set_preferred_lifetime(p, ~0) >= 0);
        assert_se(sd_radv_prefix_set_preferred_lifetime(p, 42) >= 0);
        assert_se(sd_radv_prefix_set_preferred_lifetime(p, 0) >= 0);

        assert_se(sd_radv_prefix_set_prefix(NULL, NULL, 0) < 0);
        assert_se(sd_radv_prefix_set_prefix(p, NULL, 0) < 0);

        assert_se(sd_radv_prefix_set_prefix(p, &prefix[0].address, 64) >= 0);
        assert_se(sd_radv_prefix_set_prefix(p, &prefix[0].address, 0) < 0);
        assert_se(sd_radv_prefix_set_prefix(p, &prefix[0].address, 1) < 0);
        assert_se(sd_radv_prefix_set_prefix(p, &prefix[0].address, 2) < 0);
        assert_se(sd_radv_prefix_set_prefix(p, &prefix[0].address, 3) >= 0);
        assert_se(sd_radv_prefix_set_prefix(p, &prefix[0].address, 125) >= 0);
        assert_se(sd_radv_prefix_set_prefix(p, &prefix[0].address, 128) >= 0);
        assert_se(sd_radv_prefix_set_prefix(p, &prefix[0].address, 129) < 0);
        assert_se(sd_radv_prefix_set_prefix(p, &prefix[0].address, 255) < 0);

        p = sd_radv_prefix_unref(p);
        assert_se(!p);
}
Exemple #3
0
static void test_ra(void) {
        sd_event *e;
        sd_radv *ra;
        usec_t time_now = now(clock_boottime_or_monotonic());
        unsigned i;

        printf("* %s\n", __FUNCTION__);

        assert_se(socketpair(AF_UNIX, SOCK_SEQPACKET, 0, test_fd) >= 0);

        assert_se(sd_event_new(&e) >= 0);

        assert_se(sd_radv_new(&ra) >= 0);
        assert_se(ra);

        assert_se(sd_radv_attach_event(ra, e, 0) >= 0);

        assert_se(sd_radv_set_ifindex(ra, 42) >= 0);
        assert_se(sd_radv_set_mac(ra, &mac_addr) >= 0);
        assert_se(sd_radv_set_router_lifetime(ra, 180) >= 0);
        assert_se(sd_radv_set_hop_limit(ra, 64) >= 0);
        assert_se(sd_radv_set_managed_information(ra, true) >= 0);
        assert_se(sd_radv_set_other_information(ra, true) >= 0);
        assert_se(sd_radv_set_rdnss(ra, 60, &test_rdnss, 1) >= 0);
        assert_se(sd_radv_set_dnssl(ra, 60, (char **)test_dnssl) >= 0);

        for (i = 0; i < ELEMENTSOF(prefix); i++) {
                sd_radv_prefix *p;

                printf("Test prefix %u\n", i);
                assert_se(sd_radv_prefix_new(&p) >= 0);

                assert_se(sd_radv_prefix_set_prefix(p, &prefix[i].address,
                                                    prefix[i].prefixlen) >= 0);
                if (prefix[i].valid)
                        assert_se(sd_radv_prefix_set_valid_lifetime(p, prefix[i].valid) >= 0);
                if (prefix[i].preferred)
                        assert_se(sd_radv_prefix_set_preferred_lifetime(p, prefix[i].preferred) >= 0);

                assert_se((sd_radv_add_prefix(ra, p, false) >= 0) == prefix[i].succesful);
                assert_se(sd_radv_add_prefix(ra, p, false) < 0);

                p = sd_radv_prefix_unref(p);
                assert_se(!p);
        }

        assert_se(sd_event_add_io(e, &recv_router_advertisement, test_fd[0],
                                  EPOLLIN, radv_recv, ra) >= 0);

        assert_se(sd_event_add_time(e, &test_hangcheck, clock_boottime_or_monotonic(),
                                 time_now + 2 *USEC_PER_SEC, 0,
                                 test_rs_hangcheck, NULL) >= 0);

        assert_se(sd_radv_start(ra) >= 0);

        sd_event_loop(e);

        test_hangcheck = sd_event_source_unref(test_hangcheck);

        ra = sd_radv_unref(ra);
        assert_se(!ra);

        close(test_fd[0]);

        sd_event_unref(e);
}