summaryrefslogtreecommitdiff
path: root/src/network/networkd-link.c
diff options
context:
space:
mode:
authorTom Gundersen <teg@jklm.no>2015-10-26 12:29:37 +0100
committerTom Gundersen <teg@jklm.no>2015-10-30 12:32:49 +0100
commitf833694d4f6a6dffabc6a4e552ecbd40aa3ce479 (patch)
treecae41cb509957b305446c0c3921b35b1497d0b10 /src/network/networkd-link.c
parentf703cc2c5756088605a37d7d9a9b84e719b667f5 (diff)
networkd: route - add expiration support
This should really live in the kernel, but the netlink API currently does not support it. Until support has been added, expire the route from userspace.
Diffstat (limited to 'src/network/networkd-link.c')
-rw-r--r--src/network/networkd-link.c30
1 files changed, 24 insertions, 6 deletions
diff --git a/src/network/networkd-link.c b/src/network/networkd-link.c
index 9beaa7822b..7316a08d29 100644
--- a/src/network/networkd-link.c
+++ b/src/network/networkd-link.c
@@ -26,6 +26,7 @@
#include "alloc-util.h"
#include "bus-util.h"
#include "dhcp-lease-internal.h"
+#include "event-util.h"
#include "fd-util.h"
#include "fileio.h"
#include "netlink-util.h"
@@ -2227,6 +2228,9 @@ network_file_fail:
return log_oom();
STRV_FOREACH(route_str, routes_strv) {
+ Route *route;
+ _cleanup_event_source_unref_ sd_event_source *expire = NULL;
+ usec_t lifetime;
char *prefixlen_str;
int family;
unsigned char prefixlen, tos, table;
@@ -2240,9 +2244,11 @@ network_file_fail:
*prefixlen_str ++ = '\0';
- r = sscanf(prefixlen_str, "%hhu/%hhu/%"SCNu32"/%hhu", &prefixlen, &tos, &priority, &table);
- if (r != 4) {
- log_link_debug(link, "Failed to parse destination prefix length, tos, priority or table %s", prefixlen_str);
+ r = sscanf(prefixlen_str, "%hhu/%hhu/%"SCNu32"/%hhu/"USEC_FMT, &prefixlen, &tos, &priority, &table, &lifetime);
+ if (r != 5) {
+ log_link_debug(link,
+ "Failed to parse destination prefix length, tos, priority, table or expiration %s",
+ prefixlen_str);
continue;
}
@@ -2252,9 +2258,21 @@ network_file_fail:
continue;
}
- r = route_add(link, family, &route_dst, prefixlen, tos, priority, table, NULL);
+ r = route_add(link, family, &route_dst, prefixlen, tos, priority, table, &route);
if (r < 0)
return log_link_error_errno(link, r, "Failed to add route: %m");
+
+ if (lifetime != USEC_INFINITY) {
+ r = sd_event_add_time(link->manager->event, &expire, clock_boottime_or_monotonic(), 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 = expire;
+ expire = NULL;
}
}
@@ -2741,8 +2759,8 @@ int link_save(Link *link) {
if (r < 0)
goto fail;
- fprintf(f, "%s%s/%hhu/%hhu/%"PRIu32"/%hhu", space ? " " : "", route_str,
- route->dst_prefixlen, route->tos, route->priority, route->table);
+ fprintf(f, "%s%s/%hhu/%hhu/%"PRIu32"/%hhu/"USEC_FMT, space ? " " : "", route_str,
+ route->dst_prefixlen, route->tos, route->priority, route->table, route->lifetime);
space = true;
}