aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2018-12-03 17:55:00 +0100
committerGitHub <noreply@github.com>2018-12-03 17:55:00 +0100
commita20f73221ad3662690fb08830cda421b6db35600 (patch)
tree2f2d3e031625621353a12607c31332e5da0469e8
parentnetwork: drop unnecessary buffers (diff)
parentnetwork: use typesafe netlink_call_async() macro where applicable (diff)
downloadsystemd-a20f73221ad3662690fb08830cda421b6db35600.tar.gz
systemd-a20f73221ad3662690fb08830cda421b6db35600.tar.bz2
systemd-a20f73221ad3662690fb08830cda421b6db35600.zip
Merge pull request #10976 from yuwata/typesafe-netlink-call
netlink: introduce typesafe netlink functions
-rw-r--r--src/basic/macro.h5
-rw-r--r--src/libsystemd/sd-netlink/netlink-util.h20
-rw-r--r--src/network/netdev/bridge.c7
-rw-r--r--src/network/netdev/geneve.c11
-rw-r--r--src/network/netdev/netdev.c32
-rw-r--r--src/network/netdev/netdev.h8
-rw-r--r--src/network/netdev/wireguard.c2
-rw-r--r--src/network/networkd-address-label.c33
-rw-r--r--src/network/networkd-address-label.h2
-rw-r--r--src/network/networkd-address.c31
-rw-r--r--src/network/networkd-address.h4
-rw-r--r--src/network/networkd-brvlan.c7
-rw-r--r--src/network/networkd-dhcp4.c19
-rw-r--r--src/network/networkd-dhcp6.c20
-rw-r--r--src/network/networkd-fdb.c7
-rw-r--r--src/network/networkd-ipv4ll.c10
-rw-r--r--src/network/networkd-ipv6-proxy-ndp.c7
-rw-r--r--src/network/networkd-link.c147
-rw-r--r--src/network/networkd-link.h7
-rw-r--r--src/network/networkd-manager.c6
-rw-r--r--src/network/networkd-ndisc.c11
-rw-r--r--src/network/networkd-route.c33
-rw-r--r--src/network/networkd-route.h4
-rw-r--r--src/network/networkd-routing-policy-rule.c22
-rw-r--r--src/network/networkd-routing-policy-rule.h6
-rw-r--r--src/systemd/_sd-common.h2
-rw-r--r--src/systemd/sd-bus.h2
-rw-r--r--src/systemd/sd-event.h2
-rw-r--r--src/systemd/sd-netlink.h2
-rw-r--r--src/systemd/sd-resolve.h2
30 files changed, 224 insertions, 247 deletions
diff --git a/src/basic/macro.h b/src/basic/macro.h
index f54f13e4f..80a1d1abb 100644
--- a/src/basic/macro.h
+++ b/src/basic/macro.h
@@ -458,6 +458,11 @@ static inline int __coverity_check__(int condition) {
#endif
#endif
+#define DEFINE_TRIVIAL_DESTRUCTOR(name, type, func) \
+ static inline void name(type *p) { \
+ func(p); \
+ }
+
#define DEFINE_TRIVIAL_CLEANUP_FUNC(type, func) \
static inline void func##p(type *p) { \
if (*p) \
diff --git a/src/libsystemd/sd-netlink/netlink-util.h b/src/libsystemd/sd-netlink/netlink-util.h
index b326ceeca..d2723285a 100644
--- a/src/libsystemd/sd-netlink/netlink-util.h
+++ b/src/libsystemd/sd-netlink/netlink-util.h
@@ -38,3 +38,23 @@ int rtnl_set_link_properties(sd_netlink **rtnl, int ifindex, const char *alias,
int rtnl_log_parse_error(int r);
int rtnl_log_create_error(int r);
+
+#define netlink_call_async(nl, ret_slot, message, callback, destroy_callback, userdata) \
+ ({ \
+ int (*_callback_)(sd_netlink *, sd_netlink_message *, typeof(userdata)) = callback; \
+ void (*_destroy_)(typeof(userdata)) = destroy_callback; \
+ sd_netlink_call_async(nl, ret_slot, message, \
+ (sd_netlink_message_handler_t) _callback_, \
+ (sd_netlink_destroy_t) _destroy_, \
+ userdata, 0, __func__); \
+ })
+
+#define netlink_add_match(nl, ret_slot, metch, callback, destroy_callback, userdata) \
+ ({ \
+ int (*_callback_)(sd_netlink *, sd_netlink_message *, typeof(userdata)) = callback; \
+ void (*_destroy_)(typeof(userdata)) = destroy_callback; \
+ sd_netlink_add_match(nl, ret_slot, match, \
+ (sd_netlink_message_handler_t) _callback_, \
+ (sd_netlink_destroy_t) _destroy_, \
+ userdata, __func__); \
+ })
diff --git a/src/network/netdev/bridge.c b/src/network/netdev/bridge.c
index cb00780b8..0c804adb2 100644
--- a/src/network/netdev/bridge.c
+++ b/src/network/netdev/bridge.c
@@ -9,8 +9,7 @@
#include "vlan-util.h"
/* callback for brige netdev's parameter set */
-static int netdev_bridge_set_handler(sd_netlink *rtnl, sd_netlink_message *m, void *userdata) {
- NetDev *netdev = userdata;
+static int netdev_bridge_set_handler(sd_netlink *rtnl, sd_netlink_message *m, NetDev *netdev) {
int r;
assert(netdev);
@@ -129,8 +128,8 @@ static int netdev_bridge_post_create(NetDev *netdev, Link *link, sd_netlink_mess
if (r < 0)
return log_netdev_error_errno(netdev, r, "Could not append IFLA_INFO_DATA attribute: %m");
- r = sd_netlink_call_async(netdev->manager->rtnl, NULL, req, netdev_bridge_set_handler,
- netdev_destroy_callback, netdev, 0, __func__);
+ r = netlink_call_async(netdev->manager->rtnl, NULL, req, netdev_bridge_set_handler,
+ netdev_destroy_callback, netdev);
if (r < 0)
return log_netdev_error_errno(netdev, r, "Could not send rtnetlink message: %m");
diff --git a/src/network/netdev/geneve.c b/src/network/netdev/geneve.c
index 1742e399b..089bbfea2 100644
--- a/src/network/netdev/geneve.c
+++ b/src/network/netdev/geneve.c
@@ -2,12 +2,14 @@
#include <net/if.h>
+#include "sd-netlink.h"
+
#include "alloc-util.h"
#include "conf-parser.h"
#include "extract-word.h"
#include "geneve.h"
+#include "netlink-util.h"
#include "parse-util.h"
-#include "sd-netlink.h"
#include "string-util.h"
#include "strv.h"
#include "missing.h"
@@ -17,8 +19,7 @@
#define DEFAULT_GENEVE_DESTINATION_PORT 6081
/* callback for geneve netdev's created without a backing Link */
-static int geneve_netdev_create_handler(sd_netlink *rtnl, sd_netlink_message *m, void *userdata) {
- NetDev *netdev = userdata;
+static int geneve_netdev_create_handler(sd_netlink *rtnl, sd_netlink_message *m, NetDev *netdev) {
int r;
assert(netdev);
@@ -136,8 +137,8 @@ static int netdev_geneve_create(NetDev *netdev) {
if (r < 0)
return log_netdev_error_errno(netdev, r, "Could not append IFLA_LINKINFO attribute: %m");
- r = sd_netlink_call_async(netdev->manager->rtnl, NULL, m, geneve_netdev_create_handler,
- netdev_destroy_callback, netdev, 0, __func__);
+ r = netlink_call_async(netdev->manager->rtnl, NULL, m, geneve_netdev_create_handler,
+ netdev_destroy_callback, netdev);
if (r < 0)
return log_netdev_error_errno(netdev, r, "Could not send rtnetlink message: %m");
diff --git a/src/network/netdev/netdev.c b/src/network/netdev/netdev.c
index c3cebe450..f0e9d0024 100644
--- a/src/network/netdev/netdev.c
+++ b/src/network/netdev/netdev.c
@@ -191,14 +191,6 @@ static NetDev *netdev_free(NetDev *netdev) {
DEFINE_TRIVIAL_REF_UNREF_FUNC(NetDev, netdev, netdev_free);
-void netdev_destroy_callback(void *userdata) {
- NetDev *netdev = userdata;
-
- assert(userdata);
-
- netdev_unref(netdev);
-}
-
void netdev_drop(NetDev *netdev) {
if (!netdev || netdev->state == NETDEV_STATE_LINGER)
return;
@@ -242,7 +234,7 @@ static int netdev_enter_failed(NetDev *netdev) {
return 0;
}
-static int netdev_enslave_ready(NetDev *netdev, Link* link, sd_netlink_message_handler_t callback) {
+static int netdev_enslave_ready(NetDev *netdev, Link* link, link_netlink_message_handler_t callback) {
_cleanup_(sd_netlink_message_unrefp) sd_netlink_message *req = NULL;
int r;
@@ -269,8 +261,8 @@ static int netdev_enslave_ready(NetDev *netdev, Link* link, sd_netlink_message_h
if (r < 0)
return log_netdev_error_errno(netdev, r, "Could not append IFLA_MASTER attribute: %m");
- r = sd_netlink_call_async(netdev->manager->rtnl, NULL, req, callback,
- link_netlink_destroy_callback, link, 0, __func__);
+ r = netlink_call_async(netdev->manager->rtnl, NULL, req, callback,
+ link_netlink_destroy_callback, link);
if (r < 0)
return log_netdev_error_errno(netdev, r, "Could not send rtnetlink message: %m");
@@ -314,8 +306,7 @@ static int netdev_enter_ready(NetDev *netdev) {
}
/* callback for netdev's created without a backing Link */
-static int netdev_create_handler(sd_netlink *rtnl, sd_netlink_message *m, void *userdata) {
- NetDev *netdev = userdata;
+static int netdev_create_handler(sd_netlink *rtnl, sd_netlink_message *m, NetDev *netdev) {
int r;
assert(netdev);
@@ -336,7 +327,7 @@ static int netdev_create_handler(sd_netlink *rtnl, sd_netlink_message *m, void *
return 1;
}
-static int netdev_enslave(NetDev *netdev, Link *link, sd_netlink_message_handler_t callback) {
+static int netdev_enslave(NetDev *netdev, Link *link, link_netlink_message_handler_t callback) {
int r;
assert(netdev);
@@ -512,8 +503,7 @@ int netdev_get_mac(const char *ifname, struct ether_addr **ret) {
return 0;
}
-static int netdev_create(NetDev *netdev, Link *link,
- sd_netlink_message_handler_t callback) {
+static int netdev_create(NetDev *netdev, Link *link, link_netlink_message_handler_t callback) {
int r;
assert(netdev);
@@ -580,15 +570,15 @@ static int netdev_create(NetDev *netdev, Link *link,
return log_netdev_error_errno(netdev, r, "Could not append IFLA_LINKINFO attribute: %m");
if (link) {
- r = sd_netlink_call_async(netdev->manager->rtnl, NULL, m, callback,
- link_netlink_destroy_callback, link, 0, __func__);
+ r = netlink_call_async(netdev->manager->rtnl, NULL, m, callback,
+ link_netlink_destroy_callback, link);
if (r < 0)
return log_netdev_error_errno(netdev, r, "Could not send rtnetlink message: %m");
link_ref(link);
} else {
- r = sd_netlink_call_async(netdev->manager->rtnl, NULL, m, netdev_create_handler,
- netdev_destroy_callback, netdev, 0, __func__);
+ r = netlink_call_async(netdev->manager->rtnl, NULL, m, netdev_create_handler,
+ netdev_destroy_callback, netdev);
if (r < 0)
return log_netdev_error_errno(netdev, r, "Could not send rtnetlink message: %m");
@@ -604,7 +594,7 @@ static int netdev_create(NetDev *netdev, Link *link,
}
/* the callback must be called, possibly after a timeout, as otherwise the Link will hang */
-int netdev_join(NetDev *netdev, Link *link, sd_netlink_message_handler_t callback) {
+int netdev_join(NetDev *netdev, Link *link, link_netlink_message_handler_t callback) {
int r;
assert(netdev);
diff --git a/src/network/netdev/netdev.h b/src/network/netdev/netdev.h
index 8c84a4397..bfe109418 100644
--- a/src/network/netdev/netdev.h
+++ b/src/network/netdev/netdev.h
@@ -5,13 +5,13 @@
#include "conf-parser.h"
#include "list.h"
+#include "../networkd-link.h"
#include "time-util.h"
typedef struct netdev_join_callback netdev_join_callback;
-typedef struct Link Link;
struct netdev_join_callback {
- sd_netlink_message_handler_t callback;
+ link_netlink_message_handler_t callback;
Link *link;
LIST_FIELDS(netdev_join_callback, callbacks);
@@ -153,13 +153,13 @@ void netdev_drop(NetDev *netdev);
NetDev *netdev_unref(NetDev *netdev);
NetDev *netdev_ref(NetDev *netdev);
-void netdev_destroy_callback(void *userdata);
+DEFINE_TRIVIAL_DESTRUCTOR(netdev_destroy_callback, NetDev, netdev_unref);
DEFINE_TRIVIAL_CLEANUP_FUNC(NetDev*, netdev_unref);
int netdev_get(Manager *manager, const char *name, NetDev **ret);
int netdev_set_ifindex(NetDev *netdev, sd_netlink_message *newlink);
int netdev_get_mac(const char *ifname, struct ether_addr **ret);
-int netdev_join(NetDev *netdev, Link *link, sd_netlink_message_handler_t cb);
+int netdev_join(NetDev *netdev, Link *link, link_netlink_message_handler_t cb);
const char *netdev_kind_to_string(NetDevKind d) _const_;
NetDevKind netdev_kind_from_string(const char *d) _pure_;
diff --git a/src/network/netdev/wireguard.c b/src/network/netdev/wireguard.c
index d5a0a19e9..7fefef300 100644
--- a/src/network/netdev/wireguard.c
+++ b/src/network/netdev/wireguard.c
@@ -300,7 +300,7 @@ static int wireguard_resolve_handler(sd_resolve_query *q,
return 0;
}
- r = sd_event_source_set_destroy_callback(s, netdev_destroy_callback);
+ r = sd_event_source_set_destroy_callback(s, (sd_event_destroy_t) netdev_destroy_callback);
if (r < 0) {
log_netdev_warning_errno(netdev, r, "Failed to set destroy callback to event source: %m");
return 0;
diff --git a/src/network/networkd-address-label.c b/src/network/networkd-address-label.c
index 691bbf476..94a12f8bf 100644
--- a/src/network/networkd-address-label.c
+++ b/src/network/networkd-address-label.c
@@ -79,10 +79,36 @@ static int address_label_new_static(Network *network, const char *filename, unsi
return 0;
}
+static int address_label_handler(sd_netlink *rtnl, sd_netlink_message *m, Link *link) {
+ int r;
+
+ assert(rtnl);
+ assert(m);
+ assert(link);
+ assert(link->ifname);
+ assert(link->address_label_messages > 0);
+
+ link->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)
+ log_link_warning_errno(link, r, "could not set address label: %m");
+ else if (r >= 0)
+ manager_rtnl_process_address(rtnl, m, link->manager);
+
+ if (link->address_label_messages == 0)
+ log_link_debug(link, "Addresses label set");
+
+ return 1;
+}
+
int address_label_configure(
AddressLabel *label,
Link *link,
- sd_netlink_message_handler_t callback,
+ link_netlink_message_handler_t callback,
bool update) {
_cleanup_(sd_netlink_message_unrefp) sd_netlink_message *req = NULL;
@@ -111,8 +137,9 @@ int address_label_configure(
if (r < 0)
return log_error_errno(r, "Could not append IFA_ADDRESS 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 ?: address_label_handler,
+ link_netlink_destroy_callback, link);
if (r < 0)
return log_error_errno(r, "Could not send rtnetlink message: %m");
diff --git a/src/network/networkd-address-label.h b/src/network/networkd-address-label.h
index da506b2de..6922cb0fa 100644
--- a/src/network/networkd-address-label.h
+++ b/src/network/networkd-address-label.h
@@ -32,7 +32,7 @@ void address_label_free(AddressLabel *label);
DEFINE_TRIVIAL_CLEANUP_FUNC(AddressLabel*, address_label_free);
-int address_label_configure(AddressLabel *address, Link *link, sd_netlink_message_handler_t callback, bool update);
+int address_label_configure(AddressLabel *address, Link *link, link_netlink_message_handler_t callback, bool update);
CONFIG_PARSER_PROTOTYPE(config_parse_address_label);
CONFIG_PARSER_PROTOTYPE(config_parse_address_label_prefix);
diff --git a/src/network/networkd-address.c b/src/network/networkd-address.c
index 09f041602..dce9a73c1 100644
--- a/src/network/networkd-address.c
+++ b/src/network/networkd-address.c
@@ -428,10 +428,27 @@ int address_get(Link *link,
return -ENOENT;
}
+static int address_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 != -EADDRNOTAVAIL)
+ log_link_warning_errno(link, r, "Could not drop address: %m");
+
+ return 1;
+}
+
int address_remove(
Address *address,
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_free_ char *b = NULL;
@@ -465,8 +482,9 @@ int address_remove(
if (r < 0)
return log_error_errno(r, "Could not append IFA_LOCAL 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 ?: address_remove_handler,
+ link_netlink_destroy_callback, link);
if (r < 0)
return log_error_errno(r, "Could not send rtnetlink message: %m");
@@ -539,7 +557,7 @@ static int address_acquire(Link *link, Address *original, Address **ret) {
int address_configure(
Address *address,
Link *link,
- sd_netlink_message_handler_t callback,
+ link_netlink_message_handler_t callback,
bool update) {
_cleanup_(sd_netlink_message_unrefp) sd_netlink_message *req = NULL;
@@ -551,6 +569,7 @@ int address_configure(
assert(link->ifindex > 0);
assert(link->manager);
assert(link->manager->rtnl);
+ assert(callback);
/* If this is a new address, then refuse adding more than the limit */
if (address_get(link, address->family, &address->in_addr, address->prefixlen, NULL) <= 0 &&
@@ -644,8 +663,8 @@ int address_configure(
if (r < 0)
return r;
- 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) {
address_release(address);
return log_error_errno(r, "Could not send rtnetlink message: %m");
diff --git a/src/network/networkd-address.h b/src/network/networkd-address.h
index cd80741cb..4714c07d4 100644
--- a/src/network/networkd-address.h
+++ b/src/network/networkd-address.h
@@ -54,8 +54,8 @@ int address_add(Link *link, int family, const union in_addr_union *in_addr, unsi
int address_get(Link *link, int family, const union in_addr_union *in_addr, unsigned char prefixlen, Address **ret);
int address_update(Address *address, unsigned char flags, unsigned char scope, const struct ifa_cacheinfo *cinfo);
int address_drop(Address *address);
-int address_configure(Address *address, Link *link, sd_netlink_message_handler_t callback, bool update);
-int address_remove(Address *address, Link *link, sd_netlink_message_handler_t callback);
+int address_configure(Address *address, Link *link, link_netlink_message_handler_t callback, bool update);
+int address_remove(Address *address, Link *link, link_netlink_message_handler_t callback);
bool address_equal(Address *a1, Address *a2);
bool address_is_ready(const Address *a);
diff --git a/src/network/networkd-brvlan.c b/src/network/networkd-brvlan.c
index c7ca57d5e..1d18e29b7 100644
--- a/src/network/networkd-brvlan.c
+++ b/src/network/networkd-brvlan.c
@@ -135,8 +135,7 @@ static int append_vlan_info_data(Link *const link, sd_netlink_message *req, uint
return cnt;
}
-static int set_brvlan_handler(sd_netlink *rtnl, sd_netlink_message *m, void *userdata) {
- Link *link = userdata;
+static int set_brvlan_handler(sd_netlink *rtnl, sd_netlink_message *m, Link *link) {
int r;
assert(link);
@@ -195,8 +194,8 @@ int br_vlan_configure(Link *link, uint16_t pvid, uint32_t *br_vid_bitmap, uint32
return log_link_error_errno(link, r, "Could not close IFLA_AF_SPEC container: %m");
/* send message to the kernel */
- r = sd_netlink_call_async(rtnl, NULL, req, set_brvlan_handler,
- link_netlink_destroy_callback, link, 0, __func__);
+ r = netlink_call_async(rtnl, NULL, req, set_brvlan_handler,
+ link_netlink_destroy_callback, link);
if (r < 0)
return log_link_error_errno(link, r, "Could not send rtnetlink message: %m");
diff --git a/src/network/networkd-dhcp4.c b/src/network/networkd-dhcp4.c
index 597791e02..31dbea942 100644
--- a/src/network/networkd-dhcp4.c
+++ b/src/network/networkd-dhcp4.c
@@ -14,9 +14,7 @@
#include "string-util.h"
#include "sysctl-util.h"
-static int dhcp4_route_handler(sd_netlink *rtnl, sd_netlink_message *m,
- void *userdata) {
- Link *link = userdata;
+static int dhcp4_route_handler(sd_netlink *rtnl, sd_netlink_message *m, Link *link) {
int r;
assert(link);
@@ -216,8 +214,7 @@ static int dhcp_lease_lost(Link *link) {
assert_se(sd_dhcp_route_get_destination(routes[i], &route->dst.in) >= 0);
assert_se(sd_dhcp_route_get_destination_prefix_length(routes[i], &route->dst_prefixlen) >= 0);
- route_remove(route, link,
- link_route_remove_handler);
+ route_remove(route, link, NULL);
}
}
}
@@ -237,8 +234,7 @@ static int dhcp_lease_lost(Link *link) {
route_gw->dst_prefixlen = 32;
route_gw->scope = RT_SCOPE_LINK;
- route_remove(route_gw, link,
- link_route_remove_handler);
+ route_remove(route_gw, link, NULL);
}
r = route_new(&route);
@@ -246,8 +242,7 @@ static int dhcp_lease_lost(Link *link) {
route->family = AF_INET;
route->gw.in = gateway;
- route_remove(route, link,
- link_route_remove_handler);
+ route_remove(route, link, NULL);
}
}
@@ -261,7 +256,7 @@ static int dhcp_lease_lost(Link *link) {
address->in_addr.in = addr;
address->prefixlen = prefixlen;
- address_remove(address, link, link_address_remove_handler);
+ address_remove(address, link, NULL);
}
}
@@ -303,9 +298,7 @@ static int dhcp_lease_lost(Link *link) {
return 0;
}
-static int dhcp4_address_handler(sd_netlink *rtnl, sd_netlink_message *m,
- void *userdata) {
- Link *link = userdata;
+static int dhcp4_address_handler(sd_netlink *rtnl, sd_netlink_message *m, Link *link) {
int r;
assert(link);
diff --git a/src/network/networkd-dhcp6.c b/src/network/networkd-dhcp6.c
index 40b8780e5..4b5c4b8b4 100644
--- a/src/network/networkd-dhcp6.c
+++ b/src/network/networkd-dhcp6.c
@@ -24,13 +24,9 @@ static bool dhcp6_get_prefix_delegation(Link *link) {
if (!link->network)
return false;
- if (!IN_SET(link->network->router_prefix_delegation,
- RADV_PREFIX_DELEGATION_DHCP6,
- RADV_PREFIX_DELEGATION_BOTH)) {
- return false;
- }
-
- return true;
+ return IN_SET(link->network->router_prefix_delegation,
+ RADV_PREFIX_DELEGATION_DHCP6,
+ RADV_PREFIX_DELEGATION_BOTH);
}
static bool dhcp6_enable_prefix_delegation(Link *dhcp6_link) {
@@ -100,8 +96,7 @@ static int dhcp6_pd_prefix_assign(Link *link, struct in6_addr *prefix,
return sd_radv_start(radv);
}
-static int dhcp6_route_remove_handler(sd_netlink *nl, sd_netlink_message *m, void *userdata) {
- Link *link = userdata;
+static int dhcp6_route_remove_handler(sd_netlink *nl, sd_netlink_message *m, Link *link) {
int r;
assert(link);
@@ -247,8 +242,7 @@ static int dhcp6_pd_prefix_distribute(Link *dhcp6_link, Iterator *i,
return 0;
}
-static int dhcp6_route_handler(sd_netlink *nl, sd_netlink_message *m, void *userdata) {
- Link *link = userdata;
+static int dhcp6_route_handler(sd_netlink *nl, sd_netlink_message *m, Link *link) {
int r;
assert(link);
@@ -406,9 +400,7 @@ int dhcp6_request_prefix_delegation(Link *link) {
return 0;
}
-static int dhcp6_address_handler(sd_netlink *rtnl, sd_netlink_message *m,
- void *userdata) {
- Link *link = userdata;
+static int dhcp6_address_handler(sd_netlink *rtnl, sd_netlink_message *m, Link *link) {
int r;
assert(link);
diff --git a/src/network/networkd-fdb.c b/src/network/networkd-fdb.c
index c7742a93f..324f6a5a1 100644
--- a/src/network/networkd-fdb.c
+++ b/src/network/networkd-fdb.c
@@ -87,8 +87,7 @@ int fdb_entry_new_static(
return 0;
}
-static int set_fdb_handler(sd_netlink *rtnl, sd_netlink_message *m, void *userdata) {
- Link *link = userdata;
+static int set_fdb_handler(sd_netlink *rtnl, sd_netlink_message *m, Link *link) {
int r;
assert(link);
@@ -147,8 +146,8 @@ int fdb_entry_configure(Link *link, FdbEntry *fdb_entry) {
}
/* send message to the kernel to update its internal static MAC table. */
- r = sd_netlink_call_async(rtnl, NULL, req, set_fdb_handler,
- link_netlink_destroy_callback, link, 0, __func__);
+ r = netlink_call_async(rtnl, NULL, req, set_fdb_handler,
+ link_netlink_destroy_callback, link);
if (r < 0)
return log_link_error_errno(link, r, "Could not send rtnetlink message: %m");
diff --git a/src/network/networkd-ipv4ll.c b/src/network/networkd-ipv4ll.c
index 0f333175d..3562e9053 100644
--- a/src/network/networkd-ipv4ll.c
+++ b/src/network/networkd-ipv4ll.c
@@ -34,7 +34,7 @@ static int ipv4ll_address_lost(Link *link) {
address->prefixlen = 16;
address->scope = RT_SCOPE_LINK;
- address_remove(address, link, link_address_remove_handler);
+ address_remove(address, link, NULL);
r = route_new(&route);
if (r < 0)
@@ -44,15 +44,14 @@ static int ipv4ll_address_lost(Link *link) {
route->scope = RT_SCOPE_LINK;
route->priority = IPV4LL_ROUTE_METRIC;
- route_remove(route, link, link_route_remove_handler);
+ route_remove(route, link, NULL);
link_check_ready(link);
return 0;
}
-static int ipv4ll_route_handler(sd_netlink *rtnl, sd_netlink_message *m, void *userdata) {
- Link *link = userdata;
+static int ipv4ll_route_handler(sd_netlink *rtnl, sd_netlink_message *m, Link *link) {
int r;
assert(link);
@@ -72,8 +71,7 @@ static int ipv4ll_route_handler(sd_netlink *rtnl, sd_netlink_message *m, void *u
return 1;
}
-static int ipv4ll_address_handler(sd_netlink *rtnl, sd_netlink_message *m, void *userdata) {
- Link *link = userdata;
+static int ipv4ll_address_handler(sd_netlink *rtnl, sd_netlink_message *m, Link *link) {
int r;
assert(link);
diff --git a/src/network/networkd-ipv6-proxy-ndp.c b/src/network/networkd-ipv6-proxy-ndp.c
index 8d58406c3..f594b27f7 100644
--- a/src/network/networkd-ipv6-proxy-ndp.c
+++ b/src/network/networkd-ipv6-proxy-ndp.c
@@ -135,8 +135,7 @@ int config_parse_ipv6_proxy_ndp_address(
return 0;
}
-static int set_ipv6_proxy_ndp_address_handler(sd_netlink *rtnl, sd_netlink_message *m, void *userdata) {
- Link *link = userdata;
+static int set_ipv6_proxy_ndp_address_handler(sd_netlink *rtnl, sd_netlink_message *m, Link *link) {
int r;
assert(link);
@@ -174,8 +173,8 @@ int ipv6_proxy_ndp_address_configure(Link *link, IPv6ProxyNDPAddress *ipv6_proxy
if (r < 0)
return rtnl_log_create_error(r);
- r = sd_netlink_call_async(rtnl, NULL, req, set_ipv6_proxy_ndp_address_handler,
- link_netlink_destroy_callback, link, 0, __func__);
+ r = netlink_call_async(rtnl, NULL, req, set_ipv6_proxy_ndp_address_handler,
+ link_netlink_destroy_callback, link);
if (r < 0)
return log_link_error_errno(link, r, "Could not send rtnetlink message: %m");
diff --git a/src/network/networkd-link.c b/src/network/networkd-link.c
index 2c18bcef1..5296f687a 100644
--- a/src/network/networkd-link.c
+++ b/src/network/networkd-link.c
@@ -592,14 +592,6 @@ static Link *link_free(Link *link) {
DEFINE_TRIVIAL_REF_UNREF_FUNC(Link, link, link_free);
-void link_netlink_destroy_callback(void *userdata) {
- Link *link = userdata;
-
- assert(userdata);
-
- link_unref(link);
-}
-
int link_get(Manager *m, int ifindex, Link **ret) {
Link *link;
@@ -803,7 +795,7 @@ static int link_set_routing_policy_rule(Link *link) {
continue;
}
- r = routing_policy_rule_configure(rule, link, link_routing_policy_rule_handler, false);
+ r = routing_policy_rule_configure(rule, link, NULL, false);
if (r < 0) {
log_link_warning_errno(link, r, "Could not set routing policy rules: %m");
link_enter_failed(link);
@@ -823,8 +815,7 @@ static int link_set_routing_policy_rule(Link *link) {
return 0;
}
-static int route_handler(sd_netlink *rtnl, sd_netlink_message *m, void *userdata) {
- Link *link = userdata;
+static int route_handler(sd_netlink *rtnl, sd_netlink_message *m, Link *link) {
int r;
assert(link);
@@ -894,26 +885,7 @@ static int link_enter_set_routes(Link *link) {
return 0;
}
-int link_route_remove_handler(sd_netlink *rtnl, sd_netlink_message *m, void *userdata) {
- Link *link = userdata;
- 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;
-}
-
-static int address_handler(sd_netlink *rtnl, sd_netlink_message *m, void *userdata) {
- Link *link = userdata;
+static int address_handler(sd_netlink *rtnl, sd_netlink_message *m, Link *link) {
int r;
assert(rtnl);
@@ -943,33 +915,6 @@ static int address_handler(sd_netlink *rtnl, sd_netlink_message *m, void *userda
return 1;
}
-static int address_label_handler(sd_netlink *rtnl, sd_netlink_message *m, void *userdata) {
- Link *link = userdata;
- int r;
-
- assert(rtnl);
- assert(m);
- assert(link);
- assert(link->ifname);
- assert(link->address_label_messages > 0);
-
- link->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)
- log_link_warning_errno(link, r, "could not set address label: %m");
- else if (r >= 0)
- manager_rtnl_process_address(rtnl, m, link->manager);
-
- if (link->address_label_messages == 0)
- log_link_debug(link, "Addresses label set");
-
- return 1;
-}
-
static int link_push_uplink_dns_to_dhcp_server(Link *link, sd_dhcp_server *s) {
_cleanup_free_ struct in_addr *addresses = NULL;
size_t n_addresses = 0, n_allocated = 0;
@@ -1108,7 +1053,7 @@ static int link_enter_set_addresses(Link *link) {
}
LIST_FOREACH(labels, label, link->network->address_labels) {
- r = address_label_configure(label, link, address_label_handler, false);
+ r = address_label_configure(label, link, NULL, false);
if (r < 0) {
log_link_warning_errno(link, r, "Could not set address label: %m");
link_enter_failed(link);
@@ -1243,24 +1188,6 @@ static int link_enter_set_addresses(Link *link) {
return 0;
}
-int link_address_remove_handler(sd_netlink *rtnl, sd_netlink_message *m, void *userdata) {
- Link *link = userdata;
- 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 != -EADDRNOTAVAIL)
- log_link_warning_errno(link, r, "Could not drop address: %m");
-
- return 1;
-}
-
static int link_set_bridge_vlan(Link *link) {
int r = 0;
@@ -1287,8 +1214,7 @@ static int link_set_proxy_arp(Link *link) {
return 0;
}
-static int link_set_handler(sd_netlink *rtnl, sd_netlink_message *m, void *userdata) {
- Link *link = userdata;
+static int link_set_handler(sd_netlink *rtnl, sd_netlink_message *m, Link *link) {
int r;
assert(link);
@@ -1306,8 +1232,7 @@ static int link_set_handler(sd_netlink *rtnl, sd_netlink_message *m, void *userd
static int link_configure_after_setting_mtu(Link *link);
-static int set_mtu_handler(sd_netlink *rtnl, sd_netlink_message *m, void *userdata) {
- Link *link = userdata;
+static int set_mtu_handler(sd_netlink *rtnl, sd_netlink_message *m, Link *link) {
int r;
assert(m);
@@ -1368,8 +1293,8 @@ int link_set_mtu(Link *link, uint32_t mtu) {
if (r < 0)
return log_link_error_errno(link, r, "Could not append MTU: %m");
- r = sd_netlink_call_async(link->manager->rtnl, NULL, req, set_mtu_handler,
- link_netlink_destroy_callback, link, 0, __func__);
+ r = netlink_call_async(link->manager->rtnl, NULL, req, set_mtu_handler,
+ link_netlink_destroy_callback, link);
if (r < 0)
return log_link_error_errno(link, r, "Could not send rtnetlink message: %m");
@@ -1379,8 +1304,7 @@ int link_set_mtu(Link *link, uint32_t mtu) {
return 0;
}
-static int set_flags_handler(sd_netlink *rtnl, sd_netlink_message *m, void *userdata) {
- Link *link = userdata;
+static int set_flags_handler(sd_netlink *rtnl, sd_netlink_message *m, Link *link) {
int r;
assert(m);
@@ -1439,8 +1363,8 @@ static int link_set_flags(Link *link) {
if (r < 0)
return log_link_error_errno(link, r, "Could not set link flags: %m");
- r = sd_netlink_call_async(link->manager->rtnl, NULL, req, set_flags_handler,
- link_netlink_destroy_callback, link, 0, __func__);
+ r = netlink_call_async(link->manager->rtnl, NULL, req, set_flags_handler,
+ link_netlink_destroy_callback, link);
if (r < 0)
return log_link_error_errno(link, r, "Could not send rtnetlink message: %m");
@@ -1515,8 +1439,8 @@ static int link_set_bridge(Link *link) {
if (r < 0)
return log_link_error_errno(link, r, "Could not append IFLA_LINKINFO attribute: %m");
- r = sd_netlink_call_async(link->manager->rtnl, NULL, req, link_set_handler,
- link_netlink_destroy_callback, link, 0, __func__);
+ r = netlink_call_async(link->manager->rtnl, NULL, req, link_set_handler,
+ link_netlink_destroy_callback, link);
if (r < 0)
return log_link_error_errno(link, r, "Could not send rtnetlink message: %m");
@@ -1568,8 +1492,8 @@ static int link_bond_set(Link *link) {
if (r < 0)
return log_link_error_errno(link, r, "Could not append IFLA_INFO_DATA attribute: %m");
- r = sd_netlink_call_async(link->manager->rtnl, NULL, req, set_flags_handler,
- link_netlink_destroy_callback, link, 0, __func__);
+ r = netlink_call_async(link->manager->rtnl, NULL, req, set_flags_handler,
+ link_netlink_destroy_callback, link);
if (r < 0)
return log_link_error_errno(link, r, "Could not send rtnetlink message: %m");
@@ -1768,8 +1692,7 @@ bool link_has_carrier(Link *link) {
return false;
}
-static int link_up_handler(sd_netlink *rtnl, sd_netlink_message *m, void *userdata) {
- Link *link = userdata;
+static int link_up_handler(sd_netlink *rtnl, sd_netlink_message *m, Link *link) {
int r;
assert(link);
@@ -1861,8 +1784,8 @@ int link_up(Link *link) {
if (r < 0)
return log_link_error_errno(link, r, "Could not close IFLA_AF_SPEC container: %m");
- r = sd_netlink_call_async(link->manager->rtnl, NULL, req, link_up_handler,
- link_netlink_destroy_callback, link, 0, __func__);
+ r = netlink_call_async(link->manager->rtnl, NULL, req, link_up_handler,
+ link_netlink_destroy_callback, link);
if (r < 0)
return log_link_error_errno(link, r, "Could not send rtnetlink message: %m");
@@ -1887,8 +1810,8 @@ static int link_up_can(Link *link) {
if (r < 0)
return log_link_error_errno(link, r, "Could not set link flags: %m");
- r = sd_netlink_call_async(link->manager->rtnl, NULL, req, link_up_handler,
- link_netlink_destroy_callback, link, 0, __func__);
+ r = netlink_call_async(link->manager->rtnl, NULL, req, link_up_handler,
+ link_netlink_destroy_callback, link);
if (r < 0)
return log_link_error_errno(link, r, "Could not send rtnetlink message: %m");
@@ -1977,8 +1900,8 @@ static int link_set_can(Link *link) {
if (r < 0)
return log_link_error_errno(link, r, "Failed to close netlink container: %m");
- r = sd_netlink_call_async(link->manager->rtnl, NULL, m, link_set_handler,
- link_netlink_destroy_callback, link, 0, __func__);
+ r = netlink_call_async(link->manager->rtnl, NULL, m, link_set_handler,
+ link_netlink_destroy_callback, link);
if (r < 0)
return log_link_error_errno(link, r, "Could not send rtnetlink message: %m");
@@ -1997,8 +1920,7 @@ static int link_set_can(Link *link) {
return r;
}
-static int link_down_handler(sd_netlink *rtnl, sd_netlink_message *m, void *userdata) {
- Link *link = userdata;
+static int link_down_handler(sd_netlink *rtnl, sd_netlink_message *m, Link *link) {
int r;
assert(link);
@@ -2035,8 +1957,8 @@ int link_down(Link *link) {
if (r < 0)
return log_link_error_errno(link, r, "Could not set link flags: %m");
- r = sd_netlink_call_async(link->manager->rtnl, NULL, req, link_down_handler,
- link_netlink_destroy_callback, link, 0, __func__);
+ r = netlink_call_async(link->manager->rtnl, NULL, req, link_down_handler,
+ link_netlink_destroy_callback, link);
if (r < 0)
return log_link_error_errno(link, r, "Could not send rtnetlink message: %m");
@@ -2343,8 +2265,7 @@ static int link_joined(Link *link) {
return link_enter_set_addresses(link);
}
-static int netdev_join_handler(sd_netlink *rtnl, sd_netlink_message *m, void *userdata) {
- Link *link = userdata;
+static int netdev_join_handler(sd_netlink *rtnl, sd_netlink_message *m, Link *link) {
int r;
assert(link);
@@ -2693,7 +2614,7 @@ static int link_drop_foreign_config(Link *link) {
if (r < 0)
return log_link_error_errno(link, r, "Failed to add address: %m");
} else {
- r = address_remove(address, link, link_address_remove_handler);
+ r = address_remove(address, link, NULL);
if (r < 0)
return r;
}
@@ -2709,7 +2630,7 @@ static int link_drop_foreign_config(Link *link) {
if (r < 0)
return r;
} else {
- r = route_remove(route, link, link_route_remove_handler);
+ r = route_remove(route, link, NULL);
if (r < 0)
return r;
}
@@ -2729,7 +2650,7 @@ static int link_drop_config(Link *link) {
if (address->family == AF_INET6 && in_addr_is_link_local(AF_INET6, &address->in_addr) == 1)
continue;
- r = address_remove(address, link, link_address_remove_handler);
+ r = address_remove(address, link, NULL);
if (r < 0)
return r;
@@ -2748,7 +2669,7 @@ static int link_drop_config(Link *link) {
if (route->protocol == RTPROT_KERNEL)
continue;
- r = route_remove(route, link, link_route_remove_handler);
+ r = route_remove(route, link, NULL);
if (r < 0)
return r;
}
@@ -3167,8 +3088,8 @@ static int link_initialized_and_synced(Link *link) {
return 1;
}
-static int link_initialized_handler(sd_netlink *rtnl, sd_netlink_message *m, void *userdata) {
- (void) link_initialized_and_synced(userdata);
+static int link_initialized_handler(sd_netlink *rtnl, sd_netlink_message *m, Link *link) {
+ (void) link_initialized_and_synced(link);
return 1;
}
@@ -3201,8 +3122,8 @@ int link_initialized(Link *link, sd_device *device) {
if (r < 0)
return r;
- r = sd_netlink_call_async(link->manager->rtnl, NULL, req, link_initialized_handler,
- link_netlink_destroy_callback, link, 0, __func__);
+ r = netlink_call_async(link->manager->rtnl, NULL, req, link_initialized_handler,
+ link_netlink_destroy_callback, link);
if (r < 0)
return r;
diff --git a/src/network/networkd-link.h b/src/network/networkd-link.h
index 7261b3142..3fdfa55b2 100644
--- a/src/network/networkd-link.h
+++ b/src/network/networkd-link.h
@@ -126,12 +126,14 @@ typedef struct Link {
Hashmap *bound_to_links;
} Link;
+typedef int (*link_netlink_message_handler_t)(sd_netlink*, sd_netlink_message*, Link*);
+
DUID *link_get_duid(Link *link);
int get_product_uuid_handler(sd_bus_message *m, void *userdata, sd_bus_error *ret_error);
Link *link_unref(Link *link);
Link *link_ref(Link *link);
-void link_netlink_destroy_callback(void *userdata);
+DEFINE_TRIVIAL_DESTRUCTOR(link_netlink_destroy_callback, Link, link_unref);
int link_get(Manager *m, int ifindex, Link **ret);
int link_add(Manager *manager, sd_netlink_message *message, Link **ret);
@@ -140,9 +142,6 @@ void link_drop(Link *link);
int link_up(Link *link);
int link_down(Link *link);
-int link_address_remove_handler(sd_netlink *rtnl, sd_netlink_message *m, void *userdata);
-int link_route_remove_handler(sd_netlink *rtnl, sd_netlink_message *m, void *userdata);
-
void link_enter_failed(Link *link);
int link_initialized(Link *link, sd_device *device);
diff --git a/src/network/networkd-manager.c b/src/network/networkd-manager.c
index 2a69e7b0a..fc861aeef 100644
--- a/src/network/networkd-manager.c
+++ b/src/network/networkd-manager.c
@@ -1238,8 +1238,7 @@ Link *manager_dhcp6_prefix_get(Manager *m, struct in6_addr *addr) {
return hashmap_get(m->dhcp6_prefixes, addr);
}
-static int dhcp6_route_add_handler(sd_netlink *nl, sd_netlink_message *m, void *userdata) {
- Link *link = userdata;
+static int dhcp6_route_add_handler(sd_netlink *nl, sd_netlink_message *m, Link *link) {
int r;
assert(link);
@@ -1297,8 +1296,7 @@ int manager_dhcp6_prefix_add(Manager *m, struct in6_addr *addr, Link *link) {
return hashmap_put(m->dhcp6_prefixes, addr, link);
}
-static int dhcp6_route_remove_handler(sd_netlink *nl, sd_netlink_message *m, void *userdata) {
- Link *link = userdata;
+static int dhcp6_route_remove_handler(sd_netlink *nl, sd_netlink_message *m, Link *link) {
int r;
assert(link);
diff --git a/src/network/networkd-ndisc.c b/src/network/networkd-ndisc.c
index 8596db11c..84625f7fa 100644
--- a/src/network/networkd-ndisc.c
+++ b/src/network/networkd-ndisc.c
@@ -16,8 +16,7 @@
#define NDISC_RDNSS_MAX 64U
#define NDISC_PREFIX_LFT_MIN 7200U
-static int ndisc_route_handler(sd_netlink *rtnl, sd_netlink_message *m, void *userdata) {
- Link *link = userdata;
+static int ndisc_netlink_message_handler(sd_netlink *rtnl, sd_netlink_message *m, Link *link) {
int r;
assert(link);
@@ -111,7 +110,7 @@ static int ndisc_router_process_default(Link *link, sd_ndisc_router *rt) {
route->lifetime = time_now + lifetime * USEC_PER_SEC;
route->mtu = mtu;
- r = route_configure(route, link, ndisc_route_handler);
+ r = route_configure(route, link, ndisc_netlink_message_handler);
if (r < 0) {
log_link_warning_errno(link, r, "Could not set default route: %m");
link_enter_failed(link);
@@ -199,7 +198,7 @@ static int ndisc_router_process_autonomous_prefix(Link *link, sd_ndisc_router *r
if (address->cinfo.ifa_valid == 0)
return 0;
- r = address_configure(address, link, ndisc_route_handler, true);
+ r = address_configure(address, link, ndisc_netlink_message_handler, true);
if (r < 0) {
log_link_warning_errno(link, r, "Could not set SLAAC address: %m");
link_enter_failed(link);
@@ -249,7 +248,7 @@ static int ndisc_router_process_onlink_prefix(Link *link, sd_ndisc_router *rt) {
if (r < 0)
return log_link_error_errno(link, r, "Failed to get prefix address: %m");
- r = route_configure(route, link, ndisc_route_handler);
+ r = route_configure(route, link, ndisc_netlink_message_handler);
if (r < 0) {
log_link_warning_errno(link, r, "Could not set prefix route: %m");
link_enter_failed(link);
@@ -310,7 +309,7 @@ static int ndisc_router_process_route(Link *link, sd_ndisc_router *rt) {
if (r < 0)
return log_link_error_errno(link, r, "Failed to get route address: %m");
- r = route_configure(route, link, ndisc_route_handler);
+ r = route_configure(route, link, ndisc_netlink_message_handler);
if (r < 0) {
log_link_warning_errno(link, r, "Could not set additional route: %m");
link_enter_failed(link);
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");
diff --git a/src/network/networkd-route.h b/src/network/networkd-route.h
index fe000d61b..4eddf5194 100644
--- a/src/network/networkd-route.h
+++ b/src/network/networkd-route.h
@@ -45,8 +45,8 @@ struct Route {
int route_new_static(Network *network, const char *filename, unsigned section_line, Route **ret);
int route_new(Route **ret);
void route_free(Route *route);
-int route_configure(Route *route, Link *link, sd_netlink_message_handler_t callback);
-int route_remove(Route *route, Link *link, sd_netlink_message_handler_t callback);
+int route_configure(Route *route, Link *link, link_netlink_message_handler_t callback);
+int route_remove(Route *route, Link *link, link_netlink_message_handler_t callback);
int route_get(Link *link, int family, const union in_addr_union *dst, unsigned char dst_prefixlen, unsigned char tos, uint32_t priority, uint32_t table, Route **ret);
int route_add(Link *link, int family, const union in_addr_union *dst, unsigned char dst_prefixlen, unsigned char tos, uint32_t priority, uint32_t table, Route **ret);
diff --git a/src/network/networkd-routing-policy-rule.c b/src/network/networkd-routing-policy-rule.c
index 2df4c9c47..d16cd892b 100644
--- a/src/network/networkd-routing-policy-rule.c
+++ b/src/network/networkd-routing-policy-rule.c
@@ -341,8 +341,7 @@ int routing_policy_rule_add_foreign(Manager *m,
return routing_policy_rule_add_internal(m, &m->rules_foreign, family, from, from_prefixlen, to, to_prefixlen, tos, fwmark, table, iif, oif, protocol, sport, dport, ret);
}
-static int routing_policy_rule_remove_handler(sd_netlink *rtnl, sd_netlink_message *m, void *userdata) {
- Link *link = userdata;
+static int routing_policy_rule_remove_handler(sd_netlink *rtnl, sd_netlink_message *m, Link *link) {
int r;
assert(m);
@@ -361,7 +360,7 @@ static int routing_policy_rule_remove_handler(sd_netlink *rtnl, sd_netlink_messa
return 1;
}
-int routing_policy_rule_remove(RoutingPolicyRule *routing_policy_rule, Link *link, sd_netlink_message_handler_t callback) {
+int routing_policy_rule_remove(RoutingPolicyRule *routing_policy_rule, Link *link, link_netlink_message_handler_t callback) {
_cleanup_(sd_netlink_message_unrefp) sd_netlink_message *m = NULL;
int r;
@@ -404,8 +403,9 @@ int routing_policy_rule_remove(RoutingPolicyRule *routing_policy_rule, Link *lin
return log_error_errno(r, "Could not set destination prefix length: %m");
}
- r = sd_netlink_call_async(link->manager->rtnl, NULL, m, callback,
- link_netlink_destroy_callback, link, 0, __func__);
+ r = netlink_call_async(link->manager->rtnl, NULL, m,
+ callback ?: routing_policy_rule_remove_handler,
+ link_netlink_destroy_callback, link);
if (r < 0)
return log_error_errno(r, "Could not send rtnetlink message: %m");
@@ -461,8 +461,7 @@ static int routing_policy_rule_new_static(Network *network, const char *filename
return 0;
}
-int link_routing_policy_rule_handler(sd_netlink *rtnl, sd_netlink_message *m, void *userdata) {
- Link *link = userdata;
+static int routing_policy_rule_handler(sd_netlink *rtnl, sd_netlink_message *m, Link *link) {
int r;
assert(rtnl);
@@ -489,7 +488,7 @@ int link_routing_policy_rule_handler(sd_netlink *rtnl, sd_netlink_message *m, vo
return 1;
}
-int routing_policy_rule_configure(RoutingPolicyRule *rule, Link *link, sd_netlink_message_handler_t callback, bool update) {
+int routing_policy_rule_configure(RoutingPolicyRule *rule, Link *link, link_netlink_message_handler_t callback, bool update) {
_cleanup_(sd_netlink_message_unrefp) sd_netlink_message *m = NULL;
int r;
@@ -597,8 +596,9 @@ int routing_policy_rule_configure(RoutingPolicyRule *rule, Link *link, sd_netlin
rule->link = link;
- r = sd_netlink_call_async(link->manager->rtnl, NULL, m, callback,
- link_netlink_destroy_callback, link, 0, __func__);
+ r = netlink_call_async(link->manager->rtnl, NULL, m,
+ callback ?: routing_policy_rule_handler,
+ link_netlink_destroy_callback, link);
if (r < 0)
return log_error_errno(r, "Could not send rtnetlink message: %m");
@@ -1223,7 +1223,7 @@ void routing_policy_rule_purge(Manager *m, Link *link) {
existing = set_get(m->rules_foreign, rule);
if (existing) {
- r = routing_policy_rule_remove(rule, link, routing_policy_rule_remove_handler);
+ r = routing_policy_rule_remove(rule, link, NULL);
if (r < 0) {
log_warning_errno(r, "Could not remove routing policy rules: %m");
continue;
diff --git a/src/network/networkd-routing-policy-rule.h b/src/network/networkd-routing-policy-rule.h
index 5665f9979..2114eb4c3 100644
--- a/src/network/networkd-routing-policy-rule.h
+++ b/src/network/networkd-routing-policy-rule.h
@@ -53,10 +53,8 @@ void routing_policy_rule_free(RoutingPolicyRule *rule);
DEFINE_TRIVIAL_CLEANUP_FUNC(RoutingPolicyRule*, routing_policy_rule_free);
-int routing_policy_rule_configure(RoutingPolicyRule *address, Link *link, sd_netlink_message_handler_t callback, bool update);
-int routing_policy_rule_remove(RoutingPolicyRule *routing_policy_rule, Link *link, sd_netlink_message_handler_t callback);
-int link_routing_policy_rule_remove_handler(sd_netlink *rtnl, sd_netlink_message *m, void *userdata);
-int link_routing_policy_rule_handler(sd_netlink *rtnl, sd_netlink_message *m, void *userdata);
+int routing_policy_rule_configure(RoutingPolicyRule *address, Link *link, link_netlink_message_handler_t callback, bool update);
+int routing_policy_rule_remove(RoutingPolicyRule *routing_policy_rule, Link *link, link_netlink_message_handler_t callback);
int routing_policy_rule_add(Manager *m, int family, const union in_addr_union *from, uint8_t from_prefixlen, const union in_addr_union *to, uint8_t to_prefixlen,
uint8_t tos, uint32_t fwmark, uint32_t table, const char *iif, const char *oif, uint8_t protocol, const struct fib_rule_port_range *sport,
diff --git a/src/systemd/_sd-common.h b/src/systemd/_sd-common.h
index b026b5c55..9950339d5 100644
--- a/src/systemd/_sd-common.h
+++ b/src/systemd/_sd-common.h
@@ -23,6 +23,8 @@
# error "Do not include _sd-common.h directly; it is a private header."
#endif
+typedef void (*_sd_destroy_t)(void *userdata);
+
#ifndef _sd_printf_
# if __GNUC__ >= 4
# define _sd_printf_(a,b) __attribute__ ((__format__(printf, a, b)))
diff --git a/src/systemd/sd-bus.h b/src/systemd/sd-bus.h
index 220ddb99e..4c1acab9f 100644
--- a/src/systemd/sd-bus.h
+++ b/src/systemd/sd-bus.h
@@ -107,7 +107,7 @@ typedef int (*sd_bus_property_set_t) (sd_bus *bus, const char *path, const char
typedef int (*sd_bus_object_find_t) (sd_bus *bus, const char *path, const char *interface, void *userdata, void **ret_found, sd_bus_error *ret_error);
typedef int (*sd_bus_node_enumerator_t) (sd_bus *bus, const char *prefix, void *userdata, char ***ret_nodes, sd_bus_error *ret_error);
typedef int (*sd_bus_track_handler_t) (sd_bus_track *track, void *userdata);
-typedef void (*sd_bus_destroy_t)(void *userdata);
+typedef _sd_destroy_t sd_bus_destroy_t;
#include "sd-bus-protocol.h"
#include "sd-bus-vtable.h"
diff --git a/src/systemd/sd-event.h b/src/systemd/sd-event.h
index b15cade20..787a12f24 100644
--- a/src/systemd/sd-event.h
+++ b/src/systemd/sd-event.h
@@ -77,7 +77,7 @@ typedef int (*sd_event_child_handler_t)(sd_event_source *s, const siginfo_t *si,
typedef void* sd_event_child_handler_t;
#endif
typedef int (*sd_event_inotify_handler_t)(sd_event_source *s, const struct inotify_event *event, void *userdata);
-typedef void (*sd_event_destroy_t)(void *userdata);
+typedef _sd_destroy_t sd_event_destroy_t;
int sd_event_default(sd_event **e);
diff --git a/src/systemd/sd-netlink.h b/src/systemd/sd-netlink.h
index e1b89559a..20bff2838 100644
--- a/src/systemd/sd-netlink.h
+++ b/src/systemd/sd-netlink.h
@@ -39,7 +39,7 @@ typedef enum {SD_GENL_ID_CTRL, SD_GENL_WIREGUARD, SD_GENL_FOU} sd_genl_family;
/* callback */
typedef int (*sd_netlink_message_handler_t)(sd_netlink *nl, sd_netlink_message *m, void *userdata);
-typedef void (*sd_netlink_destroy_t)(void *userdata);
+typedef _sd_destroy_t sd_netlink_destroy_t;
/* bus */
int sd_netlink_new_from_netlink(sd_netlink **nl, int fd);
diff --git a/src/systemd/sd-resolve.h b/src/systemd/sd-resolve.h
index 089fcdee3..93a9a8a44 100644
--- a/src/systemd/sd-resolve.h
+++ b/src/systemd/sd-resolve.h
@@ -42,7 +42,7 @@ typedef struct sd_resolve_query sd_resolve_query;
/* A callback on completion */
typedef int (*sd_resolve_getaddrinfo_handler_t)(sd_resolve_query *q, int ret, const struct addrinfo *ai, void *userdata);
typedef int (*sd_resolve_getnameinfo_handler_t)(sd_resolve_query *q, int ret, const char *host, const char *serv, void *userdata);
-typedef void (*sd_resolve_destroy_t)(void *userdata);
+typedef _sd_destroy_t sd_resolve_destroy_t;
enum {
SD_RESOLVE_GET_HOST = 1 << 0,