network: do not create default route for ipv4 link local addressing
authorYu Watanabe <watanabe.yu+github@gmail.com>
Wed, 28 Aug 2019 13:42:33 +0000 (22:42 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Sun, 15 Sep 2019 13:33:11 +0000 (22:33 +0900)
When nspawn container with private network starts, networkd creates
the default route for the interface. The route may cause problem on
the host side, and it can be created with DefaultRouteOnDevice= now.
Hence, this makes networkd not create the route implicitly any more.

Closes #13418.

src/network/networkd-ipv4ll.c
src/network/networkd-link.c
src/network/networkd-link.h
test/test-network/systemd-networkd-tests.py

index e50a315..6216a06 100644 (file)
 
 static int ipv4ll_address_lost(Link *link) {
         _cleanup_(address_freep) Address *address = NULL;
-        _cleanup_(route_freep) Route *route = NULL;
         struct in_addr addr;
         int r;
 
         assert(link);
 
-        link->ipv4ll_route = false;
         link->ipv4ll_address = false;
 
         r = sd_ipv4ll_get_address(link->ipv4ll, &addr);
@@ -40,60 +38,11 @@ static int ipv4ll_address_lost(Link *link) {
         if (r < 0)
                 return r;
 
-        r = route_new(&route);
-        if (r < 0)
-                return log_link_error_errno(link, r, "Could not allocate route: %m");
-
-        route->family = AF_INET;
-        route->scope = RT_SCOPE_LINK;
-        route->priority = IPV4LL_ROUTE_METRIC;
-
-        r = route_remove(route, link, NULL);
-        if (r < 0)
-                return r;
-
         link_check_ready(link);
 
         return 0;
 }
 
-static int ipv4ll_route_handler(sd_netlink *rtnl, sd_netlink_message *m, Link *link) {
-        int r;
-
-        assert(link);
-        assert(!link->ipv4ll_route);
-
-        r = sd_netlink_message_get_errno(m);
-        if (r < 0 && r != -EEXIST) {
-                log_link_error_errno(link, r, "could not set ipv4ll route: %m");
-                link_enter_failed(link);
-                return 1;
-        }
-
-        link->ipv4ll_route = true;
-
-        link_check_ready(link);
-
-        return 1;
-}
-
-static int ipv4ll_route_configure(Link *link) {
-        _cleanup_(route_freep) Route *route = NULL;
-        int r;
-
-        r = route_new(&route);
-        if (r < 0)
-                return r;
-
-        route->family = AF_INET;
-        route->scope = RT_SCOPE_LINK;
-        route->protocol = RTPROT_STATIC;
-        route->priority = IPV4LL_ROUTE_METRIC;
-        route->table = link_get_vrf_table(link);
-
-        return route_configure(route, link, ipv4ll_route_handler);
-}
-
 static int ipv4ll_address_handler(sd_netlink *rtnl, sd_netlink_message *m, Link *link) {
         int r;
 
@@ -109,12 +58,7 @@ static int ipv4ll_address_handler(sd_netlink *rtnl, sd_netlink_message *m, Link
                 (void) manager_rtnl_process_address(rtnl, m, link->manager);
 
         link->ipv4ll_address = true;
-
-        r = ipv4ll_route_configure(link);
-        if (r < 0) {
-                log_link_error_errno(link, r, "Failed to configure ipv4ll route: %m");
-                link_enter_failed(link);
-        }
+        link_check_ready(link);
 
         return 1;
 }
@@ -128,7 +72,6 @@ static int ipv4ll_address_claimed(sd_ipv4ll *ll, Link *link) {
         assert(link);
 
         link->ipv4ll_address = false;
-        link->ipv4ll_route = false;
 
         r = sd_ipv4ll_get_address(ll, &address);
         if (r == -ENOENT)
index f5bb788..a05971c 100644 (file)
@@ -1020,7 +1020,7 @@ void link_check_ready(Link *link) {
 
         if (link_has_carrier(link) || !link->network->configure_without_carrier) {
 
-                if (link_ipv4ll_enabled(link, ADDRESS_FAMILY_IPV4) && !(link->ipv4ll_address && link->ipv4ll_route))
+                if (link_ipv4ll_enabled(link, ADDRESS_FAMILY_IPV4) && !link->ipv4ll_address)
                         return;
 
                 if (link_ipv6ll_enabled(link) &&
@@ -1030,7 +1030,7 @@ void link_check_ready(Link *link) {
                 if ((link_dhcp4_enabled(link) || link_dhcp6_enabled(link)) &&
                     !link->dhcp4_configured &&
                     !link->dhcp6_configured &&
-                    !(link_ipv4ll_enabled(link, ADDRESS_FAMILY_FALLBACK_IPV4) && link->ipv4ll_address && link->ipv4ll_route))
+                    !(link_ipv4ll_enabled(link, ADDRESS_FAMILY_FALLBACK_IPV4) && link->ipv4ll_address))
                         /* When DHCP is enabled, at least one protocol must provide an address, or
                          * an IPv4ll fallback address must be configured. */
                         return;
index 3eff6fb..d364692 100644 (file)
@@ -97,7 +97,6 @@ typedef struct Link {
 
         sd_ipv4ll *ipv4ll;
         bool ipv4ll_address:1;
-        bool ipv4ll_route:1;
 
         bool neighbors_configured;
 
index 374d9cd..dd031de 100755 (executable)
@@ -2892,7 +2892,6 @@ class NetworkdDHCPClientTests(unittest.TestCase, Utilities):
         output = check_output('ip route show vrf vrf99')
         print(output)
         self.assertRegex(output, 'default via 192.168.5.1 dev veth99 proto dhcp src 192.168.5.')
-        self.assertRegex(output, 'default dev veth99 proto static scope link')
         self.assertRegex(output, '169.254.0.0/16 dev veth99 proto kernel scope link src 169.254')
         self.assertRegex(output, '192.168.5.0/24 dev veth99 proto kernel scope link src 192.168.5')
         self.assertRegex(output, '192.168.5.0/24 via 192.168.5.5 dev veth99 proto dhcp')