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