diff options
author | Lennart Poettering <lennart@poettering.net> | 2018-12-03 17:55:00 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-12-03 17:55:00 +0100 |
commit | a20f73221ad3662690fb08830cda421b6db35600 (patch) | |
tree | 2f2d3e031625621353a12607c31332e5da0469e8 /src/network/networkd-route.c | |
parent | network: drop unnecessary buffers (diff) | |
parent | network: use typesafe netlink_call_async() macro where applicable (diff) | |
download | systemd-a20f73221ad3662690fb08830cda421b6db35600.tar.gz systemd-a20f73221ad3662690fb08830cda421b6db35600.tar.bz2 systemd-a20f73221ad3662690fb08830cda421b6db35600.zip |
Merge pull request #10976 from yuwata/typesafe-netlink-call
netlink: introduce typesafe netlink functions
Diffstat (limited to 'src/network/networkd-route.c')
-rw-r--r-- | src/network/networkd-route.c | 33 |
1 files changed, 26 insertions, 7 deletions
diff --git a/src/network/networkd-route.c b/src/network/networkd-route.c index 74a1d7c02..363ec2e89 100644 --- a/src/network/networkd-route.c +++ b/src/network/networkd-route.c @@ -378,8 +378,25 @@ void route_update(Route *route, route->type = type; } +static int route_remove_handler(sd_netlink *rtnl, sd_netlink_message *m, Link *link) { + int r; + + assert(m); + assert(link); + assert(link->ifname); + + if (IN_SET(link->state, LINK_STATE_FAILED, LINK_STATE_LINGER)) + return 1; + + r = sd_netlink_message_get_errno(m); + if (r < 0 && r != -ESRCH) + log_link_warning_errno(link, r, "Could not drop route: %m"); + + return 1; +} + int route_remove(Route *route, Link *link, - sd_netlink_message_handler_t callback) { + link_netlink_message_handler_t callback) { _cleanup_(sd_netlink_message_unrefp) sd_netlink_message *req = NULL; int r; @@ -454,8 +471,9 @@ int route_remove(Route *route, Link *link, return log_error_errno(r, "Could not append RTA_OIF attribute: %m"); } - r = sd_netlink_call_async(link->manager->rtnl, NULL, req, callback, - link_netlink_destroy_callback, link, 0, __func__); + r = netlink_call_async(link->manager->rtnl, NULL, req, + callback ?: route_remove_handler, + link_netlink_destroy_callback, link); if (r < 0) return log_error_errno(r, "Could not send rtnetlink message: %m"); @@ -470,7 +488,7 @@ int route_expire_handler(sd_event_source *s, uint64_t usec, void *userdata) { assert(route); - r = route_remove(route, route->link, link_route_remove_handler); + r = route_remove(route, route->link, NULL); if (r < 0) log_warning_errno(r, "Could not remove route: %m"); else @@ -482,7 +500,7 @@ int route_expire_handler(sd_event_source *s, uint64_t usec, void *userdata) { int route_configure( Route *route, Link *link, - sd_netlink_message_handler_t callback) { + link_netlink_message_handler_t callback) { _cleanup_(sd_netlink_message_unrefp) sd_netlink_message *req = NULL; _cleanup_(sd_event_source_unrefp) sd_event_source *expire = NULL; @@ -494,6 +512,7 @@ int route_configure( assert(link->manager->rtnl); assert(link->ifindex > 0); assert(IN_SET(route->family, AF_INET, AF_INET6)); + assert(callback); if (route_get(link, route->family, &route->dst, route->dst_prefixlen, route->tos, route->priority, route->table, NULL) <= 0 && set_size(link->routes) >= routes_max()) @@ -635,8 +654,8 @@ int route_configure( if (r < 0) return log_error_errno(r, "Could not append RTA_METRICS attribute: %m"); - r = sd_netlink_call_async(link->manager->rtnl, NULL, req, callback, - link_netlink_destroy_callback, link, 0, __func__); + r = netlink_call_async(link->manager->rtnl, NULL, req, callback, + link_netlink_destroy_callback, link); if (r < 0) return log_error_errno(r, "Could not send rtnetlink message: %m"); |