1 // SPDX-License-Identifier: ISC
5 * Copyright (c) 2013, 2016 Renato Westphal <renato@openbsd.org>
6 * Copyright (c) 2009 Michele Marchetto <michele@openbsd.org>
7 * Copyright (c) 2004, 2005, 2008 Esben Norby <norby@openbsd.org>
14 #include "openbsd-tree.h"
16 #include <net/pfkeyv2.h>
20 #include "lib/ldp_sync.h"
22 /* forward declarations */
23 TAILQ_HEAD(mapping_head
, mapping_entry
);
29 union ldpd_addr src_addr
;
35 RB_ENTRY(adj
) global_entry
, nbr_entry
, ia_entry
;
36 struct in_addr lsr_id
;
39 struct hello_source source
;
40 struct event
*inactivity_timer
;
42 union ldpd_addr trans_addr
;
44 RB_PROTOTYPE(global_adj_head
, adj
, global_entry
, adj_compare
)
45 RB_PROTOTYPE(nbr_adj_head
, adj
, nbr_entry
, adj_compare
)
46 RB_PROTOTYPE(ia_adj_head
, adj
, ia_entry
, adj_compare
)
51 struct ibuf_read
*rbuf
;
59 RB_ENTRY(nbr
) id_tree
, addr_tree
, pid_tree
;
61 struct nbr_adj_head adj_tree
; /* adjacencies */
62 struct event
*ev_connect
;
63 struct event
*keepalive_timer
;
64 struct event
*keepalive_timeout
;
65 struct event
*init_timeout
;
66 struct event
*initdelay_timer
;
68 struct mapping_head mapping_list
;
69 struct mapping_head withdraw_list
;
70 struct mapping_head request_list
;
71 struct mapping_head release_list
;
72 struct mapping_head abortreq_list
;
74 uint32_t peerid
; /* unique ID in DB */
77 int v4_enabled
; /* announce/process v4 msgs */
78 int v6_enabled
; /* announce/process v6 msgs */
79 struct in_addr id
; /* lsr id */
80 union ldpd_addr laddr
; /* local address */
81 union ldpd_addr raddr
; /* remote address */
82 ifindex_t raddr_scope
; /* remote address scope (v6) */
90 struct ldp_stats stats
;
96 enum auth_method method
;
97 char md5key
[TCP_MD5_KEY_LEN
];
101 #define F_NBR_GTSM_NEGOTIATED 0x01
102 #define F_NBR_CAP_DYNAMIC 0x02
103 #define F_NBR_CAP_TWCARD 0x04
104 #define F_NBR_CAP_UNOTIF 0x08
106 RB_HEAD(nbr_id_head
, nbr
);
107 RB_PROTOTYPE(nbr_id_head
, nbr
, id_tree
, nbr_id_compare
)
108 RB_HEAD(nbr_addr_head
, nbr
);
109 RB_PROTOTYPE(nbr_addr_head
, nbr
, addr_tree
, nbr_addr_compare
)
110 RB_HEAD(nbr_pid_head
, nbr
);
111 RB_PROTOTYPE(nbr_pid_head
, nbr
, pid_tree
, nbr_pid_compare
)
113 struct pending_conn
{
114 TAILQ_ENTRY(pending_conn
) entry
;
117 union ldpd_addr addr
;
118 struct event
*ev_timeout
;
120 #define PENDING_CONN_TIMEOUT 5
122 struct mapping_entry
{
123 TAILQ_ENTRY(mapping_entry
) entry
;
132 extern struct ldpd_conf
*leconf
;
133 extern struct ldpd_sysdep sysdep
;
134 extern struct nbr_id_head nbrs_by_id
;
135 extern struct nbr_addr_head nbrs_by_addr
;
136 extern struct nbr_pid_head nbrs_by_pid
;
139 void accept_init(void);
140 int accept_add(int, void (*)(struct event
*), void *);
141 void accept_del(int);
142 void accept_pause(void);
143 void accept_unpause(void);
146 int send_hello(enum hello_type
, struct iface_af
*, struct tnbr
*);
147 void recv_hello(struct in_addr
, struct ldp_msg
*, int, union ldpd_addr
*,
148 struct iface
*, int, char *, uint16_t);
151 void send_init(struct nbr
*);
152 int recv_init(struct nbr
*, char *, uint16_t);
153 void send_capability(struct nbr
*, uint16_t, int);
154 int recv_capability(struct nbr
*, char *, uint16_t);
157 void send_keepalive(struct nbr
*);
158 int recv_keepalive(struct nbr
*, char *, uint16_t);
161 void send_notification_full(struct tcp_conn
*, struct notify_msg
*);
162 void send_notification(struct tcp_conn
*, uint32_t, uint32_t, uint16_t);
163 void send_notification_rtlvs(struct nbr
*, uint32_t, uint32_t, uint16_t,
164 uint16_t, uint16_t, char *);
165 int recv_notification(struct nbr
*, char *, uint16_t);
166 int gen_status_tlv(struct ibuf
*, uint32_t, uint32_t, uint16_t);
169 void send_address_single(struct nbr
*, struct if_addr
*, int);
170 void send_address_all(struct nbr
*, int);
171 void send_mac_withdrawal(struct nbr
*, struct map
*, uint8_t *);
172 int recv_address(struct nbr
*, char *, uint16_t);
175 #define PREFIX_SIZE(x) (((x) + 7) / 8)
176 void send_labelmessage(struct nbr
*, uint16_t, struct mapping_head
*);
177 int recv_labelmessage(struct nbr
*, char *, uint16_t, uint16_t);
178 int gen_pw_status_tlv(struct ibuf
*, uint32_t);
179 uint16_t len_fec_tlv(struct map
*);
180 int gen_fec_tlv(struct ibuf
*, struct map
*);
181 int tlv_decode_fec_elm(struct nbr
*, struct ldp_msg
*, char *,
182 uint16_t, struct map
*);
186 void ldpe_init(struct ldpd_init
*);
187 int ldpe_imsg_compose_parent(int, pid_t
, void *,
189 void ldpe_imsg_compose_parent_sync(int, pid_t
, void *, uint16_t);
190 int ldpe_imsg_compose_lde(int, uint32_t, pid_t
, void *,
192 int ldpe_acl_check(char *, int, union ldpd_addr
*, uint8_t);
193 void ldpe_reset_nbrs(int);
194 void ldpe_reset_ds_nbrs(void);
195 void ldpe_remove_dynamic_tnbrs(int);
196 void ldpe_stop_init_backoff(int);
198 void ldpe_iface_ctl(struct ctl_conn
*c
, ifindex_t ifidx
);
199 void ldpe_adj_ctl(struct ctl_conn
*);
200 void ldpe_adj_detail_ctl(struct ctl_conn
*);
201 void ldpe_nbr_ctl(struct ctl_conn
*);
202 void ldpe_ldp_sync_ctl(struct ctl_conn
*);
203 void mapping_list_add(struct mapping_head
*, struct map
*);
204 void mapping_list_clr(struct mapping_head
*);
205 void ldpe_set_config_change_time(void);
208 struct iface
*if_new(const char *);
209 void ldpe_if_init(struct iface
*);
210 void ldpe_if_exit(struct iface
*);
211 struct iface
*if_lookup(struct ldpd_conf
*c
, ifindex_t ifidx
);
212 struct iface
*if_lookup_name(struct ldpd_conf
*, const char *);
213 void if_update_info(struct iface
*, struct kif
*);
214 struct iface_af
*iface_af_get(struct iface
*, int);
215 void if_addr_add(struct kaddr
*);
216 void if_addr_del(struct kaddr
*);
217 void ldp_if_update(struct iface
*, int);
218 void if_update_all(int);
219 uint16_t if_get_hello_holdtime(struct iface_af
*);
220 uint16_t if_get_hello_interval(struct iface_af
*);
221 uint16_t if_get_wait_for_sync_interval(void);
222 struct ctl_iface
*if_to_ctl(struct iface_af
*);
223 in_addr_t
if_get_ipv4_addr(struct iface
*);
224 int ldp_sync_fsm_adj_event(struct adj
*, enum ldp_sync_event
);
225 int ldp_sync_fsm_nbr_event(struct nbr
*, enum ldp_sync_event
);
226 int ldp_sync_fsm_state_req(struct ldp_igp_sync_if_state_req
*);
227 int ldp_sync_fsm(struct iface
*, enum ldp_sync_event
);
228 void ldp_sync_fsm_reset_all(void);
229 const char *ldp_sync_state_name(int);
230 const char *ldp_sync_event_name(int);
231 struct ctl_ldp_sync
*ldp_sync_to_ctl(struct iface
*);
234 struct adj
*adj_new(struct in_addr
, struct hello_source
*,
236 void adj_del(struct adj
*, uint32_t);
237 struct adj
*adj_find(struct in_addr
, struct hello_source
*);
238 int adj_get_af(const struct adj
*adj
);
239 void adj_start_itimer(struct adj
*);
240 void adj_stop_itimer(struct adj
*);
241 struct tnbr
*tnbr_new(int, union ldpd_addr
*);
242 struct tnbr
*tnbr_find(struct ldpd_conf
*, int, union ldpd_addr
*);
243 struct tnbr
*tnbr_check(struct ldpd_conf
*, struct tnbr
*);
244 void tnbr_update(struct tnbr
*);
245 void tnbr_update_all(int);
246 uint16_t tnbr_get_hello_holdtime(struct tnbr
*);
247 uint16_t tnbr_get_hello_interval(struct tnbr
*);
248 struct ctl_adj
*adj_to_ctl(struct adj
*);
251 int nbr_fsm(struct nbr
*, enum nbr_event
);
252 struct nbr
*nbr_new(struct in_addr
, int, int, union ldpd_addr
*,
254 void nbr_del(struct nbr
*);
255 struct nbr
*nbr_find_ldpid(uint32_t);
256 struct nbr
*nbr_get_first_ldpid(void);
257 struct nbr
*nbr_get_next_ldpid(uint32_t);
258 struct nbr
*nbr_find_addr(int, union ldpd_addr
*);
259 struct nbr
*nbr_find_peerid(uint32_t);
260 int nbr_adj_count(struct nbr
*, int);
261 int nbr_session_active_role(struct nbr
*);
262 void nbr_stop_ktimer(struct nbr
*);
263 void nbr_stop_ktimeout(struct nbr
*);
264 void nbr_stop_itimeout(struct nbr
*);
265 void nbr_start_idtimer(struct nbr
*);
266 void nbr_stop_idtimer(struct nbr
*);
267 int nbr_pending_idtimer(struct nbr
*);
268 int nbr_pending_connect(struct nbr
*);
269 int nbr_establish_connection(struct nbr
*);
270 int nbr_gtsm_enabled(struct nbr
*, struct nbr_params
*);
271 int nbr_gtsm_setup(int, int, struct nbr_params
*);
272 int nbr_gtsm_check(int, struct nbr
*, struct nbr_params
*);
273 struct nbr_params
*nbr_params_new(struct in_addr
);
274 struct nbr_params
*nbr_params_find(struct ldpd_conf
*, struct in_addr
);
275 uint16_t nbr_get_keepalive(int, struct in_addr
);
276 struct ctl_nbr
*nbr_to_ctl(struct nbr
*);
277 void nbr_clear_ctl(struct ctl_nbr
*);
280 int gen_ldp_hdr(struct ibuf
*, uint16_t);
281 int gen_msg_hdr(struct ibuf
*, uint16_t, uint16_t);
282 int send_packet(int, int, union ldpd_addr
*,
283 struct iface_af
*, void *, size_t);
284 void disc_recv_packet(struct event
*thread
);
285 void session_accept(struct event
*thread
);
286 void session_accept_nbr(struct nbr
*, int);
287 void session_shutdown(struct nbr
*, uint32_t, uint32_t,
289 void session_close(struct nbr
*);
290 struct tcp_conn
*tcp_new(int, struct nbr
*);
291 void pending_conn_del(struct pending_conn
*);
292 struct pending_conn
*pending_conn_find(int, union ldpd_addr
*);
294 extern char *pkt_ptr
; /* packet buffer */
298 int pfkey_read(int, struct sadb_msg
*);
299 int pfkey_establish(struct nbr
*, struct nbr_params
*);
300 int pfkey_remove(struct nbr
*);
301 int pfkey_init(void);
305 void ldpe_l2vpn_init(struct l2vpn
*);
306 void ldpe_l2vpn_exit(struct l2vpn
*);
307 void ldpe_l2vpn_pw_init(struct l2vpn_pw
*);
308 void ldpe_l2vpn_pw_exit(struct l2vpn_pw
*);
310 DECLARE_HOOK(ldp_nbr_state_change
, (struct nbr
* nbr
, int old_state
),
313 #endif /* _LDPE_H_ */