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