]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/network/networkd-link.h
network: beef up ipv6 RA support considerably
[thirdparty/systemd.git] / src / network / networkd-link.h
CommitLineData
fc2f9534
LP
1#pragma once
2
0b1831c2
TG
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
80431934
PM
22#include <endian.h>
23
634f0f98 24#include "sd-bus.h"
fc2f9534
LP
25#include "sd-dhcp-client.h"
26#include "sd-dhcp-server.h"
fc2f9534 27#include "sd-dhcp6-client.h"
07630cea 28#include "sd-ipv4ll.h"
fc2f9534 29#include "sd-lldp.h"
07630cea 30#include "sd-ndisc.h"
634f0f98 31#include "sd-netlink.h"
fc2f9534 32
634f0f98
ZJS
33#include "list.h"
34#include "set.h"
0b1831c2
TG
35
36typedef enum LinkState {
8434fd5c 37 LINK_STATE_PENDING,
0b1831c2
TG
38 LINK_STATE_ENSLAVING,
39 LINK_STATE_SETTING_ADDRESSES,
40 LINK_STATE_SETTING_ROUTES,
41 LINK_STATE_CONFIGURED,
42 LINK_STATE_UNMANAGED,
43 LINK_STATE_FAILED,
44 LINK_STATE_LINGER,
45 _LINK_STATE_MAX,
46 _LINK_STATE_INVALID = -1
47} LinkState;
48
fc2f9534
LP
49typedef enum LinkOperationalState {
50 LINK_OPERSTATE_OFF,
51 LINK_OPERSTATE_NO_CARRIER,
52 LINK_OPERSTATE_DORMANT,
53 LINK_OPERSTATE_CARRIER,
54 LINK_OPERSTATE_DEGRADED,
55 LINK_OPERSTATE_ROUTABLE,
56 _LINK_OPERSTATE_MAX,
57 _LINK_OPERSTATE_INVALID = -1
58} LinkOperationalState;
59
634f0f98
ZJS
60typedef struct Manager Manager;
61typedef struct Network Network;
62typedef struct Address Address;
fc2f9534 63
634f0f98 64typedef struct Link {
0b1831c2
TG
65 Manager *manager;
66
67 int n_ref;
68
69 int ifindex;
70 char *ifname;
b710e6b6 71 unsigned short iftype;
0b1831c2
TG
72 char *state_file;
73 struct ether_addr mac;
c601ebf7 74 struct in6_addr ipv6ll_address;
0b1831c2
TG
75 uint32_t mtu;
76 struct udev_device *udev_device;
77
78 unsigned flags;
79 uint8_t kernel_operstate;
80
81 Network *network;
82
83 LinkState state;
84 LinkOperationalState operstate;
85
3c9b8860 86 unsigned link_messages;
0b1831c2
TG
87 unsigned enslaving;
88
cf1d700d 89 Set *addresses;
adda1ed9 90 Set *addresses_foreign;
1c8e710c
TG
91 Set *routes;
92 Set *routes_foreign;
0b1831c2
TG
93
94 sd_dhcp_client *dhcp_client;
95 sd_dhcp_lease *dhcp_lease;
96 char *lease_file;
97 uint16_t original_mtu;
3c9b8860
TG
98 unsigned dhcp4_messages;
99 bool dhcp4_configured;
18d29550 100 bool dhcp6_configured;
1e7a0e21 101
3b015d40
TG
102 unsigned ndisc_messages;
103 bool ndisc_configured;
b22d8a00 104
0b1831c2 105 sd_ipv4ll *ipv4ll;
e7ab854c
TG
106 bool ipv4ll_address:1;
107 bool ipv4ll_route:1;
0b1831c2 108
3c9b8860
TG
109 bool static_configured;
110
0b1831c2
TG
111 LIST_HEAD(Address, pool_addresses);
112
113 sd_dhcp_server *dhcp_server;
114
1e7a0e21
LP
115 sd_ndisc *ndisc;
116 Set *ndisc_rdnss;
117 Set *ndisc_dnssl;
118
0b1831c2 119 sd_dhcp6_client *dhcp6_client;
be3a09b7 120 bool rtnl_extended_attrs;
ce43e484 121
8e1ad1ea 122 /* This is about LLDP reception */
ce43e484 123 sd_lldp *lldp;
49699bac 124 char *lldp_file;
0d4ad91d 125
8e1ad1ea
LP
126 /* This is about LLDP transmission */
127 unsigned lldp_tx_fast; /* The LLDP txFast counter (See 802.1ab-2009, section 9.2.5.18) */
7272b25e 128 sd_event_source *lldp_emit_event_source;
8e1ad1ea 129
0d4ad91d
AR
130 Hashmap *bound_by_links;
131 Hashmap *bound_to_links;
634f0f98 132} Link;
0b1831c2
TG
133
134Link *link_unref(Link *link);
135Link *link_ref(Link *link);
136int link_get(Manager *m, int ifindex, Link **ret);
1c4baffc 137int link_add(Manager *manager, sd_netlink_message *message, Link **ret);
0b1831c2
TG
138void link_drop(Link *link);
139
91b5f997
TG
140int link_address_remove_handler(sd_netlink *rtnl, sd_netlink_message *m, void *userdata);
141int link_route_remove_handler(sd_netlink *rtnl, sd_netlink_message *m, void *userdata);
0b1831c2 142
b22d8a00 143void link_enter_failed(Link *link);
0b1831c2
TG
144int link_initialized(Link *link, struct udev_device *device);
145
8012cd39 146void link_check_ready(Link *link);
b22d8a00 147
84de38c5 148void link_update_operstate(Link *link);
1c4baffc 149int link_update(Link *link, sd_netlink_message *message);
b22d8a00 150
84de38c5
TG
151void link_dirty(Link *link);
152void link_clean(Link *link);
0b1831c2
TG
153int link_save(Link *link);
154
9c0a72f9 155int link_carrier_reset(Link *link);
a61bb41c 156bool link_has_carrier(Link *link);
0b1831c2 157
c601ebf7 158int link_ipv6ll_gained(Link *link, const struct in6_addr *address);
e7ab854c 159
3c9b8860
TG
160int link_set_mtu(Link *link, uint32_t mtu);
161int link_set_hostname(Link *link, const char *hostname);
21b80ad1 162int link_set_timezone(Link *link, const char *timezone);
3c9b8860 163
b22d8a00 164int ipv4ll_configure(Link *link);
3c9b8860 165int dhcp4_configure(Link *link);
7a695d8e 166int dhcp6_configure(Link *link);
720bec40 167int dhcp6_request_address(Link *link, int ir);
b22d8a00 168
0b1831c2
TG
169const char* link_state_to_string(LinkState s) _const_;
170LinkState link_state_from_string(const char *s) _pure_;
171
fc2f9534
LP
172const char* link_operstate_to_string(LinkOperationalState s) _const_;
173LinkOperationalState link_operstate_from_string(const char *s) _pure_;
174
e331e246
TG
175extern const sd_bus_vtable link_vtable[];
176
177int link_node_enumerator(sd_bus *bus, const char *path, void *userdata, char ***nodes, sd_bus_error *error);
178int link_object_find(sd_bus *bus, const char *path, const char *interface, void *userdata, void **found, sd_bus_error *error);
179int link_send_changed(Link *link, const char *property, ...) _sentinel_;
0b1831c2
TG
180
181DEFINE_TRIVIAL_CLEANUP_FUNC(Link*, link_unref);
182#define _cleanup_link_unref_ _cleanup_(link_unrefp)
183
184/* Macros which append INTERFACE= to the message */
185
f2341e0a
LP
186#define log_link_full(link, level, error, ...) \
187 ({ \
188 Link *_l = (link); \
189 _l ? log_object_internal(level, error, __FILE__, __LINE__, __func__, "INTERFACE=", _l->ifname, ##__VA_ARGS__) : \
190 log_internal(level, error, __FILE__, __LINE__, __func__, ##__VA_ARGS__); \
191 }) \
192
193#define log_link_debug(link, ...) log_link_full(link, LOG_DEBUG, 0, ##__VA_ARGS__)
194#define log_link_info(link, ...) log_link_full(link, LOG_INFO, 0, ##__VA_ARGS__)
195#define log_link_notice(link, ...) log_link_full(link, LOG_NOTICE, 0, ##__VA_ARGS__)
196#define log_link_warning(link, ...) log_link_full(link, LOG_WARNING, 0, ##__VA_ARGS__)
197#define log_link_error(link, ...) log_link_full(link, LOG_ERR, 0, ##__VA_ARGS__)
6c861f0a
LP
198
199#define log_link_debug_errno(link, error, ...) log_link_full(link, LOG_DEBUG, error, ##__VA_ARGS__)
200#define log_link_info_errno(link, error, ...) log_link_full(link, LOG_INFO, error, ##__VA_ARGS__)
201#define log_link_notice_errno(link, error, ...) log_link_full(link, LOG_NOTICE, error, ##__VA_ARGS__)
202#define log_link_warning_errno(link, error, ...) log_link_full(link, LOG_WARNING, error, ##__VA_ARGS__)
203#define log_link_error_errno(link, error, ...) log_link_full(link, LOG_ERR, error, ##__VA_ARGS__)
204
f2341e0a
LP
205#define LOG_LINK_MESSAGE(link, fmt, ...) "MESSAGE=%s: " fmt, (link)->ifname, ##__VA_ARGS__
206#define LOG_LINK_INTERFACE(link) "INTERFACE=%s", (link)->ifname
0b1831c2 207
80431934
PM
208#define ADDRESS_FMT_VAL(address) \
209 be32toh((address).s_addr) >> 24, \
210 (be32toh((address).s_addr) >> 16) & 0xFFu, \
211 (be32toh((address).s_addr) >> 8) & 0xFFu, \
212 be32toh((address).s_addr) & 0xFFu