static void test_prefixes_cb(sd_icmp6_nd *nd, int event, void *userdata) { sd_event *e = userdata; struct { struct in6_addr addr; uint8_t prefixlen; bool success; } addrs[] = { { { { { 0x20, 0x01, 0x0d, 0xb8, 0xde, 0xad, 0xbe, 0xef, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } } }, 63, true }, { { { { 0x20, 0x01, 0x0d, 0xb8, 0xde, 0xad, 0x0d, 0xad, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } } }, 64, false }, { { { { 0x20, 0x01, 0x0d, 0xb8, 0x0b, 0x16, 0xd0, 0x0d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } } }, 60, true }, { { { { 0x20, 0x01, 0x0d, 0xb8, 0x00, 0x9d, 0xab, 0xcd, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } } }, 64, true }, { { { { 0x20, 0x01, 0x0d, 0xb8, 0xde, 0xad, 0xbe, 0xed, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 } } }, 63, false }, }; uint8_t prefixlen; unsigned int i; for (i = 0; i < ELEMENTSOF(addrs); i++) { printf(" %s prefix %02x%02x:%02x%02x:%02x%02x:%02x%02x", __FUNCTION__, addrs[i].addr.s6_addr[0], addrs[i].addr.s6_addr[1], addrs[i].addr.s6_addr[2], addrs[i].addr.s6_addr[3], addrs[i].addr.s6_addr[4], addrs[i].addr.s6_addr[5], addrs[i].addr.s6_addr[6], addrs[i].addr.s6_addr[7]); if (addrs[i].success) { assert_se(sd_icmp6_ra_get_prefixlen(nd, &addrs[i].addr, &prefixlen) >= 0); assert_se(addrs[i].prefixlen == prefixlen); printf("/%d onlink\n", prefixlen); } else { assert_se(sd_icmp6_ra_get_prefixlen(nd, &addrs[i].addr, &prefixlen) == -EADDRNOTAVAIL); printf("/128 offlink\n"); } } send_ra_function = send_ra_short_prefix; assert_se(sd_icmp6_nd_set_callback(nd, test_short_prefix_cb, e) >= 0); assert_se(sd_icmp6_nd_stop(nd) >= 0); assert_se(sd_icmp6_router_solicitation_start(nd) >= 0); }
static int dhcp6_lease_address_acquired(sd_dhcp6_client *client, Link *link) { int r; sd_dhcp6_lease *lease; struct in6_addr ip6_addr; uint32_t lifetime_preferred, lifetime_valid; uint8_t prefixlen; r = sd_dhcp6_client_get_lease(client, &lease); if (r < 0) return r; sd_dhcp6_lease_reset_address_iter(lease); while (sd_dhcp6_lease_get_address(lease, &ip6_addr, &lifetime_preferred, &lifetime_valid) >= 0) { r = sd_icmp6_ra_get_prefixlen(link->icmp6_router_discovery, &ip6_addr, &prefixlen); if (r < 0 && r != -EADDRNOTAVAIL) { log_link_warning_errno(link, r, "Could not get prefix information: %m"); return r; } if (r == -EADDRNOTAVAIL) prefixlen = 128; r = dhcp6_address_change(link, &ip6_addr, prefixlen, lifetime_preferred, lifetime_valid); if (r < 0) return r; } return 0; }