]> git.proxmox.com Git - mirror_frr.git/blame - ldpd/ldpe.h
ldpd: add synchronous IPC channels
[mirror_frr.git] / ldpd / ldpe.h
CommitLineData
8429abe0
RW
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
eac6e3f0
RW
24#include "openbsd-queue.h"
25#include "openbsd-tree.h"
26#ifdef __OpenBSD__
8429abe0 27#include <net/pfkeyv2.h>
eac6e3f0 28#endif
8429abe0
RW
29
30#include "ldpd.h"
31
32#define min(x,y) ((x) <= (y) ? (x) : (y))
33#define max(x,y) ((x) > (y) ? (x) : (y))
34
057d48bd
RW
35/* forward declarations */
36TAILQ_HEAD(mapping_head, mapping_entry);
37
8429abe0
RW
38struct hello_source {
39 enum hello_type type;
40 struct {
41 struct iface_af *ia;
42 union ldpd_addr src_addr;
43 } link;
44 struct tnbr *target;
45};
46
47struct adj {
057d48bd 48 RB_ENTRY(adj) global_entry, nbr_entry, ia_entry;
8429abe0
RW
49 struct in_addr lsr_id;
50 struct nbr *nbr;
51 int ds_tlv;
52 struct hello_source source;
eac6e3f0 53 struct thread *inactivity_timer;
8429abe0
RW
54 uint16_t holdtime;
55 union ldpd_addr trans_addr;
56};
057d48bd
RW
57RB_PROTOTYPE(global_adj_head, adj, global_entry, adj_compare)
58RB_PROTOTYPE(nbr_adj_head, adj, nbr_entry, adj_compare)
59RB_PROTOTYPE(ia_adj_head, adj, ia_entry, adj_compare)
8429abe0
RW
60
61struct tcp_conn {
62 struct nbr *nbr;
63 int fd;
64 struct ibuf_read *rbuf;
65 struct evbuf wbuf;
eac6e3f0
RW
66 struct thread *rev;
67 in_port_t lport;
68 in_port_t rport;
8429abe0
RW
69};
70
71struct nbr {
72 RB_ENTRY(nbr) id_tree, addr_tree, pid_tree;
73 struct tcp_conn *tcp;
057d48bd 74 struct nbr_adj_head adj_tree; /* adjacencies */
eac6e3f0
RW
75 struct thread *ev_connect;
76 struct thread *keepalive_timer;
77 struct thread *keepalive_timeout;
78 struct thread *init_timeout;
79 struct thread *initdelay_timer;
8429abe0
RW
80
81 struct mapping_head mapping_list;
82 struct mapping_head withdraw_list;
83 struct mapping_head request_list;
84 struct mapping_head release_list;
85 struct mapping_head abortreq_list;
86
87 uint32_t peerid; /* unique ID in DB */
88 int af;
89 int ds_tlv;
90 int v4_enabled; /* announce/process v4 msgs */
91 int v6_enabled; /* announce/process v6 msgs */
92 struct in_addr id; /* lsr id */
93 union ldpd_addr laddr; /* local address */
94 union ldpd_addr raddr; /* remote address */
95 uint32_t raddr_scope; /* remote address scope (v6) */
96 time_t uptime;
97 int fd;
98 int state;
99 uint32_t conf_seqnum;
100 int idtimer_cnt;
101 uint16_t keepalive;
102 uint16_t max_pdu_len;
103
104 struct {
105 uint8_t established;
106 uint32_t spi_in;
107 uint32_t spi_out;
108 enum auth_method method;
109 char md5key[TCP_MD5_KEY_LEN];
110 } auth;
111 int flags;
112};
113#define F_NBR_GTSM_NEGOTIATED 0x01
114
115RB_HEAD(nbr_id_head, nbr);
116RB_PROTOTYPE(nbr_id_head, nbr, id_tree, nbr_id_compare)
117RB_HEAD(nbr_addr_head, nbr);
118RB_PROTOTYPE(nbr_addr_head, nbr, addr_tree, nbr_addr_compare)
119RB_HEAD(nbr_pid_head, nbr);
120RB_PROTOTYPE(nbr_pid_head, nbr, pid_tree, nbr_pid_compare)
121
122struct pending_conn {
123 TAILQ_ENTRY(pending_conn) entry;
124 int fd;
125 int af;
126 union ldpd_addr addr;
eac6e3f0 127 struct thread *ev_timeout;
8429abe0
RW
128};
129#define PENDING_CONN_TIMEOUT 5
130
131struct mapping_entry {
132 TAILQ_ENTRY(mapping_entry) entry;
133 struct map map;
134};
135
136struct ldpd_sysdep {
137 uint8_t no_pfkey;
138 uint8_t no_md5sig;
139};
140
141extern struct ldpd_conf *leconf;
142extern struct ldpd_sysdep sysdep;
143extern struct nbr_id_head nbrs_by_id;
144extern struct nbr_addr_head nbrs_by_addr;
145extern struct nbr_pid_head nbrs_by_pid;
146
147/* accept.c */
148void accept_init(void);
eac6e3f0 149int accept_add(int, int (*)(struct thread *), void *);
8429abe0
RW
150void accept_del(int);
151void accept_pause(void);
152void accept_unpause(void);
153
154/* hello.c */
155int send_hello(enum hello_type, struct iface_af *, struct tnbr *);
156void recv_hello(struct in_addr, struct ldp_msg *, int, union ldpd_addr *,
157 struct iface *, int, char *, uint16_t);
158
159/* init.c */
160void send_init(struct nbr *);
161int recv_init(struct nbr *, char *, uint16_t);
162
163/* keepalive.c */
164void send_keepalive(struct nbr *);
165int recv_keepalive(struct nbr *, char *, uint16_t);
166
167/* notification.c */
168void send_notification_full(struct tcp_conn *, struct notify_msg *);
169void send_notification(uint32_t, struct tcp_conn *, uint32_t,
170 uint16_t);
171void send_notification_nbr(struct nbr *, uint32_t, uint32_t, uint16_t);
172int recv_notification(struct nbr *, char *, uint16_t);
173int gen_status_tlv(struct ibuf *, uint32_t, uint32_t, uint16_t);
174
175/* address.c */
176void send_address_single(struct nbr *, struct if_addr *, int);
177void send_address_all(struct nbr *, int);
178int recv_address(struct nbr *, char *, uint16_t);
179
180/* labelmapping.c */
181#define PREFIX_SIZE(x) (((x) + 7) / 8)
182void send_labelmessage(struct nbr *, uint16_t, struct mapping_head *);
183int recv_labelmessage(struct nbr *, char *, uint16_t, uint16_t);
184int gen_pw_status_tlv(struct ibuf *, uint32_t);
185int gen_fec_tlv(struct ibuf *, struct map *);
186int tlv_decode_fec_elm(struct nbr *, struct ldp_msg *, char *,
187 uint16_t, struct map *);
188
189/* ldpe.c */
eac6e3f0 190void ldpe(const char *, const char *);
8429abe0
RW
191int ldpe_imsg_compose_parent(int, pid_t, void *,
192 uint16_t);
193int ldpe_imsg_compose_lde(int, uint32_t, pid_t, void *,
194 uint16_t);
195void ldpe_reset_nbrs(int);
196void ldpe_reset_ds_nbrs(void);
197void ldpe_remove_dynamic_tnbrs(int);
198void ldpe_stop_init_backoff(int);
199struct ctl_conn;
200void ldpe_iface_ctl(struct ctl_conn *, unsigned int);
201void ldpe_adj_ctl(struct ctl_conn *);
202void ldpe_nbr_ctl(struct ctl_conn *);
203void mapping_list_add(struct mapping_head *, struct map *);
204void mapping_list_clr(struct mapping_head *);
205
206/* interface.c */
207struct iface *if_new(struct kif *);
208void if_exit(struct iface *);
209struct iface *if_lookup(struct ldpd_conf *, unsigned short);
eac6e3f0
RW
210struct iface *if_lookup_name(struct ldpd_conf *, const char *);
211void if_update_info(struct iface *, struct kif *);
8429abe0
RW
212struct iface_af *iface_af_get(struct iface *, int);
213void if_addr_add(struct kaddr *);
214void if_addr_del(struct kaddr *);
215void if_update(struct iface *, int);
216void if_update_all(int);
eac6e3f0
RW
217uint16_t if_get_hello_holdtime(struct iface_af *);
218uint16_t if_get_hello_interval(struct iface_af *);
8429abe0
RW
219struct ctl_iface *if_to_ctl(struct iface_af *);
220in_addr_t if_get_ipv4_addr(struct iface *);
221
222/* adjacency.c */
223struct adj *adj_new(struct in_addr, struct hello_source *,
224 union ldpd_addr *);
225void adj_del(struct adj *, uint32_t);
226struct adj *adj_find(struct hello_source *);
227int adj_get_af(struct adj *adj);
228void adj_start_itimer(struct adj *);
229void adj_stop_itimer(struct adj *);
eac6e3f0 230struct tnbr *tnbr_new(int, union ldpd_addr *);
8429abe0 231struct tnbr *tnbr_find(struct ldpd_conf *, int, union ldpd_addr *);
7989cdba 232struct tnbr *tnbr_check(struct ldpd_conf *, struct tnbr *);
8429abe0
RW
233void tnbr_update(struct tnbr *);
234void tnbr_update_all(int);
eac6e3f0
RW
235uint16_t tnbr_get_hello_holdtime(struct tnbr *);
236uint16_t tnbr_get_hello_interval(struct tnbr *);
8429abe0
RW
237struct ctl_adj *adj_to_ctl(struct adj *);
238
239/* neighbor.c */
240int nbr_fsm(struct nbr *, enum nbr_event);
241struct nbr *nbr_new(struct in_addr, int, int, union ldpd_addr *,
242 uint32_t);
243void nbr_del(struct nbr *);
244struct nbr *nbr_find_ldpid(uint32_t);
245struct nbr *nbr_find_addr(int, union ldpd_addr *);
246struct nbr *nbr_find_peerid(uint32_t);
247int nbr_adj_count(struct nbr *, int);
248int nbr_session_active_role(struct nbr *);
249void nbr_stop_ktimer(struct nbr *);
250void nbr_stop_ktimeout(struct nbr *);
251void nbr_stop_itimeout(struct nbr *);
252void nbr_start_idtimer(struct nbr *);
253void nbr_stop_idtimer(struct nbr *);
254int nbr_pending_idtimer(struct nbr *);
255int nbr_pending_connect(struct nbr *);
256int nbr_establish_connection(struct nbr *);
257int nbr_gtsm_enabled(struct nbr *, struct nbr_params *);
258int nbr_gtsm_setup(int, int, struct nbr_params *);
259int nbr_gtsm_check(int, struct nbr *, struct nbr_params *);
260struct nbr_params *nbr_params_new(struct in_addr);
261struct nbr_params *nbr_params_find(struct ldpd_conf *, struct in_addr);
262uint16_t nbr_get_keepalive(int, struct in_addr);
263struct ctl_nbr *nbr_to_ctl(struct nbr *);
264void nbr_clear_ctl(struct ctl_nbr *);
265
266/* packet.c */
267int gen_ldp_hdr(struct ibuf *, uint16_t);
268int gen_msg_hdr(struct ibuf *, uint16_t, uint16_t);
269int send_packet(int, int, union ldpd_addr *,
270 struct iface_af *, void *, size_t);
eac6e3f0
RW
271int disc_recv_packet(struct thread *);
272int session_accept(struct thread *);
8429abe0
RW
273void session_accept_nbr(struct nbr *, int);
274void session_shutdown(struct nbr *, uint32_t, uint32_t,
275 uint32_t);
276void session_close(struct nbr *);
277struct tcp_conn *tcp_new(int, struct nbr *);
278void pending_conn_del(struct pending_conn *);
279struct pending_conn *pending_conn_find(int, union ldpd_addr *);
280
281char *pkt_ptr; /* packet buffer */
282
283/* pfkey.c */
eac6e3f0 284#ifdef __OpenBSD__
8429abe0
RW
285int pfkey_read(int, struct sadb_msg *);
286int pfkey_establish(struct nbr *, struct nbr_params *);
287int pfkey_remove(struct nbr *);
288int pfkey_init(void);
eac6e3f0 289#endif
8429abe0
RW
290
291/* l2vpn.c */
292void ldpe_l2vpn_init(struct l2vpn *);
293void ldpe_l2vpn_exit(struct l2vpn *);
294void ldpe_l2vpn_pw_init(struct l2vpn_pw *);
295void ldpe_l2vpn_pw_exit(struct l2vpn_pw *);
296
297#endif /* _LDPE_H_ */