xref: /openbsd/usr.sbin/dvmrpd/rde.h (revision 088a2cd9)
1 /*	$OpenBSD: rde.h,v 1.17 2024/05/18 11:17:30 jsg Exp $ */
2 
3 /*
4  * Copyright (c) 2005, 2006 Esben Norby <norby@openbsd.org>
5  *
6  * Permission to use, copy, modify, and distribute this software for any
7  * purpose with or without fee is hereby granted, provided that the above
8  * copyright notice and this permission notice appear in all copies.
9  *
10  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17  */
18 
19 #ifndef _RDE_H_
20 #define _RDE_H_
21 
22 #include <sys/types.h>
23 #include <sys/time.h>
24 #include <sys/tree.h>
25 #include <sys/queue.h>
26 #include <event.h>
27 #include <limits.h>
28 
29 struct adv_rtr {
30 	struct in_addr		 addr;
31 	u_int8_t		 metric;
32 };
33 
34 struct rt_node {
35 	RB_ENTRY(rt_node)	 entry;
36 	struct event		 expiration_timer;
37 	struct event		 holddown_timer;
38 
39 	struct adv_rtr		 adv_rtr[MAXVIFS];
40 
41 	u_int16_t		 ds_cnt[MAXVIFS];
42 	u_int8_t		 ttls[MAXVIFS];	/* downstream vif(s) */
43 
44 	LIST_HEAD(, ds_nbr)	 ds_list;
45 
46 	struct in_addr		 prefix;
47 	struct in_addr		 nexthop;
48 	time_t			 uptime;
49 
50 	u_short			 ifindex;	/* learned from this iface */
51 
52 	u_int8_t		 cost;
53 	u_int8_t		 old_cost;	/* used when in hold-down */
54 	u_int8_t		 flags;
55 	u_int8_t		 prefixlen;
56 	u_int8_t		 invalid;
57 	u_int8_t		 connected;
58 };
59 
60 struct prune_node {
61 	LIST_ENTRY(prune_node)	 entry;
62 	struct event		 lifetime_timer;
63 
64 	struct mfc_node		*parent;	/* back ptr to mfc_node */
65 
66 	struct in_addr		 nbr;
67 	unsigned int		 ifindex;
68 };
69 
70 struct mfc_node {
71 	RB_ENTRY(mfc_node)	 entry;
72 	struct event		 expiration_timer;
73 	struct event		 prune_timer;
74 
75 	LIST_HEAD(, prune_node)	 prune_list;
76 
77 	struct in_addr		 origin;
78 	struct in_addr		 group;
79 	time_t			 uptime;
80 	u_short			 ifindex;		/* incoming vif */
81 	u_int8_t		 ttls[MAXVIFS];		/* outgoing vif(s) */
82 	u_int8_t		 prune_cnt[MAXVIFS];
83 };
84 
85 /* downstream neighbor per source */
86 struct ds_nbr {
87 	LIST_ENTRY(ds_nbr)	 entry;
88 	struct in_addr		 addr;
89 };
90 
91 /* rde.c */
92 pid_t	rde(struct dvmrpd_conf *, int [2], int [2], int [2]);
93 int	rde_imsg_compose_parent(int, pid_t, void *, u_int16_t);
94 int	rde_imsg_compose_dvmrpe(int, u_int32_t, pid_t, void *, u_int16_t);
95 
96 void	rde_group_list_add(struct iface *, struct in_addr);
97 int	rde_group_list_find(struct iface *, struct in_addr);
98 void	rde_group_list_remove(struct iface *, struct in_addr);
99 
100 /* rde_mfc.c */
101 void		 mfc_init(void);
102 int		 mfc_compare(struct mfc_node *, struct mfc_node *);
103 struct mfc_node *mfc_find(in_addr_t, in_addr_t);
104 int		 mfc_insert(struct mfc_node *);
105 int		 mfc_remove(struct mfc_node *);
106 void		 mfc_clear(void);
107 void		 mfc_dump(pid_t);
108 void		 mfc_update(struct mfc *);
109 void		 mfc_delete(struct mfc *);
110 struct rt_node	*mfc_find_origin(struct in_addr);
111 void		 mfc_update_source(struct rt_node *);
112 int		 mfc_check_members(struct rt_node *, struct iface *);
113 void		 mfc_recv_prune(struct prune *);
114 
115 /* rde_srt.c */
116 void		 rt_init(void);
117 int		 rt_compare(struct rt_node *, struct rt_node *);
118 struct rt_node	*rt_find(in_addr_t, u_int8_t);
119 struct rt_node	*rr_new_rt(struct route_report *, u_int32_t, int);
120 int		 rt_insert(struct rt_node *);
121 void		 rt_update(struct rt_node *);
122 int		 rt_remove(struct rt_node *);
123 void		 rt_clear(void);
124 void		 rt_snap(u_int32_t);
125 void		 rt_dump(pid_t);
126 struct rt_node	*rt_match_origin(in_addr_t);
127 
128 int		 srt_check_route(struct route_report *, int);
129 
130 struct ds_nbr	*srt_find_ds(struct rt_node *, u_int32_t);
131 void		 srt_expire_nbr(struct in_addr, unsigned int);
132 void		 srt_check_downstream_ifaces(struct rt_node *, struct iface *);
133 
134 #endif	/* _RDE_H_ */
135