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>
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.
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.
24 #include "openbsd-queue.h"
25 #include "openbsd-tree.h"
27 #include <net/pfkeyv2.h>
32 #define min(x,y) ((x) <= (y) ? (x) : (y))
33 #define max(x,y) ((x) > (y) ? (x) : (y))
35 /* forward declarations */
36 TAILQ_HEAD(mapping_head
, mapping_entry
);
42 union ldpd_addr src_addr
;
48 RB_ENTRY(adj
) global_entry
, nbr_entry
, ia_entry
;
49 struct in_addr lsr_id
;
52 struct hello_source source
;
53 struct thread
*inactivity_timer
;
55 union ldpd_addr trans_addr
;
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
)
64 struct ibuf_read
*rbuf
;
72 RB_ENTRY(nbr
) id_tree
, addr_tree
, pid_tree
;
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
;
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
;
87 uint32_t peerid
; /* unique ID in DB */
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) */
102 uint16_t max_pdu_len
;
108 enum auth_method method
;
109 char md5key
[TCP_MD5_KEY_LEN
];
113 #define F_NBR_GTSM_NEGOTIATED 0x01
115 RB_HEAD(nbr_id_head
, nbr
);
116 RB_PROTOTYPE(nbr_id_head
, nbr
, id_tree
, nbr_id_compare
)
117 RB_HEAD(nbr_addr_head
, nbr
);
118 RB_PROTOTYPE(nbr_addr_head
, nbr
, addr_tree
, nbr_addr_compare
)
119 RB_HEAD(nbr_pid_head
, nbr
);
120 RB_PROTOTYPE(nbr_pid_head
, nbr
, pid_tree
, nbr_pid_compare
)
122 struct pending_conn
{
123 TAILQ_ENTRY(pending_conn
) entry
;
126 union ldpd_addr addr
;
127 struct thread
*ev_timeout
;
129 #define PENDING_CONN_TIMEOUT 5
131 struct mapping_entry
{
132 TAILQ_ENTRY(mapping_entry
) entry
;
141 extern struct ldpd_conf
*leconf
;
142 extern struct ldpd_sysdep sysdep
;
143 extern struct nbr_id_head nbrs_by_id
;
144 extern struct nbr_addr_head nbrs_by_addr
;
145 extern struct nbr_pid_head nbrs_by_pid
;
148 void accept_init(void);
149 int accept_add(int, int (*)(struct thread
*), void *);
150 void accept_del(int);
151 void accept_pause(void);
152 void accept_unpause(void);
155 int send_hello(enum hello_type
, struct iface_af
*, struct tnbr
*);
156 void recv_hello(struct in_addr
, struct ldp_msg
*, int, union ldpd_addr
*,
157 struct iface
*, int, char *, uint16_t);
160 void send_init(struct nbr
*);
161 int recv_init(struct nbr
*, char *, uint16_t);
164 void send_keepalive(struct nbr
*);
165 int recv_keepalive(struct nbr
*, char *, uint16_t);
168 void send_notification_full(struct tcp_conn
*, struct notify_msg
*);
169 void send_notification(uint32_t, struct tcp_conn
*, uint32_t,
171 void send_notification_nbr(struct nbr
*, uint32_t, uint32_t, uint16_t);
172 int recv_notification(struct nbr
*, char *, uint16_t);
173 int gen_status_tlv(struct ibuf
*, uint32_t, uint32_t, uint16_t);
176 void send_address_single(struct nbr
*, struct if_addr
*, int);
177 void send_address_all(struct nbr
*, int);
178 int recv_address(struct nbr
*, char *, uint16_t);
181 #define PREFIX_SIZE(x) (((x) + 7) / 8)
182 void send_labelmessage(struct nbr
*, uint16_t, struct mapping_head
*);
183 int recv_labelmessage(struct nbr
*, char *, uint16_t, uint16_t);
184 int gen_pw_status_tlv(struct ibuf
*, uint32_t);
185 int gen_fec_tlv(struct ibuf
*, struct map
*);
186 int tlv_decode_fec_elm(struct nbr
*, struct ldp_msg
*, char *,
187 uint16_t, struct map
*);
190 void ldpe(const char *, const char *, const char *);
191 int ldpe_imsg_compose_parent(int, pid_t
, void *,
193 int ldpe_imsg_compose_lde(int, uint32_t, pid_t
, void *,
195 int ldpe_acl_check(char *, int, union ldpd_addr
*, uint8_t);
196 void ldpe_reset_nbrs(int);
197 void ldpe_reset_ds_nbrs(void);
198 void ldpe_remove_dynamic_tnbrs(int);
199 void ldpe_stop_init_backoff(int);
201 void ldpe_iface_ctl(struct ctl_conn
*, unsigned int);
202 void ldpe_adj_ctl(struct ctl_conn
*);
203 void ldpe_nbr_ctl(struct ctl_conn
*);
204 void mapping_list_add(struct mapping_head
*, struct map
*);
205 void mapping_list_clr(struct mapping_head
*);
208 struct iface
*if_new(struct kif
*);
209 void if_exit(struct iface
*);
210 struct iface
*if_lookup(struct ldpd_conf
*, unsigned short);
211 struct iface
*if_lookup_name(struct ldpd_conf
*, const char *);
212 void if_update_info(struct iface
*, struct kif
*);
213 struct iface_af
*iface_af_get(struct iface
*, int);
214 void if_addr_add(struct kaddr
*);
215 void if_addr_del(struct kaddr
*);
216 void if_update(struct iface
*, int);
217 void if_update_all(int);
218 uint16_t if_get_hello_holdtime(struct iface_af
*);
219 uint16_t if_get_hello_interval(struct iface_af
*);
220 struct ctl_iface
*if_to_ctl(struct iface_af
*);
221 in_addr_t
if_get_ipv4_addr(struct iface
*);
224 struct adj
*adj_new(struct in_addr
, struct hello_source
*,
226 void adj_del(struct adj
*, uint32_t);
227 struct adj
*adj_find(struct hello_source
*);
228 int adj_get_af(struct adj
*adj
);
229 void adj_start_itimer(struct adj
*);
230 void adj_stop_itimer(struct adj
*);
231 struct tnbr
*tnbr_new(int, union ldpd_addr
*);
232 struct tnbr
*tnbr_find(struct ldpd_conf
*, int, union ldpd_addr
*);
233 struct tnbr
*tnbr_check(struct ldpd_conf
*, struct tnbr
*);
234 void tnbr_update(struct tnbr
*);
235 void tnbr_update_all(int);
236 uint16_t tnbr_get_hello_holdtime(struct tnbr
*);
237 uint16_t tnbr_get_hello_interval(struct tnbr
*);
238 struct ctl_adj
*adj_to_ctl(struct adj
*);
241 int nbr_fsm(struct nbr
*, enum nbr_event
);
242 struct nbr
*nbr_new(struct in_addr
, int, int, union ldpd_addr
*,
244 void nbr_del(struct nbr
*);
245 struct nbr
*nbr_find_ldpid(uint32_t);
246 struct nbr
*nbr_find_addr(int, union ldpd_addr
*);
247 struct nbr
*nbr_find_peerid(uint32_t);
248 int nbr_adj_count(struct nbr
*, int);
249 int nbr_session_active_role(struct nbr
*);
250 void nbr_stop_ktimer(struct nbr
*);
251 void nbr_stop_ktimeout(struct nbr
*);
252 void nbr_stop_itimeout(struct nbr
*);
253 void nbr_start_idtimer(struct nbr
*);
254 void nbr_stop_idtimer(struct nbr
*);
255 int nbr_pending_idtimer(struct nbr
*);
256 int nbr_pending_connect(struct nbr
*);
257 int nbr_establish_connection(struct nbr
*);
258 int nbr_gtsm_enabled(struct nbr
*, struct nbr_params
*);
259 int nbr_gtsm_setup(int, int, struct nbr_params
*);
260 int nbr_gtsm_check(int, struct nbr
*, struct nbr_params
*);
261 struct nbr_params
*nbr_params_new(struct in_addr
);
262 struct nbr_params
*nbr_params_find(struct ldpd_conf
*, struct in_addr
);
263 uint16_t nbr_get_keepalive(int, struct in_addr
);
264 struct ctl_nbr
*nbr_to_ctl(struct nbr
*);
265 void nbr_clear_ctl(struct ctl_nbr
*);
268 int gen_ldp_hdr(struct ibuf
*, uint16_t);
269 int gen_msg_hdr(struct ibuf
*, uint16_t, uint16_t);
270 int send_packet(int, int, union ldpd_addr
*,
271 struct iface_af
*, void *, size_t);
272 int disc_recv_packet(struct thread
*);
273 int session_accept(struct thread
*);
274 void session_accept_nbr(struct nbr
*, int);
275 void session_shutdown(struct nbr
*, uint32_t, uint32_t,
277 void session_close(struct nbr
*);
278 struct tcp_conn
*tcp_new(int, struct nbr
*);
279 void pending_conn_del(struct pending_conn
*);
280 struct pending_conn
*pending_conn_find(int, union ldpd_addr
*);
282 char *pkt_ptr
; /* packet buffer */
286 int pfkey_read(int, struct sadb_msg
*);
287 int pfkey_establish(struct nbr
*, struct nbr_params
*);
288 int pfkey_remove(struct nbr
*);
289 int pfkey_init(void);
293 void ldpe_l2vpn_init(struct l2vpn
*);
294 void ldpe_l2vpn_exit(struct l2vpn
*);
295 void ldpe_l2vpn_pw_init(struct l2vpn_pw
*);
296 void ldpe_l2vpn_pw_exit(struct l2vpn_pw
*);
298 #endif /* _LDPE_H_ */