1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
8 #include "sd-ipv4acd.h"
10 #include "conf-parser.h"
11 #include "in-addr-util.h"
12 #include "networkd-link.h"
13 #include "networkd-util.h"
15 #define CACHE_INFO_INFINITY_LIFE_TIME 0xFFFFFFFFU
17 typedef struct Manager Manager
;
18 typedef struct Network Network
;
19 typedef int (*address_ready_callback_t
)(Address
*address
);
21 typedef struct Address
{
23 NetworkConfigSection
*section
;
28 unsigned char prefixlen
;
33 struct in_addr broadcast
;
34 struct ifa_cacheinfo cinfo
;
36 union in_addr_union in_addr
;
37 union in_addr_union in_addr_peer
;
40 bool ip_masquerade_done
:1;
41 bool ipv6_masquerade_done
:1;
42 AddressFamily duplicate_address_detection
;
44 /* Called when address become ready */
45 address_ready_callback_t callback
;
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
);
58 int generate_ipv6_eui_64_address(const Link
*link
, struct in6_addr
*ret
);
60 DEFINE_NETWORK_SECTION_FUNCTIONS(Address
, address_free
);
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
);
68 void ipv4_dad_unref(Link
*link
);
69 int ipv4_dad_stop(Link
*link
);
70 int ipv4_dad_update_mac(Link
*link
);
72 int manager_rtnl_process_address(sd_netlink
*nl
, sd_netlink_message
*message
, Manager
*m
);
74 void network_drop_invalid_addresses(Network
*network
);
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
;
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
);
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