]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/systemd/sd-network.h
network: add an online state for links and manager
[thirdparty/systemd.git] / src / systemd / sd-network.h
CommitLineData
db9ecf05 1/* SPDX-License-Identifier: LGPL-2.1-or-later */
82bdf8ce
TG
2#ifndef foosdnetworkhfoo
3#define foosdnetworkhfoo
fe8db0c5
TG
4
5/***
fe8db0c5
TG
6 systemd is free software; you can redistribute it and/or modify it
7 under the terms of the GNU Lesser General Public License as published by
8 the Free Software Foundation; either version 2.1 of the License, or
9 (at your option) any later version.
10
11 systemd is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
15
16 You should have received a copy of the GNU Lesser General Public License
17 along with systemd; If not, see <http://www.gnu.org/licenses/>.
18***/
19
fe8db0c5 20#include <inttypes.h>
71d35b6b 21#include <sys/types.h>
fe8db0c5 22
fe8db0c5
TG
23#include "_sd-common.h"
24
25/*
26 * A few points:
27 *
28 * Instead of returning an empty string array or empty integer array, we
29 * may return NULL.
30 *
31 * Free the data the library returns with libc free(). String arrays
10b17992 32 * are NULL terminated, and you need to free the array itself in
fe8db0c5
TG
33 * addition to the strings contained.
34 *
10b17992
JSJ
35 * We return error codes as negative errno, kernel-style. On success, we
36 * return 0 or positive.
fe8db0c5 37 *
10b17992
JSJ
38 * These functions access data in /run. This is a virtual file system;
39 * therefore, accesses are relatively cheap.
fe8db0c5
TG
40 *
41 * See sd-network(3) for more information.
42 */
43
44_SD_BEGIN_DECLARATIONS;
45
6436165d 46/* Get overall operational state
54cba0b1 47 * Possible states: down, up, dormant, carrier, degraded, routable
6436165d
LP
48 * Possible return codes:
49 * -ENODATA: networkd is not aware of any links
50 */
51int sd_network_get_operational_state(char **state);
ac999bf0
YW
52int sd_network_get_carrier_state(char **state);
53int sd_network_get_address_state(char **state);
bbea8813
L
54int sd_network_get_ipv4_address_state(char **state);
55int sd_network_get_ipv6_address_state(char **state);
bcdcc596 56int sd_network_get_online_state(char **state);
6436165d 57
03cc0fd1
LP
58/* Get DNS entries for all links. These are string representations of
59 * IP addresses */
8612e936 60int sd_network_get_dns(char ***dns);
03cc0fd1
LP
61
62/* Get NTP entries for all links. These are domain names or string
91c40d86 63 * representations of IP addresses */
8612e936
LP
64int sd_network_get_ntp(char ***ntp);
65
3df9bec5
LP
66/* Get the search domains for all links. */
67int sd_network_get_search_domains(char ***domains);
68
69/* Get the search domains for all links. */
70int sd_network_get_route_domains(char ***domains);
03cc0fd1 71
438ca2bb 72/* Get setup state from ifindex.
8434fd5c
TG
73 * Possible states:
74 * pending: udev is still processing the link, we don't yet know if we will manage it
75 * failed: networkd failed to manage the link
76 * configuring: in the process of retrieving configuration or configuring the link
77 * configured: link configured successfully
78 * unmanaged: networkd is not handling the link
79 * linger: the link is gone, but has not yet been dropped by networkd
deb2e523
TG
80 * Possible return codes:
81 * -ENODATA: networkd is not aware of the link
deb2e523 82 */
438ca2bb 83int sd_network_link_get_setup_state(int ifindex, char **state);
deb2e523 84
91c40d86 85/* Get operational state from ifindex.
d3df0e39
TG
86 * Possible states:
87 * off: the device is powered down
88 * no-carrier: the device is powered up, but it does not yet have a carrier
89 * dormant: the device has a carrier, but is not yet ready for normal traffic
90 * carrier: the link has a carrier
91 * degraded: the link has carrier and addresses valid on the local link configured
92 * routable: the link has carrier and routable address configured
deb2e523
TG
93 * Possible return codes:
94 * -ENODATA: networkd is not aware of the link
95 */
d6731e4c 96int sd_network_link_get_operational_state(int ifindex, char **state);
22eab27c 97int sd_network_link_get_required_operstate_for_online(int ifindex, char **state);
bbea8813 98int sd_network_link_get_required_family_for_online(int ifindex, char **state);
ac999bf0
YW
99int sd_network_link_get_carrier_state(int ifindex, char **state);
100int sd_network_link_get_address_state(int ifindex, char **state);
bbea8813
L
101int sd_network_link_get_ipv4_address_state(int ifindex, char **state);
102int sd_network_link_get_ipv6_address_state(int ifindex, char **state);
bcdcc596 103int sd_network_link_get_online_state(int ifindex, char **state);
deb2e523 104
c1a38904
MTL
105/* Indicates whether the network is relevant to being online.
106 * Possible return codes:
107 * 0: the connection is not required
108 * 1: the connection is required to consider the system online
109 * <0: networkd is not aware of the link
110 */
111int sd_network_link_get_required_for_online(int ifindex);
112
a853652a
DS
113/* Get activation policy for ifindex.
114 * Possible values are as specified for ActivationPolicy=
115 */
116int sd_network_link_get_activation_policy(int ifindex, char **policy);
117
adc5b2e2
TG
118/* Get path to .network file applied to link */
119int sd_network_link_get_network_file(int ifindex, char **filename);
120
6f4dedb2
TG
121/* Get DNS entries for a given link. These are string representations of
122 * IP addresses */
b295beea 123int sd_network_link_get_dns(int ifindex, char ***ret);
7dbf94a9 124
6f4dedb2 125/* Get NTP entries for a given link. These are domain names or string
91c40d86 126 * representations of IP addresses */
b295beea 127int sd_network_link_get_ntp(int ifindex, char ***ret);
eb46288c
SS
128
129/* Get SIP entries for a given link. These are string
130 * representations of IP addresses */
131int sd_network_link_get_sip(int ifindex, char ***ret);
7dbf94a9 132
03cc0fd1
LP
133/* Indicates whether or not LLMNR should be enabled for the link
134 * Possible levels of support: yes, no, resolve
135 * Possible return codes:
91c40d86
TH
136 * -ENODATA: networkd is not aware of the link
137 */
d6731e4c 138int sd_network_link_get_llmnr(int ifindex, char **llmnr);
03cc0fd1 139
ad6c0475
LP
140/* Indicates whether or not MulticastDNS should be enabled for the
141 * link.
aaa297d4
LP
142 * Possible levels of support: yes, no, resolve
143 * Possible return codes:
144 * -ENODATA: networkd is not aware of the link
145 */
146int sd_network_link_get_mdns(int ifindex, char **mdns);
147
c9299be2 148/* Indicates whether or not DNS-over-TLS should be enabled for the
d050561a 149 * link.
4310bfc2 150 * Possible levels of support: yes, no, opportunistic
d050561a
IT
151 * Possible return codes:
152 * -ENODATA: networkd is not aware of the link
153 */
c9299be2 154int sd_network_link_get_dns_over_tls(int ifindex, char **dns_over_tls);
d050561a 155
ad6c0475
LP
156/* Indicates whether or not DNSSEC should be enabled for the link
157 * Possible levels of support: yes, no, allow-downgrade
158 * Possible return codes:
159 * -ENODATA: networkd is not aware of the link
160 */
161int sd_network_link_get_dnssec(int ifindex, char **dnssec);
162
8a516214
LP
163/* Returns the list of per-interface DNSSEC negative trust anchors
164 * Possible return codes:
165 * -ENODATA: networkd is not aware of the link, or has no such data
166 */
167int sd_network_link_get_dnssec_negative_trust_anchors(int ifindex, char ***nta);
168
3df9bec5
LP
169/* Get the search DNS domain names for a given link. */
170int sd_network_link_get_search_domains(int ifindex, char ***domains);
171
172/* Get the route DNS domain names for a given link. */
173int sd_network_link_get_route_domains(int ifindex, char ***domains);
9b4d1882 174
c629354e
LP
175/* Get whether this link shall be used as 'default route' for DNS queries */
176int sd_network_link_get_dns_default_route(int ifindex);
177
b295beea
LP
178/* Get the carrier interface indexes to which current link is bound to. */
179int sd_network_link_get_carrier_bound_to(int ifindex, int **ifindexes);
0d4ad91d
AR
180
181/* Get the CARRIERS that are bound to current link. */
b295beea 182int sd_network_link_get_carrier_bound_by(int ifindex, int **ifindexes);
0d4ad91d 183
01dd1380
SS
184/* Get DHCPv6 client IAID for a given link. */
185int sd_network_link_get_dhcp6_client_iaid_string(int ifindex, char **iaid);
186
a9deab2e
SS
187/* Get DHCPv6 client DUID for a given link. */
188int sd_network_link_get_dhcp6_client_duid_string(int ifindex, char **duid);
189
fe8db0c5
TG
190/* Monitor object */
191typedef struct sd_network_monitor sd_network_monitor;
192
7e141e49 193/* Create a new monitor. Category must be NULL, "links" or "leases". */
0014a4ad 194int sd_network_monitor_new(sd_network_monitor **ret, const char *category);
fe8db0c5
TG
195
196/* Destroys the passed monitor. Returns NULL. */
197sd_network_monitor* sd_network_monitor_unref(sd_network_monitor *m);
198
199/* Flushes the monitor */
200int sd_network_monitor_flush(sd_network_monitor *m);
201
202/* Get FD from monitor */
203int sd_network_monitor_get_fd(sd_network_monitor *m);
204
205/* Get poll() mask to monitor */
206int sd_network_monitor_get_events(sd_network_monitor *m);
207
208/* Get timeout for poll(), as usec value relative to CLOCK_MONOTONIC's epoch */
209int sd_network_monitor_get_timeout(sd_network_monitor *m, uint64_t *timeout_usec);
210
4afd3348
LP
211_SD_DEFINE_POINTER_CLEANUP_FUNC(sd_network_monitor, sd_network_monitor_unref);
212
fe8db0c5
TG
213_SD_END_DECLARATIONS;
214
215#endif