]>
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" |
fc2f9534 LP |
7 | #include "sd-dhcp-client.h" |
8 | #include "sd-dhcp-server.h" | |
fc2f9534 | 9 | #include "sd-dhcp6-client.h" |
07630cea | 10 | #include "sd-ipv4ll.h" |
fc2f9534 | 11 | #include "sd-lldp.h" |
07630cea | 12 | #include "sd-ndisc.h" |
9d5d0090 | 13 | #include "sd-radv.h" |
634f0f98 | 14 | #include "sd-netlink.h" |
fc2f9534 | 15 | |
634f0f98 ZJS |
16 | #include "list.h" |
17 | #include "set.h" | |
0b1831c2 TG |
18 | |
19 | typedef enum LinkState { | |
8434fd5c | 20 | LINK_STATE_PENDING, |
0b1831c2 TG |
21 | LINK_STATE_ENSLAVING, |
22 | LINK_STATE_SETTING_ADDRESSES, | |
23 | LINK_STATE_SETTING_ROUTES, | |
24 | LINK_STATE_CONFIGURED, | |
25 | LINK_STATE_UNMANAGED, | |
26 | LINK_STATE_FAILED, | |
27 | LINK_STATE_LINGER, | |
28 | _LINK_STATE_MAX, | |
29 | _LINK_STATE_INVALID = -1 | |
30 | } LinkState; | |
31 | ||
fc2f9534 LP |
32 | typedef enum LinkOperationalState { |
33 | LINK_OPERSTATE_OFF, | |
34 | LINK_OPERSTATE_NO_CARRIER, | |
35 | LINK_OPERSTATE_DORMANT, | |
36 | LINK_OPERSTATE_CARRIER, | |
37 | LINK_OPERSTATE_DEGRADED, | |
38 | LINK_OPERSTATE_ROUTABLE, | |
39 | _LINK_OPERSTATE_MAX, | |
40 | _LINK_OPERSTATE_INVALID = -1 | |
41 | } LinkOperationalState; | |
42 | ||
634f0f98 ZJS |
43 | typedef struct Manager Manager; |
44 | typedef struct Network Network; | |
45 | typedef struct Address Address; | |
f24648a6 | 46 | typedef struct DUID DUID; |
fc2f9534 | 47 | |
634f0f98 | 48 | typedef struct Link { |
0b1831c2 TG |
49 | Manager *manager; |
50 | ||
51 | int n_ref; | |
52 | ||
53 | int ifindex; | |
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 TG |
60 | uint32_t mtu; |
61 | struct udev_device *udev_device; | |
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; | |
73 | unsigned route_messages; | |
74 | unsigned routing_policy_rule_messages; | |
75 | unsigned routing_policy_rule_remove_messages; | |
0b1831c2 TG |
76 | unsigned enslaving; |
77 | ||
cf1d700d | 78 | Set *addresses; |
adda1ed9 | 79 | Set *addresses_foreign; |
1c8e710c TG |
80 | Set *routes; |
81 | Set *routes_foreign; | |
0b1831c2 TG |
82 | |
83 | sd_dhcp_client *dhcp_client; | |
84 | sd_dhcp_lease *dhcp_lease; | |
85 | char *lease_file; | |
4e964aa0 | 86 | uint32_t original_mtu; |
3c9b8860 TG |
87 | unsigned dhcp4_messages; |
88 | bool dhcp4_configured; | |
18d29550 | 89 | bool dhcp6_configured; |
1e7a0e21 | 90 | |
3b015d40 TG |
91 | unsigned ndisc_messages; |
92 | bool ndisc_configured; | |
b22d8a00 | 93 | |
0b1831c2 | 94 | sd_ipv4ll *ipv4ll; |
e7ab854c TG |
95 | bool ipv4ll_address:1; |
96 | bool ipv4ll_route:1; | |
0b1831c2 | 97 | |
7715629e ST |
98 | bool static_routes_configured; |
99 | bool routing_policy_rules_configured; | |
97e7fb39 | 100 | bool setting_mtu; |
3c9b8860 | 101 | |
0b1831c2 TG |
102 | LIST_HEAD(Address, pool_addresses); |
103 | ||
104 | sd_dhcp_server *dhcp_server; | |
105 | ||
1e7a0e21 LP |
106 | sd_ndisc *ndisc; |
107 | Set *ndisc_rdnss; | |
108 | Set *ndisc_dnssl; | |
109 | ||
091214b6 PF |
110 | sd_radv *radv; |
111 | ||
0b1831c2 | 112 | sd_dhcp6_client *dhcp6_client; |
be3a09b7 | 113 | bool rtnl_extended_attrs; |
ce43e484 | 114 | |
8e1ad1ea | 115 | /* This is about LLDP reception */ |
ce43e484 | 116 | sd_lldp *lldp; |
49699bac | 117 | char *lldp_file; |
0d4ad91d | 118 | |
8e1ad1ea LP |
119 | /* This is about LLDP transmission */ |
120 | unsigned lldp_tx_fast; /* The LLDP txFast counter (See 802.1ab-2009, section 9.2.5.18) */ | |
7272b25e | 121 | sd_event_source *lldp_emit_event_source; |
8e1ad1ea | 122 | |
0d4ad91d AR |
123 | Hashmap *bound_by_links; |
124 | Hashmap *bound_to_links; | |
634f0f98 | 125 | } Link; |
0b1831c2 | 126 | |
f24648a6 YW |
127 | DUID *link_get_duid(Link *link); |
128 | ||
0b1831c2 TG |
129 | Link *link_unref(Link *link); |
130 | Link *link_ref(Link *link); | |
131 | int link_get(Manager *m, int ifindex, Link **ret); | |
1c4baffc | 132 | int link_add(Manager *manager, sd_netlink_message *message, Link **ret); |
0b1831c2 TG |
133 | void link_drop(Link *link); |
134 | ||
14b6bb77 RW |
135 | int link_up(Link *link); |
136 | int link_down(Link *link); | |
137 | ||
91b5f997 TG |
138 | int link_address_remove_handler(sd_netlink *rtnl, sd_netlink_message *m, void *userdata); |
139 | int link_route_remove_handler(sd_netlink *rtnl, sd_netlink_message *m, void *userdata); | |
0b1831c2 | 140 | |
b22d8a00 | 141 | void link_enter_failed(Link *link); |
0b1831c2 TG |
142 | int link_initialized(Link *link, struct udev_device *device); |
143 | ||
8012cd39 | 144 | void link_check_ready(Link *link); |
b22d8a00 | 145 | |
84de38c5 | 146 | void link_update_operstate(Link *link); |
1c4baffc | 147 | int link_update(Link *link, sd_netlink_message *message); |
b22d8a00 | 148 | |
84de38c5 TG |
149 | void link_dirty(Link *link); |
150 | void link_clean(Link *link); | |
0b1831c2 TG |
151 | int link_save(Link *link); |
152 | ||
9c0a72f9 | 153 | int link_carrier_reset(Link *link); |
a61bb41c | 154 | bool link_has_carrier(Link *link); |
0b1831c2 | 155 | |
c601ebf7 | 156 | int link_ipv6ll_gained(Link *link, const struct in6_addr *address); |
e7ab854c | 157 | |
3c9b8860 | 158 | int link_set_mtu(Link *link, uint32_t mtu); |
3c9b8860 | 159 | |
b22d8a00 | 160 | int ipv4ll_configure(Link *link); |
3c9b8860 | 161 | int dhcp4_configure(Link *link); |
fff1f40c | 162 | int dhcp4_set_client_identifier(Link *link); |
64b21ece | 163 | int dhcp4_set_promote_secondaries(Link *link); |
7a695d8e | 164 | int dhcp6_configure(Link *link); |
720bec40 | 165 | int dhcp6_request_address(Link *link, int ir); |
b22d8a00 | 166 | |
0b1831c2 TG |
167 | const char* link_state_to_string(LinkState s) _const_; |
168 | LinkState link_state_from_string(const char *s) _pure_; | |
169 | ||
fc2f9534 LP |
170 | const char* link_operstate_to_string(LinkOperationalState s) _const_; |
171 | LinkOperationalState link_operstate_from_string(const char *s) _pure_; | |
172 | ||
e331e246 TG |
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_; | |
0b1831c2 TG |
178 | |
179 | DEFINE_TRIVIAL_CLEANUP_FUNC(Link*, link_unref); | |
0b1831c2 TG |
180 | |
181 | /* Macros which append INTERFACE= to the message */ | |
182 | ||
f2341e0a LP |
183 | #define log_link_full(link, level, error, ...) \ |
184 | ({ \ | |
8dec4a9d | 185 | const Link *_l = (link); \ |
4b58153d | 186 | _l ? log_object_internal(level, error, __FILE__, __LINE__, __func__, "INTERFACE=", _l->ifname, NULL, NULL, ##__VA_ARGS__) : \ |
f2341e0a LP |
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__) | |
6c861f0a LP |
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 | ||
f2341e0a LP |
202 | #define LOG_LINK_MESSAGE(link, fmt, ...) "MESSAGE=%s: " fmt, (link)->ifname, ##__VA_ARGS__ |
203 | #define LOG_LINK_INTERFACE(link) "INTERFACE=%s", (link)->ifname | |
0b1831c2 | 204 | |
80431934 PM |
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 |