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