2 * Zebra dataplane layer.
3 * Copyright (c) 2018 Volta Networks, Inc.
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; see the file COPYING; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24 #include "lib/libfrr.h"
25 #include "lib/debug.h"
26 #include "lib/frratomic.h"
27 #include "lib/frr_pthread.h"
28 #include "lib/memory.h"
29 #include "lib/queue.h"
30 #include "lib/zebra.h"
31 #include "zebra/zebra_router.h"
32 #include "zebra/zebra_memory.h"
33 #include "zebra/zebra_router.h"
34 #include "zebra/zebra_dplane.h"
36 #include "zebra/debug.h"
38 /* Memory type for context blocks */
39 DEFINE_MTYPE_STATIC(ZEBRA
, DP_CTX
, "Zebra DPlane Ctx")
40 DEFINE_MTYPE_STATIC(ZEBRA
, DP_PROV
, "Zebra DPlane Provider")
46 /* Enable test dataplane provider */
47 /*#define DPLANE_TEST_PROVIDER 1 */
49 /* Default value for max queued incoming updates */
50 const uint32_t DPLANE_DEFAULT_MAX_QUEUED
= 200;
52 /* Default value for new work per cycle */
53 const uint32_t DPLANE_DEFAULT_NEW_WORK
= 100;
55 /* Validation check macro for context blocks */
56 /* #define DPLANE_DEBUG 1 */
60 # define DPLANE_CTX_VALID(p) \
65 # define DPLANE_CTX_VALID(p)
67 #endif /* DPLANE_DEBUG */
70 * Nexthop information captured for nexthop/nexthop group updates
72 struct dplane_nexthop_info
{
78 struct nexthop_group ng
;
79 struct nh_grp nh_grp
[MULTIPATH_NUM
];
84 * Route information captured for route updates.
86 struct dplane_route_info
{
88 /* Dest and (optional) source prefixes */
89 struct prefix zd_dest
;
99 route_tag_t zd_old_tag
;
101 uint32_t zd_old_metric
;
103 uint16_t zd_instance
;
104 uint16_t zd_old_instance
;
107 uint8_t zd_old_distance
;
110 uint32_t zd_nexthop_mtu
;
112 /* Nexthop hash entry info */
113 struct dplane_nexthop_info nhe
;
116 struct nexthop_group zd_ng
;
118 /* "Previous" nexthops, used only in route updates without netlink */
119 struct nexthop_group zd_old_ng
;
121 /* TODO -- use fixed array of nexthops, to avoid mallocs? */
126 * Pseudowire info for the dataplane
128 struct dplane_pw_info
{
134 mpls_label_t local_label
;
135 mpls_label_t remote_label
;
138 struct nexthop_group nhg
;
140 union pw_protocol_fields fields
;
144 * Interface/prefix info for the dataplane
146 struct dplane_intf_info
{
151 #define DPLANE_INTF_CONNECTED (1 << 0) /* Connected peer, p2p */
152 #define DPLANE_INTF_SECONDARY (1 << 1)
153 #define DPLANE_INTF_BROADCAST (1 << 2)
154 #define DPLANE_INTF_HAS_DEST DPLANE_INTF_CONNECTED
155 #define DPLANE_INTF_HAS_LABEL (1 << 4)
157 /* Interface address/prefix */
158 struct prefix prefix
;
160 /* Dest address, for p2p, or broadcast prefix */
161 struct prefix dest_prefix
;
168 * EVPN MAC address info for the dataplane.
170 struct dplane_mac_info
{
172 ifindex_t br_ifindex
;
174 struct in_addr vtep_ip
;
180 * EVPN neighbor info for the dataplane
182 struct dplane_neigh_info
{
183 struct ipaddr ip_addr
;
190 * The context block used to exchange info about route updates across
191 * the boundary between the zebra main context (and pthread) and the
192 * dataplane layer (and pthread).
194 struct zebra_dplane_ctx
{
197 enum dplane_op_e zd_op
;
199 /* Status on return */
200 enum zebra_dplane_result zd_status
;
202 /* Dplane provider id */
203 uint32_t zd_provider
;
205 /* Flags - used by providers, e.g. */
213 /* Some updates may be generated by notifications: allow the
214 * plugin to notice and ignore results from its own notifications.
216 uint32_t zd_notif_provider
;
218 /* TODO -- internal/sub-operation status? */
219 enum zebra_dplane_result zd_remote_status
;
220 enum zebra_dplane_result zd_kernel_status
;
223 uint32_t zd_table_id
;
225 char zd_ifname
[INTERFACE_NAMSIZ
];
226 ifindex_t zd_ifindex
;
228 /* Support info for different kinds of updates */
230 struct dplane_route_info rinfo
;
232 struct dplane_pw_info pw
;
233 struct dplane_intf_info intf
;
234 struct dplane_mac_info macinfo
;
235 struct dplane_neigh_info neigh
;
238 /* Namespace info, used especially for netlink kernel communication */
239 struct zebra_dplane_info zd_ns_info
;
241 /* Embedded list linkage */
242 TAILQ_ENTRY(zebra_dplane_ctx
) zd_q_entries
;
245 /* Flag that can be set by a pre-kernel provider as a signal that an update
246 * should bypass the kernel.
248 #define DPLANE_CTX_FLAG_NO_KERNEL 0x01
252 * Registration block for one dataplane provider.
254 struct zebra_dplane_provider
{
256 char dp_name
[DPLANE_PROVIDER_NAMELEN
+ 1];
258 /* Priority, for ordering among providers */
265 pthread_mutex_t dp_mutex
;
267 /* Plugin-provided extra data */
273 int (*dp_start
)(struct zebra_dplane_provider
*prov
);
275 int (*dp_fp
)(struct zebra_dplane_provider
*prov
);
277 int (*dp_fini
)(struct zebra_dplane_provider
*prov
, bool early_p
);
279 _Atomic
uint32_t dp_in_counter
;
280 _Atomic
uint32_t dp_in_queued
;
281 _Atomic
uint32_t dp_in_max
;
282 _Atomic
uint32_t dp_out_counter
;
283 _Atomic
uint32_t dp_out_queued
;
284 _Atomic
uint32_t dp_out_max
;
285 _Atomic
uint32_t dp_error_counter
;
287 /* Queue of contexts inbound to the provider */
288 struct dplane_ctx_q dp_ctx_in_q
;
290 /* Queue of completed contexts outbound from the provider back
291 * towards the dataplane module.
293 struct dplane_ctx_q dp_ctx_out_q
;
295 /* Embedded list linkage for provider objects */
296 TAILQ_ENTRY(zebra_dplane_provider
) dp_prov_link
;
302 static struct zebra_dplane_globals
{
303 /* Mutex to control access to dataplane components */
304 pthread_mutex_t dg_mutex
;
306 /* Results callback registered by zebra 'core' */
307 int (*dg_results_cb
)(struct dplane_ctx_q
*ctxlist
);
309 /* Sentinel for beginning of shutdown */
310 volatile bool dg_is_shutdown
;
312 /* Sentinel for end of shutdown */
313 volatile bool dg_run
;
315 /* Update context queue inbound to the dataplane */
316 TAILQ_HEAD(zdg_ctx_q
, zebra_dplane_ctx
) dg_update_ctx_q
;
318 /* Ordered list of providers */
319 TAILQ_HEAD(zdg_prov_q
, zebra_dplane_provider
) dg_providers_q
;
321 /* Counter used to assign internal ids to providers */
322 uint32_t dg_provider_id
;
324 /* Limit number of pending, unprocessed updates */
325 _Atomic
uint32_t dg_max_queued_updates
;
327 /* Control whether system route notifications should be produced. */
328 bool dg_sys_route_notifs
;
330 /* Limit number of new updates dequeued at once, to pace an
333 uint32_t dg_updates_per_cycle
;
335 _Atomic
uint32_t dg_routes_in
;
336 _Atomic
uint32_t dg_routes_queued
;
337 _Atomic
uint32_t dg_routes_queued_max
;
338 _Atomic
uint32_t dg_route_errors
;
339 _Atomic
uint32_t dg_other_errors
;
341 _Atomic
uint32_t dg_nexthops_in
;
342 _Atomic
uint32_t dg_nexthop_errors
;
344 _Atomic
uint32_t dg_lsps_in
;
345 _Atomic
uint32_t dg_lsp_errors
;
347 _Atomic
uint32_t dg_pws_in
;
348 _Atomic
uint32_t dg_pw_errors
;
350 _Atomic
uint32_t dg_intf_addrs_in
;
351 _Atomic
uint32_t dg_intf_addr_errors
;
353 _Atomic
uint32_t dg_macs_in
;
354 _Atomic
uint32_t dg_mac_errors
;
356 _Atomic
uint32_t dg_neighs_in
;
357 _Atomic
uint32_t dg_neigh_errors
;
359 _Atomic
uint32_t dg_update_yields
;
361 /* Dataplane pthread */
362 struct frr_pthread
*dg_pthread
;
364 /* Event-delivery context 'master' for the dplane */
365 struct thread_master
*dg_master
;
367 /* Event/'thread' pointer for queued updates */
368 struct thread
*dg_t_update
;
370 /* Event pointer for pending shutdown check loop */
371 struct thread
*dg_t_shutdown_check
;
376 * Lock and unlock for interactions with the zebra 'core' pthread
378 #define DPLANE_LOCK() pthread_mutex_lock(&zdplane_info.dg_mutex)
379 #define DPLANE_UNLOCK() pthread_mutex_unlock(&zdplane_info.dg_mutex)
383 * Lock and unlock for individual providers
385 #define DPLANE_PROV_LOCK(p) pthread_mutex_lock(&((p)->dp_mutex))
386 #define DPLANE_PROV_UNLOCK(p) pthread_mutex_unlock(&((p)->dp_mutex))
389 static int dplane_thread_loop(struct thread
*event
);
390 static void dplane_info_from_zns(struct zebra_dplane_info
*ns_info
,
391 struct zebra_ns
*zns
);
392 static enum zebra_dplane_result
lsp_update_internal(zebra_lsp_t
*lsp
,
393 enum dplane_op_e op
);
394 static enum zebra_dplane_result
pw_update_internal(struct zebra_pw
*pw
,
395 enum dplane_op_e op
);
396 static enum zebra_dplane_result
intf_addr_update_internal(
397 const struct interface
*ifp
, const struct connected
*ifc
,
398 enum dplane_op_e op
);
399 static enum zebra_dplane_result
mac_update_internal(
400 enum dplane_op_e op
, const struct interface
*ifp
,
401 const struct interface
*br_ifp
,
402 vlanid_t vid
, const struct ethaddr
*mac
,
403 struct in_addr vtep_ip
, bool sticky
);
404 static enum zebra_dplane_result
neigh_update_internal(
406 const struct interface
*ifp
,
407 const struct ethaddr
*mac
,
408 const struct ipaddr
*ip
,
409 uint32_t flags
, uint16_t state
);
415 /* Obtain thread_master for dataplane thread */
416 struct thread_master
*dplane_get_thread_master(void)
418 return zdplane_info
.dg_master
;
422 * Allocate a dataplane update context
424 struct zebra_dplane_ctx
*dplane_ctx_alloc(void)
426 struct zebra_dplane_ctx
*p
;
428 /* TODO -- just alloc'ing memory, but would like to maintain
431 p
= XCALLOC(MTYPE_DP_CTX
, sizeof(struct zebra_dplane_ctx
));
436 /* Enable system route notifications */
437 void dplane_enable_sys_route_notifs(void)
439 zdplane_info
.dg_sys_route_notifs
= true;
443 * Free a dataplane results context.
445 static void dplane_ctx_free(struct zebra_dplane_ctx
**pctx
)
450 DPLANE_CTX_VALID(*pctx
);
452 /* TODO -- just freeing memory, but would like to maintain
456 /* Some internal allocations may need to be freed, depending on
457 * the type of info captured in the ctx.
459 switch ((*pctx
)->zd_op
) {
460 case DPLANE_OP_ROUTE_INSTALL
:
461 case DPLANE_OP_ROUTE_UPDATE
:
462 case DPLANE_OP_ROUTE_DELETE
:
463 case DPLANE_OP_SYS_ROUTE_ADD
:
464 case DPLANE_OP_SYS_ROUTE_DELETE
:
465 case DPLANE_OP_ROUTE_NOTIFY
:
467 /* Free allocated nexthops */
468 if ((*pctx
)->u
.rinfo
.zd_ng
.nexthop
) {
469 /* This deals with recursive nexthops too */
470 nexthops_free((*pctx
)->u
.rinfo
.zd_ng
.nexthop
);
472 (*pctx
)->u
.rinfo
.zd_ng
.nexthop
= NULL
;
475 if ((*pctx
)->u
.rinfo
.zd_old_ng
.nexthop
) {
476 /* This deals with recursive nexthops too */
477 nexthops_free((*pctx
)->u
.rinfo
.zd_old_ng
.nexthop
);
479 (*pctx
)->u
.rinfo
.zd_old_ng
.nexthop
= NULL
;
484 case DPLANE_OP_NH_INSTALL
:
485 case DPLANE_OP_NH_UPDATE
:
486 case DPLANE_OP_NH_DELETE
: {
487 if ((*pctx
)->u
.rinfo
.nhe
.ng
.nexthop
) {
488 /* This deals with recursive nexthops too */
489 nexthops_free((*pctx
)->u
.rinfo
.nhe
.ng
.nexthop
);
491 (*pctx
)->u
.rinfo
.nhe
.ng
.nexthop
= NULL
;
496 case DPLANE_OP_LSP_INSTALL
:
497 case DPLANE_OP_LSP_UPDATE
:
498 case DPLANE_OP_LSP_DELETE
:
499 case DPLANE_OP_LSP_NOTIFY
:
501 zebra_nhlfe_t
*nhlfe
, *next
;
503 /* Free allocated NHLFEs */
504 for (nhlfe
= (*pctx
)->u
.lsp
.nhlfe_list
; nhlfe
; nhlfe
= next
) {
507 zebra_mpls_nhlfe_del(nhlfe
);
510 /* Clear pointers in lsp struct, in case we're cacheing
511 * free context structs.
513 (*pctx
)->u
.lsp
.nhlfe_list
= NULL
;
514 (*pctx
)->u
.lsp
.best_nhlfe
= NULL
;
519 case DPLANE_OP_PW_INSTALL
:
520 case DPLANE_OP_PW_UNINSTALL
:
521 /* Free allocated nexthops */
522 if ((*pctx
)->u
.pw
.nhg
.nexthop
) {
523 /* This deals with recursive nexthops too */
524 nexthops_free((*pctx
)->u
.pw
.nhg
.nexthop
);
526 (*pctx
)->u
.pw
.nhg
.nexthop
= NULL
;
530 case DPLANE_OP_ADDR_INSTALL
:
531 case DPLANE_OP_ADDR_UNINSTALL
:
532 /* Maybe free label string, if allocated */
533 if ((*pctx
)->u
.intf
.label
!= NULL
&&
534 (*pctx
)->u
.intf
.label
!= (*pctx
)->u
.intf
.label_buf
) {
535 free((*pctx
)->u
.intf
.label
);
536 (*pctx
)->u
.intf
.label
= NULL
;
540 case DPLANE_OP_MAC_INSTALL
:
541 case DPLANE_OP_MAC_DELETE
:
542 case DPLANE_OP_NEIGH_INSTALL
:
543 case DPLANE_OP_NEIGH_UPDATE
:
544 case DPLANE_OP_NEIGH_DELETE
:
545 case DPLANE_OP_VTEP_ADD
:
546 case DPLANE_OP_VTEP_DELETE
:
551 XFREE(MTYPE_DP_CTX
, *pctx
);
556 * Return a context block to the dplane module after processing
558 void dplane_ctx_fini(struct zebra_dplane_ctx
**pctx
)
560 /* TODO -- maintain pool; for now, just free */
561 dplane_ctx_free(pctx
);
564 /* Enqueue a context block */
565 void dplane_ctx_enqueue_tail(struct dplane_ctx_q
*q
,
566 const struct zebra_dplane_ctx
*ctx
)
568 TAILQ_INSERT_TAIL(q
, (struct zebra_dplane_ctx
*)ctx
, zd_q_entries
);
571 /* Append a list of context blocks to another list */
572 void dplane_ctx_list_append(struct dplane_ctx_q
*to_list
,
573 struct dplane_ctx_q
*from_list
)
575 if (TAILQ_FIRST(from_list
)) {
576 TAILQ_CONCAT(to_list
, from_list
, zd_q_entries
);
578 /* And clear 'from' list */
579 TAILQ_INIT(from_list
);
583 /* Dequeue a context block from the head of a list */
584 struct zebra_dplane_ctx
*dplane_ctx_dequeue(struct dplane_ctx_q
*q
)
586 struct zebra_dplane_ctx
*ctx
= TAILQ_FIRST(q
);
589 TAILQ_REMOVE(q
, ctx
, zd_q_entries
);
595 * Accessors for information from the context object
597 enum zebra_dplane_result
dplane_ctx_get_status(
598 const struct zebra_dplane_ctx
*ctx
)
600 DPLANE_CTX_VALID(ctx
);
602 return ctx
->zd_status
;
605 void dplane_ctx_set_status(struct zebra_dplane_ctx
*ctx
,
606 enum zebra_dplane_result status
)
608 DPLANE_CTX_VALID(ctx
);
610 ctx
->zd_status
= status
;
613 /* Retrieve last/current provider id */
614 uint32_t dplane_ctx_get_provider(const struct zebra_dplane_ctx
*ctx
)
616 DPLANE_CTX_VALID(ctx
);
617 return ctx
->zd_provider
;
620 /* Providers run before the kernel can control whether a kernel
621 * update should be done.
623 void dplane_ctx_set_skip_kernel(struct zebra_dplane_ctx
*ctx
)
625 DPLANE_CTX_VALID(ctx
);
627 SET_FLAG(ctx
->zd_flags
, DPLANE_CTX_FLAG_NO_KERNEL
);
630 bool dplane_ctx_is_skip_kernel(const struct zebra_dplane_ctx
*ctx
)
632 DPLANE_CTX_VALID(ctx
);
634 return CHECK_FLAG(ctx
->zd_flags
, DPLANE_CTX_FLAG_NO_KERNEL
);
637 void dplane_ctx_set_op(struct zebra_dplane_ctx
*ctx
, enum dplane_op_e op
)
639 DPLANE_CTX_VALID(ctx
);
643 enum dplane_op_e
dplane_ctx_get_op(const struct zebra_dplane_ctx
*ctx
)
645 DPLANE_CTX_VALID(ctx
);
650 const char *dplane_op2str(enum dplane_op_e op
)
652 const char *ret
= "UNKNOWN";
660 case DPLANE_OP_ROUTE_INSTALL
:
661 ret
= "ROUTE_INSTALL";
663 case DPLANE_OP_ROUTE_UPDATE
:
664 ret
= "ROUTE_UPDATE";
666 case DPLANE_OP_ROUTE_DELETE
:
667 ret
= "ROUTE_DELETE";
669 case DPLANE_OP_ROUTE_NOTIFY
:
670 ret
= "ROUTE_NOTIFY";
674 case DPLANE_OP_NH_INSTALL
:
677 case DPLANE_OP_NH_UPDATE
:
680 case DPLANE_OP_NH_DELETE
:
684 case DPLANE_OP_LSP_INSTALL
:
687 case DPLANE_OP_LSP_UPDATE
:
690 case DPLANE_OP_LSP_DELETE
:
693 case DPLANE_OP_LSP_NOTIFY
:
697 case DPLANE_OP_PW_INSTALL
:
700 case DPLANE_OP_PW_UNINSTALL
:
701 ret
= "PW_UNINSTALL";
704 case DPLANE_OP_SYS_ROUTE_ADD
:
705 ret
= "SYS_ROUTE_ADD";
707 case DPLANE_OP_SYS_ROUTE_DELETE
:
708 ret
= "SYS_ROUTE_DEL";
711 case DPLANE_OP_ADDR_INSTALL
:
712 ret
= "ADDR_INSTALL";
714 case DPLANE_OP_ADDR_UNINSTALL
:
715 ret
= "ADDR_UNINSTALL";
718 case DPLANE_OP_MAC_INSTALL
:
721 case DPLANE_OP_MAC_DELETE
:
725 case DPLANE_OP_NEIGH_INSTALL
:
726 ret
= "NEIGH_INSTALL";
728 case DPLANE_OP_NEIGH_UPDATE
:
729 ret
= "NEIGH_UPDATE";
731 case DPLANE_OP_NEIGH_DELETE
:
732 ret
= "NEIGH_DELETE";
734 case DPLANE_OP_VTEP_ADD
:
737 case DPLANE_OP_VTEP_DELETE
:
745 const char *dplane_res2str(enum zebra_dplane_result res
)
747 const char *ret
= "<Unknown>";
750 case ZEBRA_DPLANE_REQUEST_FAILURE
:
753 case ZEBRA_DPLANE_REQUEST_QUEUED
:
756 case ZEBRA_DPLANE_REQUEST_SUCCESS
:
764 void dplane_ctx_set_dest(struct zebra_dplane_ctx
*ctx
,
765 const struct prefix
*dest
)
767 DPLANE_CTX_VALID(ctx
);
769 prefix_copy(&(ctx
->u
.rinfo
.zd_dest
), dest
);
772 const struct prefix
*dplane_ctx_get_dest(const struct zebra_dplane_ctx
*ctx
)
774 DPLANE_CTX_VALID(ctx
);
776 return &(ctx
->u
.rinfo
.zd_dest
);
779 void dplane_ctx_set_src(struct zebra_dplane_ctx
*ctx
, const struct prefix
*src
)
781 DPLANE_CTX_VALID(ctx
);
784 prefix_copy(&(ctx
->u
.rinfo
.zd_src
), src
);
786 memset(&(ctx
->u
.rinfo
.zd_src
), 0, sizeof(struct prefix
));
789 /* Source prefix is a little special - return NULL for "no src prefix" */
790 const struct prefix
*dplane_ctx_get_src(const struct zebra_dplane_ctx
*ctx
)
792 DPLANE_CTX_VALID(ctx
);
794 if (ctx
->u
.rinfo
.zd_src
.prefixlen
== 0 &&
795 IN6_IS_ADDR_UNSPECIFIED(&(ctx
->u
.rinfo
.zd_src
.u
.prefix6
))) {
798 return &(ctx
->u
.rinfo
.zd_src
);
802 bool dplane_ctx_is_update(const struct zebra_dplane_ctx
*ctx
)
804 DPLANE_CTX_VALID(ctx
);
806 return ctx
->zd_is_update
;
809 uint32_t dplane_ctx_get_seq(const struct zebra_dplane_ctx
*ctx
)
811 DPLANE_CTX_VALID(ctx
);
816 uint32_t dplane_ctx_get_old_seq(const struct zebra_dplane_ctx
*ctx
)
818 DPLANE_CTX_VALID(ctx
);
820 return ctx
->zd_old_seq
;
823 void dplane_ctx_set_vrf(struct zebra_dplane_ctx
*ctx
, vrf_id_t vrf
)
825 DPLANE_CTX_VALID(ctx
);
827 ctx
->zd_vrf_id
= vrf
;
830 vrf_id_t
dplane_ctx_get_vrf(const struct zebra_dplane_ctx
*ctx
)
832 DPLANE_CTX_VALID(ctx
);
834 return ctx
->zd_vrf_id
;
837 bool dplane_ctx_is_from_notif(const struct zebra_dplane_ctx
*ctx
)
839 DPLANE_CTX_VALID(ctx
);
841 return (ctx
->zd_notif_provider
!= 0);
844 uint32_t dplane_ctx_get_notif_provider(const struct zebra_dplane_ctx
*ctx
)
846 DPLANE_CTX_VALID(ctx
);
848 return ctx
->zd_notif_provider
;
851 void dplane_ctx_set_notif_provider(struct zebra_dplane_ctx
*ctx
,
854 DPLANE_CTX_VALID(ctx
);
856 ctx
->zd_notif_provider
= id
;
858 const char *dplane_ctx_get_ifname(const struct zebra_dplane_ctx
*ctx
)
860 DPLANE_CTX_VALID(ctx
);
862 return ctx
->zd_ifname
;
865 ifindex_t
dplane_ctx_get_ifindex(const struct zebra_dplane_ctx
*ctx
)
867 DPLANE_CTX_VALID(ctx
);
869 return ctx
->zd_ifindex
;
872 void dplane_ctx_set_type(struct zebra_dplane_ctx
*ctx
, int type
)
874 DPLANE_CTX_VALID(ctx
);
876 ctx
->u
.rinfo
.zd_type
= type
;
879 int dplane_ctx_get_type(const struct zebra_dplane_ctx
*ctx
)
881 DPLANE_CTX_VALID(ctx
);
883 return ctx
->u
.rinfo
.zd_type
;
886 int dplane_ctx_get_old_type(const struct zebra_dplane_ctx
*ctx
)
888 DPLANE_CTX_VALID(ctx
);
890 return ctx
->u
.rinfo
.zd_old_type
;
893 void dplane_ctx_set_afi(struct zebra_dplane_ctx
*ctx
, afi_t afi
)
895 DPLANE_CTX_VALID(ctx
);
897 ctx
->u
.rinfo
.zd_afi
= afi
;
900 afi_t
dplane_ctx_get_afi(const struct zebra_dplane_ctx
*ctx
)
902 DPLANE_CTX_VALID(ctx
);
904 return ctx
->u
.rinfo
.zd_afi
;
907 void dplane_ctx_set_safi(struct zebra_dplane_ctx
*ctx
, safi_t safi
)
909 DPLANE_CTX_VALID(ctx
);
911 ctx
->u
.rinfo
.zd_safi
= safi
;
914 safi_t
dplane_ctx_get_safi(const struct zebra_dplane_ctx
*ctx
)
916 DPLANE_CTX_VALID(ctx
);
918 return ctx
->u
.rinfo
.zd_safi
;
921 void dplane_ctx_set_table(struct zebra_dplane_ctx
*ctx
, uint32_t table
)
923 DPLANE_CTX_VALID(ctx
);
925 ctx
->zd_table_id
= table
;
928 uint32_t dplane_ctx_get_table(const struct zebra_dplane_ctx
*ctx
)
930 DPLANE_CTX_VALID(ctx
);
932 return ctx
->zd_table_id
;
935 route_tag_t
dplane_ctx_get_tag(const struct zebra_dplane_ctx
*ctx
)
937 DPLANE_CTX_VALID(ctx
);
939 return ctx
->u
.rinfo
.zd_tag
;
942 void dplane_ctx_set_tag(struct zebra_dplane_ctx
*ctx
, route_tag_t tag
)
944 DPLANE_CTX_VALID(ctx
);
946 ctx
->u
.rinfo
.zd_tag
= tag
;
949 route_tag_t
dplane_ctx_get_old_tag(const struct zebra_dplane_ctx
*ctx
)
951 DPLANE_CTX_VALID(ctx
);
953 return ctx
->u
.rinfo
.zd_old_tag
;
956 uint16_t dplane_ctx_get_instance(const struct zebra_dplane_ctx
*ctx
)
958 DPLANE_CTX_VALID(ctx
);
960 return ctx
->u
.rinfo
.zd_instance
;
963 void dplane_ctx_set_instance(struct zebra_dplane_ctx
*ctx
, uint16_t instance
)
965 DPLANE_CTX_VALID(ctx
);
967 ctx
->u
.rinfo
.zd_instance
= instance
;
970 uint16_t dplane_ctx_get_old_instance(const struct zebra_dplane_ctx
*ctx
)
972 DPLANE_CTX_VALID(ctx
);
974 return ctx
->u
.rinfo
.zd_old_instance
;
977 uint32_t dplane_ctx_get_metric(const struct zebra_dplane_ctx
*ctx
)
979 DPLANE_CTX_VALID(ctx
);
981 return ctx
->u
.rinfo
.zd_metric
;
984 uint32_t dplane_ctx_get_old_metric(const struct zebra_dplane_ctx
*ctx
)
986 DPLANE_CTX_VALID(ctx
);
988 return ctx
->u
.rinfo
.zd_old_metric
;
991 uint32_t dplane_ctx_get_mtu(const struct zebra_dplane_ctx
*ctx
)
993 DPLANE_CTX_VALID(ctx
);
995 return ctx
->u
.rinfo
.zd_mtu
;
998 uint32_t dplane_ctx_get_nh_mtu(const struct zebra_dplane_ctx
*ctx
)
1000 DPLANE_CTX_VALID(ctx
);
1002 return ctx
->u
.rinfo
.zd_nexthop_mtu
;
1005 uint8_t dplane_ctx_get_distance(const struct zebra_dplane_ctx
*ctx
)
1007 DPLANE_CTX_VALID(ctx
);
1009 return ctx
->u
.rinfo
.zd_distance
;
1012 void dplane_ctx_set_distance(struct zebra_dplane_ctx
*ctx
, uint8_t distance
)
1014 DPLANE_CTX_VALID(ctx
);
1016 ctx
->u
.rinfo
.zd_distance
= distance
;
1019 uint8_t dplane_ctx_get_old_distance(const struct zebra_dplane_ctx
*ctx
)
1021 DPLANE_CTX_VALID(ctx
);
1023 return ctx
->u
.rinfo
.zd_old_distance
;
1027 * Set the nexthops associated with a context: note that processing code
1028 * may well expect that nexthops are in canonical (sorted) order, so we
1029 * will enforce that here.
1031 void dplane_ctx_set_nexthops(struct zebra_dplane_ctx
*ctx
, struct nexthop
*nh
)
1033 DPLANE_CTX_VALID(ctx
);
1035 if (ctx
->u
.rinfo
.zd_ng
.nexthop
) {
1036 nexthops_free(ctx
->u
.rinfo
.zd_ng
.nexthop
);
1037 ctx
->u
.rinfo
.zd_ng
.nexthop
= NULL
;
1039 nexthop_group_copy_nh_sorted(&(ctx
->u
.rinfo
.zd_ng
), nh
);
1042 const struct nexthop_group
*dplane_ctx_get_ng(
1043 const struct zebra_dplane_ctx
*ctx
)
1045 DPLANE_CTX_VALID(ctx
);
1047 return &(ctx
->u
.rinfo
.zd_ng
);
1050 const struct nexthop_group
*dplane_ctx_get_old_ng(
1051 const struct zebra_dplane_ctx
*ctx
)
1053 DPLANE_CTX_VALID(ctx
);
1055 return &(ctx
->u
.rinfo
.zd_old_ng
);
1058 const struct zebra_dplane_info
*dplane_ctx_get_ns(
1059 const struct zebra_dplane_ctx
*ctx
)
1061 DPLANE_CTX_VALID(ctx
);
1063 return &(ctx
->zd_ns_info
);
1066 /* Accessors for nexthop information */
1067 uint32_t dplane_ctx_get_nhe_id(const struct zebra_dplane_ctx
*ctx
)
1069 DPLANE_CTX_VALID(ctx
);
1070 return ctx
->u
.rinfo
.nhe
.id
;
1073 afi_t
dplane_ctx_get_nhe_afi(const struct zebra_dplane_ctx
*ctx
)
1075 DPLANE_CTX_VALID(ctx
);
1076 return ctx
->u
.rinfo
.nhe
.afi
;
1079 vrf_id_t
dplane_ctx_get_nhe_vrf_id(const struct zebra_dplane_ctx
*ctx
)
1081 DPLANE_CTX_VALID(ctx
);
1082 return ctx
->u
.rinfo
.nhe
.vrf_id
;
1085 int dplane_ctx_get_nhe_type(const struct zebra_dplane_ctx
*ctx
)
1087 DPLANE_CTX_VALID(ctx
);
1088 return ctx
->u
.rinfo
.nhe
.type
;
1091 const struct nexthop_group
*
1092 dplane_ctx_get_nhe_ng(const struct zebra_dplane_ctx
*ctx
)
1094 DPLANE_CTX_VALID(ctx
);
1095 return &(ctx
->u
.rinfo
.nhe
.ng
);
1098 const struct nh_grp
*
1099 dplane_ctx_get_nhe_nh_grp(const struct zebra_dplane_ctx
*ctx
)
1101 DPLANE_CTX_VALID(ctx
);
1102 return ctx
->u
.rinfo
.nhe
.nh_grp
;
1105 uint8_t dplane_ctx_get_nhe_nh_grp_count(const struct zebra_dplane_ctx
*ctx
)
1107 DPLANE_CTX_VALID(ctx
);
1108 return ctx
->u
.rinfo
.nhe
.nh_grp_count
;
1111 /* Accessors for LSP information */
1113 mpls_label_t
dplane_ctx_get_in_label(const struct zebra_dplane_ctx
*ctx
)
1115 DPLANE_CTX_VALID(ctx
);
1117 return ctx
->u
.lsp
.ile
.in_label
;
1120 void dplane_ctx_set_in_label(struct zebra_dplane_ctx
*ctx
, mpls_label_t label
)
1122 DPLANE_CTX_VALID(ctx
);
1124 ctx
->u
.lsp
.ile
.in_label
= label
;
1127 uint8_t dplane_ctx_get_addr_family(const struct zebra_dplane_ctx
*ctx
)
1129 DPLANE_CTX_VALID(ctx
);
1131 return ctx
->u
.lsp
.addr_family
;
1134 void dplane_ctx_set_addr_family(struct zebra_dplane_ctx
*ctx
,
1137 DPLANE_CTX_VALID(ctx
);
1139 ctx
->u
.lsp
.addr_family
= family
;
1142 uint32_t dplane_ctx_get_lsp_flags(const struct zebra_dplane_ctx
*ctx
)
1144 DPLANE_CTX_VALID(ctx
);
1146 return ctx
->u
.lsp
.flags
;
1149 void dplane_ctx_set_lsp_flags(struct zebra_dplane_ctx
*ctx
,
1152 DPLANE_CTX_VALID(ctx
);
1154 ctx
->u
.lsp
.flags
= flags
;
1157 const zebra_nhlfe_t
*dplane_ctx_get_nhlfe(const struct zebra_dplane_ctx
*ctx
)
1159 DPLANE_CTX_VALID(ctx
);
1161 return ctx
->u
.lsp
.nhlfe_list
;
1164 zebra_nhlfe_t
*dplane_ctx_add_nhlfe(struct zebra_dplane_ctx
*ctx
,
1165 enum lsp_types_t lsp_type
,
1166 enum nexthop_types_t nh_type
,
1170 mpls_label_t out_labels
[])
1172 zebra_nhlfe_t
*nhlfe
;
1174 DPLANE_CTX_VALID(ctx
);
1176 nhlfe
= zebra_mpls_lsp_add_nhlfe(&(ctx
->u
.lsp
),
1177 lsp_type
, nh_type
, gate
,
1178 ifindex
, num_labels
, out_labels
);
1183 const zebra_nhlfe_t
*
1184 dplane_ctx_get_best_nhlfe(const struct zebra_dplane_ctx
*ctx
)
1186 DPLANE_CTX_VALID(ctx
);
1188 return ctx
->u
.lsp
.best_nhlfe
;
1191 const zebra_nhlfe_t
*
1192 dplane_ctx_set_best_nhlfe(struct zebra_dplane_ctx
*ctx
,
1193 zebra_nhlfe_t
*nhlfe
)
1195 DPLANE_CTX_VALID(ctx
);
1197 ctx
->u
.lsp
.best_nhlfe
= nhlfe
;
1198 return ctx
->u
.lsp
.best_nhlfe
;
1201 uint32_t dplane_ctx_get_lsp_num_ecmp(const struct zebra_dplane_ctx
*ctx
)
1203 DPLANE_CTX_VALID(ctx
);
1205 return ctx
->u
.lsp
.num_ecmp
;
1208 mpls_label_t
dplane_ctx_get_pw_local_label(const struct zebra_dplane_ctx
*ctx
)
1210 DPLANE_CTX_VALID(ctx
);
1212 return ctx
->u
.pw
.local_label
;
1215 mpls_label_t
dplane_ctx_get_pw_remote_label(const struct zebra_dplane_ctx
*ctx
)
1217 DPLANE_CTX_VALID(ctx
);
1219 return ctx
->u
.pw
.remote_label
;
1222 int dplane_ctx_get_pw_type(const struct zebra_dplane_ctx
*ctx
)
1224 DPLANE_CTX_VALID(ctx
);
1226 return ctx
->u
.pw
.type
;
1229 int dplane_ctx_get_pw_af(const struct zebra_dplane_ctx
*ctx
)
1231 DPLANE_CTX_VALID(ctx
);
1233 return ctx
->u
.pw
.af
;
1236 uint32_t dplane_ctx_get_pw_flags(const struct zebra_dplane_ctx
*ctx
)
1238 DPLANE_CTX_VALID(ctx
);
1240 return ctx
->u
.pw
.flags
;
1243 int dplane_ctx_get_pw_status(const struct zebra_dplane_ctx
*ctx
)
1245 DPLANE_CTX_VALID(ctx
);
1247 return ctx
->u
.pw
.status
;
1250 const union g_addr
*dplane_ctx_get_pw_dest(
1251 const struct zebra_dplane_ctx
*ctx
)
1253 DPLANE_CTX_VALID(ctx
);
1255 return &(ctx
->u
.pw
.dest
);
1258 const union pw_protocol_fields
*dplane_ctx_get_pw_proto(
1259 const struct zebra_dplane_ctx
*ctx
)
1261 DPLANE_CTX_VALID(ctx
);
1263 return &(ctx
->u
.pw
.fields
);
1266 const struct nexthop_group
*
1267 dplane_ctx_get_pw_nhg(const struct zebra_dplane_ctx
*ctx
)
1269 DPLANE_CTX_VALID(ctx
);
1271 return &(ctx
->u
.pw
.nhg
);
1274 /* Accessors for interface information */
1275 uint32_t dplane_ctx_get_intf_metric(const struct zebra_dplane_ctx
*ctx
)
1277 DPLANE_CTX_VALID(ctx
);
1279 return ctx
->u
.intf
.metric
;
1282 /* Is interface addr p2p? */
1283 bool dplane_ctx_intf_is_connected(const struct zebra_dplane_ctx
*ctx
)
1285 DPLANE_CTX_VALID(ctx
);
1287 return (ctx
->u
.intf
.flags
& DPLANE_INTF_CONNECTED
);
1290 bool dplane_ctx_intf_is_secondary(const struct zebra_dplane_ctx
*ctx
)
1292 DPLANE_CTX_VALID(ctx
);
1294 return (ctx
->u
.intf
.flags
& DPLANE_INTF_SECONDARY
);
1297 bool dplane_ctx_intf_is_broadcast(const struct zebra_dplane_ctx
*ctx
)
1299 DPLANE_CTX_VALID(ctx
);
1301 return (ctx
->u
.intf
.flags
& DPLANE_INTF_BROADCAST
);
1304 const struct prefix
*dplane_ctx_get_intf_addr(
1305 const struct zebra_dplane_ctx
*ctx
)
1307 DPLANE_CTX_VALID(ctx
);
1309 return &(ctx
->u
.intf
.prefix
);
1312 bool dplane_ctx_intf_has_dest(const struct zebra_dplane_ctx
*ctx
)
1314 DPLANE_CTX_VALID(ctx
);
1316 return (ctx
->u
.intf
.flags
& DPLANE_INTF_HAS_DEST
);
1319 const struct prefix
*dplane_ctx_get_intf_dest(
1320 const struct zebra_dplane_ctx
*ctx
)
1322 DPLANE_CTX_VALID(ctx
);
1324 if (ctx
->u
.intf
.flags
& DPLANE_INTF_HAS_DEST
)
1325 return &(ctx
->u
.intf
.dest_prefix
);
1330 bool dplane_ctx_intf_has_label(const struct zebra_dplane_ctx
*ctx
)
1332 DPLANE_CTX_VALID(ctx
);
1334 return (ctx
->u
.intf
.flags
& DPLANE_INTF_HAS_LABEL
);
1337 const char *dplane_ctx_get_intf_label(const struct zebra_dplane_ctx
*ctx
)
1339 DPLANE_CTX_VALID(ctx
);
1341 return ctx
->u
.intf
.label
;
1344 /* Accessors for MAC information */
1345 vlanid_t
dplane_ctx_mac_get_vlan(const struct zebra_dplane_ctx
*ctx
)
1347 DPLANE_CTX_VALID(ctx
);
1348 return ctx
->u
.macinfo
.vid
;
1351 bool dplane_ctx_mac_is_sticky(const struct zebra_dplane_ctx
*ctx
)
1353 DPLANE_CTX_VALID(ctx
);
1354 return ctx
->u
.macinfo
.is_sticky
;
1357 const struct ethaddr
*dplane_ctx_mac_get_addr(
1358 const struct zebra_dplane_ctx
*ctx
)
1360 DPLANE_CTX_VALID(ctx
);
1361 return &(ctx
->u
.macinfo
.mac
);
1364 const struct in_addr
*dplane_ctx_mac_get_vtep_ip(
1365 const struct zebra_dplane_ctx
*ctx
)
1367 DPLANE_CTX_VALID(ctx
);
1368 return &(ctx
->u
.macinfo
.vtep_ip
);
1371 ifindex_t
dplane_ctx_mac_get_br_ifindex(const struct zebra_dplane_ctx
*ctx
)
1373 DPLANE_CTX_VALID(ctx
);
1374 return ctx
->u
.macinfo
.br_ifindex
;
1377 /* Accessors for neighbor information */
1378 const struct ipaddr
*dplane_ctx_neigh_get_ipaddr(
1379 const struct zebra_dplane_ctx
*ctx
)
1381 DPLANE_CTX_VALID(ctx
);
1382 return &(ctx
->u
.neigh
.ip_addr
);
1385 const struct ethaddr
*dplane_ctx_neigh_get_mac(
1386 const struct zebra_dplane_ctx
*ctx
)
1388 DPLANE_CTX_VALID(ctx
);
1389 return &(ctx
->u
.neigh
.mac
);
1392 uint32_t dplane_ctx_neigh_get_flags(const struct zebra_dplane_ctx
*ctx
)
1394 DPLANE_CTX_VALID(ctx
);
1395 return ctx
->u
.neigh
.flags
;
1398 uint16_t dplane_ctx_neigh_get_state(const struct zebra_dplane_ctx
*ctx
)
1400 DPLANE_CTX_VALID(ctx
);
1401 return ctx
->u
.neigh
.state
;
1405 * End of dplane context accessors
1410 * Retrieve the limit on the number of pending, unprocessed updates.
1412 uint32_t dplane_get_in_queue_limit(void)
1414 return atomic_load_explicit(&zdplane_info
.dg_max_queued_updates
,
1415 memory_order_relaxed
);
1419 * Configure limit on the number of pending, queued updates.
1421 void dplane_set_in_queue_limit(uint32_t limit
, bool set
)
1423 /* Reset to default on 'unset' */
1425 limit
= DPLANE_DEFAULT_MAX_QUEUED
;
1427 atomic_store_explicit(&zdplane_info
.dg_max_queued_updates
, limit
,
1428 memory_order_relaxed
);
1432 * Retrieve the current queue depth of incoming, unprocessed updates
1434 uint32_t dplane_get_in_queue_len(void)
1436 return atomic_load_explicit(&zdplane_info
.dg_routes_queued
,
1437 memory_order_seq_cst
);
1441 * Common dataplane context init with zebra namespace info.
1443 static int dplane_ctx_ns_init(struct zebra_dplane_ctx
*ctx
,
1444 struct zebra_ns
*zns
,
1447 dplane_info_from_zns(&(ctx
->zd_ns_info
), zns
);
1449 #if defined(HAVE_NETLINK)
1450 /* Increment message counter after copying to context struct - may need
1451 * two messages in some 'update' cases.
1454 zns
->netlink_dplane
.seq
+= 2;
1456 zns
->netlink_dplane
.seq
++;
1457 #endif /* HAVE_NETLINK */
1463 * Initialize a context block for a route update from zebra data structs.
1465 static int dplane_ctx_route_init(struct zebra_dplane_ctx
*ctx
,
1466 enum dplane_op_e op
,
1467 struct route_node
*rn
,
1468 struct route_entry
*re
)
1471 const struct route_table
*table
= NULL
;
1472 const rib_table_info_t
*info
;
1473 const struct prefix
*p
, *src_p
;
1474 struct zebra_ns
*zns
;
1475 struct zebra_vrf
*zvrf
;
1476 struct nexthop
*nexthop
;
1478 if (!ctx
|| !rn
|| !re
)
1482 ctx
->zd_status
= ZEBRA_DPLANE_REQUEST_SUCCESS
;
1484 ctx
->u
.rinfo
.zd_type
= re
->type
;
1485 ctx
->u
.rinfo
.zd_old_type
= re
->type
;
1487 /* Prefixes: dest, and optional source */
1488 srcdest_rnode_prefixes(rn
, &p
, &src_p
);
1490 prefix_copy(&(ctx
->u
.rinfo
.zd_dest
), p
);
1493 prefix_copy(&(ctx
->u
.rinfo
.zd_src
), src_p
);
1495 memset(&(ctx
->u
.rinfo
.zd_src
), 0, sizeof(ctx
->u
.rinfo
.zd_src
));
1497 ctx
->zd_table_id
= re
->table
;
1499 ctx
->u
.rinfo
.zd_metric
= re
->metric
;
1500 ctx
->u
.rinfo
.zd_old_metric
= re
->metric
;
1501 ctx
->zd_vrf_id
= re
->vrf_id
;
1502 ctx
->u
.rinfo
.zd_mtu
= re
->mtu
;
1503 ctx
->u
.rinfo
.zd_nexthop_mtu
= re
->nexthop_mtu
;
1504 ctx
->u
.rinfo
.zd_instance
= re
->instance
;
1505 ctx
->u
.rinfo
.zd_tag
= re
->tag
;
1506 ctx
->u
.rinfo
.zd_old_tag
= re
->tag
;
1507 ctx
->u
.rinfo
.zd_distance
= re
->distance
;
1509 table
= srcdest_rnode_table(rn
);
1512 ctx
->u
.rinfo
.zd_afi
= info
->afi
;
1513 ctx
->u
.rinfo
.zd_safi
= info
->safi
;
1515 /* Copy nexthops; recursive info is included too */
1516 copy_nexthops(&(ctx
->u
.rinfo
.zd_ng
.nexthop
),
1517 re
->nhe
->nhg
->nexthop
, NULL
);
1519 /* Ensure that the dplane's nexthops flags are clear. */
1520 for (ALL_NEXTHOPS(ctx
->u
.rinfo
.zd_ng
, nexthop
))
1521 UNSET_FLAG(nexthop
->flags
, NEXTHOP_FLAG_FIB
);
1523 /* Don't need some info when capturing a system notification */
1524 if (op
== DPLANE_OP_SYS_ROUTE_ADD
||
1525 op
== DPLANE_OP_SYS_ROUTE_DELETE
) {
1530 /* Extract ns info - can't use pointers to 'core' structs */
1531 zvrf
= vrf_info_lookup(re
->vrf_id
);
1533 dplane_ctx_ns_init(ctx
, zns
, (op
== DPLANE_OP_ROUTE_UPDATE
));
1537 struct nhg_hash_entry
*nhe
=
1538 zebra_nhg_resolve(zebra_nhg_lookup_id(re
->nhe_id
));
1540 ctx
->u
.rinfo
.nhe
.id
= nhe
->id
;
1542 * Check if the nhe is installed/queued before doing anything
1545 * If its a delete we only use the prefix anyway, so this only
1546 * matters for INSTALL/UPDATE.
1548 if (((op
== DPLANE_OP_ROUTE_INSTALL
)
1549 || (op
== DPLANE_OP_ROUTE_UPDATE
))
1550 && !CHECK_FLAG(nhe
->flags
, NEXTHOP_GROUP_INSTALLED
)
1551 && !CHECK_FLAG(nhe
->flags
, NEXTHOP_GROUP_QUEUED
)) {
1556 #endif /* HAVE_NETLINK */
1558 /* Trying out the sequence number idea, so we can try to detect
1559 * when a result is stale.
1561 re
->dplane_sequence
= zebra_router_get_next_sequence();
1562 ctx
->zd_seq
= re
->dplane_sequence
;
1571 * dplane_ctx_nexthop_init() - Initialize a context block for a nexthop update
1573 * @ctx: Dataplane context to init
1574 * @op: Operation being performed
1575 * @nhe: Nexthop group hash entry
1577 * Return: Result status
1579 static int dplane_ctx_nexthop_init(struct zebra_dplane_ctx
*ctx
,
1580 enum dplane_op_e op
,
1581 struct nhg_hash_entry
*nhe
)
1583 struct zebra_vrf
*zvrf
= NULL
;
1584 struct zebra_ns
*zns
= NULL
;
1592 ctx
->zd_status
= ZEBRA_DPLANE_REQUEST_SUCCESS
;
1594 /* Copy over nhe info */
1595 ctx
->u
.rinfo
.nhe
.id
= nhe
->id
;
1596 ctx
->u
.rinfo
.nhe
.afi
= nhe
->afi
;
1597 ctx
->u
.rinfo
.nhe
.vrf_id
= nhe
->vrf_id
;
1598 ctx
->u
.rinfo
.nhe
.type
= nhe
->type
;
1600 nexthop_group_copy(&(ctx
->u
.rinfo
.nhe
.ng
), nhe
->nhg
);
1602 /* If its a group, convert it to a grp array of ids */
1603 if (!zebra_nhg_depends_is_empty(nhe
)
1604 && !CHECK_FLAG(nhe
->flags
, NEXTHOP_GROUP_RECURSIVE
))
1605 ctx
->u
.rinfo
.nhe
.nh_grp_count
= zebra_nhg_nhe2grp(
1606 ctx
->u
.rinfo
.nhe
.nh_grp
, nhe
, MULTIPATH_NUM
);
1608 zvrf
= vrf_info_lookup(nhe
->vrf_id
);
1611 * Fallback to default namespace if the vrf got ripped out from under
1614 zns
= zvrf
? zvrf
->zns
: zebra_ns_lookup(NS_DEFAULT
);
1617 * TODO: Might not need to mark this as an update, since
1618 * it probably won't require two messages
1620 dplane_ctx_ns_init(ctx
, zns
, (op
== DPLANE_OP_NH_UPDATE
));
1629 * Capture information for an LSP update in a dplane context.
1631 static int dplane_ctx_lsp_init(struct zebra_dplane_ctx
*ctx
,
1632 enum dplane_op_e op
,
1636 zebra_nhlfe_t
*nhlfe
, *new_nhlfe
;
1638 if (IS_ZEBRA_DEBUG_DPLANE_DETAIL
)
1639 zlog_debug("init dplane ctx %s: in-label %u ecmp# %d",
1640 dplane_op2str(op
), lsp
->ile
.in_label
,
1644 ctx
->zd_status
= ZEBRA_DPLANE_REQUEST_SUCCESS
;
1646 /* Capture namespace info */
1647 dplane_ctx_ns_init(ctx
, zebra_ns_lookup(NS_DEFAULT
),
1648 (op
== DPLANE_OP_LSP_UPDATE
));
1650 memset(&ctx
->u
.lsp
, 0, sizeof(ctx
->u
.lsp
));
1652 ctx
->u
.lsp
.ile
= lsp
->ile
;
1653 ctx
->u
.lsp
.addr_family
= lsp
->addr_family
;
1654 ctx
->u
.lsp
.num_ecmp
= lsp
->num_ecmp
;
1655 ctx
->u
.lsp
.flags
= lsp
->flags
;
1657 /* Copy source LSP's nhlfes, and capture 'best' nhlfe */
1658 for (nhlfe
= lsp
->nhlfe_list
; nhlfe
; nhlfe
= nhlfe
->next
) {
1659 /* Not sure if this is meaningful... */
1660 if (nhlfe
->nexthop
== NULL
)
1664 zebra_mpls_lsp_add_nhlfe(
1667 nhlfe
->nexthop
->type
,
1668 &(nhlfe
->nexthop
->gate
),
1669 nhlfe
->nexthop
->ifindex
,
1670 nhlfe
->nexthop
->nh_label
->num_labels
,
1671 nhlfe
->nexthop
->nh_label
->label
);
1673 if (new_nhlfe
== NULL
|| new_nhlfe
->nexthop
== NULL
) {
1678 /* Need to copy flags too */
1679 new_nhlfe
->flags
= nhlfe
->flags
;
1680 new_nhlfe
->nexthop
->flags
= nhlfe
->nexthop
->flags
;
1682 if (nhlfe
== lsp
->best_nhlfe
)
1683 ctx
->u
.lsp
.best_nhlfe
= new_nhlfe
;
1686 /* On error the ctx will be cleaned-up, so we don't need to
1687 * deal with any allocated nhlfe or nexthop structs here.
1694 * Capture information for an LSP update in a dplane context.
1696 static int dplane_ctx_pw_init(struct zebra_dplane_ctx
*ctx
,
1697 enum dplane_op_e op
,
1698 struct zebra_pw
*pw
)
1702 struct route_table
*table
;
1703 struct route_node
*rn
;
1704 struct route_entry
*re
;
1706 if (IS_ZEBRA_DEBUG_DPLANE_DETAIL
)
1707 zlog_debug("init dplane ctx %s: pw '%s', loc %u, rem %u",
1708 dplane_op2str(op
), pw
->ifname
, pw
->local_label
,
1712 ctx
->zd_status
= ZEBRA_DPLANE_REQUEST_SUCCESS
;
1714 /* Capture namespace info: no netlink support as of 12/18,
1715 * but just in case...
1717 dplane_ctx_ns_init(ctx
, zebra_ns_lookup(NS_DEFAULT
), false);
1719 memset(&ctx
->u
.pw
, 0, sizeof(ctx
->u
.pw
));
1721 /* This name appears to be c-string, so we use string copy. */
1722 strlcpy(ctx
->zd_ifname
, pw
->ifname
, sizeof(ctx
->zd_ifname
));
1724 ctx
->zd_vrf_id
= pw
->vrf_id
;
1725 ctx
->zd_ifindex
= pw
->ifindex
;
1726 ctx
->u
.pw
.type
= pw
->type
;
1727 ctx
->u
.pw
.af
= pw
->af
;
1728 ctx
->u
.pw
.local_label
= pw
->local_label
;
1729 ctx
->u
.pw
.remote_label
= pw
->remote_label
;
1730 ctx
->u
.pw
.flags
= pw
->flags
;
1732 ctx
->u
.pw
.dest
= pw
->nexthop
;
1734 ctx
->u
.pw
.fields
= pw
->data
;
1736 /* Capture nexthop info for the pw destination. We need to look
1737 * up and use zebra datastructs, but we're running in the zebra
1738 * pthread here so that should be ok.
1740 memcpy(&p
.u
, &pw
->nexthop
, sizeof(pw
->nexthop
));
1742 p
.prefixlen
= ((pw
->af
== AF_INET
) ?
1743 IPV4_MAX_PREFIXLEN
: IPV6_MAX_PREFIXLEN
);
1745 afi
= (pw
->af
== AF_INET
) ? AFI_IP
: AFI_IP6
;
1746 table
= zebra_vrf_table(afi
, SAFI_UNICAST
, pw
->vrf_id
);
1748 rn
= route_node_match(table
, &p
);
1750 RNODE_FOREACH_RE(rn
, re
) {
1751 if (CHECK_FLAG(re
->flags
, ZEBRA_FLAG_SELECTED
))
1756 copy_nexthops(&(ctx
->u
.pw
.nhg
.nexthop
),
1757 re
->nhe
->nhg
->nexthop
, NULL
);
1759 route_unlock_node(rn
);
1767 * Enqueue a new update,
1768 * and ensure an event is active for the dataplane pthread.
1770 static int dplane_update_enqueue(struct zebra_dplane_ctx
*ctx
)
1773 uint32_t high
, curr
;
1775 /* Enqueue for processing by the dataplane pthread */
1778 TAILQ_INSERT_TAIL(&zdplane_info
.dg_update_ctx_q
, ctx
,
1783 curr
= atomic_add_fetch_explicit(
1785 /* TODO -- issue with the clang atomic/intrinsics currently;
1786 * casting away the 'Atomic'-ness of the variable works.
1788 (uint32_t *)&(zdplane_info
.dg_routes_queued
),
1790 &(zdplane_info
.dg_routes_queued
),
1792 1, memory_order_seq_cst
);
1794 /* Maybe update high-water counter also */
1795 high
= atomic_load_explicit(&zdplane_info
.dg_routes_queued_max
,
1796 memory_order_seq_cst
);
1797 while (high
< curr
) {
1798 if (atomic_compare_exchange_weak_explicit(
1799 &zdplane_info
.dg_routes_queued_max
,
1801 memory_order_seq_cst
,
1802 memory_order_seq_cst
))
1806 /* Ensure that an event for the dataplane thread is active */
1807 ret
= dplane_provider_work_ready();
1813 * Utility that prepares a route update and enqueues it for processing
1815 static enum zebra_dplane_result
1816 dplane_route_update_internal(struct route_node
*rn
,
1817 struct route_entry
*re
,
1818 struct route_entry
*old_re
,
1819 enum dplane_op_e op
)
1821 enum zebra_dplane_result result
= ZEBRA_DPLANE_REQUEST_FAILURE
;
1823 struct zebra_dplane_ctx
*ctx
= NULL
;
1825 /* Obtain context block */
1826 ctx
= dplane_ctx_alloc();
1828 /* Init context with info from zebra data structs */
1829 ret
= dplane_ctx_route_init(ctx
, op
, rn
, re
);
1831 /* Capture some extra info for update case
1832 * where there's a different 'old' route.
1834 if ((op
== DPLANE_OP_ROUTE_UPDATE
) &&
1835 old_re
&& (old_re
!= re
)) {
1836 ctx
->zd_is_update
= true;
1838 old_re
->dplane_sequence
=
1839 zebra_router_get_next_sequence();
1840 ctx
->zd_old_seq
= old_re
->dplane_sequence
;
1842 ctx
->u
.rinfo
.zd_old_tag
= old_re
->tag
;
1843 ctx
->u
.rinfo
.zd_old_type
= old_re
->type
;
1844 ctx
->u
.rinfo
.zd_old_instance
= old_re
->instance
;
1845 ctx
->u
.rinfo
.zd_old_distance
= old_re
->distance
;
1846 ctx
->u
.rinfo
.zd_old_metric
= old_re
->metric
;
1848 #ifndef HAVE_NETLINK
1849 /* For bsd, capture previous re's nexthops too, sigh.
1850 * We'll need these to do per-nexthop deletes.
1852 copy_nexthops(&(ctx
->u
.rinfo
.zd_old_ng
.nexthop
),
1853 old_re
->nhe
->nhg
->nexthop
, NULL
);
1854 #endif /* !HAVE_NETLINK */
1857 /* Enqueue context for processing */
1858 ret
= dplane_update_enqueue(ctx
);
1861 /* Update counter */
1862 atomic_fetch_add_explicit(&zdplane_info
.dg_routes_in
, 1,
1863 memory_order_relaxed
);
1866 result
= ZEBRA_DPLANE_REQUEST_QUEUED
;
1869 result
= ZEBRA_DPLANE_REQUEST_SUCCESS
;
1871 atomic_fetch_add_explicit(&zdplane_info
.dg_route_errors
,
1872 1, memory_order_relaxed
);
1874 dplane_ctx_free(&ctx
);
1881 * dplane_nexthop_update_internal() - Helper for enqueuing nexthop changes
1883 * @nhe: Nexthop group hash entry where the change occured
1884 * @op: The operation to be enqued
1886 * Return: Result of the change
1888 static enum zebra_dplane_result
1889 dplane_nexthop_update_internal(struct nhg_hash_entry
*nhe
, enum dplane_op_e op
)
1891 enum zebra_dplane_result result
= ZEBRA_DPLANE_REQUEST_FAILURE
;
1893 struct zebra_dplane_ctx
*ctx
= NULL
;
1895 /* Obtain context block */
1896 ctx
= dplane_ctx_alloc();
1902 ret
= dplane_ctx_nexthop_init(ctx
, op
, nhe
);
1904 ret
= dplane_update_enqueue(ctx
);
1907 /* Update counter */
1908 atomic_fetch_add_explicit(&zdplane_info
.dg_nexthops_in
, 1,
1909 memory_order_relaxed
);
1912 result
= ZEBRA_DPLANE_REQUEST_QUEUED
;
1914 atomic_fetch_add_explicit(&zdplane_info
.dg_nexthop_errors
, 1,
1915 memory_order_relaxed
);
1917 dplane_ctx_free(&ctx
);
1924 * Enqueue a route 'add' for the dataplane.
1926 enum zebra_dplane_result
dplane_route_add(struct route_node
*rn
,
1927 struct route_entry
*re
)
1929 enum zebra_dplane_result ret
= ZEBRA_DPLANE_REQUEST_FAILURE
;
1931 if (rn
== NULL
|| re
== NULL
)
1934 ret
= dplane_route_update_internal(rn
, re
, NULL
,
1935 DPLANE_OP_ROUTE_INSTALL
);
1942 * Enqueue a route update for the dataplane.
1944 enum zebra_dplane_result
dplane_route_update(struct route_node
*rn
,
1945 struct route_entry
*re
,
1946 struct route_entry
*old_re
)
1948 enum zebra_dplane_result ret
= ZEBRA_DPLANE_REQUEST_FAILURE
;
1950 if (rn
== NULL
|| re
== NULL
)
1953 ret
= dplane_route_update_internal(rn
, re
, old_re
,
1954 DPLANE_OP_ROUTE_UPDATE
);
1960 * Enqueue a route removal for the dataplane.
1962 enum zebra_dplane_result
dplane_route_delete(struct route_node
*rn
,
1963 struct route_entry
*re
)
1965 enum zebra_dplane_result ret
= ZEBRA_DPLANE_REQUEST_FAILURE
;
1967 if (rn
== NULL
|| re
== NULL
)
1970 ret
= dplane_route_update_internal(rn
, re
, NULL
,
1971 DPLANE_OP_ROUTE_DELETE
);
1978 * Notify the dplane when system/connected routes change.
1980 enum zebra_dplane_result
dplane_sys_route_add(struct route_node
*rn
,
1981 struct route_entry
*re
)
1983 enum zebra_dplane_result ret
= ZEBRA_DPLANE_REQUEST_FAILURE
;
1985 /* Ignore this event unless a provider plugin has requested it. */
1986 if (!zdplane_info
.dg_sys_route_notifs
) {
1987 ret
= ZEBRA_DPLANE_REQUEST_SUCCESS
;
1991 if (rn
== NULL
|| re
== NULL
)
1994 ret
= dplane_route_update_internal(rn
, re
, NULL
,
1995 DPLANE_OP_SYS_ROUTE_ADD
);
2002 * Notify the dplane when system/connected routes are deleted.
2004 enum zebra_dplane_result
dplane_sys_route_del(struct route_node
*rn
,
2005 struct route_entry
*re
)
2007 enum zebra_dplane_result ret
= ZEBRA_DPLANE_REQUEST_FAILURE
;
2009 /* Ignore this event unless a provider plugin has requested it. */
2010 if (!zdplane_info
.dg_sys_route_notifs
) {
2011 ret
= ZEBRA_DPLANE_REQUEST_SUCCESS
;
2015 if (rn
== NULL
|| re
== NULL
)
2018 ret
= dplane_route_update_internal(rn
, re
, NULL
,
2019 DPLANE_OP_SYS_ROUTE_DELETE
);
2026 * Update from an async notification, to bring other fibs up-to-date.
2028 enum zebra_dplane_result
2029 dplane_route_notif_update(struct route_node
*rn
,
2030 struct route_entry
*re
,
2031 enum dplane_op_e op
,
2032 struct zebra_dplane_ctx
*ctx
)
2034 enum zebra_dplane_result ret
= ZEBRA_DPLANE_REQUEST_FAILURE
;
2035 struct zebra_dplane_ctx
*new_ctx
= NULL
;
2036 struct nexthop
*nexthop
;
2038 if (rn
== NULL
|| re
== NULL
)
2041 new_ctx
= dplane_ctx_alloc();
2042 if (new_ctx
== NULL
)
2045 /* Init context with info from zebra data structs */
2046 dplane_ctx_route_init(new_ctx
, op
, rn
, re
);
2048 /* For add/update, need to adjust the nexthops so that we match
2049 * the notification state, which may not be the route-entry/RIB
2052 if (op
== DPLANE_OP_ROUTE_UPDATE
||
2053 op
== DPLANE_OP_ROUTE_INSTALL
) {
2055 nexthops_free(new_ctx
->u
.rinfo
.zd_ng
.nexthop
);
2056 new_ctx
->u
.rinfo
.zd_ng
.nexthop
= NULL
;
2058 copy_nexthops(&(new_ctx
->u
.rinfo
.zd_ng
.nexthop
),
2059 (rib_active_nhg(re
))->nexthop
, NULL
);
2061 for (ALL_NEXTHOPS(new_ctx
->u
.rinfo
.zd_ng
, nexthop
))
2062 UNSET_FLAG(nexthop
->flags
, NEXTHOP_FLAG_FIB
);
2066 /* Capture info about the source of the notification, in 'ctx' */
2067 dplane_ctx_set_notif_provider(new_ctx
,
2068 dplane_ctx_get_notif_provider(ctx
));
2070 dplane_update_enqueue(new_ctx
);
2072 ret
= ZEBRA_DPLANE_REQUEST_QUEUED
;
2079 * Enqueue a nexthop add for the dataplane.
2081 enum zebra_dplane_result
dplane_nexthop_add(struct nhg_hash_entry
*nhe
)
2083 enum zebra_dplane_result ret
= ZEBRA_DPLANE_REQUEST_FAILURE
;
2086 ret
= dplane_nexthop_update_internal(nhe
, DPLANE_OP_NH_INSTALL
);
2091 * Enqueue a nexthop update for the dataplane.
2093 * Might not need this func since zebra's nexthop objects should be immutable?
2095 enum zebra_dplane_result
dplane_nexthop_update(struct nhg_hash_entry
*nhe
)
2097 enum zebra_dplane_result ret
= ZEBRA_DPLANE_REQUEST_FAILURE
;
2100 ret
= dplane_nexthop_update_internal(nhe
, DPLANE_OP_NH_UPDATE
);
2105 * Enqueue a nexthop removal for the dataplane.
2107 enum zebra_dplane_result
dplane_nexthop_delete(struct nhg_hash_entry
*nhe
)
2109 enum zebra_dplane_result ret
= ZEBRA_DPLANE_REQUEST_FAILURE
;
2112 ret
= dplane_nexthop_update_internal(nhe
, DPLANE_OP_NH_DELETE
);
2118 * Enqueue LSP add for the dataplane.
2120 enum zebra_dplane_result
dplane_lsp_add(zebra_lsp_t
*lsp
)
2122 enum zebra_dplane_result ret
=
2123 lsp_update_internal(lsp
, DPLANE_OP_LSP_INSTALL
);
2129 * Enqueue LSP update for the dataplane.
2131 enum zebra_dplane_result
dplane_lsp_update(zebra_lsp_t
*lsp
)
2133 enum zebra_dplane_result ret
=
2134 lsp_update_internal(lsp
, DPLANE_OP_LSP_UPDATE
);
2140 * Enqueue LSP delete for the dataplane.
2142 enum zebra_dplane_result
dplane_lsp_delete(zebra_lsp_t
*lsp
)
2144 enum zebra_dplane_result ret
=
2145 lsp_update_internal(lsp
, DPLANE_OP_LSP_DELETE
);
2150 /* Update or un-install resulting from an async notification */
2151 enum zebra_dplane_result
2152 dplane_lsp_notif_update(zebra_lsp_t
*lsp
,
2153 enum dplane_op_e op
,
2154 struct zebra_dplane_ctx
*notif_ctx
)
2156 enum zebra_dplane_result result
= ZEBRA_DPLANE_REQUEST_FAILURE
;
2158 struct zebra_dplane_ctx
*ctx
= NULL
;
2160 /* Obtain context block */
2161 ctx
= dplane_ctx_alloc();
2167 ret
= dplane_ctx_lsp_init(ctx
, op
, lsp
);
2171 /* Capture info about the source of the notification */
2172 dplane_ctx_set_notif_provider(
2174 dplane_ctx_get_notif_provider(notif_ctx
));
2176 ret
= dplane_update_enqueue(ctx
);
2179 /* Update counter */
2180 atomic_fetch_add_explicit(&zdplane_info
.dg_lsps_in
, 1,
2181 memory_order_relaxed
);
2184 result
= ZEBRA_DPLANE_REQUEST_QUEUED
;
2186 atomic_fetch_add_explicit(&zdplane_info
.dg_lsp_errors
, 1,
2187 memory_order_relaxed
);
2189 dplane_ctx_free(&ctx
);
2195 * Enqueue pseudowire install for the dataplane.
2197 enum zebra_dplane_result
dplane_pw_install(struct zebra_pw
*pw
)
2199 return pw_update_internal(pw
, DPLANE_OP_PW_INSTALL
);
2203 * Enqueue pseudowire un-install for the dataplane.
2205 enum zebra_dplane_result
dplane_pw_uninstall(struct zebra_pw
*pw
)
2207 return pw_update_internal(pw
, DPLANE_OP_PW_UNINSTALL
);
2211 * Common internal LSP update utility
2213 static enum zebra_dplane_result
lsp_update_internal(zebra_lsp_t
*lsp
,
2214 enum dplane_op_e op
)
2216 enum zebra_dplane_result result
= ZEBRA_DPLANE_REQUEST_FAILURE
;
2218 struct zebra_dplane_ctx
*ctx
= NULL
;
2220 /* Obtain context block */
2221 ctx
= dplane_ctx_alloc();
2223 ret
= dplane_ctx_lsp_init(ctx
, op
, lsp
);
2227 ret
= dplane_update_enqueue(ctx
);
2230 /* Update counter */
2231 atomic_fetch_add_explicit(&zdplane_info
.dg_lsps_in
, 1,
2232 memory_order_relaxed
);
2235 result
= ZEBRA_DPLANE_REQUEST_QUEUED
;
2237 atomic_fetch_add_explicit(&zdplane_info
.dg_lsp_errors
, 1,
2238 memory_order_relaxed
);
2239 dplane_ctx_free(&ctx
);
2246 * Internal, common handler for pseudowire updates.
2248 static enum zebra_dplane_result
pw_update_internal(struct zebra_pw
*pw
,
2249 enum dplane_op_e op
)
2251 enum zebra_dplane_result result
= ZEBRA_DPLANE_REQUEST_FAILURE
;
2253 struct zebra_dplane_ctx
*ctx
= NULL
;
2255 ctx
= dplane_ctx_alloc();
2257 ret
= dplane_ctx_pw_init(ctx
, op
, pw
);
2261 ret
= dplane_update_enqueue(ctx
);
2264 /* Update counter */
2265 atomic_fetch_add_explicit(&zdplane_info
.dg_pws_in
, 1,
2266 memory_order_relaxed
);
2269 result
= ZEBRA_DPLANE_REQUEST_QUEUED
;
2271 atomic_fetch_add_explicit(&zdplane_info
.dg_pw_errors
, 1,
2272 memory_order_relaxed
);
2273 dplane_ctx_free(&ctx
);
2280 * Enqueue interface address add for the dataplane.
2282 enum zebra_dplane_result
dplane_intf_addr_set(const struct interface
*ifp
,
2283 const struct connected
*ifc
)
2285 #if !defined(HAVE_NETLINK) && defined(HAVE_STRUCT_IFALIASREQ)
2286 /* Extra checks for this OS path. */
2288 /* Don't configure PtP addresses on broadcast ifs or reverse */
2289 if (!(ifp
->flags
& IFF_POINTOPOINT
) != !CONNECTED_PEER(ifc
)) {
2290 if (IS_ZEBRA_DEBUG_KERNEL
|| IS_ZEBRA_DEBUG_DPLANE
)
2291 zlog_debug("Failed to set intf addr: mismatch p2p and connected");
2293 return ZEBRA_DPLANE_REQUEST_FAILURE
;
2296 /* Ensure that no existing installed v4 route conflicts with
2297 * the new interface prefix. This check must be done in the
2298 * zebra pthread context, and any route delete (if needed)
2299 * is enqueued before the interface address programming attempt.
2301 if (ifc
->address
->family
== AF_INET
) {
2302 struct prefix_ipv4
*p
;
2304 p
= (struct prefix_ipv4
*)ifc
->address
;
2305 rib_lookup_and_pushup(p
, ifp
->vrf_id
);
2309 return intf_addr_update_internal(ifp
, ifc
, DPLANE_OP_ADDR_INSTALL
);
2313 * Enqueue interface address remove/uninstall for the dataplane.
2315 enum zebra_dplane_result
dplane_intf_addr_unset(const struct interface
*ifp
,
2316 const struct connected
*ifc
)
2318 return intf_addr_update_internal(ifp
, ifc
, DPLANE_OP_ADDR_UNINSTALL
);
2321 static enum zebra_dplane_result
intf_addr_update_internal(
2322 const struct interface
*ifp
, const struct connected
*ifc
,
2323 enum dplane_op_e op
)
2325 enum zebra_dplane_result result
= ZEBRA_DPLANE_REQUEST_FAILURE
;
2327 struct zebra_dplane_ctx
*ctx
= NULL
;
2328 struct zebra_ns
*zns
;
2330 if (IS_ZEBRA_DEBUG_DPLANE_DETAIL
) {
2331 char addr_str
[PREFIX_STRLEN
];
2333 prefix2str(ifc
->address
, addr_str
, sizeof(addr_str
));
2335 zlog_debug("init intf ctx %s: idx %d, addr %u:%s",
2336 dplane_op2str(op
), ifp
->ifindex
, ifp
->vrf_id
,
2340 ctx
= dplane_ctx_alloc();
2343 ctx
->zd_status
= ZEBRA_DPLANE_REQUEST_SUCCESS
;
2344 ctx
->zd_vrf_id
= ifp
->vrf_id
;
2346 zns
= zebra_ns_lookup(ifp
->vrf_id
);
2347 dplane_ctx_ns_init(ctx
, zns
, false);
2349 /* Init the interface-addr-specific area */
2350 memset(&ctx
->u
.intf
, 0, sizeof(ctx
->u
.intf
));
2352 strlcpy(ctx
->zd_ifname
, ifp
->name
, sizeof(ctx
->zd_ifname
));
2353 ctx
->zd_ifindex
= ifp
->ifindex
;
2354 ctx
->u
.intf
.prefix
= *(ifc
->address
);
2356 if (if_is_broadcast(ifp
))
2357 ctx
->u
.intf
.flags
|= DPLANE_INTF_BROADCAST
;
2359 if (CONNECTED_PEER(ifc
)) {
2360 ctx
->u
.intf
.dest_prefix
= *(ifc
->destination
);
2361 ctx
->u
.intf
.flags
|=
2362 (DPLANE_INTF_CONNECTED
| DPLANE_INTF_HAS_DEST
);
2365 if (CHECK_FLAG(ifc
->flags
, ZEBRA_IFA_SECONDARY
))
2366 ctx
->u
.intf
.flags
|= DPLANE_INTF_SECONDARY
;
2371 ctx
->u
.intf
.flags
|= DPLANE_INTF_HAS_LABEL
;
2373 /* Use embedded buffer if it's adequate; else allocate. */
2374 len
= strlen(ifc
->label
);
2376 if (len
< sizeof(ctx
->u
.intf
.label_buf
)) {
2377 strlcpy(ctx
->u
.intf
.label_buf
, ifc
->label
,
2378 sizeof(ctx
->u
.intf
.label_buf
));
2379 ctx
->u
.intf
.label
= ctx
->u
.intf
.label_buf
;
2381 ctx
->u
.intf
.label
= strdup(ifc
->label
);
2385 ret
= dplane_update_enqueue(ctx
);
2387 /* Increment counter */
2388 atomic_fetch_add_explicit(&zdplane_info
.dg_intf_addrs_in
, 1,
2389 memory_order_relaxed
);
2392 result
= ZEBRA_DPLANE_REQUEST_QUEUED
;
2395 atomic_fetch_add_explicit(&zdplane_info
.dg_intf_addr_errors
,
2396 1, memory_order_relaxed
);
2397 dplane_ctx_free(&ctx
);
2404 * Enqueue vxlan/evpn mac add (or update).
2406 enum zebra_dplane_result
dplane_mac_add(const struct interface
*ifp
,
2407 const struct interface
*bridge_ifp
,
2409 const struct ethaddr
*mac
,
2410 struct in_addr vtep_ip
,
2413 enum zebra_dplane_result result
;
2415 /* Use common helper api */
2416 result
= mac_update_internal(DPLANE_OP_MAC_INSTALL
, ifp
, bridge_ifp
,
2417 vid
, mac
, vtep_ip
, sticky
);
2422 * Enqueue vxlan/evpn mac delete.
2424 enum zebra_dplane_result
dplane_mac_del(const struct interface
*ifp
,
2425 const struct interface
*bridge_ifp
,
2427 const struct ethaddr
*mac
,
2428 struct in_addr vtep_ip
)
2430 enum zebra_dplane_result result
;
2432 /* Use common helper api */
2433 result
= mac_update_internal(DPLANE_OP_MAC_DELETE
, ifp
, bridge_ifp
,
2434 vid
, mac
, vtep_ip
, false);
2439 * Common helper api for MAC address/vxlan updates
2441 static enum zebra_dplane_result
2442 mac_update_internal(enum dplane_op_e op
,
2443 const struct interface
*ifp
,
2444 const struct interface
*br_ifp
,
2446 const struct ethaddr
*mac
,
2447 struct in_addr vtep_ip
,
2450 enum zebra_dplane_result result
= ZEBRA_DPLANE_REQUEST_FAILURE
;
2452 struct zebra_dplane_ctx
*ctx
= NULL
;
2453 struct zebra_ns
*zns
;
2455 if (IS_ZEBRA_DEBUG_DPLANE_DETAIL
) {
2456 char buf1
[ETHER_ADDR_STRLEN
], buf2
[PREFIX_STRLEN
];
2458 zlog_debug("init mac ctx %s: mac %s, ifp %s, vtep %s",
2460 prefix_mac2str(mac
, buf1
, sizeof(buf1
)),
2462 inet_ntop(AF_INET
, &vtep_ip
, buf2
, sizeof(buf2
)));
2465 ctx
= dplane_ctx_alloc();
2468 ctx
->zd_status
= ZEBRA_DPLANE_REQUEST_SUCCESS
;
2469 ctx
->zd_vrf_id
= ifp
->vrf_id
;
2471 zns
= zebra_ns_lookup(ifp
->vrf_id
);
2472 dplane_ctx_ns_init(ctx
, zns
, false);
2474 strlcpy(ctx
->zd_ifname
, ifp
->name
, sizeof(ctx
->zd_ifname
));
2475 ctx
->zd_ifindex
= ifp
->ifindex
;
2477 /* Init the mac-specific data area */
2478 memset(&ctx
->u
.macinfo
, 0, sizeof(ctx
->u
.macinfo
));
2480 ctx
->u
.macinfo
.br_ifindex
= br_ifp
->ifindex
;
2481 ctx
->u
.macinfo
.vtep_ip
= vtep_ip
;
2482 ctx
->u
.macinfo
.mac
= *mac
;
2483 ctx
->u
.macinfo
.vid
= vid
;
2484 ctx
->u
.macinfo
.is_sticky
= sticky
;
2486 /* Enqueue for processing on the dplane pthread */
2487 ret
= dplane_update_enqueue(ctx
);
2489 /* Increment counter */
2490 atomic_fetch_add_explicit(&zdplane_info
.dg_macs_in
, 1,
2491 memory_order_relaxed
);
2494 result
= ZEBRA_DPLANE_REQUEST_QUEUED
;
2497 atomic_fetch_add_explicit(&zdplane_info
.dg_mac_errors
, 1,
2498 memory_order_relaxed
);
2499 dplane_ctx_free(&ctx
);
2506 * Enqueue evpn neighbor add for the dataplane.
2508 enum zebra_dplane_result
dplane_neigh_add(const struct interface
*ifp
,
2509 const struct ipaddr
*ip
,
2510 const struct ethaddr
*mac
,
2513 enum zebra_dplane_result result
= ZEBRA_DPLANE_REQUEST_FAILURE
;
2515 result
= neigh_update_internal(DPLANE_OP_NEIGH_INSTALL
,
2516 ifp
, mac
, ip
, flags
, DPLANE_NUD_NOARP
);
2522 * Enqueue evpn neighbor update for the dataplane.
2524 enum zebra_dplane_result
dplane_neigh_update(const struct interface
*ifp
,
2525 const struct ipaddr
*ip
,
2526 const struct ethaddr
*mac
)
2528 enum zebra_dplane_result result
;
2530 result
= neigh_update_internal(DPLANE_OP_NEIGH_UPDATE
,
2531 ifp
, mac
, ip
, 0, DPLANE_NUD_PROBE
);
2537 * Enqueue evpn neighbor delete for the dataplane.
2539 enum zebra_dplane_result
dplane_neigh_delete(const struct interface
*ifp
,
2540 const struct ipaddr
*ip
)
2542 enum zebra_dplane_result result
;
2544 result
= neigh_update_internal(DPLANE_OP_NEIGH_DELETE
,
2545 ifp
, NULL
, ip
, 0, 0);
2551 * Enqueue evpn VTEP add for the dataplane.
2553 enum zebra_dplane_result
dplane_vtep_add(const struct interface
*ifp
,
2554 const struct in_addr
*ip
,
2557 enum zebra_dplane_result result
;
2558 struct ethaddr mac
= { {0, 0, 0, 0, 0, 0} };
2561 if (IS_ZEBRA_DEBUG_VXLAN
)
2562 zlog_debug("Install %s into flood list for VNI %u intf %s(%u)",
2563 inet_ntoa(*ip
), vni
, ifp
->name
, ifp
->ifindex
);
2565 SET_IPADDR_V4(&addr
);
2566 addr
.ipaddr_v4
= *ip
;
2568 result
= neigh_update_internal(DPLANE_OP_VTEP_ADD
,
2569 ifp
, &mac
, &addr
, 0, 0);
2575 * Enqueue evpn VTEP add for the dataplane.
2577 enum zebra_dplane_result
dplane_vtep_delete(const struct interface
*ifp
,
2578 const struct in_addr
*ip
,
2581 enum zebra_dplane_result result
;
2582 struct ethaddr mac
= { {0, 0, 0, 0, 0, 0} };
2585 if (IS_ZEBRA_DEBUG_VXLAN
)
2587 "Uninstall %s from flood list for VNI %u intf %s(%u)",
2588 inet_ntoa(*ip
), vni
, ifp
->name
, ifp
->ifindex
);
2590 SET_IPADDR_V4(&addr
);
2591 addr
.ipaddr_v4
= *ip
;
2593 result
= neigh_update_internal(DPLANE_OP_VTEP_DELETE
,
2594 ifp
, &mac
, &addr
, 0, 0);
2600 * Common helper api for evpn neighbor updates
2602 static enum zebra_dplane_result
2603 neigh_update_internal(enum dplane_op_e op
,
2604 const struct interface
*ifp
,
2605 const struct ethaddr
*mac
,
2606 const struct ipaddr
*ip
,
2607 uint32_t flags
, uint16_t state
)
2609 enum zebra_dplane_result result
= ZEBRA_DPLANE_REQUEST_FAILURE
;
2611 struct zebra_dplane_ctx
*ctx
= NULL
;
2612 struct zebra_ns
*zns
;
2614 if (IS_ZEBRA_DEBUG_DPLANE_DETAIL
) {
2615 char buf1
[ETHER_ADDR_STRLEN
], buf2
[PREFIX_STRLEN
];
2617 zlog_debug("init neigh ctx %s: ifp %s, mac %s, ip %s",
2619 prefix_mac2str(mac
, buf1
, sizeof(buf1
)),
2621 ipaddr2str(ip
, buf2
, sizeof(buf2
)));
2624 ctx
= dplane_ctx_alloc();
2627 ctx
->zd_status
= ZEBRA_DPLANE_REQUEST_SUCCESS
;
2628 ctx
->zd_vrf_id
= ifp
->vrf_id
;
2630 zns
= zebra_ns_lookup(ifp
->vrf_id
);
2631 dplane_ctx_ns_init(ctx
, zns
, false);
2633 strlcpy(ctx
->zd_ifname
, ifp
->name
, sizeof(ctx
->zd_ifname
));
2634 ctx
->zd_ifindex
= ifp
->ifindex
;
2636 /* Init the neighbor-specific data area */
2637 memset(&ctx
->u
.neigh
, 0, sizeof(ctx
->u
.neigh
));
2639 ctx
->u
.neigh
.ip_addr
= *ip
;
2641 ctx
->u
.neigh
.mac
= *mac
;
2642 ctx
->u
.neigh
.flags
= flags
;
2643 ctx
->u
.neigh
.state
= state
;
2645 /* Enqueue for processing on the dplane pthread */
2646 ret
= dplane_update_enqueue(ctx
);
2648 /* Increment counter */
2649 atomic_fetch_add_explicit(&zdplane_info
.dg_neighs_in
, 1,
2650 memory_order_relaxed
);
2653 result
= ZEBRA_DPLANE_REQUEST_QUEUED
;
2656 atomic_fetch_add_explicit(&zdplane_info
.dg_neigh_errors
, 1,
2657 memory_order_relaxed
);
2658 dplane_ctx_free(&ctx
);
2665 * Handler for 'show dplane'
2667 int dplane_show_helper(struct vty
*vty
, bool detailed
)
2669 uint64_t queued
, queue_max
, limit
, errs
, incoming
, yields
,
2672 /* Using atomics because counters are being changed in different
2675 incoming
= atomic_load_explicit(&zdplane_info
.dg_routes_in
,
2676 memory_order_relaxed
);
2677 limit
= atomic_load_explicit(&zdplane_info
.dg_max_queued_updates
,
2678 memory_order_relaxed
);
2679 queued
= atomic_load_explicit(&zdplane_info
.dg_routes_queued
,
2680 memory_order_relaxed
);
2681 queue_max
= atomic_load_explicit(&zdplane_info
.dg_routes_queued_max
,
2682 memory_order_relaxed
);
2683 errs
= atomic_load_explicit(&zdplane_info
.dg_route_errors
,
2684 memory_order_relaxed
);
2685 yields
= atomic_load_explicit(&zdplane_info
.dg_update_yields
,
2686 memory_order_relaxed
);
2687 other_errs
= atomic_load_explicit(&zdplane_info
.dg_other_errors
,
2688 memory_order_relaxed
);
2690 vty_out(vty
, "Zebra dataplane:\nRoute updates: %"PRIu64
"\n",
2692 vty_out(vty
, "Route update errors: %"PRIu64
"\n", errs
);
2693 vty_out(vty
, "Other errors : %"PRIu64
"\n", other_errs
);
2694 vty_out(vty
, "Route update queue limit: %"PRIu64
"\n", limit
);
2695 vty_out(vty
, "Route update queue depth: %"PRIu64
"\n", queued
);
2696 vty_out(vty
, "Route update queue max: %"PRIu64
"\n", queue_max
);
2697 vty_out(vty
, "Dplane update yields: %"PRIu64
"\n", yields
);
2699 incoming
= atomic_load_explicit(&zdplane_info
.dg_lsps_in
,
2700 memory_order_relaxed
);
2701 errs
= atomic_load_explicit(&zdplane_info
.dg_lsp_errors
,
2702 memory_order_relaxed
);
2703 vty_out(vty
, "LSP updates: %"PRIu64
"\n", incoming
);
2704 vty_out(vty
, "LSP update errors: %"PRIu64
"\n", errs
);
2706 incoming
= atomic_load_explicit(&zdplane_info
.dg_pws_in
,
2707 memory_order_relaxed
);
2708 errs
= atomic_load_explicit(&zdplane_info
.dg_pw_errors
,
2709 memory_order_relaxed
);
2710 vty_out(vty
, "PW updates: %"PRIu64
"\n", incoming
);
2711 vty_out(vty
, "PW update errors: %"PRIu64
"\n", errs
);
2713 incoming
= atomic_load_explicit(&zdplane_info
.dg_intf_addrs_in
,
2714 memory_order_relaxed
);
2715 errs
= atomic_load_explicit(&zdplane_info
.dg_intf_addr_errors
,
2716 memory_order_relaxed
);
2717 vty_out(vty
, "Intf addr updates: %"PRIu64
"\n", incoming
);
2718 vty_out(vty
, "Intf addr errors: %"PRIu64
"\n", errs
);
2720 incoming
= atomic_load_explicit(&zdplane_info
.dg_macs_in
,
2721 memory_order_relaxed
);
2722 errs
= atomic_load_explicit(&zdplane_info
.dg_mac_errors
,
2723 memory_order_relaxed
);
2724 vty_out(vty
, "EVPN MAC updates: %"PRIu64
"\n", incoming
);
2725 vty_out(vty
, "EVPN MAC errors: %"PRIu64
"\n", errs
);
2727 incoming
= atomic_load_explicit(&zdplane_info
.dg_neighs_in
,
2728 memory_order_relaxed
);
2729 errs
= atomic_load_explicit(&zdplane_info
.dg_neigh_errors
,
2730 memory_order_relaxed
);
2731 vty_out(vty
, "EVPN neigh updates: %"PRIu64
"\n", incoming
);
2732 vty_out(vty
, "EVPN neigh errors: %"PRIu64
"\n", errs
);
2738 * Handler for 'show dplane providers'
2740 int dplane_show_provs_helper(struct vty
*vty
, bool detailed
)
2742 struct zebra_dplane_provider
*prov
;
2743 uint64_t in
, in_max
, out
, out_max
;
2745 vty_out(vty
, "Zebra dataplane providers:\n");
2748 prov
= TAILQ_FIRST(&zdplane_info
.dg_providers_q
);
2751 /* Show counters, useful info from each registered provider */
2754 in
= atomic_load_explicit(&prov
->dp_in_counter
,
2755 memory_order_relaxed
);
2756 in_max
= atomic_load_explicit(&prov
->dp_in_max
,
2757 memory_order_relaxed
);
2758 out
= atomic_load_explicit(&prov
->dp_out_counter
,
2759 memory_order_relaxed
);
2760 out_max
= atomic_load_explicit(&prov
->dp_out_max
,
2761 memory_order_relaxed
);
2763 vty_out(vty
, "%s (%u): in: %"PRIu64
", q_max: %"PRIu64
", "
2764 "out: %"PRIu64
", q_max: %"PRIu64
"\n",
2765 prov
->dp_name
, prov
->dp_id
, in
, in_max
, out
, out_max
);
2768 prov
= TAILQ_NEXT(prov
, dp_prov_link
);
2776 * Helper for 'show run' etc.
2778 int dplane_config_write_helper(struct vty
*vty
)
2780 if (zdplane_info
.dg_max_queued_updates
!= DPLANE_DEFAULT_MAX_QUEUED
)
2781 vty_out(vty
, "zebra dplane limit %u\n",
2782 zdplane_info
.dg_max_queued_updates
);
2788 * Provider registration
2790 int dplane_provider_register(const char *name
,
2791 enum dplane_provider_prio prio
,
2793 int (*start_fp
)(struct zebra_dplane_provider
*),
2794 int (*fp
)(struct zebra_dplane_provider
*),
2795 int (*fini_fp
)(struct zebra_dplane_provider
*,
2798 struct zebra_dplane_provider
**prov_p
)
2801 struct zebra_dplane_provider
*p
= NULL
, *last
;
2809 if (prio
<= DPLANE_PRIO_NONE
||
2810 prio
> DPLANE_PRIO_LAST
) {
2815 /* Allocate and init new provider struct */
2816 p
= XCALLOC(MTYPE_DP_PROV
, sizeof(struct zebra_dplane_provider
));
2818 pthread_mutex_init(&(p
->dp_mutex
), NULL
);
2819 TAILQ_INIT(&(p
->dp_ctx_in_q
));
2820 TAILQ_INIT(&(p
->dp_ctx_out_q
));
2822 p
->dp_flags
= flags
;
2823 p
->dp_priority
= prio
;
2825 p
->dp_start
= start_fp
;
2826 p
->dp_fini
= fini_fp
;
2829 /* Lock - the dplane pthread may be running */
2832 p
->dp_id
= ++zdplane_info
.dg_provider_id
;
2835 strlcpy(p
->dp_name
, name
, DPLANE_PROVIDER_NAMELEN
);
2837 snprintf(p
->dp_name
, DPLANE_PROVIDER_NAMELEN
,
2838 "provider-%u", p
->dp_id
);
2840 /* Insert into list ordered by priority */
2841 TAILQ_FOREACH(last
, &zdplane_info
.dg_providers_q
, dp_prov_link
) {
2842 if (last
->dp_priority
> p
->dp_priority
)
2847 TAILQ_INSERT_BEFORE(last
, p
, dp_prov_link
);
2849 TAILQ_INSERT_TAIL(&zdplane_info
.dg_providers_q
, p
,
2855 if (IS_ZEBRA_DEBUG_DPLANE
)
2856 zlog_debug("dplane: registered new provider '%s' (%u), prio %d",
2857 p
->dp_name
, p
->dp_id
, p
->dp_priority
);
2866 /* Accessors for provider attributes */
2867 const char *dplane_provider_get_name(const struct zebra_dplane_provider
*prov
)
2869 return prov
->dp_name
;
2872 uint32_t dplane_provider_get_id(const struct zebra_dplane_provider
*prov
)
2877 void *dplane_provider_get_data(const struct zebra_dplane_provider
*prov
)
2879 return prov
->dp_data
;
2882 int dplane_provider_get_work_limit(const struct zebra_dplane_provider
*prov
)
2884 return zdplane_info
.dg_updates_per_cycle
;
2887 /* Lock/unlock a provider's mutex - iff the provider was registered with
2888 * the THREADED flag.
2890 void dplane_provider_lock(struct zebra_dplane_provider
*prov
)
2892 if (dplane_provider_is_threaded(prov
))
2893 DPLANE_PROV_LOCK(prov
);
2896 void dplane_provider_unlock(struct zebra_dplane_provider
*prov
)
2898 if (dplane_provider_is_threaded(prov
))
2899 DPLANE_PROV_UNLOCK(prov
);
2903 * Dequeue and maintain associated counter
2905 struct zebra_dplane_ctx
*dplane_provider_dequeue_in_ctx(
2906 struct zebra_dplane_provider
*prov
)
2908 struct zebra_dplane_ctx
*ctx
= NULL
;
2910 dplane_provider_lock(prov
);
2912 ctx
= TAILQ_FIRST(&(prov
->dp_ctx_in_q
));
2914 TAILQ_REMOVE(&(prov
->dp_ctx_in_q
), ctx
, zd_q_entries
);
2916 atomic_fetch_sub_explicit(&prov
->dp_in_queued
, 1,
2917 memory_order_relaxed
);
2920 dplane_provider_unlock(prov
);
2926 * Dequeue work to a list, return count
2928 int dplane_provider_dequeue_in_list(struct zebra_dplane_provider
*prov
,
2929 struct dplane_ctx_q
*listp
)
2932 struct zebra_dplane_ctx
*ctx
;
2934 limit
= zdplane_info
.dg_updates_per_cycle
;
2936 dplane_provider_lock(prov
);
2938 for (ret
= 0; ret
< limit
; ret
++) {
2939 ctx
= TAILQ_FIRST(&(prov
->dp_ctx_in_q
));
2941 TAILQ_REMOVE(&(prov
->dp_ctx_in_q
), ctx
, zd_q_entries
);
2943 TAILQ_INSERT_TAIL(listp
, ctx
, zd_q_entries
);
2950 atomic_fetch_sub_explicit(&prov
->dp_in_queued
, ret
,
2951 memory_order_relaxed
);
2953 dplane_provider_unlock(prov
);
2959 * Enqueue and maintain associated counter
2961 void dplane_provider_enqueue_out_ctx(struct zebra_dplane_provider
*prov
,
2962 struct zebra_dplane_ctx
*ctx
)
2964 dplane_provider_lock(prov
);
2966 TAILQ_INSERT_TAIL(&(prov
->dp_ctx_out_q
), ctx
,
2969 dplane_provider_unlock(prov
);
2971 atomic_fetch_add_explicit(&(prov
->dp_out_counter
), 1,
2972 memory_order_relaxed
);
2976 * Accessor for provider object
2978 bool dplane_provider_is_threaded(const struct zebra_dplane_provider
*prov
)
2980 return (prov
->dp_flags
& DPLANE_PROV_FLAG_THREADED
);
2984 * Internal helper that copies information from a zebra ns object; this is
2985 * called in the zebra main pthread context as part of dplane ctx init.
2987 static void dplane_info_from_zns(struct zebra_dplane_info
*ns_info
,
2988 struct zebra_ns
*zns
)
2990 ns_info
->ns_id
= zns
->ns_id
;
2992 #if defined(HAVE_NETLINK)
2993 ns_info
->is_cmd
= true;
2994 ns_info
->nls
= zns
->netlink_dplane
;
2995 #endif /* NETLINK */
2999 * Provider api to signal that work/events are available
3000 * for the dataplane pthread.
3002 int dplane_provider_work_ready(void)
3004 /* Note that during zebra startup, we may be offered work before
3005 * the dataplane pthread (and thread-master) are ready. We want to
3006 * enqueue the work, but the event-scheduling machinery may not be
3009 if (zdplane_info
.dg_run
) {
3010 thread_add_event(zdplane_info
.dg_master
,
3011 dplane_thread_loop
, NULL
, 0,
3012 &zdplane_info
.dg_t_update
);
3019 * Enqueue a context directly to zebra main.
3021 void dplane_provider_enqueue_to_zebra(struct zebra_dplane_ctx
*ctx
)
3023 struct dplane_ctx_q temp_list
;
3025 /* Zebra's api takes a list, so we need to use a temporary list */
3026 TAILQ_INIT(&temp_list
);
3028 TAILQ_INSERT_TAIL(&temp_list
, ctx
, zd_q_entries
);
3029 (zdplane_info
.dg_results_cb
)(&temp_list
);
3033 * Kernel dataplane provider
3037 * Handler for kernel LSP updates
3039 static enum zebra_dplane_result
3040 kernel_dplane_lsp_update(struct zebra_dplane_ctx
*ctx
)
3042 enum zebra_dplane_result res
;
3044 /* Call into the synchronous kernel-facing code here */
3045 res
= kernel_lsp_update(ctx
);
3047 if (res
!= ZEBRA_DPLANE_REQUEST_SUCCESS
)
3048 atomic_fetch_add_explicit(
3049 &zdplane_info
.dg_lsp_errors
, 1,
3050 memory_order_relaxed
);
3056 * Handler for kernel pseudowire updates
3058 static enum zebra_dplane_result
3059 kernel_dplane_pw_update(struct zebra_dplane_ctx
*ctx
)
3061 enum zebra_dplane_result res
;
3063 if (IS_ZEBRA_DEBUG_DPLANE_DETAIL
)
3064 zlog_debug("Dplane pw %s: op %s af %d loc: %u rem: %u",
3065 dplane_ctx_get_ifname(ctx
),
3066 dplane_op2str(ctx
->zd_op
),
3067 dplane_ctx_get_pw_af(ctx
),
3068 dplane_ctx_get_pw_local_label(ctx
),
3069 dplane_ctx_get_pw_remote_label(ctx
));
3071 res
= kernel_pw_update(ctx
);
3073 if (res
!= ZEBRA_DPLANE_REQUEST_SUCCESS
)
3074 atomic_fetch_add_explicit(
3075 &zdplane_info
.dg_pw_errors
, 1,
3076 memory_order_relaxed
);
3082 * Handler for kernel route updates
3084 static enum zebra_dplane_result
3085 kernel_dplane_route_update(struct zebra_dplane_ctx
*ctx
)
3087 enum zebra_dplane_result res
;
3089 if (IS_ZEBRA_DEBUG_DPLANE_DETAIL
) {
3090 char dest_str
[PREFIX_STRLEN
];
3092 prefix2str(dplane_ctx_get_dest(ctx
),
3093 dest_str
, sizeof(dest_str
));
3095 zlog_debug("%u:%s Dplane route update ctx %p op %s",
3096 dplane_ctx_get_vrf(ctx
), dest_str
,
3097 ctx
, dplane_op2str(dplane_ctx_get_op(ctx
)));
3100 /* Call into the synchronous kernel-facing code here */
3101 res
= kernel_route_update(ctx
);
3103 if (res
!= ZEBRA_DPLANE_REQUEST_SUCCESS
)
3104 atomic_fetch_add_explicit(
3105 &zdplane_info
.dg_route_errors
, 1,
3106 memory_order_relaxed
);
3112 * Handler for kernel-facing interface address updates
3114 static enum zebra_dplane_result
3115 kernel_dplane_address_update(struct zebra_dplane_ctx
*ctx
)
3117 enum zebra_dplane_result res
;
3119 if (IS_ZEBRA_DEBUG_DPLANE_DETAIL
) {
3120 char dest_str
[PREFIX_STRLEN
];
3122 prefix2str(dplane_ctx_get_intf_addr(ctx
), dest_str
,
3125 zlog_debug("Dplane intf %s, idx %u, addr %s",
3126 dplane_op2str(dplane_ctx_get_op(ctx
)),
3127 dplane_ctx_get_ifindex(ctx
), dest_str
);
3130 res
= kernel_address_update_ctx(ctx
);
3132 if (res
!= ZEBRA_DPLANE_REQUEST_SUCCESS
)
3133 atomic_fetch_add_explicit(&zdplane_info
.dg_intf_addr_errors
,
3134 1, memory_order_relaxed
);
3140 * kernel_dplane_nexthop_update() - Handler for kernel nexthop updates
3142 * @ctx: Dataplane context
3144 * Return: Dataplane result flag
3146 static enum zebra_dplane_result
3147 kernel_dplane_nexthop_update(struct zebra_dplane_ctx
*ctx
)
3149 enum zebra_dplane_result res
;
3151 if (IS_ZEBRA_DEBUG_DPLANE_DETAIL
) {
3152 zlog_debug("ID (%u) Dplane nexthop update ctx %p op %s",
3153 dplane_ctx_get_nhe_id(ctx
), ctx
,
3154 dplane_op2str(dplane_ctx_get_op(ctx
)));
3157 res
= kernel_nexthop_update(ctx
);
3159 if (res
!= ZEBRA_DPLANE_REQUEST_SUCCESS
)
3160 atomic_fetch_add_explicit(&zdplane_info
.dg_nexthop_errors
, 1,
3161 memory_order_relaxed
);
3167 * Handler for kernel-facing EVPN MAC address updates
3169 static enum zebra_dplane_result
3170 kernel_dplane_mac_update(struct zebra_dplane_ctx
*ctx
)
3172 enum zebra_dplane_result res
;
3174 if (IS_ZEBRA_DEBUG_DPLANE_DETAIL
) {
3175 char buf
[ETHER_ADDR_STRLEN
];
3177 prefix_mac2str(dplane_ctx_mac_get_addr(ctx
), buf
,
3180 zlog_debug("Dplane %s, mac %s, ifindex %u",
3181 dplane_op2str(dplane_ctx_get_op(ctx
)),
3182 buf
, dplane_ctx_get_ifindex(ctx
));
3185 res
= kernel_mac_update_ctx(ctx
);
3187 if (res
!= ZEBRA_DPLANE_REQUEST_SUCCESS
)
3188 atomic_fetch_add_explicit(&zdplane_info
.dg_mac_errors
,
3189 1, memory_order_relaxed
);
3195 * Handler for kernel-facing EVPN neighbor updates
3197 static enum zebra_dplane_result
3198 kernel_dplane_neigh_update(struct zebra_dplane_ctx
*ctx
)
3200 enum zebra_dplane_result res
;
3202 if (IS_ZEBRA_DEBUG_DPLANE_DETAIL
) {
3203 char buf
[PREFIX_STRLEN
];
3205 ipaddr2str(dplane_ctx_neigh_get_ipaddr(ctx
), buf
,
3208 zlog_debug("Dplane %s, ip %s, ifindex %u",
3209 dplane_op2str(dplane_ctx_get_op(ctx
)),
3210 buf
, dplane_ctx_get_ifindex(ctx
));
3213 res
= kernel_neigh_update_ctx(ctx
);
3215 if (res
!= ZEBRA_DPLANE_REQUEST_SUCCESS
)
3216 atomic_fetch_add_explicit(&zdplane_info
.dg_neigh_errors
,
3217 1, memory_order_relaxed
);
3223 * Kernel provider callback
3225 static int kernel_dplane_process_func(struct zebra_dplane_provider
*prov
)
3227 enum zebra_dplane_result res
;
3228 struct zebra_dplane_ctx
*ctx
;
3231 limit
= dplane_provider_get_work_limit(prov
);
3233 if (IS_ZEBRA_DEBUG_DPLANE_DETAIL
)
3234 zlog_debug("dplane provider '%s': processing",
3235 dplane_provider_get_name(prov
));
3237 for (counter
= 0; counter
< limit
; counter
++) {
3239 ctx
= dplane_provider_dequeue_in_ctx(prov
);
3243 /* A previous provider plugin may have asked to skip the
3246 if (dplane_ctx_is_skip_kernel(ctx
)) {
3247 res
= ZEBRA_DPLANE_REQUEST_SUCCESS
;
3251 /* Dispatch to appropriate kernel-facing apis */
3252 switch (dplane_ctx_get_op(ctx
)) {
3254 case DPLANE_OP_ROUTE_INSTALL
:
3255 case DPLANE_OP_ROUTE_UPDATE
:
3256 case DPLANE_OP_ROUTE_DELETE
:
3257 res
= kernel_dplane_route_update(ctx
);
3260 case DPLANE_OP_NH_INSTALL
:
3261 case DPLANE_OP_NH_UPDATE
:
3262 case DPLANE_OP_NH_DELETE
:
3263 res
= kernel_dplane_nexthop_update(ctx
);
3266 case DPLANE_OP_LSP_INSTALL
:
3267 case DPLANE_OP_LSP_UPDATE
:
3268 case DPLANE_OP_LSP_DELETE
:
3269 res
= kernel_dplane_lsp_update(ctx
);
3272 case DPLANE_OP_PW_INSTALL
:
3273 case DPLANE_OP_PW_UNINSTALL
:
3274 res
= kernel_dplane_pw_update(ctx
);
3277 case DPLANE_OP_ADDR_INSTALL
:
3278 case DPLANE_OP_ADDR_UNINSTALL
:
3279 res
= kernel_dplane_address_update(ctx
);
3282 case DPLANE_OP_MAC_INSTALL
:
3283 case DPLANE_OP_MAC_DELETE
:
3284 res
= kernel_dplane_mac_update(ctx
);
3287 case DPLANE_OP_NEIGH_INSTALL
:
3288 case DPLANE_OP_NEIGH_UPDATE
:
3289 case DPLANE_OP_NEIGH_DELETE
:
3290 case DPLANE_OP_VTEP_ADD
:
3291 case DPLANE_OP_VTEP_DELETE
:
3292 res
= kernel_dplane_neigh_update(ctx
);
3295 /* Ignore 'notifications' - no-op */
3296 case DPLANE_OP_SYS_ROUTE_ADD
:
3297 case DPLANE_OP_SYS_ROUTE_DELETE
:
3298 case DPLANE_OP_ROUTE_NOTIFY
:
3299 case DPLANE_OP_LSP_NOTIFY
:
3300 res
= ZEBRA_DPLANE_REQUEST_SUCCESS
;
3304 atomic_fetch_add_explicit(
3305 &zdplane_info
.dg_other_errors
, 1,
3306 memory_order_relaxed
);
3308 res
= ZEBRA_DPLANE_REQUEST_FAILURE
;
3313 dplane_ctx_set_status(ctx
, res
);
3315 dplane_provider_enqueue_out_ctx(prov
, ctx
);
3318 /* Ensure that we'll run the work loop again if there's still
3321 if (counter
>= limit
) {
3322 if (IS_ZEBRA_DEBUG_DPLANE_DETAIL
)
3323 zlog_debug("dplane provider '%s' reached max updates %d",
3324 dplane_provider_get_name(prov
), counter
);
3326 atomic_fetch_add_explicit(&zdplane_info
.dg_update_yields
,
3327 1, memory_order_relaxed
);
3329 dplane_provider_work_ready();
3335 #if DPLANE_TEST_PROVIDER
3338 * Test dataplane provider plugin
3342 * Test provider process callback
3344 static int test_dplane_process_func(struct zebra_dplane_provider
*prov
)
3346 struct zebra_dplane_ctx
*ctx
;
3349 /* Just moving from 'in' queue to 'out' queue */
3351 if (IS_ZEBRA_DEBUG_DPLANE_DETAIL
)
3352 zlog_debug("dplane provider '%s': processing",
3353 dplane_provider_get_name(prov
));
3355 limit
= dplane_provider_get_work_limit(prov
);
3357 for (counter
= 0; counter
< limit
; counter
++) {
3359 ctx
= dplane_provider_dequeue_in_ctx(prov
);
3363 if (IS_ZEBRA_DEBUG_DPLANE_DETAIL
)
3364 zlog_debug("dplane provider '%s': op %s",
3365 dplane_provider_get_name(prov
),
3366 dplane_op2str(dplane_ctx_get_op(ctx
)));
3368 dplane_ctx_set_status(ctx
, ZEBRA_DPLANE_REQUEST_SUCCESS
);
3370 dplane_provider_enqueue_out_ctx(prov
, ctx
);
3373 if (IS_ZEBRA_DEBUG_DPLANE_DETAIL
)
3374 zlog_debug("dplane provider '%s': processed %d",
3375 dplane_provider_get_name(prov
), counter
);
3377 /* Ensure that we'll run the work loop again if there's still
3380 if (counter
>= limit
)
3381 dplane_provider_work_ready();
3387 * Test provider shutdown/fini callback
3389 static int test_dplane_shutdown_func(struct zebra_dplane_provider
*prov
,
3392 if (IS_ZEBRA_DEBUG_DPLANE
)
3393 zlog_debug("dplane provider '%s': %sshutdown",
3394 dplane_provider_get_name(prov
),
3395 early
? "early " : "");
3399 #endif /* DPLANE_TEST_PROVIDER */
3402 * Register default kernel provider
3404 static void dplane_provider_init(void)
3408 ret
= dplane_provider_register("Kernel",
3410 DPLANE_PROV_FLAGS_DEFAULT
, NULL
,
3411 kernel_dplane_process_func
,
3416 zlog_err("Unable to register kernel dplane provider: %d",
3419 #if DPLANE_TEST_PROVIDER
3420 /* Optional test provider ... */
3421 ret
= dplane_provider_register("Test",
3422 DPLANE_PRIO_PRE_KERNEL
,
3423 DPLANE_PROV_FLAGS_DEFAULT
, NULL
,
3424 test_dplane_process_func
,
3425 test_dplane_shutdown_func
,
3426 NULL
/* data */, NULL
);
3429 zlog_err("Unable to register test dplane provider: %d",
3431 #endif /* DPLANE_TEST_PROVIDER */
3434 /* Indicates zebra shutdown/exit is in progress. Some operations may be
3435 * simplified or skipped during shutdown processing.
3437 bool dplane_is_in_shutdown(void)
3439 return zdplane_info
.dg_is_shutdown
;
3443 * Early or pre-shutdown, de-init notification api. This runs pretty
3444 * early during zebra shutdown, as a signal to stop new work and prepare
3445 * for updates generated by shutdown/cleanup activity, as zebra tries to
3446 * remove everything it's responsible for.
3447 * NB: This runs in the main zebra pthread context.
3449 void zebra_dplane_pre_finish(void)
3451 if (IS_ZEBRA_DEBUG_DPLANE
)
3452 zlog_debug("Zebra dataplane pre-fini called");
3454 zdplane_info
.dg_is_shutdown
= true;
3456 /* TODO -- Notify provider(s) of pending shutdown */
3460 * Utility to determine whether work remains enqueued within the dplane;
3461 * used during system shutdown processing.
3463 static bool dplane_work_pending(void)
3466 struct zebra_dplane_ctx
*ctx
;
3467 struct zebra_dplane_provider
*prov
;
3469 /* TODO -- just checking incoming/pending work for now, must check
3474 ctx
= TAILQ_FIRST(&zdplane_info
.dg_update_ctx_q
);
3475 prov
= TAILQ_FIRST(&zdplane_info
.dg_providers_q
);
3486 dplane_provider_lock(prov
);
3488 ctx
= TAILQ_FIRST(&(prov
->dp_ctx_in_q
));
3490 ctx
= TAILQ_FIRST(&(prov
->dp_ctx_out_q
));
3492 dplane_provider_unlock(prov
);
3498 prov
= TAILQ_NEXT(prov
, dp_prov_link
);
3510 * Shutdown-time intermediate callback, used to determine when all pending
3511 * in-flight updates are done. If there's still work to do, reschedules itself.
3512 * If all work is done, schedules an event to the main zebra thread for
3513 * final zebra shutdown.
3514 * This runs in the dplane pthread context.
3516 static int dplane_check_shutdown_status(struct thread
*event
)
3518 if (IS_ZEBRA_DEBUG_DPLANE
)
3519 zlog_debug("Zebra dataplane shutdown status check called");
3521 if (dplane_work_pending()) {
3522 /* Reschedule dplane check on a short timer */
3523 thread_add_timer_msec(zdplane_info
.dg_master
,
3524 dplane_check_shutdown_status
,
3526 &zdplane_info
.dg_t_shutdown_check
);
3528 /* TODO - give up and stop waiting after a short time? */
3531 /* We appear to be done - schedule a final callback event
3532 * for the zebra main pthread.
3534 thread_add_event(zrouter
.master
, zebra_finalize
, NULL
, 0, NULL
);
3541 * Shutdown, de-init api. This runs pretty late during shutdown,
3542 * after zebra has tried to free/remove/uninstall all routes during shutdown.
3543 * At this point, dplane work may still remain to be done, so we can't just
3544 * blindly terminate. If there's still work to do, we'll periodically check
3545 * and when done, we'll enqueue a task to the zebra main thread for final
3546 * termination processing.
3548 * NB: This runs in the main zebra thread context.
3550 void zebra_dplane_finish(void)
3552 if (IS_ZEBRA_DEBUG_DPLANE
)
3553 zlog_debug("Zebra dataplane fini called");
3555 thread_add_event(zdplane_info
.dg_master
,
3556 dplane_check_shutdown_status
, NULL
, 0,
3557 &zdplane_info
.dg_t_shutdown_check
);
3561 * Main dataplane pthread event loop. The thread takes new incoming work
3562 * and offers it to the first provider. It then iterates through the
3563 * providers, taking complete work from each one and offering it
3564 * to the next in order. At each step, a limited number of updates are
3565 * processed during a cycle in order to provide some fairness.
3567 * This loop through the providers is only run once, so that the dataplane
3568 * pthread can look for other pending work - such as i/o work on behalf of
3571 static int dplane_thread_loop(struct thread
*event
)
3573 struct dplane_ctx_q work_list
;
3574 struct dplane_ctx_q error_list
;
3575 struct zebra_dplane_provider
*prov
;
3576 struct zebra_dplane_ctx
*ctx
, *tctx
;
3577 int limit
, counter
, error_counter
;
3578 uint64_t curr
, high
;
3580 /* Capture work limit per cycle */
3581 limit
= zdplane_info
.dg_updates_per_cycle
;
3583 /* Init temporary lists used to move contexts among providers */
3584 TAILQ_INIT(&work_list
);
3585 TAILQ_INIT(&error_list
);
3588 /* Check for zebra shutdown */
3589 if (!zdplane_info
.dg_run
)
3592 /* Dequeue some incoming work from zebra (if any) onto the temporary
3597 /* Locate initial registered provider */
3598 prov
= TAILQ_FIRST(&zdplane_info
.dg_providers_q
);
3600 /* Move new work from incoming list to temp list */
3601 for (counter
= 0; counter
< limit
; counter
++) {
3602 ctx
= TAILQ_FIRST(&zdplane_info
.dg_update_ctx_q
);
3604 TAILQ_REMOVE(&zdplane_info
.dg_update_ctx_q
, ctx
,
3607 ctx
->zd_provider
= prov
->dp_id
;
3609 TAILQ_INSERT_TAIL(&work_list
, ctx
, zd_q_entries
);
3617 atomic_fetch_sub_explicit(&zdplane_info
.dg_routes_queued
, counter
,
3618 memory_order_relaxed
);
3620 if (IS_ZEBRA_DEBUG_DPLANE_DETAIL
)
3621 zlog_debug("dplane: incoming new work counter: %d", counter
);
3623 /* Iterate through the registered providers, offering new incoming
3624 * work. If the provider has outgoing work in its queue, take that
3625 * work for the next provider
3629 /* At each iteration, the temporary work list has 'counter'
3632 if (IS_ZEBRA_DEBUG_DPLANE_DETAIL
)
3633 zlog_debug("dplane enqueues %d new work to provider '%s'",
3634 counter
, dplane_provider_get_name(prov
));
3636 /* Capture current provider id in each context; check for
3639 TAILQ_FOREACH_SAFE(ctx
, &work_list
, zd_q_entries
, tctx
) {
3640 if (dplane_ctx_get_status(ctx
) ==
3641 ZEBRA_DPLANE_REQUEST_SUCCESS
) {
3642 ctx
->zd_provider
= prov
->dp_id
;
3645 * TODO -- improve error-handling: recirc
3646 * errors backwards so that providers can
3647 * 'undo' their work (if they want to)
3650 /* Move to error list; will be returned
3653 TAILQ_REMOVE(&work_list
, ctx
, zd_q_entries
);
3654 TAILQ_INSERT_TAIL(&error_list
,
3660 /* Enqueue new work to the provider */
3661 dplane_provider_lock(prov
);
3663 if (TAILQ_FIRST(&work_list
))
3664 TAILQ_CONCAT(&(prov
->dp_ctx_in_q
), &work_list
,
3667 atomic_fetch_add_explicit(&prov
->dp_in_counter
, counter
,
3668 memory_order_relaxed
);
3669 atomic_fetch_add_explicit(&prov
->dp_in_queued
, counter
,
3670 memory_order_relaxed
);
3671 curr
= atomic_load_explicit(&prov
->dp_in_queued
,
3672 memory_order_relaxed
);
3673 high
= atomic_load_explicit(&prov
->dp_in_max
,
3674 memory_order_relaxed
);
3676 atomic_store_explicit(&prov
->dp_in_max
, curr
,
3677 memory_order_relaxed
);
3679 dplane_provider_unlock(prov
);
3681 /* Reset the temp list (though the 'concat' may have done this
3682 * already), and the counter
3684 TAILQ_INIT(&work_list
);
3687 /* Call into the provider code. Note that this is
3688 * unconditional: we offer to do work even if we don't enqueue
3691 (*prov
->dp_fp
)(prov
);
3693 /* Check for zebra shutdown */
3694 if (!zdplane_info
.dg_run
)
3697 /* Dequeue completed work from the provider */
3698 dplane_provider_lock(prov
);
3700 while (counter
< limit
) {
3701 ctx
= TAILQ_FIRST(&(prov
->dp_ctx_out_q
));
3703 TAILQ_REMOVE(&(prov
->dp_ctx_out_q
), ctx
,
3706 TAILQ_INSERT_TAIL(&work_list
,
3713 dplane_provider_unlock(prov
);
3715 if (IS_ZEBRA_DEBUG_DPLANE_DETAIL
)
3716 zlog_debug("dplane dequeues %d completed work from provider %s",
3717 counter
, dplane_provider_get_name(prov
));
3719 /* Locate next provider */
3721 prov
= TAILQ_NEXT(prov
, dp_prov_link
);
3725 /* After all providers have been serviced, enqueue any completed
3726 * work and any errors back to zebra so it can process the results.
3728 if (IS_ZEBRA_DEBUG_DPLANE_DETAIL
)
3729 zlog_debug("dplane has %d completed, %d errors, for zebra main",
3730 counter
, error_counter
);
3733 * Hand lists through the api to zebra main,
3734 * to reduce the number of lock/unlock cycles
3737 /* Call through to zebra main */
3738 (zdplane_info
.dg_results_cb
)(&error_list
);
3740 TAILQ_INIT(&error_list
);
3742 /* Call through to zebra main */
3743 (zdplane_info
.dg_results_cb
)(&work_list
);
3745 TAILQ_INIT(&work_list
);
3752 * Final phase of shutdown, after all work enqueued to dplane has been
3753 * processed. This is called from the zebra main pthread context.
3755 void zebra_dplane_shutdown(void)
3757 if (IS_ZEBRA_DEBUG_DPLANE
)
3758 zlog_debug("Zebra dataplane shutdown called");
3760 /* Stop dplane thread, if it's running */
3762 zdplane_info
.dg_run
= false;
3764 if (zdplane_info
.dg_t_update
)
3765 thread_cancel_async(zdplane_info
.dg_t_update
->master
,
3766 &zdplane_info
.dg_t_update
, NULL
);
3768 frr_pthread_stop(zdplane_info
.dg_pthread
, NULL
);
3770 /* Destroy pthread */
3771 frr_pthread_destroy(zdplane_info
.dg_pthread
);
3772 zdplane_info
.dg_pthread
= NULL
;
3773 zdplane_info
.dg_master
= NULL
;
3775 /* TODO -- Notify provider(s) of final shutdown */
3777 /* TODO -- Clean-up provider objects */
3779 /* TODO -- Clean queue(s), free memory */
3783 * Initialize the dataplane module during startup, internal/private version
3785 static void zebra_dplane_init_internal(void)
3787 memset(&zdplane_info
, 0, sizeof(zdplane_info
));
3789 pthread_mutex_init(&zdplane_info
.dg_mutex
, NULL
);
3791 TAILQ_INIT(&zdplane_info
.dg_update_ctx_q
);
3792 TAILQ_INIT(&zdplane_info
.dg_providers_q
);
3794 zdplane_info
.dg_updates_per_cycle
= DPLANE_DEFAULT_NEW_WORK
;
3796 zdplane_info
.dg_max_queued_updates
= DPLANE_DEFAULT_MAX_QUEUED
;
3798 /* Register default kernel 'provider' during init */
3799 dplane_provider_init();
3803 * Start the dataplane pthread. This step needs to be run later than the
3804 * 'init' step, in case zebra has fork-ed.
3806 void zebra_dplane_start(void)
3808 struct zebra_dplane_provider
*prov
;
3809 struct frr_pthread_attr pattr
= {
3810 .start
= frr_pthread_attr_default
.start
,
3811 .stop
= frr_pthread_attr_default
.stop
3814 /* Start dataplane pthread */
3816 zdplane_info
.dg_pthread
= frr_pthread_new(&pattr
, "Zebra dplane thread",
3819 zdplane_info
.dg_master
= zdplane_info
.dg_pthread
->master
;
3821 zdplane_info
.dg_run
= true;
3823 /* Enqueue an initial event for the dataplane pthread */
3824 thread_add_event(zdplane_info
.dg_master
, dplane_thread_loop
, NULL
, 0,
3825 &zdplane_info
.dg_t_update
);
3827 /* Call start callbacks for registered providers */
3830 prov
= TAILQ_FIRST(&zdplane_info
.dg_providers_q
);
3836 (prov
->dp_start
)(prov
);
3838 /* Locate next provider */
3840 prov
= TAILQ_NEXT(prov
, dp_prov_link
);
3844 frr_pthread_run(zdplane_info
.dg_pthread
, NULL
);
3848 * Initialize the dataplane module at startup; called by zebra rib_init()
3850 void zebra_dplane_init(int (*results_fp
)(struct dplane_ctx_q
*))
3852 zebra_dplane_init_internal();
3853 zdplane_info
.dg_results_cb
= results_fp
;