]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/network/networkd-link.h
networkd: don't warn about missing links unnecessarily
[thirdparty/systemd.git] / src / network / networkd-link.h
CommitLineData
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
24#include "networkd.h"
25
26typedef enum LinkState {
8434fd5c 27 LINK_STATE_PENDING,
0b1831c2
TG
28 LINK_STATE_ENSLAVING,
29 LINK_STATE_SETTING_ADDRESSES,
30 LINK_STATE_SETTING_ROUTES,
31 LINK_STATE_CONFIGURED,
32 LINK_STATE_UNMANAGED,
33 LINK_STATE_FAILED,
34 LINK_STATE_LINGER,
35 _LINK_STATE_MAX,
36 _LINK_STATE_INVALID = -1
37} LinkState;
38
39typedef enum LinkOperationalState {
d3df0e39
TG
40 LINK_OPERSTATE_OFF,
41 LINK_OPERSTATE_NO_CARRIER,
0b1831c2
TG
42 LINK_OPERSTATE_DORMANT,
43 LINK_OPERSTATE_CARRIER,
44 LINK_OPERSTATE_DEGRADED,
45 LINK_OPERSTATE_ROUTABLE,
46 _LINK_OPERSTATE_MAX,
47 _LINK_OPERSTATE_INVALID = -1
48} LinkOperationalState;
49
50struct Link {
51 Manager *manager;
52
53 int n_ref;
54
55 int ifindex;
56 char *ifname;
57 char *state_file;
58 struct ether_addr mac;
59 uint32_t mtu;
60 struct udev_device *udev_device;
61
62 unsigned flags;
63 uint8_t kernel_operstate;
64
65 Network *network;
66
67 LinkState state;
68 LinkOperationalState operstate;
69
3c9b8860 70 unsigned link_messages;
0b1831c2
TG
71 unsigned enslaving;
72
73 LIST_HEAD(Address, addresses);
74
75 sd_dhcp_client *dhcp_client;
76 sd_dhcp_lease *dhcp_lease;
77 char *lease_file;
78 uint16_t original_mtu;
3c9b8860
TG
79 unsigned dhcp4_messages;
80 bool dhcp4_configured;
b22d8a00 81
0b1831c2 82 sd_ipv4ll *ipv4ll;
b22d8a00
TG
83 bool ipv4ll_address;
84 bool ipv4ll_route;
0b1831c2 85
3c9b8860
TG
86 bool static_configured;
87
0b1831c2
TG
88 LIST_HEAD(Address, pool_addresses);
89
90 sd_dhcp_server *dhcp_server;
91
92 sd_icmp6_nd *icmp6_router_discovery;
93 sd_dhcp6_client *dhcp6_client;
ce43e484
SS
94
95 sd_lldp *lldp;
49699bac 96 char *lldp_file;
0b1831c2
TG
97};
98
99Link *link_unref(Link *link);
100Link *link_ref(Link *link);
101int link_get(Manager *m, int ifindex, Link **ret);
102int link_add(Manager *manager, sd_rtnl_message *message, Link **ret);
103void link_drop(Link *link);
104
b22d8a00
TG
105int link_address_drop_handler(sd_rtnl *rtnl, sd_rtnl_message *m, void *userdata);
106int link_route_drop_handler(sd_rtnl *rtnl, sd_rtnl_message *m, void *userdata);
0b1831c2 107
b22d8a00 108void link_enter_failed(Link *link);
0b1831c2
TG
109int link_initialized(Link *link, struct udev_device *device);
110
b22d8a00
TG
111void link_client_handler(Link *link);
112
113int link_update(Link *link, sd_rtnl_message *message);
114int link_rtnl_process_address(sd_rtnl *rtnl, sd_rtnl_message *message, void *userdata);
115
0b1831c2
TG
116int link_save(Link *link);
117
9c0a72f9 118int link_carrier_reset(Link *link);
a61bb41c 119bool link_has_carrier(Link *link);
0b1831c2 120
3c9b8860
TG
121int link_set_mtu(Link *link, uint32_t mtu);
122int link_set_hostname(Link *link, const char *hostname);
123
b22d8a00 124int ipv4ll_configure(Link *link);
3c9b8860 125int dhcp4_configure(Link *link);
5c79bd79 126int icmp6_configure(Link *link);
b22d8a00 127
0b1831c2
TG
128const char* link_state_to_string(LinkState s) _const_;
129LinkState link_state_from_string(const char *s) _pure_;
130
131const char* link_operstate_to_string(LinkOperationalState s) _const_;
132LinkOperationalState link_operstate_from_string(const char *s) _pure_;
133
134DEFINE_TRIVIAL_CLEANUP_FUNC(Link*, link_unref);
135#define _cleanup_link_unref_ _cleanup_(link_unrefp)
136
137/* Macros which append INTERFACE= to the message */
138
6c861f0a
LP
139#define log_link_full(link, level, error, fmt, ...) \
140 log_object_internal(level, error, __FILE__, __LINE__, __func__, "INTERFACE=", link->ifname, "%-*s: " fmt, IFNAMSIZ, link->ifname, ##__VA_ARGS__)
141
142#define log_link_debug(link, ...) log_link_full(link, LOG_DEBUG, 0, ##__VA_ARGS__)
143#define log_link_info(link, ...) log_link_full(link, LOG_INFO, 0, ##__VA_ARGS__)
144#define log_link_notice(link, ...) log_link_full(link, LOG_NOTICE, 0, ##__VA_ARGS__)
145#define log_link_warning(link, ...) log_link_full(link, LOG_WARNING, 0, ##__VA_ARGS__)
146#define log_link_error(link, ...) log_link_full(link, LOG_ERR, 0, ##__VA_ARGS__)
147
148#define log_link_debug_errno(link, error, ...) log_link_full(link, LOG_DEBUG, error, ##__VA_ARGS__)
149#define log_link_info_errno(link, error, ...) log_link_full(link, LOG_INFO, error, ##__VA_ARGS__)
150#define log_link_notice_errno(link, error, ...) log_link_full(link, LOG_NOTICE, error, ##__VA_ARGS__)
151#define log_link_warning_errno(link, error, ...) log_link_full(link, LOG_WARNING, error, ##__VA_ARGS__)
152#define log_link_error_errno(link, error, ...) log_link_full(link, LOG_ERR, error, ##__VA_ARGS__)
153
154#define log_link_struct(link, level, ...) log_struct(level, "INTERFACE=%s", link->ifname, __VA_ARGS__)
0b1831c2
TG
155
156#define ADDRESS_FMT_VAL(address) \
157 (address).s_addr & 0xFF, \
158 ((address).s_addr >> 8) & 0xFF, \
159 ((address).s_addr >> 16) & 0xFF, \
160 (address).s_addr >> 24