]>
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 Esben Norby <norby@openbsd.org> | |
7 | * Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org> | |
8 | * | |
9 | * Permission to use, copy, modify, and distribute this software for any | |
10 | * purpose with or without fee is hereby granted, provided that the above | |
11 | * copyright notice and this permission notice appear in all copies. | |
12 | * | |
13 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | |
14 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | |
15 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | |
16 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | |
17 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | |
18 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | |
19 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | |
20 | */ | |
21 | ||
22 | #ifndef _LDPD_H_ | |
23 | #define _LDPD_H_ | |
24 | ||
cd85bc2e | 25 | #include "queue.h" |
eac6e3f0 RW |
26 | #include "openbsd-tree.h" |
27 | #include "imsg.h" | |
28 | #include "thread.h" | |
4af8997d | 29 | #include "qobj.h" |
26519d8c | 30 | #include "prefix.h" |
45a8eba9 | 31 | #include "filter.h" |
e4a82008 | 32 | #include "vty.h" |
6833ae01 | 33 | #include "pw.h" |
87b5f1b7 | 34 | #include "zclient.h" |
8429abe0 RW |
35 | |
36 | #include "ldp.h" | |
37 | ||
38 | #define CONF_FILE "/etc/ldpd.conf" | |
8429abe0 RW |
39 | #define LDPD_USER "_ldpd" |
40 | ||
28e8294c RW |
41 | #define LDPD_FD_ASYNC 3 |
42 | #define LDPD_FD_SYNC 4 | |
43 | ||
8429abe0 RW |
44 | #define LDPD_OPT_VERBOSE 0x00000001 |
45 | #define LDPD_OPT_VERBOSE2 0x00000002 | |
46 | #define LDPD_OPT_NOACTION 0x00000004 | |
47 | ||
48 | #define TCP_MD5_KEY_LEN 80 | |
8429abe0 RW |
49 | |
50 | #define RT_BUF_SIZE 16384 | |
51 | #define MAX_RTSOCK_BUF 128 * 1024 | |
52 | #define LDP_BACKLOG 128 | |
53 | ||
54 | #define F_LDPD_INSERTED 0x0001 | |
55 | #define F_CONNECTED 0x0002 | |
56 | #define F_STATIC 0x0004 | |
57 | #define F_DYNAMIC 0x0008 | |
58 | #define F_REJECT 0x0010 | |
59 | #define F_BLACKHOLE 0x0020 | |
60 | #define F_REDISTRIBUTED 0x0040 | |
61 | ||
62 | struct evbuf { | |
eac6e3f0 RW |
63 | struct msgbuf wbuf; |
64 | struct thread *ev; | |
65 | int (*handler)(struct thread *); | |
66 | void *arg; | |
8429abe0 RW |
67 | }; |
68 | ||
69 | struct imsgev { | |
70 | struct imsgbuf ibuf; | |
eac6e3f0 RW |
71 | int (*handler_write)(struct thread *); |
72 | struct thread *ev_write; | |
73 | int (*handler_read)(struct thread *); | |
74 | struct thread *ev_read; | |
8429abe0 RW |
75 | }; |
76 | ||
77 | enum imsg_type { | |
78 | IMSG_NONE, | |
79 | IMSG_CTL_RELOAD, | |
80 | IMSG_CTL_SHOW_INTERFACE, | |
81 | IMSG_CTL_SHOW_DISCOVERY, | |
bc0eb287 | 82 | IMSG_CTL_SHOW_DISCOVERY_DTL, |
eac6e3f0 RW |
83 | IMSG_CTL_SHOW_DISC_IFACE, |
84 | IMSG_CTL_SHOW_DISC_TNBR, | |
85 | IMSG_CTL_SHOW_DISC_ADJ, | |
8429abe0 | 86 | IMSG_CTL_SHOW_NBR, |
eac6e3f0 RW |
87 | IMSG_CTL_SHOW_NBR_DISC, |
88 | IMSG_CTL_SHOW_NBR_END, | |
8429abe0 | 89 | IMSG_CTL_SHOW_LIB, |
0f7b5df9 RW |
90 | IMSG_CTL_SHOW_LIB_BEGIN, |
91 | IMSG_CTL_SHOW_LIB_SENT, | |
92 | IMSG_CTL_SHOW_LIB_RCVD, | |
93 | IMSG_CTL_SHOW_LIB_END, | |
8429abe0 RW |
94 | IMSG_CTL_SHOW_L2VPN_PW, |
95 | IMSG_CTL_SHOW_L2VPN_BINDING, | |
96 | IMSG_CTL_CLEAR_NBR, | |
97 | IMSG_CTL_FIB_COUPLE, | |
98 | IMSG_CTL_FIB_DECOUPLE, | |
99 | IMSG_CTL_KROUTE, | |
100 | IMSG_CTL_KROUTE_ADDR, | |
101 | IMSG_CTL_IFINFO, | |
102 | IMSG_CTL_END, | |
103 | IMSG_CTL_LOG_VERBOSE, | |
104 | IMSG_KLABEL_CHANGE, | |
105 | IMSG_KLABEL_DELETE, | |
87b5f1b7 RW |
106 | IMSG_KPW_ADD, |
107 | IMSG_KPW_DELETE, | |
108 | IMSG_KPW_SET, | |
109 | IMSG_KPW_UNSET, | |
8429abe0 RW |
110 | IMSG_IFSTATUS, |
111 | IMSG_NEWADDR, | |
112 | IMSG_DELADDR, | |
eac6e3f0 | 113 | IMSG_RTRID_UPDATE, |
8429abe0 RW |
114 | IMSG_LABEL_MAPPING, |
115 | IMSG_LABEL_MAPPING_FULL, | |
116 | IMSG_LABEL_REQUEST, | |
117 | IMSG_LABEL_RELEASE, | |
118 | IMSG_LABEL_WITHDRAW, | |
119 | IMSG_LABEL_ABORT, | |
120 | IMSG_REQUEST_ADD, | |
121 | IMSG_REQUEST_ADD_END, | |
122 | IMSG_MAPPING_ADD, | |
123 | IMSG_MAPPING_ADD_END, | |
124 | IMSG_RELEASE_ADD, | |
125 | IMSG_RELEASE_ADD_END, | |
126 | IMSG_WITHDRAW_ADD, | |
127 | IMSG_WITHDRAW_ADD_END, | |
128 | IMSG_ADDRESS_ADD, | |
129 | IMSG_ADDRESS_DEL, | |
130 | IMSG_NOTIFICATION, | |
131 | IMSG_NOTIFICATION_SEND, | |
132 | IMSG_NEIGHBOR_UP, | |
133 | IMSG_NEIGHBOR_DOWN, | |
134 | IMSG_NETWORK_ADD, | |
8cb1fc45 | 135 | IMSG_NETWORK_UPDATE, |
8429abe0 RW |
136 | IMSG_SOCKET_IPC, |
137 | IMSG_SOCKET_NET, | |
138 | IMSG_CLOSE_SOCKETS, | |
139 | IMSG_REQUEST_SOCKETS, | |
140 | IMSG_SETUP_SOCKETS, | |
141 | IMSG_RECONF_CONF, | |
142 | IMSG_RECONF_IFACE, | |
143 | IMSG_RECONF_TNBR, | |
144 | IMSG_RECONF_NBRP, | |
145 | IMSG_RECONF_L2VPN, | |
146 | IMSG_RECONF_L2VPN_IF, | |
147 | IMSG_RECONF_L2VPN_PW, | |
eac6e3f0 RW |
148 | IMSG_RECONF_L2VPN_IPW, |
149 | IMSG_RECONF_END, | |
150 | IMSG_DEBUG_UPDATE, | |
45a8eba9 | 151 | IMSG_LOG, |
274f5abf | 152 | IMSG_ACL_CHECK, |
87b5f1b7 | 153 | IMSG_INIT, |
2d1aa1e8 | 154 | IMSG_PW_UPDATE, |
155 | IMSG_FILTER_UPDATE, | |
156 | IMSG_NBR_SHUTDOWN | |
274f5abf RW |
157 | }; |
158 | ||
159 | struct ldpd_init { | |
160 | char user[256]; | |
161 | char group[256]; | |
162 | char ctl_sock_path[MAXPATHLEN]; | |
163 | char zclient_serv_path[MAXPATHLEN]; | |
d7c0a89a | 164 | unsigned short instance; |
8429abe0 RW |
165 | }; |
166 | ||
2d1aa1e8 | 167 | struct ldp_access { |
168 | char name[ACL_NAMSIZ]; | |
169 | enum access_type type; | |
170 | }; | |
171 | ||
8429abe0 RW |
172 | union ldpd_addr { |
173 | struct in_addr v4; | |
174 | struct in6_addr v6; | |
175 | }; | |
176 | ||
177 | #define IN6_IS_SCOPE_EMBED(a) \ | |
178 | ((IN6_IS_ADDR_LINKLOCAL(a)) || \ | |
179 | (IN6_IS_ADDR_MC_LINKLOCAL(a)) || \ | |
180 | (IN6_IS_ADDR_MC_INTFACELOCAL(a))) | |
181 | ||
182 | /* interface states */ | |
183 | #define IF_STA_DOWN 0x01 | |
184 | #define IF_STA_ACTIVE 0x02 | |
185 | ||
186 | /* targeted neighbor states */ | |
187 | #define TNBR_STA_DOWN 0x01 | |
188 | #define TNBR_STA_ACTIVE 0x02 | |
189 | ||
190 | /* interface types */ | |
191 | enum iface_type { | |
192 | IF_TYPE_POINTOPOINT, | |
193 | IF_TYPE_BROADCAST | |
194 | }; | |
195 | ||
196 | /* neighbor states */ | |
197 | #define NBR_STA_PRESENT 0x0001 | |
198 | #define NBR_STA_INITIAL 0x0002 | |
199 | #define NBR_STA_OPENREC 0x0004 | |
200 | #define NBR_STA_OPENSENT 0x0008 | |
201 | #define NBR_STA_OPER 0x0010 | |
202 | #define NBR_STA_SESSION (NBR_STA_INITIAL | NBR_STA_OPENREC | \ | |
203 | NBR_STA_OPENSENT | NBR_STA_OPER) | |
204 | ||
205 | /* neighbor events */ | |
206 | enum nbr_event { | |
207 | NBR_EVT_NOTHING, | |
208 | NBR_EVT_MATCH_ADJ, | |
209 | NBR_EVT_CONNECT_UP, | |
210 | NBR_EVT_CLOSE_SESSION, | |
211 | NBR_EVT_INIT_RCVD, | |
212 | NBR_EVT_KEEPALIVE_RCVD, | |
213 | NBR_EVT_PDU_RCVD, | |
214 | NBR_EVT_PDU_SENT, | |
215 | NBR_EVT_INIT_SENT | |
216 | }; | |
217 | ||
218 | /* neighbor actions */ | |
219 | enum nbr_action { | |
220 | NBR_ACT_NOTHING, | |
221 | NBR_ACT_RST_KTIMEOUT, | |
222 | NBR_ACT_SESSION_EST, | |
223 | NBR_ACT_RST_KTIMER, | |
224 | NBR_ACT_CONNECT_SETUP, | |
225 | NBR_ACT_PASSIVE_INIT, | |
226 | NBR_ACT_KEEPALIVE_SEND, | |
227 | NBR_ACT_CLOSE_SESSION | |
228 | }; | |
229 | ||
057d48bd RW |
230 | /* forward declarations */ |
231 | RB_HEAD(global_adj_head, adj); | |
232 | RB_HEAD(nbr_adj_head, adj); | |
233 | RB_HEAD(ia_adj_head, adj); | |
8429abe0 RW |
234 | |
235 | struct map { | |
236 | uint8_t type; | |
237 | uint32_t msg_id; | |
238 | union { | |
239 | struct { | |
240 | uint16_t af; | |
241 | union ldpd_addr prefix; | |
242 | uint8_t prefixlen; | |
243 | } prefix; | |
244 | struct { | |
245 | uint16_t type; | |
246 | uint32_t pwid; | |
247 | uint32_t group_id; | |
248 | uint16_t ifmtu; | |
249 | } pwid; | |
d4afb819 RW |
250 | struct { |
251 | uint8_t type; | |
252 | union { | |
253 | uint16_t prefix_af; | |
aba50a83 | 254 | uint16_t pw_type; |
d4afb819 RW |
255 | } u; |
256 | } twcard; | |
8429abe0 RW |
257 | } fec; |
258 | struct { | |
259 | uint32_t status_code; | |
260 | uint32_t msg_id; | |
261 | uint16_t msg_type; | |
262 | } st; | |
263 | uint32_t label; | |
264 | uint32_t requestid; | |
265 | uint32_t pw_status; | |
266 | uint8_t flags; | |
267 | }; | |
268 | #define F_MAP_REQ_ID 0x01 /* optional request message id present */ | |
269 | #define F_MAP_STATUS 0x02 /* status */ | |
270 | #define F_MAP_PW_CWORD 0x04 /* pseudowire control word */ | |
271 | #define F_MAP_PW_ID 0x08 /* pseudowire connection id */ | |
272 | #define F_MAP_PW_IFMTU 0x10 /* pseudowire interface parameter */ | |
273 | #define F_MAP_PW_STATUS 0x20 /* pseudowire status */ | |
274 | ||
275 | struct notify_msg { | |
276 | uint32_t status_code; | |
277 | uint32_t msg_id; /* network byte order */ | |
278 | uint16_t msg_type; /* network byte order */ | |
279 | uint32_t pw_status; | |
280 | struct map fec; | |
8819fc38 RW |
281 | struct { |
282 | uint16_t type; | |
283 | uint16_t length; | |
284 | char *data; | |
285 | } rtlvs; | |
8429abe0 RW |
286 | uint8_t flags; |
287 | }; | |
288 | #define F_NOTIF_PW_STATUS 0x01 /* pseudowire status tlv present */ | |
289 | #define F_NOTIF_FEC 0x02 /* fec tlv present */ | |
8819fc38 | 290 | #define F_NOTIF_RETURNED_TLVS 0x04 /* returned tlvs present */ |
8429abe0 RW |
291 | |
292 | struct if_addr { | |
293 | LIST_ENTRY(if_addr) entry; | |
294 | int af; | |
295 | union ldpd_addr addr; | |
296 | uint8_t prefixlen; | |
297 | union ldpd_addr dstbrd; | |
298 | }; | |
299 | LIST_HEAD(if_addr_head, if_addr); | |
300 | ||
301 | struct iface_af { | |
302 | struct iface *iface; | |
303 | int af; | |
304 | int enabled; | |
305 | int state; | |
057d48bd | 306 | struct ia_adj_head adj_tree; |
8429abe0 | 307 | time_t uptime; |
eac6e3f0 | 308 | struct thread *hello_timer; |
8429abe0 RW |
309 | uint16_t hello_holdtime; |
310 | uint16_t hello_interval; | |
311 | }; | |
312 | ||
313 | struct iface { | |
7d3d7491 | 314 | RB_ENTRY(iface) entry; |
8429abe0 | 315 | char name[IF_NAMESIZE]; |
6cd8093d | 316 | ifindex_t ifindex; |
8429abe0 RW |
317 | struct if_addr_head addr_list; |
318 | struct in6_addr linklocal; | |
319 | enum iface_type type; | |
988ded8d | 320 | int operative; |
8429abe0 RW |
321 | struct iface_af ipv4; |
322 | struct iface_af ipv6; | |
4af8997d | 323 | QOBJ_FIELDS |
8429abe0 | 324 | }; |
7d3d7491 RW |
325 | RB_HEAD(iface_head, iface); |
326 | RB_PROTOTYPE(iface_head, iface, entry, iface_compare); | |
4af8997d | 327 | DECLARE_QOBJ_TYPE(iface) |
8429abe0 RW |
328 | |
329 | /* source of targeted hellos */ | |
330 | struct tnbr { | |
7989cdba | 331 | RB_ENTRY(tnbr) entry; |
eac6e3f0 | 332 | struct thread *hello_timer; |
8429abe0 RW |
333 | struct adj *adj; |
334 | int af; | |
335 | union ldpd_addr addr; | |
336 | int state; | |
8429abe0 RW |
337 | uint16_t pw_count; |
338 | uint8_t flags; | |
4af8997d | 339 | QOBJ_FIELDS |
8429abe0 | 340 | }; |
7989cdba RW |
341 | RB_HEAD(tnbr_head, tnbr); |
342 | RB_PROTOTYPE(tnbr_head, tnbr, entry, tnbr_compare); | |
4af8997d | 343 | DECLARE_QOBJ_TYPE(tnbr) |
8429abe0 RW |
344 | #define F_TNBR_CONFIGURED 0x01 |
345 | #define F_TNBR_DYNAMIC 0x02 | |
346 | ||
347 | enum auth_method { | |
348 | AUTH_NONE, | |
349 | AUTH_MD5SIG | |
350 | }; | |
351 | ||
352 | /* neighbor specific parameters */ | |
353 | struct nbr_params { | |
76c4abd1 | 354 | RB_ENTRY(nbr_params) entry; |
8429abe0 RW |
355 | struct in_addr lsr_id; |
356 | uint16_t keepalive; | |
357 | int gtsm_enabled; | |
358 | uint8_t gtsm_hops; | |
359 | struct { | |
360 | enum auth_method method; | |
361 | char md5key[TCP_MD5_KEY_LEN]; | |
362 | uint8_t md5key_len; | |
363 | } auth; | |
364 | uint8_t flags; | |
4af8997d | 365 | QOBJ_FIELDS |
8429abe0 | 366 | }; |
76c4abd1 RW |
367 | RB_HEAD(nbrp_head, nbr_params); |
368 | RB_PROTOTYPE(nbrp_head, nbr_params, entry, nbr_params_compare); | |
4af8997d | 369 | DECLARE_QOBJ_TYPE(nbr_params) |
8429abe0 RW |
370 | #define F_NBRP_KEEPALIVE 0x01 |
371 | #define F_NBRP_GTSM 0x02 | |
372 | #define F_NBRP_GTSM_HOPS 0x04 | |
373 | ||
0f7b5df9 RW |
374 | struct ldp_stats { |
375 | uint32_t kalive_sent; | |
376 | uint32_t kalive_rcvd; | |
377 | uint32_t addr_sent; | |
378 | uint32_t addr_rcvd; | |
379 | uint32_t addrwdraw_sent; | |
380 | uint32_t addrwdraw_rcvd; | |
381 | uint32_t notif_sent; | |
382 | uint32_t notif_rcvd; | |
383 | uint32_t capability_sent; | |
384 | uint32_t capability_rcvd; | |
385 | uint32_t labelmap_sent; | |
386 | uint32_t labelmap_rcvd; | |
387 | uint32_t labelreq_sent; | |
388 | uint32_t labelreq_rcvd; | |
389 | uint32_t labelwdraw_sent; | |
390 | uint32_t labelwdraw_rcvd; | |
391 | uint32_t labelrel_sent; | |
392 | uint32_t labelrel_rcvd; | |
393 | uint32_t labelabreq_sent; | |
394 | uint32_t labelabreq_rcvd; | |
395 | }; | |
396 | ||
8429abe0 | 397 | struct l2vpn_if { |
029c1958 | 398 | RB_ENTRY(l2vpn_if) entry; |
8429abe0 RW |
399 | struct l2vpn *l2vpn; |
400 | char ifname[IF_NAMESIZE]; | |
6cd8093d | 401 | ifindex_t ifindex; |
988ded8d | 402 | int operative; |
9bff8057 | 403 | uint8_t mac[ETH_ALEN]; |
4af8997d | 404 | QOBJ_FIELDS |
8429abe0 | 405 | }; |
029c1958 RW |
406 | RB_HEAD(l2vpn_if_head, l2vpn_if); |
407 | RB_PROTOTYPE(l2vpn_if_head, l2vpn_if, entry, l2vpn_if_compare); | |
4af8997d | 408 | DECLARE_QOBJ_TYPE(l2vpn_if) |
8429abe0 RW |
409 | |
410 | struct l2vpn_pw { | |
20bacaeb | 411 | RB_ENTRY(l2vpn_pw) entry; |
8429abe0 RW |
412 | struct l2vpn *l2vpn; |
413 | struct in_addr lsr_id; | |
414 | int af; | |
415 | union ldpd_addr addr; | |
416 | uint32_t pwid; | |
417 | char ifname[IF_NAMESIZE]; | |
6cd8093d | 418 | ifindex_t ifindex; |
3c5b5220 | 419 | bool enabled; |
8429abe0 RW |
420 | uint32_t remote_group; |
421 | uint16_t remote_mtu; | |
87b5f1b7 | 422 | uint32_t local_status; |
8429abe0 RW |
423 | uint32_t remote_status; |
424 | uint8_t flags; | |
6bbdd9e9 | 425 | uint8_t reason; |
4af8997d | 426 | QOBJ_FIELDS |
8429abe0 | 427 | }; |
20bacaeb RW |
428 | RB_HEAD(l2vpn_pw_head, l2vpn_pw); |
429 | RB_PROTOTYPE(l2vpn_pw_head, l2vpn_pw, entry, l2vpn_pw_compare); | |
4af8997d | 430 | DECLARE_QOBJ_TYPE(l2vpn_pw) |
8429abe0 RW |
431 | #define F_PW_STATUSTLV_CONF 0x01 /* status tlv configured */ |
432 | #define F_PW_STATUSTLV 0x02 /* status tlv negotiated */ | |
433 | #define F_PW_CWORD_CONF 0x04 /* control word configured */ | |
434 | #define F_PW_CWORD 0x08 /* control word negotiated */ | |
87b5f1b7 | 435 | #define F_PW_STATIC_NBR_ADDR 0x10 /* static neighbor address configured */ |
8429abe0 | 436 | |
6bbdd9e9 | 437 | #define F_PW_NO_ERR 0x00 /* no error reported */ |
438 | #define F_PW_LOCAL_NOT_FWD 0x01 /* locally can't forward over PW */ | |
439 | #define F_PW_REMOTE_NOT_FWD 0x02 /* remote end of PW reported fwd error*/ | |
440 | #define F_PW_NO_REMOTE_LABEL 0x03 /* have not recvd label from peer */ | |
441 | #define F_PW_MTU_MISMATCH 0x04 /* mtu mismatch between peers */ | |
442 | ||
8429abe0 | 443 | struct l2vpn { |
90d7e7bd | 444 | RB_ENTRY(l2vpn) entry; |
8429abe0 RW |
445 | char name[L2VPN_NAME_LEN]; |
446 | int type; | |
447 | int pw_type; | |
448 | int mtu; | |
449 | char br_ifname[IF_NAMESIZE]; | |
6cd8093d | 450 | ifindex_t br_ifindex; |
029c1958 | 451 | struct l2vpn_if_head if_tree; |
20bacaeb RW |
452 | struct l2vpn_pw_head pw_tree; |
453 | struct l2vpn_pw_head pw_inactive_tree; | |
4af8997d | 454 | QOBJ_FIELDS |
8429abe0 | 455 | }; |
90d7e7bd RW |
456 | RB_HEAD(l2vpn_head, l2vpn); |
457 | RB_PROTOTYPE(l2vpn_head, l2vpn, entry, l2vpn_compare); | |
4af8997d | 458 | DECLARE_QOBJ_TYPE(l2vpn) |
8429abe0 RW |
459 | #define L2VPN_TYPE_VPWS 1 |
460 | #define L2VPN_TYPE_VPLS 2 | |
461 | ||
462 | /* ldp_conf */ | |
54ca644b | 463 | extern enum ldpd_process { |
8429abe0 RW |
464 | PROC_MAIN, |
465 | PROC_LDP_ENGINE, | |
466 | PROC_LDE_ENGINE | |
467 | } ldpd_process; | |
468 | ||
fa68f9da RW |
469 | static const char * const log_procnames[] = { |
470 | "parent", | |
471 | "ldpe", | |
472 | "lde" | |
473 | }; | |
474 | ||
8429abe0 RW |
475 | enum socket_type { |
476 | LDP_SOCKET_DISC, | |
477 | LDP_SOCKET_EDISC, | |
478 | LDP_SOCKET_SESSION | |
479 | }; | |
480 | ||
481 | enum hello_type { | |
482 | HELLO_LINK, | |
483 | HELLO_TARGETED | |
484 | }; | |
485 | ||
486 | struct ldpd_af_conf { | |
487 | uint16_t keepalive; | |
eac6e3f0 RW |
488 | uint16_t lhello_holdtime; |
489 | uint16_t lhello_interval; | |
8429abe0 RW |
490 | uint16_t thello_holdtime; |
491 | uint16_t thello_interval; | |
492 | union ldpd_addr trans_addr; | |
45a8eba9 RW |
493 | char acl_thello_accept_from[ACL_NAMSIZ]; |
494 | char acl_label_allocate_for[ACL_NAMSIZ]; | |
495 | char acl_label_advertise_to[ACL_NAMSIZ]; | |
496 | char acl_label_advertise_for[ACL_NAMSIZ]; | |
497 | char acl_label_expnull_for[ACL_NAMSIZ]; | |
498 | char acl_label_accept_from[ACL_NAMSIZ]; | |
499 | char acl_label_accept_for[ACL_NAMSIZ]; | |
8429abe0 RW |
500 | int flags; |
501 | }; | |
502 | #define F_LDPD_AF_ENABLED 0x0001 | |
503 | #define F_LDPD_AF_THELLO_ACCEPT 0x0002 | |
504 | #define F_LDPD_AF_EXPNULL 0x0004 | |
505 | #define F_LDPD_AF_NO_GTSM 0x0008 | |
45a8eba9 | 506 | #define F_LDPD_AF_ALLOCHOSTONLY 0x0010 |
8429abe0 RW |
507 | |
508 | struct ldpd_conf { | |
509 | struct in_addr rtr_id; | |
510 | struct ldpd_af_conf ipv4; | |
511 | struct ldpd_af_conf ipv6; | |
7d3d7491 | 512 | struct iface_head iface_tree; |
7989cdba | 513 | struct tnbr_head tnbr_tree; |
76c4abd1 | 514 | struct nbrp_head nbrp_tree; |
90d7e7bd | 515 | struct l2vpn_head l2vpn_tree; |
eac6e3f0 RW |
516 | uint16_t lhello_holdtime; |
517 | uint16_t lhello_interval; | |
518 | uint16_t thello_holdtime; | |
519 | uint16_t thello_interval; | |
8429abe0 RW |
520 | uint16_t trans_pref; |
521 | int flags; | |
4af8997d | 522 | QOBJ_FIELDS |
8429abe0 | 523 | }; |
4af8997d | 524 | DECLARE_QOBJ_TYPE(ldpd_conf) |
8429abe0 RW |
525 | #define F_LDPD_NO_FIB_UPDATE 0x0001 |
526 | #define F_LDPD_DS_CISCO_INTEROP 0x0002 | |
eac6e3f0 | 527 | #define F_LDPD_ENABLED 0x0004 |
aff1743c KS |
528 | #define F_LDPD_ORDERED_CONTROL 0x0008 |
529 | ||
8429abe0 RW |
530 | |
531 | struct ldpd_af_global { | |
eac6e3f0 RW |
532 | struct thread *disc_ev; |
533 | struct thread *edisc_ev; | |
8429abe0 RW |
534 | int ldp_disc_socket; |
535 | int ldp_edisc_socket; | |
536 | int ldp_session_socket; | |
537 | }; | |
538 | ||
539 | struct ldpd_global { | |
540 | int cmd_opts; | |
eac6e3f0 | 541 | struct in_addr rtr_id; |
8429abe0 RW |
542 | struct ldpd_af_global ipv4; |
543 | struct ldpd_af_global ipv6; | |
544 | uint32_t conf_seqnum; | |
545 | int pfkeysock; | |
546 | struct if_addr_head addr_list; | |
057d48bd | 547 | struct global_adj_head adj_tree; |
8429abe0 RW |
548 | struct in_addr mcast_addr_v4; |
549 | struct in6_addr mcast_addr_v6; | |
550 | TAILQ_HEAD(, pending_conn) pending_conns; | |
551 | }; | |
552 | ||
553 | /* kroute */ | |
554 | struct kroute { | |
555 | int af; | |
556 | union ldpd_addr prefix; | |
557 | uint8_t prefixlen; | |
558 | union ldpd_addr nexthop; | |
559 | uint32_t local_label; | |
560 | uint32_t remote_label; | |
6cd8093d | 561 | ifindex_t ifindex; |
e132dea0 RW |
562 | uint8_t route_type; |
563 | uint8_t route_instance; | |
8429abe0 RW |
564 | uint16_t flags; |
565 | }; | |
566 | ||
8429abe0 | 567 | struct kaddr { |
9cf67225 | 568 | char ifname[IF_NAMESIZE]; |
6cd8093d | 569 | ifindex_t ifindex; |
8429abe0 RW |
570 | int af; |
571 | union ldpd_addr addr; | |
572 | uint8_t prefixlen; | |
573 | union ldpd_addr dstbrd; | |
574 | }; | |
575 | ||
576 | struct kif { | |
577 | char ifname[IF_NAMESIZE]; | |
6cd8093d | 578 | ifindex_t ifindex; |
8429abe0 | 579 | int flags; |
988ded8d | 580 | int operative; |
9bff8057 | 581 | uint8_t mac[ETH_ALEN]; |
8429abe0 | 582 | int mtu; |
8429abe0 RW |
583 | }; |
584 | ||
45a8eba9 RW |
585 | struct acl_check { |
586 | char acl[ACL_NAMSIZ]; | |
587 | int af; | |
588 | union ldpd_addr addr; | |
589 | uint8_t prefixlen; | |
590 | }; | |
591 | ||
8429abe0 RW |
592 | /* control data structures */ |
593 | struct ctl_iface { | |
594 | int af; | |
595 | char name[IF_NAMESIZE]; | |
6cd8093d | 596 | ifindex_t ifindex; |
8429abe0 | 597 | int state; |
8429abe0 | 598 | enum iface_type type; |
8429abe0 RW |
599 | uint16_t hello_holdtime; |
600 | uint16_t hello_interval; | |
601 | time_t uptime; | |
602 | uint16_t adj_cnt; | |
603 | }; | |
604 | ||
eac6e3f0 RW |
605 | struct ctl_disc_if { |
606 | char name[IF_NAMESIZE]; | |
607 | int active_v4; | |
608 | int active_v6; | |
609 | int no_adj; | |
610 | }; | |
611 | ||
612 | struct ctl_disc_tnbr { | |
613 | int af; | |
614 | union ldpd_addr addr; | |
615 | int no_adj; | |
616 | }; | |
617 | ||
8429abe0 RW |
618 | struct ctl_adj { |
619 | int af; | |
620 | struct in_addr id; | |
621 | enum hello_type type; | |
622 | char ifname[IF_NAMESIZE]; | |
623 | union ldpd_addr src_addr; | |
624 | uint16_t holdtime; | |
0f7b5df9 | 625 | uint16_t holdtime_remaining; |
8429abe0 | 626 | union ldpd_addr trans_addr; |
0f7b5df9 | 627 | int ds_tlv; |
8429abe0 RW |
628 | }; |
629 | ||
630 | struct ctl_nbr { | |
631 | int af; | |
632 | struct in_addr id; | |
633 | union ldpd_addr laddr; | |
eac6e3f0 | 634 | in_port_t lport; |
8429abe0 | 635 | union ldpd_addr raddr; |
eac6e3f0 | 636 | in_port_t rport; |
0f7b5df9 | 637 | enum auth_method auth_method; |
eac6e3f0 | 638 | uint16_t holdtime; |
8429abe0 RW |
639 | time_t uptime; |
640 | int nbr_state; | |
0f7b5df9 | 641 | struct ldp_stats stats; |
99cfc17f | 642 | int flags; |
8429abe0 RW |
643 | }; |
644 | ||
645 | struct ctl_rt { | |
646 | int af; | |
647 | union ldpd_addr prefix; | |
648 | uint8_t prefixlen; | |
649 | struct in_addr nexthop; /* lsr-id */ | |
650 | uint32_t local_label; | |
651 | uint32_t remote_label; | |
652 | uint8_t flags; | |
653 | uint8_t in_use; | |
0f7b5df9 | 654 | int no_downstream; |
8429abe0 RW |
655 | }; |
656 | ||
657 | struct ctl_pw { | |
658 | uint16_t type; | |
eac6e3f0 | 659 | char l2vpn_name[L2VPN_NAME_LEN]; |
8429abe0 RW |
660 | char ifname[IF_NAMESIZE]; |
661 | uint32_t pwid; | |
662 | struct in_addr lsr_id; | |
663 | uint32_t local_label; | |
664 | uint32_t local_gid; | |
665 | uint16_t local_ifmtu; | |
eac6e3f0 | 666 | uint8_t local_cword; |
8429abe0 RW |
667 | uint32_t remote_label; |
668 | uint32_t remote_gid; | |
669 | uint16_t remote_ifmtu; | |
eac6e3f0 | 670 | uint8_t remote_cword; |
8429abe0 | 671 | uint32_t status; |
6bbdd9e9 | 672 | uint8_t reason; |
8429abe0 RW |
673 | }; |
674 | ||
56b8a8d2 | 675 | extern struct ldpd_conf *ldpd_conf, *vty_conf; |
8429abe0 | 676 | extern struct ldpd_global global; |
274f5abf | 677 | extern struct ldpd_init init; |
8429abe0 RW |
678 | |
679 | /* parse.y */ | |
680 | struct ldpd_conf *parse_config(char *); | |
681 | int cmdline_symset(char *); | |
682 | ||
683 | /* kroute.c */ | |
87b5f1b7 | 684 | void pw2zpw(struct l2vpn_pw *, struct zapi_pw *); |
8429abe0 RW |
685 | void kif_redistribute(const char *); |
686 | int kr_change(struct kroute *); | |
687 | int kr_delete(struct kroute *); | |
87b5f1b7 RW |
688 | int kmpw_add(struct zapi_pw *); |
689 | int kmpw_del(struct zapi_pw *); | |
690 | int kmpw_set(struct zapi_pw *); | |
691 | int kmpw_unset(struct zapi_pw *); | |
8429abe0 RW |
692 | |
693 | /* util.c */ | |
694 | uint8_t mask2prefixlen(in_addr_t); | |
695 | uint8_t mask2prefixlen6(struct sockaddr_in6 *); | |
696 | in_addr_t prefixlen2mask(uint8_t); | |
697 | struct in6_addr *prefixlen2mask6(uint8_t); | |
698 | void ldp_applymask(int, union ldpd_addr *, | |
699 | const union ldpd_addr *, int); | |
700 | int ldp_addrcmp(int, const union ldpd_addr *, | |
701 | const union ldpd_addr *); | |
702 | int ldp_addrisset(int, const union ldpd_addr *); | |
703 | int ldp_prefixcmp(int, const union ldpd_addr *, | |
704 | const union ldpd_addr *, uint8_t); | |
705 | int bad_addr_v4(struct in_addr); | |
706 | int bad_addr_v6(struct in6_addr *); | |
707 | int bad_addr(int, union ldpd_addr *); | |
708 | void embedscope(struct sockaddr_in6 *); | |
709 | void recoverscope(struct sockaddr_in6 *); | |
710 | void addscope(struct sockaddr_in6 *, uint32_t); | |
711 | void clearscope(struct in6_addr *); | |
4149ef7c A |
712 | void addr2sa(int af, const union ldpd_addr *, uint16_t, |
713 | union sockunion *su); | |
eac6e3f0 RW |
714 | void sa2addr(struct sockaddr *, int *, union ldpd_addr *, |
715 | in_port_t *); | |
716 | socklen_t sockaddr_len(struct sockaddr *); | |
8429abe0 RW |
717 | |
718 | /* ldpd.c */ | |
eac6e3f0 | 719 | int ldp_write_handler(struct thread *); |
8429abe0 RW |
720 | void main_imsg_compose_ldpe(int, pid_t, void *, uint16_t); |
721 | void main_imsg_compose_lde(int, pid_t, void *, uint16_t); | |
eac6e3f0 RW |
722 | int main_imsg_compose_both(enum imsg_type, void *, |
723 | uint16_t); | |
8429abe0 | 724 | void imsg_event_add(struct imsgev *); |
eac6e3f0 RW |
725 | int imsg_compose_event(struct imsgev *, uint16_t, uint32_t, |
726 | pid_t, int, void *, uint16_t); | |
8429abe0 RW |
727 | void evbuf_enqueue(struct evbuf *, struct ibuf *); |
728 | void evbuf_event_add(struct evbuf *); | |
eac6e3f0 RW |
729 | void evbuf_init(struct evbuf *, int, |
730 | int (*)(struct thread *), void *); | |
8429abe0 | 731 | void evbuf_clear(struct evbuf *); |
45a8eba9 RW |
732 | int ldp_acl_request(struct imsgev *, char *, int, |
733 | union ldpd_addr *, uint8_t); | |
734 | void ldp_acl_reply(struct imsgev *, struct acl_check *); | |
8429abe0 RW |
735 | struct ldpd_af_conf *ldp_af_conf_get(struct ldpd_conf *, int); |
736 | struct ldpd_af_global *ldp_af_global_get(struct ldpd_global *, int); | |
737 | int ldp_is_dual_stack(struct ldpd_conf *); | |
eac6e3f0 | 738 | in_addr_t ldp_rtr_id_get(struct ldpd_conf *); |
e4a82008 | 739 | int ldp_config_apply(struct vty *, struct ldpd_conf *); |
eac6e3f0 | 740 | void ldp_clear_config(struct ldpd_conf *); |
8429abe0 RW |
741 | void merge_config(struct ldpd_conf *, struct ldpd_conf *); |
742 | struct ldpd_conf *config_new_empty(void); | |
743 | void config_clear(struct ldpd_conf *); | |
744 | ||
bbee85d2 RW |
745 | /* ldp_vty_conf.c */ |
746 | /* NOTE: the parameters' names should be preserved because of codegen */ | |
7d3d7491 | 747 | struct iface *iface_new_api(struct ldpd_conf *conf, |
bbee85d2 | 748 | const char *name); |
7d3d7491 RW |
749 | void iface_del_api(struct ldpd_conf *conf, |
750 | struct iface *iface); | |
7989cdba | 751 | struct tnbr *tnbr_new_api(struct ldpd_conf *conf, int af, |
bbee85d2 | 752 | union ldpd_addr *addr); |
7989cdba | 753 | void tnbr_del_api(struct ldpd_conf *conf, struct tnbr *tnbr); |
76c4abd1 | 754 | struct nbr_params *nbrp_new_api(struct ldpd_conf *conf, |
bbee85d2 | 755 | struct in_addr lsr_id); |
76c4abd1 RW |
756 | void nbrp_del_api(struct ldpd_conf *conf, |
757 | struct nbr_params *nbrp); | |
90d7e7bd RW |
758 | struct l2vpn *l2vpn_new_api(struct ldpd_conf *conf, const char *name); |
759 | void l2vpn_del_api(struct ldpd_conf *conf, | |
760 | struct l2vpn *l2vpn); | |
bbee85d2 RW |
761 | struct l2vpn_if *l2vpn_if_new_api(struct ldpd_conf *conf, |
762 | struct l2vpn *l2vpn, const char *ifname); | |
029c1958 RW |
763 | void l2vpn_if_del_api(struct l2vpn *l2vpn, |
764 | struct l2vpn_if *lif); | |
bbee85d2 RW |
765 | struct l2vpn_pw *l2vpn_pw_new_api(struct ldpd_conf *conf, |
766 | struct l2vpn *l2vpn, const char *ifname); | |
20bacaeb RW |
767 | void l2vpn_pw_del_api(struct l2vpn *l2vpn, |
768 | struct l2vpn_pw *pw); | |
bbee85d2 | 769 | |
8429abe0 RW |
770 | /* socket.c */ |
771 | int ldp_create_socket(int, enum socket_type); | |
eac6e3f0 RW |
772 | void sock_set_nonblock(int); |
773 | void sock_set_cloexec(int); | |
8429abe0 RW |
774 | void sock_set_recvbuf(int); |
775 | int sock_set_reuse(int, int); | |
776 | int sock_set_bindany(int, int); | |
eac6e3f0 | 777 | int sock_set_md5sig(int, int, union ldpd_addr *, const char *); |
8429abe0 | 778 | int sock_set_ipv4_tos(int, int); |
eac6e3f0 | 779 | int sock_set_ipv4_pktinfo(int, int); |
6cd8093d | 780 | int sock_set_ipv4_recvdstaddr(int fd, ifindex_t ifindex); |
8429abe0 RW |
781 | int sock_set_ipv4_recvif(int, int); |
782 | int sock_set_ipv4_minttl(int, int); | |
783 | int sock_set_ipv4_ucast_ttl(int fd, int); | |
784 | int sock_set_ipv4_mcast_ttl(int, uint8_t); | |
785 | int sock_set_ipv4_mcast(struct iface *); | |
786 | int sock_set_ipv4_mcast_loop(int); | |
787 | int sock_set_ipv6_dscp(int, int); | |
788 | int sock_set_ipv6_pktinfo(int, int); | |
789 | int sock_set_ipv6_minhopcount(int, int); | |
790 | int sock_set_ipv6_ucast_hops(int, int); | |
791 | int sock_set_ipv6_mcast_hops(int, int); | |
792 | int sock_set_ipv6_mcast(struct iface *); | |
793 | int sock_set_ipv6_mcast_loop(int); | |
794 | ||
fa68f9da RW |
795 | /* logmsg.h */ |
796 | struct in6_addr; | |
797 | union ldpd_addr; | |
798 | struct hello_source; | |
799 | struct fec; | |
800 | ||
801 | const char *log_sockaddr(void *); | |
802 | const char *log_in6addr(const struct in6_addr *); | |
6cd8093d DS |
803 | const char *log_in6addr_scope(const struct in6_addr *addr, |
804 | ifindex_t ifidx); | |
fa68f9da RW |
805 | const char *log_addr(int, const union ldpd_addr *); |
806 | char *log_label(uint32_t); | |
807 | const char *log_time(time_t); | |
808 | char *log_hello_src(const struct hello_source *); | |
809 | const char *log_map(const struct map *); | |
810 | const char *log_fec(const struct fec *); | |
811 | const char *af_name(int); | |
812 | const char *socket_name(int); | |
813 | const char *nbr_state_name(int); | |
814 | const char *if_state_name(int); | |
815 | const char *if_type_name(enum iface_type); | |
816 | const char *msg_name(uint16_t); | |
817 | const char *status_code_name(uint32_t); | |
818 | const char *pw_type_name(uint16_t); | |
6bbdd9e9 | 819 | const char *pw_error_code(uint8_t); |
fa68f9da | 820 | |
eac6e3f0 RW |
821 | /* quagga */ |
822 | extern struct thread_master *master; | |
372b8bd3 | 823 | extern char ctl_sock_path[MAXPATHLEN]; |
eac6e3f0 RW |
824 | |
825 | /* ldp_zebra.c */ | |
64dffe25 RW |
826 | void ldp_zebra_init(struct thread_master *); |
827 | void ldp_zebra_destroy(void); | |
eac6e3f0 RW |
828 | |
829 | /* compatibility */ | |
830 | #ifndef __OpenBSD__ | |
831 | #define __IPV6_ADDR_MC_SCOPE(a) ((a)->s6_addr[1] & 0x0f) | |
832 | #define __IPV6_ADDR_SCOPE_INTFACELOCAL 0x01 | |
833 | #define IN6_IS_ADDR_MC_INTFACELOCAL(a) \ | |
834 | (IN6_IS_ADDR_MULTICAST(a) && \ | |
835 | (__IPV6_ADDR_MC_SCOPE(a) == __IPV6_ADDR_SCOPE_INTFACELOCAL)) | |
836 | #endif | |
8429abe0 RW |
837 | |
838 | #endif /* _LDPD_H_ */ |