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