]> git.proxmox.com Git - mirror_frr.git/blob - ldpd/ldp_zebra.c
Merge pull request #13118 from opensourcerouting/fix/password_xfer_config
[mirror_frr.git] / ldpd / ldp_zebra.c
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3 * Copyright (C) 2016 by Open Source Routing.
4 */
5
6 #include <zebra.h>
7
8 #include "prefix.h"
9 #include "stream.h"
10 #include "memory.h"
11 #include "zclient.h"
12 #include "command.h"
13 #include "network.h"
14 #include "linklist.h"
15 #include "mpls.h"
16
17 #include "ldpd.h"
18 #include "ldpe.h"
19 #include "lde.h"
20 #include "ldp_sync.h"
21 #include "log.h"
22 #include "ldp_debug.h"
23
24 static void ifp2kif(struct interface *, struct kif *);
25 static void ifc2kaddr(struct interface *, struct connected *,
26 struct kaddr *);
27 static int ldp_zebra_send_mpls_labels(int, struct kroute *);
28 static int ldp_router_id_update(ZAPI_CALLBACK_ARGS);
29 static int ldp_interface_address_add(ZAPI_CALLBACK_ARGS);
30 static int ldp_interface_address_delete(ZAPI_CALLBACK_ARGS);
31 static int ldp_zebra_read_route(ZAPI_CALLBACK_ARGS);
32 static int ldp_zebra_read_pw_status_update(ZAPI_CALLBACK_ARGS);
33 static void ldp_zebra_connected(struct zclient *);
34 static void ldp_zebra_filter_update(struct access_list *access);
35
36 static void ldp_zebra_opaque_register(void);
37 static void ldp_zebra_opaque_unregister(void);
38 static int ldp_sync_zebra_send_announce(void);
39 static int ldp_zebra_opaque_msg_handler(ZAPI_CALLBACK_ARGS);
40 static void ldp_sync_zebra_init(void);
41
42 static struct zclient *zclient;
43 static bool zebra_registered = false;
44
45 static void
46 ifp2kif(struct interface *ifp, struct kif *kif)
47 {
48 memset(kif, 0, sizeof(*kif));
49 strlcpy(kif->ifname, ifp->name, sizeof(kif->ifname));
50 kif->ifindex = ifp->ifindex;
51 kif->operative = if_is_operative(ifp);
52 if (ifp->ll_type == ZEBRA_LLT_ETHER)
53 memcpy(kif->mac, ifp->hw_addr, ETH_ALEN);
54 }
55
56 static void
57 ifc2kaddr(struct interface *ifp, struct connected *ifc, struct kaddr *ka)
58 {
59 memset(ka, 0, sizeof(*ka));
60 strlcpy(ka->ifname, ifp->name, sizeof(ka->ifname));
61 ka->ifindex = ifp->ifindex;
62 ka->af = ifc->address->family;
63 ka->prefixlen = ifc->address->prefixlen;
64
65 switch (ka->af) {
66 case AF_INET:
67 ka->addr.v4 = ifc->address->u.prefix4;
68 if (ifc->destination)
69 ka->dstbrd.v4 = ifc->destination->u.prefix4;
70 break;
71 case AF_INET6:
72 ka->addr.v6 = ifc->address->u.prefix6;
73 if (ifc->destination)
74 ka->dstbrd.v6 = ifc->destination->u.prefix6;
75 break;
76 default:
77 break;
78 }
79 }
80
81 void
82 pw2zpw(struct l2vpn_pw *pw, struct zapi_pw *zpw)
83 {
84 memset(zpw, 0, sizeof(*zpw));
85 strlcpy(zpw->ifname, pw->ifname, sizeof(zpw->ifname));
86 zpw->ifindex = pw->ifindex;
87 zpw->type = pw->l2vpn->pw_type;
88 zpw->af = pw->af;
89 zpw->nexthop.ipv6 = pw->addr.v6;
90 zpw->local_label = NO_LABEL;
91 zpw->remote_label = NO_LABEL;
92 if (pw->flags & F_PW_CWORD)
93 zpw->flags = F_PSEUDOWIRE_CWORD;
94 zpw->data.ldp.lsr_id = pw->lsr_id;
95 zpw->data.ldp.pwid = pw->pwid;
96 strlcpy(zpw->data.ldp.vpn_name, pw->l2vpn->name,
97 sizeof(zpw->data.ldp.vpn_name));
98 }
99
100 static void
101 ldp_zebra_opaque_register(void)
102 {
103 zclient_register_opaque(zclient, LDP_IGP_SYNC_IF_STATE_REQUEST);
104 zclient_register_opaque(zclient, LDP_RLFA_REGISTER);
105 zclient_register_opaque(zclient, LDP_RLFA_UNREGISTER_ALL);
106 }
107
108 static void
109 ldp_zebra_opaque_unregister(void)
110 {
111 zclient_unregister_opaque(zclient, LDP_IGP_SYNC_IF_STATE_REQUEST);
112 zclient_unregister_opaque(zclient, LDP_RLFA_REGISTER);
113 zclient_unregister_opaque(zclient, LDP_RLFA_UNREGISTER_ALL);
114 }
115
116 int
117 ldp_sync_zebra_send_state_update(struct ldp_igp_sync_if_state *state)
118 {
119 if (zclient_send_opaque(zclient, LDP_IGP_SYNC_IF_STATE_UPDATE,
120 (const uint8_t *)state, sizeof(*state))
121 == ZCLIENT_SEND_FAILURE)
122 return -1;
123 else
124 return 0;
125 }
126
127 static int
128 ldp_sync_zebra_send_announce(void)
129 {
130 struct ldp_igp_sync_announce announce;
131 announce.proto = ZEBRA_ROUTE_LDP;
132
133 if (zclient_send_opaque(zclient, LDP_IGP_SYNC_ANNOUNCE_UPDATE,
134 (const uint8_t *)&announce, sizeof(announce))
135 == ZCLIENT_SEND_FAILURE)
136 return -1;
137 else
138 return 0;
139 }
140
141 int ldp_zebra_send_rlfa_labels(struct zapi_rlfa_response *rlfa_labels)
142 {
143 int ret;
144
145 ret = zclient_send_opaque(zclient, LDP_RLFA_LABELS,
146 (const uint8_t *)rlfa_labels,
147 sizeof(*rlfa_labels));
148 if (ret == ZCLIENT_SEND_FAILURE) {
149 log_warn("failed to send RLFA labels to IGP");
150 return -1;
151 }
152
153 return 0;
154 }
155
156 static int
157 ldp_zebra_opaque_msg_handler(ZAPI_CALLBACK_ARGS)
158 {
159 struct stream *s;
160 struct zapi_opaque_msg info;
161 struct ldp_igp_sync_if_state_req state_req;
162 struct zapi_rlfa_igp igp;
163 struct zapi_rlfa_request rlfa;
164
165 s = zclient->ibuf;
166
167 if (zclient_opaque_decode(s, &info) != 0)
168 return -1;
169
170 switch (info.type) {
171 case LDP_IGP_SYNC_IF_STATE_REQUEST:
172 STREAM_GET(&state_req, s, sizeof(state_req));
173 main_imsg_compose_ldpe(IMSG_LDP_SYNC_IF_STATE_REQUEST, 0, &state_req,
174 sizeof(state_req));
175 break;
176 case LDP_RLFA_REGISTER:
177 STREAM_GET(&rlfa, s, sizeof(rlfa));
178 main_imsg_compose_both(IMSG_RLFA_REG, &rlfa, sizeof(rlfa));
179 break;
180 case LDP_RLFA_UNREGISTER_ALL:
181 STREAM_GET(&igp, s, sizeof(igp));
182 main_imsg_compose_both(IMSG_RLFA_UNREG_ALL, &igp, sizeof(igp));
183 break;
184 default:
185 break;
186 }
187
188 stream_failure:
189 return 0;
190 }
191
192 static void
193 ldp_sync_zebra_init(void)
194 {
195 ldp_sync_zebra_send_announce();
196 }
197
198 static int
199 ldp_zebra_send_mpls_labels(int cmd, struct kroute *kr)
200 {
201 struct zapi_labels zl = {};
202 struct zapi_nexthop *znh;
203
204 if (kr->local_label < MPLS_LABEL_RESERVED_MAX)
205 return (0);
206
207 debug_zebra_out("prefix %s/%u nexthop %s ifindex %u labels %s/%s (%s)",
208 log_addr(kr->af, &kr->prefix), kr->prefixlen,
209 log_addr(kr->af, &kr->nexthop), kr->ifindex,
210 log_label(kr->local_label), log_label(kr->remote_label),
211 (cmd == ZEBRA_MPLS_LABELS_ADD) ? "add" : "delete");
212
213 zl.type = ZEBRA_LSP_LDP;
214 zl.local_label = kr->local_label;
215
216 /* Set prefix. */
217 if (kr->remote_label != NO_LABEL) {
218 SET_FLAG(zl.message, ZAPI_LABELS_FTN);
219 zl.route.prefix.family = kr->af;
220 switch (kr->af) {
221 case AF_INET:
222 zl.route.prefix.u.prefix4 = kr->prefix.v4;
223 break;
224 case AF_INET6:
225 zl.route.prefix.u.prefix6 = kr->prefix.v6;
226 break;
227 default:
228 fatalx("ldp_zebra_send_mpls_labels: unknown af");
229 }
230 zl.route.prefix.prefixlen = kr->prefixlen;
231 zl.route.type = kr->route_type;
232 zl.route.instance = kr->route_instance;
233 }
234
235 /* If allow-broken-lsps is enabled then if an lsp is received with
236 * no remote label, instruct the forwarding plane to pop the top-level
237 * label and forward packets normally. This is a best-effort attempt
238 * to deliver labeled IP packets to their final destination (instead of
239 * dropping them).
240 */
241 if (kr->remote_label == NO_LABEL
242 && !(ldpd_conf->flags & F_LDPD_ALLOW_BROKEN_LSP)
243 && cmd == ZEBRA_MPLS_LABELS_ADD)
244 return 0;
245
246 if (kr->remote_label == NO_LABEL)
247 kr->remote_label = MPLS_LABEL_IMPLICIT_NULL;
248
249 /* Set nexthop. */
250 zl.nexthop_num = 1;
251 znh = &zl.nexthops[0];
252 switch (kr->af) {
253 case AF_INET:
254 znh->gate.ipv4 = kr->nexthop.v4;
255 if (kr->ifindex)
256 znh->type = NEXTHOP_TYPE_IPV4_IFINDEX;
257 else
258 znh->type = NEXTHOP_TYPE_IPV4;
259 break;
260 case AF_INET6:
261 znh->gate.ipv6 = kr->nexthop.v6;
262 if (kr->ifindex)
263 znh->type = NEXTHOP_TYPE_IPV6_IFINDEX;
264 else
265 znh->type = NEXTHOP_TYPE_IPV6;
266 break;
267 default:
268 break;
269 }
270 znh->ifindex = kr->ifindex;
271 znh->label_num = 1;
272 znh->labels[0] = kr->remote_label;
273
274 if (zebra_send_mpls_labels(zclient, cmd, &zl) == ZCLIENT_SEND_FAILURE)
275 return -1;
276
277 return 0;
278 }
279
280 int
281 kr_change(struct kroute *kr)
282 {
283 return (ldp_zebra_send_mpls_labels(ZEBRA_MPLS_LABELS_ADD, kr));
284 }
285
286 int
287 kr_delete(struct kroute *kr)
288 {
289 return (ldp_zebra_send_mpls_labels(ZEBRA_MPLS_LABELS_DELETE, kr));
290 }
291
292 int
293 kmpw_add(struct zapi_pw *zpw)
294 {
295 debug_zebra_out("pseudowire %s nexthop %s (add)",
296 zpw->ifname, log_addr(zpw->af, (union ldpd_addr *)&zpw->nexthop));
297
298 return zebra_send_pw(zclient, ZEBRA_PW_ADD, zpw)
299 == ZCLIENT_SEND_FAILURE;
300 }
301
302 int
303 kmpw_del(struct zapi_pw *zpw)
304 {
305 debug_zebra_out("pseudowire %s nexthop %s (del)",
306 zpw->ifname, log_addr(zpw->af, (union ldpd_addr *)&zpw->nexthop));
307
308 return zebra_send_pw(zclient, ZEBRA_PW_DELETE, zpw)
309 == ZCLIENT_SEND_FAILURE;
310 }
311
312 int
313 kmpw_set(struct zapi_pw *zpw)
314 {
315 debug_zebra_out("pseudowire %s nexthop %s labels %u/%u (set)",
316 zpw->ifname, log_addr(zpw->af, (union ldpd_addr *)&zpw->nexthop),
317 zpw->local_label, zpw->remote_label);
318
319 return zebra_send_pw(zclient, ZEBRA_PW_SET, zpw)
320 == ZCLIENT_SEND_FAILURE;
321 }
322
323 int
324 kmpw_unset(struct zapi_pw *zpw)
325 {
326 debug_zebra_out("pseudowire %s nexthop %s (unset)",
327 zpw->ifname, log_addr(zpw->af, (union ldpd_addr *)&zpw->nexthop));
328
329 return zebra_send_pw(zclient, ZEBRA_PW_UNSET, zpw)
330 == ZCLIENT_SEND_FAILURE;
331 }
332
333 void
334 kif_redistribute(const char *ifname)
335 {
336 struct vrf *vrf = vrf_lookup_by_id(VRF_DEFAULT);
337 struct listnode *cnode;
338 struct interface *ifp;
339 struct connected *ifc;
340 struct kif kif;
341 struct kaddr ka;
342
343 FOR_ALL_INTERFACES (vrf, ifp) {
344 if (ifname && strcmp(ifname, ifp->name) != 0)
345 continue;
346
347 ifp2kif(ifp, &kif);
348 main_imsg_compose_both(IMSG_IFSTATUS, &kif, sizeof(kif));
349
350 for (ALL_LIST_ELEMENTS_RO(ifp->connected, cnode, ifc)) {
351 ifc2kaddr(ifp, ifc, &ka);
352 main_imsg_compose_ldpe(IMSG_NEWADDR, 0, &ka,
353 sizeof(ka));
354 }
355 }
356 }
357
358 static int
359 ldp_router_id_update(ZAPI_CALLBACK_ARGS)
360 {
361 struct prefix router_id;
362
363 zebra_router_id_update_read(zclient->ibuf, &router_id);
364
365 if (bad_addr_v4(router_id.u.prefix4))
366 return (0);
367
368 debug_zebra_in("router-id update %pI4", &router_id.u.prefix4);
369
370 global.rtr_id.s_addr = router_id.u.prefix4.s_addr;
371 main_imsg_compose_ldpe(IMSG_RTRID_UPDATE, 0, &global.rtr_id,
372 sizeof(global.rtr_id));
373
374 return (0);
375 }
376
377 static int
378 ldp_ifp_create(struct interface *ifp)
379 {
380 struct kif kif;
381
382 debug_zebra_in("interface add %s index %d mtu %d", ifp->name,
383 ifp->ifindex, ifp->mtu);
384
385 ifp2kif(ifp, &kif);
386 main_imsg_compose_both(IMSG_IFSTATUS, &kif, sizeof(kif));
387
388 return 0;
389 }
390
391 static int
392 ldp_ifp_destroy(struct interface *ifp)
393 {
394 struct kif kif;
395
396 debug_zebra_in("interface delete %s index %d mtu %d", ifp->name,
397 ifp->ifindex, ifp->mtu);
398
399 ifp2kif(ifp, &kif);
400 main_imsg_compose_both(IMSG_IFSTATUS, &kif, sizeof(kif));
401
402 return (0);
403 }
404
405 static int
406 ldp_interface_status_change(struct interface *ifp)
407 {
408 struct listnode *node;
409 struct connected *ifc;
410 struct kif kif;
411 struct kaddr ka;
412
413 debug_zebra_in("interface %s state update", ifp->name);
414
415 ifp2kif(ifp, &kif);
416 main_imsg_compose_both(IMSG_IFSTATUS, &kif, sizeof(kif));
417
418 if (if_is_operative(ifp)) {
419 for (ALL_LIST_ELEMENTS_RO(ifp->connected, node, ifc)) {
420 ifc2kaddr(ifp, ifc, &ka);
421 main_imsg_compose_ldpe(IMSG_NEWADDR, 0, &ka,
422 sizeof(ka));
423 }
424 } else {
425 for (ALL_LIST_ELEMENTS_RO(ifp->connected, node, ifc)) {
426 ifc2kaddr(ifp, ifc, &ka);
427 main_imsg_compose_ldpe(IMSG_DELADDR, 0, &ka,
428 sizeof(ka));
429 }
430 }
431
432 return (0);
433 }
434
435 static int ldp_ifp_up(struct interface *ifp)
436 {
437 return ldp_interface_status_change(ifp);
438 }
439
440 static int ldp_ifp_down(struct interface *ifp)
441 {
442 return ldp_interface_status_change(ifp);
443 }
444
445 static int
446 ldp_interface_address_add(ZAPI_CALLBACK_ARGS)
447 {
448 struct connected *ifc;
449 struct interface *ifp;
450 struct kaddr ka;
451
452 ifc = zebra_interface_address_read(cmd, zclient->ibuf, vrf_id);
453 if (ifc == NULL)
454 return (0);
455
456 ifp = ifc->ifp;
457 ifc2kaddr(ifp, ifc, &ka);
458
459 /* Filter invalid addresses. */
460 if (bad_addr(ka.af, &ka.addr))
461 return (0);
462
463 debug_zebra_in("address add %s/%u interface %s",
464 log_addr(ka.af, &ka.addr), ka.prefixlen, ifp->name);
465
466 /* notify ldpe about new address */
467 main_imsg_compose_ldpe(IMSG_NEWADDR, 0, &ka, sizeof(ka));
468
469 return (0);
470 }
471
472 static int
473 ldp_interface_address_delete(ZAPI_CALLBACK_ARGS)
474 {
475 struct connected *ifc;
476 struct interface *ifp;
477 struct kaddr ka;
478
479 ifc = zebra_interface_address_read(cmd, zclient->ibuf, vrf_id);
480 if (ifc == NULL)
481 return (0);
482
483 ifp = ifc->ifp;
484 ifc2kaddr(ifp, ifc, &ka);
485 connected_free(&ifc);
486
487 /* Filter invalid addresses. */
488 if (bad_addr(ka.af, &ka.addr))
489 return (0);
490
491 debug_zebra_in("address delete %s/%u interface %s",
492 log_addr(ka.af, &ka.addr), ka.prefixlen, ifp->name);
493
494 /* notify ldpe about removed address */
495 main_imsg_compose_ldpe(IMSG_DELADDR, 0, &ka, sizeof(ka));
496
497 return (0);
498 }
499
500 static int
501 ldp_zebra_read_route(ZAPI_CALLBACK_ARGS)
502 {
503 struct zapi_route api;
504 struct zapi_nexthop *api_nh;
505 struct kroute kr;
506 int i, add = 0;
507
508 if (zapi_route_decode(zclient->ibuf, &api) < 0)
509 return -1;
510
511 /* we completely ignore srcdest routes for now. */
512 if (CHECK_FLAG(api.message, ZAPI_MESSAGE_SRCPFX))
513 return (0);
514
515 memset(&kr, 0, sizeof(kr));
516 kr.af = api.prefix.family;
517 switch (kr.af) {
518 case AF_INET:
519 kr.prefix.v4 = api.prefix.u.prefix4;
520 break;
521 case AF_INET6:
522 kr.prefix.v6 = api.prefix.u.prefix6;
523 break;
524 default:
525 break;
526 }
527 kr.prefixlen = api.prefix.prefixlen;
528 kr.route_type = api.type;
529 kr.route_instance = api.instance;
530
531 switch (api.type) {
532 case ZEBRA_ROUTE_CONNECT:
533 kr.flags |= F_CONNECTED;
534 break;
535 case ZEBRA_ROUTE_BGP:
536 /* LDP should follow the IGP and ignore BGP routes */
537 return (0);
538 default:
539 break;
540 }
541
542 if (bad_addr(kr.af, &kr.prefix) ||
543 (kr.af == AF_INET6 && IN6_IS_SCOPE_EMBED(&kr.prefix.v6)))
544 return (0);
545
546 if (cmd == ZEBRA_REDISTRIBUTE_ROUTE_ADD)
547 add = 1;
548
549 if (api.nexthop_num == 0)
550 debug_zebra_in("route %s %s/%d (%s)", (add) ? "add" : "delete",
551 log_addr(kr.af, &kr.prefix), kr.prefixlen,
552 zebra_route_string(api.type));
553
554 /* loop through all the nexthops */
555 for (i = 0; i < api.nexthop_num; i++) {
556 api_nh = &api.nexthops[i];
557 switch (api_nh->type) {
558 case NEXTHOP_TYPE_IPV4:
559 if (kr.af != AF_INET)
560 continue;
561 kr.nexthop.v4 = api_nh->gate.ipv4;
562 kr.ifindex = 0;
563 break;
564 case NEXTHOP_TYPE_IPV4_IFINDEX:
565 if (kr.af != AF_INET)
566 continue;
567 kr.nexthop.v4 = api_nh->gate.ipv4;
568 kr.ifindex = api_nh->ifindex;
569 break;
570 case NEXTHOP_TYPE_IPV6:
571 if (kr.af != AF_INET6)
572 continue;
573 kr.nexthop.v6 = api_nh->gate.ipv6;
574 kr.ifindex = 0;
575 break;
576 case NEXTHOP_TYPE_IPV6_IFINDEX:
577 if (kr.af != AF_INET6)
578 continue;
579 kr.nexthop.v6 = api_nh->gate.ipv6;
580 kr.ifindex = api_nh->ifindex;
581 break;
582 case NEXTHOP_TYPE_IFINDEX:
583 if (!(kr.flags & F_CONNECTED))
584 continue;
585 break;
586 case NEXTHOP_TYPE_BLACKHOLE:
587 continue;
588 }
589
590 debug_zebra_in("route %s %s/%d nexthop %s ifindex %u (%s)",
591 (add) ? "add" : "delete", log_addr(kr.af, &kr.prefix),
592 kr.prefixlen, log_addr(kr.af, &kr.nexthop), kr.ifindex,
593 zebra_route_string(api.type));
594
595 if (add)
596 main_imsg_compose_lde(IMSG_NETWORK_ADD, 0, &kr,
597 sizeof(kr));
598 }
599
600 main_imsg_compose_lde(IMSG_NETWORK_UPDATE, 0, &kr, sizeof(kr));
601
602 return (0);
603 }
604
605 /*
606 * Receive PW status update from Zebra and send it to LDE process.
607 */
608 static int
609 ldp_zebra_read_pw_status_update(ZAPI_CALLBACK_ARGS)
610 {
611 struct zapi_pw_status zpw;
612
613 zebra_read_pw_status_update(cmd, zclient, length, vrf_id, &zpw);
614
615 debug_zebra_in("pseudowire %s status %s 0x%x", zpw.ifname,
616 (zpw.status == PW_FORWARDING) ? "up" : "down",
617 zpw.status);
618
619 main_imsg_compose_lde(IMSG_PW_UPDATE, 0, &zpw, sizeof(zpw));
620
621 return (0);
622 }
623
624 void ldp_zebra_regdereg_zebra_info(bool want_register)
625 {
626 if (zebra_registered == want_register)
627 return;
628
629 log_debug("%s to receive default VRF information",
630 want_register ? "Register" : "De-register");
631
632 if (want_register) {
633 zclient_send_reg_requests(zclient, VRF_DEFAULT);
634 zebra_redistribute_send(ZEBRA_REDISTRIBUTE_ADD, zclient, AFI_IP,
635 ZEBRA_ROUTE_ALL, 0, VRF_DEFAULT);
636 zebra_redistribute_send(ZEBRA_REDISTRIBUTE_ADD, zclient,
637 AFI_IP6, ZEBRA_ROUTE_ALL, 0,
638 VRF_DEFAULT);
639 } else {
640 zclient_send_dereg_requests(zclient, VRF_DEFAULT);
641 zebra_redistribute_send(ZEBRA_REDISTRIBUTE_DELETE, zclient,
642 AFI_IP, ZEBRA_ROUTE_ALL, 0,
643 VRF_DEFAULT);
644 zebra_redistribute_send(ZEBRA_REDISTRIBUTE_DELETE, zclient,
645 AFI_IP6, ZEBRA_ROUTE_ALL, 0,
646 VRF_DEFAULT);
647 }
648 zebra_registered = want_register;
649 }
650
651 static void
652 ldp_zebra_connected(struct zclient *zclient)
653 {
654 zebra_registered = false;
655
656 /* if MPLS was already enabled and we are re-connecting, register again
657 */
658 if (vty_conf->flags & F_LDPD_ENABLED)
659 ldp_zebra_regdereg_zebra_info(true);
660
661 ldp_zebra_opaque_register();
662
663 ldp_sync_zebra_init();
664 }
665
666 static void
667 ldp_zebra_filter_update(struct access_list *access)
668 {
669 struct ldp_access laccess;
670
671 if (access && access->name[0] != '\0') {
672 strlcpy(laccess.name, access->name, sizeof(laccess.name));
673 debug_evt("%s ACL update filter name %s", __func__,
674 access->name);
675
676 main_imsg_compose_both(IMSG_FILTER_UPDATE, &laccess,
677 sizeof(laccess));
678 }
679 }
680
681 extern struct zebra_privs_t ldpd_privs;
682
683 static zclient_handler *const ldp_handlers[] = {
684 [ZEBRA_ROUTER_ID_UPDATE] = ldp_router_id_update,
685 [ZEBRA_INTERFACE_ADDRESS_ADD] = ldp_interface_address_add,
686 [ZEBRA_INTERFACE_ADDRESS_DELETE] = ldp_interface_address_delete,
687 [ZEBRA_REDISTRIBUTE_ROUTE_ADD] = ldp_zebra_read_route,
688 [ZEBRA_REDISTRIBUTE_ROUTE_DEL] = ldp_zebra_read_route,
689 [ZEBRA_PW_STATUS_UPDATE] = ldp_zebra_read_pw_status_update,
690 [ZEBRA_OPAQUE_MESSAGE] = ldp_zebra_opaque_msg_handler,
691 };
692
693 void ldp_zebra_init(struct event_loop *master)
694 {
695 if_zapi_callbacks(ldp_ifp_create, ldp_ifp_up,
696 ldp_ifp_down, ldp_ifp_destroy);
697
698 /* Set default values. */
699 zclient = zclient_new(master, &zclient_options_default, ldp_handlers,
700 array_size(ldp_handlers));
701 zclient_init(zclient, ZEBRA_ROUTE_LDP, 0, &ldpd_privs);
702
703 /* set callbacks */
704 zclient->zebra_connected = ldp_zebra_connected;
705
706 /* Access list initialize. */
707 access_list_add_hook(ldp_zebra_filter_update);
708 access_list_delete_hook(ldp_zebra_filter_update);
709 }
710
711 void
712 ldp_zebra_destroy(void)
713 {
714 ldp_zebra_opaque_unregister();
715 zclient_stop(zclient);
716 zclient_free(zclient);
717 zclient = NULL;
718 }