Skip to content

Commit

Permalink
Merge pull request systemd#13508 from yuwata/network-route-fix-13506
Browse files Browse the repository at this point in the history
network: takes more route information into hash func
  • Loading branch information
keszybz committed Sep 17, 2019
2 parents 898fc00 + fa3e401 commit 404ca55
Show file tree
Hide file tree
Showing 7 changed files with 163 additions and 249 deletions.
4 changes: 3 additions & 1 deletion src/libsystemd/sd-netlink/netlink-message.c
Original file line number Diff line number Diff line change
Expand Up @@ -577,7 +577,9 @@ static int netlink_message_read_internal(sd_netlink_message *m, unsigned short t

assert(m->n_containers < RTNL_CONTAINER_DEPTH);
assert(m->containers[m->n_containers].attributes);
assert(type < m->containers[m->n_containers].n_attributes);

if (type >= m->containers[m->n_containers].n_attributes)
return -ENODATA;

attribute = &m->containers[m->n_containers].attributes[type];

Expand Down
2 changes: 1 addition & 1 deletion src/network/networkd-dhcp4.c
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ static int link_set_dhcp_routes(Link *link) {
* the addresses now, let's not configure the routes either. */
return 0;

r = set_ensure_allocated(&link->dhcp_routes, &route_full_hash_ops);
r = set_ensure_allocated(&link->dhcp_routes, &route_hash_ops);
if (r < 0)
return log_oom();

Expand Down
56 changes: 30 additions & 26 deletions src/network/networkd-dhcp6.c
Original file line number Diff line number Diff line change
Expand Up @@ -134,22 +134,21 @@ int dhcp6_lease_pd_prefix_lost(sd_dhcp6_client *client, Link* link) {
&lifetime_preferred,
&lifetime_valid) >= 0) {
_cleanup_free_ char *buf = NULL;
Route *route;
_cleanup_(route_freep) Route *route = NULL;

if (pd_prefix_len >= 64)
continue;

(void) in_addr_to_string(AF_INET6, &pd_prefix, &buf);

r = route_add(link, AF_INET6, &pd_prefix, pd_prefix_len, NULL, 0, 0, 0, &route);
if (r < 0) {
log_link_warning_errno(link, r, "Failed to add unreachable route to delete for DHCPv6 delegated subnet %s/%u: %m",
strnull(buf),
pd_prefix_len);
continue;
}
r = route_new(&route);
if (r < 0)
return r;

route_update(route, NULL, 0, NULL, NULL, 0, 0, RTN_UNREACHABLE);
route->family = AF_INET6;
route->dst = pd_prefix;
route->dst_prefixlen = pd_prefix_len;
route->type = RTN_UNREACHABLE;

r = route_remove(route, link, dhcp6_route_remove_handler);
if (r < 0) {
Expand Down Expand Up @@ -290,20 +289,17 @@ static int dhcp6_lease_pd_prefix_acquired(sd_dhcp6_client *client, Link *link) {
strnull(buf), pd_prefix_len);

if (pd_prefix_len < 64) {
uint32_t table;
Route *route;

table = link_get_dhcp_route_table(link);
_cleanup_(route_freep) Route *route = NULL;

r = route_add(link, AF_INET6, &pd_prefix, pd_prefix_len, NULL, 0, 0, table, &route);
if (r < 0) {
log_link_warning_errno(link, r, "Failed to add unreachable route for DHCPv6 delegated subnet %s/%u: %m",
strnull(buf),
pd_prefix_len);
continue;
}
r = route_new(&route);
if (r < 0)
return r;

route_update(route, NULL, 0, NULL, NULL, 0, 0, RTN_UNREACHABLE);
route->family = AF_INET6;
route->dst = pd_prefix;
route->dst_prefixlen = pd_prefix_len;
route->table = link_get_dhcp_route_table(link);
route->type = RTN_UNREACHABLE;

r = route_configure(route, link, dhcp6_route_handler);
if (r < 0) {
Expand Down Expand Up @@ -721,20 +717,23 @@ static int dhcp6_route_add_handler(sd_netlink *nl, sd_netlink_message *m, Link *
}

static int dhcp6_prefix_add(Manager *m, struct in6_addr *addr, Link *link) {
_cleanup_(route_freep) Route *route = NULL;
_cleanup_free_ struct in6_addr *a = NULL;
_cleanup_free_ char *buf = NULL;
Link *assigned_link;
Route *route;
int r;

assert_return(m, -EINVAL);
assert_return(addr, -EINVAL);

r = route_add(link, AF_INET6, (union in_addr_union *) addr, 64,
NULL, 0, 0, 0, &route);
r = route_new(&route);
if (r < 0)
return r;

route->family = AF_INET6;
route->dst.in6 = *addr;
route->dst_prefixlen = 64;

r = route_configure(route, link, dhcp6_route_add_handler);
if (r < 0)
return r;
Expand Down Expand Up @@ -786,8 +785,8 @@ static int dhcp6_prefix_remove_handler(sd_netlink *nl, sd_netlink_message *m, Li
int dhcp6_prefix_remove(Manager *m, struct in6_addr *addr) {
_cleanup_free_ struct in6_addr *a = NULL;
_cleanup_(link_unrefp) Link *l = NULL;
_cleanup_(route_freep) Route *route = NULL;
_cleanup_free_ char *buf = NULL;
Route *route;
int r;

assert_return(m, -EINVAL);
Expand All @@ -798,10 +797,15 @@ int dhcp6_prefix_remove(Manager *m, struct in6_addr *addr) {
return -EINVAL;

(void) sd_radv_remove_prefix(l->radv, addr, 64);
r = route_get(l, AF_INET6, (union in_addr_union *) addr, 64, NULL, 0, 0, 0, &route);

r = route_new(&route);
if (r < 0)
return r;

route->family = AF_INET6;
route->dst.in6 = *addr;
route->dst_prefixlen = 64;

r = route_remove(route, l, dhcp6_prefix_remove_handler);
if (r < 0)
return r;
Expand Down
27 changes: 13 additions & 14 deletions src/network/networkd-link.c
Original file line number Diff line number Diff line change
Expand Up @@ -2444,7 +2444,7 @@ static int link_drop_foreign_config(Link *link) {
continue;

if (link_is_static_route_configured(link, route)) {
r = route_add(link, route->family, &route->dst, route->dst_prefixlen, &route->gw, route->tos, route->priority, route->table, NULL);
r = route_add(link, route, NULL);
if (r < 0)
return r;
} else {
Expand Down Expand Up @@ -2906,7 +2906,6 @@ static int link_load(Link *link) {
*dhcp4_address = NULL,
*ipv4ll_address = NULL;
union in_addr_union address;
union in_addr_union route_dst;
const char *p;
int r;

Expand Down Expand Up @@ -2993,14 +2992,11 @@ static int link_load(Link *link) {
p = routes;

for (;;) {
Route *route;
_cleanup_free_ char *route_str = NULL;
_cleanup_(sd_event_source_unrefp) sd_event_source *expire = NULL;
usec_t lifetime;
_cleanup_(route_freep) Route *tmp = NULL;
_cleanup_free_ char *route_str = NULL;
char *prefixlen_str;
int family;
unsigned char prefixlen, tos, table;
uint32_t priority;
Route *route;

r = extract_first_word(&p, &route_str, NULL, 0);
if (r < 0) {
Expand All @@ -3018,32 +3014,35 @@ static int link_load(Link *link) {

*prefixlen_str++ = '\0';

r = sscanf(prefixlen_str, "%hhu/%hhu/%"SCNu32"/%hhu/"USEC_FMT, &prefixlen, &tos, &priority, &table, &lifetime);
r = route_new(&tmp);
if (r < 0)
return log_oom();

r = sscanf(prefixlen_str, "%hhu/%hhu/%"SCNu32"/%"PRIu32"/"USEC_FMT, &tmp->dst_prefixlen, &tmp->tos, &tmp->priority, &tmp->table, &tmp->lifetime);
if (r != 5) {
log_link_debug(link,
"Failed to parse destination prefix length, tos, priority, table or expiration %s",
prefixlen_str);
continue;
}

r = in_addr_from_string_auto(route_str, &family, &route_dst);
r = in_addr_from_string_auto(route_str, &tmp->family, &tmp->dst);
if (r < 0) {
log_link_debug_errno(link, r, "Failed to parse route destination %s: %m", route_str);
continue;
}

r = route_add(link, family, &route_dst, prefixlen, NULL, tos, priority, table, &route);
r = route_add(link, tmp, &route);
if (r < 0)
return log_link_error_errno(link, r, "Failed to add route: %m");

if (lifetime != USEC_INFINITY && !kernel_route_expiration_supported()) {
r = sd_event_add_time(link->manager->event, &expire, clock_boottime_or_monotonic(), lifetime,
if (route->lifetime != USEC_INFINITY && !kernel_route_expiration_supported()) {
r = sd_event_add_time(link->manager->event, &expire, clock_boottime_or_monotonic(), route->lifetime,
0, route_expire_handler, route);
if (r < 0)
log_link_warning_errno(link, r, "Could not arm route expiration handler: %m");
}

route->lifetime = lifetime;
sd_event_source_unref(route->expire);
route->expire = TAKE_PTR(expire);
}
Expand Down
Loading

0 comments on commit 404ca55

Please sign in to comment.