1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
8 #include "conf-parser.h"
9 #include "firewall-util.h"
10 #include "in-addr-util.h"
11 #include "networkd-link.h"
12 #include "networkd-util.h"
13 #include "time-util.h"
15 typedef struct Address Address
;
16 typedef struct Manager Manager
;
17 typedef struct Network Network
;
18 typedef struct Request Request
;
19 typedef int (*address_ready_callback_t
)(Address
*address
);
20 typedef int (*address_netlink_handler_t
)(
22 sd_netlink_message
*m
,
30 ConfigSection
*section
;
31 NetworkConfigSource source
;
32 NetworkConfigState state
;
33 union in_addr_union provider
; /* DHCP server or router address */
36 unsigned char prefixlen
;
39 uint32_t route_metric
; /* route metric for prefix route */
40 char *label
, *netlabel
;
43 struct in_addr broadcast
;
45 union in_addr_union in_addr
;
46 union in_addr_union in_addr_peer
;
48 /* These are absolute points in time, and NOT timespans/durations.
49 * Must be specified with clock_boottime_or_monotonic(). */
50 usec_t lifetime_valid_usec
;
51 usec_t lifetime_preferred_usec
;
54 bool ip_masquerade_done
:1;
55 bool requested_as_null
:1;
57 /* duplicate_address_detection is only used by static or IPv4 dynamic addresses.
58 * To control DAD for IPv6 dynamic addresses, set IFA_F_NODAD to flags. */
59 AddressFamily duplicate_address_detection
;
61 /* Called when address become ready */
62 address_ready_callback_t callback
;
64 NFTSetContext nft_set_context
;
67 const char* format_lifetime(char *buf
, size_t l
, usec_t lifetime_usec
) _warn_unused_result_
;
68 /* Note: the lifetime of the compound literal is the immediately surrounding block,
69 * see C11 ยง6.5.2.5, and
70 * https://stackoverflow.com/questions/34880638/compound-literal-lifetime-and-if-blocks */
71 #define FORMAT_LIFETIME(lifetime) \
72 format_lifetime((char[FORMAT_TIMESPAN_MAX+STRLEN("for ")]){}, FORMAT_TIMESPAN_MAX+STRLEN("for "), lifetime)
74 int address_flags_to_string_alloc(uint32_t flags
, int family
, char **ret
);
76 int address_new(Address
**ret
);
77 Address
* address_free(Address
*address
);
78 int address_get(Link
*link
, const Address
*in
, Address
**ret
);
79 int address_get_harder(Link
*link
, const Address
*in
, Address
**ret
);
80 int address_configure_handler_internal(sd_netlink
*rtnl
, sd_netlink_message
*m
, Link
*link
, const char *error_msg
);
81 int address_remove(Address
*address
);
82 int address_remove_and_drop(Address
*address
);
83 int address_dup(const Address
*src
, Address
**ret
);
84 bool address_is_ready(const Address
*a
);
85 bool link_check_addresses_ready(Link
*link
, NetworkConfigSource source
);
87 DEFINE_SECTION_CLEANUP_FUNCTIONS(Address
, address_free
);
89 int link_drop_managed_addresses(Link
*link
);
90 int link_drop_foreign_addresses(Link
*link
);
91 int link_drop_ipv6ll_addresses(Link
*link
);
92 void link_foreignize_addresses(Link
*link
);
93 bool link_address_is_dynamic(const Link
*link
, const Address
*address
);
94 int link_get_address(Link
*link
, int family
, const union in_addr_union
*address
, unsigned char prefixlen
, Address
**ret
);
95 static inline int link_get_ipv6_address(Link
*link
, const struct in6_addr
*address
, unsigned char prefixlen
, Address
**ret
) {
97 return link_get_address(link
, AF_INET6
, &(union in_addr_union
) { .in6
= *address
}, prefixlen
, ret
);
99 static inline int link_get_ipv4_address(Link
*link
, const struct in_addr
*address
, unsigned char prefixlen
, Address
**ret
) {
101 return link_get_address(link
, AF_INET
, &(union in_addr_union
) { .in
= *address
}, prefixlen
, ret
);
103 int manager_get_address(Manager
*manager
, int family
, const union in_addr_union
*address
, unsigned char prefixlen
, Address
**ret
);
104 bool manager_has_address(Manager
*manager
, int family
, const union in_addr_union
*address
, bool check_ready
);
106 void address_cancel_request(Address
*address
);
107 int link_request_address(
109 const Address
*address
,
110 unsigned *message_counter
,
111 address_netlink_handler_t netlink_handler
,
113 int link_request_static_address(Link
*link
, const Address
*address
);
114 int link_request_static_addresses(Link
*link
);
116 int manager_rtnl_process_address(sd_netlink
*nl
, sd_netlink_message
*message
, Manager
*m
);
118 int network_drop_invalid_addresses(Network
*network
);
120 DEFINE_NETWORK_CONFIG_STATE_FUNCTIONS(Address
, address
);
122 void link_mark_addresses(Link
*link
, NetworkConfigSource source
);
124 CONFIG_PARSER_PROTOTYPE(config_parse_address
);
125 CONFIG_PARSER_PROTOTYPE(config_parse_broadcast
);
126 CONFIG_PARSER_PROTOTYPE(config_parse_label
);
127 CONFIG_PARSER_PROTOTYPE(config_parse_lifetime
);
128 CONFIG_PARSER_PROTOTYPE(config_parse_address_flags
);
129 CONFIG_PARSER_PROTOTYPE(config_parse_address_scope
);
130 CONFIG_PARSER_PROTOTYPE(config_parse_address_route_metric
);
131 CONFIG_PARSER_PROTOTYPE(config_parse_duplicate_address_detection
);
132 CONFIG_PARSER_PROTOTYPE(config_parse_address_netlabel
);
133 CONFIG_PARSER_PROTOTYPE(config_parse_address_ip_nft_set
);