]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/network/networkd-util.h
Merge pull request #13365 from keszybz/fix-commits-from-pr-13246
[thirdparty/systemd.git] / src / network / networkd-util.h
CommitLineData
53e1b683 1/* SPDX-License-Identifier: LGPL-2.1+ */
fc2f9534
LP
2#pragma once
3
a2106925 4#include "conf-parser.h"
48315d3d 5#include "hash-funcs.h"
fc2f9534
LP
6#include "macro.h"
7
2d792895 8typedef enum AddressFamily {
fc2f9534 9 /* This is a bitmask, though it usually doesn't feel that way! */
8bc17bb3
SS
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,
2d792895
YW
16 _ADDRESS_FAMILY_MAX,
17 _ADDRESS_FAMILY_INVALID = -1,
18} AddressFamily;
fc2f9534 19
48315d3d
YW
20typedef struct NetworkConfigSection {
21 unsigned line;
fcbf4cb7 22 bool invalid;
48315d3d
YW
23 char filename[];
24} NetworkConfigSection;
25
2d792895
YW
26CONFIG_PARSER_PROTOTYPE(config_parse_link_local_address_family);
27CONFIG_PARSER_PROTOTYPE(config_parse_address_family_with_kernel);
fc2f9534 28
2d792895
YW
29const char *address_family_to_string(AddressFamily b) _const_;
30AddressFamily address_family_from_string(const char *s) _pure_;
e800fd24 31
2d792895
YW
32const char *link_local_address_family_to_string(AddressFamily b) _const_;
33AddressFamily link_local_address_family_from_string(const char *s) _pure_;
f02ba163 34
f6c6ff97
YW
35const char *routing_policy_rule_address_family_to_string(AddressFamily b) _const_;
36AddressFamily routing_policy_rule_address_family_from_string(const char *s) _pure_;
37
f02ba163 38int kernel_route_expiration_supported(void);
48315d3d
YW
39
40int network_config_section_new(const char *filename, unsigned line, NetworkConfigSection **s);
41void network_config_section_free(NetworkConfigSection *network);
42DEFINE_TRIVIAL_CLEANUP_FUNC(NetworkConfigSection*, network_config_section_free);
43extern const struct hash_ops network_config_hash_ops;
fcbf4cb7
YW
44
45static inline bool section_is_invalid(NetworkConfigSection *section) {
5238e957 46 /* If this returns false, then it does _not_ mean the section is valid. */
fcbf4cb7
YW
47
48 if (!section)
49 return false;
50
51 return section->invalid;
52}
53
54#define DEFINE_NETWORK_SECTION_FUNCTIONS(type, free_func) \
55 static inline void free_func##_or_set_invalid(type *p) { \
56 assert(p); \
57 \
58 if (p->section) \
59 p->section->invalid = true; \
60 else \
61 free_func(p); \
62 } \
63 DEFINE_TRIVIAL_CLEANUP_FUNC(type*, free_func); \
64 DEFINE_TRIVIAL_CLEANUP_FUNC(type*, free_func##_or_set_invalid);