xref: /openbsd/usr.sbin/dvmrpd/dvmrpd.h (revision 088a2cd9)
1 /*	$OpenBSD: dvmrpd.h,v 1.25 2024/05/18 11:17:30 jsg Exp $ */
2 
3 /*
4  * Copyright (c) 2004, 2005, 2006 Esben Norby <norby@openbsd.org>
5  * Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
6  *
7  * Permission to use, copy, modify, and distribute this software for any
8  * purpose with or without fee is hereby granted, provided that the above
9  * copyright notice and this permission notice appear in all copies.
10  *
11  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18  */
19 
20 #ifndef _DVMRPD_H_
21 #define _DVMRPD_H_
22 
23 #include <sys/queue.h>
24 #include <sys/socket.h>
25 #include <sys/time.h>
26 #include <sys/tree.h>
27 #include <net/if.h>
28 #include <netinet/in.h>
29 #include <event.h>
30 
31 #include <imsg.h>
32 
33 #define CONF_FILE		"/etc/dvmrpd.conf"
34 #define	DVMRPD_SOCKET		"/var/run/dvmrpd.sock"
35 #define DVMRPD_USER		"_dvmrpd"
36 
37 #define NBR_HASHSIZE		128
38 
39 #define NBR_IDSELF		1
40 #define NBR_CNTSTART		(NBR_IDSELF + 1)
41 
42 #define	READ_BUF_SIZE		65535
43 #define	RT_BUF_SIZE		16384
44 
45 #define	DVMRPD_FLAG_NO_FIB_UPDATE	0x0001
46 
47 #define	F_DVMRPD_INSERTED	0x0001
48 #define	F_KERNEL		0x0002
49 #define	F_CONNECTED		0x0004
50 #define	F_DOWN			0x0010
51 #define	F_STATIC		0x0020
52 #define	F_LONGER		0x0040
53 
54 #define MAXVIFS			32	/* XXX */
55 
56 struct imsgev {
57 	struct imsgbuf		 ibuf;
58 	void			(*handler)(int, short, void *);
59 	struct event		 ev;
60 	void			*data;
61 	short			 events;
62 };
63 
64 enum imsg_type {
65 	IMSG_NONE,
66 	IMSG_CTL_RELOAD,
67 	IMSG_CTL_SHOW_IFACE,
68 	IMSG_CTL_SHOW_IGMP,
69 	IMSG_CTL_SHOW_NBR,
70 	IMSG_CTL_SHOW_RIB,
71 	IMSG_CTL_SHOW_MFC,
72 	IMSG_CTL_MFC_COUPLE,
73 	IMSG_CTL_MFC_DECOUPLE,
74 	IMSG_CTL_KROUTE,
75 	IMSG_CTL_KROUTE_ADDR,
76 	IMSG_CTL_IFINFO,
77 	IMSG_CTL_SHOW_SUM,
78 	IMSG_CTL_END,
79 	IMSG_CTL_LOG_VERBOSE,
80 	IMSG_IFINFO,
81 	IMSG_ROUTE_REPORT,
82 	IMSG_FULL_ROUTE_REPORT,
83 	IMSG_FULL_ROUTE_REPORT_END,
84 	IMSG_MFC_ADD,
85 	IMSG_MFC_DEL,
86 	IMSG_GROUP_ADD,
87 	IMSG_GROUP_DEL,
88 	IMSG_NBR_DEL,
89 	IMSG_SEND_PRUNE,
90 	IMSG_RECV_PRUNE,
91 	IMSG_FLASH_UPDATE,
92 	IMSG_FLASH_UPDATE_DS
93 };
94 
95 /* interface states */
96 #define	IF_STA_DOWN		0x01
97 #define IF_STA_QUERIER		0x02
98 #define	IF_STA_NONQUERIER	0x04
99 #define	IF_STA_ANY		0x07
100 #define	IF_STA_ACTIVE		(~IF_STA_DOWN)
101 
102 /* interface events */
103 enum iface_event {
104 	IF_EVT_NOTHING,
105 	IF_EVT_UP,
106 	IF_EVT_QTMOUT,		/* query timer expired */
107 	IF_EVT_QRECVD,		/* query received, check for lower IP */
108 	IF_EVT_QPRSNTTMOUT,	/* other querier present timeout */
109 	IF_EVT_DOWN
110 };
111 
112 /* interface actions */
113 enum iface_action {
114 	IF_ACT_NOTHING,
115 	IF_ACT_STRT,
116 	IF_ACT_QPRSNT,
117 	IF_ACT_RST
118 };
119 
120 /* interface types */
121 enum iface_type {
122 	IF_TYPE_POINTOPOINT,
123 	IF_TYPE_BROADCAST
124 };
125 
126 /* neighbor states */
127 #define	NBR_STA_DOWN		0x01
128 #define	NBR_STA_1_WAY		0x02
129 #define	NBR_STA_2_WAY		0x04
130 #define NBR_STA_ACTIVE		(~NBR_STA_DOWN)
131 #define NBR_STA_ANY		0xff
132 
133 struct group {
134 	TAILQ_ENTRY(group)	 entry;
135 	struct event		 dead_timer;
136 	struct event		 v1_host_timer;
137 	struct event		 retrans_timer;
138 
139 	struct in_addr		 addr;
140 
141 	struct iface		*iface;
142 
143 	time_t			 uptime;
144 	int			 state;
145 };
146 
147 struct rde_group {
148 	TAILQ_ENTRY(rde_group)	 entry;
149 	struct in_addr		 rde_group;
150 };
151 
152 struct mfc {
153 	struct in_addr		 origin;
154 	struct in_addr		 group;
155 	u_short			 ifindex;
156 	u_int8_t		 ttls[MAXVIFS];
157 };
158 
159 struct prune {
160 	struct in_addr		 origin;
161 	struct in_addr		 netmask;
162 	struct in_addr		 group;
163 	struct in_addr		 nexthop;
164 	u_short			 ifindex;
165 	u_int32_t		 lifetime;
166 };
167 
168 struct nbr_msg {
169 	struct in_addr		 address;
170 	unsigned int		 ifindex;
171 };
172 
173 TAILQ_HEAD(rr_head, rr_entry);
174 
175 struct iface {
176 	LIST_ENTRY(iface)	 entry;
177 	struct event		 probe_timer;
178 	struct event		 query_timer;
179 	struct event		 querier_present_timer;
180 	time_t			 uptime;
181 	LIST_HEAD(, nbr)	 nbr_list;
182 	TAILQ_HEAD(, group)	 group_list;
183 	TAILQ_HEAD(, rde_group)	 rde_group_list;
184 	struct rr_head		 rr_list;
185 
186 	char			 name[IF_NAMESIZE];
187 	struct in_addr		 addr;
188 	struct in_addr		 dst;
189 	struct in_addr		 mask;
190 	struct in_addr		 querier;	/* designated querier */
191 
192 	u_int64_t		 baudrate;
193 	u_int32_t		 gen_id;
194 	u_int32_t		 group_cnt;
195 	u_int32_t		 probe_interval;
196 
197 	u_int32_t		 query_interval;
198 	u_int32_t		 query_resp_interval;
199 	u_int32_t		 recv_query_resp_interval;
200 	u_int32_t		 group_member_interval;
201 	u_int32_t		 querier_present_interval;
202 	u_int32_t		 startup_query_interval;
203 	u_int32_t		 startup_query_cnt;
204 	u_int32_t		 last_member_query_interval;
205 	u_int32_t		 last_member_query_cnt;
206 	u_int32_t		 last_member_query_time;
207 	u_int32_t		 v1_querier_present_tmout;
208 	u_int32_t		 v1_host_present_interval;
209 	u_int32_t		 startup_query_counter; /* actual counter */
210 	u_int32_t		 dead_interval;
211 
212 	unsigned int		 ifindex;		/* ifindex and vif */
213 	int			 fd;
214 	int			 state;
215 	int			 mtu;
216 	int			 nbr_cnt;
217 	int			 adj_cnt;
218 
219 	u_int16_t		 flags;
220 	u_int16_t		 metric;
221 	enum iface_type		 type;
222 
223 	u_int8_t		 robustness;
224 	u_int8_t		 linkstate;
225 	u_int8_t		 if_type;
226 	u_int8_t		 passive;
227 	u_int8_t		 igmp_version;
228 };
229 
230 /* dvmrp_conf */
231 struct dvmrpd_conf {
232 	struct event		 ev;
233 	struct event		 report_timer;
234 	u_int32_t		 gen_id;
235 	u_int32_t		 opts;
236 #define DVMRPD_OPT_VERBOSE	 0x00000001
237 #define DVMRPD_OPT_VERBOSE2	 0x00000002
238 #define DVMRPD_OPT_NOACTION	 0x00000004
239 	int			 maxdepth;
240 	LIST_HEAD(, iface)	 iface_list;
241 	int			 dvmrp_socket;
242 	int			 mroute_socket;
243 	int			 flags;
244 };
245 
246 /* kroute */
247 struct kroute {
248 	struct in_addr		 prefix;
249 	struct in_addr		 nexthop;
250 	u_int16_t		 flags;
251 	u_short			 ifindex;
252 	u_int8_t		 prefixlen;
253 };
254 
255 struct kif {
256 	char			 ifname[IF_NAMESIZE];
257 	u_int64_t		 baudrate;
258 	int			 flags;
259 	int			 mtu;
260 	u_short			 ifindex;
261 	u_int8_t		 if_type;
262 	u_int8_t		 link_state;
263 	u_int8_t		 nh_reachable;	/* for nexthop verification */
264 };
265 
266 /* control data structures */
267 struct ctl_iface {
268 	char			 name[IF_NAMESIZE];
269 	struct in_addr		 addr;
270 	struct in_addr		 mask;
271 	struct in_addr		 querier;
272 
273 	time_t			 probe_timer;
274 	time_t			 query_timer;
275 	time_t			 querier_present_timer;
276 	time_t			 uptime;
277 
278 	u_int64_t		 baudrate;
279 	u_int32_t		 gen_id;
280 	u_int32_t		 group_cnt;
281 	u_int32_t		 probe_interval;
282 	u_int32_t		 query_interval;
283 	u_int32_t		 query_resp_interval;
284 	u_int32_t		 recv_query_resp_interval;
285 	u_int32_t		 group_member_interval;
286 	u_int32_t		 querier_present_interval;
287 	u_int32_t		 startup_query_interval;
288 	u_int32_t		 startup_query_cnt;
289 	u_int32_t		 last_member_query_interval;
290 	u_int32_t		 last_member_query_cnt;
291 	u_int32_t		 last_member_query_time;
292 	u_int32_t		 v1_querier_present_tmout;
293 	u_int32_t		 v1_host_present_interval;
294 	u_int32_t		 dead_interval;
295 
296 	unsigned int		 ifindex;
297 	int			 state;
298 	int			 mtu;
299 	int			 nbr_cnt;
300 	int			 adj_cnt;
301 
302 	u_int16_t		 flags;
303 	u_int16_t		 metric;
304 	enum iface_type		 type;
305 	u_int8_t		 robustness;
306 	u_int8_t		 linkstate;
307 	u_int8_t		 if_type;
308 	u_int8_t		 passive;
309 	u_int8_t		 igmp_version;
310 };
311 
312 struct ctl_group {
313 	time_t			 dead_timer;
314 	time_t			 v1_host_timer;
315 	time_t			 retrans_timer;
316 	time_t			 uptime;
317 	struct in_addr		 addr;
318 	int			 state;
319 };
320 
321 struct ctl_nbr {
322 	char			 name[IF_NAMESIZE];
323 	struct in_addr		 id;
324 	struct in_addr		 addr;
325 	time_t			 dead_timer;
326 	time_t			 uptime;
327 	int			 state;
328 };
329 
330 struct ctl_rt {
331 	struct in_addr		 prefix;
332 	struct in_addr		 nexthop;
333 	struct in_addr		 area;
334 	struct in_addr		 adv_rtr;
335 	time_t			 uptime;
336 	time_t			 expire;
337 	u_int32_t		 cost;
338 	u_int8_t		 flags;
339 	u_int8_t		 prefixlen;
340 };
341 
342 struct ctl_mfc {
343 	u_int8_t		 ttls[MAXVIFS];	/* outgoing vif(s) */
344 	struct in_addr		 origin;
345 	struct in_addr		 group;
346 	time_t			 uptime;
347 	time_t			 expire;
348 	u_short			 ifindex;	/* incoming vif */
349 };
350 
351 struct ctl_sum {
352 	struct in_addr		 rtr_id;
353 	u_int32_t		 hold_time;
354 };
355 
356 /* dvmrpd.c */
357 void main_imsg_compose_dvmrpe(int, pid_t, void *, u_int16_t);
358 
359 /* parse.y */
360 struct dvmrpd_conf	*parse_config(char *, int);
361 int			 cmdline_symset(char *);
362 
363 int	 imsg_compose_event(struct imsgev *, u_int16_t, u_int32_t, pid_t,
364 	    int, void *, u_int16_t);
365 void	 imsg_event_add(struct imsgev *);
366 
367 /* in_cksum.c */
368 u_int16_t	 in_cksum(void *, size_t);
369 
370 /* kroute.c */
371 int		 kif_init(void);
372 void		 kif_clear(void);
373 int		 kr_init(void);
374 void		 kr_shutdown(void);
375 void		 kr_dispatch_msg(int, short, void *);
376 void		 kr_ifinfo(char *);
377 struct kif	*kif_findname(char *);
378 
379 u_int8_t	 prefixlen_classful(in_addr_t);
380 u_int8_t	 mask2prefixlen(in_addr_t);
381 in_addr_t	 prefixlen2mask(u_int8_t);
382 
383 /* kmroute.c */
384 int		 kmr_init(int);
385 void		 kmr_shutdown(void);
386 void		 kmr_recv_msg(int, short, void *);
387 void		 kmr_mfc_couple(void);
388 void		 kmr_mfc_decouple(void);
389 void		 kmroute_clear(void);
390 int		 mrt_init(int);
391 int		 mrt_done(int);
392 int		 mrt_add_vif(int, struct iface *);
393 void		 mrt_del_vif(int, struct iface *);
394 int		 mrt_add_mfc(int, struct mfc *);
395 int		 mrt_del_mfc(int, struct mfc *);
396 
397 /* log.h */
398 const char	*nbr_state_name(int);
399 const char	*if_state_name(int);
400 const char	*if_type_name(enum iface_type);
401 const char	*group_state_name(int);
402 
403 /* printconf.c */
404 void		 print_config(struct dvmrpd_conf *);
405 
406 /* interface.c */
407 struct iface	*if_find_index(u_short);
408 
409 #define	PREFIX_SIZE(x)	(((x) + 7) / 8)
410 
411 #endif	/* _DVMRPD_H_ */
412