xref: /openbsd/sbin/slaacd/slaacd.h (revision 09467b48)
1 /*	$OpenBSD: slaacd.h,v 1.26 2019/11/22 15:30:00 florian Exp $	*/
2 
3 /*
4  * Copyright (c) 2017 Florian Obser <florian@openbsd.org>
5  * Copyright (c) 2004 Esben Norby <norby@openbsd.org>
6  * Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
7  *
8  * Permission to use, copy, modify, and distribute this software for any
9  * purpose with or without fee is hereby granted, provided that the above
10  * copyright notice and this permission notice appear in all copies.
11  *
12  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
13  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
14  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
15  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
16  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
17  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
18  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
19  */
20 
21 #define	SLAACD_SOCKET		"/dev/slaacd.sock"
22 #define SLAACD_USER		"_slaacd"
23 #define SLAACD_RTA_LABEL	"slaacd"
24 
25 #define SLAACD_SOIIKEY_LEN	16
26 
27 /* MAXDNAME from arpa/namesr.h */
28 #define SLAACD_MAX_DNSSL	1025
29 
30 #define	MAX_RDNS_COUNT		8 /* max nameserver in a RTM_PROPOSAL */
31 
32 #define	IMSG_DATA_SIZE(imsg)	((imsg).hdr.len - IMSG_HEADER_SIZE)
33 
34 static const char * const log_procnames[] = {
35 	"main",
36 	"engine",
37 	"frontend"
38 };
39 
40 struct imsgev {
41 	struct imsgbuf	 ibuf;
42 	void		(*handler)(int, short, void *);
43 	struct event	 ev;
44 	short		 events;
45 };
46 
47 enum imsg_type {
48 	IMSG_NONE,
49 #ifndef	SMALL
50 	IMSG_CTL_LOG_VERBOSE,
51 	IMSG_CTL_SHOW_INTERFACE_INFO,
52 	IMSG_CTL_SHOW_INTERFACE_INFO_RA,
53 	IMSG_CTL_SHOW_INTERFACE_INFO_RA_PREFIX,
54 	IMSG_CTL_SHOW_INTERFACE_INFO_RA_RDNS,
55 	IMSG_CTL_SHOW_INTERFACE_INFO_RA_DNSSL,
56 	IMSG_CTL_SHOW_INTERFACE_INFO_ADDR_PROPOSALS,
57 	IMSG_CTL_SHOW_INTERFACE_INFO_ADDR_PROPOSAL,
58 	IMSG_CTL_SHOW_INTERFACE_INFO_DFR_PROPOSALS,
59 	IMSG_CTL_SHOW_INTERFACE_INFO_DFR_PROPOSAL,
60 	IMSG_CTL_SHOW_INTERFACE_INFO_RDNS_PROPOSALS,
61 	IMSG_CTL_SHOW_INTERFACE_INFO_RDNS_PROPOSAL,
62 	IMSG_CTL_END,
63 	IMSG_UPDATE_ADDRESS,
64 	IMSG_UPDATE_LINK_STATE,
65 	IMSG_PROPOSE_RDNS,
66 	IMSG_REPROPOSE_RDNS,
67 #endif	/* SMALL */
68 	IMSG_CTL_SEND_SOLICITATION,
69 	IMSG_SOCKET_IPC,
70 	IMSG_ICMP6SOCK,
71 	IMSG_ROUTESOCK,
72 	IMSG_CONTROLFD,
73 	IMSG_STARTUP,
74 	IMSG_STARTUP_DONE,
75 	IMSG_UPDATE_IF,
76 	IMSG_REMOVE_IF,
77 	IMSG_RA,
78 	IMSG_CONFIGURE_ADDRESS,
79 	IMSG_WITHDRAW_ADDRESS,
80 	IMSG_DEL_ADDRESS,
81 	IMSG_DEL_ROUTE,
82 	IMSG_CONFIGURE_DFR,
83 	IMSG_WITHDRAW_DFR,
84 	IMSG_DUP_ADDRESS,
85 };
86 
87 enum {
88 	PROC_MAIN,
89 	PROC_ENGINE,
90 	PROC_FRONTEND
91 } slaacd_process;
92 
93 enum rpref {
94 	LOW,
95 	MEDIUM,
96 	HIGH,
97 };
98 
99 #ifndef	SMALL
100 struct ctl_engine_info {
101 	uint32_t		if_index;
102 	int			running;
103 	int			autoconfprivacy;
104 	int			soii;
105 	struct ether_addr	hw_address;
106 	struct sockaddr_in6	ll_address;
107 };
108 
109 struct ctl_engine_info_ra {
110 	struct sockaddr_in6	 from;
111 	struct timespec		 when;
112 	struct timespec		 uptime;
113 	uint8_t			 curhoplimit;
114 	int			 managed;
115 	int			 other;
116 	char			 rpref[sizeof("MEDIUM")];
117 	uint16_t		 router_lifetime;	/* in seconds */
118 	uint32_t		 reachable_time;	/* in milliseconds */
119 	uint32_t		 retrans_time;		/* in milliseconds */
120 	uint32_t		 mtu;
121 };
122 
123 struct ctl_engine_info_ra_prefix {
124 	struct in6_addr		prefix;
125 	uint8_t			prefix_len;
126 	int			onlink;
127 	int			autonomous;
128 	uint32_t		vltime;
129 	uint32_t		pltime;
130 };
131 
132 struct ctl_engine_info_ra_rdns {
133 	uint32_t		lifetime;
134 	struct in6_addr		rdns;
135 };
136 
137 struct ctl_engine_info_ra_dnssl {
138 	uint32_t		lifetime;
139 	char			dnssl[SLAACD_MAX_DNSSL];
140 };
141 
142 struct ctl_engine_info_address_proposal {
143 	int64_t			 id;
144 	char			 state[sizeof("PROPOSAL_NEARLY_EXPIRED")];
145 	time_t			 next_timeout;
146 	int			 timeout_count;
147 	struct timespec		 when;
148 	struct timespec		 uptime;
149 	struct sockaddr_in6	 addr;
150 	struct in6_addr		 prefix;
151 	int			 privacy;
152 	uint8_t			 prefix_len;
153 	uint32_t		 vltime;
154 	uint32_t		 pltime;
155 };
156 
157 struct ctl_engine_info_dfr_proposal {
158 	int64_t			 id;
159 	char			 state[sizeof("PROPOSAL_NEARLY_EXPIRED")];
160 	time_t			 next_timeout;
161 	int			 timeout_count;
162 	struct timespec		 when;
163 	struct timespec		 uptime;
164 	struct sockaddr_in6	 addr;
165 	uint32_t		 router_lifetime;
166 	char			 rpref[sizeof("MEDIUM")];
167 };
168 
169 struct ctl_engine_info_rdns_proposal {
170 	int64_t			 id;
171 	char			 state[sizeof("PROPOSAL_NEARLY_EXPIRED")];
172 	time_t			 next_timeout;
173 	int			 timeout_count;
174 	struct timespec		 when;
175 	struct timespec		 uptime;
176 	struct sockaddr_in6	 from;
177 	uint32_t		 rdns_lifetime;
178 	int			 rdns_count;
179 	struct in6_addr		 rdns[MAX_RDNS_COUNT];
180 };
181 
182 struct imsg_addrinfo {
183 	uint32_t		if_index;
184 	struct ether_addr	hw_address;
185 	struct sockaddr_in6	ll_address;
186 	struct sockaddr_in6	addr;
187 	struct in6_addr		mask;
188 	int			privacy;
189 	uint32_t		vltime;
190 	uint32_t		pltime;
191 };
192 
193 struct imsg_link_state {
194 	uint32_t	if_index;
195 	int		link_state;
196 };
197 
198 struct imsg_propose_rdns {
199 	uint32_t		if_index;
200 	int			rdns_count;
201 	struct in6_addr		rdns[MAX_RDNS_COUNT];
202 };
203 
204 #endif	/* SMALL */
205 
206 struct imsg_ifinfo {
207 	uint32_t		if_index;
208 	int			running;
209 	int			autoconfprivacy;
210 	int			soii;
211 	struct ether_addr	hw_address;
212 	struct sockaddr_in6	ll_address;
213 	uint8_t			soiikey[SLAACD_SOIIKEY_LEN];
214 };
215 
216 struct imsg_del_addr {
217 	uint32_t		if_index;
218 	struct sockaddr_in6	addr;
219 };
220 
221 struct imsg_del_route {
222 	uint32_t		if_index;
223 	struct sockaddr_in6	gw;
224 };
225 
226 struct imsg_ra {
227 	uint32_t		if_index;
228 	struct sockaddr_in6	from;
229 	ssize_t			len;
230 	uint8_t			packet[1500];
231 };
232 
233 struct imsg_dup_addr {
234 	uint32_t		if_index;
235 	struct sockaddr_in6	addr;
236 };
237 
238 /* slaacd.c */
239 void		imsg_event_add(struct imsgev *);
240 int		imsg_compose_event(struct imsgev *, uint16_t, uint32_t, pid_t,
241 		    int, void *, uint16_t);
242 #ifndef	SMALL
243 const char	*sin6_to_str(struct sockaddr_in6 *);
244 #else
245 #define	sin6_to_str(x...)	""
246 #endif	/* SMALL */
247