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