]> git.proxmox.com Git - mirror_frr.git/blob - ldpd/ldpe.h
ldpd: implement RFC 5918 (Typed Wildcard FEC)
[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 "openbsd-queue.h"
25 #include "openbsd-tree.h"
26 #ifdef __OpenBSD__
27 #include <net/pfkeyv2.h>
28 #endif
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
35 /* forward declarations */
36 TAILQ_HEAD(mapping_head, mapping_entry);
37
38 struct 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
47 struct adj {
48 RB_ENTRY(adj) global_entry, nbr_entry, ia_entry;
49 struct in_addr lsr_id;
50 struct nbr *nbr;
51 int ds_tlv;
52 struct hello_source source;
53 struct thread *inactivity_timer;
54 uint16_t holdtime;
55 union ldpd_addr trans_addr;
56 };
57 RB_PROTOTYPE(global_adj_head, adj, global_entry, adj_compare)
58 RB_PROTOTYPE(nbr_adj_head, adj, nbr_entry, adj_compare)
59 RB_PROTOTYPE(ia_adj_head, adj, ia_entry, adj_compare)
60
61 struct tcp_conn {
62 struct nbr *nbr;
63 int fd;
64 struct ibuf_read *rbuf;
65 struct evbuf wbuf;
66 struct thread *rev;
67 in_port_t lport;
68 in_port_t rport;
69 };
70
71 struct nbr {
72 RB_ENTRY(nbr) id_tree, addr_tree, pid_tree;
73 struct tcp_conn *tcp;
74 struct nbr_adj_head adj_tree; /* adjacencies */
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;
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 #define F_NBR_CAP_DYNAMIC 0x02
115 #define F_NBR_CAP_TWCARD 0x04
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, int (*)(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 int recv_address(struct nbr *, char *, uint16_t);
183
184 /* labelmapping.c */
185 #define PREFIX_SIZE(x) (((x) + 7) / 8)
186 void send_labelmessage(struct nbr *, uint16_t, struct mapping_head *);
187 int recv_labelmessage(struct nbr *, char *, uint16_t, uint16_t);
188 int gen_pw_status_tlv(struct ibuf *, uint32_t);
189 int gen_fec_tlv(struct ibuf *, struct map *);
190 int tlv_decode_fec_elm(struct nbr *, struct ldp_msg *, char *,
191 uint16_t, struct map *);
192
193 /* ldpe.c */
194 void ldpe(const char *, const char *, const char *);
195 int ldpe_imsg_compose_parent(int, pid_t, void *,
196 uint16_t);
197 int ldpe_imsg_compose_lde(int, uint32_t, pid_t, void *,
198 uint16_t);
199 int ldpe_acl_check(char *, int, union ldpd_addr *, uint8_t);
200 void ldpe_reset_nbrs(int);
201 void ldpe_reset_ds_nbrs(void);
202 void ldpe_remove_dynamic_tnbrs(int);
203 void ldpe_stop_init_backoff(int);
204 struct ctl_conn;
205 void ldpe_iface_ctl(struct ctl_conn *, unsigned int);
206 void ldpe_adj_ctl(struct ctl_conn *);
207 void ldpe_nbr_ctl(struct ctl_conn *);
208 void mapping_list_add(struct mapping_head *, struct map *);
209 void mapping_list_clr(struct mapping_head *);
210
211 /* interface.c */
212 struct iface *if_new(struct kif *);
213 void if_exit(struct iface *);
214 struct iface *if_lookup(struct ldpd_conf *, unsigned short);
215 struct iface *if_lookup_name(struct ldpd_conf *, const char *);
216 void if_update_info(struct iface *, struct kif *);
217 struct iface_af *iface_af_get(struct iface *, int);
218 void if_addr_add(struct kaddr *);
219 void if_addr_del(struct kaddr *);
220 void if_update(struct iface *, int);
221 void if_update_all(int);
222 uint16_t if_get_hello_holdtime(struct iface_af *);
223 uint16_t if_get_hello_interval(struct iface_af *);
224 struct ctl_iface *if_to_ctl(struct iface_af *);
225 in_addr_t if_get_ipv4_addr(struct iface *);
226
227 /* adjacency.c */
228 struct adj *adj_new(struct in_addr, struct hello_source *,
229 union ldpd_addr *);
230 void adj_del(struct adj *, uint32_t);
231 struct adj *adj_find(struct hello_source *);
232 int adj_get_af(struct adj *adj);
233 void adj_start_itimer(struct adj *);
234 void adj_stop_itimer(struct adj *);
235 struct tnbr *tnbr_new(int, union ldpd_addr *);
236 struct tnbr *tnbr_find(struct ldpd_conf *, int, union ldpd_addr *);
237 struct tnbr *tnbr_check(struct ldpd_conf *, struct tnbr *);
238 void tnbr_update(struct tnbr *);
239 void tnbr_update_all(int);
240 uint16_t tnbr_get_hello_holdtime(struct tnbr *);
241 uint16_t tnbr_get_hello_interval(struct tnbr *);
242 struct ctl_adj *adj_to_ctl(struct adj *);
243
244 /* neighbor.c */
245 int nbr_fsm(struct nbr *, enum nbr_event);
246 struct nbr *nbr_new(struct in_addr, int, int, union ldpd_addr *,
247 uint32_t);
248 void nbr_del(struct nbr *);
249 struct nbr *nbr_find_ldpid(uint32_t);
250 struct nbr *nbr_find_addr(int, union ldpd_addr *);
251 struct nbr *nbr_find_peerid(uint32_t);
252 int nbr_adj_count(struct nbr *, int);
253 int nbr_session_active_role(struct nbr *);
254 void nbr_stop_ktimer(struct nbr *);
255 void nbr_stop_ktimeout(struct nbr *);
256 void nbr_stop_itimeout(struct nbr *);
257 void nbr_start_idtimer(struct nbr *);
258 void nbr_stop_idtimer(struct nbr *);
259 int nbr_pending_idtimer(struct nbr *);
260 int nbr_pending_connect(struct nbr *);
261 int nbr_establish_connection(struct nbr *);
262 int nbr_gtsm_enabled(struct nbr *, struct nbr_params *);
263 int nbr_gtsm_setup(int, int, struct nbr_params *);
264 int nbr_gtsm_check(int, struct nbr *, struct nbr_params *);
265 struct nbr_params *nbr_params_new(struct in_addr);
266 struct nbr_params *nbr_params_find(struct ldpd_conf *, struct in_addr);
267 uint16_t nbr_get_keepalive(int, struct in_addr);
268 struct ctl_nbr *nbr_to_ctl(struct nbr *);
269 void nbr_clear_ctl(struct ctl_nbr *);
270
271 /* packet.c */
272 int gen_ldp_hdr(struct ibuf *, uint16_t);
273 int gen_msg_hdr(struct ibuf *, uint16_t, uint16_t);
274 int send_packet(int, int, union ldpd_addr *,
275 struct iface_af *, void *, size_t);
276 int disc_recv_packet(struct thread *);
277 int session_accept(struct thread *);
278 void session_accept_nbr(struct nbr *, int);
279 void session_shutdown(struct nbr *, uint32_t, uint32_t,
280 uint32_t);
281 void session_close(struct nbr *);
282 struct tcp_conn *tcp_new(int, struct nbr *);
283 void pending_conn_del(struct pending_conn *);
284 struct pending_conn *pending_conn_find(int, union ldpd_addr *);
285
286 char *pkt_ptr; /* packet buffer */
287
288 /* pfkey.c */
289 #ifdef __OpenBSD__
290 int pfkey_read(int, struct sadb_msg *);
291 int pfkey_establish(struct nbr *, struct nbr_params *);
292 int pfkey_remove(struct nbr *);
293 int pfkey_init(void);
294 #endif
295
296 /* l2vpn.c */
297 void ldpe_l2vpn_init(struct l2vpn *);
298 void ldpe_l2vpn_exit(struct l2vpn *);
299 void ldpe_l2vpn_pw_init(struct l2vpn_pw *);
300 void ldpe_l2vpn_pw_exit(struct l2vpn_pw *);
301
302 #endif /* _LDPE_H_ */