networkd: Request prefixes when configured to do so
authorPatrik Flykt <patrik.flykt@linux.intel.com>
Thu, 4 Jan 2018 13:11:51 +0000 (15:11 +0200)
committerPatrik Flykt <patrik.flykt@linux.intel.com>
Thu, 4 Jan 2018 13:22:44 +0000 (15:22 +0200)
Request prefixes via DHCPv6 if there are networks that are
configured to distribute them. As specified in RFC 3633, a DHCPv6
client cannot redistribute the prefixes via Router Advertisements
on the same link. Ignore such networks, and print out a warning if
the link where DHCPv6 is enabled tries to do so.

src/network/networkd-dhcp6.c

index a46a11bf167d4217c1237c87108586c8adc45d33..59dcf28764b2e142a40e59fd23b37f1ad6fe773e 100644 (file)
 
 static int dhcp6_lease_address_acquired(sd_dhcp6_client *client, Link *link);
 
+static bool dhcp6_verify_link(Link *link) {
+        if (!link->network) {
+                log_link_info(link, "Link is not managed by us");
+                return false;
+        }
+
+        if (!IN_SET(link->network->router_prefix_delegation,
+                            RADV_PREFIX_DELEGATION_DHCP6,
+                            RADV_PREFIX_DELEGATION_BOTH)) {
+                log_link_debug(link, "Link does not request DHCPv6 prefix delegation");
+                return false;
+        }
+
+        return true;
+}
+
+static bool dhcp6_enable_prefix_delegation(Link *dhcp6_link) {
+        Manager *manager;
+        Link *l;
+        Iterator i;
+
+        assert(dhcp6_link);
+
+        manager = dhcp6_link->manager;
+        assert(manager);
+
+        HASHMAP_FOREACH(l, manager->links, i) {
+                if (l == dhcp6_link)
+                        continue;
+
+                if (!dhcp6_verify_link(l))
+                        continue;
+
+                return true;
+        }
+
+        return false;
+}
+
 static int dhcp6_lease_information_acquired(sd_dhcp6_client *client,
                                         Link *link) {
         return 0;
@@ -283,6 +322,12 @@ int dhcp6_configure(Link *link) {
         if (r < 0)
                 goto error;
 
+        if (dhcp6_enable_prefix_delegation(link)) {
+                r = sd_dhcp6_client_set_prefix_delegation(client, true);
+                if (r < 0)
+                        goto error;
+        }
+
         link->dhcp6_client = client;
 
         return 0;