1/*	$OpenBSD: slaacd.h,v 1.38 2022/07/12 16:55: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	_PATH_LOCKFILE		"/dev/slaacd.lock"
22#define	_PATH_SLAACD_SOCKET	"/dev/slaacd.sock"
23#define SLAACD_USER		"_slaacd"
24#define SLAACD_RTA_LABEL	"slaacd"
25
26#define SLAACD_SOIIKEY_LEN	16
27
28#define	MAX_RDNS_COUNT		8 /* max nameserver in a RTM_PROPOSAL */
29
30#define	IMSG_DATA_SIZE(imsg)	((imsg).hdr.len - IMSG_HEADER_SIZE)
31
32struct imsgev {
33	struct imsgbuf	 ibuf;
34	void		(*handler)(int, short, void *);
35	struct event	 ev;
36	short		 events;
37};
38
39enum imsg_type {
40	IMSG_NONE,
41#ifndef	SMALL
42	IMSG_CTL_LOG_VERBOSE,
43	IMSG_CTL_SHOW_INTERFACE_INFO,
44	IMSG_CTL_SHOW_INTERFACE_INFO_RA,
45	IMSG_CTL_SHOW_INTERFACE_INFO_RA_PREFIX,
46	IMSG_CTL_SHOW_INTERFACE_INFO_RA_RDNS,
47	IMSG_CTL_SHOW_INTERFACE_INFO_ADDR_PROPOSALS,
48	IMSG_CTL_SHOW_INTERFACE_INFO_ADDR_PROPOSAL,
49	IMSG_CTL_SHOW_INTERFACE_INFO_DFR_PROPOSALS,
50	IMSG_CTL_SHOW_INTERFACE_INFO_DFR_PROPOSAL,
51	IMSG_CTL_SHOW_INTERFACE_INFO_RDNS_PROPOSALS,
52	IMSG_CTL_SHOW_INTERFACE_INFO_RDNS_PROPOSAL,
53	IMSG_CTL_END,
54#endif	/* SMALL */
55	IMSG_PROPOSE_RDNS,
56	IMSG_REPROPOSE_RDNS,
57	IMSG_CTL_SEND_SOLICITATION,
58	IMSG_SOCKET_IPC,
59	IMSG_OPEN_ICMP6SOCK,
60	IMSG_ICMP6SOCK,
61	IMSG_ROUTESOCK,
62	IMSG_CONTROLFD,
63	IMSG_STARTUP,
64	IMSG_UPDATE_IF,
65	IMSG_REMOVE_IF,
66	IMSG_RA,
67	IMSG_CONFIGURE_ADDRESS,
68	IMSG_WITHDRAW_ADDRESS,
69	IMSG_DEL_ADDRESS,
70	IMSG_DEL_ROUTE,
71	IMSG_CONFIGURE_DFR,
72	IMSG_WITHDRAW_DFR,
73	IMSG_DUP_ADDRESS,
74};
75
76enum rpref {
77	LOW,
78	MEDIUM,
79	HIGH,
80};
81
82#ifndef	SMALL
83struct ctl_engine_info {
84	uint32_t		if_index;
85	int			running;
86	int			autoconf;
87	int			temporary;
88	int			soii;
89	struct ether_addr	hw_address;
90	struct sockaddr_in6	ll_address;
91};
92
93struct ctl_engine_info_ra {
94	struct sockaddr_in6	 from;
95	struct timespec		 when;
96	struct timespec		 uptime;
97	uint8_t			 curhoplimit;
98	int			 managed;
99	int			 other;
100	char			 rpref[sizeof("MEDIUM")];
101	uint16_t		 router_lifetime;	/* in seconds */
102	uint32_t		 reachable_time;	/* in milliseconds */
103	uint32_t		 retrans_time;		/* in milliseconds */
104	uint32_t		 mtu;
105};
106
107struct ctl_engine_info_ra_prefix {
108	struct in6_addr		prefix;
109	uint8_t			prefix_len;
110	int			onlink;
111	int			autonomous;
112	uint32_t		vltime;
113	uint32_t		pltime;
114};
115
116struct ctl_engine_info_ra_rdns {
117	uint32_t		lifetime;
118	struct in6_addr		rdns;
119};
120
121struct ctl_engine_info_address_proposal {
122	int64_t			 id;
123	char			 state[sizeof("PROPOSAL_NEARLY_EXPIRED")];
124	time_t			 next_timeout;
125	struct timespec		 when;
126	struct timespec		 uptime;
127	struct sockaddr_in6	 addr;
128	struct in6_addr		 prefix;
129	int			 temporary;
130	uint8_t			 prefix_len;
131	uint32_t		 vltime;
132	uint32_t		 pltime;
133};
134
135struct ctl_engine_info_dfr_proposal {
136	int64_t			 id;
137	char			 state[sizeof("PROPOSAL_NEARLY_EXPIRED")];
138	time_t			 next_timeout;
139	struct timespec		 when;
140	struct timespec		 uptime;
141	struct sockaddr_in6	 addr;
142	uint32_t		 router_lifetime;
143	char			 rpref[sizeof("MEDIUM")];
144};
145
146struct ctl_engine_info_rdns_proposal {
147	int64_t			 id;
148	char			 state[sizeof("PROPOSAL_NEARLY_EXPIRED")];
149	time_t			 next_timeout;
150	struct timespec		 when;
151	struct timespec		 uptime;
152	struct sockaddr_in6	 from;
153	uint32_t		 rdns_lifetime;
154	int			 rdns_count;
155	struct in6_addr		 rdns[MAX_RDNS_COUNT];
156};
157
158#endif	/* SMALL */
159
160struct imsg_propose_rdns {
161	uint32_t		if_index;
162	int			rdomain;
163	int			rdns_count;
164	struct in6_addr		rdns[MAX_RDNS_COUNT];
165};
166
167
168struct imsg_ifinfo {
169	uint32_t		if_index;
170	int			rdomain;
171	int			running;
172	int			link_state;
173	int			autoconf;
174	int			temporary;
175	int			soii;
176	struct ether_addr	hw_address;
177	struct sockaddr_in6	ll_address;
178	uint8_t			soiikey[SLAACD_SOIIKEY_LEN];
179};
180
181struct imsg_del_addr {
182	uint32_t		if_index;
183	struct sockaddr_in6	addr;
184};
185
186struct imsg_del_route {
187	uint32_t		if_index;
188	struct sockaddr_in6	gw;
189};
190
191struct imsg_ra {
192	uint32_t		if_index;
193	struct sockaddr_in6	from;
194	ssize_t			len;
195	uint8_t			packet[1500];
196};
197
198struct imsg_dup_addr {
199	uint32_t		if_index;
200	struct sockaddr_in6	addr;
201};
202
203/* slaacd.c */
204void		imsg_event_add(struct imsgev *);
205int		imsg_compose_event(struct imsgev *, uint16_t, uint32_t, pid_t,
206		    int, void *, uint16_t);
207#ifndef	SMALL
208const char	*sin6_to_str(struct sockaddr_in6 *);
209#else
210#define	sin6_to_str(x...)	""
211#endif	/* SMALL */
212