]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/network/networkd-util.h
codespell: fix spelling errors
[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 AddressFamilyBoolean {
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_BOOLEAN_MAX,
15 _ADDRESS_FAMILY_BOOLEAN_INVALID = -1,
16 } AddressFamilyBoolean;
17
18 typedef struct NetworkConfigSection {
19 unsigned line;
20 bool invalid;
21 char filename[];
22 } NetworkConfigSection;
23
24 CONFIG_PARSER_PROTOTYPE(config_parse_address_family_boolean);
25 CONFIG_PARSER_PROTOTYPE(config_parse_address_family_boolean_with_kernel);
26
27 const char *address_family_boolean_to_string(AddressFamilyBoolean b) _const_;
28 AddressFamilyBoolean address_family_boolean_from_string(const char *s) _const_;
29
30 int kernel_route_expiration_supported(void);
31
32 int network_config_section_new(const char *filename, unsigned line, NetworkConfigSection **s);
33 void network_config_section_free(NetworkConfigSection *network);
34 DEFINE_TRIVIAL_CLEANUP_FUNC(NetworkConfigSection*, network_config_section_free);
35 extern const struct hash_ops network_config_hash_ops;
36
37 static inline bool section_is_invalid(NetworkConfigSection *section) {
38 /* If this returns false, then it does _not_ mean the section is valid. */
39
40 if (!section)
41 return false;
42
43 return section->invalid;
44 }
45
46 #define DEFINE_NETWORK_SECTION_FUNCTIONS(type, free_func) \
47 static inline void free_func##_or_set_invalid(type *p) { \
48 assert(p); \
49 \
50 if (p->section) \
51 p->section->invalid = true; \
52 else \
53 free_func(p); \
54 } \
55 DEFINE_TRIVIAL_CLEANUP_FUNC(type*, free_func); \
56 DEFINE_TRIVIAL_CLEANUP_FUNC(type*, free_func##_or_set_invalid);