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