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