]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/network/networkd-link.h
ac1532c066fc2171014fb6e9791dd10b1065c18a
[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 "networkd-util.h"
21 #include "set.h"
22
23 typedef enum LinkState {
24 LINK_STATE_PENDING, /* udev has not initialized the link */
25 LINK_STATE_INITIALIZED, /* udev has initialized the link */
26 LINK_STATE_CONFIGURING, /* configuring addresses, routes, etc. */
27 LINK_STATE_CONFIGURED, /* everything is configured */
28 LINK_STATE_UNMANAGED, /* Unmanaged=yes is set */
29 LINK_STATE_FAILED, /* at least one configuration process failed */
30 LINK_STATE_LINGER, /* RTM_DELLINK for the link has been received */
31 _LINK_STATE_MAX,
32 _LINK_STATE_INVALID = -1
33 } LinkState;
34
35 typedef struct Manager Manager;
36 typedef struct Network Network;
37 typedef struct Address Address;
38 typedef struct DUID DUID;
39
40 typedef struct Link {
41 Manager *manager;
42
43 unsigned n_ref;
44
45 int ifindex;
46 int master_ifindex;
47 char *ifname;
48 char *kind;
49 unsigned short iftype;
50 char *state_file;
51 struct ether_addr mac;
52 struct in6_addr ipv6ll_address;
53 uint32_t mtu;
54 sd_device *sd_device;
55
56 unsigned flags;
57 uint8_t kernel_operstate;
58
59 Network *network;
60
61 LinkState state;
62 LinkOperationalState operstate;
63 LinkCarrierState carrier_state;
64 LinkAddressState address_state;
65
66 unsigned address_messages;
67 unsigned address_label_messages;
68 unsigned neighbor_messages;
69 unsigned route_messages;
70 unsigned routing_policy_rule_messages;
71 unsigned routing_policy_rule_remove_messages;
72 unsigned enslaving;
73
74 Set *addresses;
75 Set *addresses_foreign;
76 Set *routes;
77 Set *routes_foreign;
78
79 bool addresses_configured;
80 bool addresses_ready;
81
82 sd_dhcp_client *dhcp_client;
83 sd_dhcp_lease *dhcp_lease, *dhcp_lease_old;
84 char *lease_file;
85 uint32_t original_mtu;
86 unsigned dhcp4_messages;
87 bool dhcp4_configured;
88 bool dhcp6_configured;
89
90 unsigned ndisc_messages;
91 bool ndisc_configured;
92
93 sd_ipv4ll *ipv4ll;
94 bool ipv4ll_address:1;
95 bool ipv4ll_route:1;
96
97 bool neighbors_configured;
98
99 bool static_routes_configured;
100 bool routing_policy_rules_configured;
101 bool setting_mtu;
102
103 LIST_HEAD(Address, pool_addresses);
104
105 sd_dhcp_server *dhcp_server;
106
107 sd_ndisc *ndisc;
108 Set *ndisc_rdnss;
109 Set *ndisc_dnssl;
110
111 sd_radv *radv;
112
113 sd_dhcp6_client *dhcp6_client;
114 bool rtnl_extended_attrs;
115
116 /* This is about LLDP reception */
117 sd_lldp *lldp;
118 char *lldp_file;
119
120 /* This is about LLDP transmission */
121 unsigned lldp_tx_fast; /* The LLDP txFast counter (See 802.1ab-2009, section 9.2.5.18) */
122 sd_event_source *lldp_emit_event_source;
123
124 Hashmap *bound_by_links;
125 Hashmap *bound_to_links;
126 Set *slaves;
127
128 /* For speed meter */
129 struct rtnl_link_stats64 stats_old, stats_new;
130 bool stats_updated;
131
132 int sysctl_ipv6_enabled;
133 } Link;
134
135 typedef int (*link_netlink_message_handler_t)(sd_netlink*, sd_netlink_message*, Link*);
136
137 DUID *link_get_duid(Link *link);
138 int get_product_uuid_handler(sd_bus_message *m, void *userdata, sd_bus_error *ret_error);
139
140 Link *link_unref(Link *link);
141 Link *link_ref(Link *link);
142 DEFINE_TRIVIAL_CLEANUP_FUNC(Link*, link_unref);
143 DEFINE_TRIVIAL_DESTRUCTOR(link_netlink_destroy_callback, Link, link_unref);
144
145 int link_get(Manager *m, int ifindex, Link **ret);
146 int link_add(Manager *manager, sd_netlink_message *message, Link **ret);
147 void link_drop(Link *link);
148
149 int link_down(Link *link, link_netlink_message_handler_t callback);
150
151 void link_enter_failed(Link *link);
152 int link_initialized(Link *link, sd_device *device);
153
154 void link_set_state(Link *link, LinkState state);
155 void link_check_ready(Link *link);
156
157 void link_update_operstate(Link *link, bool also_update_bond_master);
158 int link_update(Link *link, sd_netlink_message *message);
159
160 void link_dirty(Link *link);
161 void link_clean(Link *link);
162 int link_save(Link *link);
163
164 int link_carrier_reset(Link *link);
165 bool link_has_carrier(Link *link);
166
167 int link_ipv6ll_gained(Link *link, const struct in6_addr *address);
168
169 int link_set_mtu(Link *link, uint32_t mtu);
170
171 int ipv4ll_configure(Link *link);
172 bool link_ipv4ll_enabled(Link *link, AddressFamilyBoolean mask);
173
174 void dhcp4_release_old_lease(Link *link);
175 int dhcp4_configure(Link *link);
176 int dhcp4_set_client_identifier(Link *link);
177 int dhcp4_set_promote_secondaries(Link *link);
178 int dhcp6_request_prefix_delegation(Link *link);
179 int dhcp6_configure(Link *link);
180 int dhcp6_request_address(Link *link, int ir);
181 int dhcp6_lease_pd_prefix_lost(sd_dhcp6_client *client, Link* link);
182
183 int link_stop_clients(Link *link, bool may_keep_dhcp);
184
185 const char* link_state_to_string(LinkState s) _const_;
186 LinkState link_state_from_string(const char *s) _pure_;
187
188 uint32_t link_get_vrf_table(Link *link);
189 uint32_t link_get_dhcp_route_table(Link *link);
190 uint32_t link_get_ipv6_accept_ra_route_table(Link *link);
191 int link_request_set_routes(Link *link);
192
193 int link_sysctl_ipv6_enabled(Link *link);
194
195 #define ADDRESS_FMT_VAL(address) \
196 be32toh((address).s_addr) >> 24, \
197 (be32toh((address).s_addr) >> 16) & 0xFFu, \
198 (be32toh((address).s_addr) >> 8) & 0xFFu, \
199 be32toh((address).s_addr) & 0xFFu