]> git.proxmox.com Git - mirror_frr.git/blob - ldpd/ldpe.h
pimd: fix mtracebis tool warning
[mirror_frr.git] / ldpd / ldpe.h
1 /* $OpenBSD$ */
2
3 /*
4 * Copyright (c) 2013, 2016 Renato Westphal <renato@openbsd.org>
5 * Copyright (c) 2009 Michele Marchetto <michele@openbsd.org>
6 * Copyright (c) 2004, 2005, 2008 Esben Norby <norby@openbsd.org>
7 *
8 * Permission to use, copy, modify, and distribute this software for any
9 * purpose with or without fee is hereby granted, provided that the above
10 * copyright notice and this permission notice appear in all copies.
11 *
12 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
13 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
14 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
15 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
16 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
17 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
18 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
19 */
20
21 #ifndef _LDPE_H_
22 #define _LDPE_H_
23
24 #include "queue.h"
25 #include "openbsd-tree.h"
26 #ifdef __OpenBSD__
27 #include <net/pfkeyv2.h>
28 #endif
29
30 #include "ldpd.h"
31 #include "lib/ldp_sync.h"
32
33 /* forward declarations */
34 TAILQ_HEAD(mapping_head, mapping_entry);
35
36 struct hello_source {
37 enum hello_type type;
38 struct {
39 struct iface_af *ia;
40 union ldpd_addr src_addr;
41 } link;
42 struct tnbr *target;
43 };
44
45 struct adj {
46 RB_ENTRY(adj) global_entry, nbr_entry, ia_entry;
47 struct in_addr lsr_id;
48 struct nbr *nbr;
49 int ds_tlv;
50 struct hello_source source;
51 struct thread *inactivity_timer;
52 uint16_t holdtime;
53 union ldpd_addr trans_addr;
54 };
55 RB_PROTOTYPE(global_adj_head, adj, global_entry, adj_compare)
56 RB_PROTOTYPE(nbr_adj_head, adj, nbr_entry, adj_compare)
57 RB_PROTOTYPE(ia_adj_head, adj, ia_entry, adj_compare)
58
59 struct tcp_conn {
60 struct nbr *nbr;
61 int fd;
62 struct ibuf_read *rbuf;
63 struct evbuf wbuf;
64 struct thread *rev;
65 in_port_t lport;
66 in_port_t rport;
67 };
68
69 struct nbr {
70 RB_ENTRY(nbr) id_tree, addr_tree, pid_tree;
71 struct tcp_conn *tcp;
72 struct nbr_adj_head adj_tree; /* adjacencies */
73 struct thread *ev_connect;
74 struct thread *keepalive_timer;
75 struct thread *keepalive_timeout;
76 struct thread *init_timeout;
77 struct thread *initdelay_timer;
78
79 struct mapping_head mapping_list;
80 struct mapping_head withdraw_list;
81 struct mapping_head request_list;
82 struct mapping_head release_list;
83 struct mapping_head abortreq_list;
84
85 uint32_t peerid; /* unique ID in DB */
86 int af;
87 int ds_tlv;
88 int v4_enabled; /* announce/process v4 msgs */
89 int v6_enabled; /* announce/process v6 msgs */
90 struct in_addr id; /* lsr id */
91 union ldpd_addr laddr; /* local address */
92 union ldpd_addr raddr; /* remote address */
93 ifindex_t raddr_scope; /* remote address scope (v6) */
94 time_t uptime;
95 int fd;
96 int state;
97 uint32_t conf_seqnum;
98 int idtimer_cnt;
99 uint16_t keepalive;
100 uint16_t max_pdu_len;
101 struct ldp_stats stats;
102
103 struct {
104 uint8_t established;
105 uint32_t spi_in;
106 uint32_t spi_out;
107 enum auth_method method;
108 char md5key[TCP_MD5_KEY_LEN];
109 } auth;
110 int flags;
111 };
112 #define F_NBR_GTSM_NEGOTIATED 0x01
113 #define F_NBR_CAP_DYNAMIC 0x02
114 #define F_NBR_CAP_TWCARD 0x04
115 #define F_NBR_CAP_UNOTIF 0x08
116
117 RB_HEAD(nbr_id_head, nbr);
118 RB_PROTOTYPE(nbr_id_head, nbr, id_tree, nbr_id_compare)
119 RB_HEAD(nbr_addr_head, nbr);
120 RB_PROTOTYPE(nbr_addr_head, nbr, addr_tree, nbr_addr_compare)
121 RB_HEAD(nbr_pid_head, nbr);
122 RB_PROTOTYPE(nbr_pid_head, nbr, pid_tree, nbr_pid_compare)
123
124 struct pending_conn {
125 TAILQ_ENTRY(pending_conn) entry;
126 int fd;
127 int af;
128 union ldpd_addr addr;
129 struct thread *ev_timeout;
130 };
131 #define PENDING_CONN_TIMEOUT 5
132
133 struct mapping_entry {
134 TAILQ_ENTRY(mapping_entry) entry;
135 struct map map;
136 };
137
138 struct ldpd_sysdep {
139 uint8_t no_pfkey;
140 uint8_t no_md5sig;
141 };
142
143 extern struct ldpd_conf *leconf;
144 extern struct ldpd_sysdep sysdep;
145 extern struct nbr_id_head nbrs_by_id;
146 extern struct nbr_addr_head nbrs_by_addr;
147 extern struct nbr_pid_head nbrs_by_pid;
148
149 /* accept.c */
150 void accept_init(void);
151 int accept_add(int, void (*)(struct thread *), void *);
152 void accept_del(int);
153 void accept_pause(void);
154 void accept_unpause(void);
155
156 /* hello.c */
157 int send_hello(enum hello_type, struct iface_af *, struct tnbr *);
158 void recv_hello(struct in_addr, struct ldp_msg *, int, union ldpd_addr *,
159 struct iface *, int, char *, uint16_t);
160
161 /* init.c */
162 void send_init(struct nbr *);
163 int recv_init(struct nbr *, char *, uint16_t);
164 void send_capability(struct nbr *, uint16_t, int);
165 int recv_capability(struct nbr *, char *, uint16_t);
166
167 /* keepalive.c */
168 void send_keepalive(struct nbr *);
169 int recv_keepalive(struct nbr *, char *, uint16_t);
170
171 /* notification.c */
172 void send_notification_full(struct tcp_conn *, struct notify_msg *);
173 void send_notification(struct tcp_conn *, uint32_t, uint32_t, uint16_t);
174 void send_notification_rtlvs(struct nbr *, uint32_t, uint32_t, uint16_t,
175 uint16_t, uint16_t, char *);
176 int recv_notification(struct nbr *, char *, uint16_t);
177 int gen_status_tlv(struct ibuf *, uint32_t, uint32_t, uint16_t);
178
179 /* address.c */
180 void send_address_single(struct nbr *, struct if_addr *, int);
181 void send_address_all(struct nbr *, int);
182 void send_mac_withdrawal(struct nbr *, struct map *, uint8_t *);
183 int recv_address(struct nbr *, char *, uint16_t);
184
185 /* labelmapping.c */
186 #define PREFIX_SIZE(x) (((x) + 7) / 8)
187 void send_labelmessage(struct nbr *, uint16_t, struct mapping_head *);
188 int recv_labelmessage(struct nbr *, char *, uint16_t, uint16_t);
189 int gen_pw_status_tlv(struct ibuf *, uint32_t);
190 uint16_t len_fec_tlv(struct map *);
191 int gen_fec_tlv(struct ibuf *, struct map *);
192 int tlv_decode_fec_elm(struct nbr *, struct ldp_msg *, char *,
193 uint16_t, struct map *);
194
195 /* ldpe.c */
196 void ldpe(void);
197 void ldpe_init(struct ldpd_init *);
198 int ldpe_imsg_compose_parent(int, pid_t, void *,
199 uint16_t);
200 void ldpe_imsg_compose_parent_sync(int, pid_t, void *, uint16_t);
201 int ldpe_imsg_compose_lde(int, uint32_t, pid_t, void *,
202 uint16_t);
203 int ldpe_acl_check(char *, int, union ldpd_addr *, uint8_t);
204 void ldpe_reset_nbrs(int);
205 void ldpe_reset_ds_nbrs(void);
206 void ldpe_remove_dynamic_tnbrs(int);
207 void ldpe_stop_init_backoff(int);
208 struct ctl_conn;
209 void ldpe_iface_ctl(struct ctl_conn *c, ifindex_t ifidx);
210 void ldpe_adj_ctl(struct ctl_conn *);
211 void ldpe_adj_detail_ctl(struct ctl_conn *);
212 void ldpe_nbr_ctl(struct ctl_conn *);
213 void ldpe_ldp_sync_ctl(struct ctl_conn *);
214 void mapping_list_add(struct mapping_head *, struct map *);
215 void mapping_list_clr(struct mapping_head *);
216 void ldpe_set_config_change_time(void);
217
218 /* interface.c */
219 struct iface *if_new(const char *);
220 void ldpe_if_init(struct iface *);
221 void ldpe_if_exit(struct iface *);
222 struct iface *if_lookup(struct ldpd_conf *c, ifindex_t ifidx);
223 struct iface *if_lookup_name(struct ldpd_conf *, const char *);
224 void if_update_info(struct iface *, struct kif *);
225 struct iface_af *iface_af_get(struct iface *, int);
226 void if_addr_add(struct kaddr *);
227 void if_addr_del(struct kaddr *);
228 void ldp_if_update(struct iface *, int);
229 void if_update_all(int);
230 uint16_t if_get_hello_holdtime(struct iface_af *);
231 uint16_t if_get_hello_interval(struct iface_af *);
232 uint16_t if_get_wait_for_sync_interval(void);
233 struct ctl_iface *if_to_ctl(struct iface_af *);
234 in_addr_t if_get_ipv4_addr(struct iface *);
235 int ldp_sync_fsm_adj_event(struct adj *, enum ldp_sync_event);
236 int ldp_sync_fsm_nbr_event(struct nbr *, enum ldp_sync_event);
237 int ldp_sync_fsm_state_req(struct ldp_igp_sync_if_state_req *);
238 int ldp_sync_fsm(struct iface *, enum ldp_sync_event);
239 void ldp_sync_fsm_reset_all(void);
240 const char *ldp_sync_state_name(int);
241 const char *ldp_sync_event_name(int);
242 struct ctl_ldp_sync *ldp_sync_to_ctl(struct iface *);
243
244 /* adjacency.c */
245 struct adj *adj_new(struct in_addr, struct hello_source *,
246 union ldpd_addr *);
247 void adj_del(struct adj *, uint32_t);
248 struct adj *adj_find(struct in_addr, struct hello_source *);
249 int adj_get_af(const struct adj *adj);
250 void adj_start_itimer(struct adj *);
251 void adj_stop_itimer(struct adj *);
252 struct tnbr *tnbr_new(int, union ldpd_addr *);
253 struct tnbr *tnbr_find(struct ldpd_conf *, int, union ldpd_addr *);
254 struct tnbr *tnbr_check(struct ldpd_conf *, struct tnbr *);
255 void tnbr_update(struct tnbr *);
256 void tnbr_update_all(int);
257 uint16_t tnbr_get_hello_holdtime(struct tnbr *);
258 uint16_t tnbr_get_hello_interval(struct tnbr *);
259 struct ctl_adj *adj_to_ctl(struct adj *);
260
261 /* neighbor.c */
262 int nbr_fsm(struct nbr *, enum nbr_event);
263 struct nbr *nbr_new(struct in_addr, int, int, union ldpd_addr *,
264 uint32_t);
265 void nbr_del(struct nbr *);
266 struct nbr *nbr_find_ldpid(uint32_t);
267 struct nbr *nbr_get_first_ldpid(void);
268 struct nbr *nbr_get_next_ldpid(uint32_t);
269 struct nbr *nbr_find_addr(int, union ldpd_addr *);
270 struct nbr *nbr_find_peerid(uint32_t);
271 int nbr_adj_count(struct nbr *, int);
272 int nbr_session_active_role(struct nbr *);
273 void nbr_stop_ktimer(struct nbr *);
274 void nbr_stop_ktimeout(struct nbr *);
275 void nbr_stop_itimeout(struct nbr *);
276 void nbr_start_idtimer(struct nbr *);
277 void nbr_stop_idtimer(struct nbr *);
278 int nbr_pending_idtimer(struct nbr *);
279 int nbr_pending_connect(struct nbr *);
280 int nbr_establish_connection(struct nbr *);
281 int nbr_gtsm_enabled(struct nbr *, struct nbr_params *);
282 int nbr_gtsm_setup(int, int, struct nbr_params *);
283 int nbr_gtsm_check(int, struct nbr *, struct nbr_params *);
284 struct nbr_params *nbr_params_new(struct in_addr);
285 struct nbr_params *nbr_params_find(struct ldpd_conf *, struct in_addr);
286 uint16_t nbr_get_keepalive(int, struct in_addr);
287 struct ctl_nbr *nbr_to_ctl(struct nbr *);
288 void nbr_clear_ctl(struct ctl_nbr *);
289
290 /* packet.c */
291 int gen_ldp_hdr(struct ibuf *, uint16_t);
292 int gen_msg_hdr(struct ibuf *, uint16_t, uint16_t);
293 int send_packet(int, int, union ldpd_addr *,
294 struct iface_af *, void *, size_t);
295 void disc_recv_packet(struct thread *thread);
296 void session_accept(struct thread *thread);
297 void session_accept_nbr(struct nbr *, int);
298 void session_shutdown(struct nbr *, uint32_t, uint32_t,
299 uint32_t);
300 void session_close(struct nbr *);
301 struct tcp_conn *tcp_new(int, struct nbr *);
302 void pending_conn_del(struct pending_conn *);
303 struct pending_conn *pending_conn_find(int, union ldpd_addr *);
304
305 extern char *pkt_ptr; /* packet buffer */
306
307 /* pfkey.c */
308 #ifdef __OpenBSD__
309 int pfkey_read(int, struct sadb_msg *);
310 int pfkey_establish(struct nbr *, struct nbr_params *);
311 int pfkey_remove(struct nbr *);
312 int pfkey_init(void);
313 #endif
314
315 /* l2vpn.c */
316 void ldpe_l2vpn_init(struct l2vpn *);
317 void ldpe_l2vpn_exit(struct l2vpn *);
318 void ldpe_l2vpn_pw_init(struct l2vpn_pw *);
319 void ldpe_l2vpn_pw_exit(struct l2vpn_pw *);
320
321 DECLARE_HOOK(ldp_nbr_state_change, (struct nbr * nbr, int old_state),
322 (nbr, old_state));
323
324 #endif /* _LDPE_H_ */