]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/network/networkd-link.h
Merge pull request #11893 from yuwata/wait-online-take-operstate
[thirdparty/systemd.git] / src / network / networkd-link.h
1 /* SPDX-License-Identifier: LGPL-2.1+ */
2 #pragma once
3
4 #include <endian.h>
5
6 #include "sd-bus.h"
7 #include "sd-device.h"
8 #include "sd-dhcp-client.h"
9 #include "sd-dhcp-server.h"
10 #include "sd-dhcp6-client.h"
11 #include "sd-ipv4ll.h"
12 #include "sd-lldp.h"
13 #include "sd-ndisc.h"
14 #include "sd-radv.h"
15 #include "sd-netlink.h"
16
17 #include "list.h"
18 #include "log-link.h"
19 #include "network-util.h"
20 #include "set.h"
21
22 typedef enum LinkState {
23 LINK_STATE_PENDING,
24 LINK_STATE_CONFIGURING,
25 LINK_STATE_CONFIGURED,
26 LINK_STATE_UNMANAGED,
27 LINK_STATE_FAILED,
28 LINK_STATE_LINGER,
29 _LINK_STATE_MAX,
30 _LINK_STATE_INVALID = -1
31 } LinkState;
32
33 typedef struct Manager Manager;
34 typedef struct Network Network;
35 typedef struct Address Address;
36 typedef struct DUID DUID;
37
38 typedef struct Link {
39 Manager *manager;
40
41 unsigned n_ref;
42
43 int ifindex;
44 int master_ifindex;
45 char *ifname;
46 char *kind;
47 unsigned short iftype;
48 char *state_file;
49 struct ether_addr mac;
50 struct in6_addr ipv6ll_address;
51 uint32_t mtu;
52 sd_device *sd_device;
53
54 unsigned flags;
55 uint8_t kernel_operstate;
56
57 Network *network;
58
59 LinkState state;
60 LinkOperationalState operstate;
61
62 unsigned address_messages;
63 unsigned address_label_messages;
64 unsigned neighbor_messages;
65 unsigned route_messages;
66 unsigned routing_policy_rule_messages;
67 unsigned routing_policy_rule_remove_messages;
68 unsigned enslaving;
69 /* link_is_enslaved() has additional checks. So, it is named _raw. */
70 bool enslaved_raw;
71
72 Set *addresses;
73 Set *addresses_foreign;
74 Set *routes;
75 Set *routes_foreign;
76
77 bool addresses_configured;
78 bool addresses_ready;
79
80 sd_dhcp_client *dhcp_client;
81 sd_dhcp_lease *dhcp_lease;
82 char *lease_file;
83 uint32_t original_mtu;
84 unsigned dhcp4_messages;
85 bool dhcp4_configured;
86 bool dhcp6_configured;
87
88 unsigned ndisc_messages;
89 bool ndisc_configured;
90
91 sd_ipv4ll *ipv4ll;
92 bool ipv4ll_address:1;
93 bool ipv4ll_route:1;
94
95 bool neighbors_configured;
96
97 bool static_routes_configured;
98 bool routing_policy_rules_configured;
99 bool setting_mtu;
100
101 LIST_HEAD(Address, pool_addresses);
102
103 sd_dhcp_server *dhcp_server;
104
105 sd_ndisc *ndisc;
106 Set *ndisc_rdnss;
107 Set *ndisc_dnssl;
108
109 sd_radv *radv;
110
111 sd_dhcp6_client *dhcp6_client;
112 bool rtnl_extended_attrs;
113
114 /* This is about LLDP reception */
115 sd_lldp *lldp;
116 char *lldp_file;
117
118 /* This is about LLDP transmission */
119 unsigned lldp_tx_fast; /* The LLDP txFast counter (See 802.1ab-2009, section 9.2.5.18) */
120 sd_event_source *lldp_emit_event_source;
121
122 Hashmap *bound_by_links;
123 Hashmap *bound_to_links;
124 Hashmap *slaves;
125 } Link;
126
127 typedef int (*link_netlink_message_handler_t)(sd_netlink*, sd_netlink_message*, Link*);
128
129 DUID *link_get_duid(Link *link);
130 int get_product_uuid_handler(sd_bus_message *m, void *userdata, sd_bus_error *ret_error);
131
132 Link *link_unref(Link *link);
133 Link *link_ref(Link *link);
134 DEFINE_TRIVIAL_DESTRUCTOR(link_netlink_destroy_callback, Link, link_unref);
135
136 int link_get(Manager *m, int ifindex, Link **ret);
137 int link_add(Manager *manager, sd_netlink_message *message, Link **ret);
138 void link_drop(Link *link);
139
140 int link_down(Link *link);
141
142 void link_enter_failed(Link *link);
143 int link_initialized(Link *link, sd_device *device);
144
145 void link_check_ready(Link *link);
146
147 void link_update_operstate(Link *link, bool also_update_bond_master);
148 int link_update(Link *link, sd_netlink_message *message);
149
150 void link_dirty(Link *link);
151 void link_clean(Link *link);
152 int link_save(Link *link);
153
154 int link_carrier_reset(Link *link);
155 bool link_has_carrier(Link *link);
156
157 int link_ipv6ll_gained(Link *link, const struct in6_addr *address);
158
159 int link_set_mtu(Link *link, uint32_t mtu, bool force);
160
161 int ipv4ll_configure(Link *link);
162 int dhcp4_configure(Link *link);
163 int dhcp4_set_client_identifier(Link *link);
164 int dhcp4_set_promote_secondaries(Link *link);
165 int dhcp6_request_prefix_delegation(Link *link);
166 int dhcp6_configure(Link *link);
167 int dhcp6_request_address(Link *link, int ir);
168 int dhcp6_lease_pd_prefix_lost(sd_dhcp6_client *client, Link* link);
169
170 const char* link_state_to_string(LinkState s) _const_;
171 LinkState link_state_from_string(const char *s) _pure_;
172
173 extern const sd_bus_vtable link_vtable[];
174
175 int link_node_enumerator(sd_bus *bus, const char *path, void *userdata, char ***nodes, sd_bus_error *error);
176 int link_object_find(sd_bus *bus, const char *path, const char *interface, void *userdata, void **found, sd_bus_error *error);
177 int link_send_changed(Link *link, const char *property, ...) _sentinel_;
178
179 uint32_t link_get_vrf_table(Link *link);
180 uint32_t link_get_dhcp_route_table(Link *link);
181 uint32_t link_get_ipv6_accept_ra_route_table(Link *link);
182
183 #define ADDRESS_FMT_VAL(address) \
184 be32toh((address).s_addr) >> 24, \
185 (be32toh((address).s_addr) >> 16) & 0xFFu, \
186 (be32toh((address).s_addr) >> 8) & 0xFFu, \
187 be32toh((address).s_addr) & 0xFFu