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_memory.h"
32 #include "zebra/zebra_router.h"
33 #include "zebra/zebra_dplane.h"
34 #include "zebra/zebra_vxlan_private.h"
35 #include "zebra/zebra_mpls.h"
37 #include "zebra/debug.h"
38 #include "zebra/zebra_pbr.h"
40 /* Memory type for context blocks */
41 DEFINE_MTYPE_STATIC(ZEBRA
, DP_CTX
, "Zebra DPlane Ctx")
42 DEFINE_MTYPE_STATIC(ZEBRA
, DP_PROV
, "Zebra DPlane Provider")
48 /* Enable test dataplane provider */
49 /*#define DPLANE_TEST_PROVIDER 1 */
51 /* Default value for max queued incoming updates */
52 const uint32_t DPLANE_DEFAULT_MAX_QUEUED
= 200;
54 /* Default value for new work per cycle */
55 const uint32_t DPLANE_DEFAULT_NEW_WORK
= 100;
57 /* Validation check macro for context blocks */
58 /* #define DPLANE_DEBUG 1 */
62 # define DPLANE_CTX_VALID(p) \
67 # define DPLANE_CTX_VALID(p)
69 #endif /* DPLANE_DEBUG */
72 * Nexthop information captured for nexthop/nexthop group updates
74 struct dplane_nexthop_info
{
80 struct nexthop_group ng
;
81 struct nh_grp nh_grp
[MULTIPATH_NUM
];
86 * Route information captured for route updates.
88 struct dplane_route_info
{
90 /* Dest and (optional) source prefixes */
91 struct prefix zd_dest
;
101 route_tag_t zd_old_tag
;
103 uint32_t zd_old_metric
;
105 uint16_t zd_instance
;
106 uint16_t zd_old_instance
;
109 uint8_t zd_old_distance
;
112 uint32_t zd_nexthop_mtu
;
114 /* Nexthop hash entry info */
115 struct dplane_nexthop_info nhe
;
119 struct nexthop_group zd_ng
;
121 /* Backup nexthops (if present) */
122 struct nexthop_group backup_ng
;
124 /* "Previous" nexthops, used only in route updates without netlink */
125 struct nexthop_group zd_old_ng
;
126 struct nexthop_group old_backup_ng
;
128 /* TODO -- use fixed array of nexthops, to avoid mallocs? */
133 * Pseudowire info for the dataplane
135 struct dplane_pw_info
{
141 mpls_label_t local_label
;
142 mpls_label_t remote_label
;
145 struct nexthop_group nhg
;
147 union pw_protocol_fields fields
;
151 * Interface/prefix info for the dataplane
153 struct dplane_intf_info
{
158 #define DPLANE_INTF_CONNECTED (1 << 0) /* Connected peer, p2p */
159 #define DPLANE_INTF_SECONDARY (1 << 1)
160 #define DPLANE_INTF_BROADCAST (1 << 2)
161 #define DPLANE_INTF_HAS_DEST DPLANE_INTF_CONNECTED
162 #define DPLANE_INTF_HAS_LABEL (1 << 4)
164 /* Interface address/prefix */
165 struct prefix prefix
;
167 /* Dest address, for p2p, or broadcast prefix */
168 struct prefix dest_prefix
;
175 * EVPN MAC address info for the dataplane.
177 struct dplane_mac_info
{
179 ifindex_t br_ifindex
;
181 struct in_addr vtep_ip
;
184 uint32_t update_flags
;
188 * Neighbor info for the dataplane
190 struct dplane_neigh_info
{
191 struct ipaddr ip_addr
;
195 uint32_t update_flags
;
199 * Policy based routing rule info for the dataplane
201 struct dplane_ctx_rule
{
204 /* The route table pointed by this rule */
207 /* Filter criteria */
211 struct prefix src_ip
;
212 struct prefix dst_ip
;
215 struct dplane_rule_info
{
217 * Originating zclient sock fd, so we can know who to send
225 struct dplane_ctx_rule
new;
226 struct dplane_ctx_rule old
;
230 * The context block used to exchange info about route updates across
231 * the boundary between the zebra main context (and pthread) and the
232 * dataplane layer (and pthread).
234 struct zebra_dplane_ctx
{
237 enum dplane_op_e zd_op
;
239 /* Status on return */
240 enum zebra_dplane_result zd_status
;
242 /* Dplane provider id */
243 uint32_t zd_provider
;
245 /* Flags - used by providers, e.g. */
253 /* Some updates may be generated by notifications: allow the
254 * plugin to notice and ignore results from its own notifications.
256 uint32_t zd_notif_provider
;
258 /* TODO -- internal/sub-operation status? */
259 enum zebra_dplane_result zd_remote_status
;
260 enum zebra_dplane_result zd_kernel_status
;
263 uint32_t zd_table_id
;
265 char zd_ifname
[INTERFACE_NAMSIZ
];
266 ifindex_t zd_ifindex
;
268 /* Support info for different kinds of updates */
270 struct dplane_route_info rinfo
;
272 struct dplane_pw_info pw
;
273 struct dplane_intf_info intf
;
274 struct dplane_mac_info macinfo
;
275 struct dplane_neigh_info neigh
;
276 struct dplane_rule_info rule
;
279 /* Namespace info, used especially for netlink kernel communication */
280 struct zebra_dplane_info zd_ns_info
;
282 /* Embedded list linkage */
283 TAILQ_ENTRY(zebra_dplane_ctx
) zd_q_entries
;
286 /* Flag that can be set by a pre-kernel provider as a signal that an update
287 * should bypass the kernel.
289 #define DPLANE_CTX_FLAG_NO_KERNEL 0x01
293 * Registration block for one dataplane provider.
295 struct zebra_dplane_provider
{
297 char dp_name
[DPLANE_PROVIDER_NAMELEN
+ 1];
299 /* Priority, for ordering among providers */
306 pthread_mutex_t dp_mutex
;
308 /* Plugin-provided extra data */
314 int (*dp_start
)(struct zebra_dplane_provider
*prov
);
316 int (*dp_fp
)(struct zebra_dplane_provider
*prov
);
318 int (*dp_fini
)(struct zebra_dplane_provider
*prov
, bool early_p
);
320 _Atomic
uint32_t dp_in_counter
;
321 _Atomic
uint32_t dp_in_queued
;
322 _Atomic
uint32_t dp_in_max
;
323 _Atomic
uint32_t dp_out_counter
;
324 _Atomic
uint32_t dp_out_queued
;
325 _Atomic
uint32_t dp_out_max
;
326 _Atomic
uint32_t dp_error_counter
;
328 /* Queue of contexts inbound to the provider */
329 struct dplane_ctx_q dp_ctx_in_q
;
331 /* Queue of completed contexts outbound from the provider back
332 * towards the dataplane module.
334 struct dplane_ctx_q dp_ctx_out_q
;
336 /* Embedded list linkage for provider objects */
337 TAILQ_ENTRY(zebra_dplane_provider
) dp_prov_link
;
343 static struct zebra_dplane_globals
{
344 /* Mutex to control access to dataplane components */
345 pthread_mutex_t dg_mutex
;
347 /* Results callback registered by zebra 'core' */
348 int (*dg_results_cb
)(struct dplane_ctx_q
*ctxlist
);
350 /* Sentinel for beginning of shutdown */
351 volatile bool dg_is_shutdown
;
353 /* Sentinel for end of shutdown */
354 volatile bool dg_run
;
356 /* Update context queue inbound to the dataplane */
357 TAILQ_HEAD(zdg_ctx_q
, zebra_dplane_ctx
) dg_update_ctx_q
;
359 /* Ordered list of providers */
360 TAILQ_HEAD(zdg_prov_q
, zebra_dplane_provider
) dg_providers_q
;
362 /* Counter used to assign internal ids to providers */
363 uint32_t dg_provider_id
;
365 /* Limit number of pending, unprocessed updates */
366 _Atomic
uint32_t dg_max_queued_updates
;
368 /* Control whether system route notifications should be produced. */
369 bool dg_sys_route_notifs
;
371 /* Limit number of new updates dequeued at once, to pace an
374 uint32_t dg_updates_per_cycle
;
376 _Atomic
uint32_t dg_routes_in
;
377 _Atomic
uint32_t dg_routes_queued
;
378 _Atomic
uint32_t dg_routes_queued_max
;
379 _Atomic
uint32_t dg_route_errors
;
380 _Atomic
uint32_t dg_other_errors
;
382 _Atomic
uint32_t dg_nexthops_in
;
383 _Atomic
uint32_t dg_nexthop_errors
;
385 _Atomic
uint32_t dg_lsps_in
;
386 _Atomic
uint32_t dg_lsp_errors
;
388 _Atomic
uint32_t dg_pws_in
;
389 _Atomic
uint32_t dg_pw_errors
;
391 _Atomic
uint32_t dg_intf_addrs_in
;
392 _Atomic
uint32_t dg_intf_addr_errors
;
394 _Atomic
uint32_t dg_macs_in
;
395 _Atomic
uint32_t dg_mac_errors
;
397 _Atomic
uint32_t dg_neighs_in
;
398 _Atomic
uint32_t dg_neigh_errors
;
400 _Atomic
uint32_t dg_rules_in
;
401 _Atomic
uint32_t dg_rule_errors
;
403 _Atomic
uint32_t dg_update_yields
;
405 /* Dataplane pthread */
406 struct frr_pthread
*dg_pthread
;
408 /* Event-delivery context 'master' for the dplane */
409 struct thread_master
*dg_master
;
411 /* Event/'thread' pointer for queued updates */
412 struct thread
*dg_t_update
;
414 /* Event pointer for pending shutdown check loop */
415 struct thread
*dg_t_shutdown_check
;
420 * Lock and unlock for interactions with the zebra 'core' pthread
422 #define DPLANE_LOCK() pthread_mutex_lock(&zdplane_info.dg_mutex)
423 #define DPLANE_UNLOCK() pthread_mutex_unlock(&zdplane_info.dg_mutex)
427 * Lock and unlock for individual providers
429 #define DPLANE_PROV_LOCK(p) pthread_mutex_lock(&((p)->dp_mutex))
430 #define DPLANE_PROV_UNLOCK(p) pthread_mutex_unlock(&((p)->dp_mutex))
433 static int dplane_thread_loop(struct thread
*event
);
434 static void dplane_info_from_zns(struct zebra_dplane_info
*ns_info
,
435 struct zebra_ns
*zns
);
436 static enum zebra_dplane_result
lsp_update_internal(zebra_lsp_t
*lsp
,
437 enum dplane_op_e op
);
438 static enum zebra_dplane_result
pw_update_internal(struct zebra_pw
*pw
,
439 enum dplane_op_e op
);
440 static enum zebra_dplane_result
intf_addr_update_internal(
441 const struct interface
*ifp
, const struct connected
*ifc
,
442 enum dplane_op_e op
);
443 static enum zebra_dplane_result
mac_update_common(
444 enum dplane_op_e op
, const struct interface
*ifp
,
445 const struct interface
*br_ifp
,
446 vlanid_t vid
, const struct ethaddr
*mac
,
447 struct in_addr vtep_ip
, bool sticky
, uint32_t nhg_id
,
448 uint32_t update_flags
);
449 static enum zebra_dplane_result
neigh_update_internal(
451 const struct interface
*ifp
,
452 const struct ethaddr
*mac
,
453 const struct ipaddr
*ip
,
454 uint32_t flags
, uint16_t state
, uint32_t update_flags
);
460 /* Obtain thread_master for dataplane thread */
461 struct thread_master
*dplane_get_thread_master(void)
463 return zdplane_info
.dg_master
;
467 * Allocate a dataplane update context
469 struct zebra_dplane_ctx
*dplane_ctx_alloc(void)
471 struct zebra_dplane_ctx
*p
;
473 /* TODO -- just alloc'ing memory, but would like to maintain
476 p
= XCALLOC(MTYPE_DP_CTX
, sizeof(struct zebra_dplane_ctx
));
481 /* Enable system route notifications */
482 void dplane_enable_sys_route_notifs(void)
484 zdplane_info
.dg_sys_route_notifs
= true;
488 * Clean up dependent/internal allocations inside a context object
490 static void dplane_ctx_free_internal(struct zebra_dplane_ctx
*ctx
)
493 * Some internal allocations may need to be freed, depending on
494 * the type of info captured in the ctx.
496 switch (ctx
->zd_op
) {
497 case DPLANE_OP_ROUTE_INSTALL
:
498 case DPLANE_OP_ROUTE_UPDATE
:
499 case DPLANE_OP_ROUTE_DELETE
:
500 case DPLANE_OP_SYS_ROUTE_ADD
:
501 case DPLANE_OP_SYS_ROUTE_DELETE
:
502 case DPLANE_OP_ROUTE_NOTIFY
:
504 /* Free allocated nexthops */
505 if (ctx
->u
.rinfo
.zd_ng
.nexthop
) {
506 /* This deals with recursive nexthops too */
507 nexthops_free(ctx
->u
.rinfo
.zd_ng
.nexthop
);
509 ctx
->u
.rinfo
.zd_ng
.nexthop
= NULL
;
512 /* Free backup info also (if present) */
513 if (ctx
->u
.rinfo
.backup_ng
.nexthop
) {
514 /* This deals with recursive nexthops too */
515 nexthops_free(ctx
->u
.rinfo
.backup_ng
.nexthop
);
517 ctx
->u
.rinfo
.backup_ng
.nexthop
= NULL
;
520 if (ctx
->u
.rinfo
.zd_old_ng
.nexthop
) {
521 /* This deals with recursive nexthops too */
522 nexthops_free(ctx
->u
.rinfo
.zd_old_ng
.nexthop
);
524 ctx
->u
.rinfo
.zd_old_ng
.nexthop
= NULL
;
527 if (ctx
->u
.rinfo
.old_backup_ng
.nexthop
) {
528 /* This deals with recursive nexthops too */
529 nexthops_free(ctx
->u
.rinfo
.old_backup_ng
.nexthop
);
531 ctx
->u
.rinfo
.old_backup_ng
.nexthop
= NULL
;
536 case DPLANE_OP_NH_INSTALL
:
537 case DPLANE_OP_NH_UPDATE
:
538 case DPLANE_OP_NH_DELETE
: {
539 if (ctx
->u
.rinfo
.nhe
.ng
.nexthop
) {
540 /* This deals with recursive nexthops too */
541 nexthops_free(ctx
->u
.rinfo
.nhe
.ng
.nexthop
);
543 ctx
->u
.rinfo
.nhe
.ng
.nexthop
= NULL
;
548 case DPLANE_OP_LSP_INSTALL
:
549 case DPLANE_OP_LSP_UPDATE
:
550 case DPLANE_OP_LSP_DELETE
:
551 case DPLANE_OP_LSP_NOTIFY
:
553 zebra_nhlfe_t
*nhlfe
;
555 /* Unlink and free allocated NHLFEs */
556 frr_each_safe(nhlfe_list
, &ctx
->u
.lsp
.nhlfe_list
, nhlfe
) {
557 nhlfe_list_del(&ctx
->u
.lsp
.nhlfe_list
, nhlfe
);
558 zebra_mpls_nhlfe_free(nhlfe
);
561 /* Unlink and free allocated backup NHLFEs, if present */
562 frr_each_safe(nhlfe_list
,
563 &(ctx
->u
.lsp
.backup_nhlfe_list
), nhlfe
) {
564 nhlfe_list_del(&ctx
->u
.lsp
.backup_nhlfe_list
,
566 zebra_mpls_nhlfe_free(nhlfe
);
569 /* Clear pointers in lsp struct, in case we're caching
570 * free context structs.
572 nhlfe_list_init(&ctx
->u
.lsp
.nhlfe_list
);
573 ctx
->u
.lsp
.best_nhlfe
= NULL
;
574 nhlfe_list_init(&ctx
->u
.lsp
.backup_nhlfe_list
);
579 case DPLANE_OP_PW_INSTALL
:
580 case DPLANE_OP_PW_UNINSTALL
:
581 /* Free allocated nexthops */
582 if (ctx
->u
.pw
.nhg
.nexthop
) {
583 /* This deals with recursive nexthops too */
584 nexthops_free(ctx
->u
.pw
.nhg
.nexthop
);
586 ctx
->u
.pw
.nhg
.nexthop
= NULL
;
590 case DPLANE_OP_ADDR_INSTALL
:
591 case DPLANE_OP_ADDR_UNINSTALL
:
592 /* Maybe free label string, if allocated */
593 if (ctx
->u
.intf
.label
!= NULL
&&
594 ctx
->u
.intf
.label
!= ctx
->u
.intf
.label_buf
) {
595 free(ctx
->u
.intf
.label
);
596 ctx
->u
.intf
.label
= NULL
;
600 case DPLANE_OP_MAC_INSTALL
:
601 case DPLANE_OP_MAC_DELETE
:
602 case DPLANE_OP_NEIGH_INSTALL
:
603 case DPLANE_OP_NEIGH_UPDATE
:
604 case DPLANE_OP_NEIGH_DELETE
:
605 case DPLANE_OP_VTEP_ADD
:
606 case DPLANE_OP_VTEP_DELETE
:
607 case DPLANE_OP_RULE_ADD
:
608 case DPLANE_OP_RULE_DELETE
:
609 case DPLANE_OP_RULE_UPDATE
:
610 case DPLANE_OP_NEIGH_DISCOVER
:
617 * Free a dataplane results context.
619 static void dplane_ctx_free(struct zebra_dplane_ctx
**pctx
)
624 DPLANE_CTX_VALID(*pctx
);
626 /* TODO -- just freeing memory, but would like to maintain
630 /* Some internal allocations may need to be freed, depending on
631 * the type of info captured in the ctx.
633 dplane_ctx_free_internal(*pctx
);
635 XFREE(MTYPE_DP_CTX
, *pctx
);
639 * Reset an allocated context object for re-use. All internal allocations are
640 * freed and the context is memset.
642 void dplane_ctx_reset(struct zebra_dplane_ctx
*ctx
)
644 dplane_ctx_free_internal(ctx
);
645 memset(ctx
, 0, sizeof(*ctx
));
649 * Return a context block to the dplane module after processing
651 void dplane_ctx_fini(struct zebra_dplane_ctx
**pctx
)
653 /* TODO -- maintain pool; for now, just free */
654 dplane_ctx_free(pctx
);
657 /* Enqueue a context block */
658 void dplane_ctx_enqueue_tail(struct dplane_ctx_q
*q
,
659 const struct zebra_dplane_ctx
*ctx
)
661 TAILQ_INSERT_TAIL(q
, (struct zebra_dplane_ctx
*)ctx
, zd_q_entries
);
664 /* Append a list of context blocks to another list */
665 void dplane_ctx_list_append(struct dplane_ctx_q
*to_list
,
666 struct dplane_ctx_q
*from_list
)
668 if (TAILQ_FIRST(from_list
)) {
669 TAILQ_CONCAT(to_list
, from_list
, zd_q_entries
);
671 /* And clear 'from' list */
672 TAILQ_INIT(from_list
);
676 /* Dequeue a context block from the head of a list */
677 struct zebra_dplane_ctx
*dplane_ctx_dequeue(struct dplane_ctx_q
*q
)
679 struct zebra_dplane_ctx
*ctx
= TAILQ_FIRST(q
);
682 TAILQ_REMOVE(q
, ctx
, zd_q_entries
);
688 * Accessors for information from the context object
690 enum zebra_dplane_result
dplane_ctx_get_status(
691 const struct zebra_dplane_ctx
*ctx
)
693 DPLANE_CTX_VALID(ctx
);
695 return ctx
->zd_status
;
698 void dplane_ctx_set_status(struct zebra_dplane_ctx
*ctx
,
699 enum zebra_dplane_result status
)
701 DPLANE_CTX_VALID(ctx
);
703 ctx
->zd_status
= status
;
706 /* Retrieve last/current provider id */
707 uint32_t dplane_ctx_get_provider(const struct zebra_dplane_ctx
*ctx
)
709 DPLANE_CTX_VALID(ctx
);
710 return ctx
->zd_provider
;
713 /* Providers run before the kernel can control whether a kernel
714 * update should be done.
716 void dplane_ctx_set_skip_kernel(struct zebra_dplane_ctx
*ctx
)
718 DPLANE_CTX_VALID(ctx
);
720 SET_FLAG(ctx
->zd_flags
, DPLANE_CTX_FLAG_NO_KERNEL
);
723 bool dplane_ctx_is_skip_kernel(const struct zebra_dplane_ctx
*ctx
)
725 DPLANE_CTX_VALID(ctx
);
727 return CHECK_FLAG(ctx
->zd_flags
, DPLANE_CTX_FLAG_NO_KERNEL
);
730 void dplane_ctx_set_op(struct zebra_dplane_ctx
*ctx
, enum dplane_op_e op
)
732 DPLANE_CTX_VALID(ctx
);
736 enum dplane_op_e
dplane_ctx_get_op(const struct zebra_dplane_ctx
*ctx
)
738 DPLANE_CTX_VALID(ctx
);
743 const char *dplane_op2str(enum dplane_op_e op
)
745 const char *ret
= "UNKNOWN";
753 case DPLANE_OP_ROUTE_INSTALL
:
754 ret
= "ROUTE_INSTALL";
756 case DPLANE_OP_ROUTE_UPDATE
:
757 ret
= "ROUTE_UPDATE";
759 case DPLANE_OP_ROUTE_DELETE
:
760 ret
= "ROUTE_DELETE";
762 case DPLANE_OP_ROUTE_NOTIFY
:
763 ret
= "ROUTE_NOTIFY";
767 case DPLANE_OP_NH_INSTALL
:
770 case DPLANE_OP_NH_UPDATE
:
773 case DPLANE_OP_NH_DELETE
:
777 case DPLANE_OP_LSP_INSTALL
:
780 case DPLANE_OP_LSP_UPDATE
:
783 case DPLANE_OP_LSP_DELETE
:
786 case DPLANE_OP_LSP_NOTIFY
:
790 case DPLANE_OP_PW_INSTALL
:
793 case DPLANE_OP_PW_UNINSTALL
:
794 ret
= "PW_UNINSTALL";
797 case DPLANE_OP_SYS_ROUTE_ADD
:
798 ret
= "SYS_ROUTE_ADD";
800 case DPLANE_OP_SYS_ROUTE_DELETE
:
801 ret
= "SYS_ROUTE_DEL";
804 case DPLANE_OP_ADDR_INSTALL
:
805 ret
= "ADDR_INSTALL";
807 case DPLANE_OP_ADDR_UNINSTALL
:
808 ret
= "ADDR_UNINSTALL";
811 case DPLANE_OP_MAC_INSTALL
:
814 case DPLANE_OP_MAC_DELETE
:
818 case DPLANE_OP_NEIGH_INSTALL
:
819 ret
= "NEIGH_INSTALL";
821 case DPLANE_OP_NEIGH_UPDATE
:
822 ret
= "NEIGH_UPDATE";
824 case DPLANE_OP_NEIGH_DELETE
:
825 ret
= "NEIGH_DELETE";
827 case DPLANE_OP_VTEP_ADD
:
830 case DPLANE_OP_VTEP_DELETE
:
834 case DPLANE_OP_RULE_ADD
:
837 case DPLANE_OP_RULE_DELETE
:
840 case DPLANE_OP_RULE_UPDATE
:
844 case DPLANE_OP_NEIGH_DISCOVER
:
845 ret
= "NEIGH_DISCOVER";
852 const char *dplane_res2str(enum zebra_dplane_result res
)
854 const char *ret
= "<Unknown>";
857 case ZEBRA_DPLANE_REQUEST_FAILURE
:
860 case ZEBRA_DPLANE_REQUEST_QUEUED
:
863 case ZEBRA_DPLANE_REQUEST_SUCCESS
:
871 void dplane_ctx_set_dest(struct zebra_dplane_ctx
*ctx
,
872 const struct prefix
*dest
)
874 DPLANE_CTX_VALID(ctx
);
876 prefix_copy(&(ctx
->u
.rinfo
.zd_dest
), dest
);
879 const struct prefix
*dplane_ctx_get_dest(const struct zebra_dplane_ctx
*ctx
)
881 DPLANE_CTX_VALID(ctx
);
883 return &(ctx
->u
.rinfo
.zd_dest
);
886 void dplane_ctx_set_src(struct zebra_dplane_ctx
*ctx
, const struct prefix
*src
)
888 DPLANE_CTX_VALID(ctx
);
891 prefix_copy(&(ctx
->u
.rinfo
.zd_src
), src
);
893 memset(&(ctx
->u
.rinfo
.zd_src
), 0, sizeof(struct prefix
));
896 /* Source prefix is a little special - return NULL for "no src prefix" */
897 const struct prefix
*dplane_ctx_get_src(const struct zebra_dplane_ctx
*ctx
)
899 DPLANE_CTX_VALID(ctx
);
901 if (ctx
->u
.rinfo
.zd_src
.prefixlen
== 0 &&
902 IN6_IS_ADDR_UNSPECIFIED(&(ctx
->u
.rinfo
.zd_src
.u
.prefix6
))) {
905 return &(ctx
->u
.rinfo
.zd_src
);
909 bool dplane_ctx_is_update(const struct zebra_dplane_ctx
*ctx
)
911 DPLANE_CTX_VALID(ctx
);
913 return ctx
->zd_is_update
;
916 uint32_t dplane_ctx_get_seq(const struct zebra_dplane_ctx
*ctx
)
918 DPLANE_CTX_VALID(ctx
);
923 uint32_t dplane_ctx_get_old_seq(const struct zebra_dplane_ctx
*ctx
)
925 DPLANE_CTX_VALID(ctx
);
927 return ctx
->zd_old_seq
;
930 void dplane_ctx_set_vrf(struct zebra_dplane_ctx
*ctx
, vrf_id_t vrf
)
932 DPLANE_CTX_VALID(ctx
);
934 ctx
->zd_vrf_id
= vrf
;
937 vrf_id_t
dplane_ctx_get_vrf(const struct zebra_dplane_ctx
*ctx
)
939 DPLANE_CTX_VALID(ctx
);
941 return ctx
->zd_vrf_id
;
944 bool dplane_ctx_is_from_notif(const struct zebra_dplane_ctx
*ctx
)
946 DPLANE_CTX_VALID(ctx
);
948 return (ctx
->zd_notif_provider
!= 0);
951 uint32_t dplane_ctx_get_notif_provider(const struct zebra_dplane_ctx
*ctx
)
953 DPLANE_CTX_VALID(ctx
);
955 return ctx
->zd_notif_provider
;
958 void dplane_ctx_set_notif_provider(struct zebra_dplane_ctx
*ctx
,
961 DPLANE_CTX_VALID(ctx
);
963 ctx
->zd_notif_provider
= id
;
966 const char *dplane_ctx_get_ifname(const struct zebra_dplane_ctx
*ctx
)
968 DPLANE_CTX_VALID(ctx
);
970 return ctx
->zd_ifname
;
973 void dplane_ctx_set_ifname(struct zebra_dplane_ctx
*ctx
, const char *ifname
)
975 DPLANE_CTX_VALID(ctx
);
980 strlcpy(ctx
->zd_ifname
, ifname
, sizeof(ctx
->zd_ifname
));
983 ifindex_t
dplane_ctx_get_ifindex(const struct zebra_dplane_ctx
*ctx
)
985 DPLANE_CTX_VALID(ctx
);
987 return ctx
->zd_ifindex
;
990 void dplane_ctx_set_type(struct zebra_dplane_ctx
*ctx
, int type
)
992 DPLANE_CTX_VALID(ctx
);
994 ctx
->u
.rinfo
.zd_type
= type
;
997 int dplane_ctx_get_type(const struct zebra_dplane_ctx
*ctx
)
999 DPLANE_CTX_VALID(ctx
);
1001 return ctx
->u
.rinfo
.zd_type
;
1004 int dplane_ctx_get_old_type(const struct zebra_dplane_ctx
*ctx
)
1006 DPLANE_CTX_VALID(ctx
);
1008 return ctx
->u
.rinfo
.zd_old_type
;
1011 void dplane_ctx_set_afi(struct zebra_dplane_ctx
*ctx
, afi_t afi
)
1013 DPLANE_CTX_VALID(ctx
);
1015 ctx
->u
.rinfo
.zd_afi
= afi
;
1018 afi_t
dplane_ctx_get_afi(const struct zebra_dplane_ctx
*ctx
)
1020 DPLANE_CTX_VALID(ctx
);
1022 return ctx
->u
.rinfo
.zd_afi
;
1025 void dplane_ctx_set_safi(struct zebra_dplane_ctx
*ctx
, safi_t safi
)
1027 DPLANE_CTX_VALID(ctx
);
1029 ctx
->u
.rinfo
.zd_safi
= safi
;
1032 safi_t
dplane_ctx_get_safi(const struct zebra_dplane_ctx
*ctx
)
1034 DPLANE_CTX_VALID(ctx
);
1036 return ctx
->u
.rinfo
.zd_safi
;
1039 void dplane_ctx_set_table(struct zebra_dplane_ctx
*ctx
, uint32_t table
)
1041 DPLANE_CTX_VALID(ctx
);
1043 ctx
->zd_table_id
= table
;
1046 uint32_t dplane_ctx_get_table(const struct zebra_dplane_ctx
*ctx
)
1048 DPLANE_CTX_VALID(ctx
);
1050 return ctx
->zd_table_id
;
1053 route_tag_t
dplane_ctx_get_tag(const struct zebra_dplane_ctx
*ctx
)
1055 DPLANE_CTX_VALID(ctx
);
1057 return ctx
->u
.rinfo
.zd_tag
;
1060 void dplane_ctx_set_tag(struct zebra_dplane_ctx
*ctx
, route_tag_t tag
)
1062 DPLANE_CTX_VALID(ctx
);
1064 ctx
->u
.rinfo
.zd_tag
= tag
;
1067 route_tag_t
dplane_ctx_get_old_tag(const struct zebra_dplane_ctx
*ctx
)
1069 DPLANE_CTX_VALID(ctx
);
1071 return ctx
->u
.rinfo
.zd_old_tag
;
1074 uint16_t dplane_ctx_get_instance(const struct zebra_dplane_ctx
*ctx
)
1076 DPLANE_CTX_VALID(ctx
);
1078 return ctx
->u
.rinfo
.zd_instance
;
1081 void dplane_ctx_set_instance(struct zebra_dplane_ctx
*ctx
, uint16_t instance
)
1083 DPLANE_CTX_VALID(ctx
);
1085 ctx
->u
.rinfo
.zd_instance
= instance
;
1088 uint16_t dplane_ctx_get_old_instance(const struct zebra_dplane_ctx
*ctx
)
1090 DPLANE_CTX_VALID(ctx
);
1092 return ctx
->u
.rinfo
.zd_old_instance
;
1095 uint32_t dplane_ctx_get_metric(const struct zebra_dplane_ctx
*ctx
)
1097 DPLANE_CTX_VALID(ctx
);
1099 return ctx
->u
.rinfo
.zd_metric
;
1102 uint32_t dplane_ctx_get_old_metric(const struct zebra_dplane_ctx
*ctx
)
1104 DPLANE_CTX_VALID(ctx
);
1106 return ctx
->u
.rinfo
.zd_old_metric
;
1109 uint32_t dplane_ctx_get_mtu(const struct zebra_dplane_ctx
*ctx
)
1111 DPLANE_CTX_VALID(ctx
);
1113 return ctx
->u
.rinfo
.zd_mtu
;
1116 uint32_t dplane_ctx_get_nh_mtu(const struct zebra_dplane_ctx
*ctx
)
1118 DPLANE_CTX_VALID(ctx
);
1120 return ctx
->u
.rinfo
.zd_nexthop_mtu
;
1123 uint8_t dplane_ctx_get_distance(const struct zebra_dplane_ctx
*ctx
)
1125 DPLANE_CTX_VALID(ctx
);
1127 return ctx
->u
.rinfo
.zd_distance
;
1130 void dplane_ctx_set_distance(struct zebra_dplane_ctx
*ctx
, uint8_t distance
)
1132 DPLANE_CTX_VALID(ctx
);
1134 ctx
->u
.rinfo
.zd_distance
= distance
;
1137 uint8_t dplane_ctx_get_old_distance(const struct zebra_dplane_ctx
*ctx
)
1139 DPLANE_CTX_VALID(ctx
);
1141 return ctx
->u
.rinfo
.zd_old_distance
;
1145 * Set the nexthops associated with a context: note that processing code
1146 * may well expect that nexthops are in canonical (sorted) order, so we
1147 * will enforce that here.
1149 void dplane_ctx_set_nexthops(struct zebra_dplane_ctx
*ctx
, struct nexthop
*nh
)
1151 DPLANE_CTX_VALID(ctx
);
1153 if (ctx
->u
.rinfo
.zd_ng
.nexthop
) {
1154 nexthops_free(ctx
->u
.rinfo
.zd_ng
.nexthop
);
1155 ctx
->u
.rinfo
.zd_ng
.nexthop
= NULL
;
1157 nexthop_group_copy_nh_sorted(&(ctx
->u
.rinfo
.zd_ng
), nh
);
1161 * Set the list of backup nexthops; their ordering is preserved (they're not
1164 void dplane_ctx_set_backup_nhg(struct zebra_dplane_ctx
*ctx
,
1165 const struct nexthop_group
*nhg
)
1167 struct nexthop
*nh
, *last_nh
, *nexthop
;
1169 DPLANE_CTX_VALID(ctx
);
1171 if (ctx
->u
.rinfo
.backup_ng
.nexthop
) {
1172 nexthops_free(ctx
->u
.rinfo
.backup_ng
.nexthop
);
1173 ctx
->u
.rinfo
.backup_ng
.nexthop
= NULL
;
1178 /* Be careful to preserve the order of the backup list */
1179 for (nh
= nhg
->nexthop
; nh
; nh
= nh
->next
) {
1180 nexthop
= nexthop_dup(nh
, NULL
);
1183 NEXTHOP_APPEND(last_nh
, nexthop
);
1185 ctx
->u
.rinfo
.backup_ng
.nexthop
= nexthop
;
1191 uint32_t dplane_ctx_get_nhg_id(const struct zebra_dplane_ctx
*ctx
)
1193 DPLANE_CTX_VALID(ctx
);
1194 return ctx
->u
.rinfo
.zd_nhg_id
;
1197 const struct nexthop_group
*dplane_ctx_get_ng(
1198 const struct zebra_dplane_ctx
*ctx
)
1200 DPLANE_CTX_VALID(ctx
);
1202 return &(ctx
->u
.rinfo
.zd_ng
);
1205 const struct nexthop_group
*
1206 dplane_ctx_get_backup_ng(const struct zebra_dplane_ctx
*ctx
)
1208 DPLANE_CTX_VALID(ctx
);
1210 return &(ctx
->u
.rinfo
.backup_ng
);
1213 const struct nexthop_group
*
1214 dplane_ctx_get_old_ng(const struct zebra_dplane_ctx
*ctx
)
1216 DPLANE_CTX_VALID(ctx
);
1218 return &(ctx
->u
.rinfo
.zd_old_ng
);
1221 const struct nexthop_group
*
1222 dplane_ctx_get_old_backup_ng(const struct zebra_dplane_ctx
*ctx
)
1224 DPLANE_CTX_VALID(ctx
);
1226 return &(ctx
->u
.rinfo
.old_backup_ng
);
1229 const struct zebra_dplane_info
*dplane_ctx_get_ns(
1230 const struct zebra_dplane_ctx
*ctx
)
1232 DPLANE_CTX_VALID(ctx
);
1234 return &(ctx
->zd_ns_info
);
1237 /* Accessors for nexthop information */
1238 uint32_t dplane_ctx_get_nhe_id(const struct zebra_dplane_ctx
*ctx
)
1240 DPLANE_CTX_VALID(ctx
);
1241 return ctx
->u
.rinfo
.nhe
.id
;
1244 afi_t
dplane_ctx_get_nhe_afi(const struct zebra_dplane_ctx
*ctx
)
1246 DPLANE_CTX_VALID(ctx
);
1247 return ctx
->u
.rinfo
.nhe
.afi
;
1250 vrf_id_t
dplane_ctx_get_nhe_vrf_id(const struct zebra_dplane_ctx
*ctx
)
1252 DPLANE_CTX_VALID(ctx
);
1253 return ctx
->u
.rinfo
.nhe
.vrf_id
;
1256 int dplane_ctx_get_nhe_type(const struct zebra_dplane_ctx
*ctx
)
1258 DPLANE_CTX_VALID(ctx
);
1259 return ctx
->u
.rinfo
.nhe
.type
;
1262 const struct nexthop_group
*
1263 dplane_ctx_get_nhe_ng(const struct zebra_dplane_ctx
*ctx
)
1265 DPLANE_CTX_VALID(ctx
);
1266 return &(ctx
->u
.rinfo
.nhe
.ng
);
1269 const struct nh_grp
*
1270 dplane_ctx_get_nhe_nh_grp(const struct zebra_dplane_ctx
*ctx
)
1272 DPLANE_CTX_VALID(ctx
);
1273 return ctx
->u
.rinfo
.nhe
.nh_grp
;
1276 uint8_t dplane_ctx_get_nhe_nh_grp_count(const struct zebra_dplane_ctx
*ctx
)
1278 DPLANE_CTX_VALID(ctx
);
1279 return ctx
->u
.rinfo
.nhe
.nh_grp_count
;
1282 /* Accessors for LSP information */
1284 mpls_label_t
dplane_ctx_get_in_label(const struct zebra_dplane_ctx
*ctx
)
1286 DPLANE_CTX_VALID(ctx
);
1288 return ctx
->u
.lsp
.ile
.in_label
;
1291 void dplane_ctx_set_in_label(struct zebra_dplane_ctx
*ctx
, mpls_label_t label
)
1293 DPLANE_CTX_VALID(ctx
);
1295 ctx
->u
.lsp
.ile
.in_label
= label
;
1298 uint8_t dplane_ctx_get_addr_family(const struct zebra_dplane_ctx
*ctx
)
1300 DPLANE_CTX_VALID(ctx
);
1302 return ctx
->u
.lsp
.addr_family
;
1305 void dplane_ctx_set_addr_family(struct zebra_dplane_ctx
*ctx
,
1308 DPLANE_CTX_VALID(ctx
);
1310 ctx
->u
.lsp
.addr_family
= family
;
1313 uint32_t dplane_ctx_get_lsp_flags(const struct zebra_dplane_ctx
*ctx
)
1315 DPLANE_CTX_VALID(ctx
);
1317 return ctx
->u
.lsp
.flags
;
1320 void dplane_ctx_set_lsp_flags(struct zebra_dplane_ctx
*ctx
,
1323 DPLANE_CTX_VALID(ctx
);
1325 ctx
->u
.lsp
.flags
= flags
;
1328 const struct nhlfe_list_head
*dplane_ctx_get_nhlfe_list(
1329 const struct zebra_dplane_ctx
*ctx
)
1331 DPLANE_CTX_VALID(ctx
);
1332 return &(ctx
->u
.lsp
.nhlfe_list
);
1335 const struct nhlfe_list_head
*dplane_ctx_get_backup_nhlfe_list(
1336 const struct zebra_dplane_ctx
*ctx
)
1338 DPLANE_CTX_VALID(ctx
);
1339 return &(ctx
->u
.lsp
.backup_nhlfe_list
);
1342 zebra_nhlfe_t
*dplane_ctx_add_nhlfe(struct zebra_dplane_ctx
*ctx
,
1343 enum lsp_types_t lsp_type
,
1344 enum nexthop_types_t nh_type
,
1345 const union g_addr
*gate
,
1348 mpls_label_t
*out_labels
)
1350 zebra_nhlfe_t
*nhlfe
;
1352 DPLANE_CTX_VALID(ctx
);
1354 nhlfe
= zebra_mpls_lsp_add_nhlfe(&(ctx
->u
.lsp
),
1355 lsp_type
, nh_type
, gate
,
1356 ifindex
, num_labels
, out_labels
);
1361 zebra_nhlfe_t
*dplane_ctx_add_backup_nhlfe(struct zebra_dplane_ctx
*ctx
,
1362 enum lsp_types_t lsp_type
,
1363 enum nexthop_types_t nh_type
,
1364 const union g_addr
*gate
,
1367 mpls_label_t
*out_labels
)
1369 zebra_nhlfe_t
*nhlfe
;
1371 DPLANE_CTX_VALID(ctx
);
1373 nhlfe
= zebra_mpls_lsp_add_backup_nhlfe(&(ctx
->u
.lsp
),
1374 lsp_type
, nh_type
, gate
,
1375 ifindex
, num_labels
,
1381 const zebra_nhlfe_t
*
1382 dplane_ctx_get_best_nhlfe(const struct zebra_dplane_ctx
*ctx
)
1384 DPLANE_CTX_VALID(ctx
);
1386 return ctx
->u
.lsp
.best_nhlfe
;
1389 const zebra_nhlfe_t
*
1390 dplane_ctx_set_best_nhlfe(struct zebra_dplane_ctx
*ctx
,
1391 zebra_nhlfe_t
*nhlfe
)
1393 DPLANE_CTX_VALID(ctx
);
1395 ctx
->u
.lsp
.best_nhlfe
= nhlfe
;
1396 return ctx
->u
.lsp
.best_nhlfe
;
1399 uint32_t dplane_ctx_get_lsp_num_ecmp(const struct zebra_dplane_ctx
*ctx
)
1401 DPLANE_CTX_VALID(ctx
);
1403 return ctx
->u
.lsp
.num_ecmp
;
1406 mpls_label_t
dplane_ctx_get_pw_local_label(const struct zebra_dplane_ctx
*ctx
)
1408 DPLANE_CTX_VALID(ctx
);
1410 return ctx
->u
.pw
.local_label
;
1413 mpls_label_t
dplane_ctx_get_pw_remote_label(const struct zebra_dplane_ctx
*ctx
)
1415 DPLANE_CTX_VALID(ctx
);
1417 return ctx
->u
.pw
.remote_label
;
1420 int dplane_ctx_get_pw_type(const struct zebra_dplane_ctx
*ctx
)
1422 DPLANE_CTX_VALID(ctx
);
1424 return ctx
->u
.pw
.type
;
1427 int dplane_ctx_get_pw_af(const struct zebra_dplane_ctx
*ctx
)
1429 DPLANE_CTX_VALID(ctx
);
1431 return ctx
->u
.pw
.af
;
1434 uint32_t dplane_ctx_get_pw_flags(const struct zebra_dplane_ctx
*ctx
)
1436 DPLANE_CTX_VALID(ctx
);
1438 return ctx
->u
.pw
.flags
;
1441 int dplane_ctx_get_pw_status(const struct zebra_dplane_ctx
*ctx
)
1443 DPLANE_CTX_VALID(ctx
);
1445 return ctx
->u
.pw
.status
;
1448 void dplane_ctx_set_pw_status(struct zebra_dplane_ctx
*ctx
, int status
)
1450 DPLANE_CTX_VALID(ctx
);
1452 ctx
->u
.pw
.status
= status
;
1455 const union g_addr
*dplane_ctx_get_pw_dest(
1456 const struct zebra_dplane_ctx
*ctx
)
1458 DPLANE_CTX_VALID(ctx
);
1460 return &(ctx
->u
.pw
.dest
);
1463 const union pw_protocol_fields
*dplane_ctx_get_pw_proto(
1464 const struct zebra_dplane_ctx
*ctx
)
1466 DPLANE_CTX_VALID(ctx
);
1468 return &(ctx
->u
.pw
.fields
);
1471 const struct nexthop_group
*
1472 dplane_ctx_get_pw_nhg(const struct zebra_dplane_ctx
*ctx
)
1474 DPLANE_CTX_VALID(ctx
);
1476 return &(ctx
->u
.pw
.nhg
);
1479 /* Accessors for interface information */
1480 uint32_t dplane_ctx_get_intf_metric(const struct zebra_dplane_ctx
*ctx
)
1482 DPLANE_CTX_VALID(ctx
);
1484 return ctx
->u
.intf
.metric
;
1487 /* Is interface addr p2p? */
1488 bool dplane_ctx_intf_is_connected(const struct zebra_dplane_ctx
*ctx
)
1490 DPLANE_CTX_VALID(ctx
);
1492 return (ctx
->u
.intf
.flags
& DPLANE_INTF_CONNECTED
);
1495 bool dplane_ctx_intf_is_secondary(const struct zebra_dplane_ctx
*ctx
)
1497 DPLANE_CTX_VALID(ctx
);
1499 return (ctx
->u
.intf
.flags
& DPLANE_INTF_SECONDARY
);
1502 bool dplane_ctx_intf_is_broadcast(const struct zebra_dplane_ctx
*ctx
)
1504 DPLANE_CTX_VALID(ctx
);
1506 return (ctx
->u
.intf
.flags
& DPLANE_INTF_BROADCAST
);
1509 const struct prefix
*dplane_ctx_get_intf_addr(
1510 const struct zebra_dplane_ctx
*ctx
)
1512 DPLANE_CTX_VALID(ctx
);
1514 return &(ctx
->u
.intf
.prefix
);
1517 bool dplane_ctx_intf_has_dest(const struct zebra_dplane_ctx
*ctx
)
1519 DPLANE_CTX_VALID(ctx
);
1521 return (ctx
->u
.intf
.flags
& DPLANE_INTF_HAS_DEST
);
1524 const struct prefix
*dplane_ctx_get_intf_dest(
1525 const struct zebra_dplane_ctx
*ctx
)
1527 DPLANE_CTX_VALID(ctx
);
1529 if (ctx
->u
.intf
.flags
& DPLANE_INTF_HAS_DEST
)
1530 return &(ctx
->u
.intf
.dest_prefix
);
1535 bool dplane_ctx_intf_has_label(const struct zebra_dplane_ctx
*ctx
)
1537 DPLANE_CTX_VALID(ctx
);
1539 return (ctx
->u
.intf
.flags
& DPLANE_INTF_HAS_LABEL
);
1542 const char *dplane_ctx_get_intf_label(const struct zebra_dplane_ctx
*ctx
)
1544 DPLANE_CTX_VALID(ctx
);
1546 return ctx
->u
.intf
.label
;
1549 /* Accessors for MAC information */
1550 vlanid_t
dplane_ctx_mac_get_vlan(const struct zebra_dplane_ctx
*ctx
)
1552 DPLANE_CTX_VALID(ctx
);
1553 return ctx
->u
.macinfo
.vid
;
1556 bool dplane_ctx_mac_is_sticky(const struct zebra_dplane_ctx
*ctx
)
1558 DPLANE_CTX_VALID(ctx
);
1559 return ctx
->u
.macinfo
.is_sticky
;
1562 uint32_t dplane_ctx_mac_get_nhg_id(const struct zebra_dplane_ctx
*ctx
)
1564 DPLANE_CTX_VALID(ctx
);
1565 return ctx
->u
.macinfo
.nhg_id
;
1568 uint32_t dplane_ctx_mac_get_update_flags(const struct zebra_dplane_ctx
*ctx
)
1570 DPLANE_CTX_VALID(ctx
);
1571 return ctx
->u
.macinfo
.update_flags
;
1574 const struct ethaddr
*dplane_ctx_mac_get_addr(
1575 const struct zebra_dplane_ctx
*ctx
)
1577 DPLANE_CTX_VALID(ctx
);
1578 return &(ctx
->u
.macinfo
.mac
);
1581 const struct in_addr
*dplane_ctx_mac_get_vtep_ip(
1582 const struct zebra_dplane_ctx
*ctx
)
1584 DPLANE_CTX_VALID(ctx
);
1585 return &(ctx
->u
.macinfo
.vtep_ip
);
1588 ifindex_t
dplane_ctx_mac_get_br_ifindex(const struct zebra_dplane_ctx
*ctx
)
1590 DPLANE_CTX_VALID(ctx
);
1591 return ctx
->u
.macinfo
.br_ifindex
;
1594 /* Accessors for neighbor information */
1595 const struct ipaddr
*dplane_ctx_neigh_get_ipaddr(
1596 const struct zebra_dplane_ctx
*ctx
)
1598 DPLANE_CTX_VALID(ctx
);
1599 return &(ctx
->u
.neigh
.ip_addr
);
1602 const struct ethaddr
*dplane_ctx_neigh_get_mac(
1603 const struct zebra_dplane_ctx
*ctx
)
1605 DPLANE_CTX_VALID(ctx
);
1606 return &(ctx
->u
.neigh
.mac
);
1609 uint32_t dplane_ctx_neigh_get_flags(const struct zebra_dplane_ctx
*ctx
)
1611 DPLANE_CTX_VALID(ctx
);
1612 return ctx
->u
.neigh
.flags
;
1615 uint16_t dplane_ctx_neigh_get_state(const struct zebra_dplane_ctx
*ctx
)
1617 DPLANE_CTX_VALID(ctx
);
1618 return ctx
->u
.neigh
.state
;
1621 uint32_t dplane_ctx_neigh_get_update_flags(const struct zebra_dplane_ctx
*ctx
)
1623 DPLANE_CTX_VALID(ctx
);
1624 return ctx
->u
.neigh
.update_flags
;
1627 /* Accessors for PBR rule information */
1628 int dplane_ctx_rule_get_sock(const struct zebra_dplane_ctx
*ctx
)
1630 DPLANE_CTX_VALID(ctx
);
1632 return ctx
->u
.rule
.sock
;
1635 int dplane_ctx_rule_get_unique(const struct zebra_dplane_ctx
*ctx
)
1637 DPLANE_CTX_VALID(ctx
);
1639 return ctx
->u
.rule
.unique
;
1642 int dplane_ctx_rule_get_seq(const struct zebra_dplane_ctx
*ctx
)
1644 DPLANE_CTX_VALID(ctx
);
1646 return ctx
->u
.rule
.seq
;
1649 uint32_t dplane_ctx_rule_get_priority(const struct zebra_dplane_ctx
*ctx
)
1651 DPLANE_CTX_VALID(ctx
);
1653 return ctx
->u
.rule
.new.priority
;
1656 uint32_t dplane_ctx_rule_get_old_priority(const struct zebra_dplane_ctx
*ctx
)
1658 DPLANE_CTX_VALID(ctx
);
1660 return ctx
->u
.rule
.old
.priority
;
1663 uint32_t dplane_ctx_rule_get_table(const struct zebra_dplane_ctx
*ctx
)
1665 DPLANE_CTX_VALID(ctx
);
1667 return ctx
->u
.rule
.new.table
;
1670 uint32_t dplane_ctx_rule_get_old_table(const struct zebra_dplane_ctx
*ctx
)
1672 DPLANE_CTX_VALID(ctx
);
1674 return ctx
->u
.rule
.old
.table
;
1677 uint32_t dplane_ctx_rule_get_filter_bm(const struct zebra_dplane_ctx
*ctx
)
1679 DPLANE_CTX_VALID(ctx
);
1681 return ctx
->u
.rule
.new.filter_bm
;
1684 uint32_t dplane_ctx_rule_get_old_filter_bm(const struct zebra_dplane_ctx
*ctx
)
1686 DPLANE_CTX_VALID(ctx
);
1688 return ctx
->u
.rule
.old
.filter_bm
;
1691 uint32_t dplane_ctx_rule_get_fwmark(const struct zebra_dplane_ctx
*ctx
)
1693 DPLANE_CTX_VALID(ctx
);
1695 return ctx
->u
.rule
.new.fwmark
;
1698 uint32_t dplane_ctx_rule_get_old_fwmark(const struct zebra_dplane_ctx
*ctx
)
1700 DPLANE_CTX_VALID(ctx
);
1702 return ctx
->u
.rule
.old
.fwmark
;
1705 uint8_t dplane_ctx_rule_get_dsfield(const struct zebra_dplane_ctx
*ctx
)
1707 DPLANE_CTX_VALID(ctx
);
1709 return ctx
->u
.rule
.new.dsfield
;
1712 uint8_t dplane_ctx_rule_get_old_dsfield(const struct zebra_dplane_ctx
*ctx
)
1714 DPLANE_CTX_VALID(ctx
);
1716 return ctx
->u
.rule
.old
.dsfield
;
1719 const struct prefix
*
1720 dplane_ctx_rule_get_src_ip(const struct zebra_dplane_ctx
*ctx
)
1722 DPLANE_CTX_VALID(ctx
);
1724 return &(ctx
->u
.rule
.new.src_ip
);
1727 const struct prefix
*
1728 dplane_ctx_rule_get_old_src_ip(const struct zebra_dplane_ctx
*ctx
)
1730 DPLANE_CTX_VALID(ctx
);
1732 return &(ctx
->u
.rule
.old
.src_ip
);
1735 const struct prefix
*
1736 dplane_ctx_rule_get_dst_ip(const struct zebra_dplane_ctx
*ctx
)
1738 DPLANE_CTX_VALID(ctx
);
1740 return &(ctx
->u
.rule
.new.dst_ip
);
1743 const struct prefix
*
1744 dplane_ctx_rule_get_old_dst_ip(const struct zebra_dplane_ctx
*ctx
)
1746 DPLANE_CTX_VALID(ctx
);
1748 return &(ctx
->u
.rule
.old
.dst_ip
);
1752 * End of dplane context accessors
1757 * Retrieve the limit on the number of pending, unprocessed updates.
1759 uint32_t dplane_get_in_queue_limit(void)
1761 return atomic_load_explicit(&zdplane_info
.dg_max_queued_updates
,
1762 memory_order_relaxed
);
1766 * Configure limit on the number of pending, queued updates.
1768 void dplane_set_in_queue_limit(uint32_t limit
, bool set
)
1770 /* Reset to default on 'unset' */
1772 limit
= DPLANE_DEFAULT_MAX_QUEUED
;
1774 atomic_store_explicit(&zdplane_info
.dg_max_queued_updates
, limit
,
1775 memory_order_relaxed
);
1779 * Retrieve the current queue depth of incoming, unprocessed updates
1781 uint32_t dplane_get_in_queue_len(void)
1783 return atomic_load_explicit(&zdplane_info
.dg_routes_queued
,
1784 memory_order_seq_cst
);
1788 * Common dataplane context init with zebra namespace info.
1790 static int dplane_ctx_ns_init(struct zebra_dplane_ctx
*ctx
,
1791 struct zebra_ns
*zns
,
1794 dplane_info_from_zns(&(ctx
->zd_ns_info
), zns
);
1796 #if defined(HAVE_NETLINK)
1797 /* Increment message counter after copying to context struct - may need
1798 * two messages in some 'update' cases.
1801 zns
->netlink_dplane
.seq
+= 2;
1803 zns
->netlink_dplane
.seq
++;
1804 #endif /* HAVE_NETLINK */
1810 * Initialize a context block for a route update from zebra data structs.
1812 int dplane_ctx_route_init(struct zebra_dplane_ctx
*ctx
, enum dplane_op_e op
,
1813 struct route_node
*rn
, struct route_entry
*re
)
1816 const struct route_table
*table
= NULL
;
1817 const struct rib_table_info
*info
;
1818 const struct prefix
*p
, *src_p
;
1819 struct zebra_ns
*zns
;
1820 struct zebra_vrf
*zvrf
;
1821 struct nexthop
*nexthop
;
1822 zebra_l3vni_t
*zl3vni
;
1824 if (!ctx
|| !rn
|| !re
)
1828 ctx
->zd_status
= ZEBRA_DPLANE_REQUEST_SUCCESS
;
1830 ctx
->u
.rinfo
.zd_type
= re
->type
;
1831 ctx
->u
.rinfo
.zd_old_type
= re
->type
;
1833 /* Prefixes: dest, and optional source */
1834 srcdest_rnode_prefixes(rn
, &p
, &src_p
);
1836 prefix_copy(&(ctx
->u
.rinfo
.zd_dest
), p
);
1839 prefix_copy(&(ctx
->u
.rinfo
.zd_src
), src_p
);
1841 memset(&(ctx
->u
.rinfo
.zd_src
), 0, sizeof(ctx
->u
.rinfo
.zd_src
));
1843 ctx
->zd_table_id
= re
->table
;
1845 ctx
->u
.rinfo
.zd_metric
= re
->metric
;
1846 ctx
->u
.rinfo
.zd_old_metric
= re
->metric
;
1847 ctx
->zd_vrf_id
= re
->vrf_id
;
1848 ctx
->u
.rinfo
.zd_mtu
= re
->mtu
;
1849 ctx
->u
.rinfo
.zd_nexthop_mtu
= re
->nexthop_mtu
;
1850 ctx
->u
.rinfo
.zd_instance
= re
->instance
;
1851 ctx
->u
.rinfo
.zd_tag
= re
->tag
;
1852 ctx
->u
.rinfo
.zd_old_tag
= re
->tag
;
1853 ctx
->u
.rinfo
.zd_distance
= re
->distance
;
1855 table
= srcdest_rnode_table(rn
);
1858 ctx
->u
.rinfo
.zd_afi
= info
->afi
;
1859 ctx
->u
.rinfo
.zd_safi
= info
->safi
;
1861 /* Copy nexthops; recursive info is included too */
1862 copy_nexthops(&(ctx
->u
.rinfo
.zd_ng
.nexthop
),
1863 re
->nhe
->nhg
.nexthop
, NULL
);
1864 ctx
->u
.rinfo
.zd_nhg_id
= re
->nhe
->id
;
1866 /* Copy backup nexthop info, if present */
1867 if (re
->nhe
->backup_info
&& re
->nhe
->backup_info
->nhe
) {
1868 copy_nexthops(&(ctx
->u
.rinfo
.backup_ng
.nexthop
),
1869 re
->nhe
->backup_info
->nhe
->nhg
.nexthop
, NULL
);
1873 * Ensure that the dplane nexthops' flags are clear and copy
1874 * encapsulation information.
1876 for (ALL_NEXTHOPS(ctx
->u
.rinfo
.zd_ng
, nexthop
)) {
1877 UNSET_FLAG(nexthop
->flags
, NEXTHOP_FLAG_FIB
);
1879 /* Check for available encapsulations. */
1880 if (!CHECK_FLAG(re
->flags
, ZEBRA_FLAG_EVPN_ROUTE
))
1883 zl3vni
= zl3vni_from_vrf(nexthop
->vrf_id
);
1884 if (zl3vni
&& is_l3vni_oper_up(zl3vni
)) {
1885 nexthop
->nh_encap_type
= NET_VXLAN
;
1886 nexthop
->nh_encap
.vni
= zl3vni
->vni
;
1890 /* Don't need some info when capturing a system notification */
1891 if (op
== DPLANE_OP_SYS_ROUTE_ADD
||
1892 op
== DPLANE_OP_SYS_ROUTE_DELETE
) {
1897 /* Extract ns info - can't use pointers to 'core' structs */
1898 zvrf
= vrf_info_lookup(re
->vrf_id
);
1900 dplane_ctx_ns_init(ctx
, zns
, (op
== DPLANE_OP_ROUTE_UPDATE
));
1904 struct nhg_hash_entry
*nhe
= zebra_nhg_resolve(re
->nhe
);
1906 ctx
->u
.rinfo
.nhe
.id
= nhe
->id
;
1908 * Check if the nhe is installed/queued before doing anything
1911 * If its a delete we only use the prefix anyway, so this only
1912 * matters for INSTALL/UPDATE.
1914 if (((op
== DPLANE_OP_ROUTE_INSTALL
)
1915 || (op
== DPLANE_OP_ROUTE_UPDATE
))
1916 && !CHECK_FLAG(nhe
->flags
, NEXTHOP_GROUP_INSTALLED
)
1917 && !CHECK_FLAG(nhe
->flags
, NEXTHOP_GROUP_QUEUED
)) {
1922 #endif /* HAVE_NETLINK */
1924 /* Trying out the sequence number idea, so we can try to detect
1925 * when a result is stale.
1927 re
->dplane_sequence
= zebra_router_get_next_sequence();
1928 ctx
->zd_seq
= re
->dplane_sequence
;
1937 * dplane_ctx_nexthop_init() - Initialize a context block for a nexthop update
1939 * @ctx: Dataplane context to init
1940 * @op: Operation being performed
1941 * @nhe: Nexthop group hash entry
1943 * Return: Result status
1945 int dplane_ctx_nexthop_init(struct zebra_dplane_ctx
*ctx
, enum dplane_op_e op
,
1946 struct nhg_hash_entry
*nhe
)
1948 struct zebra_vrf
*zvrf
= NULL
;
1949 struct zebra_ns
*zns
= NULL
;
1956 ctx
->zd_status
= ZEBRA_DPLANE_REQUEST_SUCCESS
;
1958 /* Copy over nhe info */
1959 ctx
->u
.rinfo
.nhe
.id
= nhe
->id
;
1960 ctx
->u
.rinfo
.nhe
.afi
= nhe
->afi
;
1961 ctx
->u
.rinfo
.nhe
.vrf_id
= nhe
->vrf_id
;
1962 ctx
->u
.rinfo
.nhe
.type
= nhe
->type
;
1964 nexthop_group_copy(&(ctx
->u
.rinfo
.nhe
.ng
), &(nhe
->nhg
));
1966 /* If this is a group, convert it to a grp array of ids */
1967 if (!zebra_nhg_depends_is_empty(nhe
)
1968 && !CHECK_FLAG(nhe
->flags
, NEXTHOP_GROUP_RECURSIVE
))
1969 ctx
->u
.rinfo
.nhe
.nh_grp_count
= zebra_nhg_nhe2grp(
1970 ctx
->u
.rinfo
.nhe
.nh_grp
, nhe
, MULTIPATH_NUM
);
1972 zvrf
= vrf_info_lookup(nhe
->vrf_id
);
1975 * Fallback to default namespace if the vrf got ripped out from under
1978 zns
= zvrf
? zvrf
->zns
: zebra_ns_lookup(NS_DEFAULT
);
1981 * TODO: Might not need to mark this as an update, since
1982 * it probably won't require two messages
1984 dplane_ctx_ns_init(ctx
, zns
, (op
== DPLANE_OP_NH_UPDATE
));
1985 ctx
->zd_is_update
= (op
== DPLANE_OP_NH_UPDATE
);
1994 * Capture information for an LSP update in a dplane context.
1996 int dplane_ctx_lsp_init(struct zebra_dplane_ctx
*ctx
, enum dplane_op_e op
,
2000 zebra_nhlfe_t
*nhlfe
, *new_nhlfe
;
2003 ctx
->zd_status
= ZEBRA_DPLANE_REQUEST_SUCCESS
;
2005 /* Capture namespace info */
2006 dplane_ctx_ns_init(ctx
, zebra_ns_lookup(NS_DEFAULT
),
2007 (op
== DPLANE_OP_LSP_UPDATE
));
2008 ctx
->zd_is_update
= (op
== DPLANE_OP_LSP_UPDATE
);
2010 memset(&ctx
->u
.lsp
, 0, sizeof(ctx
->u
.lsp
));
2012 nhlfe_list_init(&(ctx
->u
.lsp
.nhlfe_list
));
2013 nhlfe_list_init(&(ctx
->u
.lsp
.backup_nhlfe_list
));
2015 /* This may be called to create/init a dplane context, not necessarily
2016 * to copy an lsp object.
2023 if (IS_ZEBRA_DEBUG_DPLANE_DETAIL
)
2024 zlog_debug("init dplane ctx %s: in-label %u ecmp# %d",
2025 dplane_op2str(op
), lsp
->ile
.in_label
,
2028 ctx
->u
.lsp
.ile
= lsp
->ile
;
2029 ctx
->u
.lsp
.addr_family
= lsp
->addr_family
;
2030 ctx
->u
.lsp
.num_ecmp
= lsp
->num_ecmp
;
2031 ctx
->u
.lsp
.flags
= lsp
->flags
;
2033 /* Copy source LSP's nhlfes, and capture 'best' nhlfe */
2034 frr_each(nhlfe_list
, &lsp
->nhlfe_list
, nhlfe
) {
2035 /* Not sure if this is meaningful... */
2036 if (nhlfe
->nexthop
== NULL
)
2039 new_nhlfe
= zebra_mpls_lsp_add_nh(&(ctx
->u
.lsp
), nhlfe
->type
,
2041 if (new_nhlfe
== NULL
|| new_nhlfe
->nexthop
== NULL
) {
2046 /* Need to copy flags and backup info too */
2047 new_nhlfe
->flags
= nhlfe
->flags
;
2048 new_nhlfe
->nexthop
->flags
= nhlfe
->nexthop
->flags
;
2050 if (CHECK_FLAG(new_nhlfe
->nexthop
->flags
,
2051 NEXTHOP_FLAG_HAS_BACKUP
)) {
2052 new_nhlfe
->nexthop
->backup_num
=
2053 nhlfe
->nexthop
->backup_num
;
2054 memcpy(new_nhlfe
->nexthop
->backup_idx
,
2055 nhlfe
->nexthop
->backup_idx
,
2056 new_nhlfe
->nexthop
->backup_num
);
2059 if (nhlfe
== lsp
->best_nhlfe
)
2060 ctx
->u
.lsp
.best_nhlfe
= new_nhlfe
;
2066 /* Capture backup nhlfes/nexthops */
2067 frr_each(nhlfe_list
, &lsp
->backup_nhlfe_list
, nhlfe
) {
2068 /* Not sure if this is meaningful... */
2069 if (nhlfe
->nexthop
== NULL
)
2072 new_nhlfe
= zebra_mpls_lsp_add_backup_nh(&(ctx
->u
.lsp
),
2075 if (new_nhlfe
== NULL
|| new_nhlfe
->nexthop
== NULL
) {
2080 /* Need to copy flags too */
2081 new_nhlfe
->flags
= nhlfe
->flags
;
2082 new_nhlfe
->nexthop
->flags
= nhlfe
->nexthop
->flags
;
2085 /* On error the ctx will be cleaned-up, so we don't need to
2086 * deal with any allocated nhlfe or nexthop structs here.
2094 * Capture information for an LSP update in a dplane context.
2096 static int dplane_ctx_pw_init(struct zebra_dplane_ctx
*ctx
,
2097 enum dplane_op_e op
,
2098 struct zebra_pw
*pw
)
2102 struct route_table
*table
;
2103 struct route_node
*rn
;
2104 struct route_entry
*re
;
2105 const struct nexthop_group
*nhg
;
2107 if (IS_ZEBRA_DEBUG_DPLANE_DETAIL
)
2108 zlog_debug("init dplane ctx %s: pw '%s', loc %u, rem %u",
2109 dplane_op2str(op
), pw
->ifname
, pw
->local_label
,
2113 ctx
->zd_status
= ZEBRA_DPLANE_REQUEST_SUCCESS
;
2115 /* Capture namespace info: no netlink support as of 12/18,
2116 * but just in case...
2118 dplane_ctx_ns_init(ctx
, zebra_ns_lookup(NS_DEFAULT
), false);
2120 memset(&ctx
->u
.pw
, 0, sizeof(ctx
->u
.pw
));
2122 /* This name appears to be c-string, so we use string copy. */
2123 strlcpy(ctx
->zd_ifname
, pw
->ifname
, sizeof(ctx
->zd_ifname
));
2125 ctx
->zd_vrf_id
= pw
->vrf_id
;
2126 ctx
->zd_ifindex
= pw
->ifindex
;
2127 ctx
->u
.pw
.type
= pw
->type
;
2128 ctx
->u
.pw
.af
= pw
->af
;
2129 ctx
->u
.pw
.local_label
= pw
->local_label
;
2130 ctx
->u
.pw
.remote_label
= pw
->remote_label
;
2131 ctx
->u
.pw
.flags
= pw
->flags
;
2133 ctx
->u
.pw
.dest
= pw
->nexthop
;
2135 ctx
->u
.pw
.fields
= pw
->data
;
2137 /* Capture nexthop info for the pw destination. We need to look
2138 * up and use zebra datastructs, but we're running in the zebra
2139 * pthread here so that should be ok.
2141 memcpy(&p
.u
, &pw
->nexthop
, sizeof(pw
->nexthop
));
2143 p
.prefixlen
= ((pw
->af
== AF_INET
) ?
2144 IPV4_MAX_PREFIXLEN
: IPV6_MAX_PREFIXLEN
);
2146 afi
= (pw
->af
== AF_INET
) ? AFI_IP
: AFI_IP6
;
2147 table
= zebra_vrf_table(afi
, SAFI_UNICAST
, pw
->vrf_id
);
2149 rn
= route_node_match(table
, &p
);
2151 RNODE_FOREACH_RE(rn
, re
) {
2152 if (CHECK_FLAG(re
->flags
, ZEBRA_FLAG_SELECTED
))
2157 nhg
= rib_get_fib_nhg(re
);
2158 if (nhg
&& nhg
->nexthop
)
2159 copy_nexthops(&(ctx
->u
.pw
.nhg
.nexthop
),
2160 nhg
->nexthop
, NULL
);
2162 /* Include any installed backup nexthops */
2163 nhg
= rib_get_fib_backup_nhg(re
);
2164 if (nhg
&& nhg
->nexthop
)
2165 copy_nexthops(&(ctx
->u
.pw
.nhg
.nexthop
),
2166 nhg
->nexthop
, NULL
);
2168 route_unlock_node(rn
);
2176 * dplane_ctx_rule_init_single() - Initialize a dataplane representation of a
2179 * @dplane_rule: Dataplane internal representation of a rule
2182 static void dplane_ctx_rule_init_single(struct dplane_ctx_rule
*dplane_rule
,
2183 struct zebra_pbr_rule
*rule
)
2185 dplane_rule
->priority
= rule
->rule
.priority
;
2186 dplane_rule
->table
= rule
->rule
.action
.table
;
2188 dplane_rule
->filter_bm
= rule
->rule
.filter
.filter_bm
;
2189 dplane_rule
->fwmark
= rule
->rule
.filter
.fwmark
;
2190 dplane_rule
->dsfield
= rule
->rule
.filter
.dsfield
;
2191 prefix_copy(&(dplane_rule
->dst_ip
), &rule
->rule
.filter
.dst_ip
);
2192 prefix_copy(&(dplane_rule
->src_ip
), &rule
->rule
.filter
.src_ip
);
2196 * dplane_ctx_rule_init() - Initialize a context block for a PBR rule update.
2198 * @ctx: Dataplane context to init
2199 * @op: Operation being performed
2200 * @new_rule: PBR rule
2202 * Return: Result status
2204 static int dplane_ctx_rule_init(struct zebra_dplane_ctx
*ctx
,
2205 enum dplane_op_e op
,
2206 struct zebra_pbr_rule
*new_rule
,
2207 struct zebra_pbr_rule
*old_rule
)
2209 if (IS_ZEBRA_DEBUG_DPLANE_DETAIL
) {
2210 char buf1
[PREFIX_STRLEN
];
2211 char buf2
[PREFIX_STRLEN
];
2214 "init dplane ctx %s: IF %s(%u) Prio %u Fwmark %u Src %s Dst %s Table %u",
2215 dplane_op2str(op
), new_rule
->ifname
,
2216 new_rule
->rule
.ifindex
, new_rule
->rule
.priority
,
2217 new_rule
->rule
.filter
.fwmark
,
2218 prefix2str(&new_rule
->rule
.filter
.src_ip
, buf1
,
2220 prefix2str(&new_rule
->rule
.filter
.dst_ip
, buf2
,
2222 new_rule
->rule
.action
.table
);
2226 ctx
->zd_status
= ZEBRA_DPLANE_REQUEST_SUCCESS
;
2228 dplane_ctx_ns_init(ctx
, zebra_ns_lookup(NS_DEFAULT
),
2229 op
== DPLANE_OP_RULE_UPDATE
);
2230 ctx
->zd_is_update
= (op
== DPLANE_OP_RULE_UPDATE
);
2232 ctx
->zd_vrf_id
= new_rule
->vrf_id
;
2233 memcpy(ctx
->zd_ifname
, new_rule
->ifname
, sizeof(new_rule
->ifname
));
2234 ctx
->zd_ifindex
= new_rule
->rule
.ifindex
;
2236 ctx
->u
.rule
.sock
= new_rule
->sock
;
2237 ctx
->u
.rule
.unique
= new_rule
->rule
.unique
;
2238 ctx
->u
.rule
.seq
= new_rule
->rule
.seq
;
2240 dplane_ctx_rule_init_single(&ctx
->u
.rule
.new, new_rule
);
2241 if (op
== DPLANE_OP_RULE_UPDATE
)
2242 dplane_ctx_rule_init_single(&ctx
->u
.rule
.old
, old_rule
);
2248 * Enqueue a new update,
2249 * and ensure an event is active for the dataplane pthread.
2251 static int dplane_update_enqueue(struct zebra_dplane_ctx
*ctx
)
2254 uint32_t high
, curr
;
2256 /* Enqueue for processing by the dataplane pthread */
2259 TAILQ_INSERT_TAIL(&zdplane_info
.dg_update_ctx_q
, ctx
,
2264 curr
= atomic_fetch_add_explicit(
2265 &(zdplane_info
.dg_routes_queued
),
2266 1, memory_order_seq_cst
);
2268 curr
++; /* We got the pre-incremented value */
2270 /* Maybe update high-water counter also */
2271 high
= atomic_load_explicit(&zdplane_info
.dg_routes_queued_max
,
2272 memory_order_seq_cst
);
2273 while (high
< curr
) {
2274 if (atomic_compare_exchange_weak_explicit(
2275 &zdplane_info
.dg_routes_queued_max
,
2277 memory_order_seq_cst
,
2278 memory_order_seq_cst
))
2282 /* Ensure that an event for the dataplane thread is active */
2283 ret
= dplane_provider_work_ready();
2289 * Utility that prepares a route update and enqueues it for processing
2291 static enum zebra_dplane_result
2292 dplane_route_update_internal(struct route_node
*rn
,
2293 struct route_entry
*re
,
2294 struct route_entry
*old_re
,
2295 enum dplane_op_e op
)
2297 enum zebra_dplane_result result
= ZEBRA_DPLANE_REQUEST_FAILURE
;
2299 struct zebra_dplane_ctx
*ctx
= NULL
;
2301 /* Obtain context block */
2302 ctx
= dplane_ctx_alloc();
2304 /* Init context with info from zebra data structs */
2305 ret
= dplane_ctx_route_init(ctx
, op
, rn
, re
);
2307 /* Capture some extra info for update case
2308 * where there's a different 'old' route.
2310 if ((op
== DPLANE_OP_ROUTE_UPDATE
) &&
2311 old_re
&& (old_re
!= re
)) {
2312 ctx
->zd_is_update
= true;
2314 old_re
->dplane_sequence
=
2315 zebra_router_get_next_sequence();
2316 ctx
->zd_old_seq
= old_re
->dplane_sequence
;
2318 ctx
->u
.rinfo
.zd_old_tag
= old_re
->tag
;
2319 ctx
->u
.rinfo
.zd_old_type
= old_re
->type
;
2320 ctx
->u
.rinfo
.zd_old_instance
= old_re
->instance
;
2321 ctx
->u
.rinfo
.zd_old_distance
= old_re
->distance
;
2322 ctx
->u
.rinfo
.zd_old_metric
= old_re
->metric
;
2324 #ifndef HAVE_NETLINK
2325 /* For bsd, capture previous re's nexthops too, sigh.
2326 * We'll need these to do per-nexthop deletes.
2328 copy_nexthops(&(ctx
->u
.rinfo
.zd_old_ng
.nexthop
),
2329 old_re
->nhe
->nhg
.nexthop
, NULL
);
2331 if (zebra_nhg_get_backup_nhg(old_re
->nhe
) != NULL
) {
2332 struct nexthop_group
*nhg
;
2333 struct nexthop
**nh
;
2335 nhg
= zebra_nhg_get_backup_nhg(old_re
->nhe
);
2336 nh
= &(ctx
->u
.rinfo
.old_backup_ng
.nexthop
);
2339 copy_nexthops(nh
, nhg
->nexthop
, NULL
);
2341 #endif /* !HAVE_NETLINK */
2344 /* Enqueue context for processing */
2345 ret
= dplane_update_enqueue(ctx
);
2348 /* Update counter */
2349 atomic_fetch_add_explicit(&zdplane_info
.dg_routes_in
, 1,
2350 memory_order_relaxed
);
2353 result
= ZEBRA_DPLANE_REQUEST_QUEUED
;
2356 result
= ZEBRA_DPLANE_REQUEST_SUCCESS
;
2358 atomic_fetch_add_explicit(&zdplane_info
.dg_route_errors
,
2359 1, memory_order_relaxed
);
2361 dplane_ctx_free(&ctx
);
2368 * dplane_nexthop_update_internal() - Helper for enqueuing nexthop changes
2370 * @nhe: Nexthop group hash entry where the change occured
2371 * @op: The operation to be enqued
2373 * Return: Result of the change
2375 static enum zebra_dplane_result
2376 dplane_nexthop_update_internal(struct nhg_hash_entry
*nhe
, enum dplane_op_e op
)
2378 enum zebra_dplane_result result
= ZEBRA_DPLANE_REQUEST_FAILURE
;
2380 struct zebra_dplane_ctx
*ctx
= NULL
;
2382 /* Obtain context block */
2383 ctx
= dplane_ctx_alloc();
2389 ret
= dplane_ctx_nexthop_init(ctx
, op
, nhe
);
2391 ret
= dplane_update_enqueue(ctx
);
2394 /* Update counter */
2395 atomic_fetch_add_explicit(&zdplane_info
.dg_nexthops_in
, 1,
2396 memory_order_relaxed
);
2399 result
= ZEBRA_DPLANE_REQUEST_QUEUED
;
2401 atomic_fetch_add_explicit(&zdplane_info
.dg_nexthop_errors
, 1,
2402 memory_order_relaxed
);
2404 dplane_ctx_free(&ctx
);
2411 * Enqueue a route 'add' for the dataplane.
2413 enum zebra_dplane_result
dplane_route_add(struct route_node
*rn
,
2414 struct route_entry
*re
)
2416 enum zebra_dplane_result ret
= ZEBRA_DPLANE_REQUEST_FAILURE
;
2418 if (rn
== NULL
|| re
== NULL
)
2421 ret
= dplane_route_update_internal(rn
, re
, NULL
,
2422 DPLANE_OP_ROUTE_INSTALL
);
2429 * Enqueue a route update for the dataplane.
2431 enum zebra_dplane_result
dplane_route_update(struct route_node
*rn
,
2432 struct route_entry
*re
,
2433 struct route_entry
*old_re
)
2435 enum zebra_dplane_result ret
= ZEBRA_DPLANE_REQUEST_FAILURE
;
2437 if (rn
== NULL
|| re
== NULL
)
2440 ret
= dplane_route_update_internal(rn
, re
, old_re
,
2441 DPLANE_OP_ROUTE_UPDATE
);
2447 * Enqueue a route removal for the dataplane.
2449 enum zebra_dplane_result
dplane_route_delete(struct route_node
*rn
,
2450 struct route_entry
*re
)
2452 enum zebra_dplane_result ret
= ZEBRA_DPLANE_REQUEST_FAILURE
;
2454 if (rn
== NULL
|| re
== NULL
)
2457 ret
= dplane_route_update_internal(rn
, re
, NULL
,
2458 DPLANE_OP_ROUTE_DELETE
);
2465 * Notify the dplane when system/connected routes change.
2467 enum zebra_dplane_result
dplane_sys_route_add(struct route_node
*rn
,
2468 struct route_entry
*re
)
2470 enum zebra_dplane_result ret
= ZEBRA_DPLANE_REQUEST_FAILURE
;
2472 /* Ignore this event unless a provider plugin has requested it. */
2473 if (!zdplane_info
.dg_sys_route_notifs
) {
2474 ret
= ZEBRA_DPLANE_REQUEST_SUCCESS
;
2478 if (rn
== NULL
|| re
== NULL
)
2481 ret
= dplane_route_update_internal(rn
, re
, NULL
,
2482 DPLANE_OP_SYS_ROUTE_ADD
);
2489 * Notify the dplane when system/connected routes are deleted.
2491 enum zebra_dplane_result
dplane_sys_route_del(struct route_node
*rn
,
2492 struct route_entry
*re
)
2494 enum zebra_dplane_result ret
= ZEBRA_DPLANE_REQUEST_FAILURE
;
2496 /* Ignore this event unless a provider plugin has requested it. */
2497 if (!zdplane_info
.dg_sys_route_notifs
) {
2498 ret
= ZEBRA_DPLANE_REQUEST_SUCCESS
;
2502 if (rn
== NULL
|| re
== NULL
)
2505 ret
= dplane_route_update_internal(rn
, re
, NULL
,
2506 DPLANE_OP_SYS_ROUTE_DELETE
);
2513 * Update from an async notification, to bring other fibs up-to-date.
2515 enum zebra_dplane_result
2516 dplane_route_notif_update(struct route_node
*rn
,
2517 struct route_entry
*re
,
2518 enum dplane_op_e op
,
2519 struct zebra_dplane_ctx
*ctx
)
2521 enum zebra_dplane_result result
= ZEBRA_DPLANE_REQUEST_FAILURE
;
2523 struct zebra_dplane_ctx
*new_ctx
= NULL
;
2524 struct nexthop
*nexthop
;
2525 struct nexthop_group
*nhg
;
2527 if (rn
== NULL
|| re
== NULL
)
2530 new_ctx
= dplane_ctx_alloc();
2531 if (new_ctx
== NULL
)
2534 /* Init context with info from zebra data structs */
2535 dplane_ctx_route_init(new_ctx
, op
, rn
, re
);
2537 /* For add/update, need to adjust the nexthops so that we match
2538 * the notification state, which may not be the route-entry/RIB
2541 if (op
== DPLANE_OP_ROUTE_UPDATE
||
2542 op
== DPLANE_OP_ROUTE_INSTALL
) {
2544 nexthops_free(new_ctx
->u
.rinfo
.zd_ng
.nexthop
);
2545 new_ctx
->u
.rinfo
.zd_ng
.nexthop
= NULL
;
2547 nhg
= rib_get_fib_nhg(re
);
2548 if (nhg
&& nhg
->nexthop
)
2549 copy_nexthops(&(new_ctx
->u
.rinfo
.zd_ng
.nexthop
),
2550 nhg
->nexthop
, NULL
);
2552 /* Check for installed backup nexthops also */
2553 nhg
= rib_get_fib_backup_nhg(re
);
2554 if (nhg
&& nhg
->nexthop
) {
2555 copy_nexthops(&(new_ctx
->u
.rinfo
.zd_ng
.nexthop
),
2556 nhg
->nexthop
, NULL
);
2559 for (ALL_NEXTHOPS(new_ctx
->u
.rinfo
.zd_ng
, nexthop
))
2560 UNSET_FLAG(nexthop
->flags
, NEXTHOP_FLAG_FIB
);
2564 /* Capture info about the source of the notification, in 'ctx' */
2565 dplane_ctx_set_notif_provider(new_ctx
,
2566 dplane_ctx_get_notif_provider(ctx
));
2568 ret
= dplane_update_enqueue(new_ctx
);
2572 result
= ZEBRA_DPLANE_REQUEST_QUEUED
;
2574 dplane_ctx_free(&new_ctx
);
2580 * Enqueue a nexthop add for the dataplane.
2582 enum zebra_dplane_result
dplane_nexthop_add(struct nhg_hash_entry
*nhe
)
2584 enum zebra_dplane_result ret
= ZEBRA_DPLANE_REQUEST_FAILURE
;
2587 ret
= dplane_nexthop_update_internal(nhe
, DPLANE_OP_NH_INSTALL
);
2592 * Enqueue a nexthop update for the dataplane.
2594 * Might not need this func since zebra's nexthop objects should be immutable?
2596 enum zebra_dplane_result
dplane_nexthop_update(struct nhg_hash_entry
*nhe
)
2598 enum zebra_dplane_result ret
= ZEBRA_DPLANE_REQUEST_FAILURE
;
2601 ret
= dplane_nexthop_update_internal(nhe
, DPLANE_OP_NH_UPDATE
);
2606 * Enqueue a nexthop removal for the dataplane.
2608 enum zebra_dplane_result
dplane_nexthop_delete(struct nhg_hash_entry
*nhe
)
2610 enum zebra_dplane_result ret
= ZEBRA_DPLANE_REQUEST_FAILURE
;
2613 ret
= dplane_nexthop_update_internal(nhe
, DPLANE_OP_NH_DELETE
);
2619 * Enqueue LSP add for the dataplane.
2621 enum zebra_dplane_result
dplane_lsp_add(zebra_lsp_t
*lsp
)
2623 enum zebra_dplane_result ret
=
2624 lsp_update_internal(lsp
, DPLANE_OP_LSP_INSTALL
);
2630 * Enqueue LSP update for the dataplane.
2632 enum zebra_dplane_result
dplane_lsp_update(zebra_lsp_t
*lsp
)
2634 enum zebra_dplane_result ret
=
2635 lsp_update_internal(lsp
, DPLANE_OP_LSP_UPDATE
);
2641 * Enqueue LSP delete for the dataplane.
2643 enum zebra_dplane_result
dplane_lsp_delete(zebra_lsp_t
*lsp
)
2645 enum zebra_dplane_result ret
=
2646 lsp_update_internal(lsp
, DPLANE_OP_LSP_DELETE
);
2651 /* Update or un-install resulting from an async notification */
2652 enum zebra_dplane_result
2653 dplane_lsp_notif_update(zebra_lsp_t
*lsp
,
2654 enum dplane_op_e op
,
2655 struct zebra_dplane_ctx
*notif_ctx
)
2657 enum zebra_dplane_result result
= ZEBRA_DPLANE_REQUEST_FAILURE
;
2659 struct zebra_dplane_ctx
*ctx
= NULL
;
2660 struct nhlfe_list_head
*head
;
2661 zebra_nhlfe_t
*nhlfe
, *new_nhlfe
;
2663 /* Obtain context block */
2664 ctx
= dplane_ctx_alloc();
2670 /* Copy info from zebra LSP */
2671 ret
= dplane_ctx_lsp_init(ctx
, op
, lsp
);
2675 /* Add any installed backup nhlfes */
2676 head
= &(ctx
->u
.lsp
.backup_nhlfe_list
);
2677 frr_each(nhlfe_list
, head
, nhlfe
) {
2679 if (CHECK_FLAG(nhlfe
->flags
, NHLFE_FLAG_INSTALLED
) &&
2680 CHECK_FLAG(nhlfe
->nexthop
->flags
, NEXTHOP_FLAG_FIB
)) {
2681 new_nhlfe
= zebra_mpls_lsp_add_nh(&(ctx
->u
.lsp
),
2685 /* Need to copy flags too */
2686 new_nhlfe
->flags
= nhlfe
->flags
;
2687 new_nhlfe
->nexthop
->flags
= nhlfe
->nexthop
->flags
;
2691 /* Capture info about the source of the notification */
2692 dplane_ctx_set_notif_provider(
2694 dplane_ctx_get_notif_provider(notif_ctx
));
2696 ret
= dplane_update_enqueue(ctx
);
2699 /* Update counter */
2700 atomic_fetch_add_explicit(&zdplane_info
.dg_lsps_in
, 1,
2701 memory_order_relaxed
);
2704 result
= ZEBRA_DPLANE_REQUEST_QUEUED
;
2706 atomic_fetch_add_explicit(&zdplane_info
.dg_lsp_errors
, 1,
2707 memory_order_relaxed
);
2709 dplane_ctx_free(&ctx
);
2715 * Enqueue pseudowire install for the dataplane.
2717 enum zebra_dplane_result
dplane_pw_install(struct zebra_pw
*pw
)
2719 return pw_update_internal(pw
, DPLANE_OP_PW_INSTALL
);
2723 * Enqueue pseudowire un-install for the dataplane.
2725 enum zebra_dplane_result
dplane_pw_uninstall(struct zebra_pw
*pw
)
2727 return pw_update_internal(pw
, DPLANE_OP_PW_UNINSTALL
);
2731 * Common internal LSP update utility
2733 static enum zebra_dplane_result
lsp_update_internal(zebra_lsp_t
*lsp
,
2734 enum dplane_op_e op
)
2736 enum zebra_dplane_result result
= ZEBRA_DPLANE_REQUEST_FAILURE
;
2738 struct zebra_dplane_ctx
*ctx
= NULL
;
2740 /* Obtain context block */
2741 ctx
= dplane_ctx_alloc();
2743 ret
= dplane_ctx_lsp_init(ctx
, op
, lsp
);
2747 ret
= dplane_update_enqueue(ctx
);
2750 /* Update counter */
2751 atomic_fetch_add_explicit(&zdplane_info
.dg_lsps_in
, 1,
2752 memory_order_relaxed
);
2755 result
= ZEBRA_DPLANE_REQUEST_QUEUED
;
2757 atomic_fetch_add_explicit(&zdplane_info
.dg_lsp_errors
, 1,
2758 memory_order_relaxed
);
2759 dplane_ctx_free(&ctx
);
2766 * Internal, common handler for pseudowire updates.
2768 static enum zebra_dplane_result
pw_update_internal(struct zebra_pw
*pw
,
2769 enum dplane_op_e op
)
2771 enum zebra_dplane_result result
= ZEBRA_DPLANE_REQUEST_FAILURE
;
2773 struct zebra_dplane_ctx
*ctx
= NULL
;
2775 ctx
= dplane_ctx_alloc();
2777 ret
= dplane_ctx_pw_init(ctx
, op
, pw
);
2781 ret
= dplane_update_enqueue(ctx
);
2784 /* Update counter */
2785 atomic_fetch_add_explicit(&zdplane_info
.dg_pws_in
, 1,
2786 memory_order_relaxed
);
2789 result
= ZEBRA_DPLANE_REQUEST_QUEUED
;
2791 atomic_fetch_add_explicit(&zdplane_info
.dg_pw_errors
, 1,
2792 memory_order_relaxed
);
2793 dplane_ctx_free(&ctx
);
2800 * Enqueue interface address add for the dataplane.
2802 enum zebra_dplane_result
dplane_intf_addr_set(const struct interface
*ifp
,
2803 const struct connected
*ifc
)
2805 #if !defined(HAVE_NETLINK) && defined(HAVE_STRUCT_IFALIASREQ)
2806 /* Extra checks for this OS path. */
2808 /* Don't configure PtP addresses on broadcast ifs or reverse */
2809 if (!(ifp
->flags
& IFF_POINTOPOINT
) != !CONNECTED_PEER(ifc
)) {
2810 if (IS_ZEBRA_DEBUG_KERNEL
|| IS_ZEBRA_DEBUG_DPLANE
)
2811 zlog_debug("Failed to set intf addr: mismatch p2p and connected");
2813 return ZEBRA_DPLANE_REQUEST_FAILURE
;
2816 /* Ensure that no existing installed v4 route conflicts with
2817 * the new interface prefix. This check must be done in the
2818 * zebra pthread context, and any route delete (if needed)
2819 * is enqueued before the interface address programming attempt.
2821 if (ifc
->address
->family
== AF_INET
) {
2822 struct prefix_ipv4
*p
;
2824 p
= (struct prefix_ipv4
*)ifc
->address
;
2825 rib_lookup_and_pushup(p
, ifp
->vrf_id
);
2829 return intf_addr_update_internal(ifp
, ifc
, DPLANE_OP_ADDR_INSTALL
);
2833 * Enqueue interface address remove/uninstall for the dataplane.
2835 enum zebra_dplane_result
dplane_intf_addr_unset(const struct interface
*ifp
,
2836 const struct connected
*ifc
)
2838 return intf_addr_update_internal(ifp
, ifc
, DPLANE_OP_ADDR_UNINSTALL
);
2841 static enum zebra_dplane_result
intf_addr_update_internal(
2842 const struct interface
*ifp
, const struct connected
*ifc
,
2843 enum dplane_op_e op
)
2845 enum zebra_dplane_result result
= ZEBRA_DPLANE_REQUEST_FAILURE
;
2847 struct zebra_dplane_ctx
*ctx
= NULL
;
2848 struct zebra_ns
*zns
;
2850 if (IS_ZEBRA_DEBUG_DPLANE_DETAIL
) {
2851 char addr_str
[PREFIX_STRLEN
];
2853 prefix2str(ifc
->address
, addr_str
, sizeof(addr_str
));
2855 zlog_debug("init intf ctx %s: idx %d, addr %u:%s",
2856 dplane_op2str(op
), ifp
->ifindex
, ifp
->vrf_id
,
2860 ctx
= dplane_ctx_alloc();
2863 ctx
->zd_status
= ZEBRA_DPLANE_REQUEST_SUCCESS
;
2864 ctx
->zd_vrf_id
= ifp
->vrf_id
;
2866 zns
= zebra_ns_lookup(ifp
->vrf_id
);
2867 dplane_ctx_ns_init(ctx
, zns
, false);
2869 /* Init the interface-addr-specific area */
2870 memset(&ctx
->u
.intf
, 0, sizeof(ctx
->u
.intf
));
2872 strlcpy(ctx
->zd_ifname
, ifp
->name
, sizeof(ctx
->zd_ifname
));
2873 ctx
->zd_ifindex
= ifp
->ifindex
;
2874 ctx
->u
.intf
.prefix
= *(ifc
->address
);
2876 if (if_is_broadcast(ifp
))
2877 ctx
->u
.intf
.flags
|= DPLANE_INTF_BROADCAST
;
2879 if (CONNECTED_PEER(ifc
)) {
2880 ctx
->u
.intf
.dest_prefix
= *(ifc
->destination
);
2881 ctx
->u
.intf
.flags
|=
2882 (DPLANE_INTF_CONNECTED
| DPLANE_INTF_HAS_DEST
);
2885 if (CHECK_FLAG(ifc
->flags
, ZEBRA_IFA_SECONDARY
))
2886 ctx
->u
.intf
.flags
|= DPLANE_INTF_SECONDARY
;
2891 ctx
->u
.intf
.flags
|= DPLANE_INTF_HAS_LABEL
;
2893 /* Use embedded buffer if it's adequate; else allocate. */
2894 len
= strlen(ifc
->label
);
2896 if (len
< sizeof(ctx
->u
.intf
.label_buf
)) {
2897 strlcpy(ctx
->u
.intf
.label_buf
, ifc
->label
,
2898 sizeof(ctx
->u
.intf
.label_buf
));
2899 ctx
->u
.intf
.label
= ctx
->u
.intf
.label_buf
;
2901 ctx
->u
.intf
.label
= strdup(ifc
->label
);
2905 ret
= dplane_update_enqueue(ctx
);
2907 /* Increment counter */
2908 atomic_fetch_add_explicit(&zdplane_info
.dg_intf_addrs_in
, 1,
2909 memory_order_relaxed
);
2912 result
= ZEBRA_DPLANE_REQUEST_QUEUED
;
2915 atomic_fetch_add_explicit(&zdplane_info
.dg_intf_addr_errors
,
2916 1, memory_order_relaxed
);
2917 dplane_ctx_free(&ctx
);
2924 * Enqueue vxlan/evpn mac add (or update).
2926 enum zebra_dplane_result
dplane_rem_mac_add(const struct interface
*ifp
,
2927 const struct interface
*bridge_ifp
,
2929 const struct ethaddr
*mac
,
2930 struct in_addr vtep_ip
,
2935 enum zebra_dplane_result result
;
2936 uint32_t update_flags
= 0;
2938 update_flags
|= DPLANE_MAC_REMOTE
;
2940 update_flags
|= DPLANE_MAC_WAS_STATIC
;
2942 /* Use common helper api */
2943 result
= mac_update_common(DPLANE_OP_MAC_INSTALL
, ifp
, bridge_ifp
,
2944 vid
, mac
, vtep_ip
, sticky
, nhg_id
, update_flags
);
2949 * Enqueue vxlan/evpn mac delete.
2951 enum zebra_dplane_result
dplane_rem_mac_del(const struct interface
*ifp
,
2952 const struct interface
*bridge_ifp
,
2954 const struct ethaddr
*mac
,
2955 struct in_addr vtep_ip
)
2957 enum zebra_dplane_result result
;
2958 uint32_t update_flags
= 0;
2960 update_flags
|= DPLANE_MAC_REMOTE
;
2962 /* Use common helper api */
2963 result
= mac_update_common(DPLANE_OP_MAC_DELETE
, ifp
, bridge_ifp
,
2964 vid
, mac
, vtep_ip
, false, 0, update_flags
);
2969 * Enqueue local mac add (or update).
2971 enum zebra_dplane_result
dplane_local_mac_add(const struct interface
*ifp
,
2972 const struct interface
*bridge_ifp
,
2974 const struct ethaddr
*mac
,
2976 uint32_t set_static
,
2977 uint32_t set_inactive
)
2979 enum zebra_dplane_result result
;
2980 uint32_t update_flags
= 0;
2981 struct in_addr vtep_ip
;
2984 update_flags
|= DPLANE_MAC_SET_STATIC
;
2987 update_flags
|= DPLANE_MAC_SET_INACTIVE
;
2991 /* Use common helper api */
2992 result
= mac_update_common(DPLANE_OP_MAC_INSTALL
, ifp
, bridge_ifp
,
2993 vid
, mac
, vtep_ip
, sticky
, 0,
2999 * Public api to init an empty context - either newly-allocated or
3000 * reset/cleared - for a MAC update.
3002 void dplane_mac_init(struct zebra_dplane_ctx
*ctx
,
3003 const struct interface
*ifp
,
3004 const struct interface
*br_ifp
,
3006 const struct ethaddr
*mac
,
3007 struct in_addr vtep_ip
,
3010 uint32_t update_flags
)
3012 struct zebra_ns
*zns
;
3014 ctx
->zd_status
= ZEBRA_DPLANE_REQUEST_SUCCESS
;
3015 ctx
->zd_vrf_id
= ifp
->vrf_id
;
3017 zns
= zebra_ns_lookup(ifp
->vrf_id
);
3018 dplane_ctx_ns_init(ctx
, zns
, false);
3020 strlcpy(ctx
->zd_ifname
, ifp
->name
, sizeof(ctx
->zd_ifname
));
3021 ctx
->zd_ifindex
= ifp
->ifindex
;
3023 /* Init the mac-specific data area */
3024 memset(&ctx
->u
.macinfo
, 0, sizeof(ctx
->u
.macinfo
));
3026 ctx
->u
.macinfo
.br_ifindex
= br_ifp
->ifindex
;
3027 ctx
->u
.macinfo
.vtep_ip
= vtep_ip
;
3028 ctx
->u
.macinfo
.mac
= *mac
;
3029 ctx
->u
.macinfo
.vid
= vid
;
3030 ctx
->u
.macinfo
.is_sticky
= sticky
;
3031 ctx
->u
.macinfo
.nhg_id
= nhg_id
;
3032 ctx
->u
.macinfo
.update_flags
= update_flags
;
3036 * Common helper api for MAC address/vxlan updates
3038 static enum zebra_dplane_result
3039 mac_update_common(enum dplane_op_e op
,
3040 const struct interface
*ifp
,
3041 const struct interface
*br_ifp
,
3043 const struct ethaddr
*mac
,
3044 struct in_addr vtep_ip
,
3047 uint32_t update_flags
)
3049 enum zebra_dplane_result result
= ZEBRA_DPLANE_REQUEST_FAILURE
;
3051 struct zebra_dplane_ctx
*ctx
= NULL
;
3053 if (IS_ZEBRA_DEBUG_DPLANE_DETAIL
) {
3054 char buf1
[ETHER_ADDR_STRLEN
], buf2
[PREFIX_STRLEN
];
3056 zlog_debug("init mac ctx %s: mac %s, ifp %s, vtep %s",
3058 prefix_mac2str(mac
, buf1
, sizeof(buf1
)),
3060 inet_ntop(AF_INET
, &vtep_ip
, buf2
, sizeof(buf2
)));
3063 ctx
= dplane_ctx_alloc();
3066 /* Common init for the ctx */
3067 dplane_mac_init(ctx
, ifp
, br_ifp
, vid
, mac
, vtep_ip
, sticky
,
3068 nhg_id
, update_flags
);
3070 /* Enqueue for processing on the dplane pthread */
3071 ret
= dplane_update_enqueue(ctx
);
3073 /* Increment counter */
3074 atomic_fetch_add_explicit(&zdplane_info
.dg_macs_in
, 1,
3075 memory_order_relaxed
);
3078 result
= ZEBRA_DPLANE_REQUEST_QUEUED
;
3081 atomic_fetch_add_explicit(&zdplane_info
.dg_mac_errors
, 1,
3082 memory_order_relaxed
);
3083 dplane_ctx_free(&ctx
);
3090 * Enqueue evpn neighbor add for the dataplane.
3092 enum zebra_dplane_result
dplane_rem_neigh_add(const struct interface
*ifp
,
3093 const struct ipaddr
*ip
,
3094 const struct ethaddr
*mac
,
3095 uint32_t flags
, bool was_static
)
3097 enum zebra_dplane_result result
= ZEBRA_DPLANE_REQUEST_FAILURE
;
3098 uint32_t update_flags
= 0;
3100 update_flags
|= DPLANE_NEIGH_REMOTE
;
3103 update_flags
|= DPLANE_NEIGH_WAS_STATIC
;
3105 result
= neigh_update_internal(DPLANE_OP_NEIGH_INSTALL
,
3106 ifp
, mac
, ip
, flags
, DPLANE_NUD_NOARP
,
3113 * Enqueue local neighbor add for the dataplane.
3115 enum zebra_dplane_result
dplane_local_neigh_add(const struct interface
*ifp
,
3116 const struct ipaddr
*ip
,
3117 const struct ethaddr
*mac
,
3118 bool set_router
, bool set_static
,
3121 enum zebra_dplane_result result
= ZEBRA_DPLANE_REQUEST_FAILURE
;
3122 uint32_t update_flags
= 0;
3127 update_flags
|= DPLANE_NEIGH_SET_STATIC
;
3130 update_flags
|= DPLANE_NEIGH_SET_INACTIVE
;
3131 state
= DPLANE_NUD_STALE
;
3133 state
= DPLANE_NUD_REACHABLE
;
3137 ntf
|= DPLANE_NTF_ROUTER
;
3139 result
= neigh_update_internal(DPLANE_OP_NEIGH_INSTALL
,
3141 state
, update_flags
);
3147 * Enqueue evpn neighbor delete for the dataplane.
3149 enum zebra_dplane_result
dplane_rem_neigh_delete(const struct interface
*ifp
,
3150 const struct ipaddr
*ip
)
3152 enum zebra_dplane_result result
;
3153 uint32_t update_flags
= 0;
3155 update_flags
|= DPLANE_NEIGH_REMOTE
;
3157 result
= neigh_update_internal(DPLANE_OP_NEIGH_DELETE
,
3158 ifp
, NULL
, ip
, 0, 0, update_flags
);
3164 * Enqueue evpn VTEP add for the dataplane.
3166 enum zebra_dplane_result
dplane_vtep_add(const struct interface
*ifp
,
3167 const struct in_addr
*ip
,
3170 enum zebra_dplane_result result
;
3171 struct ethaddr mac
= { {0, 0, 0, 0, 0, 0} };
3174 if (IS_ZEBRA_DEBUG_VXLAN
)
3175 zlog_debug("Install %s into flood list for VNI %u intf %s(%u)",
3176 inet_ntoa(*ip
), vni
, ifp
->name
, ifp
->ifindex
);
3178 SET_IPADDR_V4(&addr
);
3179 addr
.ipaddr_v4
= *ip
;
3181 result
= neigh_update_internal(DPLANE_OP_VTEP_ADD
,
3182 ifp
, &mac
, &addr
, 0, 0, 0);
3188 * Enqueue evpn VTEP add for the dataplane.
3190 enum zebra_dplane_result
dplane_vtep_delete(const struct interface
*ifp
,
3191 const struct in_addr
*ip
,
3194 enum zebra_dplane_result result
;
3195 struct ethaddr mac
= { {0, 0, 0, 0, 0, 0} };
3198 if (IS_ZEBRA_DEBUG_VXLAN
)
3200 "Uninstall %s from flood list for VNI %u intf %s(%u)",
3201 inet_ntoa(*ip
), vni
, ifp
->name
, ifp
->ifindex
);
3203 SET_IPADDR_V4(&addr
);
3204 addr
.ipaddr_v4
= *ip
;
3206 result
= neigh_update_internal(DPLANE_OP_VTEP_DELETE
,
3207 ifp
, &mac
, &addr
, 0, 0, 0);
3212 enum zebra_dplane_result
dplane_neigh_discover(const struct interface
*ifp
,
3213 const struct ipaddr
*ip
)
3215 enum zebra_dplane_result result
;
3217 result
= neigh_update_internal(DPLANE_OP_NEIGH_DISCOVER
, ifp
, NULL
, ip
,
3218 DPLANE_NTF_USE
, DPLANE_NUD_INCOMPLETE
, 0);
3224 * Common helper api for neighbor updates
3226 static enum zebra_dplane_result
3227 neigh_update_internal(enum dplane_op_e op
,
3228 const struct interface
*ifp
,
3229 const struct ethaddr
*mac
,
3230 const struct ipaddr
*ip
,
3231 uint32_t flags
, uint16_t state
,
3232 uint32_t update_flags
)
3234 enum zebra_dplane_result result
= ZEBRA_DPLANE_REQUEST_FAILURE
;
3236 struct zebra_dplane_ctx
*ctx
= NULL
;
3237 struct zebra_ns
*zns
;
3239 if (IS_ZEBRA_DEBUG_DPLANE_DETAIL
) {
3240 char buf1
[ETHER_ADDR_STRLEN
], buf2
[PREFIX_STRLEN
];
3242 zlog_debug("init neigh ctx %s: ifp %s, mac %s, ip %s",
3243 dplane_op2str(op
), ifp
->name
,
3244 prefix_mac2str(mac
, buf1
, sizeof(buf1
)),
3245 ipaddr2str(ip
, buf2
, sizeof(buf2
)));
3248 ctx
= dplane_ctx_alloc();
3251 ctx
->zd_status
= ZEBRA_DPLANE_REQUEST_SUCCESS
;
3252 ctx
->zd_vrf_id
= ifp
->vrf_id
;
3254 zns
= zebra_ns_lookup(ifp
->vrf_id
);
3255 dplane_ctx_ns_init(ctx
, zns
, false);
3257 strlcpy(ctx
->zd_ifname
, ifp
->name
, sizeof(ctx
->zd_ifname
));
3258 ctx
->zd_ifindex
= ifp
->ifindex
;
3260 /* Init the neighbor-specific data area */
3261 memset(&ctx
->u
.neigh
, 0, sizeof(ctx
->u
.neigh
));
3263 ctx
->u
.neigh
.ip_addr
= *ip
;
3265 ctx
->u
.neigh
.mac
= *mac
;
3266 ctx
->u
.neigh
.flags
= flags
;
3267 ctx
->u
.neigh
.state
= state
;
3268 ctx
->u
.neigh
.update_flags
= update_flags
;
3270 /* Enqueue for processing on the dplane pthread */
3271 ret
= dplane_update_enqueue(ctx
);
3273 /* Increment counter */
3274 atomic_fetch_add_explicit(&zdplane_info
.dg_neighs_in
, 1,
3275 memory_order_relaxed
);
3278 result
= ZEBRA_DPLANE_REQUEST_QUEUED
;
3281 atomic_fetch_add_explicit(&zdplane_info
.dg_neigh_errors
, 1,
3282 memory_order_relaxed
);
3283 dplane_ctx_free(&ctx
);
3290 * Common helper api for PBR rule updates
3292 static enum zebra_dplane_result
3293 rule_update_internal(enum dplane_op_e op
, struct zebra_pbr_rule
*new_rule
,
3294 struct zebra_pbr_rule
*old_rule
)
3296 enum zebra_dplane_result result
= ZEBRA_DPLANE_REQUEST_FAILURE
;
3297 struct zebra_dplane_ctx
*ctx
;
3300 ctx
= dplane_ctx_alloc();
3302 ret
= dplane_ctx_rule_init(ctx
, op
, new_rule
, old_rule
);
3306 ret
= dplane_update_enqueue(ctx
);
3309 atomic_fetch_add_explicit(&zdplane_info
.dg_rules_in
, 1,
3310 memory_order_relaxed
);
3313 result
= ZEBRA_DPLANE_REQUEST_QUEUED
;
3315 atomic_fetch_add_explicit(&zdplane_info
.dg_rule_errors
, 1,
3316 memory_order_relaxed
);
3317 dplane_ctx_free(&ctx
);
3323 enum zebra_dplane_result
dplane_pbr_rule_add(struct zebra_pbr_rule
*rule
)
3325 return rule_update_internal(DPLANE_OP_RULE_ADD
, rule
, NULL
);
3328 enum zebra_dplane_result
dplane_pbr_rule_delete(struct zebra_pbr_rule
*rule
)
3330 return rule_update_internal(DPLANE_OP_RULE_DELETE
, rule
, NULL
);
3333 enum zebra_dplane_result
dplane_pbr_rule_update(struct zebra_pbr_rule
*old_rule
,
3334 struct zebra_pbr_rule
*new_rule
)
3336 return rule_update_internal(DPLANE_OP_RULE_UPDATE
, new_rule
, old_rule
);
3340 * Handler for 'show dplane'
3342 int dplane_show_helper(struct vty
*vty
, bool detailed
)
3344 uint64_t queued
, queue_max
, limit
, errs
, incoming
, yields
,
3347 /* Using atomics because counters are being changed in different
3350 incoming
= atomic_load_explicit(&zdplane_info
.dg_routes_in
,
3351 memory_order_relaxed
);
3352 limit
= atomic_load_explicit(&zdplane_info
.dg_max_queued_updates
,
3353 memory_order_relaxed
);
3354 queued
= atomic_load_explicit(&zdplane_info
.dg_routes_queued
,
3355 memory_order_relaxed
);
3356 queue_max
= atomic_load_explicit(&zdplane_info
.dg_routes_queued_max
,
3357 memory_order_relaxed
);
3358 errs
= atomic_load_explicit(&zdplane_info
.dg_route_errors
,
3359 memory_order_relaxed
);
3360 yields
= atomic_load_explicit(&zdplane_info
.dg_update_yields
,
3361 memory_order_relaxed
);
3362 other_errs
= atomic_load_explicit(&zdplane_info
.dg_other_errors
,
3363 memory_order_relaxed
);
3365 vty_out(vty
, "Zebra dataplane:\nRoute updates: %"PRIu64
"\n",
3367 vty_out(vty
, "Route update errors: %"PRIu64
"\n", errs
);
3368 vty_out(vty
, "Other errors : %"PRIu64
"\n", other_errs
);
3369 vty_out(vty
, "Route update queue limit: %"PRIu64
"\n", limit
);
3370 vty_out(vty
, "Route update queue depth: %"PRIu64
"\n", queued
);
3371 vty_out(vty
, "Route update queue max: %"PRIu64
"\n", queue_max
);
3372 vty_out(vty
, "Dplane update yields: %"PRIu64
"\n", yields
);
3374 incoming
= atomic_load_explicit(&zdplane_info
.dg_lsps_in
,
3375 memory_order_relaxed
);
3376 errs
= atomic_load_explicit(&zdplane_info
.dg_lsp_errors
,
3377 memory_order_relaxed
);
3378 vty_out(vty
, "LSP updates: %"PRIu64
"\n", incoming
);
3379 vty_out(vty
, "LSP update errors: %"PRIu64
"\n", errs
);
3381 incoming
= atomic_load_explicit(&zdplane_info
.dg_pws_in
,
3382 memory_order_relaxed
);
3383 errs
= atomic_load_explicit(&zdplane_info
.dg_pw_errors
,
3384 memory_order_relaxed
);
3385 vty_out(vty
, "PW updates: %"PRIu64
"\n", incoming
);
3386 vty_out(vty
, "PW update errors: %"PRIu64
"\n", errs
);
3388 incoming
= atomic_load_explicit(&zdplane_info
.dg_intf_addrs_in
,
3389 memory_order_relaxed
);
3390 errs
= atomic_load_explicit(&zdplane_info
.dg_intf_addr_errors
,
3391 memory_order_relaxed
);
3392 vty_out(vty
, "Intf addr updates: %"PRIu64
"\n", incoming
);
3393 vty_out(vty
, "Intf addr errors: %"PRIu64
"\n", errs
);
3395 incoming
= atomic_load_explicit(&zdplane_info
.dg_macs_in
,
3396 memory_order_relaxed
);
3397 errs
= atomic_load_explicit(&zdplane_info
.dg_mac_errors
,
3398 memory_order_relaxed
);
3399 vty_out(vty
, "EVPN MAC updates: %"PRIu64
"\n", incoming
);
3400 vty_out(vty
, "EVPN MAC errors: %"PRIu64
"\n", errs
);
3402 incoming
= atomic_load_explicit(&zdplane_info
.dg_neighs_in
,
3403 memory_order_relaxed
);
3404 errs
= atomic_load_explicit(&zdplane_info
.dg_neigh_errors
,
3405 memory_order_relaxed
);
3406 vty_out(vty
, "EVPN neigh updates: %"PRIu64
"\n", incoming
);
3407 vty_out(vty
, "EVPN neigh errors: %"PRIu64
"\n", errs
);
3409 incoming
= atomic_load_explicit(&zdplane_info
.dg_rules_in
,
3410 memory_order_relaxed
);
3411 errs
= atomic_load_explicit(&zdplane_info
.dg_rule_errors
,
3412 memory_order_relaxed
);
3413 vty_out(vty
, "Rule updates: %" PRIu64
"\n", incoming
);
3414 vty_out(vty
, "Rule errors: %" PRIu64
"\n", errs
);
3420 * Handler for 'show dplane providers'
3422 int dplane_show_provs_helper(struct vty
*vty
, bool detailed
)
3424 struct zebra_dplane_provider
*prov
;
3425 uint64_t in
, in_max
, out
, out_max
;
3427 vty_out(vty
, "Zebra dataplane providers:\n");
3430 prov
= TAILQ_FIRST(&zdplane_info
.dg_providers_q
);
3433 /* Show counters, useful info from each registered provider */
3436 in
= atomic_load_explicit(&prov
->dp_in_counter
,
3437 memory_order_relaxed
);
3438 in_max
= atomic_load_explicit(&prov
->dp_in_max
,
3439 memory_order_relaxed
);
3440 out
= atomic_load_explicit(&prov
->dp_out_counter
,
3441 memory_order_relaxed
);
3442 out_max
= atomic_load_explicit(&prov
->dp_out_max
,
3443 memory_order_relaxed
);
3446 "%s (%u): in: %" PRIu64
", q_max: %" PRIu64
3447 ", out: %" PRIu64
", q_max: %" PRIu64
"\n",
3448 prov
->dp_name
, prov
->dp_id
, in
, in_max
, out
, out_max
);
3451 prov
= TAILQ_NEXT(prov
, dp_prov_link
);
3459 * Helper for 'show run' etc.
3461 int dplane_config_write_helper(struct vty
*vty
)
3463 if (zdplane_info
.dg_max_queued_updates
!= DPLANE_DEFAULT_MAX_QUEUED
)
3464 vty_out(vty
, "zebra dplane limit %u\n",
3465 zdplane_info
.dg_max_queued_updates
);
3471 * Provider registration
3473 int dplane_provider_register(const char *name
,
3474 enum dplane_provider_prio prio
,
3476 int (*start_fp
)(struct zebra_dplane_provider
*),
3477 int (*fp
)(struct zebra_dplane_provider
*),
3478 int (*fini_fp
)(struct zebra_dplane_provider
*,
3481 struct zebra_dplane_provider
**prov_p
)
3484 struct zebra_dplane_provider
*p
= NULL
, *last
;
3492 if (prio
<= DPLANE_PRIO_NONE
||
3493 prio
> DPLANE_PRIO_LAST
) {
3498 /* Allocate and init new provider struct */
3499 p
= XCALLOC(MTYPE_DP_PROV
, sizeof(struct zebra_dplane_provider
));
3501 pthread_mutex_init(&(p
->dp_mutex
), NULL
);
3502 TAILQ_INIT(&(p
->dp_ctx_in_q
));
3503 TAILQ_INIT(&(p
->dp_ctx_out_q
));
3505 p
->dp_flags
= flags
;
3506 p
->dp_priority
= prio
;
3508 p
->dp_start
= start_fp
;
3509 p
->dp_fini
= fini_fp
;
3512 /* Lock - the dplane pthread may be running */
3515 p
->dp_id
= ++zdplane_info
.dg_provider_id
;
3518 strlcpy(p
->dp_name
, name
, DPLANE_PROVIDER_NAMELEN
);
3520 snprintf(p
->dp_name
, DPLANE_PROVIDER_NAMELEN
,
3521 "provider-%u", p
->dp_id
);
3523 /* Insert into list ordered by priority */
3524 TAILQ_FOREACH(last
, &zdplane_info
.dg_providers_q
, dp_prov_link
) {
3525 if (last
->dp_priority
> p
->dp_priority
)
3530 TAILQ_INSERT_BEFORE(last
, p
, dp_prov_link
);
3532 TAILQ_INSERT_TAIL(&zdplane_info
.dg_providers_q
, p
,
3538 if (IS_ZEBRA_DEBUG_DPLANE
)
3539 zlog_debug("dplane: registered new provider '%s' (%u), prio %d",
3540 p
->dp_name
, p
->dp_id
, p
->dp_priority
);
3549 /* Accessors for provider attributes */
3550 const char *dplane_provider_get_name(const struct zebra_dplane_provider
*prov
)
3552 return prov
->dp_name
;
3555 uint32_t dplane_provider_get_id(const struct zebra_dplane_provider
*prov
)
3560 void *dplane_provider_get_data(const struct zebra_dplane_provider
*prov
)
3562 return prov
->dp_data
;
3565 int dplane_provider_get_work_limit(const struct zebra_dplane_provider
*prov
)
3567 return zdplane_info
.dg_updates_per_cycle
;
3570 /* Lock/unlock a provider's mutex - iff the provider was registered with
3571 * the THREADED flag.
3573 void dplane_provider_lock(struct zebra_dplane_provider
*prov
)
3575 if (dplane_provider_is_threaded(prov
))
3576 DPLANE_PROV_LOCK(prov
);
3579 void dplane_provider_unlock(struct zebra_dplane_provider
*prov
)
3581 if (dplane_provider_is_threaded(prov
))
3582 DPLANE_PROV_UNLOCK(prov
);
3586 * Dequeue and maintain associated counter
3588 struct zebra_dplane_ctx
*dplane_provider_dequeue_in_ctx(
3589 struct zebra_dplane_provider
*prov
)
3591 struct zebra_dplane_ctx
*ctx
= NULL
;
3593 dplane_provider_lock(prov
);
3595 ctx
= TAILQ_FIRST(&(prov
->dp_ctx_in_q
));
3597 TAILQ_REMOVE(&(prov
->dp_ctx_in_q
), ctx
, zd_q_entries
);
3599 atomic_fetch_sub_explicit(&prov
->dp_in_queued
, 1,
3600 memory_order_relaxed
);
3603 dplane_provider_unlock(prov
);
3609 * Dequeue work to a list, return count
3611 int dplane_provider_dequeue_in_list(struct zebra_dplane_provider
*prov
,
3612 struct dplane_ctx_q
*listp
)
3615 struct zebra_dplane_ctx
*ctx
;
3617 limit
= zdplane_info
.dg_updates_per_cycle
;
3619 dplane_provider_lock(prov
);
3621 for (ret
= 0; ret
< limit
; ret
++) {
3622 ctx
= TAILQ_FIRST(&(prov
->dp_ctx_in_q
));
3624 TAILQ_REMOVE(&(prov
->dp_ctx_in_q
), ctx
, zd_q_entries
);
3626 TAILQ_INSERT_TAIL(listp
, ctx
, zd_q_entries
);
3633 atomic_fetch_sub_explicit(&prov
->dp_in_queued
, ret
,
3634 memory_order_relaxed
);
3636 dplane_provider_unlock(prov
);
3642 * Enqueue and maintain associated counter
3644 void dplane_provider_enqueue_out_ctx(struct zebra_dplane_provider
*prov
,
3645 struct zebra_dplane_ctx
*ctx
)
3647 dplane_provider_lock(prov
);
3649 TAILQ_INSERT_TAIL(&(prov
->dp_ctx_out_q
), ctx
,
3652 dplane_provider_unlock(prov
);
3654 atomic_fetch_add_explicit(&(prov
->dp_out_counter
), 1,
3655 memory_order_relaxed
);
3659 * Accessor for provider object
3661 bool dplane_provider_is_threaded(const struct zebra_dplane_provider
*prov
)
3663 return (prov
->dp_flags
& DPLANE_PROV_FLAG_THREADED
);
3667 * Internal helper that copies information from a zebra ns object; this is
3668 * called in the zebra main pthread context as part of dplane ctx init.
3670 static void dplane_info_from_zns(struct zebra_dplane_info
*ns_info
,
3671 struct zebra_ns
*zns
)
3673 ns_info
->ns_id
= zns
->ns_id
;
3675 #if defined(HAVE_NETLINK)
3676 ns_info
->is_cmd
= true;
3677 ns_info
->nls
= zns
->netlink_dplane
;
3678 #endif /* NETLINK */
3682 * Provider api to signal that work/events are available
3683 * for the dataplane pthread.
3685 int dplane_provider_work_ready(void)
3687 /* Note that during zebra startup, we may be offered work before
3688 * the dataplane pthread (and thread-master) are ready. We want to
3689 * enqueue the work, but the event-scheduling machinery may not be
3692 if (zdplane_info
.dg_run
) {
3693 thread_add_event(zdplane_info
.dg_master
,
3694 dplane_thread_loop
, NULL
, 0,
3695 &zdplane_info
.dg_t_update
);
3702 * Enqueue a context directly to zebra main.
3704 void dplane_provider_enqueue_to_zebra(struct zebra_dplane_ctx
*ctx
)
3706 struct dplane_ctx_q temp_list
;
3708 /* Zebra's api takes a list, so we need to use a temporary list */
3709 TAILQ_INIT(&temp_list
);
3711 TAILQ_INSERT_TAIL(&temp_list
, ctx
, zd_q_entries
);
3712 (zdplane_info
.dg_results_cb
)(&temp_list
);
3716 * Kernel dataplane provider
3719 static void kernel_dplane_log_detail(struct zebra_dplane_ctx
*ctx
)
3721 char buf
[PREFIX_STRLEN
];
3723 switch (dplane_ctx_get_op(ctx
)) {
3725 case DPLANE_OP_ROUTE_INSTALL
:
3726 case DPLANE_OP_ROUTE_UPDATE
:
3727 case DPLANE_OP_ROUTE_DELETE
:
3728 prefix2str(dplane_ctx_get_dest(ctx
), buf
, sizeof(buf
));
3730 zlog_debug("%u:%s Dplane route update ctx %p op %s",
3731 dplane_ctx_get_vrf(ctx
), buf
, ctx
,
3732 dplane_op2str(dplane_ctx_get_op(ctx
)));
3735 case DPLANE_OP_NH_INSTALL
:
3736 case DPLANE_OP_NH_UPDATE
:
3737 case DPLANE_OP_NH_DELETE
:
3738 zlog_debug("ID (%u) Dplane nexthop update ctx %p op %s",
3739 dplane_ctx_get_nhe_id(ctx
), ctx
,
3740 dplane_op2str(dplane_ctx_get_op(ctx
)));
3743 case DPLANE_OP_LSP_INSTALL
:
3744 case DPLANE_OP_LSP_UPDATE
:
3745 case DPLANE_OP_LSP_DELETE
:
3748 case DPLANE_OP_PW_INSTALL
:
3749 case DPLANE_OP_PW_UNINSTALL
:
3750 zlog_debug("Dplane pw %s: op %s af %d loc: %u rem: %u",
3751 dplane_ctx_get_ifname(ctx
),
3752 dplane_op2str(ctx
->zd_op
), dplane_ctx_get_pw_af(ctx
),
3753 dplane_ctx_get_pw_local_label(ctx
),
3754 dplane_ctx_get_pw_remote_label(ctx
));
3757 case DPLANE_OP_ADDR_INSTALL
:
3758 case DPLANE_OP_ADDR_UNINSTALL
:
3759 prefix2str(dplane_ctx_get_intf_addr(ctx
), buf
, sizeof(buf
));
3761 zlog_debug("Dplane intf %s, idx %u, addr %s",
3762 dplane_op2str(dplane_ctx_get_op(ctx
)),
3763 dplane_ctx_get_ifindex(ctx
), buf
);
3766 case DPLANE_OP_MAC_INSTALL
:
3767 case DPLANE_OP_MAC_DELETE
:
3768 prefix_mac2str(dplane_ctx_mac_get_addr(ctx
), buf
,
3771 zlog_debug("Dplane %s, mac %s, ifindex %u",
3772 dplane_op2str(dplane_ctx_get_op(ctx
)),
3773 buf
, dplane_ctx_get_ifindex(ctx
));
3776 case DPLANE_OP_NEIGH_INSTALL
:
3777 case DPLANE_OP_NEIGH_UPDATE
:
3778 case DPLANE_OP_NEIGH_DELETE
:
3779 case DPLANE_OP_VTEP_ADD
:
3780 case DPLANE_OP_VTEP_DELETE
:
3781 case DPLANE_OP_NEIGH_DISCOVER
:
3782 ipaddr2str(dplane_ctx_neigh_get_ipaddr(ctx
), buf
,
3785 zlog_debug("Dplane %s, ip %s, ifindex %u",
3786 dplane_op2str(dplane_ctx_get_op(ctx
)),
3787 buf
, dplane_ctx_get_ifindex(ctx
));
3790 case DPLANE_OP_RULE_ADD
:
3791 case DPLANE_OP_RULE_DELETE
:
3792 case DPLANE_OP_RULE_UPDATE
:
3793 zlog_debug("Dplane rule update op %s, if %s(%u), ctx %p",
3794 dplane_op2str(dplane_ctx_get_op(ctx
)),
3795 dplane_ctx_get_ifname(ctx
),
3796 dplane_ctx_get_ifindex(ctx
), ctx
);
3799 case DPLANE_OP_SYS_ROUTE_ADD
:
3800 case DPLANE_OP_SYS_ROUTE_DELETE
:
3801 case DPLANE_OP_ROUTE_NOTIFY
:
3802 case DPLANE_OP_LSP_NOTIFY
:
3804 case DPLANE_OP_NONE
:
3809 static void kernel_dplane_handle_result(struct zebra_dplane_ctx
*ctx
)
3811 enum zebra_dplane_result res
= dplane_ctx_get_status(ctx
);
3813 switch (dplane_ctx_get_op(ctx
)) {
3815 case DPLANE_OP_ROUTE_INSTALL
:
3816 case DPLANE_OP_ROUTE_UPDATE
:
3817 case DPLANE_OP_ROUTE_DELETE
:
3818 if (res
!= ZEBRA_DPLANE_REQUEST_SUCCESS
)
3819 atomic_fetch_add_explicit(&zdplane_info
.dg_route_errors
,
3820 1, memory_order_relaxed
);
3822 if ((dplane_ctx_get_op(ctx
) != DPLANE_OP_ROUTE_DELETE
)
3823 && (res
== ZEBRA_DPLANE_REQUEST_SUCCESS
)) {
3824 struct nexthop
*nexthop
;
3826 /* Update installed nexthops to signal which have been
3829 for (ALL_NEXTHOPS_PTR(dplane_ctx_get_ng(ctx
),
3831 if (CHECK_FLAG(nexthop
->flags
,
3832 NEXTHOP_FLAG_RECURSIVE
))
3835 if (CHECK_FLAG(nexthop
->flags
,
3836 NEXTHOP_FLAG_ACTIVE
)) {
3837 SET_FLAG(nexthop
->flags
,
3844 case DPLANE_OP_NH_INSTALL
:
3845 case DPLANE_OP_NH_UPDATE
:
3846 case DPLANE_OP_NH_DELETE
:
3847 if (res
!= ZEBRA_DPLANE_REQUEST_SUCCESS
)
3848 atomic_fetch_add_explicit(
3849 &zdplane_info
.dg_nexthop_errors
, 1,
3850 memory_order_relaxed
);
3853 case DPLANE_OP_LSP_INSTALL
:
3854 case DPLANE_OP_LSP_UPDATE
:
3855 case DPLANE_OP_LSP_DELETE
:
3856 if (res
!= ZEBRA_DPLANE_REQUEST_SUCCESS
)
3857 atomic_fetch_add_explicit(&zdplane_info
.dg_lsp_errors
,
3858 1, memory_order_relaxed
);
3861 case DPLANE_OP_PW_INSTALL
:
3862 case DPLANE_OP_PW_UNINSTALL
:
3863 if (res
!= ZEBRA_DPLANE_REQUEST_SUCCESS
)
3864 atomic_fetch_add_explicit(&zdplane_info
.dg_pw_errors
, 1,
3865 memory_order_relaxed
);
3868 case DPLANE_OP_ADDR_INSTALL
:
3869 case DPLANE_OP_ADDR_UNINSTALL
:
3870 if (res
!= ZEBRA_DPLANE_REQUEST_SUCCESS
)
3871 atomic_fetch_add_explicit(
3872 &zdplane_info
.dg_intf_addr_errors
, 1,
3873 memory_order_relaxed
);
3876 case DPLANE_OP_MAC_INSTALL
:
3877 case DPLANE_OP_MAC_DELETE
:
3878 if (res
!= ZEBRA_DPLANE_REQUEST_SUCCESS
)
3879 atomic_fetch_add_explicit(&zdplane_info
.dg_mac_errors
,
3880 1, memory_order_relaxed
);
3883 case DPLANE_OP_NEIGH_INSTALL
:
3884 case DPLANE_OP_NEIGH_UPDATE
:
3885 case DPLANE_OP_NEIGH_DELETE
:
3886 case DPLANE_OP_VTEP_ADD
:
3887 case DPLANE_OP_VTEP_DELETE
:
3888 case DPLANE_OP_NEIGH_DISCOVER
:
3889 if (res
!= ZEBRA_DPLANE_REQUEST_SUCCESS
)
3890 atomic_fetch_add_explicit(&zdplane_info
.dg_neigh_errors
,
3891 1, memory_order_relaxed
);
3894 case DPLANE_OP_RULE_ADD
:
3895 case DPLANE_OP_RULE_DELETE
:
3896 case DPLANE_OP_RULE_UPDATE
:
3897 if (res
!= ZEBRA_DPLANE_REQUEST_SUCCESS
)
3898 atomic_fetch_add_explicit(&zdplane_info
.dg_rule_errors
,
3899 1, memory_order_relaxed
);
3902 /* Ignore 'notifications' - no-op */
3903 case DPLANE_OP_SYS_ROUTE_ADD
:
3904 case DPLANE_OP_SYS_ROUTE_DELETE
:
3905 case DPLANE_OP_ROUTE_NOTIFY
:
3906 case DPLANE_OP_LSP_NOTIFY
:
3909 case DPLANE_OP_NONE
:
3910 if (res
!= ZEBRA_DPLANE_REQUEST_SUCCESS
)
3911 atomic_fetch_add_explicit(&zdplane_info
.dg_other_errors
,
3912 1, memory_order_relaxed
);
3918 * Kernel provider callback
3920 static int kernel_dplane_process_func(struct zebra_dplane_provider
*prov
)
3922 struct zebra_dplane_ctx
*ctx
, *tctx
;
3923 struct dplane_ctx_q work_list
;
3926 TAILQ_INIT(&work_list
);
3928 limit
= dplane_provider_get_work_limit(prov
);
3930 if (IS_ZEBRA_DEBUG_DPLANE_DETAIL
)
3931 zlog_debug("dplane provider '%s': processing",
3932 dplane_provider_get_name(prov
));
3934 for (counter
= 0; counter
< limit
; counter
++) {
3935 ctx
= dplane_provider_dequeue_in_ctx(prov
);
3939 if (IS_ZEBRA_DEBUG_DPLANE_DETAIL
)
3940 kernel_dplane_log_detail(ctx
);
3942 TAILQ_INSERT_TAIL(&work_list
, ctx
, zd_q_entries
);
3945 kernel_update_multi(&work_list
);
3947 TAILQ_FOREACH_SAFE (ctx
, &work_list
, zd_q_entries
, tctx
) {
3948 kernel_dplane_handle_result(ctx
);
3950 TAILQ_REMOVE(&work_list
, ctx
, zd_q_entries
);
3951 dplane_provider_enqueue_out_ctx(prov
, ctx
);
3954 /* Ensure that we'll run the work loop again if there's still
3957 if (counter
>= limit
) {
3958 if (IS_ZEBRA_DEBUG_DPLANE_DETAIL
)
3959 zlog_debug("dplane provider '%s' reached max updates %d",
3960 dplane_provider_get_name(prov
), counter
);
3962 atomic_fetch_add_explicit(&zdplane_info
.dg_update_yields
,
3963 1, memory_order_relaxed
);
3965 dplane_provider_work_ready();
3971 #ifdef DPLANE_TEST_PROVIDER
3974 * Test dataplane provider plugin
3978 * Test provider process callback
3980 static int test_dplane_process_func(struct zebra_dplane_provider
*prov
)
3982 struct zebra_dplane_ctx
*ctx
;
3985 /* Just moving from 'in' queue to 'out' queue */
3987 if (IS_ZEBRA_DEBUG_DPLANE_DETAIL
)
3988 zlog_debug("dplane provider '%s': processing",
3989 dplane_provider_get_name(prov
));
3991 limit
= dplane_provider_get_work_limit(prov
);
3993 for (counter
= 0; counter
< limit
; counter
++) {
3994 ctx
= dplane_provider_dequeue_in_ctx(prov
);
3998 if (IS_ZEBRA_DEBUG_DPLANE_DETAIL
)
3999 zlog_debug("dplane provider '%s': op %s",
4000 dplane_provider_get_name(prov
),
4001 dplane_op2str(dplane_ctx_get_op(ctx
)));
4003 dplane_ctx_set_status(ctx
, ZEBRA_DPLANE_REQUEST_SUCCESS
);
4005 dplane_provider_enqueue_out_ctx(prov
, ctx
);
4008 if (IS_ZEBRA_DEBUG_DPLANE_DETAIL
)
4009 zlog_debug("dplane provider '%s': processed %d",
4010 dplane_provider_get_name(prov
), counter
);
4012 /* Ensure that we'll run the work loop again if there's still
4015 if (counter
>= limit
)
4016 dplane_provider_work_ready();
4022 * Test provider shutdown/fini callback
4024 static int test_dplane_shutdown_func(struct zebra_dplane_provider
*prov
,
4027 if (IS_ZEBRA_DEBUG_DPLANE
)
4028 zlog_debug("dplane provider '%s': %sshutdown",
4029 dplane_provider_get_name(prov
),
4030 early
? "early " : "");
4034 #endif /* DPLANE_TEST_PROVIDER */
4037 * Register default kernel provider
4039 static void dplane_provider_init(void)
4043 ret
= dplane_provider_register("Kernel",
4045 DPLANE_PROV_FLAGS_DEFAULT
, NULL
,
4046 kernel_dplane_process_func
,
4051 zlog_err("Unable to register kernel dplane provider: %d",
4054 #ifdef DPLANE_TEST_PROVIDER
4055 /* Optional test provider ... */
4056 ret
= dplane_provider_register("Test",
4057 DPLANE_PRIO_PRE_KERNEL
,
4058 DPLANE_PROV_FLAGS_DEFAULT
, NULL
,
4059 test_dplane_process_func
,
4060 test_dplane_shutdown_func
,
4061 NULL
/* data */, NULL
);
4064 zlog_err("Unable to register test dplane provider: %d",
4066 #endif /* DPLANE_TEST_PROVIDER */
4069 /* Indicates zebra shutdown/exit is in progress. Some operations may be
4070 * simplified or skipped during shutdown processing.
4072 bool dplane_is_in_shutdown(void)
4074 return zdplane_info
.dg_is_shutdown
;
4078 * Early or pre-shutdown, de-init notification api. This runs pretty
4079 * early during zebra shutdown, as a signal to stop new work and prepare
4080 * for updates generated by shutdown/cleanup activity, as zebra tries to
4081 * remove everything it's responsible for.
4082 * NB: This runs in the main zebra pthread context.
4084 void zebra_dplane_pre_finish(void)
4086 struct zebra_dplane_provider
*prov
;
4088 if (IS_ZEBRA_DEBUG_DPLANE
)
4089 zlog_debug("Zebra dataplane pre-finish called");
4091 zdplane_info
.dg_is_shutdown
= true;
4093 /* Notify provider(s) of pending shutdown. */
4094 TAILQ_FOREACH(prov
, &zdplane_info
.dg_providers_q
, dp_prov_link
) {
4095 if (prov
->dp_fini
== NULL
)
4098 prov
->dp_fini(prov
, true /* early */);
4103 * Utility to determine whether work remains enqueued within the dplane;
4104 * used during system shutdown processing.
4106 static bool dplane_work_pending(void)
4109 struct zebra_dplane_ctx
*ctx
;
4110 struct zebra_dplane_provider
*prov
;
4112 /* TODO -- just checking incoming/pending work for now, must check
4117 ctx
= TAILQ_FIRST(&zdplane_info
.dg_update_ctx_q
);
4118 prov
= TAILQ_FIRST(&zdplane_info
.dg_providers_q
);
4129 dplane_provider_lock(prov
);
4131 ctx
= TAILQ_FIRST(&(prov
->dp_ctx_in_q
));
4133 ctx
= TAILQ_FIRST(&(prov
->dp_ctx_out_q
));
4135 dplane_provider_unlock(prov
);
4141 prov
= TAILQ_NEXT(prov
, dp_prov_link
);
4153 * Shutdown-time intermediate callback, used to determine when all pending
4154 * in-flight updates are done. If there's still work to do, reschedules itself.
4155 * If all work is done, schedules an event to the main zebra thread for
4156 * final zebra shutdown.
4157 * This runs in the dplane pthread context.
4159 static int dplane_check_shutdown_status(struct thread
*event
)
4161 if (IS_ZEBRA_DEBUG_DPLANE
)
4162 zlog_debug("Zebra dataplane shutdown status check called");
4164 if (dplane_work_pending()) {
4165 /* Reschedule dplane check on a short timer */
4166 thread_add_timer_msec(zdplane_info
.dg_master
,
4167 dplane_check_shutdown_status
,
4169 &zdplane_info
.dg_t_shutdown_check
);
4171 /* TODO - give up and stop waiting after a short time? */
4174 /* We appear to be done - schedule a final callback event
4175 * for the zebra main pthread.
4177 thread_add_event(zrouter
.master
, zebra_finalize
, NULL
, 0, NULL
);
4184 * Shutdown, de-init api. This runs pretty late during shutdown,
4185 * after zebra has tried to free/remove/uninstall all routes during shutdown.
4186 * At this point, dplane work may still remain to be done, so we can't just
4187 * blindly terminate. If there's still work to do, we'll periodically check
4188 * and when done, we'll enqueue a task to the zebra main thread for final
4189 * termination processing.
4191 * NB: This runs in the main zebra thread context.
4193 void zebra_dplane_finish(void)
4195 if (IS_ZEBRA_DEBUG_DPLANE
)
4196 zlog_debug("Zebra dataplane fini called");
4198 thread_add_event(zdplane_info
.dg_master
,
4199 dplane_check_shutdown_status
, NULL
, 0,
4200 &zdplane_info
.dg_t_shutdown_check
);
4204 * Main dataplane pthread event loop. The thread takes new incoming work
4205 * and offers it to the first provider. It then iterates through the
4206 * providers, taking complete work from each one and offering it
4207 * to the next in order. At each step, a limited number of updates are
4208 * processed during a cycle in order to provide some fairness.
4210 * This loop through the providers is only run once, so that the dataplane
4211 * pthread can look for other pending work - such as i/o work on behalf of
4214 static int dplane_thread_loop(struct thread
*event
)
4216 struct dplane_ctx_q work_list
;
4217 struct dplane_ctx_q error_list
;
4218 struct zebra_dplane_provider
*prov
;
4219 struct zebra_dplane_ctx
*ctx
, *tctx
;
4220 int limit
, counter
, error_counter
;
4221 uint64_t curr
, high
;
4223 /* Capture work limit per cycle */
4224 limit
= zdplane_info
.dg_updates_per_cycle
;
4226 /* Init temporary lists used to move contexts among providers */
4227 TAILQ_INIT(&work_list
);
4228 TAILQ_INIT(&error_list
);
4231 /* Check for zebra shutdown */
4232 if (!zdplane_info
.dg_run
)
4235 /* Dequeue some incoming work from zebra (if any) onto the temporary
4240 /* Locate initial registered provider */
4241 prov
= TAILQ_FIRST(&zdplane_info
.dg_providers_q
);
4243 /* Move new work from incoming list to temp list */
4244 for (counter
= 0; counter
< limit
; counter
++) {
4245 ctx
= TAILQ_FIRST(&zdplane_info
.dg_update_ctx_q
);
4247 TAILQ_REMOVE(&zdplane_info
.dg_update_ctx_q
, ctx
,
4250 ctx
->zd_provider
= prov
->dp_id
;
4252 TAILQ_INSERT_TAIL(&work_list
, ctx
, zd_q_entries
);
4260 atomic_fetch_sub_explicit(&zdplane_info
.dg_routes_queued
, counter
,
4261 memory_order_relaxed
);
4263 if (IS_ZEBRA_DEBUG_DPLANE_DETAIL
)
4264 zlog_debug("dplane: incoming new work counter: %d", counter
);
4266 /* Iterate through the registered providers, offering new incoming
4267 * work. If the provider has outgoing work in its queue, take that
4268 * work for the next provider
4272 /* At each iteration, the temporary work list has 'counter'
4275 if (IS_ZEBRA_DEBUG_DPLANE_DETAIL
)
4276 zlog_debug("dplane enqueues %d new work to provider '%s'",
4277 counter
, dplane_provider_get_name(prov
));
4279 /* Capture current provider id in each context; check for
4282 TAILQ_FOREACH_SAFE(ctx
, &work_list
, zd_q_entries
, tctx
) {
4283 if (dplane_ctx_get_status(ctx
) ==
4284 ZEBRA_DPLANE_REQUEST_SUCCESS
) {
4285 ctx
->zd_provider
= prov
->dp_id
;
4288 * TODO -- improve error-handling: recirc
4289 * errors backwards so that providers can
4290 * 'undo' their work (if they want to)
4293 /* Move to error list; will be returned
4296 TAILQ_REMOVE(&work_list
, ctx
, zd_q_entries
);
4297 TAILQ_INSERT_TAIL(&error_list
,
4303 /* Enqueue new work to the provider */
4304 dplane_provider_lock(prov
);
4306 if (TAILQ_FIRST(&work_list
))
4307 TAILQ_CONCAT(&(prov
->dp_ctx_in_q
), &work_list
,
4310 atomic_fetch_add_explicit(&prov
->dp_in_counter
, counter
,
4311 memory_order_relaxed
);
4312 atomic_fetch_add_explicit(&prov
->dp_in_queued
, counter
,
4313 memory_order_relaxed
);
4314 curr
= atomic_load_explicit(&prov
->dp_in_queued
,
4315 memory_order_relaxed
);
4316 high
= atomic_load_explicit(&prov
->dp_in_max
,
4317 memory_order_relaxed
);
4319 atomic_store_explicit(&prov
->dp_in_max
, curr
,
4320 memory_order_relaxed
);
4322 dplane_provider_unlock(prov
);
4324 /* Reset the temp list (though the 'concat' may have done this
4325 * already), and the counter
4327 TAILQ_INIT(&work_list
);
4330 /* Call into the provider code. Note that this is
4331 * unconditional: we offer to do work even if we don't enqueue
4334 (*prov
->dp_fp
)(prov
);
4336 /* Check for zebra shutdown */
4337 if (!zdplane_info
.dg_run
)
4340 /* Dequeue completed work from the provider */
4341 dplane_provider_lock(prov
);
4343 while (counter
< limit
) {
4344 ctx
= TAILQ_FIRST(&(prov
->dp_ctx_out_q
));
4346 TAILQ_REMOVE(&(prov
->dp_ctx_out_q
), ctx
,
4349 TAILQ_INSERT_TAIL(&work_list
,
4356 dplane_provider_unlock(prov
);
4358 if (IS_ZEBRA_DEBUG_DPLANE_DETAIL
)
4359 zlog_debug("dplane dequeues %d completed work from provider %s",
4360 counter
, dplane_provider_get_name(prov
));
4362 /* Locate next provider */
4364 prov
= TAILQ_NEXT(prov
, dp_prov_link
);
4368 /* After all providers have been serviced, enqueue any completed
4369 * work and any errors back to zebra so it can process the results.
4371 if (IS_ZEBRA_DEBUG_DPLANE_DETAIL
)
4372 zlog_debug("dplane has %d completed, %d errors, for zebra main",
4373 counter
, error_counter
);
4376 * Hand lists through the api to zebra main,
4377 * to reduce the number of lock/unlock cycles
4380 /* Call through to zebra main */
4381 (zdplane_info
.dg_results_cb
)(&error_list
);
4383 TAILQ_INIT(&error_list
);
4385 /* Call through to zebra main */
4386 (zdplane_info
.dg_results_cb
)(&work_list
);
4388 TAILQ_INIT(&work_list
);
4395 * Final phase of shutdown, after all work enqueued to dplane has been
4396 * processed. This is called from the zebra main pthread context.
4398 void zebra_dplane_shutdown(void)
4400 struct zebra_dplane_provider
*dp
;
4402 if (IS_ZEBRA_DEBUG_DPLANE
)
4403 zlog_debug("Zebra dataplane shutdown called");
4405 /* Stop dplane thread, if it's running */
4407 zdplane_info
.dg_run
= false;
4409 if (zdplane_info
.dg_t_update
)
4410 thread_cancel_async(zdplane_info
.dg_t_update
->master
,
4411 &zdplane_info
.dg_t_update
, NULL
);
4413 frr_pthread_stop(zdplane_info
.dg_pthread
, NULL
);
4415 /* Destroy pthread */
4416 frr_pthread_destroy(zdplane_info
.dg_pthread
);
4417 zdplane_info
.dg_pthread
= NULL
;
4418 zdplane_info
.dg_master
= NULL
;
4420 /* Notify provider(s) of final shutdown.
4421 * Note that this call is in the main pthread, so providers must
4422 * be prepared for that.
4424 TAILQ_FOREACH(dp
, &zdplane_info
.dg_providers_q
, dp_prov_link
) {
4425 if (dp
->dp_fini
== NULL
)
4428 dp
->dp_fini(dp
, false);
4431 /* TODO -- Clean-up provider objects */
4433 /* TODO -- Clean queue(s), free memory */
4437 * Initialize the dataplane module during startup, internal/private version
4439 static void zebra_dplane_init_internal(void)
4441 memset(&zdplane_info
, 0, sizeof(zdplane_info
));
4443 pthread_mutex_init(&zdplane_info
.dg_mutex
, NULL
);
4445 TAILQ_INIT(&zdplane_info
.dg_update_ctx_q
);
4446 TAILQ_INIT(&zdplane_info
.dg_providers_q
);
4448 zdplane_info
.dg_updates_per_cycle
= DPLANE_DEFAULT_NEW_WORK
;
4450 zdplane_info
.dg_max_queued_updates
= DPLANE_DEFAULT_MAX_QUEUED
;
4452 /* Register default kernel 'provider' during init */
4453 dplane_provider_init();
4457 * Start the dataplane pthread. This step needs to be run later than the
4458 * 'init' step, in case zebra has fork-ed.
4460 void zebra_dplane_start(void)
4462 struct zebra_dplane_provider
*prov
;
4463 struct frr_pthread_attr pattr
= {
4464 .start
= frr_pthread_attr_default
.start
,
4465 .stop
= frr_pthread_attr_default
.stop
4468 /* Start dataplane pthread */
4470 zdplane_info
.dg_pthread
= frr_pthread_new(&pattr
, "Zebra dplane thread",
4473 zdplane_info
.dg_master
= zdplane_info
.dg_pthread
->master
;
4475 zdplane_info
.dg_run
= true;
4477 /* Enqueue an initial event for the dataplane pthread */
4478 thread_add_event(zdplane_info
.dg_master
, dplane_thread_loop
, NULL
, 0,
4479 &zdplane_info
.dg_t_update
);
4481 /* Call start callbacks for registered providers */
4484 prov
= TAILQ_FIRST(&zdplane_info
.dg_providers_q
);
4490 (prov
->dp_start
)(prov
);
4492 /* Locate next provider */
4494 prov
= TAILQ_NEXT(prov
, dp_prov_link
);
4498 frr_pthread_run(zdplane_info
.dg_pthread
, NULL
);
4502 * Initialize the dataplane module at startup; called by zebra rib_init()
4504 void zebra_dplane_init(int (*results_fp
)(struct dplane_ctx_q
*))
4506 zebra_dplane_init_internal();
4507 zdplane_info
.dg_results_cb
= results_fp
;