xref: /openbsd-src/usr.sbin/ospf6d/ospfe.h (revision 50b7afb2c2c0993b0894d4e34bf857cb13ed9c80)
1 /*	$OpenBSD: ospfe.h,v 1.18 2013/03/25 14:29:35 markus 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 _OSPFE_H_
20 #define _OSPFE_H_
21 
22 #define max(x,y) ((x) > (y) ? (x) : (y))
23 
24 #include <sys/types.h>
25 #include <sys/socket.h>
26 #include <netinet/in.h>
27 #include <netinet/in_systm.h>
28 #include <netinet/ip.h>
29 
30 TAILQ_HEAD(ctl_conns, ctl_conn)	ctl_conns;
31 
32 struct lsa_entry {
33 	TAILQ_ENTRY(lsa_entry)	 entry;
34 	union {
35 		struct lsa_hdr	*lu_lsa;
36 		struct lsa_ref	*lu_ref;
37 	}			 le_data;
38 	unsigned short		 le_when;
39 	unsigned short		 le_oneshot;
40 };
41 #define	le_lsa	le_data.lu_lsa
42 #define	le_ref	le_data.lu_ref
43 
44 struct lsa_ref {
45 	LIST_ENTRY(lsa_ref)	 entry;
46 	struct lsa_hdr		 hdr;
47 	void			*data;
48 	time_t			 stamp;
49 	int			 refcnt;
50 	u_int16_t		 len;
51 };
52 
53 struct nbr_stats {
54 	u_int32_t		 sta_chng;
55 };
56 
57 struct nbr {
58 	LIST_ENTRY(nbr)		 entry, hash;
59 	struct event		 inactivity_timer;
60 	struct event		 db_tx_timer;
61 	struct event		 lsreq_tx_timer;
62 	struct event		 ls_retrans_timer;
63 	struct event		 adj_timer;
64 
65 	struct nbr_stats	 stats;
66 
67 	struct lsa_head		 ls_retrans_list;
68 	struct lsa_head		 db_sum_list;
69 	struct lsa_head		 ls_req_list;
70 
71 	struct in6_addr		 addr;		/* ip6 address */
72 	struct in_addr		 id;		/* router id */
73 	struct in_addr		 dr;		/* designated router */
74 	struct in_addr		 bdr;		/* backup designated router */
75 
76 	struct iface		*iface;
77 	struct lsa_entry	*ls_req;
78 	struct lsa_entry	*dd_end;
79 
80 	u_int32_t		 iface_id;	/* id of neighbor's iface */
81 	u_int32_t		 dd_seq_num;
82 	u_int32_t		 dd_pending;
83 	u_int32_t		 peerid;	/* unique ID in DB */
84 	u_int32_t		 ls_req_cnt;
85 	u_int32_t		 ls_ret_cnt;
86 	u_int32_t		 options;
87 	u_int32_t		 last_rx_options;
88 	u_int32_t		 link_options;	/* options from link-LSA */
89 
90 	time_t			 uptime;
91 	int			 state;
92 	u_int8_t		 priority;
93 	u_int8_t		 last_rx_bits;
94 	u_int8_t		 dd_master;
95 	u_int8_t		 dd_more;
96 	u_int8_t		 dd_snapshot;	/* snapshot running */
97 };
98 
99 /* database.c */
100 int	 send_db_description(struct nbr *);
101 void	 recv_db_description(struct nbr *, char *, u_int16_t);
102 void	 db_sum_list_add(struct nbr *, struct lsa_hdr *);
103 int	 db_sum_list_del(struct nbr *, struct lsa_hdr *);
104 void	 db_sum_list_clr(struct nbr *);
105 void	 db_tx_timer(int, short, void *);
106 void	 start_db_tx_timer(struct nbr *);
107 void	 stop_db_tx_timer(struct nbr *);
108 
109 /* hello.c */
110 int	 send_hello(struct iface *);
111 void	 recv_hello(struct iface *,  struct in6_addr *, u_int32_t,
112 	     char *, u_int16_t);
113 
114 /* ospfe.c */
115 pid_t		 ospfe(struct ospfd_conf *, int[2], int[2], int[2]);
116 void		 ospfe_dispatch_main(int, short, void *);
117 void		 ospfe_dispatch_rde(int, short, void *);
118 int		 ospfe_imsg_compose_parent(int, pid_t, void *, u_int16_t);
119 int		 ospfe_imsg_compose_rde(int, u_int32_t, pid_t, void *,
120 		     u_int16_t);
121 u_int32_t	 ospfe_router_id(void);
122 void		 ospfe_fib_update(int);
123 void		 ospfe_iface_ctl(struct ctl_conn *, unsigned int);
124 void		 ospfe_nbr_ctl(struct ctl_conn *);
125 void		 orig_rtr_lsa(struct iface *);
126 void		 orig_net_lsa(struct iface *);
127 void		 orig_link_lsa(struct iface *);
128 void		 ospfe_demote_area(struct area *, int);
129 void		 ospfe_demote_iface(struct iface *, int);
130 
131 /* interface.c */
132 int		 if_fsm(struct iface *, enum iface_event);
133 
134 void		 if_del(struct iface *);
135 void		 if_start(struct ospfd_conf *, struct iface *);
136 
137 int		 if_act_start(struct iface *);
138 int		 if_act_elect(struct iface *);
139 int		 if_act_reset(struct iface *);
140 
141 struct ctl_iface	*if_to_ctl(struct iface *);
142 
143 int	 if_join_group(struct iface *, struct in6_addr *);
144 int	 if_leave_group(struct iface *, struct in6_addr *);
145 int	 if_set_mcast(struct iface *);
146 void	 if_set_recvbuf(int);
147 int	 if_set_mcast_loop(int);
148 int	 if_set_ipv6_pktinfo(int, int);
149 int	 if_set_ipv6_checksum(int);
150 
151 /* lsack.c */
152 int	 delay_lsa_ack(struct iface *, struct lsa_hdr *);
153 int	 send_ls_ack(struct iface *, struct in6_addr, void *, size_t);
154 void	 recv_ls_ack(struct nbr *, char *, u_int16_t);
155 int	 lsa_hdr_check(struct nbr *, struct lsa_hdr *);
156 void	 ls_ack_list_add(struct iface *, struct lsa_hdr *);
157 void	 ls_ack_list_free(struct iface *, struct lsa_entry *);
158 void	 ls_ack_list_clr(struct iface *);
159 int	 ls_ack_list_empty(struct iface *);
160 void	 ls_ack_tx_timer(int, short, void *);
161 void	 start_ls_ack_tx_timer(struct iface *);
162 void	 stop_ls_ack_tx_timer(struct iface *);
163 
164 /* lsreq.c */
165 int	 send_ls_req(struct nbr *);
166 void	 recv_ls_req(struct nbr *, char *, u_int16_t);
167 void	 ls_req_list_add(struct nbr *, struct lsa_hdr *);
168 int	 ls_req_list_del(struct nbr *, struct lsa_hdr *);
169 struct lsa_entry	*ls_req_list_get(struct nbr *, struct lsa_hdr *);
170 void	 ls_req_list_free(struct nbr *, struct lsa_entry *);
171 void	 ls_req_list_clr(struct nbr *);
172 int	 ls_req_list_empty(struct nbr *);
173 void	 ls_req_tx_timer(int, short, void *);
174 void	 start_ls_req_tx_timer(struct nbr *);
175 void	 stop_ls_req_tx_timer(struct nbr *);
176 
177 /* lsupdate.c */
178 int		 lsa_flood(struct iface *, struct nbr *, struct lsa_hdr *,
179 		     void *);
180 void		 recv_ls_update(struct nbr *, char *, u_int16_t);
181 
182 void		 ls_retrans_list_add(struct nbr *, struct lsa_hdr *,
183 		     unsigned short, unsigned short);
184 int		 ls_retrans_list_del(struct nbr *, struct lsa_hdr *);
185 struct lsa_entry	*ls_retrans_list_get(struct nbr *, struct lsa_hdr *);
186 void		 ls_retrans_list_free(struct nbr *, struct lsa_entry *);
187 void		 ls_retrans_list_clr(struct nbr *);
188 void		 ls_retrans_timer(int, short, void *);
189 
190 void		 lsa_cache_init(u_int32_t);
191 struct lsa_ref	*lsa_cache_add(void *, u_int16_t);
192 struct lsa_ref	*lsa_cache_get(struct lsa_hdr *);
193 void		 lsa_cache_put(struct lsa_ref *, struct nbr *);
194 
195 /* neighbor.c */
196 void		 nbr_init(u_int32_t);
197 struct nbr	*nbr_new(u_int32_t, struct iface *, u_int32_t, int,
198 		     struct in6_addr *);
199 void		 nbr_del(struct nbr *);
200 
201 struct nbr	*nbr_find_id(struct iface *, u_int32_t);
202 struct nbr	*nbr_find_peerid(u_int32_t);
203 
204 int	 nbr_fsm(struct nbr *, enum nbr_event);
205 
206 void	 nbr_itimer(int, short, void *);
207 void	 nbr_start_itimer(struct nbr *);
208 void	 nbr_stop_itimer(struct nbr *);
209 void	 nbr_reset_itimer(struct nbr *);
210 
211 void	 nbr_adj_timer(int, short, void *);
212 void	 nbr_start_adj_timer(struct nbr *);
213 
214 int	 nbr_act_reset_itimer(struct nbr *);
215 int	 nbr_act_start_itimer(struct nbr *);
216 int	 nbr_act_eval(struct nbr *);
217 int	 nbr_act_snapshot(struct nbr *);
218 int	 nbr_act_exchange_done(struct nbr *);
219 int	 nbr_act_adj_ok(struct nbr *);
220 int	 nbr_act_restart_dd(struct nbr *);
221 int	 nbr_act_delete(struct nbr *);
222 int	 nbr_act_clear_lists(struct nbr *);
223 int	 nbr_act_hello_check(struct nbr *);
224 
225 struct ctl_nbr	*nbr_to_ctl(struct nbr *);
226 
227 struct lsa_hdr	*lsa_hdr_new(void);
228 
229 /* packet.c */
230 int	 gen_ospf_hdr(struct ibuf *, struct iface *, u_int8_t);
231 int	 upd_ospf_hdr(struct ibuf *, struct iface *);
232 int	 send_packet(struct iface *, void *, size_t, struct in6_addr *);
233 void	 recv_packet(int, short, void *);
234 
235 char	*pkt_ptr;	/* packet buffer */
236 
237 #endif	/* _OSPFE_H_ */
238