diff options
author | Yu Watanabe <watanabe.yu+github@gmail.com> | 2022-10-03 05:39:56 +0200 |
---|---|---|
committer | Yu Watanabe <watanabe.yu+github@gmail.com> | 2022-10-03 17:25:14 +0200 |
commit | d4b7631468e0a28da1366d7f2d6f616b35acce70 (patch) | |
tree | d61f54b0ee05398f83da271ace0b6d720dd1a8a8 /src | |
parent | network: ndisc: ignore prefix option with link-local prefix (diff) | |
download | systemd-d4b7631468e0a28da1366d7f2d6f616b35acce70.tar.xz systemd-d4b7631468e0a28da1366d7f2d6f616b35acce70.zip |
network: introduce {address,route}_remove_and_drop()
Preparation for later commits.
Diffstat (limited to 'src')
-rw-r--r-- | src/network/networkd-address.c | 12 | ||||
-rw-r--r-- | src/network/networkd-address.h | 1 | ||||
-rw-r--r-- | src/network/networkd-route.c | 15 | ||||
-rw-r--r-- | src/network/networkd-route.h | 1 |
4 files changed, 29 insertions, 0 deletions
diff --git a/src/network/networkd-address.c b/src/network/networkd-address.c index bb1eedc6f1..60d3c6286e 100644 --- a/src/network/networkd-address.c +++ b/src/network/networkd-address.c @@ -765,6 +765,18 @@ int address_remove(Address *address) { return 0; } +int address_remove_and_drop(Address *address) { + if (!address) + return 0; + + address_cancel_request(address); + + if (address_exists(address)) + return address_remove(address); + + return address_drop(address); +} + bool link_address_is_dynamic(const Link *link, const Address *address) { Route *route; diff --git a/src/network/networkd-address.h b/src/network/networkd-address.h index ef29caf4e7..7a1e44632d 100644 --- a/src/network/networkd-address.h +++ b/src/network/networkd-address.h @@ -78,6 +78,7 @@ Address* address_free(Address *address); int address_get(Link *link, const Address *in, Address **ret); int address_configure_handler_internal(sd_netlink *rtnl, sd_netlink_message *m, Link *link, const char *error_msg); int address_remove(Address *address); +int address_remove_and_drop(Address *address); int address_dup(const Address *src, Address **ret); bool address_is_ready(const Address *a); void address_set_broadcast(Address *a, Link *link); diff --git a/src/network/networkd-route.c b/src/network/networkd-route.c index f1fba4ff42..2b17959ca2 100644 --- a/src/network/networkd-route.c +++ b/src/network/networkd-route.c @@ -781,6 +781,21 @@ int route_remove(Route *route) { return 0; } +int route_remove_and_drop(Route *route) { + if (!route) + return 0; + + route_cancel_request(route, NULL); + + if (route_exists(route)) + return route_remove(route); + + if (route->state == 0) + route_free(route); + + return 0; +} + static void manager_mark_routes(Manager *manager, bool foreign, const Link *except) { Route *route; Link *link; diff --git a/src/network/networkd-route.h b/src/network/networkd-route.h index 071803cefb..5fc76b17f8 100644 --- a/src/network/networkd-route.h +++ b/src/network/networkd-route.h @@ -85,6 +85,7 @@ int route_dup(const Route *src, Route **ret); int route_configure_handler_internal(sd_netlink *rtnl, sd_netlink_message *m, Link *link, const char *error_msg); int route_remove(Route *route); +int route_remove_and_drop(Route *route); int route_get(Manager *manager, Link *link, const Route *in, Route **ret); |