1 /*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
6 This file is part of systemd.
8 Copyright 2013 Tom Gundersen <teg@jklm.no>
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.
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.
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/>.
26 #include "sd-dhcp-client.h"
27 #include "sd-dhcp-server.h"
28 #include "sd-ipv4ll.h"
29 #include "sd-icmp6-nd.h"
30 #include "sd-dhcp6-client.h"
33 typedef struct Link Link
;
35 typedef enum LinkState
{
38 LINK_STATE_SETTING_ADDRESSES
,
39 LINK_STATE_SETTING_ROUTES
,
40 LINK_STATE_CONFIGURED
,
45 _LINK_STATE_INVALID
= -1
48 typedef enum LinkOperationalState
{
50 LINK_OPERSTATE_NO_CARRIER
,
51 LINK_OPERSTATE_DORMANT
,
52 LINK_OPERSTATE_CARRIER
,
53 LINK_OPERSTATE_DEGRADED
,
54 LINK_OPERSTATE_ROUTABLE
,
56 _LINK_OPERSTATE_INVALID
= -1
57 } LinkOperationalState
;
60 #include "networkd-network.h"
61 #include "networkd-address.h"
71 struct ether_addr mac
;
73 struct udev_device
*udev_device
;
76 uint8_t kernel_operstate
;
81 LinkOperationalState operstate
;
83 unsigned link_messages
;
86 LIST_HEAD(Address
, addresses
);
88 sd_dhcp_client
*dhcp_client
;
89 sd_dhcp_lease
*dhcp_lease
;
91 uint16_t original_mtu
;
92 unsigned dhcp4_messages
;
93 bool dhcp4_configured
;
94 bool dhcp6_configured
;
100 bool static_configured
;
102 LIST_HEAD(Address
, pool_addresses
);
104 sd_dhcp_server
*dhcp_server
;
106 sd_icmp6_nd
*icmp6_router_discovery
;
107 sd_dhcp6_client
*dhcp6_client
;
108 bool rtnl_extended_attrs
;
113 Hashmap
*bound_by_links
;
114 Hashmap
*bound_to_links
;
117 Link
*link_unref(Link
*link
);
118 Link
*link_ref(Link
*link
);
119 int link_get(Manager
*m
, int ifindex
, Link
**ret
);
120 int link_add(Manager
*manager
, sd_netlink_message
*message
, Link
**ret
);
121 void link_drop(Link
*link
);
123 int link_address_drop_handler(sd_netlink
*rtnl
, sd_netlink_message
*m
, void *userdata
);
124 int link_route_drop_handler(sd_netlink
*rtnl
, sd_netlink_message
*m
, void *userdata
);
126 void link_enter_failed(Link
*link
);
127 int link_initialized(Link
*link
, struct udev_device
*device
);
129 void link_client_handler(Link
*link
);
131 int link_update(Link
*link
, sd_netlink_message
*message
);
132 int link_rtnl_process_address(sd_netlink
*rtnl
, sd_netlink_message
*message
, void *userdata
);
134 int link_save(Link
*link
);
136 int link_carrier_reset(Link
*link
);
137 bool link_has_carrier(Link
*link
);
139 int link_set_mtu(Link
*link
, uint32_t mtu
);
140 int link_set_hostname(Link
*link
, const char *hostname
);
141 int link_set_timezone(Link
*link
, const char *timezone
);
143 int ipv4ll_configure(Link
*link
);
144 int dhcp4_configure(Link
*link
);
145 int icmp6_configure(Link
*link
);
147 bool link_lldp_enabled(Link
*link
);
148 bool link_ipv4ll_enabled(Link
*link
);
149 bool link_ipv6ll_enabled(Link
*link
);
150 bool link_dhcp4_server_enabled(Link
*link
);
151 bool link_dhcp4_enabled(Link
*link
);
152 bool link_dhcp6_enabled(Link
*link
);
154 const char* link_state_to_string(LinkState s
) _const_
;
155 LinkState
link_state_from_string(const char *s
) _pure_
;
157 const char* link_operstate_to_string(LinkOperationalState s
) _const_
;
158 LinkOperationalState
link_operstate_from_string(const char *s
) _pure_
;
160 extern const sd_bus_vtable link_vtable
[];
162 int link_node_enumerator(sd_bus
*bus
, const char *path
, void *userdata
, char ***nodes
, sd_bus_error
*error
);
163 int link_object_find(sd_bus
*bus
, const char *path
, const char *interface
, void *userdata
, void **found
, sd_bus_error
*error
);
164 int link_send_changed(Link
*link
, const char *property
, ...) _sentinel_
;
166 DEFINE_TRIVIAL_CLEANUP_FUNC(Link
*, link_unref
);
167 #define _cleanup_link_unref_ _cleanup_(link_unrefp)
169 /* Macros which append INTERFACE= to the message */
171 #define log_link_full(link, level, error, ...) \
174 _l ? log_object_internal(level, error, __FILE__, __LINE__, __func__, "INTERFACE=", _l->ifname, ##__VA_ARGS__) : \
175 log_internal(level, error, __FILE__, __LINE__, __func__, ##__VA_ARGS__); \
178 #define log_link_debug(link, ...) log_link_full(link, LOG_DEBUG, 0, ##__VA_ARGS__)
179 #define log_link_info(link, ...) log_link_full(link, LOG_INFO, 0, ##__VA_ARGS__)
180 #define log_link_notice(link, ...) log_link_full(link, LOG_NOTICE, 0, ##__VA_ARGS__)
181 #define log_link_warning(link, ...) log_link_full(link, LOG_WARNING, 0, ##__VA_ARGS__)
182 #define log_link_error(link, ...) log_link_full(link, LOG_ERR, 0, ##__VA_ARGS__)
184 #define log_link_debug_errno(link, error, ...) log_link_full(link, LOG_DEBUG, error, ##__VA_ARGS__)
185 #define log_link_info_errno(link, error, ...) log_link_full(link, LOG_INFO, error, ##__VA_ARGS__)
186 #define log_link_notice_errno(link, error, ...) log_link_full(link, LOG_NOTICE, error, ##__VA_ARGS__)
187 #define log_link_warning_errno(link, error, ...) log_link_full(link, LOG_WARNING, error, ##__VA_ARGS__)
188 #define log_link_error_errno(link, error, ...) log_link_full(link, LOG_ERR, error, ##__VA_ARGS__)
190 #define LOG_LINK_MESSAGE(link, fmt, ...) "MESSAGE=%s: " fmt, (link)->ifname, ##__VA_ARGS__
191 #define LOG_LINK_INTERFACE(link) "INTERFACE=%s", (link)->ifname
193 #define ADDRESS_FMT_VAL(address) \
194 be32toh((address).s_addr) >> 24, \
195 (be32toh((address).s_addr) >> 16) & 0xFFu, \
196 (be32toh((address).s_addr) >> 8) & 0xFFu, \
197 be32toh((address).s_addr) & 0xFFu