]>
git.ipfire.org Git - thirdparty/systemd.git/blob - src/libsystemd/sd-netlink/netlink-util.h
1 /* SPDX-License-Identifier: LGPL-2.1+ */
4 #include "sd-netlink.h"
6 #include "in-addr-util.h"
7 #include "socket-util.h"
10 int rtnl_message_new_synthetic_error(sd_netlink
*rtnl
, int error
, uint32_t serial
, sd_netlink_message
**ret
);
11 uint32_t rtnl_message_get_serial(sd_netlink_message
*m
);
12 void rtnl_message_seal(sd_netlink_message
*m
);
14 static inline bool rtnl_message_type_is_neigh(uint16_t type
) {
15 return IN_SET(type
, RTM_NEWNEIGH
, RTM_GETNEIGH
, RTM_DELNEIGH
);
18 static inline bool rtnl_message_type_is_route(uint16_t type
) {
19 return IN_SET(type
, RTM_NEWROUTE
, RTM_GETROUTE
, RTM_DELROUTE
);
22 static inline bool rtnl_message_type_is_link(uint16_t type
) {
23 return IN_SET(type
, RTM_NEWLINK
, RTM_SETLINK
, RTM_GETLINK
, RTM_DELLINK
);
26 static inline bool rtnl_message_type_is_addr(uint16_t type
) {
27 return IN_SET(type
, RTM_NEWADDR
, RTM_GETADDR
, RTM_DELADDR
);
30 static inline bool rtnl_message_type_is_addrlabel(uint16_t type
) {
31 return IN_SET(type
, RTM_NEWADDRLABEL
, RTM_DELADDRLABEL
, RTM_GETADDRLABEL
);
34 static inline bool rtnl_message_type_is_routing_policy_rule(uint16_t type
) {
35 return IN_SET(type
, RTM_NEWRULE
, RTM_DELRULE
, RTM_GETRULE
);
38 int rtnl_set_link_name(sd_netlink
**rtnl
, int ifindex
, const char *name
);
39 int rtnl_set_link_properties(sd_netlink
**rtnl
, int ifindex
, const char *alias
, const struct ether_addr
*mac
, uint32_t mtu
);
41 int rtnl_log_parse_error(int r
);
42 int rtnl_log_create_error(int r
);
44 #define netlink_call_async(nl, ret_slot, message, callback, destroy_callback, userdata) \
46 int (*_callback_)(sd_netlink *, sd_netlink_message *, typeof(userdata)) = callback; \
47 void (*_destroy_)(typeof(userdata)) = destroy_callback; \
48 sd_netlink_call_async(nl, ret_slot, message, \
49 (sd_netlink_message_handler_t) _callback_, \
50 (sd_netlink_destroy_t) _destroy_, \
51 userdata, 0, __func__); \
54 #define netlink_add_match(nl, ret_slot, metch, callback, destroy_callback, userdata) \
56 int (*_callback_)(sd_netlink *, sd_netlink_message *, typeof(userdata)) = callback; \
57 void (*_destroy_)(typeof(userdata)) = destroy_callback; \
58 sd_netlink_add_match(nl, ret_slot, match, \
59 (sd_netlink_message_handler_t) _callback_, \
60 (sd_netlink_destroy_t) _destroy_, \
61 userdata, __func__); \
64 int netlink_message_append_in_addr_union(sd_netlink_message
*m
, unsigned short type
, int family
, const union in_addr_union
*data
);
65 int netlink_message_append_sockaddr_union(sd_netlink_message
*m
, unsigned short type
, const union sockaddr_union
*data
);