1 /*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
4 This file is part of systemd.
6 Copyright 2013 Tom Gundersen <teg@jklm.no>
8 systemd is free software; you can redistribute it and/or modify it
9 under the terms of the GNU Lesser General Public License as published by
10 the Free Software Foundation; either version 2.1 of the License, or
11 (at your option) any later version.
13 systemd is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 Lesser General Public License for more details.
18 You should have received a copy of the GNU Lesser General Public License
19 along with systemd; If not, see <http://www.gnu.org/licenses/>.
26 typedef enum LinkState {
29 LINK_STATE_SETTING_ADDRESSES,
30 LINK_STATE_SETTING_ROUTES,
31 LINK_STATE_CONFIGURED,
36 _LINK_STATE_INVALID = -1
39 typedef enum LinkOperationalState {
41 LINK_OPERSTATE_NO_CARRIER,
42 LINK_OPERSTATE_DORMANT,
43 LINK_OPERSTATE_CARRIER,
44 LINK_OPERSTATE_DEGRADED,
45 LINK_OPERSTATE_ROUTABLE,
47 _LINK_OPERSTATE_INVALID = -1
48 } LinkOperationalState;
58 struct ether_addr mac;
60 struct udev_device *udev_device;
63 uint8_t kernel_operstate;
68 LinkOperationalState operstate;
70 unsigned link_messages;
73 LIST_HEAD(Address, addresses);
75 sd_dhcp_client *dhcp_client;
76 sd_dhcp_lease *dhcp_lease;
78 uint16_t original_mtu;
79 unsigned dhcp4_messages;
80 bool dhcp4_configured;
86 bool static_configured;
88 LIST_HEAD(Address, pool_addresses);
90 sd_dhcp_server *dhcp_server;
92 sd_icmp6_nd *icmp6_router_discovery;
93 sd_dhcp6_client *dhcp6_client;
99 Link *link_unref(Link *link);
100 Link *link_ref(Link *link);
101 int link_get(Manager *m, int ifindex, Link **ret);
102 int link_add(Manager *manager, sd_rtnl_message *message, Link **ret);
103 void link_drop(Link *link);
105 int link_address_drop_handler(sd_rtnl *rtnl, sd_rtnl_message *m, void *userdata);
106 int link_route_drop_handler(sd_rtnl *rtnl, sd_rtnl_message *m, void *userdata);
108 void link_enter_failed(Link *link);
109 int link_initialized(Link *link, struct udev_device *device);
111 void link_client_handler(Link *link);
113 int link_update(Link *link, sd_rtnl_message *message);
114 int link_rtnl_process_address(sd_rtnl *rtnl, sd_rtnl_message *message, void *userdata);
116 int link_save(Link *link);
118 bool link_has_carrier(Link *link);
120 int link_set_mtu(Link *link, uint32_t mtu);
121 int link_set_hostname(Link *link, const char *hostname);
123 int ipv4ll_configure(Link *link);
124 int dhcp4_configure(Link *link);
125 int icmp6_configure(Link *link);
127 const char* link_state_to_string(LinkState s) _const_;
128 LinkState link_state_from_string(const char *s) _pure_;
130 const char* link_operstate_to_string(LinkOperationalState s) _const_;
131 LinkOperationalState link_operstate_from_string(const char *s) _pure_;
133 DEFINE_TRIVIAL_CLEANUP_FUNC(Link*, link_unref);
134 #define _cleanup_link_unref_ _cleanup_(link_unrefp)
136 /* Macros which append INTERFACE= to the message */
138 #define log_link_full(link, level, error, fmt, ...) \
139 log_object_internal(level, error, __FILE__, __LINE__, __func__, "INTERFACE=", link->ifname, "%-*s: " fmt, IFNAMSIZ, link->ifname, ##__VA_ARGS__)
141 #define log_link_debug(link, ...) log_link_full(link, LOG_DEBUG, 0, ##__VA_ARGS__)
142 #define log_link_info(link, ...) log_link_full(link, LOG_INFO, 0, ##__VA_ARGS__)
143 #define log_link_notice(link, ...) log_link_full(link, LOG_NOTICE, 0, ##__VA_ARGS__)
144 #define log_link_warning(link, ...) log_link_full(link, LOG_WARNING, 0, ##__VA_ARGS__)
145 #define log_link_error(link, ...) log_link_full(link, LOG_ERR, 0, ##__VA_ARGS__)
147 #define log_link_debug_errno(link, error, ...) log_link_full(link, LOG_DEBUG, error, ##__VA_ARGS__)
148 #define log_link_info_errno(link, error, ...) log_link_full(link, LOG_INFO, error, ##__VA_ARGS__)
149 #define log_link_notice_errno(link, error, ...) log_link_full(link, LOG_NOTICE, error, ##__VA_ARGS__)
150 #define log_link_warning_errno(link, error, ...) log_link_full(link, LOG_WARNING, error, ##__VA_ARGS__)
151 #define log_link_error_errno(link, error, ...) log_link_full(link, LOG_ERR, error, ##__VA_ARGS__)
153 #define log_link_struct(link, level, ...) log_struct(level, "INTERFACE=%s", link->ifname, __VA_ARGS__)
155 #define ADDRESS_FMT_VAL(address) \
156 (address).s_addr & 0xFF, \
157 ((address).s_addr >> 8) & 0xFF, \
158 ((address).s_addr >> 16) & 0xFF, \
159 (address).s_addr >> 24