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