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 {
27 LINK_STATE_INITIALIZING,
29 LINK_STATE_SETTING_ADDRESSES,
30 LINK_STATE_SETTING_ROUTES,
31 LINK_STATE_CONFIGURED,
36 _LINK_STATE_INVALID = -1
39 typedef enum LinkOperationalState {
40 LINK_OPERSTATE_UNKNOWN,
41 LINK_OPERSTATE_DORMANT,
42 LINK_OPERSTATE_CARRIER,
43 LINK_OPERSTATE_DEGRADED,
44 LINK_OPERSTATE_ROUTABLE,
46 _LINK_OPERSTATE_INVALID = -1
47 } LinkOperationalState;
57 struct ether_addr mac;
59 struct udev_device *udev_device;
62 uint8_t kernel_operstate;
67 LinkOperationalState operstate;
69 unsigned addr_messages;
70 unsigned route_messages;
73 LIST_HEAD(Address, addresses);
75 sd_dhcp_client *dhcp_client;
76 sd_dhcp_lease *dhcp_lease;
78 uint16_t original_mtu;
84 LIST_HEAD(Address, pool_addresses);
86 sd_dhcp_server *dhcp_server;
88 sd_icmp6_nd *icmp6_router_discovery;
89 sd_dhcp6_client *dhcp6_client;
92 Link *link_unref(Link *link);
93 Link *link_ref(Link *link);
94 int link_get(Manager *m, int ifindex, Link **ret);
95 int link_add(Manager *manager, sd_rtnl_message *message, Link **ret);
96 void link_drop(Link *link);
98 int link_get_address_handler(sd_rtnl *rtnl, sd_rtnl_message *m, void *userdata);
99 int link_address_drop_handler(sd_rtnl *rtnl, sd_rtnl_message *m, void *userdata);
100 int link_route_drop_handler(sd_rtnl *rtnl, sd_rtnl_message *m, void *userdata);
102 void link_enter_failed(Link *link);
103 int link_initialized(Link *link, struct udev_device *device);
105 void link_client_handler(Link *link);
107 int link_update(Link *link, sd_rtnl_message *message);
108 int link_rtnl_process_address(sd_rtnl *rtnl, sd_rtnl_message *message, void *userdata);
110 int link_save(Link *link);
112 bool link_has_carrier(unsigned flags, uint8_t operstate);
114 int ipv4ll_configure(Link *link);
116 const char* link_state_to_string(LinkState s) _const_;
117 LinkState link_state_from_string(const char *s) _pure_;
119 const char* link_operstate_to_string(LinkOperationalState s) _const_;
120 LinkOperationalState link_operstate_from_string(const char *s) _pure_;
122 DEFINE_TRIVIAL_CLEANUP_FUNC(Link*, link_unref);
123 #define _cleanup_link_unref_ _cleanup_(link_unrefp)
125 /* Macros which append INTERFACE= to the message */
127 #define log_full_link(level, link, fmt, ...) log_meta_object(level, __FILE__, __LINE__, __func__, "INTERFACE=", link->ifname, "%-*s: " fmt, IFNAMSIZ, link->ifname, ##__VA_ARGS__)
128 #define log_debug_link(link, ...) log_full_link(LOG_DEBUG, link, ##__VA_ARGS__)
129 #define log_info_link(link, ...) log_full_link(LOG_INFO, link, ##__VA_ARGS__)
130 #define log_notice_link(link, ...) log_full_link(LOG_NOTICE, link, ##__VA_ARGS__)
131 #define log_warning_link(link, ...) log_full_link(LOG_WARNING, link, ##__VA_ARGS__)
132 #define log_error_link(link, ...) log_full_link(LOG_ERR, link, ##__VA_ARGS__)
134 #define log_struct_link(level, link, ...) log_struct(level, "INTERFACE=%s", link->ifname, __VA_ARGS__)
136 #define ADDRESS_FMT_VAL(address) \
137 (address).s_addr & 0xFF, \
138 ((address).s_addr >> 8) & 0xFF, \
139 ((address).s_addr >> 16) & 0xFF, \
140 (address).s_addr >> 24