]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/network/networkd-util.h
network: split out copying logic from routing_policy_rule_add_internal()
[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
DD
34
35int kernel_route_expiration_supported(void);
48315d3d
YW
36
37int network_config_section_new(const char *filename, unsigned line, NetworkConfigSection **s);
38void network_config_section_free(NetworkConfigSection *network);
39DEFINE_TRIVIAL_CLEANUP_FUNC(NetworkConfigSection*, network_config_section_free);
40extern const struct hash_ops network_config_hash_ops;
fcbf4cb7
YW
41
42static inline bool section_is_invalid(NetworkConfigSection *section) {
5238e957 43 /* If this returns false, then it does _not_ mean the section is valid. */
fcbf4cb7
YW
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);