]>
Commit | Line | Data |
---|---|---|
53e1b683 | 1 | /* SPDX-License-Identifier: LGPL-2.1+ */ |
fc2f9534 LP |
2 | #pragma once |
3 | ||
80431934 PM |
4 | #include <endian.h> |
5 | ||
634f0f98 | 6 | #include "sd-bus.h" |
51517f9e | 7 | #include "sd-device.h" |
fc2f9534 LP |
8 | #include "sd-dhcp-client.h" |
9 | #include "sd-dhcp-server.h" | |
fc2f9534 | 10 | #include "sd-dhcp6-client.h" |
07630cea | 11 | #include "sd-ipv4ll.h" |
fc2f9534 | 12 | #include "sd-lldp.h" |
07630cea | 13 | #include "sd-ndisc.h" |
9d5d0090 | 14 | #include "sd-radv.h" |
634f0f98 | 15 | #include "sd-netlink.h" |
fc2f9534 | 16 | |
634f0f98 ZJS |
17 | #include "list.h" |
18 | #include "set.h" | |
0b1831c2 TG |
19 | |
20 | typedef enum LinkState { | |
8434fd5c | 21 | LINK_STATE_PENDING, |
289e6774 | 22 | LINK_STATE_CONFIGURING, |
0b1831c2 TG |
23 | LINK_STATE_CONFIGURED, |
24 | LINK_STATE_UNMANAGED, | |
25 | LINK_STATE_FAILED, | |
26 | LINK_STATE_LINGER, | |
27 | _LINK_STATE_MAX, | |
28 | _LINK_STATE_INVALID = -1 | |
29 | } LinkState; | |
30 | ||
fc2f9534 LP |
31 | typedef enum LinkOperationalState { |
32 | LINK_OPERSTATE_OFF, | |
33 | LINK_OPERSTATE_NO_CARRIER, | |
34 | LINK_OPERSTATE_DORMANT, | |
35 | LINK_OPERSTATE_CARRIER, | |
36 | LINK_OPERSTATE_DEGRADED, | |
37 | LINK_OPERSTATE_ROUTABLE, | |
38 | _LINK_OPERSTATE_MAX, | |
39 | _LINK_OPERSTATE_INVALID = -1 | |
40 | } LinkOperationalState; | |
41 | ||
634f0f98 ZJS |
42 | typedef struct Manager Manager; |
43 | typedef struct Network Network; | |
44 | typedef struct Address Address; | |
f24648a6 | 45 | typedef struct DUID DUID; |
fc2f9534 | 46 | |
634f0f98 | 47 | typedef struct Link { |
0b1831c2 TG |
48 | Manager *manager; |
49 | ||
cf4b2f99 | 50 | unsigned n_ref; |
0b1831c2 TG |
51 | |
52 | int ifindex; | |
cbff7170 | 53 | int master_ifindex; |
0b1831c2 | 54 | char *ifname; |
6cad256d | 55 | char *kind; |
b710e6b6 | 56 | unsigned short iftype; |
0b1831c2 TG |
57 | char *state_file; |
58 | struct ether_addr mac; | |
c601ebf7 | 59 | struct in6_addr ipv6ll_address; |
0b1831c2 | 60 | uint32_t mtu; |
51517f9e | 61 | sd_device *sd_device; |
0b1831c2 TG |
62 | |
63 | unsigned flags; | |
64 | uint8_t kernel_operstate; | |
65 | ||
66 | Network *network; | |
67 | ||
68 | LinkState state; | |
69 | LinkOperationalState operstate; | |
70 | ||
7715629e ST |
71 | unsigned address_messages; |
72 | unsigned address_label_messages; | |
e4a71bf3 | 73 | unsigned neighbor_messages; |
7715629e ST |
74 | unsigned route_messages; |
75 | unsigned routing_policy_rule_messages; | |
76 | unsigned routing_policy_rule_remove_messages; | |
0b1831c2 TG |
77 | unsigned enslaving; |
78 | ||
cf1d700d | 79 | Set *addresses; |
adda1ed9 | 80 | Set *addresses_foreign; |
1c8e710c TG |
81 | Set *routes; |
82 | Set *routes_foreign; | |
0b1831c2 | 83 | |
c42ff3a1 WKI |
84 | bool addresses_configured; |
85 | ||
0b1831c2 TG |
86 | sd_dhcp_client *dhcp_client; |
87 | sd_dhcp_lease *dhcp_lease; | |
88 | char *lease_file; | |
4e964aa0 | 89 | uint32_t original_mtu; |
3c9b8860 TG |
90 | unsigned dhcp4_messages; |
91 | bool dhcp4_configured; | |
18d29550 | 92 | bool dhcp6_configured; |
1e7a0e21 | 93 | |
3b015d40 TG |
94 | unsigned ndisc_messages; |
95 | bool ndisc_configured; | |
b22d8a00 | 96 | |
0b1831c2 | 97 | sd_ipv4ll *ipv4ll; |
e7ab854c TG |
98 | bool ipv4ll_address:1; |
99 | bool ipv4ll_route:1; | |
0b1831c2 | 100 | |
e4a71bf3 WKI |
101 | bool neighbors_configured; |
102 | ||
7715629e ST |
103 | bool static_routes_configured; |
104 | bool routing_policy_rules_configured; | |
97e7fb39 | 105 | bool setting_mtu; |
3c9b8860 | 106 | |
0b1831c2 TG |
107 | LIST_HEAD(Address, pool_addresses); |
108 | ||
109 | sd_dhcp_server *dhcp_server; | |
110 | ||
1e7a0e21 LP |
111 | sd_ndisc *ndisc; |
112 | Set *ndisc_rdnss; | |
113 | Set *ndisc_dnssl; | |
114 | ||
091214b6 PF |
115 | sd_radv *radv; |
116 | ||
0b1831c2 | 117 | sd_dhcp6_client *dhcp6_client; |
be3a09b7 | 118 | bool rtnl_extended_attrs; |
ce43e484 | 119 | |
8e1ad1ea | 120 | /* This is about LLDP reception */ |
ce43e484 | 121 | sd_lldp *lldp; |
49699bac | 122 | char *lldp_file; |
0d4ad91d | 123 | |
8e1ad1ea LP |
124 | /* This is about LLDP transmission */ |
125 | unsigned lldp_tx_fast; /* The LLDP txFast counter (See 802.1ab-2009, section 9.2.5.18) */ | |
7272b25e | 126 | sd_event_source *lldp_emit_event_source; |
8e1ad1ea | 127 | |
0d4ad91d AR |
128 | Hashmap *bound_by_links; |
129 | Hashmap *bound_to_links; | |
634f0f98 | 130 | } Link; |
0b1831c2 | 131 | |
302a796f YW |
132 | typedef int (*link_netlink_message_handler_t)(sd_netlink*, sd_netlink_message*, Link*); |
133 | ||
f24648a6 | 134 | DUID *link_get_duid(Link *link); |
27dfc982 | 135 | int get_product_uuid_handler(sd_bus_message *m, void *userdata, sd_bus_error *ret_error); |
f24648a6 | 136 | |
0b1831c2 TG |
137 | Link *link_unref(Link *link); |
138 | Link *link_ref(Link *link); | |
302a796f | 139 | DEFINE_TRIVIAL_DESTRUCTOR(link_netlink_destroy_callback, Link, link_unref); |
1046bf9b | 140 | |
0b1831c2 | 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 | ||
b22d8a00 | 148 | void link_enter_failed(Link *link); |
51517f9e | 149 | int link_initialized(Link *link, sd_device *device); |
0b1831c2 | 150 | |
8012cd39 | 151 | void link_check_ready(Link *link); |
b22d8a00 | 152 | |
84de38c5 | 153 | void link_update_operstate(Link *link); |
1c4baffc | 154 | int link_update(Link *link, sd_netlink_message *message); |
b22d8a00 | 155 | |
84de38c5 TG |
156 | void link_dirty(Link *link); |
157 | void link_clean(Link *link); | |
0b1831c2 TG |
158 | int link_save(Link *link); |
159 | ||
9c0a72f9 | 160 | int link_carrier_reset(Link *link); |
a61bb41c | 161 | bool link_has_carrier(Link *link); |
0b1831c2 | 162 | |
c601ebf7 | 163 | int link_ipv6ll_gained(Link *link, const struct in6_addr *address); |
e7ab854c | 164 | |
3c9b8860 | 165 | int link_set_mtu(Link *link, uint32_t mtu); |
3c9b8860 | 166 | |
b22d8a00 | 167 | int ipv4ll_configure(Link *link); |
3c9b8860 | 168 | int dhcp4_configure(Link *link); |
fff1f40c | 169 | int dhcp4_set_client_identifier(Link *link); |
64b21ece | 170 | int dhcp4_set_promote_secondaries(Link *link); |
10752343 | 171 | int dhcp6_request_prefix_delegation(Link *link); |
7a695d8e | 172 | int dhcp6_configure(Link *link); |
720bec40 | 173 | int dhcp6_request_address(Link *link, int ir); |
65dd5e31 | 174 | int dhcp6_lease_pd_prefix_lost(sd_dhcp6_client *client, Link* link); |
b22d8a00 | 175 | |
0b1831c2 TG |
176 | const char* link_state_to_string(LinkState s) _const_; |
177 | LinkState link_state_from_string(const char *s) _pure_; | |
178 | ||
fc2f9534 LP |
179 | const char* link_operstate_to_string(LinkOperationalState s) _const_; |
180 | LinkOperationalState link_operstate_from_string(const char *s) _pure_; | |
181 | ||
e331e246 TG |
182 | extern const sd_bus_vtable link_vtable[]; |
183 | ||
184 | int link_node_enumerator(sd_bus *bus, const char *path, void *userdata, char ***nodes, sd_bus_error *error); | |
185 | int link_object_find(sd_bus *bus, const char *path, const char *interface, void *userdata, void **found, sd_bus_error *error); | |
186 | int link_send_changed(Link *link, const char *property, ...) _sentinel_; | |
0b1831c2 | 187 | |
0b1831c2 TG |
188 | /* Macros which append INTERFACE= to the message */ |
189 | ||
f2341e0a LP |
190 | #define log_link_full(link, level, error, ...) \ |
191 | ({ \ | |
8dec4a9d | 192 | const Link *_l = (link); \ |
4b58153d | 193 | _l ? log_object_internal(level, error, __FILE__, __LINE__, __func__, "INTERFACE=", _l->ifname, NULL, NULL, ##__VA_ARGS__) : \ |
f2341e0a LP |
194 | log_internal(level, error, __FILE__, __LINE__, __func__, ##__VA_ARGS__); \ |
195 | }) \ | |
196 | ||
197 | #define log_link_debug(link, ...) log_link_full(link, LOG_DEBUG, 0, ##__VA_ARGS__) | |
198 | #define log_link_info(link, ...) log_link_full(link, LOG_INFO, 0, ##__VA_ARGS__) | |
199 | #define log_link_notice(link, ...) log_link_full(link, LOG_NOTICE, 0, ##__VA_ARGS__) | |
200 | #define log_link_warning(link, ...) log_link_full(link, LOG_WARNING, 0, ##__VA_ARGS__) | |
201 | #define log_link_error(link, ...) log_link_full(link, LOG_ERR, 0, ##__VA_ARGS__) | |
6c861f0a LP |
202 | |
203 | #define log_link_debug_errno(link, error, ...) log_link_full(link, LOG_DEBUG, error, ##__VA_ARGS__) | |
204 | #define log_link_info_errno(link, error, ...) log_link_full(link, LOG_INFO, error, ##__VA_ARGS__) | |
205 | #define log_link_notice_errno(link, error, ...) log_link_full(link, LOG_NOTICE, error, ##__VA_ARGS__) | |
206 | #define log_link_warning_errno(link, error, ...) log_link_full(link, LOG_WARNING, error, ##__VA_ARGS__) | |
207 | #define log_link_error_errno(link, error, ...) log_link_full(link, LOG_ERR, error, ##__VA_ARGS__) | |
208 | ||
f2341e0a LP |
209 | #define LOG_LINK_MESSAGE(link, fmt, ...) "MESSAGE=%s: " fmt, (link)->ifname, ##__VA_ARGS__ |
210 | #define LOG_LINK_INTERFACE(link) "INTERFACE=%s", (link)->ifname | |
0b1831c2 | 211 | |
80431934 PM |
212 | #define ADDRESS_FMT_VAL(address) \ |
213 | be32toh((address).s_addr) >> 24, \ | |
214 | (be32toh((address).s_addr) >> 16) & 0xFFu, \ | |
215 | (be32toh((address).s_addr) >> 8) & 0xFFu, \ | |
216 | be32toh((address).s_addr) & 0xFFu |