]>
Commit | Line | Data |
---|---|---|
0b1831c2 TG |
1 | /*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/ |
2 | ||
3 | /*** | |
4 | This file is part of systemd. | |
5 | ||
6 | Copyright 2013 Tom Gundersen <teg@jklm.no> | |
7 | ||
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. | |
12 | ||
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. | |
17 | ||
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/>. | |
20 | ***/ | |
21 | ||
22 | #pragma once | |
23 | ||
80431934 PM |
24 | #include <endian.h> |
25 | ||
0b1831c2 TG |
26 | #include "networkd.h" |
27 | ||
28 | typedef enum LinkState { | |
8434fd5c | 29 | LINK_STATE_PENDING, |
0b1831c2 TG |
30 | LINK_STATE_ENSLAVING, |
31 | LINK_STATE_SETTING_ADDRESSES, | |
32 | LINK_STATE_SETTING_ROUTES, | |
33 | LINK_STATE_CONFIGURED, | |
34 | LINK_STATE_UNMANAGED, | |
35 | LINK_STATE_FAILED, | |
36 | LINK_STATE_LINGER, | |
37 | _LINK_STATE_MAX, | |
38 | _LINK_STATE_INVALID = -1 | |
39 | } LinkState; | |
40 | ||
0b1831c2 TG |
41 | struct Link { |
42 | Manager *manager; | |
43 | ||
44 | int n_ref; | |
45 | ||
46 | int ifindex; | |
47 | char *ifname; | |
48 | char *state_file; | |
49 | struct ether_addr mac; | |
50 | uint32_t mtu; | |
51 | struct udev_device *udev_device; | |
52 | ||
53 | unsigned flags; | |
54 | uint8_t kernel_operstate; | |
55 | ||
56 | Network *network; | |
57 | ||
58 | LinkState state; | |
59 | LinkOperationalState operstate; | |
60 | ||
3c9b8860 | 61 | unsigned link_messages; |
0b1831c2 TG |
62 | unsigned enslaving; |
63 | ||
64 | LIST_HEAD(Address, addresses); | |
65 | ||
66 | sd_dhcp_client *dhcp_client; | |
67 | sd_dhcp_lease *dhcp_lease; | |
68 | char *lease_file; | |
69 | uint16_t original_mtu; | |
3c9b8860 TG |
70 | unsigned dhcp4_messages; |
71 | bool dhcp4_configured; | |
b22d8a00 | 72 | |
0b1831c2 | 73 | sd_ipv4ll *ipv4ll; |
b22d8a00 TG |
74 | bool ipv4ll_address; |
75 | bool ipv4ll_route; | |
0b1831c2 | 76 | |
3c9b8860 TG |
77 | bool static_configured; |
78 | ||
0b1831c2 TG |
79 | LIST_HEAD(Address, pool_addresses); |
80 | ||
81 | sd_dhcp_server *dhcp_server; | |
82 | ||
83 | sd_icmp6_nd *icmp6_router_discovery; | |
84 | sd_dhcp6_client *dhcp6_client; | |
be3a09b7 | 85 | bool rtnl_extended_attrs; |
ce43e484 SS |
86 | |
87 | sd_lldp *lldp; | |
49699bac | 88 | char *lldp_file; |
0d4ad91d AR |
89 | |
90 | Hashmap *bound_by_links; | |
91 | Hashmap *bound_to_links; | |
0b1831c2 TG |
92 | }; |
93 | ||
94 | Link *link_unref(Link *link); | |
95 | Link *link_ref(Link *link); | |
96 | int link_get(Manager *m, int ifindex, Link **ret); | |
1c4baffc | 97 | int link_add(Manager *manager, sd_netlink_message *message, Link **ret); |
0b1831c2 TG |
98 | void link_drop(Link *link); |
99 | ||
1c4baffc TG |
100 | int link_address_drop_handler(sd_netlink *rtnl, sd_netlink_message *m, void *userdata); |
101 | int link_route_drop_handler(sd_netlink *rtnl, sd_netlink_message *m, void *userdata); | |
0b1831c2 | 102 | |
b22d8a00 | 103 | void link_enter_failed(Link *link); |
0b1831c2 TG |
104 | int link_initialized(Link *link, struct udev_device *device); |
105 | ||
b22d8a00 TG |
106 | void link_client_handler(Link *link); |
107 | ||
1c4baffc TG |
108 | int link_update(Link *link, sd_netlink_message *message); |
109 | int link_rtnl_process_address(sd_netlink *rtnl, sd_netlink_message *message, void *userdata); | |
b22d8a00 | 110 | |
0b1831c2 TG |
111 | int link_save(Link *link); |
112 | ||
9c0a72f9 | 113 | int link_carrier_reset(Link *link); |
a61bb41c | 114 | bool link_has_carrier(Link *link); |
0b1831c2 | 115 | |
3c9b8860 TG |
116 | int link_set_mtu(Link *link, uint32_t mtu); |
117 | int link_set_hostname(Link *link, const char *hostname); | |
21b80ad1 | 118 | int link_set_timezone(Link *link, const char *timezone); |
3c9b8860 | 119 | |
b22d8a00 | 120 | int ipv4ll_configure(Link *link); |
3c9b8860 | 121 | int dhcp4_configure(Link *link); |
5c79bd79 | 122 | int icmp6_configure(Link *link); |
b22d8a00 | 123 | |
a97dcc12 TG |
124 | bool link_lldp_enabled(Link *link); |
125 | bool link_ipv4ll_enabled(Link *link); | |
d0d6a4cd | 126 | bool link_ipv6ll_enabled(Link *link); |
a97dcc12 TG |
127 | bool link_dhcp4_server_enabled(Link *link); |
128 | bool link_dhcp4_enabled(Link *link); | |
129 | bool link_dhcp6_enabled(Link *link); | |
130 | ||
0b1831c2 TG |
131 | const char* link_state_to_string(LinkState s) _const_; |
132 | LinkState link_state_from_string(const char *s) _pure_; | |
133 | ||
e331e246 TG |
134 | extern const sd_bus_vtable link_vtable[]; |
135 | ||
136 | int link_node_enumerator(sd_bus *bus, const char *path, void *userdata, char ***nodes, sd_bus_error *error); | |
137 | int link_object_find(sd_bus *bus, const char *path, const char *interface, void *userdata, void **found, sd_bus_error *error); | |
138 | int link_send_changed(Link *link, const char *property, ...) _sentinel_; | |
0b1831c2 TG |
139 | |
140 | DEFINE_TRIVIAL_CLEANUP_FUNC(Link*, link_unref); | |
141 | #define _cleanup_link_unref_ _cleanup_(link_unrefp) | |
142 | ||
143 | /* Macros which append INTERFACE= to the message */ | |
144 | ||
f2341e0a LP |
145 | #define log_link_full(link, level, error, ...) \ |
146 | ({ \ | |
147 | Link *_l = (link); \ | |
148 | _l ? log_object_internal(level, error, __FILE__, __LINE__, __func__, "INTERFACE=", _l->ifname, ##__VA_ARGS__) : \ | |
149 | log_internal(level, error, __FILE__, __LINE__, __func__, ##__VA_ARGS__); \ | |
150 | }) \ | |
151 | ||
152 | #define log_link_debug(link, ...) log_link_full(link, LOG_DEBUG, 0, ##__VA_ARGS__) | |
153 | #define log_link_info(link, ...) log_link_full(link, LOG_INFO, 0, ##__VA_ARGS__) | |
154 | #define log_link_notice(link, ...) log_link_full(link, LOG_NOTICE, 0, ##__VA_ARGS__) | |
155 | #define log_link_warning(link, ...) log_link_full(link, LOG_WARNING, 0, ##__VA_ARGS__) | |
156 | #define log_link_error(link, ...) log_link_full(link, LOG_ERR, 0, ##__VA_ARGS__) | |
6c861f0a LP |
157 | |
158 | #define log_link_debug_errno(link, error, ...) log_link_full(link, LOG_DEBUG, error, ##__VA_ARGS__) | |
159 | #define log_link_info_errno(link, error, ...) log_link_full(link, LOG_INFO, error, ##__VA_ARGS__) | |
160 | #define log_link_notice_errno(link, error, ...) log_link_full(link, LOG_NOTICE, error, ##__VA_ARGS__) | |
161 | #define log_link_warning_errno(link, error, ...) log_link_full(link, LOG_WARNING, error, ##__VA_ARGS__) | |
162 | #define log_link_error_errno(link, error, ...) log_link_full(link, LOG_ERR, error, ##__VA_ARGS__) | |
163 | ||
f2341e0a LP |
164 | #define LOG_LINK_MESSAGE(link, fmt, ...) "MESSAGE=%s: " fmt, (link)->ifname, ##__VA_ARGS__ |
165 | #define LOG_LINK_INTERFACE(link) "INTERFACE=%s", (link)->ifname | |
0b1831c2 | 166 | |
80431934 PM |
167 | #define ADDRESS_FMT_VAL(address) \ |
168 | be32toh((address).s_addr) >> 24, \ | |
169 | (be32toh((address).s_addr) >> 16) & 0xFFu, \ | |
170 | (be32toh((address).s_addr) >> 8) & 0xFFu, \ | |
171 | be32toh((address).s_addr) & 0xFFu |