summaryrefslogtreecommitdiff
path: root/src/network/networkd-address-label.c
diff options
context:
space:
mode:
authorYu Watanabe <watanabe.yu+github@gmail.com>2022-02-28 09:20:42 +0900
committerYu Watanabe <watanabe.yu+github@gmail.com>2022-03-11 14:20:31 +0900
commit80d62d4f1aa62c03828e4cbe2c2dfb2a19765af8 (patch)
tree33e0ee22b8f8e36836a585cf09e89523a4d01266 /src/network/networkd-address-label.c
parente26d3d407cbdf9138139ca9526573c494ed55e81 (diff)
downloadsystemd-80d62d4f1aa62c03828e4cbe2c2dfb2a19765af8.tar.gz
network: introduce request_call_netlink_async()
In most netlink handlers, we do the following, 1. decrease the message counter, 2. check the link state, 3. error handling, 4. update link state via e.g. link_check_ready(). The first two steps are mostly common, hence let's extract it. Moreover, this is not only extracting the common logic, but provide a strong advantage; `request_call_netlink_async()` assigns the relevant Request object to the userdata of the netlink slot, and the request object has full information about the message we sent. Hence, in the future, netlink handler can print more detailed error message. E.g. when an address is failed to configure, then currently we only show an address is failed to configure, but with this commit, potentially we can show which address is failed explicitly. This does not change such error handling yet. But let's do that later.
Diffstat (limited to 'src/network/networkd-address-label.c')
-rw-r--r--src/network/networkd-address-label.c24
1 files changed, 8 insertions, 16 deletions
diff --git a/src/network/networkd-address-label.c b/src/network/networkd-address-label.c
index c165cde092..5c31a44ce4 100644
--- a/src/network/networkd-address-label.c
+++ b/src/network/networkd-address-label.c
@@ -65,19 +65,17 @@ static int address_label_new_static(Network *network, const char *filename, unsi
return 0;
}
-static int address_label_configure_handler(sd_netlink *rtnl, sd_netlink_message *m, Link *link) {
+static int address_label_configure_handler(
+ sd_netlink *rtnl,
+ sd_netlink_message *m,
+ Request *req,
+ Link *link,
+ void *userdata) {
+
int r;
- assert(rtnl);
assert(m);
assert(link);
- assert(link->ifname);
- assert(link->static_address_label_messages > 0);
-
- link->static_address_label_messages--;
-
- if (IN_SET(link->state, LINK_STATE_FAILED, LINK_STATE_LINGER))
- return 1;
r = sd_netlink_message_get_errno(m);
if (r < 0 && r != -EEXIST) {
@@ -123,13 +121,7 @@ static int address_label_configure(AddressLabel *label, Link *link, Request *req
if (r < 0)
return r;
- r = netlink_call_async(link->manager->rtnl, NULL, m, req->netlink_handler,
- link_netlink_destroy_callback, link);
- if (r < 0)
- return r;
-
- link_ref(link);
- return 0;
+ return request_call_netlink_async(link->manager->rtnl, m, req);
}
int address_label_process_request(Request *req, Link *link, void *userdata) {