xref: /openbsd/usr.sbin/ospf6d/rde.h (revision 404b540a)
1 /*	$OpenBSD: rde.h,v 1.17 2009/03/29 21:42:30 stsp Exp $ */
2 
3 /*
4  * Copyright (c) 2004, 2005 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 v_nexthop {
30 	TAILQ_ENTRY(v_nexthop)	 entry;
31 	struct vertex		*prev;
32 	struct in6_addr		 nexthop;
33 	u_int32_t		 ifindex;
34 };
35 
36 TAILQ_HEAD(v_nexthead, v_nexthop);
37 
38 struct vertex {
39 	RB_ENTRY(vertex)	 entry;
40 	TAILQ_ENTRY(vertex)	 cand;
41 	struct v_nexthead	 nexthop;
42 	struct event		 ev;
43 	struct area		*area;
44 	struct lsa		*lsa;
45 	struct lsa_tree		*lsa_tree;
46 	time_t			 changed;
47 	time_t			 stamp;
48 	u_int32_t		 cost;
49 	u_int32_t		 peerid;	/* neighbor unique imsg ID */
50 	u_int32_t		 ls_id;
51 	u_int32_t		 adv_rtr;
52 	u_int16_t		 type;
53 	u_int8_t		 flooded;
54 	u_int8_t		 deleted;
55 	u_int8_t		 self;
56 };
57 
58 struct rde_req_entry {
59 	TAILQ_ENTRY(rde_req_entry)	entry;
60 	u_int32_t			ls_id;
61 	u_int32_t			adv_rtr;
62 	u_int8_t			type;
63 };
64 
65 /* just the info RDE needs */
66 struct rde_nbr {
67 	LIST_ENTRY(rde_nbr)		 entry, hash;
68 	struct in6_addr			 addr;
69 	struct in_addr			 id;
70 	struct in_addr			 area_id;
71 	TAILQ_HEAD(, rde_req_entry)	 req_list;
72 	struct area			*area;
73 	struct iface			*iface;
74 	u_int32_t			 peerid;	/* unique ID in DB */
75 	unsigned int			 ifindex;
76 	u_int32_t		 	 iface_id;	/* id of neighbor's
77 							   iface */
78 	int				 state;
79 	int				 self;
80 };
81 
82 /* expanded and host-byte-order version of a lsa_prefix */
83 struct rt_prefix {
84 	struct in6_addr	prefix;
85 	u_int16_t	metric;
86 	u_int8_t	prefixlen;
87 	u_int8_t	options;
88 };
89 
90 struct rt_nexthop {
91 	TAILQ_ENTRY(rt_nexthop)	entry;
92 	struct in6_addr		nexthop;
93 	struct in_addr		adv_rtr;
94 	time_t			uptime;
95 	u_int8_t		connected;
96 	u_int8_t		invalid;
97 };
98 
99 struct rt_node {
100 	RB_ENTRY(rt_node)	entry;
101 	TAILQ_HEAD(,rt_nexthop)	nexthop;
102 	struct in6_addr		prefix;
103 	struct in_addr		area;
104 	u_int32_t		cost;
105 	u_int32_t		cost2;
106 	u_int32_t		ext_tag;
107 	enum path_type		p_type;
108 	enum dst_type		d_type;
109 	u_int8_t		flags;
110 	u_int8_t		prefixlen;
111 	u_int8_t		invalid;
112 };
113 
114 struct abr_rtr {
115 	struct in6_addr		 addr;
116 	struct in_addr		 abr_id;
117 	struct in6_addr		 dst_ip;
118 	struct in_addr		 area;
119 	u_int16_t		 metric;
120 };
121 
122 extern struct lsa_tree	asext_tree;
123 
124 /* rde.c */
125 pid_t		 rde(struct ospfd_conf *, int [2], int [2], int [2]);
126 int		 rde_imsg_compose_ospfe(int, u_int32_t, pid_t, void *,
127 		     u_int16_t);
128 u_int32_t	 rde_router_id(void);
129 void		 rde_send_change_kroute(struct rt_node *);
130 void		 rde_send_delete_kroute(struct rt_node *);
131 void		 rde_nbr_del(struct rde_nbr *);
132 int		 rde_nbr_loading(struct area *);
133 struct rde_nbr	*rde_nbr_self(struct area *);
134 struct rde_nbr	*rde_nbr_find(u_int32_t);
135 void		 rde_summary_update(struct rt_node *, struct area *);
136 
137 /* rde_lsdb.c */
138 void		 lsa_init(struct lsa_tree *);
139 int		 lsa_compare(struct vertex *, struct vertex *);
140 void		 vertex_free(struct vertex *);
141 int		 lsa_newer(struct lsa_hdr *, struct lsa_hdr *);
142 int		 lsa_check(struct rde_nbr *, struct lsa *, u_int16_t);
143 int		 lsa_self(struct lsa *);
144 void		 lsa_flush(struct rde_nbr *, struct lsa *);
145 void		 lsa_reflood(struct vertex *, struct lsa*);
146 int		 lsa_add(struct rde_nbr *, struct lsa *);
147 void		 lsa_del(struct rde_nbr *, struct lsa_hdr *);
148 void		 lsa_age(struct vertex *);
149 struct vertex	*lsa_find(struct iface *, u_int16_t, u_int32_t, u_int32_t);
150 struct vertex	*lsa_find_rtr(struct area *, u_int32_t);
151 struct vertex	*lsa_find_tree(struct lsa_tree *, u_int16_t, u_int32_t, u_int32_t);
152 u_int16_t	 lsa_num_links(struct vertex *);
153 void		 lsa_snap(struct rde_nbr *, u_int32_t);
154 void		 lsa_dump(struct lsa_tree *, int, pid_t);
155 void		 lsa_merge(struct rde_nbr *, struct lsa *, struct vertex *);
156 void		 lsa_remove_invalid_sums(struct area *);
157 
158 /* rde_spf.c */
159 void		 spf_calc(struct area *);
160 void		 rt_calc(struct vertex *, struct area *, struct ospfd_conf *);
161 void		 asext_calc(struct vertex *);
162 void		 spf_tree_clr(struct area *);
163 
164 void		 cand_list_init(void);
165 void		 cand_list_add(struct vertex *);
166 struct vertex	*cand_list_pop(void);
167 int		 cand_list_present(struct vertex *);
168 void		 cand_list_clr(void);
169 
170 void		 spf_timer(int, short, void *);
171 void		 start_spf_timer(void);
172 void		 stop_spf_timer(struct ospfd_conf *);
173 void		 start_spf_holdtimer(struct ospfd_conf *);
174 
175 void		 rt_init(void);
176 int		 rt_compare(struct rt_node *, struct rt_node *);
177 struct rt_node	*rt_find(struct in6_addr *, u_int8_t, enum dst_type);
178 int		 rt_insert(struct rt_node *);
179 int		 rt_remove(struct rt_node *);
180 void		 rt_clear(void);
181 void		 rt_dump(struct in_addr, pid_t, u_int8_t);
182 
183 struct lsa_rtr_link	*get_rtr_link(struct vertex *, unsigned int);
184 struct lsa_net_link	*get_net_link(struct vertex *, unsigned int);
185 
186 RB_PROTOTYPE(lsa_tree, vertex, entry, lsa_compare)
187 
188 #endif	/* _RDE_H_ */
189