chiark / gitweb /
networkd: allow specification of DHCP route metric
[elogind.git] / src / network / networkd-dhcp4.c
index 499e813f200d61a3f4486e4c577ca4a2142ac970..e0b3acad1b8ede49512bc337519693dc89e032fd 100644 (file)
@@ -67,9 +67,18 @@ static int link_set_dhcp_routes(Link *link) {
                 return r;
         }
         if (r >= 0) {
+                struct in_addr address;
                 _cleanup_route_free_ Route *route = NULL;
                 _cleanup_route_free_ Route *route_gw = NULL;
 
+                r = sd_dhcp_lease_get_address(link->dhcp_lease, &address);
+                if (r < 0) {
+                        log_warning_link(link,
+                                         "DHCP error: could not get address: %s",
+                                         strerror(-r));
+                        return r;
+                }
+
                 r = route_new_dynamic(&route, RTPROT_DHCP);
                 if (r < 0) {
                         log_error_link(link,
@@ -92,8 +101,9 @@ static int link_set_dhcp_routes(Link *link) {
                 route_gw->family = AF_INET;
                 route_gw->dst_addr.in = gateway;
                 route_gw->dst_prefixlen = 32;
+                route_gw->prefsrc_addr.in = address;
                 route_gw->scope = RT_SCOPE_LINK;
-                route_gw->metrics = DHCP_ROUTE_METRIC;
+                route_gw->metrics = link->network->dhcp_route_metric;
 
                 r = route_configure(route_gw, link, &dhcp4_route_handler);
                 if (r < 0) {
@@ -107,7 +117,8 @@ static int link_set_dhcp_routes(Link *link) {
 
                 route->family = AF_INET;
                 route->in_addr.in = gateway;
-                route->metrics = DHCP_ROUTE_METRIC;
+                route->prefsrc_addr.in = address;
+                route->metrics = link->network->dhcp_route_metric;
 
                 r = route_configure(route, link, &dhcp4_route_handler);
                 if (r < 0) {
@@ -146,7 +157,7 @@ static int link_set_dhcp_routes(Link *link) {
                 route->in_addr.in = static_routes[i].gw_addr;
                 route->dst_addr.in = static_routes[i].dst_addr;
                 route->dst_prefixlen = static_routes[i].dst_prefixlen;
-                route->metrics = DHCP_ROUTE_METRIC;
+                route->metrics = link->network->dhcp_route_metric;
 
                 r = route_configure(route, link, &dhcp4_route_handler);
                 if (r < 0) {
@@ -575,7 +586,7 @@ int dhcp4_configure(Link *link) {
 
         assert(link);
         assert(link->network);
-        assert(link->network->ipv4ll);
+        assert(IN_SET(link->network->dhcp, DHCP_SUPPORT_BOTH, DHCP_SUPPORT_V4));
 
         r = sd_dhcp_client_new(&link->dhcp_client);
         if (r < 0)