Merge pull request #13551 from keszybz/ll-no-default-route

Link local no default route
This commit is contained in:
Zbigniew Jędrzejewski-Szmek
2019-09-16 14:27:41 +02:00
committed by GitHub
7 changed files with 28 additions and 68 deletions
+1 -58
View File
@@ -12,13 +12,11 @@
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)
+2 -2
View 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;
-1
View File
@@ -97,7 +97,6 @@ typedef struct Link {
sd_ipv4ll *ipv4ll;
bool ipv4ll_address:1;
bool ipv4ll_route:1;
bool neighbors_configured;
+10
View File
@@ -914,6 +914,7 @@ static int manager_rtnl_process_link(sd_netlink *rtnl, sd_netlink_message *messa
int manager_rtnl_process_rule(sd_netlink *rtnl, sd_netlink_message *message, void *userdata) {
_cleanup_(routing_policy_rule_freep) RoutingPolicyRule *tmp = NULL;
_cleanup_free_ char *from = NULL, *to = NULL;
RoutingPolicyRule *rule = NULL;
const char *iif = NULL, *oif = NULL;
Manager *m = userdata;
@@ -1094,9 +1095,16 @@ int manager_rtnl_process_rule(sd_netlink *rtnl, sd_netlink_message *message, voi
(void) routing_policy_rule_get(m, tmp, &rule);
if (DEBUG_LOGGING) {
(void) in_addr_to_string(tmp->family, &tmp->from, &from);
(void) in_addr_to_string(tmp->family, &tmp->to, &to);
}
switch (type) {
case RTM_NEWRULE:
if (!rule) {
log_debug("Remembering foreign routing policy rule: %s/%u -> %s/%u, iif: %s, oif: %s, table: %u",
from, tmp->from_prefixlen, to, tmp->to_prefixlen, strna(tmp->iif), strna(tmp->oif), tmp->table);
r = routing_policy_rule_add_foreign(m, tmp, &rule);
if (r < 0) {
log_warning_errno(r, "Could not remember foreign rule, ignoring: %m");
@@ -1105,6 +1113,8 @@ int manager_rtnl_process_rule(sd_netlink *rtnl, sd_netlink_message *message, voi
}
break;
case RTM_DELRULE:
log_debug("Forgetting routing policy rule: %s/%u -> %s/%u, iif: %s, oif: %s, table: %u",
from, tmp->from_prefixlen, to, tmp->to_prefixlen, strna(tmp->iif), strna(tmp->oif), tmp->table);
routing_policy_rule_free(rule);
break;
+5 -6
View File
@@ -680,7 +680,7 @@ int route_configure(
return log_link_error_errno(link, r, "Could not set route family: %m");
}
if (route->dst_prefixlen) {
if (route->dst_prefixlen > 0) {
r = netlink_message_append_in_addr_union(req, RTA_DST, route->family, &route->dst);
if (r < 0)
return log_link_error_errno(link, r, "Could not append RTA_DST attribute: %m");
@@ -690,7 +690,7 @@ int route_configure(
return log_link_error_errno(link, r, "Could not set destination prefix length: %m");
}
if (route->src_prefixlen) {
if (route->src_prefixlen > 0) {
r = netlink_message_append_in_addr_union(req, RTA_SRC, route->family, &route->src);
if (r < 0)
return log_link_error_errno(link, r, "Could not append RTA_SRC attribute: %m");
@@ -876,11 +876,10 @@ int network_add_default_route_on_device(Network *network) {
if (r < 0)
return r;
r = in_addr_from_string(AF_INET, "169.254.0.0", &n->dst);
if (r < 0)
return r;
n->family = AF_INET;
n->scope = RT_SCOPE_LINK;
n->scope_set = true;
n->protocol = RTPROT_STATIC;
TAKE_PTR(n);
return 0;
@@ -453,6 +453,16 @@ int routing_policy_rule_configure(RoutingPolicyRule *rule, Link *link, link_netl
assert(link->manager);
assert(link->manager->rtnl);
if (DEBUG_LOGGING) {
_cleanup_free_ char *from = NULL, *to = NULL;
(void) in_addr_to_string(rule->family, &rule->from, &from);
(void) in_addr_to_string(rule->family, &rule->to, &to);
log_debug("Configuring routing policy rule: %s/%u -> %s/%u, iif: %s, oif: %s, table: %u",
from, rule->from_prefixlen, to, rule->to_prefixlen, strna(rule->iif), strna(rule->oif), rule->table);
}
r = sd_rtnl_message_new_routing_policy_rule(link->manager->rtnl, &m, RTM_NEWRULE, rule->family);
if (r < 0)
return log_error_errno(r, "Could not allocate RTM_NEWRULE message: %m");
@@ -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')