]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/systemd/sd-network.h
Merge pull request #18007 from fw-strlen/ipv6_masq_and_dnat
[thirdparty/systemd.git] / src / systemd / sd-network.h
1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
2 #ifndef foosdnetworkhfoo
3 #define foosdnetworkhfoo
4
5 /***
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
20 #include <inttypes.h>
21 #include <sys/types.h>
22
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
32 * are NULL terminated, and you need to free the array itself in
33 * addition to the strings contained.
34 *
35 * We return error codes as negative errno, kernel-style. On success, we
36 * return 0 or positive.
37 *
38 * These functions access data in /run. This is a virtual file system;
39 * therefore, accesses are relatively cheap.
40 *
41 * See sd-network(3) for more information.
42 */
43
44 _SD_BEGIN_DECLARATIONS;
45
46 /* Get overall operational state
47 * Possible states: down, up, dormant, carrier, degraded, routable
48 * Possible return codes:
49 * -ENODATA: networkd is not aware of any links
50 */
51 int sd_network_get_operational_state(char **state);
52 int sd_network_get_carrier_state(char **state);
53 int sd_network_get_address_state(char **state);
54
55 /* Get DNS entries for all links. These are string representations of
56 * IP addresses */
57 int sd_network_get_dns(char ***dns);
58
59 /* Get NTP entries for all links. These are domain names or string
60 * representations of IP addresses */
61 int sd_network_get_ntp(char ***ntp);
62
63 /* Get the search domains for all links. */
64 int sd_network_get_search_domains(char ***domains);
65
66 /* Get the search domains for all links. */
67 int sd_network_get_route_domains(char ***domains);
68
69 /* Get setup state from ifindex.
70 * Possible states:
71 * pending: udev is still processing the link, we don't yet know if we will manage it
72 * failed: networkd failed to manage the link
73 * configuring: in the process of retrieving configuration or configuring the link
74 * configured: link configured successfully
75 * unmanaged: networkd is not handling the link
76 * linger: the link is gone, but has not yet been dropped by networkd
77 * Possible return codes:
78 * -ENODATA: networkd is not aware of the link
79 */
80 int sd_network_link_get_setup_state(int ifindex, char **state);
81
82 /* Get operational state from ifindex.
83 * Possible states:
84 * off: the device is powered down
85 * no-carrier: the device is powered up, but it does not yet have a carrier
86 * dormant: the device has a carrier, but is not yet ready for normal traffic
87 * carrier: the link has a carrier
88 * degraded: the link has carrier and addresses valid on the local link configured
89 * routable: the link has carrier and routable address configured
90 * Possible return codes:
91 * -ENODATA: networkd is not aware of the link
92 */
93 int sd_network_link_get_operational_state(int ifindex, char **state);
94 int sd_network_link_get_required_operstate_for_online(int ifindex, char **state);
95 int sd_network_link_get_carrier_state(int ifindex, char **state);
96 int sd_network_link_get_address_state(int ifindex, char **state);
97
98 /* Indicates whether the network is relevant to being online.
99 * Possible return codes:
100 * 0: the connection is not required
101 * 1: the connection is required to consider the system online
102 * <0: networkd is not aware of the link
103 */
104 int sd_network_link_get_required_for_online(int ifindex);
105
106 /* Get activation policy for ifindex.
107 * Possible values are as specified for ActivationPolicy=
108 */
109 int sd_network_link_get_activation_policy(int ifindex, char **policy);
110
111 /* Get path to .network file applied to link */
112 int sd_network_link_get_network_file(int ifindex, char **filename);
113
114 /* Get DNS entries for a given link. These are string representations of
115 * IP addresses */
116 int sd_network_link_get_dns(int ifindex, char ***ret);
117
118 /* Get NTP entries for a given link. These are domain names or string
119 * representations of IP addresses */
120 int sd_network_link_get_ntp(int ifindex, char ***ret);
121
122 /* Get SIP entries for a given link. These are string
123 * representations of IP addresses */
124 int sd_network_link_get_sip(int ifindex, char ***ret);
125
126 /* Indicates whether or not LLMNR should be enabled for the link
127 * Possible levels of support: yes, no, resolve
128 * Possible return codes:
129 * -ENODATA: networkd is not aware of the link
130 */
131 int sd_network_link_get_llmnr(int ifindex, char **llmnr);
132
133 /* Indicates whether or not MulticastDNS should be enabled for the
134 * link.
135 * Possible levels of support: yes, no, resolve
136 * Possible return codes:
137 * -ENODATA: networkd is not aware of the link
138 */
139 int sd_network_link_get_mdns(int ifindex, char **mdns);
140
141 /* Indicates whether or not DNS-over-TLS should be enabled for the
142 * link.
143 * Possible levels of support: yes, no, opportunistic
144 * Possible return codes:
145 * -ENODATA: networkd is not aware of the link
146 */
147 int sd_network_link_get_dns_over_tls(int ifindex, char **dns_over_tls);
148
149 /* Indicates whether or not DNSSEC should be enabled for the link
150 * Possible levels of support: yes, no, allow-downgrade
151 * Possible return codes:
152 * -ENODATA: networkd is not aware of the link
153 */
154 int sd_network_link_get_dnssec(int ifindex, char **dnssec);
155
156 /* Returns the list of per-interface DNSSEC negative trust anchors
157 * Possible return codes:
158 * -ENODATA: networkd is not aware of the link, or has no such data
159 */
160 int sd_network_link_get_dnssec_negative_trust_anchors(int ifindex, char ***nta);
161
162 /* Get the search DNS domain names for a given link. */
163 int sd_network_link_get_search_domains(int ifindex, char ***domains);
164
165 /* Get the route DNS domain names for a given link. */
166 int sd_network_link_get_route_domains(int ifindex, char ***domains);
167
168 /* Get whether this link shall be used as 'default route' for DNS queries */
169 int sd_network_link_get_dns_default_route(int ifindex);
170
171 /* Get the carrier interface indexes to which current link is bound to. */
172 int sd_network_link_get_carrier_bound_to(int ifindex, int **ifindexes);
173
174 /* Get the CARRIERS that are bound to current link. */
175 int sd_network_link_get_carrier_bound_by(int ifindex, int **ifindexes);
176
177 /* Get DHCPv6 client IAID for a given link. */
178 int sd_network_link_get_dhcp6_client_iaid_string(int ifindex, char **iaid);
179
180 /* Get DHCPv6 client DUID for a given link. */
181 int sd_network_link_get_dhcp6_client_duid_string(int ifindex, char **duid);
182
183 /* Monitor object */
184 typedef struct sd_network_monitor sd_network_monitor;
185
186 /* Create a new monitor. Category must be NULL, "links" or "leases". */
187 int sd_network_monitor_new(sd_network_monitor **ret, const char *category);
188
189 /* Destroys the passed monitor. Returns NULL. */
190 sd_network_monitor* sd_network_monitor_unref(sd_network_monitor *m);
191
192 /* Flushes the monitor */
193 int sd_network_monitor_flush(sd_network_monitor *m);
194
195 /* Get FD from monitor */
196 int sd_network_monitor_get_fd(sd_network_monitor *m);
197
198 /* Get poll() mask to monitor */
199 int sd_network_monitor_get_events(sd_network_monitor *m);
200
201 /* Get timeout for poll(), as usec value relative to CLOCK_MONOTONIC's epoch */
202 int sd_network_monitor_get_timeout(sd_network_monitor *m, uint64_t *timeout_usec);
203
204 _SD_DEFINE_POINTER_CLEANUP_FUNC(sd_network_monitor, sd_network_monitor_unref);
205
206 _SD_END_DECLARATIONS;
207
208 #endif