]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/network/networkd-address.h
Merge pull request #18007 from fw-strlen/ipv6_masq_and_dnat
[thirdparty/systemd.git] / src / network / networkd-address.h
1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
2 #pragma once
3
4 #include <inttypes.h>
5 #include <stdbool.h>
6 #include <stdio.h>
7
8 #include "sd-ipv4acd.h"
9
10 #include "conf-parser.h"
11 #include "in-addr-util.h"
12 #include "networkd-link.h"
13 #include "networkd-util.h"
14
15 #define CACHE_INFO_INFINITY_LIFE_TIME 0xFFFFFFFFU
16
17 typedef struct Manager Manager;
18 typedef struct Network Network;
19 typedef int (*address_ready_callback_t)(Address *address);
20
21 typedef struct Address {
22 Network *network;
23 NetworkConfigSection *section;
24
25 Link *link;
26
27 int family;
28 unsigned char prefixlen;
29 unsigned char scope;
30 uint32_t flags;
31 char *label;
32
33 struct in_addr broadcast;
34 struct ifa_cacheinfo cinfo;
35
36 union in_addr_union in_addr;
37 union in_addr_union in_addr_peer;
38
39 bool scope_set:1;
40 bool ip_masquerade_done:1;
41 bool ipv6_masquerade_done:1;
42 AddressFamily duplicate_address_detection;
43
44 /* Called when address become ready */
45 address_ready_callback_t callback;
46
47 sd_ipv4acd *acd;
48 } Address;
49
50 int address_new(Address **ret);
51 Address *address_free(Address *address);
52 int address_get(Link *link, const Address *in, Address **ret);
53 int address_configure(const Address *address, Link *link, link_netlink_message_handler_t callback, Address **ret);
54 int address_remove(const Address *address, Link *link, link_netlink_message_handler_t callback);
55 bool address_equal(const Address *a1, const Address *a2);
56 bool address_is_ready(const Address *a);
57
58 int generate_ipv6_eui_64_address(const Link *link, struct in6_addr *ret);
59
60 DEFINE_NETWORK_SECTION_FUNCTIONS(Address, address_free);
61
62 int link_set_addresses(Link *link);
63 int link_drop_addresses(Link *link);
64 int link_drop_foreign_addresses(Link *link);
65 bool link_address_is_dynamic(const Link *link, const Address *address);
66 int link_has_ipv6_address(Link *link, const struct in6_addr *address);
67
68 void ipv4_dad_unref(Link *link);
69 int ipv4_dad_stop(Link *link);
70 int ipv4_dad_update_mac(Link *link);
71
72 int manager_rtnl_process_address(sd_netlink *nl, sd_netlink_message *message, Manager *m);
73
74 void network_drop_invalid_addresses(Network *network);
75
76 void address_hash_func(const Address *a, struct siphash *state);
77 int address_compare_func(const Address *a1, const Address *a2);
78 extern const struct hash_ops address_hash_ops;
79
80 CONFIG_PARSER_PROTOTYPE(config_parse_address);
81 CONFIG_PARSER_PROTOTYPE(config_parse_broadcast);
82 CONFIG_PARSER_PROTOTYPE(config_parse_label);
83 CONFIG_PARSER_PROTOTYPE(config_parse_lifetime);
84 CONFIG_PARSER_PROTOTYPE(config_parse_address_flags);
85 CONFIG_PARSER_PROTOTYPE(config_parse_address_scope);
86 CONFIG_PARSER_PROTOTYPE(config_parse_duplicate_address_detection);
87
88 #define IPV4_ADDRESS_FMT_STR "%u.%u.%u.%u"
89 #define IPV4_ADDRESS_FMT_VAL(address) \
90 be32toh((address).s_addr) >> 24, \
91 (be32toh((address).s_addr) >> 16) & 0xFFu, \
92 (be32toh((address).s_addr) >> 8) & 0xFFu, \
93 be32toh((address).s_addr) & 0xFFu