]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
network: dhcp6pd: set server address for unreachable route
authorYu Watanabe <watanabe.yu+github@gmail.com>
Sat, 4 Dec 2021 19:36:48 +0000 (04:36 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Tue, 7 Dec 2021 09:35:30 +0000 (18:35 +0900)
This is just for json output.

src/network/networkd-dhcp-prefix-delegation.c

index b388a9f882c5fe2cb2be5064a642fb6c484720af..46e75e77c12b272e090cc7153b42b4d474205e12 100644 (file)
@@ -665,13 +665,20 @@ static int dhcp6_route_handler(sd_netlink *rtnl, sd_netlink_message *m, Link *li
         return 1;
 }
 
-static int dhcp6_request_unreachable_route(Link *link, const struct in6_addr *addr, uint8_t prefixlen, usec_t lifetime_usec) {
+static int dhcp6_request_unreachable_route(
+                Link *link,
+                const struct in6_addr *addr,
+                uint8_t prefixlen,
+                usec_t lifetime_usec,
+                const union in_addr_union *server_address) {
+
         _cleanup_(route_freep) Route *route = NULL;
         Route *existing;
         int r;
 
         assert(link);
         assert(addr);
+        assert(server_address);
 
         if (prefixlen >= 64) {
                 _cleanup_free_ char *buf = NULL;
@@ -687,6 +694,7 @@ static int dhcp6_request_unreachable_route(Link *link, const struct in6_addr *ad
                 return log_oom();
 
         route->source = NETWORK_CONFIG_SOURCE_DHCP6;
+        route->provider = *server_address;
         route->family = AF_INET6;
         route->dst.in6 = *addr;
         route->dst_prefixlen = prefixlen;
@@ -797,6 +805,7 @@ static int dhcp6_pd_assign_prefixes(Link *link, Link *uplink) {
 }
 
 int dhcp6_pd_prefix_acquired(Link *dhcp6_link) {
+        union in_addr_union server_address;
         usec_t timestamp_usec;
         Link *link;
         int r;
@@ -804,6 +813,10 @@ int dhcp6_pd_prefix_acquired(Link *dhcp6_link) {
         assert(dhcp6_link);
         assert(dhcp6_link->dhcp6_lease);
 
+        r = sd_dhcp6_lease_get_server_address(dhcp6_link->dhcp6_lease, &server_address.in6);
+        if (r < 0)
+                return log_link_warning_errno(dhcp6_link, r, "Failed to get server address of DHCPv6 lease: %m");
+
         r = sd_dhcp6_lease_get_timestamp(dhcp6_link->dhcp6_lease, clock_boottime_or_monotonic(), &timestamp_usec);
         if (r < 0)
                 return log_link_warning_errno(dhcp6_link, r, "Failed to get timestamp of DHCPv6 lease: %m");
@@ -831,7 +844,7 @@ int dhcp6_pd_prefix_acquired(Link *dhcp6_link) {
                 if (r < 0)
                         return r;
 
-                r = dhcp6_request_unreachable_route(dhcp6_link, &pd_prefix, pd_prefix_len, lifetime_valid_usec);
+                r = dhcp6_request_unreachable_route(dhcp6_link, &pd_prefix, pd_prefix_len, lifetime_valid_usec, &server_address);
                 if (r < 0)
                         return r;
         }