1 /* SPDX-License-Identifier: LGPL-2.1+ */
8 #include "sd-dhcp-client.h"
9 #include "sd-dhcp-server.h"
10 #include "sd-dhcp6-client.h"
11 #include "sd-ipv4ll.h"
15 #include "sd-netlink.h"
20 typedef enum LinkState
{
23 LINK_STATE_SETTING_ADDRESSES
,
24 LINK_STATE_SETTING_ROUTES
,
25 LINK_STATE_CONFIGURED
,
30 _LINK_STATE_INVALID
= -1
33 typedef enum LinkOperationalState
{
35 LINK_OPERSTATE_NO_CARRIER
,
36 LINK_OPERSTATE_DORMANT
,
37 LINK_OPERSTATE_CARRIER
,
38 LINK_OPERSTATE_DEGRADED
,
39 LINK_OPERSTATE_ROUTABLE
,
41 _LINK_OPERSTATE_INVALID
= -1
42 } LinkOperationalState
;
44 typedef struct Manager Manager
;
45 typedef struct Network Network
;
46 typedef struct Address Address
;
47 typedef struct DUID DUID
;
58 unsigned short iftype
;
60 struct ether_addr mac
;
61 struct in6_addr ipv6ll_address
;
66 uint8_t kernel_operstate
;
71 LinkOperationalState operstate
;
73 unsigned address_messages
;
74 unsigned address_label_messages
;
75 unsigned route_messages
;
76 unsigned routing_policy_rule_messages
;
77 unsigned routing_policy_rule_remove_messages
;
81 Set
*addresses_foreign
;
85 sd_dhcp_client
*dhcp_client
;
86 sd_dhcp_lease
*dhcp_lease
;
88 uint32_t original_mtu
;
89 unsigned dhcp4_messages
;
90 bool dhcp4_configured
;
91 bool dhcp6_configured
;
93 unsigned ndisc_messages
;
94 bool ndisc_configured
;
97 bool ipv4ll_address
:1;
100 bool static_routes_configured
;
101 bool routing_policy_rules_configured
;
104 LIST_HEAD(Address
, pool_addresses
);
106 sd_dhcp_server
*dhcp_server
;
114 sd_dhcp6_client
*dhcp6_client
;
115 bool rtnl_extended_attrs
;
117 /* This is about LLDP reception */
121 /* This is about LLDP transmission */
122 unsigned lldp_tx_fast
; /* The LLDP txFast counter (See 802.1ab-2009, section 9.2.5.18) */
123 sd_event_source
*lldp_emit_event_source
;
125 Hashmap
*bound_by_links
;
126 Hashmap
*bound_to_links
;
129 DUID
*link_get_duid(Link
*link
);
130 int get_product_uuid_handler(sd_bus_message
*m
, void *userdata
, sd_bus_error
*ret_error
);
132 Link
*link_unref(Link
*link
);
133 Link
*link_ref(Link
*link
);
134 void link_netlink_destroy_callback(void *userdata
);
136 int link_get(Manager
*m
, int ifindex
, Link
**ret
);
137 int link_add(Manager
*manager
, sd_netlink_message
*message
, Link
**ret
);
138 void link_drop(Link
*link
);
140 int link_up(Link
*link
);
141 int link_down(Link
*link
);
143 void link_enter_failed(Link
*link
);
144 int link_initialized(Link
*link
, sd_device
*device
);
146 void link_check_ready(Link
*link
);
148 void link_update_operstate(Link
*link
);
149 int link_update(Link
*link
, sd_netlink_message
*message
);
151 void link_dirty(Link
*link
);
152 void link_clean(Link
*link
);
153 int link_save(Link
*link
);
155 int link_carrier_reset(Link
*link
);
156 bool link_has_carrier(Link
*link
);
158 int link_ipv6ll_gained(Link
*link
, const struct in6_addr
*address
);
160 int link_set_mtu(Link
*link
, uint32_t mtu
);
162 int ipv4ll_configure(Link
*link
);
163 int dhcp4_configure(Link
*link
);
164 int dhcp4_set_client_identifier(Link
*link
);
165 int dhcp4_set_promote_secondaries(Link
*link
);
166 int dhcp6_request_prefix_delegation(Link
*link
);
167 int dhcp6_configure(Link
*link
);
168 int dhcp6_request_address(Link
*link
, int ir
);
169 int dhcp6_lease_pd_prefix_lost(sd_dhcp6_client
*client
, Link
* link
);
171 const char* link_state_to_string(LinkState s
) _const_
;
172 LinkState
link_state_from_string(const char *s
) _pure_
;
174 const char* link_operstate_to_string(LinkOperationalState s
) _const_
;
175 LinkOperationalState
link_operstate_from_string(const char *s
) _pure_
;
177 extern const sd_bus_vtable link_vtable
[];
179 int link_node_enumerator(sd_bus
*bus
, const char *path
, void *userdata
, char ***nodes
, sd_bus_error
*error
);
180 int link_object_find(sd_bus
*bus
, const char *path
, const char *interface
, void *userdata
, void **found
, sd_bus_error
*error
);
181 int link_send_changed(Link
*link
, const char *property
, ...) _sentinel_
;
183 /* Macros which append INTERFACE= to the message */
185 #define log_link_full(link, level, error, ...) \
187 const Link *_l = (link); \
188 _l ? log_object_internal(level, error, __FILE__, __LINE__, __func__, "INTERFACE=", _l->ifname, NULL, NULL, ##__VA_ARGS__) : \
189 log_internal(level, error, __FILE__, __LINE__, __func__, ##__VA_ARGS__); \
192 #define log_link_debug(link, ...) log_link_full(link, LOG_DEBUG, 0, ##__VA_ARGS__)
193 #define log_link_info(link, ...) log_link_full(link, LOG_INFO, 0, ##__VA_ARGS__)
194 #define log_link_notice(link, ...) log_link_full(link, LOG_NOTICE, 0, ##__VA_ARGS__)
195 #define log_link_warning(link, ...) log_link_full(link, LOG_WARNING, 0, ##__VA_ARGS__)
196 #define log_link_error(link, ...) log_link_full(link, LOG_ERR, 0, ##__VA_ARGS__)
198 #define log_link_debug_errno(link, error, ...) log_link_full(link, LOG_DEBUG, error, ##__VA_ARGS__)
199 #define log_link_info_errno(link, error, ...) log_link_full(link, LOG_INFO, error, ##__VA_ARGS__)
200 #define log_link_notice_errno(link, error, ...) log_link_full(link, LOG_NOTICE, error, ##__VA_ARGS__)
201 #define log_link_warning_errno(link, error, ...) log_link_full(link, LOG_WARNING, error, ##__VA_ARGS__)
202 #define log_link_error_errno(link, error, ...) log_link_full(link, LOG_ERR, error, ##__VA_ARGS__)
204 #define LOG_LINK_MESSAGE(link, fmt, ...) "MESSAGE=%s: " fmt, (link)->ifname, ##__VA_ARGS__
205 #define LOG_LINK_INTERFACE(link) "INTERFACE=%s", (link)->ifname
207 #define ADDRESS_FMT_VAL(address) \
208 be32toh((address).s_addr) >> 24, \
209 (be32toh((address).s_addr) >> 16) & 0xFFu, \
210 (be32toh((address).s_addr) >> 8) & 0xFFu, \
211 be32toh((address).s_addr) & 0xFFu