]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/systemd/sd-ndisc.h
0a5447593ffc32e5cb6991fecea6c7b134374263
[thirdparty/systemd.git] / src / systemd / sd-ndisc.h
1 /* SPDX-License-Identifier: LGPL-2.1+ */
2 #ifndef foosdndiscfoo
3 #define foosdndiscfoo
4
5 /***
6 Copyright (C) 2014 Intel Corporation. All rights reserved.
7
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.
12
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.
17
18 You should have received a copy of the GNU Lesser General Public License
19 along with systemd; If not, see <http://www.gnu.org/licenses/>.
20 ***/
21
22 #include <inttypes.h>
23 #include <net/ethernet.h>
24 #include <netinet/in.h>
25 #include <sys/types.h>
26
27 #include "sd-event.h"
28
29 #include "_sd-common.h"
30
31 _SD_BEGIN_DECLARATIONS;
32
33 /* Neightbor Discovery Options, RFC 4861, Section 4.6 and
34 * https://www.iana.org/assignments/icmpv6-parameters/icmpv6-parameters.xhtml#icmpv6-parameters-5 */
35 enum {
36 SD_NDISC_OPTION_SOURCE_LL_ADDRESS = 1,
37 SD_NDISC_OPTION_TARGET_LL_ADDRESS = 2,
38 SD_NDISC_OPTION_PREFIX_INFORMATION = 3,
39 SD_NDISC_OPTION_MTU = 5,
40 SD_NDISC_OPTION_ROUTE_INFORMATION = 24,
41 SD_NDISC_OPTION_RDNSS = 25,
42 SD_NDISC_OPTION_FLAGS_EXTENSION = 26,
43 SD_NDISC_OPTION_DNSSL = 31,
44 SD_NDISC_OPTION_CAPTIVE_PORTAL = 37,
45 };
46
47 /* Route preference, RFC 4191, Section 2.1 */
48 enum {
49 SD_NDISC_PREFERENCE_LOW = 3U,
50 SD_NDISC_PREFERENCE_MEDIUM = 0U,
51 SD_NDISC_PREFERENCE_HIGH = 1U,
52 };
53
54 typedef struct sd_ndisc sd_ndisc;
55 typedef struct sd_ndisc_router sd_ndisc_router;
56
57 typedef enum sd_ndisc_event {
58 SD_NDISC_EVENT_TIMEOUT = 't',
59 SD_NDISC_EVENT_ROUTER = 'r',
60 } sd_ndisc_event;
61
62 typedef void (*sd_ndisc_callback_t)(sd_ndisc *nd, sd_ndisc_event event, sd_ndisc_router *rt, void *userdata);
63
64 int sd_ndisc_new(sd_ndisc **ret);
65 sd_ndisc *sd_ndisc_ref(sd_ndisc *nd);
66 sd_ndisc *sd_ndisc_unref(sd_ndisc *nd);
67
68 int sd_ndisc_start(sd_ndisc *nd);
69 int sd_ndisc_stop(sd_ndisc *nd);
70
71 int sd_ndisc_attach_event(sd_ndisc *nd, sd_event *event, int64_t priority);
72 int sd_ndisc_detach_event(sd_ndisc *nd);
73 sd_event *sd_ndisc_get_event(sd_ndisc *nd);
74
75 int sd_ndisc_set_callback(sd_ndisc *nd, sd_ndisc_callback_t cb, void *userdata);
76 int sd_ndisc_set_ifindex(sd_ndisc *nd, int interface_index);
77 int sd_ndisc_set_mac(sd_ndisc *nd, const struct ether_addr *mac_addr);
78
79 int sd_ndisc_get_mtu(sd_ndisc *nd, uint32_t *ret);
80 int sd_ndisc_get_hop_limit(sd_ndisc *nd, uint8_t *ret);
81
82 int sd_ndisc_router_from_raw(sd_ndisc_router **ret, const void *raw, size_t raw_size);
83 sd_ndisc_router *sd_ndisc_router_ref(sd_ndisc_router *rt);
84 sd_ndisc_router *sd_ndisc_router_unref(sd_ndisc_router *rt);
85
86 int sd_ndisc_router_get_address(sd_ndisc_router *rt, struct in6_addr *ret_addr);
87 int sd_ndisc_router_get_timestamp(sd_ndisc_router *rt, clockid_t clock, uint64_t *ret);
88 int sd_ndisc_router_get_raw(sd_ndisc_router *rt, const void **ret, size_t *size);
89
90 int sd_ndisc_router_get_hop_limit(sd_ndisc_router *rt, uint8_t *ret);
91 int sd_ndisc_router_get_flags(sd_ndisc_router *rt, uint64_t *ret_flags);
92 int sd_ndisc_router_get_preference(sd_ndisc_router *rt, unsigned *ret);
93 int sd_ndisc_router_get_lifetime(sd_ndisc_router *rt, uint16_t *ret_lifetime);
94 int sd_ndisc_router_get_mtu(sd_ndisc_router *rt, uint32_t *ret);
95
96 /* Generic option access */
97 int sd_ndisc_router_option_rewind(sd_ndisc_router *rt);
98 int sd_ndisc_router_option_next(sd_ndisc_router *rt);
99 int sd_ndisc_router_option_get_type(sd_ndisc_router *rt, uint8_t *ret);
100 int sd_ndisc_router_option_is_type(sd_ndisc_router *rt, uint8_t type);
101 int sd_ndisc_router_option_get_raw(sd_ndisc_router *rt, const void **ret, size_t *size);
102
103 /* Specific option access: SD_NDISC_OPTION_PREFIX_INFORMATION */
104 int sd_ndisc_router_prefix_get_valid_lifetime(sd_ndisc_router *rt, uint32_t *ret);
105 int sd_ndisc_router_prefix_get_preferred_lifetime(sd_ndisc_router *rt, uint32_t *ret);
106 int sd_ndisc_router_prefix_get_flags(sd_ndisc_router *rt, uint8_t *ret);
107 int sd_ndisc_router_prefix_get_address(sd_ndisc_router *rt, struct in6_addr *ret_addr);
108 int sd_ndisc_router_prefix_get_prefixlen(sd_ndisc_router *rt, unsigned *prefixlen);
109
110 /* Specific option access: SD_NDISC_OPTION_ROUTE_INFORMATION */
111 int sd_ndisc_router_route_get_lifetime(sd_ndisc_router *rt, uint32_t *ret);
112 int sd_ndisc_router_route_get_address(sd_ndisc_router *rt, struct in6_addr *ret_addr);
113 int sd_ndisc_router_route_get_prefixlen(sd_ndisc_router *rt, unsigned *prefixlen);
114 int sd_ndisc_router_route_get_preference(sd_ndisc_router *rt, unsigned *ret);
115
116 /* Specific option access: SD_NDISC_OPTION_RDNSS */
117 int sd_ndisc_router_rdnss_get_addresses(sd_ndisc_router *rt, const struct in6_addr **ret);
118 int sd_ndisc_router_rdnss_get_lifetime(sd_ndisc_router *rt, uint32_t *ret);
119
120 /* Specific option access: SD_NDISC_OPTION_DNSSL */
121 int sd_ndisc_router_dnssl_get_domains(sd_ndisc_router *rt, char ***ret);
122 int sd_ndisc_router_dnssl_get_lifetime(sd_ndisc_router *rt, uint32_t *ret);
123
124 _SD_DEFINE_POINTER_CLEANUP_FUNC(sd_ndisc, sd_ndisc_unref);
125 _SD_DEFINE_POINTER_CLEANUP_FUNC(sd_ndisc_router, sd_ndisc_router_unref);
126
127 _SD_END_DECLARATIONS;
128
129 #endif