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