From 4df42cd99d9a484d6045e2b26601f52538237e82 Mon Sep 17 00:00:00 2001 From: Florian Westphal Date: Fri, 4 Sep 2020 01:04:51 +0200 Subject: [PATCH] sd-netlink: add a read function Will be used by nftables nfnetlink backend. It sends a series of netlink messages that form a nftables update transaction. The transaction will then generate a series of ack messages (or an error). This function will be used to read these acks. --- src/libsystemd/sd-netlink/sd-netlink.c | 32 ++++++++++++++++++-------- src/systemd/sd-netlink.h | 1 + 2 files changed, 23 insertions(+), 10 deletions(-) diff --git a/src/libsystemd/sd-netlink/sd-netlink.c b/src/libsystemd/sd-netlink/sd-netlink.c index 5a8b4d9322..ceb8333cbe 100644 --- a/src/libsystemd/sd-netlink/sd-netlink.c +++ b/src/libsystemd/sd-netlink/sd-netlink.c @@ -621,21 +621,15 @@ int sd_netlink_call_async( return k; } -int sd_netlink_call(sd_netlink *rtnl, - sd_netlink_message *message, - uint64_t usec, - sd_netlink_message **ret) { +int sd_netlink_read(sd_netlink *rtnl, + uint32_t serial, + uint64_t usec, + sd_netlink_message **ret) { usec_t timeout; - uint32_t serial; int r; assert_return(rtnl, -EINVAL); assert_return(!rtnl_pid_changed(rtnl), -ECHILD); - assert_return(message, -EINVAL); - - r = sd_netlink_send(rtnl, message, &serial); - if (r < 0) - return r; timeout = calc_elapse(usec); @@ -705,6 +699,24 @@ int sd_netlink_call(sd_netlink *rtnl, } } +int sd_netlink_call(sd_netlink *rtnl, + sd_netlink_message *message, + uint64_t usec, + sd_netlink_message **ret) { + uint32_t serial; + int r; + + assert_return(rtnl, -EINVAL); + assert_return(!rtnl_pid_changed(rtnl), -ECHILD); + assert_return(message, -EINVAL); + + r = sd_netlink_send(rtnl, message, &serial); + if (r < 0) + return r; + + return sd_netlink_read(rtnl, serial, usec, ret); +} + int sd_netlink_get_events(const sd_netlink *rtnl) { assert_return(rtnl, -EINVAL); assert_return(!rtnl_pid_changed(rtnl), -ECHILD); diff --git a/src/systemd/sd-netlink.h b/src/systemd/sd-netlink.h index 2b52c4ca88..41a7d89b60 100644 --- a/src/systemd/sd-netlink.h +++ b/src/systemd/sd-netlink.h @@ -66,6 +66,7 @@ int sd_netlink_call_async(sd_netlink *nl, sd_netlink_slot **ret_slot, sd_netlink void *userdata, uint64_t usec, const char *description); int sd_netlink_call(sd_netlink *nl, sd_netlink_message *message, uint64_t timeout, sd_netlink_message **reply); +int sd_netlink_read(sd_netlink *nl, uint32_t serial, uint64_t timeout, sd_netlink_message **reply); int sd_netlink_get_events(const sd_netlink *nl); int sd_netlink_get_timeout(const sd_netlink *nl, uint64_t *timeout);