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