Line data Source code
1 : /* SPDX-License-Identifier: LGPL-2.1+ */
2 : #pragma once
3 :
4 : #include "sd-netlink.h"
5 :
6 : #include "in-addr-util.h"
7 : #include "socket-util.h"
8 : #include "util.h"
9 :
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);
13 :
14 0 : static inline bool rtnl_message_type_is_neigh(uint16_t type) {
15 0 : return IN_SET(type, RTM_NEWNEIGH, RTM_GETNEIGH, RTM_DELNEIGH);
16 : }
17 :
18 36 : static inline bool rtnl_message_type_is_route(uint16_t type) {
19 36 : return IN_SET(type, RTM_NEWROUTE, RTM_GETROUTE, RTM_DELROUTE);
20 : }
21 :
22 57 : static inline bool rtnl_message_type_is_link(uint16_t type) {
23 57 : return IN_SET(type, RTM_NEWLINK, RTM_SETLINK, RTM_GETLINK, RTM_DELLINK);
24 : }
25 :
26 75 : static inline bool rtnl_message_type_is_addr(uint16_t type) {
27 75 : return IN_SET(type, RTM_NEWADDR, RTM_GETADDR, RTM_DELADDR);
28 : }
29 :
30 0 : static inline bool rtnl_message_type_is_addrlabel(uint16_t type) {
31 0 : return IN_SET(type, RTM_NEWADDRLABEL, RTM_DELADDRLABEL, RTM_GETADDRLABEL);
32 : }
33 :
34 0 : static inline bool rtnl_message_type_is_routing_policy_rule(uint16_t type) {
35 0 : return IN_SET(type, RTM_NEWRULE, RTM_DELRULE, RTM_GETRULE);
36 : }
37 :
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);
40 :
41 : int rtnl_log_parse_error(int r);
42 : int rtnl_log_create_error(int r);
43 :
44 : #define netlink_call_async(nl, ret_slot, message, callback, destroy_callback, userdata) \
45 : ({ \
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__); \
52 : })
53 :
54 : #define netlink_add_match(nl, ret_slot, metch, callback, destroy_callback, userdata) \
55 : ({ \
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__); \
62 : })
63 :
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);
|