]>
Commit | Line | Data |
---|---|---|
f579559b TG |
1 | /*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/ |
2 | ||
3 | /*** | |
4 | This file is part of systemd. | |
5 | ||
6 | Copyright 2013 Tom Gundersen <teg@jklm.no> | |
7 | ||
8 | systemd is free software; you can redistribute it and/or modify it | |
9 | under the terms of the GNU Lesser General Public License as published by | |
10 | the Free Software Foundation; either version 2.1 of the License, or | |
11 | (at your option) any later version. | |
12 | ||
13 | systemd is distributed in the hope that it will be useful, but | |
14 | WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
16 | Lesser General Public License for more details. | |
17 | ||
18 | You should have received a copy of the GNU Lesser General Public License | |
19 | along with systemd; If not, see <http://www.gnu.org/licenses/>. | |
20 | ***/ | |
21 | ||
22 | #pragma once | |
23 | ||
24 | #include <arpa/inet.h> | |
f579559b TG |
25 | |
26 | #include "sd-event.h" | |
27 | #include "sd-rtnl.h" | |
1346b1f0 | 28 | #include "sd-bus.h" |
f5be5601 | 29 | #include "sd-dhcp-client.h" |
dd43110f | 30 | #include "sd-dhcp-server.h" |
5c1d3fc9 | 31 | #include "sd-ipv4ll.h" |
4138fb2c PF |
32 | #include "sd-icmp6-nd.h" |
33 | #include "sd-dhcp6-client.h" | |
f579559b TG |
34 | #include "udev.h" |
35 | ||
36 | #include "rtnl-util.h" | |
37 | #include "hashmap.h" | |
38 | #include "list.h" | |
06f021a8 | 39 | #include "set.h" |
2cc412b5 | 40 | #include "condition-util.h" |
5d3de3fe | 41 | #include "socket-util.h" |
f579559b | 42 | |
aba496a5 | 43 | #define CACHE_INFO_INFINITY_LIFE_TIME 0xFFFFFFFFU |
326cb406 | 44 | #define VXLAN_VID_MAX (1u << 24) - 1 |
e1ea665e | 45 | #define DHCP_STATIC_ROUTE_METRIC 1024 |
aba496a5 | 46 | |
1a436809 | 47 | typedef struct NetDev NetDev; |
f579559b TG |
48 | typedef struct Network Network; |
49 | typedef struct Link Link; | |
50 | typedef struct Address Address; | |
51 | typedef struct Route Route; | |
52 | typedef struct Manager Manager; | |
11bf3cce | 53 | typedef struct AddressPool AddressPool; |
f579559b | 54 | |
52433f6b | 55 | typedef struct netdev_enslave_callback netdev_enslave_callback; |
02b59d57 | 56 | |
52433f6b | 57 | struct netdev_enslave_callback { |
02b59d57 TG |
58 | sd_rtnl_message_handler_t callback; |
59 | Link *link; | |
60 | ||
52433f6b | 61 | LIST_FIELDS(netdev_enslave_callback, callbacks); |
02b59d57 TG |
62 | }; |
63 | ||
fe6b2d55 TG |
64 | typedef enum MacVlanMode { |
65 | NETDEV_MACVLAN_MODE_PRIVATE = MACVLAN_MODE_PRIVATE, | |
66 | NETDEV_MACVLAN_MODE_VEPA = MACVLAN_MODE_VEPA, | |
67 | NETDEV_MACVLAN_MODE_BRIDGE = MACVLAN_MODE_BRIDGE, | |
68 | NETDEV_MACVLAN_MODE_PASSTHRU = MACVLAN_MODE_PASSTHRU, | |
69 | _NETDEV_MACVLAN_MODE_MAX, | |
70 | _NETDEV_MACVLAN_MODE_INVALID = -1 | |
71 | } MacVlanMode; | |
72 | ||
1a436809 | 73 | typedef enum NetDevKind { |
52433f6b TG |
74 | NETDEV_KIND_BRIDGE, |
75 | NETDEV_KIND_BOND, | |
54abf461 | 76 | NETDEV_KIND_VLAN, |
fe6b2d55 | 77 | NETDEV_KIND_MACVLAN, |
326cb406 | 78 | NETDEV_KIND_VXLAN, |
7951dea2 SS |
79 | NETDEV_KIND_IPIP, |
80 | NETDEV_KIND_GRE, | |
81 | NETDEV_KIND_SIT, | |
10142d75 | 82 | NETDEV_KIND_VETH, |
a613382b | 83 | NETDEV_KIND_VTI, |
52433f6b TG |
84 | _NETDEV_KIND_MAX, |
85 | _NETDEV_KIND_INVALID = -1 | |
1a436809 | 86 | } NetDevKind; |
52433f6b | 87 | |
1a436809 | 88 | typedef enum NetDevState { |
52433f6b TG |
89 | NETDEV_STATE_FAILED, |
90 | NETDEV_STATE_CREATING, | |
91 | NETDEV_STATE_READY, | |
2cc7e981 | 92 | NETDEV_STATE_LINGER, |
52433f6b TG |
93 | _NETDEV_STATE_MAX, |
94 | _NETDEV_STATE_INVALID = -1, | |
1a436809 | 95 | } NetDevState; |
52433f6b | 96 | |
1a436809 | 97 | struct NetDev { |
02b59d57 TG |
98 | Manager *manager; |
99 | ||
14b746f7 TG |
100 | int n_ref; |
101 | ||
02b59d57 TG |
102 | char *filename; |
103 | ||
edbb03e9 TG |
104 | Condition *match_host; |
105 | Condition *match_virt; | |
106 | Condition *match_kernel; | |
107 | Condition *match_arch; | |
c0dda186 | 108 | |
02b59d57 | 109 | char *description; |
af4e9e2c | 110 | char *ifname; |
10142d75 | 111 | char *ifname_peer; |
7951dea2 | 112 | size_t mtu; |
96c90742 TG |
113 | struct ether_addr *mac; |
114 | struct ether_addr *mac_peer; | |
1a436809 | 115 | NetDevKind kind; |
02b59d57 | 116 | |
672682a6 | 117 | uint64_t vlanid; |
326cb406 | 118 | uint64_t vxlanid; |
fe6b2d55 | 119 | int32_t macvlan_mode; |
54abf461 | 120 | |
50add290 | 121 | int ifindex; |
1a436809 | 122 | NetDevState state; |
02b59d57 | 123 | |
a9f434cf | 124 | bool tunnel_pmtudisc; |
326cb406 | 125 | bool learning; |
1324e3ae SS |
126 | unsigned ttl; |
127 | unsigned tos; | |
128 | struct in_addr local; | |
129 | struct in_addr remote; | |
326cb406 | 130 | struct in_addr group; |
7951dea2 | 131 | |
52433f6b | 132 | LIST_HEAD(netdev_enslave_callback, callbacks); |
02b59d57 TG |
133 | }; |
134 | ||
ed942a9e TG |
135 | typedef enum DHCPSupport { |
136 | DHCP_SUPPORT_NONE, | |
137 | DHCP_SUPPORT_BOTH, | |
138 | DHCP_SUPPORT_V4, | |
139 | DHCP_SUPPORT_V6, | |
140 | _DHCP_SUPPORT_MAX, | |
141 | _DHCP_SUPPORT_INVALID = -1, | |
142 | } DHCPSupport; | |
143 | ||
f579559b TG |
144 | struct Network { |
145 | Manager *manager; | |
146 | ||
147 | char *filename; | |
148 | ||
149 | struct ether_addr *match_mac; | |
150 | char *match_path; | |
151 | char *match_driver; | |
152 | char *match_type; | |
153 | char *match_name; | |
2cc412b5 TG |
154 | Condition *match_host; |
155 | Condition *match_virt; | |
156 | Condition *match_kernel; | |
edbb03e9 | 157 | Condition *match_arch; |
f579559b TG |
158 | |
159 | char *description; | |
1a436809 TG |
160 | NetDev *bridge; |
161 | NetDev *bond; | |
7951dea2 | 162 | NetDev *tunnel; |
672682a6 | 163 | Hashmap *vlans; |
fe6b2d55 | 164 | Hashmap *macvlans; |
326cb406 | 165 | Hashmap *vxlans; |
ed942a9e | 166 | DHCPSupport dhcp; |
5be4d38e | 167 | bool dhcp_dns; |
bcb7a07e | 168 | bool dhcp_ntp; |
4f882b2a | 169 | bool dhcp_mtu; |
1346b1f0 | 170 | bool dhcp_hostname; |
039ebe6a | 171 | bool dhcp_domainname; |
eb27aeca | 172 | bool dhcp_critical; |
e1ea665e | 173 | bool dhcp_routes; |
5c1d3fc9 | 174 | bool ipv4ll; |
f579559b | 175 | |
dd43110f TG |
176 | bool dhcp_server; |
177 | ||
f048a16b TG |
178 | LIST_HEAD(Address, static_addresses); |
179 | LIST_HEAD(Route, static_routes); | |
f579559b | 180 | |
6ae115c1 TG |
181 | Hashmap *addresses_by_section; |
182 | Hashmap *routes_by_section; | |
183 | ||
d4920165 | 184 | LIST_HEAD(Address, dns); |
bcb7a07e | 185 | LIST_HEAD(Address, ntp); |
06f021a8 | 186 | |
f579559b TG |
187 | LIST_FIELDS(Network, networks); |
188 | }; | |
189 | ||
190 | struct Address { | |
191 | Network *network; | |
6ae115c1 | 192 | uint64_t section; |
f579559b TG |
193 | |
194 | unsigned char family; | |
195 | unsigned char prefixlen; | |
5c1d3fc9 | 196 | unsigned char scope; |
f579559b TG |
197 | char *label; |
198 | ||
eb0ea358 | 199 | struct in_addr broadcast; |
aba496a5 | 200 | struct ifa_cacheinfo cinfo; |
8cd11a0f | 201 | |
5d3de3fe | 202 | union in_addr_union in_addr; |
f579559b | 203 | |
3d3d4255 | 204 | LIST_FIELDS(Address, addresses); |
f579559b TG |
205 | }; |
206 | ||
207 | struct Route { | |
208 | Network *network; | |
6ae115c1 | 209 | uint64_t section; |
f579559b TG |
210 | |
211 | unsigned char family; | |
6ae115c1 | 212 | unsigned char dst_prefixlen; |
5c1d3fc9 UTL |
213 | unsigned char scope; |
214 | uint32_t metrics; | |
f579559b | 215 | |
5d3de3fe LP |
216 | union in_addr_union in_addr; |
217 | union in_addr_union dst_addr; | |
6ae115c1 | 218 | |
3d3d4255 | 219 | LIST_FIELDS(Route, routes); |
f579559b TG |
220 | }; |
221 | ||
f882c247 | 222 | typedef enum LinkState { |
505f8da7 | 223 | LINK_STATE_INITIALIZING, |
52433f6b | 224 | LINK_STATE_ENSLAVING, |
ef1ba606 TG |
225 | LINK_STATE_SETTING_ADDRESSES, |
226 | LINK_STATE_SETTING_ROUTES, | |
f882c247 | 227 | LINK_STATE_CONFIGURED, |
57bd6899 | 228 | LINK_STATE_UNMANAGED, |
f882c247 | 229 | LINK_STATE_FAILED, |
370e9930 | 230 | LINK_STATE_LINGER, |
f882c247 TG |
231 | _LINK_STATE_MAX, |
232 | _LINK_STATE_INVALID = -1 | |
233 | } LinkState; | |
234 | ||
e375dcde TG |
235 | typedef enum LinkOperationalState { |
236 | LINK_OPERSTATE_UNKNOWN, | |
237 | LINK_OPERSTATE_DORMANT, | |
238 | LINK_OPERSTATE_CARRIER, | |
239 | LINK_OPERSTATE_DEGRADED, | |
240 | LINK_OPERSTATE_ROUTABLE, | |
241 | _LINK_OPERSTATE_MAX, | |
242 | _LINK_OPERSTATE_INVALID = -1 | |
243 | } LinkOperationalState; | |
244 | ||
f579559b TG |
245 | struct Link { |
246 | Manager *manager; | |
247 | ||
14b746f7 TG |
248 | int n_ref; |
249 | ||
0617ffab | 250 | uint64_t ifindex; |
c166a070 | 251 | char *ifname; |
fe8db0c5 | 252 | char *state_file; |
8cd11a0f | 253 | struct ether_addr mac; |
b5db00e5 | 254 | struct udev_device *udev_device; |
f579559b TG |
255 | |
256 | unsigned flags; | |
e375dcde | 257 | uint8_t kernel_operstate; |
f579559b TG |
258 | |
259 | Network *network; | |
f882c247 TG |
260 | |
261 | LinkState state; | |
e375dcde | 262 | LinkOperationalState operstate; |
f882c247 | 263 | |
f5be5601 TG |
264 | unsigned addr_messages; |
265 | unsigned route_messages; | |
52433f6b | 266 | unsigned enslaving; |
f5be5601 | 267 | |
428fd0a7 TG |
268 | LIST_HEAD(Address, addresses); |
269 | ||
a6cc569e TG |
270 | sd_dhcp_client *dhcp_client; |
271 | sd_dhcp_lease *dhcp_lease; | |
68a8723c | 272 | char *lease_file; |
a6cc569e | 273 | uint16_t original_mtu; |
5c1d3fc9 | 274 | sd_ipv4ll *ipv4ll; |
dd43110f | 275 | |
11bf3cce LP |
276 | LIST_HEAD(Address, pool_addresses); |
277 | ||
dd43110f | 278 | sd_dhcp_server *dhcp_server; |
4138fb2c PF |
279 | |
280 | sd_icmp6_nd *icmp6_router_discovery; | |
281 | sd_dhcp6_client *dhcp6_client; | |
f579559b TG |
282 | }; |
283 | ||
11bf3cce LP |
284 | struct AddressPool { |
285 | Manager *manager; | |
286 | ||
287 | unsigned family; | |
288 | unsigned prefixlen; | |
289 | ||
290 | union in_addr_union in_addr; | |
291 | ||
292 | LIST_FIELDS(AddressPool, address_pools); | |
293 | }; | |
294 | ||
f579559b TG |
295 | struct Manager { |
296 | sd_rtnl *rtnl; | |
297 | sd_event *event; | |
1346b1f0 | 298 | sd_bus *bus; |
f579559b TG |
299 | struct udev *udev; |
300 | struct udev_monitor *udev_monitor; | |
301 | sd_event_source *udev_event_source; | |
0c2f9b84 TG |
302 | sd_event_source *sigterm_event_source; |
303 | sd_event_source *sigint_event_source; | |
f579559b | 304 | |
bbf7c048 TG |
305 | char *state_file; |
306 | ||
f579559b | 307 | Hashmap *links; |
52433f6b | 308 | Hashmap *netdevs; |
f579559b | 309 | LIST_HEAD(Network, networks); |
11bf3cce | 310 | LIST_HEAD(AddressPool, address_pools); |
f579559b | 311 | |
f579559b TG |
312 | usec_t network_dirs_ts_usec; |
313 | }; | |
314 | ||
2ad8416d ZJS |
315 | extern const char* const network_dirs[]; |
316 | ||
f579559b TG |
317 | /* Manager */ |
318 | ||
319 | int manager_new(Manager **ret); | |
320 | void manager_free(Manager *m); | |
321 | ||
02b59d57 TG |
322 | int manager_load_config(Manager *m); |
323 | bool manager_should_reload(Manager *m); | |
324 | ||
505f8da7 | 325 | int manager_rtnl_enumerate_links(Manager *m); |
f579559b | 326 | |
f882c247 | 327 | int manager_rtnl_listen(Manager *m); |
505f8da7 | 328 | int manager_udev_listen(Manager *m); |
1346b1f0 | 329 | int manager_bus_listen(Manager *m); |
f882c247 | 330 | |
bbf7c048 | 331 | int manager_save(Manager *m); |
3bef724f | 332 | |
11bf3cce LP |
333 | int manager_address_pool_acquire(Manager *m, unsigned family, unsigned prefixlen, union in_addr_union *found); |
334 | ||
f579559b TG |
335 | DEFINE_TRIVIAL_CLEANUP_FUNC(Manager*, manager_free); |
336 | #define _cleanup_manager_free_ _cleanup_(manager_freep) | |
337 | ||
1a436809 | 338 | /* NetDev */ |
52433f6b TG |
339 | |
340 | int netdev_load(Manager *manager); | |
2cc7e981 | 341 | void netdev_drop(NetDev *netdev); |
02b59d57 | 342 | |
14b746f7 TG |
343 | NetDev *netdev_unref(NetDev *netdev); |
344 | NetDev *netdev_ref(NetDev *netdev); | |
02b59d57 | 345 | |
14b746f7 TG |
346 | DEFINE_TRIVIAL_CLEANUP_FUNC(NetDev*, netdev_unref); |
347 | #define _cleanup_netdev_unref_ _cleanup_(netdev_unrefp) | |
02b59d57 | 348 | |
1a436809 | 349 | int netdev_get(Manager *manager, const char *name, NetDev **ret); |
d39edfc7 | 350 | int netdev_set_ifindex(NetDev *netdev, sd_rtnl_message *newlink); |
1a436809 | 351 | int netdev_enslave(NetDev *netdev, Link *link, sd_rtnl_message_handler_t cb); |
d5b3d845 | 352 | int netdev_create_tunnel(NetDev *netdev, Link *link, sd_rtnl_message_handler_t callback); |
10142d75 | 353 | int netdev_create_veth(NetDev *netdev, sd_rtnl_message_handler_t callback); |
326cb406 | 354 | int netdev_create_vxlan(NetDev *netdev, Link *link, sd_rtnl_message_handler_t callback); |
02b59d57 | 355 | |
1a436809 TG |
356 | const char *netdev_kind_to_string(NetDevKind d) _const_; |
357 | NetDevKind netdev_kind_from_string(const char *d) _pure_; | |
52433f6b | 358 | |
fe6b2d55 TG |
359 | const char *macvlan_mode_to_string(MacVlanMode d) _const_; |
360 | MacVlanMode macvlan_mode_from_string(const char *d) _pure_; | |
361 | ||
52433f6b | 362 | int config_parse_netdev_kind(const char *unit, const char *filename, unsigned line, const char *section, unsigned section_line, const char *lvalue, int ltype, const char *rvalue, void *data, void *userdata); |
02b59d57 | 363 | |
fe6b2d55 TG |
364 | int config_parse_macvlan_mode(const char *unit, const char *filename, unsigned line, const char *section, unsigned section_line, const char *lvalue, int ltype, const char *rvalue, void *data, void *userdata); |
365 | ||
c0dda186 TG |
366 | /* gperf */ |
367 | const struct ConfigPerfItem* network_netdev_gperf_lookup(const char *key, unsigned length); | |
368 | ||
f579559b TG |
369 | /* Network */ |
370 | ||
371 | int network_load(Manager *manager); | |
f579559b TG |
372 | |
373 | void network_free(Network *network); | |
374 | ||
375 | DEFINE_TRIVIAL_CLEANUP_FUNC(Network*, network_free); | |
376 | #define _cleanup_network_free_ _cleanup_(network_freep) | |
377 | ||
505f8da7 TG |
378 | int network_get(Manager *manager, struct udev_device *device, |
379 | const char *ifname, const struct ether_addr *mac, | |
380 | Network **ret); | |
f579559b TG |
381 | int network_apply(Manager *manager, Network *network, Link *link); |
382 | ||
69a93e7d | 383 | int config_parse_netdev(const char *unit, const char *filename, unsigned line, |
02b59d57 TG |
384 | const char *section, unsigned section_line, const char *lvalue, |
385 | int ltype, const char *rvalue, void *data, void *userdata); | |
386 | ||
7951dea2 SS |
387 | int config_parse_tunnel(const char *unit, |
388 | const char *filename, | |
389 | unsigned line, | |
390 | const char *section, | |
391 | unsigned section_line, | |
392 | const char *lvalue, | |
393 | int ltype, | |
394 | const char *rvalue, | |
395 | void *data, | |
396 | void *userdata); | |
397 | ||
398 | int config_parse_tunnel_address(const char *unit, | |
399 | const char *filename, | |
400 | unsigned line, | |
401 | const char *section, | |
402 | unsigned section_line, | |
403 | const char *lvalue, | |
404 | int ltype, | |
405 | const char *rvalue, | |
406 | void *data, | |
407 | void *userdata); | |
408 | ||
02b59d57 | 409 | /* gperf */ |
c0dda186 | 410 | const struct ConfigPerfItem* network_network_gperf_lookup(const char *key, unsigned length); |
f579559b TG |
411 | |
412 | /* Route */ | |
f048a16b TG |
413 | int route_new_static(Network *network, unsigned section, Route **ret); |
414 | int route_new_dynamic(Route **ret); | |
f579559b | 415 | void route_free(Route *route); |
f882c247 | 416 | int route_configure(Route *route, Link *link, sd_rtnl_message_handler_t callback); |
5c1d3fc9 UTL |
417 | int route_drop(Route *route, Link *link, sd_rtnl_message_handler_t callback); |
418 | ||
f579559b TG |
419 | |
420 | DEFINE_TRIVIAL_CLEANUP_FUNC(Route*, route_free); | |
421 | #define _cleanup_route_free_ _cleanup_(route_freep) | |
422 | ||
423 | int config_parse_gateway(const char *unit, const char *filename, unsigned line, | |
71a61510 TG |
424 | const char *section, unsigned section_line, const char *lvalue, |
425 | int ltype, const char *rvalue, void *data, void *userdata); | |
f579559b | 426 | |
6ae115c1 TG |
427 | int config_parse_destination(const char *unit, const char *filename, unsigned line, |
428 | const char *section, unsigned section_line, const char *lvalue, | |
429 | int ltype, const char *rvalue, void *data, void *userdata); | |
430 | ||
f579559b | 431 | /* Address */ |
f048a16b TG |
432 | int address_new_static(Network *network, unsigned section, Address **ret); |
433 | int address_new_dynamic(Address **ret); | |
f579559b | 434 | void address_free(Address *address); |
f882c247 | 435 | int address_configure(Address *address, Link *link, sd_rtnl_message_handler_t callback); |
aba496a5 | 436 | int address_update(Address *address, Link *link, sd_rtnl_message_handler_t callback); |
407fe036 | 437 | int address_drop(Address *address, Link *link, sd_rtnl_message_handler_t callback); |
9505d3c6 | 438 | bool address_equal(Address *a1, Address *a2); |
f579559b TG |
439 | |
440 | DEFINE_TRIVIAL_CLEANUP_FUNC(Address*, address_free); | |
441 | #define _cleanup_address_free_ _cleanup_(address_freep) | |
442 | ||
3bef724f TG |
443 | int config_parse_dns(const char *unit, const char *filename, unsigned line, |
444 | const char *section, unsigned section_line, const char *lvalue, | |
445 | int ltype, const char *rvalue, void *data, void *userdata); | |
446 | ||
f579559b | 447 | int config_parse_address(const char *unit, const char *filename, unsigned line, |
71a61510 TG |
448 | const char *section, unsigned section_line, const char *lvalue, |
449 | int ltype, const char *rvalue, void *data, void *userdata); | |
f579559b | 450 | |
eb0ea358 TG |
451 | int config_parse_broadcast(const char *unit, const char *filename, unsigned line, |
452 | const char *section, unsigned section_line, const char *lvalue, | |
453 | int ltype, const char *rvalue, void *data, void *userdata); | |
454 | ||
6ae115c1 TG |
455 | int config_parse_label(const char *unit, const char *filename, unsigned line, |
456 | const char *section, unsigned section_line, const char *lvalue, | |
457 | int ltype, const char *rvalue, void *data, void *userdata); | |
458 | ||
f579559b TG |
459 | /* Link */ |
460 | ||
14b746f7 TG |
461 | Link *link_unref(Link *link); |
462 | Link *link_ref(Link *link); | |
11a7f229 | 463 | int link_get(Manager *m, int ifindex, Link **ret); |
505f8da7 | 464 | int link_add(Manager *manager, sd_rtnl_message *message, Link **ret); |
370e9930 | 465 | void link_drop(Link *link); |
f579559b | 466 | |
22936833 | 467 | int link_update(Link *link, sd_rtnl_message *message); |
fbbeb65a | 468 | int link_rtnl_process_address(sd_rtnl *rtnl, sd_rtnl_message *message, void *userdata); |
dd3efc09 | 469 | |
505f8da7 TG |
470 | int link_initialized(Link *link, struct udev_device *device); |
471 | ||
fe8db0c5 TG |
472 | int link_save(Link *link); |
473 | ||
bbf7c048 TG |
474 | bool link_has_carrier(unsigned flags, uint8_t operstate); |
475 | ||
fe8db0c5 TG |
476 | const char* link_state_to_string(LinkState s) _const_; |
477 | LinkState link_state_from_string(const char *s) _pure_; | |
478 | ||
e375dcde TG |
479 | const char* link_operstate_to_string(LinkOperationalState s) _const_; |
480 | LinkOperationalState link_operstate_from_string(const char *s) _pure_; | |
481 | ||
14b746f7 TG |
482 | DEFINE_TRIVIAL_CLEANUP_FUNC(Link*, link_unref); |
483 | #define _cleanup_link_unref_ _cleanup_(link_unrefp) | |
3333d748 | 484 | |
ed942a9e TG |
485 | /* DHCP support */ |
486 | ||
487 | const char* dhcp_support_to_string(DHCPSupport i) _const_; | |
488 | DHCPSupport dhcp_support_from_string(const char *s) _pure_; | |
489 | ||
490 | int config_parse_dhcp(const char *unit, const char *filename, unsigned line, | |
491 | const char *section, unsigned section_line, const char *lvalue, | |
492 | int ltype, const char *rvalue, void *data, void *userdata); | |
493 | ||
11bf3cce LP |
494 | /* Address Pool */ |
495 | ||
496 | int address_pool_new(Manager *m, AddressPool **ret, unsigned family, const union in_addr_union *u, unsigned prefixlen); | |
497 | int address_pool_new_from_string(Manager *m, AddressPool **ret, unsigned family, const char *p, unsigned prefixlen); | |
498 | void address_pool_free(AddressPool *p); | |
499 | ||
500 | int address_pool_acquire(AddressPool *p, unsigned prefixlen, union in_addr_union *found); | |
501 | ||
3333d748 ZJS |
502 | /* Macros which append INTERFACE= to the message */ |
503 | ||
97578344 | 504 | #define log_full_link(level, link, fmt, ...) log_meta_object(level, __FILE__, __LINE__, __func__, "INTERFACE=", link->ifname, "%-*s: " fmt, IFNAMSIZ, link->ifname, ##__VA_ARGS__) |
39032b87 ZJS |
505 | #define log_debug_link(link, ...) log_full_link(LOG_DEBUG, link, ##__VA_ARGS__) |
506 | #define log_info_link(link, ...) log_full_link(LOG_INFO, link, ##__VA_ARGS__) | |
507 | #define log_notice_link(link, ...) log_full_link(LOG_NOTICE, link, ##__VA_ARGS__) | |
508 | #define log_warning_link(link, ...) log_full_link(LOG_WARNING, link, ##__VA_ARGS__) | |
509 | #define log_error_link(link, ...) log_full_link(LOG_ERR, link, ##__VA_ARGS__) | |
3333d748 ZJS |
510 | |
511 | #define log_struct_link(level, link, ...) log_struct(level, "INTERFACE=%s", link->ifname, __VA_ARGS__) | |
512 | ||
513 | /* More macros which append INTERFACE= to the message */ | |
514 | ||
97578344 | 515 | #define log_full_netdev(level, netdev, fmt, ...) log_meta_object(level, __FILE__, __LINE__, __func__, "INTERFACE=", netdev->ifname, "%-*s: " fmt, IFNAMSIZ, netdev->ifname, ##__VA_ARGS__) |
52433f6b TG |
516 | #define log_debug_netdev(netdev, ...) log_full_netdev(LOG_DEBUG, netdev, ##__VA_ARGS__) |
517 | #define log_info_netdev(netdev, ...) log_full_netdev(LOG_INFO, netdev, ##__VA_ARGS__) | |
518 | #define log_notice_netdev(netdev, ...) log_full_netdev(LOG_NOTICE, netdev, ##__VA_ARGS__) | |
519 | #define log_warning_netdev(netdev, ...) log_full_netdev(LOG_WARNING, netdev,## __VA_ARGS__) | |
520 | #define log_error_netdev(netdev, ...) log_full_netdev(LOG_ERR, netdev, ##__VA_ARGS__) | |
3333d748 | 521 | |
af4e9e2c | 522 | #define log_struct_netdev(level, netdev, ...) log_struct(level, "INTERFACE=%s", netdev->ifname, __VA_ARGS__) |
3333d748 | 523 | |
af4e9e2c | 524 | #define NETDEV(netdev) "INTERFACE=%s", netdev->ifname |
62870613 ZJS |
525 | #define ADDRESS_FMT_VAL(address) \ |
526 | (address).s_addr & 0xFF, \ | |
527 | ((address).s_addr >> 8) & 0xFF, \ | |
528 | ((address).s_addr >> 16) & 0xFF, \ | |
529 | (address).s_addr >> 24 |