chiark / gitweb /
sd-network: expose 'unmanaged' as a regular state
[elogind.git] / src / systemd / sd-network.h
1 /*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
2
3 #ifndef foosdnetworkhfoo
4 #define foosdnetworkhfoo
5
6 /***
7   This file is part of systemd.
8
9   Copyright 2011 Lennart Poettering
10   Copyright 2014 Tom Gundersen
11
12   systemd is free software; you can redistribute it and/or modify it
13   under the terms of the GNU Lesser General Public License as published by
14   the Free Software Foundation; either version 2.1 of the License, or
15   (at your option) any later version.
16
17   systemd is distributed in the hope that it will be useful, but
18   WITHOUT ANY WARRANTY; without even the implied warranty of
19   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20   Lesser General Public License for more details.
21
22   You should have received a copy of the GNU Lesser General Public License
23   along with systemd; If not, see <http://www.gnu.org/licenses/>.
24 ***/
25
26 #include <sys/types.h>
27 #include <inttypes.h>
28
29 #include "sd-dhcp-lease.h"
30
31 #include "_sd-common.h"
32
33 /*
34  * A few points:
35  *
36  * Instead of returning an empty string array or empty integer array, we
37  * may return NULL.
38  *
39  * Free the data the library returns with libc free(). String arrays
40  * are NULL terminated, and you need to free the array itself in
41  * addition to the strings contained.
42  *
43  * We return error codes as negative errno, kernel-style. On success, we
44  * return 0 or positive.
45  *
46  * These functions access data in /run. This is a virtual file system;
47  * therefore, accesses are relatively cheap.
48  *
49  * See sd-network(3) for more information.
50  */
51
52 _SD_BEGIN_DECLARATIONS;
53
54 /* Get state from ifindex.
55  * Possible states: failed, configuring, configured, unmanaged
56  * Possible return codes:
57  *   -ENODATA: networkd is not aware of the link
58  *   -EBUSY: udev is still processing the link, networkd does not yet know if it will manage it
59  */
60 int sd_network_get_link_state(unsigned ifindex, char **state);
61
62 /* Get operatinal state from ifindex.
63  * Possible states: unknown, dormant, carrier, degraded, routable
64  * Possible return codes:
65  *   -ENODATA: networkd is not aware of the link
66  */
67 int sd_network_get_link_operational_state(unsigned ifindex, char **state);
68
69 /* Get overall opeartional state
70  * Possible states: unknown, dormant, carrier, degraded, routable
71  * Possible return codes:
72  *   -ENODATA: networkd is not aware of any links
73  */
74 int sd_network_get_operational_state(char **state);
75
76 /* Returns true if link exists and is loopback, and false otherwise */
77 int sd_network_link_is_loopback(unsigned ifindex);
78
79 /* Get DHCPv4 lease from ifindex. */
80 int sd_network_get_dhcp_lease(unsigned ifindex, sd_dhcp_lease **ret);
81
82 /* Returns true if link is configured to respect DNS entries received by DHCP */
83 int sd_network_dhcp_use_dns(unsigned ifindex);
84
85 /* Returns true if link is configured to respect NTP entries received by DHCP */
86 int sd_network_dhcp_use_ntp(unsigned ifindex);
87
88 /* Get IPv4 DNS entries statically configured for the link */
89 int sd_network_get_dns(unsigned ifindex, struct in_addr **addr);
90
91 /* Get IPv4 NTP entries statically configured for the link */
92 int sd_network_get_ntp(unsigned ifindex, struct in_addr **addr);
93
94 /* Get IPv6 DNS entries statically configured for the link */
95 int sd_network_get_dns6(unsigned ifindex, struct in6_addr **addr);
96
97 /* Get IPv6 NTP entries statically configured for the link */
98 int sd_network_get_ntp6(unsigned ifindex, struct in6_addr **addr);
99
100 /* Get all network interfaces' indices, and store them in *indices. Returns
101  * the number of indices. If indices is NULL, only returns the number of indices. */
102 int sd_network_get_ifindices(unsigned **ifindices);
103
104 /* Monitor object */
105 typedef struct sd_network_monitor sd_network_monitor;
106
107 /* Create a new monitor. Category must be NULL, "links" or "leases". */
108 int sd_network_monitor_new(sd_network_monitor **ret, const char *category);
109
110 /* Destroys the passed monitor. Returns NULL. */
111 sd_network_monitor* sd_network_monitor_unref(sd_network_monitor *m);
112
113 /* Flushes the monitor */
114 int sd_network_monitor_flush(sd_network_monitor *m);
115
116 /* Get FD from monitor */
117 int sd_network_monitor_get_fd(sd_network_monitor *m);
118
119 /* Get poll() mask to monitor */
120 int sd_network_monitor_get_events(sd_network_monitor *m);
121
122 /* Get timeout for poll(), as usec value relative to CLOCK_MONOTONIC's epoch */
123 int sd_network_monitor_get_timeout(sd_network_monitor *m, uint64_t *timeout_usec);
124
125 _SD_END_DECLARATIONS;
126
127 #endif