]>
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" | |
31 | ||
32 | #define min(x,y) ((x) <= (y) ? (x) : (y)) | |
33 | #define max(x,y) ((x) > (y) ? (x) : (y)) | |
34 | ||
057d48bd RW |
35 | /* forward declarations */ |
36 | TAILQ_HEAD(mapping_head, mapping_entry); | |
37 | ||
8429abe0 RW |
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 { | |
057d48bd | 48 | RB_ENTRY(adj) global_entry, nbr_entry, ia_entry; |
8429abe0 RW |
49 | struct in_addr lsr_id; |
50 | struct nbr *nbr; | |
51 | int ds_tlv; | |
52 | struct hello_source source; | |
eac6e3f0 | 53 | struct thread *inactivity_timer; |
8429abe0 RW |
54 | uint16_t holdtime; |
55 | union ldpd_addr trans_addr; | |
56 | }; | |
057d48bd RW |
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) | |
8429abe0 RW |
60 | |
61 | struct tcp_conn { | |
62 | struct nbr *nbr; | |
63 | int fd; | |
64 | struct ibuf_read *rbuf; | |
65 | struct evbuf wbuf; | |
eac6e3f0 RW |
66 | struct thread *rev; |
67 | in_port_t lport; | |
68 | in_port_t rport; | |
8429abe0 RW |
69 | }; |
70 | ||
71 | struct nbr { | |
72 | RB_ENTRY(nbr) id_tree, addr_tree, pid_tree; | |
73 | struct tcp_conn *tcp; | |
057d48bd | 74 | struct nbr_adj_head adj_tree; /* adjacencies */ |
eac6e3f0 RW |
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; | |
8429abe0 RW |
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; | |
0f7b5df9 | 103 | struct ldp_stats stats; |
8429abe0 RW |
104 | |
105 | struct { | |
106 | uint8_t established; | |
107 | uint32_t spi_in; | |
108 | uint32_t spi_out; | |
109 | enum auth_method method; | |
110 | char md5key[TCP_MD5_KEY_LEN]; | |
111 | } auth; | |
112 | int flags; | |
113 | }; | |
114 | #define F_NBR_GTSM_NEGOTIATED 0x01 | |
8819fc38 | 115 | #define F_NBR_CAP_DYNAMIC 0x02 |
d4afb819 | 116 | #define F_NBR_CAP_TWCARD 0x04 |
257799cd | 117 | #define F_NBR_CAP_UNOTIF 0x08 |
8429abe0 RW |
118 | |
119 | RB_HEAD(nbr_id_head, nbr); | |
120 | RB_PROTOTYPE(nbr_id_head, nbr, id_tree, nbr_id_compare) | |
121 | RB_HEAD(nbr_addr_head, nbr); | |
122 | RB_PROTOTYPE(nbr_addr_head, nbr, addr_tree, nbr_addr_compare) | |
123 | RB_HEAD(nbr_pid_head, nbr); | |
124 | RB_PROTOTYPE(nbr_pid_head, nbr, pid_tree, nbr_pid_compare) | |
125 | ||
126 | struct pending_conn { | |
127 | TAILQ_ENTRY(pending_conn) entry; | |
128 | int fd; | |
129 | int af; | |
130 | union ldpd_addr addr; | |
eac6e3f0 | 131 | struct thread *ev_timeout; |
8429abe0 RW |
132 | }; |
133 | #define PENDING_CONN_TIMEOUT 5 | |
134 | ||
135 | struct mapping_entry { | |
136 | TAILQ_ENTRY(mapping_entry) entry; | |
137 | struct map map; | |
138 | }; | |
139 | ||
140 | struct ldpd_sysdep { | |
141 | uint8_t no_pfkey; | |
142 | uint8_t no_md5sig; | |
143 | }; | |
144 | ||
145 | extern struct ldpd_conf *leconf; | |
146 | extern struct ldpd_sysdep sysdep; | |
147 | extern struct nbr_id_head nbrs_by_id; | |
148 | extern struct nbr_addr_head nbrs_by_addr; | |
149 | extern struct nbr_pid_head nbrs_by_pid; | |
150 | ||
151 | /* accept.c */ | |
152 | void accept_init(void); | |
eac6e3f0 | 153 | int accept_add(int, int (*)(struct thread *), void *); |
8429abe0 RW |
154 | void accept_del(int); |
155 | void accept_pause(void); | |
156 | void accept_unpause(void); | |
157 | ||
158 | /* hello.c */ | |
159 | int send_hello(enum hello_type, struct iface_af *, struct tnbr *); | |
160 | void recv_hello(struct in_addr, struct ldp_msg *, int, union ldpd_addr *, | |
161 | struct iface *, int, char *, uint16_t); | |
162 | ||
163 | /* init.c */ | |
164 | void send_init(struct nbr *); | |
165 | int recv_init(struct nbr *, char *, uint16_t); | |
8819fc38 RW |
166 | void send_capability(struct nbr *, uint16_t, int); |
167 | int recv_capability(struct nbr *, char *, uint16_t); | |
8429abe0 RW |
168 | |
169 | /* keepalive.c */ | |
170 | void send_keepalive(struct nbr *); | |
171 | int recv_keepalive(struct nbr *, char *, uint16_t); | |
172 | ||
173 | /* notification.c */ | |
174 | void send_notification_full(struct tcp_conn *, struct notify_msg *); | |
adbdf465 | 175 | void send_notification(struct tcp_conn *, uint32_t, uint32_t, uint16_t); |
8819fc38 RW |
176 | void send_notification_rtlvs(struct nbr *, uint32_t, uint32_t, uint16_t, |
177 | uint16_t, uint16_t, char *); | |
8429abe0 RW |
178 | int recv_notification(struct nbr *, char *, uint16_t); |
179 | int gen_status_tlv(struct ibuf *, uint32_t, uint32_t, uint16_t); | |
180 | ||
181 | /* address.c */ | |
182 | void send_address_single(struct nbr *, struct if_addr *, int); | |
183 | void send_address_all(struct nbr *, int); | |
26519d8c | 184 | void send_mac_withdrawal(struct nbr *, struct map *, uint8_t *); |
8429abe0 RW |
185 | int recv_address(struct nbr *, char *, uint16_t); |
186 | ||
187 | /* labelmapping.c */ | |
188 | #define PREFIX_SIZE(x) (((x) + 7) / 8) | |
189 | void send_labelmessage(struct nbr *, uint16_t, struct mapping_head *); | |
190 | int recv_labelmessage(struct nbr *, char *, uint16_t, uint16_t); | |
191 | int gen_pw_status_tlv(struct ibuf *, uint32_t); | |
257799cd | 192 | uint16_t len_fec_tlv(struct map *); |
8429abe0 RW |
193 | int gen_fec_tlv(struct ibuf *, struct map *); |
194 | int tlv_decode_fec_elm(struct nbr *, struct ldp_msg *, char *, | |
195 | uint16_t, struct map *); | |
196 | ||
197 | /* ldpe.c */ | |
274f5abf RW |
198 | void ldpe(void); |
199 | void ldpe_init(struct ldpd_init *); | |
8429abe0 RW |
200 | int ldpe_imsg_compose_parent(int, pid_t, void *, |
201 | uint16_t); | |
f2232fdf | 202 | void ldpe_imsg_compose_parent_sync(int, pid_t, void *, uint16_t); |
8429abe0 RW |
203 | int ldpe_imsg_compose_lde(int, uint32_t, pid_t, void *, |
204 | uint16_t); | |
45a8eba9 | 205 | int ldpe_acl_check(char *, int, union ldpd_addr *, uint8_t); |
8429abe0 RW |
206 | void ldpe_reset_nbrs(int); |
207 | void ldpe_reset_ds_nbrs(void); | |
208 | void ldpe_remove_dynamic_tnbrs(int); | |
209 | void ldpe_stop_init_backoff(int); | |
210 | struct ctl_conn; | |
211 | void ldpe_iface_ctl(struct ctl_conn *, unsigned int); | |
212 | void ldpe_adj_ctl(struct ctl_conn *); | |
bc0eb287 | 213 | void ldpe_adj_detail_ctl(struct ctl_conn *); |
8429abe0 RW |
214 | void ldpe_nbr_ctl(struct ctl_conn *); |
215 | void mapping_list_add(struct mapping_head *, struct map *); | |
216 | void mapping_list_clr(struct mapping_head *); | |
217 | ||
218 | /* interface.c */ | |
52b530fc | 219 | struct iface *if_new(const char *); |
1d75a89d RW |
220 | void ldpe_if_init(struct iface *); |
221 | void ldpe_if_exit(struct iface *); | |
8429abe0 | 222 | struct iface *if_lookup(struct ldpd_conf *, unsigned short); |
eac6e3f0 RW |
223 | struct iface *if_lookup_name(struct ldpd_conf *, const char *); |
224 | void if_update_info(struct iface *, struct kif *); | |
8429abe0 RW |
225 | struct iface_af *iface_af_get(struct iface *, int); |
226 | void if_addr_add(struct kaddr *); | |
227 | void if_addr_del(struct kaddr *); | |
61cd1100 | 228 | void ldp_if_update(struct iface *, int); |
8429abe0 | 229 | void if_update_all(int); |
eac6e3f0 RW |
230 | uint16_t if_get_hello_holdtime(struct iface_af *); |
231 | uint16_t if_get_hello_interval(struct iface_af *); | |
8429abe0 RW |
232 | struct ctl_iface *if_to_ctl(struct iface_af *); |
233 | in_addr_t if_get_ipv4_addr(struct iface *); | |
234 | ||
235 | /* adjacency.c */ | |
236 | struct adj *adj_new(struct in_addr, struct hello_source *, | |
237 | union ldpd_addr *); | |
238 | void adj_del(struct adj *, uint32_t); | |
f2725627 | 239 | struct adj *adj_find(struct in_addr, struct hello_source *); |
522faa1f | 240 | int adj_get_af(const struct adj *adj); |
8429abe0 RW |
241 | void adj_start_itimer(struct adj *); |
242 | void adj_stop_itimer(struct adj *); | |
eac6e3f0 | 243 | struct tnbr *tnbr_new(int, union ldpd_addr *); |
8429abe0 | 244 | struct tnbr *tnbr_find(struct ldpd_conf *, int, union ldpd_addr *); |
7989cdba | 245 | struct tnbr *tnbr_check(struct ldpd_conf *, struct tnbr *); |
8429abe0 RW |
246 | void tnbr_update(struct tnbr *); |
247 | void tnbr_update_all(int); | |
eac6e3f0 RW |
248 | uint16_t tnbr_get_hello_holdtime(struct tnbr *); |
249 | uint16_t tnbr_get_hello_interval(struct tnbr *); | |
8429abe0 RW |
250 | struct ctl_adj *adj_to_ctl(struct adj *); |
251 | ||
252 | /* neighbor.c */ | |
253 | int nbr_fsm(struct nbr *, enum nbr_event); | |
254 | struct nbr *nbr_new(struct in_addr, int, int, union ldpd_addr *, | |
255 | uint32_t); | |
256 | void nbr_del(struct nbr *); | |
257 | struct nbr *nbr_find_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 *); | |
278 | ||
279 | /* packet.c */ | |
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); | |
eac6e3f0 RW |
284 | int disc_recv_packet(struct thread *); |
285 | int session_accept(struct thread *); | |
8429abe0 RW |
286 | void session_accept_nbr(struct nbr *, int); |
287 | void session_shutdown(struct nbr *, uint32_t, uint32_t, | |
288 | 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 *); | |
293 | ||
294 | char *pkt_ptr; /* packet buffer */ | |
295 | ||
296 | /* pfkey.c */ | |
eac6e3f0 | 297 | #ifdef __OpenBSD__ |
8429abe0 RW |
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); | |
eac6e3f0 | 302 | #endif |
8429abe0 RW |
303 | |
304 | /* l2vpn.c */ | |
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 *); | |
309 | ||
310 | #endif /* _LDPE_H_ */ |