]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/network/networkd-link.h
tree-wide: drop 'This file is part of systemd' blurb
[thirdparty/systemd.git] / src / network / networkd-link.h
1 /* SPDX-License-Identifier: LGPL-2.1+ */
2 #pragma once
3
4 /***
5 Copyright 2013 Tom Gundersen <teg@jklm.no>
6 ***/
7
8 #include <endian.h>
9
10 #include "sd-bus.h"
11 #include "sd-dhcp-client.h"
12 #include "sd-dhcp-server.h"
13 #include "sd-dhcp6-client.h"
14 #include "sd-ipv4ll.h"
15 #include "sd-lldp.h"
16 #include "sd-ndisc.h"
17 #include "sd-radv.h"
18 #include "sd-netlink.h"
19
20 #include "list.h"
21 #include "set.h"
22
23 typedef enum LinkState {
24 LINK_STATE_PENDING,
25 LINK_STATE_ENSLAVING,
26 LINK_STATE_SETTING_ADDRESSES,
27 LINK_STATE_SETTING_ROUTES,
28 LINK_STATE_CONFIGURED,
29 LINK_STATE_UNMANAGED,
30 LINK_STATE_FAILED,
31 LINK_STATE_LINGER,
32 _LINK_STATE_MAX,
33 _LINK_STATE_INVALID = -1
34 } LinkState;
35
36 typedef enum LinkOperationalState {
37 LINK_OPERSTATE_OFF,
38 LINK_OPERSTATE_NO_CARRIER,
39 LINK_OPERSTATE_DORMANT,
40 LINK_OPERSTATE_CARRIER,
41 LINK_OPERSTATE_DEGRADED,
42 LINK_OPERSTATE_ROUTABLE,
43 _LINK_OPERSTATE_MAX,
44 _LINK_OPERSTATE_INVALID = -1
45 } LinkOperationalState;
46
47 typedef struct Manager Manager;
48 typedef struct Network Network;
49 typedef struct Address Address;
50
51 typedef struct Link {
52 Manager *manager;
53
54 int n_ref;
55
56 int ifindex;
57 char *ifname;
58 char *kind;
59 unsigned short iftype;
60 char *state_file;
61 struct ether_addr mac;
62 struct in6_addr ipv6ll_address;
63 uint32_t mtu;
64 struct udev_device *udev_device;
65
66 unsigned flags;
67 uint8_t kernel_operstate;
68
69 Network *network;
70
71 LinkState state;
72 LinkOperationalState operstate;
73
74 unsigned address_messages;
75 unsigned address_label_messages;
76 unsigned route_messages;
77 unsigned routing_policy_rule_messages;
78 unsigned routing_policy_rule_remove_messages;
79 unsigned enslaving;
80
81 Set *addresses;
82 Set *addresses_foreign;
83 Set *routes;
84 Set *routes_foreign;
85
86 sd_dhcp_client *dhcp_client;
87 sd_dhcp_lease *dhcp_lease;
88 char *lease_file;
89 uint32_t original_mtu;
90 unsigned dhcp4_messages;
91 bool dhcp4_configured;
92 bool dhcp6_configured;
93
94 unsigned ndisc_messages;
95 bool ndisc_configured;
96
97 sd_ipv4ll *ipv4ll;
98 bool ipv4ll_address:1;
99 bool ipv4ll_route:1;
100
101 bool static_routes_configured;
102 bool routing_policy_rules_configured;
103 bool setting_mtu;
104
105 LIST_HEAD(Address, pool_addresses);
106
107 sd_dhcp_server *dhcp_server;
108
109 sd_ndisc *ndisc;
110 Set *ndisc_rdnss;
111 Set *ndisc_dnssl;
112
113 sd_radv *radv;
114
115 sd_dhcp6_client *dhcp6_client;
116 bool rtnl_extended_attrs;
117
118 /* This is about LLDP reception */
119 sd_lldp *lldp;
120 char *lldp_file;
121
122 /* This is about LLDP transmission */
123 unsigned lldp_tx_fast; /* The LLDP txFast counter (See 802.1ab-2009, section 9.2.5.18) */
124 sd_event_source *lldp_emit_event_source;
125
126 Hashmap *bound_by_links;
127 Hashmap *bound_to_links;
128 } Link;
129
130 Link *link_unref(Link *link);
131 Link *link_ref(Link *link);
132 int link_get(Manager *m, int ifindex, Link **ret);
133 int link_add(Manager *manager, sd_netlink_message *message, Link **ret);
134 void link_drop(Link *link);
135
136 int link_up(Link *link);
137 int link_down(Link *link);
138
139 int link_address_remove_handler(sd_netlink *rtnl, sd_netlink_message *m, void *userdata);
140 int link_route_remove_handler(sd_netlink *rtnl, sd_netlink_message *m, void *userdata);
141
142 void link_enter_failed(Link *link);
143 int link_initialized(Link *link, struct udev_device *device);
144
145 void link_check_ready(Link *link);
146
147 void link_update_operstate(Link *link);
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);
160
161 int ipv4ll_configure(Link *link);
162 int dhcp4_configure(Link *link);
163 int dhcp4_set_promote_secondaries(Link *link);
164 int dhcp6_configure(Link *link);
165 int dhcp6_request_address(Link *link, int ir);
166
167 const char* link_state_to_string(LinkState s) _const_;
168 LinkState link_state_from_string(const char *s) _pure_;
169
170 const char* link_operstate_to_string(LinkOperationalState s) _const_;
171 LinkOperationalState link_operstate_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 DEFINE_TRIVIAL_CLEANUP_FUNC(Link*, link_unref);
180
181 /* Macros which append INTERFACE= to the message */
182
183 #define log_link_full(link, level, error, ...) \
184 ({ \
185 const Link *_l = (link); \
186 _l ? log_object_internal(level, error, __FILE__, __LINE__, __func__, "INTERFACE=", _l->ifname, NULL, NULL, ##__VA_ARGS__) : \
187 log_internal(level, error, __FILE__, __LINE__, __func__, ##__VA_ARGS__); \
188 }) \
189
190 #define log_link_debug(link, ...) log_link_full(link, LOG_DEBUG, 0, ##__VA_ARGS__)
191 #define log_link_info(link, ...) log_link_full(link, LOG_INFO, 0, ##__VA_ARGS__)
192 #define log_link_notice(link, ...) log_link_full(link, LOG_NOTICE, 0, ##__VA_ARGS__)
193 #define log_link_warning(link, ...) log_link_full(link, LOG_WARNING, 0, ##__VA_ARGS__)
194 #define log_link_error(link, ...) log_link_full(link, LOG_ERR, 0, ##__VA_ARGS__)
195
196 #define log_link_debug_errno(link, error, ...) log_link_full(link, LOG_DEBUG, error, ##__VA_ARGS__)
197 #define log_link_info_errno(link, error, ...) log_link_full(link, LOG_INFO, error, ##__VA_ARGS__)
198 #define log_link_notice_errno(link, error, ...) log_link_full(link, LOG_NOTICE, error, ##__VA_ARGS__)
199 #define log_link_warning_errno(link, error, ...) log_link_full(link, LOG_WARNING, error, ##__VA_ARGS__)
200 #define log_link_error_errno(link, error, ...) log_link_full(link, LOG_ERR, error, ##__VA_ARGS__)
201
202 #define LOG_LINK_MESSAGE(link, fmt, ...) "MESSAGE=%s: " fmt, (link)->ifname, ##__VA_ARGS__
203 #define LOG_LINK_INTERFACE(link) "INTERFACE=%s", (link)->ifname
204
205 #define ADDRESS_FMT_VAL(address) \
206 be32toh((address).s_addr) >> 24, \
207 (be32toh((address).s_addr) >> 16) & 0xFFu, \
208 (be32toh((address).s_addr) >> 8) & 0xFFu, \
209 be32toh((address).s_addr) & 0xFFu