]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/network/networkd-link.h
core,network: Use const qualifiers for block-local variables in macro functions ...
[thirdparty/systemd.git] / src / network / networkd-link.h
1 #pragma once
2
3 /***
4 This file is part of systemd.
5
6 Copyright 2013 Tom Gundersen <teg@jklm.no>
7
8 systemd is free software; you can redistribute it and/or modify it
9 under the terms of the GNU Lesser General Public License as published by
10 the Free Software Foundation; either version 2.1 of the License, or
11 (at your option) any later version.
12
13 systemd is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 Lesser General Public License for more details.
17
18 You should have received a copy of the GNU Lesser General Public License
19 along with systemd; If not, see <http://www.gnu.org/licenses/>.
20 ***/
21
22 #include <endian.h>
23
24 #include "sd-bus.h"
25 #include "sd-dhcp-client.h"
26 #include "sd-dhcp-server.h"
27 #include "sd-dhcp6-client.h"
28 #include "sd-ipv4ll.h"
29 #include "sd-lldp.h"
30 #include "sd-ndisc.h"
31 #include "sd-netlink.h"
32
33 #include "list.h"
34 #include "set.h"
35
36 typedef enum LinkState {
37 LINK_STATE_PENDING,
38 LINK_STATE_ENSLAVING,
39 LINK_STATE_SETTING_ADDRESSES,
40 LINK_STATE_SETTING_ROUTES,
41 LINK_STATE_CONFIGURED,
42 LINK_STATE_UNMANAGED,
43 LINK_STATE_FAILED,
44 LINK_STATE_LINGER,
45 _LINK_STATE_MAX,
46 _LINK_STATE_INVALID = -1
47 } LinkState;
48
49 typedef enum LinkOperationalState {
50 LINK_OPERSTATE_OFF,
51 LINK_OPERSTATE_NO_CARRIER,
52 LINK_OPERSTATE_DORMANT,
53 LINK_OPERSTATE_CARRIER,
54 LINK_OPERSTATE_DEGRADED,
55 LINK_OPERSTATE_ROUTABLE,
56 _LINK_OPERSTATE_MAX,
57 _LINK_OPERSTATE_INVALID = -1
58 } LinkOperationalState;
59
60 typedef struct Manager Manager;
61 typedef struct Network Network;
62 typedef struct Address Address;
63
64 typedef struct Link {
65 Manager *manager;
66
67 int n_ref;
68
69 int ifindex;
70 char *ifname;
71 char *kind;
72 unsigned short iftype;
73 char *state_file;
74 struct ether_addr mac;
75 struct in6_addr ipv6ll_address;
76 uint32_t mtu;
77 struct udev_device *udev_device;
78
79 unsigned flags;
80 uint8_t kernel_operstate;
81
82 Network *network;
83
84 LinkState state;
85 LinkOperationalState operstate;
86
87 unsigned link_messages;
88 unsigned enslaving;
89
90 Set *addresses;
91 Set *addresses_foreign;
92 Set *routes;
93 Set *routes_foreign;
94
95 sd_dhcp_client *dhcp_client;
96 sd_dhcp_lease *dhcp_lease;
97 char *lease_file;
98 uint16_t original_mtu;
99 unsigned dhcp4_messages;
100 bool dhcp4_configured;
101 bool dhcp6_configured;
102
103 unsigned ndisc_messages;
104 bool ndisc_configured;
105
106 sd_ipv4ll *ipv4ll;
107 bool ipv4ll_address:1;
108 bool ipv4ll_route:1;
109
110 bool static_configured;
111
112 LIST_HEAD(Address, pool_addresses);
113
114 sd_dhcp_server *dhcp_server;
115
116 sd_ndisc *ndisc;
117 Set *ndisc_rdnss;
118 Set *ndisc_dnssl;
119
120 sd_dhcp6_client *dhcp6_client;
121 bool rtnl_extended_attrs;
122
123 /* This is about LLDP reception */
124 sd_lldp *lldp;
125 char *lldp_file;
126
127 /* This is about LLDP transmission */
128 unsigned lldp_tx_fast; /* The LLDP txFast counter (See 802.1ab-2009, section 9.2.5.18) */
129 sd_event_source *lldp_emit_event_source;
130
131 Hashmap *bound_by_links;
132 Hashmap *bound_to_links;
133 } Link;
134
135 Link *link_unref(Link *link);
136 Link *link_ref(Link *link);
137 int link_get(Manager *m, int ifindex, Link **ret);
138 int link_add(Manager *manager, sd_netlink_message *message, Link **ret);
139 void link_drop(Link *link);
140
141 int link_address_remove_handler(sd_netlink *rtnl, sd_netlink_message *m, void *userdata);
142 int link_route_remove_handler(sd_netlink *rtnl, sd_netlink_message *m, void *userdata);
143
144 void link_enter_failed(Link *link);
145 int link_initialized(Link *link, struct udev_device *device);
146
147 void link_check_ready(Link *link);
148
149 void link_update_operstate(Link *link);
150 int link_update(Link *link, sd_netlink_message *message);
151
152 void link_dirty(Link *link);
153 void link_clean(Link *link);
154 int link_save(Link *link);
155
156 int link_carrier_reset(Link *link);
157 bool link_has_carrier(Link *link);
158
159 int link_ipv6ll_gained(Link *link, const struct in6_addr *address);
160
161 int link_set_mtu(Link *link, uint32_t mtu);
162 int link_set_hostname(Link *link, const char *hostname);
163 int link_set_timezone(Link *link, const char *timezone);
164
165 int ipv4ll_configure(Link *link);
166 int dhcp4_configure(Link *link);
167 int dhcp6_configure(Link *link);
168 int dhcp6_request_address(Link *link, int ir);
169
170 const char* link_state_to_string(LinkState s) _const_;
171 LinkState link_state_from_string(const char *s) _pure_;
172
173 const char* link_operstate_to_string(LinkOperationalState s) _const_;
174 LinkOperationalState link_operstate_from_string(const char *s) _pure_;
175
176 extern const sd_bus_vtable link_vtable[];
177
178 int link_node_enumerator(sd_bus *bus, const char *path, void *userdata, char ***nodes, sd_bus_error *error);
179 int link_object_find(sd_bus *bus, const char *path, const char *interface, void *userdata, void **found, sd_bus_error *error);
180 int link_send_changed(Link *link, const char *property, ...) _sentinel_;
181
182 DEFINE_TRIVIAL_CLEANUP_FUNC(Link*, link_unref);
183 #define _cleanup_link_unref_ _cleanup_(link_unrefp)
184
185 /* Macros which append INTERFACE= to the message */
186
187 #define log_link_full(link, level, error, ...) \
188 ({ \
189 const Link *_l = (link); \
190 _l ? log_object_internal(level, error, __FILE__, __LINE__, __func__, "INTERFACE=", _l->ifname, ##__VA_ARGS__) : \
191 log_internal(level, error, __FILE__, __LINE__, __func__, ##__VA_ARGS__); \
192 }) \
193
194 #define log_link_debug(link, ...) log_link_full(link, LOG_DEBUG, 0, ##__VA_ARGS__)
195 #define log_link_info(link, ...) log_link_full(link, LOG_INFO, 0, ##__VA_ARGS__)
196 #define log_link_notice(link, ...) log_link_full(link, LOG_NOTICE, 0, ##__VA_ARGS__)
197 #define log_link_warning(link, ...) log_link_full(link, LOG_WARNING, 0, ##__VA_ARGS__)
198 #define log_link_error(link, ...) log_link_full(link, LOG_ERR, 0, ##__VA_ARGS__)
199
200 #define log_link_debug_errno(link, error, ...) log_link_full(link, LOG_DEBUG, error, ##__VA_ARGS__)
201 #define log_link_info_errno(link, error, ...) log_link_full(link, LOG_INFO, error, ##__VA_ARGS__)
202 #define log_link_notice_errno(link, error, ...) log_link_full(link, LOG_NOTICE, error, ##__VA_ARGS__)
203 #define log_link_warning_errno(link, error, ...) log_link_full(link, LOG_WARNING, error, ##__VA_ARGS__)
204 #define log_link_error_errno(link, error, ...) log_link_full(link, LOG_ERR, error, ##__VA_ARGS__)
205
206 #define LOG_LINK_MESSAGE(link, fmt, ...) "MESSAGE=%s: " fmt, (link)->ifname, ##__VA_ARGS__
207 #define LOG_LINK_INTERFACE(link) "INTERFACE=%s", (link)->ifname
208
209 #define ADDRESS_FMT_VAL(address) \
210 be32toh((address).s_addr) >> 24, \
211 (be32toh((address).s_addr) >> 16) & 0xFFu, \
212 (be32toh((address).s_addr) >> 8) & 0xFFu, \
213 be32toh((address).s_addr) & 0xFFu