]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/network/networkd-address.h
network: drop duplicated address_set_broadcast()
[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 "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"
14
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)(
21 sd_netlink *rtnl,
22 sd_netlink_message *m,
23 Request *req,
24 Link *link,
25 Address *address);
26
27 struct Address {
28 Link *link;
29 Network *network;
30 ConfigSection *section;
31 NetworkConfigSource source;
32 NetworkConfigState state;
33 union in_addr_union provider; /* DHCP server or router address */
34
35 int family;
36 unsigned char prefixlen;
37 unsigned char scope;
38 uint32_t flags;
39 uint32_t route_metric; /* route metric for prefix route */
40 char *label, *netlabel;
41
42 int set_broadcast;
43 struct in_addr broadcast;
44
45 union in_addr_union in_addr;
46 union in_addr_union in_addr_peer;
47
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;
52
53 bool scope_set:1;
54 bool ip_masquerade_done:1;
55 bool requested_as_null:1;
56
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;
60
61 /* Called when address become ready */
62 address_ready_callback_t callback;
63
64 NFTSetContext nft_set_context;
65 };
66
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)
73
74 int address_flags_to_string_alloc(uint32_t flags, int family, char **ret);
75
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);
86
87 DEFINE_SECTION_CLEANUP_FUNCTIONS(Address, address_free);
88
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) {
96 assert(address);
97 return link_get_address(link, AF_INET6, &(union in_addr_union) { .in6 = *address }, prefixlen, ret);
98 }
99 static inline int link_get_ipv4_address(Link *link, const struct in_addr *address, unsigned char prefixlen, Address **ret) {
100 assert(address);
101 return link_get_address(link, AF_INET, &(union in_addr_union) { .in = *address }, prefixlen, ret);
102 }
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);
105
106 void address_cancel_request(Address *address);
107 int link_request_address(
108 Link *link,
109 const Address *address,
110 unsigned *message_counter,
111 address_netlink_handler_t netlink_handler,
112 Request **ret);
113 int link_request_static_address(Link *link, const Address *address);
114 int link_request_static_addresses(Link *link);
115
116 int manager_rtnl_process_address(sd_netlink *nl, sd_netlink_message *message, Manager *m);
117
118 int network_drop_invalid_addresses(Network *network);
119
120 DEFINE_NETWORK_CONFIG_STATE_FUNCTIONS(Address, address);
121
122 void link_mark_addresses(Link *link, NetworkConfigSource source);
123
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);