1:255.13-alt1
[systemd_ALT.git] / src / systemd / sd-ndisc.h
blob3f93e3a40682849f673ae689b77fad030cba739a
1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
2 #ifndef foosdndiscfoo
3 #define foosdndiscfoo
5 /***
6 Copyright © 2014 Intel Corporation. All rights reserved.
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.
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.
18 You should have received a copy of the GNU Lesser General Public License
19 along with systemd; If not, see <https://www.gnu.org/licenses/>.
20 ***/
22 #include <errno.h>
23 #include <inttypes.h>
24 #include <net/ethernet.h>
25 #include <netinet/in.h>
26 #include <sys/types.h>
28 #include "sd-event.h"
30 #include "_sd-common.h"
32 _SD_BEGIN_DECLARATIONS;
34 /* Neighbor Discovery Options, RFC 4861, Section 4.6 and
35 * https://www.iana.org/assignments/icmpv6-parameters/icmpv6-parameters.xhtml#icmpv6-parameters-5 */
36 enum {
37 SD_NDISC_OPTION_SOURCE_LL_ADDRESS = 1,
38 SD_NDISC_OPTION_TARGET_LL_ADDRESS = 2,
39 SD_NDISC_OPTION_PREFIX_INFORMATION = 3,
40 SD_NDISC_OPTION_MTU = 5,
41 SD_NDISC_OPTION_ROUTE_INFORMATION = 24,
42 SD_NDISC_OPTION_RDNSS = 25,
43 SD_NDISC_OPTION_FLAGS_EXTENSION = 26,
44 SD_NDISC_OPTION_DNSSL = 31,
45 SD_NDISC_OPTION_CAPTIVE_PORTAL = 37,
46 SD_NDISC_OPTION_PREF64 = 38
49 /* Route preference, RFC 4191, Section 2.1 */
50 enum {
51 SD_NDISC_PREFERENCE_LOW = 3U,
52 SD_NDISC_PREFERENCE_MEDIUM = 0U,
53 SD_NDISC_PREFERENCE_HIGH = 1U
56 typedef struct sd_ndisc sd_ndisc;
57 typedef struct sd_ndisc_router sd_ndisc_router;
59 __extension__ typedef enum sd_ndisc_event_t {
60 SD_NDISC_EVENT_TIMEOUT,
61 SD_NDISC_EVENT_ROUTER,
62 _SD_NDISC_EVENT_MAX,
63 _SD_NDISC_EVENT_INVALID = -EINVAL,
64 _SD_ENUM_FORCE_S64(NDISC_EVENT)
65 } sd_ndisc_event_t;
67 typedef void (*sd_ndisc_callback_t)(sd_ndisc *nd, sd_ndisc_event_t event, sd_ndisc_router *rt, void *userdata);
69 int sd_ndisc_new(sd_ndisc **ret);
70 sd_ndisc *sd_ndisc_ref(sd_ndisc *nd);
71 sd_ndisc *sd_ndisc_unref(sd_ndisc *nd);
73 int sd_ndisc_start(sd_ndisc *nd);
74 int sd_ndisc_stop(sd_ndisc *nd);
76 int sd_ndisc_attach_event(sd_ndisc *nd, sd_event *event, int64_t priority);
77 int sd_ndisc_detach_event(sd_ndisc *nd);
78 sd_event *sd_ndisc_get_event(sd_ndisc *nd);
80 int sd_ndisc_set_callback(sd_ndisc *nd, sd_ndisc_callback_t cb, void *userdata);
81 int sd_ndisc_set_ifindex(sd_ndisc *nd, int interface_index);
82 int sd_ndisc_set_ifname(sd_ndisc *nd, const char *interface_name);
83 int sd_ndisc_get_ifname(sd_ndisc *nd, const char **ret);
84 int sd_ndisc_set_mac(sd_ndisc *nd, const struct ether_addr *mac_addr);
86 sd_ndisc_router *sd_ndisc_router_ref(sd_ndisc_router *rt);
87 sd_ndisc_router *sd_ndisc_router_unref(sd_ndisc_router *rt);
89 int sd_ndisc_router_get_address(sd_ndisc_router *rt, struct in6_addr *ret);
90 int sd_ndisc_router_get_timestamp(sd_ndisc_router *rt, clockid_t clock, uint64_t *ret);
91 int sd_ndisc_router_get_raw(sd_ndisc_router *rt, const void **ret, size_t *ret_size);
93 int sd_ndisc_router_get_hop_limit(sd_ndisc_router *rt, uint8_t *ret);
94 int sd_ndisc_router_get_icmp6_ratelimit(sd_ndisc_router *rt, uint64_t *ret);
95 int sd_ndisc_router_get_flags(sd_ndisc_router *rt, uint64_t *ret);
96 int sd_ndisc_router_get_preference(sd_ndisc_router *rt, unsigned *ret);
97 int sd_ndisc_router_get_lifetime(sd_ndisc_router *rt, uint64_t *ret);
98 int sd_ndisc_router_get_lifetime_timestamp(sd_ndisc_router *rt, clockid_t clock, uint64_t *ret);
99 int sd_ndisc_router_get_mtu(sd_ndisc_router *rt, uint32_t *ret);
101 /* Generic option access */
102 int sd_ndisc_router_option_rewind(sd_ndisc_router *rt);
103 int sd_ndisc_router_option_next(sd_ndisc_router *rt);
104 int sd_ndisc_router_option_get_type(sd_ndisc_router *rt, uint8_t *ret);
105 int sd_ndisc_router_option_is_type(sd_ndisc_router *rt, uint8_t type);
106 int sd_ndisc_router_option_get_raw(sd_ndisc_router *rt, const void **ret, size_t *ret_size);
108 /* Specific option access: SD_NDISC_OPTION_PREFIX_INFORMATION */
109 int sd_ndisc_router_prefix_get_valid_lifetime(sd_ndisc_router *rt, uint64_t *ret);
110 int sd_ndisc_router_prefix_get_valid_lifetime_timestamp(sd_ndisc_router *rt, clockid_t clock, uint64_t *ret);
111 int sd_ndisc_router_prefix_get_preferred_lifetime(sd_ndisc_router *rt, uint64_t *ret);
112 int sd_ndisc_router_prefix_get_preferred_lifetime_timestamp(sd_ndisc_router *rt, clockid_t clock, uint64_t *ret);
113 int sd_ndisc_router_prefix_get_flags(sd_ndisc_router *rt, uint8_t *ret);
114 int sd_ndisc_router_prefix_get_address(sd_ndisc_router *rt, struct in6_addr *ret);
115 int sd_ndisc_router_prefix_get_prefixlen(sd_ndisc_router *rt, unsigned *ret);
117 /* Specific option access: SD_NDISC_OPTION_ROUTE_INFORMATION */
118 int sd_ndisc_router_route_get_lifetime(sd_ndisc_router *rt, uint64_t *ret);
119 int sd_ndisc_router_route_get_lifetime_timestamp(sd_ndisc_router *rt, clockid_t clock, uint64_t *ret);
120 int sd_ndisc_router_route_get_address(sd_ndisc_router *rt, struct in6_addr *ret);
121 int sd_ndisc_router_route_get_prefixlen(sd_ndisc_router *rt, unsigned *ret);
122 int sd_ndisc_router_route_get_preference(sd_ndisc_router *rt, unsigned *ret);
124 /* Specific option access: SD_NDISC_OPTION_RDNSS */
125 int sd_ndisc_router_rdnss_get_addresses(sd_ndisc_router *rt, const struct in6_addr **ret);
126 int sd_ndisc_router_rdnss_get_lifetime(sd_ndisc_router *rt, uint64_t *ret);
127 int sd_ndisc_router_rdnss_get_lifetime_timestamp(sd_ndisc_router *rt, clockid_t clock, uint64_t *ret);
129 /* Specific option access: SD_NDISC_OPTION_DNSSL */
130 int sd_ndisc_router_dnssl_get_domains(sd_ndisc_router *rt, char ***ret);
131 int sd_ndisc_router_dnssl_get_lifetime(sd_ndisc_router *rt, uint64_t *ret);
132 int sd_ndisc_router_dnssl_get_lifetime_timestamp(sd_ndisc_router *rt, clockid_t clock, uint64_t *ret);
134 /* Specific option access: SD_NDISC_OPTION_CAPTIVE_PORTAL */
135 int sd_ndisc_router_captive_portal_get_uri(sd_ndisc_router *rt, const char **ret, size_t *ret_size);
137 /* Specific option access: SD_NDISC_OPTION_PREF64 */
138 int sd_ndisc_router_prefix64_get_prefix(sd_ndisc_router *rt, struct in6_addr *ret);
139 int sd_ndisc_router_prefix64_get_prefixlen(sd_ndisc_router *rt, unsigned *ret);
140 int sd_ndisc_router_prefix64_get_lifetime(sd_ndisc_router *rt, uint64_t *ret);
141 int sd_ndisc_router_prefix64_get_lifetime_timestamp(sd_ndisc_router *rt, clockid_t clock, uint64_t *ret);
143 _SD_DEFINE_POINTER_CLEANUP_FUNC(sd_ndisc, sd_ndisc_unref);
144 _SD_DEFINE_POINTER_CLEANUP_FUNC(sd_ndisc_router, sd_ndisc_router_unref);
146 _SD_END_DECLARATIONS;
148 #endif