]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/network/networkd-util.h
c96c2fd9fa2208015b377835911f2bb4e1189c84
[thirdparty/systemd.git] / src / network / networkd-util.h
1 /* SPDX-License-Identifier: LGPL-2.1+ */
2 #pragma once
3
4 #include "conf-parser.h"
5 #include "hash-funcs.h"
6 #include "macro.h"
7
8 typedef enum AddressFamily {
9 /* This is a bitmask, though it usually doesn't feel that way! */
10 ADDRESS_FAMILY_NO = 0,
11 ADDRESS_FAMILY_IPV4 = 1 << 0,
12 ADDRESS_FAMILY_IPV6 = 1 << 1,
13 ADDRESS_FAMILY_YES = ADDRESS_FAMILY_IPV4 | ADDRESS_FAMILY_IPV6,
14 ADDRESS_FAMILY_FALLBACK_IPV4 = 1 << 2,
15 ADDRESS_FAMILY_FALLBACK = ADDRESS_FAMILY_FALLBACK_IPV4 | ADDRESS_FAMILY_IPV6,
16 _ADDRESS_FAMILY_MAX,
17 _ADDRESS_FAMILY_INVALID = -1,
18 } AddressFamily;
19
20 typedef struct NetworkConfigSection {
21 unsigned line;
22 bool invalid;
23 char filename[];
24 } NetworkConfigSection;
25
26 CONFIG_PARSER_PROTOTYPE(config_parse_link_local_address_family);
27 CONFIG_PARSER_PROTOTYPE(config_parse_address_family_with_kernel);
28
29 const char *address_family_to_string(AddressFamily b) _const_;
30 AddressFamily address_family_from_string(const char *s) _pure_;
31
32 const char *link_local_address_family_to_string(AddressFamily b) _const_;
33 AddressFamily link_local_address_family_from_string(const char *s) _pure_;
34
35 int kernel_route_expiration_supported(void);
36
37 int network_config_section_new(const char *filename, unsigned line, NetworkConfigSection **s);
38 void network_config_section_free(NetworkConfigSection *network);
39 DEFINE_TRIVIAL_CLEANUP_FUNC(NetworkConfigSection*, network_config_section_free);
40 extern const struct hash_ops network_config_hash_ops;
41
42 static inline bool section_is_invalid(NetworkConfigSection *section) {
43 /* If this returns false, then it does _not_ mean the section is valid. */
44
45 if (!section)
46 return false;
47
48 return section->invalid;
49 }
50
51 #define DEFINE_NETWORK_SECTION_FUNCTIONS(type, free_func) \
52 static inline void free_func##_or_set_invalid(type *p) { \
53 assert(p); \
54 \
55 if (p->section) \
56 p->section->invalid = true; \
57 else \
58 free_func(p); \
59 } \
60 DEFINE_TRIVIAL_CLEANUP_FUNC(type*, free_func); \
61 DEFINE_TRIVIAL_CLEANUP_FUNC(type*, free_func##_or_set_invalid);