Branch data Line data Source code
1 : : /* SPDX-License-Identifier: LGPL-2.1+ */
2 : : #ifndef foosdnetlinkhfoo
3 : : #define foosdnetlinkhfoo
4 : :
5 : : /***
6 : : systemd is free software; you can redistribute it and/or modify it
7 : : under the terms of the GNU Lesser General Public License as published by
8 : : the Free Software Foundation; either version 2.1 of the License, or
9 : : (at your option) any later version.
10 : :
11 : : systemd is distributed in the hope that it will be useful, but
12 : : WITHOUT ANY WARRANTY; without even the implied warranty of
13 : : MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 : : Lesser General Public License for more details.
15 : :
16 : : You should have received a copy of the GNU Lesser General Public License
17 : : along with systemd; If not, see <http://www.gnu.org/licenses/>.
18 : : ***/
19 : :
20 : : #include <inttypes.h>
21 : : #include <net/ethernet.h>
22 : : #include <netinet/in.h>
23 : : #include <linux/neighbour.h>
24 : : #include <linux/rtnetlink.h>
25 : :
26 : : #include "sd-event.h"
27 : :
28 : : #include "_sd-common.h"
29 : :
30 : : _SD_BEGIN_DECLARATIONS;
31 : :
32 : : typedef struct sd_netlink sd_netlink;
33 : : typedef struct sd_genl_socket sd_genl_socket;
34 : : typedef struct sd_netlink_message sd_netlink_message;
35 : : typedef struct sd_netlink_slot sd_netlink_slot;
36 : :
37 : : typedef enum sd_gen_family {
38 : : SD_GENL_ID_CTRL,
39 : : SD_GENL_WIREGUARD,
40 : : SD_GENL_FOU,
41 : : SD_GENL_L2TP,
42 : : SD_GENL_MACSEC,
43 : : } sd_genl_family;
44 : :
45 : : /* callback */
46 : :
47 : : typedef int (*sd_netlink_message_handler_t)(sd_netlink *nl, sd_netlink_message *m, void *userdata);
48 : : typedef _sd_destroy_t sd_netlink_destroy_t;
49 : :
50 : : /* bus */
51 : : int sd_netlink_new_from_netlink(sd_netlink **nl, int fd);
52 : : int sd_netlink_open(sd_netlink **nl);
53 : : int sd_netlink_open_fd(sd_netlink **nl, int fd);
54 : : int sd_netlink_inc_rcvbuf(sd_netlink *nl, const size_t size);
55 : :
56 : : sd_netlink *sd_netlink_ref(sd_netlink *nl);
57 : : sd_netlink *sd_netlink_unref(sd_netlink *nl);
58 : :
59 : : int sd_netlink_send(sd_netlink *nl, sd_netlink_message *message, uint32_t *serial);
60 : : int sd_netlink_call_async(sd_netlink *nl, sd_netlink_slot **ret_slot, sd_netlink_message *message,
61 : : sd_netlink_message_handler_t callback, sd_netlink_destroy_t destoy_callback,
62 : : void *userdata, uint64_t usec, const char *description);
63 : : int sd_netlink_call(sd_netlink *nl, sd_netlink_message *message, uint64_t timeout,
64 : : sd_netlink_message **reply);
65 : :
66 : : int sd_netlink_get_events(sd_netlink *nl);
67 : : int sd_netlink_get_timeout(sd_netlink *nl, uint64_t *timeout);
68 : : int sd_netlink_process(sd_netlink *nl, sd_netlink_message **ret);
69 : : int sd_netlink_wait(sd_netlink *nl, uint64_t timeout);
70 : :
71 : : int sd_netlink_add_match(sd_netlink *nl, sd_netlink_slot **ret_slot, uint16_t match,
72 : : sd_netlink_message_handler_t callback,
73 : : sd_netlink_destroy_t destroy_callback,
74 : : void *userdata, const char *description);
75 : :
76 : : int sd_netlink_attach_event(sd_netlink *nl, sd_event *e, int64_t priority);
77 : : int sd_netlink_detach_event(sd_netlink *nl);
78 : :
79 : : int sd_netlink_message_append_string(sd_netlink_message *m, unsigned short type, const char *data);
80 : : int sd_netlink_message_append_flag(sd_netlink_message *m, unsigned short type);
81 : : int sd_netlink_message_append_u8(sd_netlink_message *m, unsigned short type, uint8_t data);
82 : : int sd_netlink_message_append_u16(sd_netlink_message *m, unsigned short type, uint16_t data);
83 : : int sd_netlink_message_append_u32(sd_netlink_message *m, unsigned short type, uint32_t data);
84 : : int sd_netlink_message_append_u64(sd_netlink_message *m, unsigned short type, uint64_t data);
85 : : int sd_netlink_message_append_data(sd_netlink_message *m, unsigned short type, const void *data, size_t len);
86 : : int sd_netlink_message_append_in_addr(sd_netlink_message *m, unsigned short type, const struct in_addr *data);
87 : : int sd_netlink_message_append_in6_addr(sd_netlink_message *m, unsigned short type, const struct in6_addr *data);
88 : : int sd_netlink_message_append_sockaddr_in(sd_netlink_message *m, unsigned short type, const struct sockaddr_in *data);
89 : : int sd_netlink_message_append_sockaddr_in6(sd_netlink_message *m, unsigned short type, const struct sockaddr_in6 *data);
90 : : int sd_netlink_message_append_ether_addr(sd_netlink_message *m, unsigned short type, const struct ether_addr *data);
91 : : int sd_netlink_message_append_cache_info(sd_netlink_message *m, unsigned short type, const struct ifa_cacheinfo *info);
92 : :
93 : : int sd_netlink_message_open_container(sd_netlink_message *m, unsigned short type);
94 : : int sd_netlink_message_open_container_union(sd_netlink_message *m, unsigned short type, const char *key);
95 : : int sd_netlink_message_close_container(sd_netlink_message *m);
96 : :
97 : : int sd_netlink_message_read(sd_netlink_message *m, unsigned short type, size_t size, void *data);
98 : : int sd_netlink_message_read_string(sd_netlink_message *m, unsigned short type, const char **data);
99 : : int sd_netlink_message_read_u8(sd_netlink_message *m, unsigned short type, uint8_t *data);
100 : : int sd_netlink_message_read_u16(sd_netlink_message *m, unsigned short type, uint16_t *data);
101 : : int sd_netlink_message_read_u32(sd_netlink_message *m, unsigned short type, uint32_t *data);
102 : : int sd_netlink_message_read_ether_addr(sd_netlink_message *m, unsigned short type, struct ether_addr *data);
103 : : int sd_netlink_message_read_cache_info(sd_netlink_message *m, unsigned short type, struct ifa_cacheinfo *info);
104 : : int sd_netlink_message_read_in_addr(sd_netlink_message *m, unsigned short type, struct in_addr *data);
105 : : int sd_netlink_message_read_in6_addr(sd_netlink_message *m, unsigned short type, struct in6_addr *data);
106 : : int sd_netlink_message_enter_container(sd_netlink_message *m, unsigned short type);
107 : : int sd_netlink_message_enter_array(sd_netlink_message *m, unsigned short type);
108 : : int sd_netlink_message_exit_container(sd_netlink_message *m);
109 : :
110 : : int sd_netlink_message_open_array(sd_netlink_message *m, uint16_t type);
111 : : int sd_netlink_message_cancel_array(sd_netlink_message *m);
112 : :
113 : : int sd_netlink_message_rewind(sd_netlink_message *m);
114 : :
115 : : sd_netlink_message *sd_netlink_message_next(sd_netlink_message *m);
116 : :
117 : : sd_netlink_message *sd_netlink_message_ref(sd_netlink_message *m);
118 : : sd_netlink_message *sd_netlink_message_unref(sd_netlink_message *m);
119 : :
120 : : int sd_netlink_message_request_dump(sd_netlink_message *m, int dump);
121 : : int sd_netlink_message_is_error(sd_netlink_message *m);
122 : : int sd_netlink_message_get_errno(sd_netlink_message *m);
123 : : int sd_netlink_message_get_type(sd_netlink_message *m, uint16_t *type);
124 : : int sd_netlink_message_set_flags(sd_netlink_message *m, uint16_t flags);
125 : : int sd_netlink_message_is_broadcast(sd_netlink_message *m);
126 : :
127 : : /* rtnl */
128 : :
129 : : int sd_rtnl_message_new_link(sd_netlink *nl, sd_netlink_message **ret, uint16_t msg_type, int index);
130 : : int sd_rtnl_message_new_addr_update(sd_netlink *nl, sd_netlink_message **ret, int index, int family);
131 : : int sd_rtnl_message_new_addr(sd_netlink *nl, sd_netlink_message **ret, uint16_t msg_type, int index, int family);
132 : : int sd_rtnl_message_new_route(sd_netlink *nl, sd_netlink_message **ret, uint16_t nlmsg_type, int rtm_family, unsigned char rtm_protocol);
133 : : int sd_rtnl_message_new_neigh(sd_netlink *nl, sd_netlink_message **ret, uint16_t msg_type, int index, int nda_family);
134 : :
135 : : int sd_rtnl_message_get_family(sd_netlink_message *m, int *family);
136 : :
137 : : int sd_rtnl_message_addr_set_prefixlen(sd_netlink_message *m, unsigned char prefixlen);
138 : : int sd_rtnl_message_addr_set_scope(sd_netlink_message *m, unsigned char scope);
139 : : int sd_rtnl_message_addr_set_flags(sd_netlink_message *m, unsigned char flags);
140 : : int sd_rtnl_message_addr_get_family(sd_netlink_message *m, int *family);
141 : : int sd_rtnl_message_addr_get_prefixlen(sd_netlink_message *m, unsigned char *prefixlen);
142 : : int sd_rtnl_message_addr_get_scope(sd_netlink_message *m, unsigned char *scope);
143 : : int sd_rtnl_message_addr_get_flags(sd_netlink_message *m, unsigned char *flags);
144 : : int sd_rtnl_message_addr_get_ifindex(sd_netlink_message *m, int *ifindex);
145 : :
146 : : int sd_rtnl_message_link_set_flags(sd_netlink_message *m, unsigned flags, unsigned change);
147 : : int sd_rtnl_message_link_set_type(sd_netlink_message *m, unsigned type);
148 : : int sd_rtnl_message_link_set_family(sd_netlink_message *m, unsigned family);
149 : : int sd_rtnl_message_link_get_ifindex(sd_netlink_message *m, int *ifindex);
150 : : int sd_rtnl_message_link_get_flags(sd_netlink_message *m, unsigned *flags);
151 : : int sd_rtnl_message_link_get_type(sd_netlink_message *m, unsigned short *type);
152 : :
153 : : int sd_rtnl_message_route_set_dst_prefixlen(sd_netlink_message *m, unsigned char prefixlen);
154 : : int sd_rtnl_message_route_set_src_prefixlen(sd_netlink_message *m, unsigned char prefixlen);
155 : : int sd_rtnl_message_route_set_scope(sd_netlink_message *m, unsigned char scope);
156 : : int sd_rtnl_message_route_set_flags(sd_netlink_message *m, unsigned flags);
157 : : int sd_rtnl_message_route_set_table(sd_netlink_message *m, unsigned char table);
158 : : int sd_rtnl_message_route_set_type(sd_netlink_message *m, unsigned char type);
159 : : int sd_rtnl_message_route_get_flags(sd_netlink_message *m, unsigned *flags);
160 : : int sd_rtnl_message_route_get_family(sd_netlink_message *m, int *family);
161 : : int sd_rtnl_message_route_set_family(sd_netlink_message *m, int family);
162 : : int sd_rtnl_message_route_get_protocol(sd_netlink_message *m, unsigned char *protocol);
163 : : int sd_rtnl_message_route_get_scope(sd_netlink_message *m, unsigned char *scope);
164 : : int sd_rtnl_message_route_get_tos(sd_netlink_message *m, unsigned char *tos);
165 : : int sd_rtnl_message_route_get_table(sd_netlink_message *m, unsigned char *table);
166 : : int sd_rtnl_message_route_get_dst_prefixlen(sd_netlink_message *m, unsigned char *dst_len);
167 : : int sd_rtnl_message_route_get_src_prefixlen(sd_netlink_message *m, unsigned char *src_len);
168 : : int sd_rtnl_message_route_get_type(sd_netlink_message *m, unsigned char *type);
169 : :
170 : : int sd_rtnl_message_neigh_set_flags(sd_netlink_message *m, uint8_t flags);
171 : : int sd_rtnl_message_neigh_set_state(sd_netlink_message *m, uint16_t state);
172 : : int sd_rtnl_message_neigh_get_family(sd_netlink_message *m, int *family);
173 : : int sd_rtnl_message_neigh_get_ifindex(sd_netlink_message *m, int *family);
174 : : int sd_rtnl_message_neigh_get_state(sd_netlink_message *m, uint16_t *state);
175 : : int sd_rtnl_message_neigh_get_flags(sd_netlink_message *m, uint8_t *flags);
176 : :
177 : : int sd_rtnl_message_new_addrlabel(sd_netlink *rtnl, sd_netlink_message **ret, uint16_t nlmsg_type, int ifindex, int ifal_family);
178 : : int sd_rtnl_message_addrlabel_set_prefixlen(sd_netlink_message *m, unsigned char prefixlen);
179 : : int sd_rtnl_message_addrlabel_get_prefixlen(sd_netlink_message *m, unsigned char *prefixlen);
180 : :
181 : : int sd_rtnl_message_new_routing_policy_rule(sd_netlink *rtnl, sd_netlink_message **ret, uint16_t nlmsg_type, int ifal_family);
182 : : int sd_rtnl_message_routing_policy_rule_set_tos(sd_netlink_message *m, unsigned char tos);
183 : : int sd_rtnl_message_routing_policy_rule_get_tos(sd_netlink_message *m, unsigned char *tos);
184 : : int sd_rtnl_message_routing_policy_rule_set_table(sd_netlink_message *m, unsigned char table);
185 : : int sd_rtnl_message_routing_policy_rule_get_table(sd_netlink_message *m, unsigned char *table);
186 : : int sd_rtnl_message_routing_policy_rule_set_rtm_src_prefixlen(sd_netlink_message *m, unsigned char len);
187 : : int sd_rtnl_message_routing_policy_rule_get_rtm_src_prefixlen(sd_netlink_message *m, unsigned char *len);
188 : : int sd_rtnl_message_routing_policy_rule_set_rtm_dst_prefixlen(sd_netlink_message *m, unsigned char len);
189 : : int sd_rtnl_message_routing_policy_rule_get_rtm_dst_prefixlen(sd_netlink_message *m, unsigned char *len);
190 : : int sd_rtnl_message_routing_policy_rule_set_rtm_type(sd_netlink_message *m, unsigned char type);
191 : : int sd_rtnl_message_routing_policy_rule_get_rtm_type(sd_netlink_message *m, unsigned char *type);
192 : : int sd_rtnl_message_routing_policy_rule_set_flags(sd_netlink_message *m, unsigned flags);
193 : : int sd_rtnl_message_routing_policy_rule_get_flags(sd_netlink_message *m, unsigned *flags);
194 : :
195 : : /* genl */
196 : : int sd_genl_socket_open(sd_netlink **nl);
197 : : int sd_genl_message_new(sd_netlink *nl, sd_genl_family family, uint8_t cmd, sd_netlink_message **m);
198 : :
199 : : /* slot */
200 : : sd_netlink_slot *sd_netlink_slot_ref(sd_netlink_slot *nl);
201 : : sd_netlink_slot *sd_netlink_slot_unref(sd_netlink_slot *nl);
202 : :
203 : : sd_netlink *sd_netlink_slot_get_netlink(sd_netlink_slot *slot);
204 : : void *sd_netlink_slot_get_userdata(sd_netlink_slot *slot);
205 : : void *sd_netlink_slot_set_userdata(sd_netlink_slot *slot, void *userdata);
206 : : int sd_netlink_slot_get_destroy_callback(sd_netlink_slot *slot, sd_netlink_destroy_t *callback);
207 : : int sd_netlink_slot_set_destroy_callback(sd_netlink_slot *slot, sd_netlink_destroy_t callback);
208 : : int sd_netlink_slot_get_floating(sd_netlink_slot *slot);
209 : : int sd_netlink_slot_set_floating(sd_netlink_slot *slot, int b);
210 : : int sd_netlink_slot_get_description(sd_netlink_slot *slot, const char **description);
211 : : int sd_netlink_slot_set_description(sd_netlink_slot *slot, const char *description);
212 : :
213 [ + + ]: 216 : _SD_DEFINE_POINTER_CLEANUP_FUNC(sd_netlink, sd_netlink_unref);
214 [ + + ]: 856 : _SD_DEFINE_POINTER_CLEANUP_FUNC(sd_netlink_message, sd_netlink_message_unref);
215 [ + + ]: 20 : _SD_DEFINE_POINTER_CLEANUP_FUNC(sd_netlink_slot, sd_netlink_slot_unref);
216 : :
217 : : _SD_END_DECLARATIONS;
218 : :
219 : : #endif
|