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 (zebra_nhg_kernel_nexthops_enabled()
1915 && (((op
== DPLANE_OP_ROUTE_INSTALL
)
1916 || (op
== DPLANE_OP_ROUTE_UPDATE
))
1917 && !CHECK_FLAG(nhe
->flags
, NEXTHOP_GROUP_INSTALLED
)
1918 && !CHECK_FLAG(nhe
->flags
, NEXTHOP_GROUP_QUEUED
))) {
1923 #endif /* HAVE_NETLINK */
1925 /* Trying out the sequence number idea, so we can try to detect
1926 * when a result is stale.
1928 re
->dplane_sequence
= zebra_router_get_next_sequence();
1929 ctx
->zd_seq
= re
->dplane_sequence
;
1938 * dplane_ctx_nexthop_init() - Initialize a context block for a nexthop update
1940 * @ctx: Dataplane context to init
1941 * @op: Operation being performed
1942 * @nhe: Nexthop group hash entry
1944 * Return: Result status
1946 int dplane_ctx_nexthop_init(struct zebra_dplane_ctx
*ctx
, enum dplane_op_e op
,
1947 struct nhg_hash_entry
*nhe
)
1949 struct zebra_vrf
*zvrf
= NULL
;
1950 struct zebra_ns
*zns
= NULL
;
1957 ctx
->zd_status
= ZEBRA_DPLANE_REQUEST_SUCCESS
;
1959 /* Copy over nhe info */
1960 ctx
->u
.rinfo
.nhe
.id
= nhe
->id
;
1961 ctx
->u
.rinfo
.nhe
.afi
= nhe
->afi
;
1962 ctx
->u
.rinfo
.nhe
.vrf_id
= nhe
->vrf_id
;
1963 ctx
->u
.rinfo
.nhe
.type
= nhe
->type
;
1965 nexthop_group_copy(&(ctx
->u
.rinfo
.nhe
.ng
), &(nhe
->nhg
));
1967 /* If this is a group, convert it to a grp array of ids */
1968 if (!zebra_nhg_depends_is_empty(nhe
)
1969 && !CHECK_FLAG(nhe
->flags
, NEXTHOP_GROUP_RECURSIVE
))
1970 ctx
->u
.rinfo
.nhe
.nh_grp_count
= zebra_nhg_nhe2grp(
1971 ctx
->u
.rinfo
.nhe
.nh_grp
, nhe
, MULTIPATH_NUM
);
1973 zvrf
= vrf_info_lookup(nhe
->vrf_id
);
1976 * Fallback to default namespace if the vrf got ripped out from under
1979 zns
= zvrf
? zvrf
->zns
: zebra_ns_lookup(NS_DEFAULT
);
1982 * TODO: Might not need to mark this as an update, since
1983 * it probably won't require two messages
1985 dplane_ctx_ns_init(ctx
, zns
, (op
== DPLANE_OP_NH_UPDATE
));
1986 ctx
->zd_is_update
= (op
== DPLANE_OP_NH_UPDATE
);
1995 * Capture information for an LSP update in a dplane context.
1997 int dplane_ctx_lsp_init(struct zebra_dplane_ctx
*ctx
, enum dplane_op_e op
,
2001 zebra_nhlfe_t
*nhlfe
, *new_nhlfe
;
2004 ctx
->zd_status
= ZEBRA_DPLANE_REQUEST_SUCCESS
;
2006 /* Capture namespace info */
2007 dplane_ctx_ns_init(ctx
, zebra_ns_lookup(NS_DEFAULT
),
2008 (op
== DPLANE_OP_LSP_UPDATE
));
2009 ctx
->zd_is_update
= (op
== DPLANE_OP_LSP_UPDATE
);
2011 memset(&ctx
->u
.lsp
, 0, sizeof(ctx
->u
.lsp
));
2013 nhlfe_list_init(&(ctx
->u
.lsp
.nhlfe_list
));
2014 nhlfe_list_init(&(ctx
->u
.lsp
.backup_nhlfe_list
));
2016 /* This may be called to create/init a dplane context, not necessarily
2017 * to copy an lsp object.
2024 if (IS_ZEBRA_DEBUG_DPLANE_DETAIL
)
2025 zlog_debug("init dplane ctx %s: in-label %u ecmp# %d",
2026 dplane_op2str(op
), lsp
->ile
.in_label
,
2029 ctx
->u
.lsp
.ile
= lsp
->ile
;
2030 ctx
->u
.lsp
.addr_family
= lsp
->addr_family
;
2031 ctx
->u
.lsp
.num_ecmp
= lsp
->num_ecmp
;
2032 ctx
->u
.lsp
.flags
= lsp
->flags
;
2034 /* Copy source LSP's nhlfes, and capture 'best' nhlfe */
2035 frr_each(nhlfe_list
, &lsp
->nhlfe_list
, nhlfe
) {
2036 /* Not sure if this is meaningful... */
2037 if (nhlfe
->nexthop
== NULL
)
2040 new_nhlfe
= zebra_mpls_lsp_add_nh(&(ctx
->u
.lsp
), nhlfe
->type
,
2042 if (new_nhlfe
== NULL
|| new_nhlfe
->nexthop
== NULL
) {
2047 /* Need to copy flags and backup info too */
2048 new_nhlfe
->flags
= nhlfe
->flags
;
2049 new_nhlfe
->nexthop
->flags
= nhlfe
->nexthop
->flags
;
2051 if (CHECK_FLAG(new_nhlfe
->nexthop
->flags
,
2052 NEXTHOP_FLAG_HAS_BACKUP
)) {
2053 new_nhlfe
->nexthop
->backup_num
=
2054 nhlfe
->nexthop
->backup_num
;
2055 memcpy(new_nhlfe
->nexthop
->backup_idx
,
2056 nhlfe
->nexthop
->backup_idx
,
2057 new_nhlfe
->nexthop
->backup_num
);
2060 if (nhlfe
== lsp
->best_nhlfe
)
2061 ctx
->u
.lsp
.best_nhlfe
= new_nhlfe
;
2067 /* Capture backup nhlfes/nexthops */
2068 frr_each(nhlfe_list
, &lsp
->backup_nhlfe_list
, nhlfe
) {
2069 /* Not sure if this is meaningful... */
2070 if (nhlfe
->nexthop
== NULL
)
2073 new_nhlfe
= zebra_mpls_lsp_add_backup_nh(&(ctx
->u
.lsp
),
2076 if (new_nhlfe
== NULL
|| new_nhlfe
->nexthop
== NULL
) {
2081 /* Need to copy flags too */
2082 new_nhlfe
->flags
= nhlfe
->flags
;
2083 new_nhlfe
->nexthop
->flags
= nhlfe
->nexthop
->flags
;
2086 /* On error the ctx will be cleaned-up, so we don't need to
2087 * deal with any allocated nhlfe or nexthop structs here.
2095 * Capture information for an LSP update in a dplane context.
2097 static int dplane_ctx_pw_init(struct zebra_dplane_ctx
*ctx
,
2098 enum dplane_op_e op
,
2099 struct zebra_pw
*pw
)
2103 struct route_table
*table
;
2104 struct route_node
*rn
;
2105 struct route_entry
*re
;
2106 const struct nexthop_group
*nhg
;
2108 if (IS_ZEBRA_DEBUG_DPLANE_DETAIL
)
2109 zlog_debug("init dplane ctx %s: pw '%s', loc %u, rem %u",
2110 dplane_op2str(op
), pw
->ifname
, pw
->local_label
,
2114 ctx
->zd_status
= ZEBRA_DPLANE_REQUEST_SUCCESS
;
2116 /* Capture namespace info: no netlink support as of 12/18,
2117 * but just in case...
2119 dplane_ctx_ns_init(ctx
, zebra_ns_lookup(NS_DEFAULT
), false);
2121 memset(&ctx
->u
.pw
, 0, sizeof(ctx
->u
.pw
));
2123 /* This name appears to be c-string, so we use string copy. */
2124 strlcpy(ctx
->zd_ifname
, pw
->ifname
, sizeof(ctx
->zd_ifname
));
2126 ctx
->zd_vrf_id
= pw
->vrf_id
;
2127 ctx
->zd_ifindex
= pw
->ifindex
;
2128 ctx
->u
.pw
.type
= pw
->type
;
2129 ctx
->u
.pw
.af
= pw
->af
;
2130 ctx
->u
.pw
.local_label
= pw
->local_label
;
2131 ctx
->u
.pw
.remote_label
= pw
->remote_label
;
2132 ctx
->u
.pw
.flags
= pw
->flags
;
2134 ctx
->u
.pw
.dest
= pw
->nexthop
;
2136 ctx
->u
.pw
.fields
= pw
->data
;
2138 /* Capture nexthop info for the pw destination. We need to look
2139 * up and use zebra datastructs, but we're running in the zebra
2140 * pthread here so that should be ok.
2142 memcpy(&p
.u
, &pw
->nexthop
, sizeof(pw
->nexthop
));
2144 p
.prefixlen
= ((pw
->af
== AF_INET
) ?
2145 IPV4_MAX_PREFIXLEN
: IPV6_MAX_PREFIXLEN
);
2147 afi
= (pw
->af
== AF_INET
) ? AFI_IP
: AFI_IP6
;
2148 table
= zebra_vrf_table(afi
, SAFI_UNICAST
, pw
->vrf_id
);
2150 rn
= route_node_match(table
, &p
);
2152 RNODE_FOREACH_RE(rn
, re
) {
2153 if (CHECK_FLAG(re
->flags
, ZEBRA_FLAG_SELECTED
))
2158 nhg
= rib_get_fib_nhg(re
);
2159 if (nhg
&& nhg
->nexthop
)
2160 copy_nexthops(&(ctx
->u
.pw
.nhg
.nexthop
),
2161 nhg
->nexthop
, NULL
);
2163 /* Include any installed backup nexthops */
2164 nhg
= rib_get_fib_backup_nhg(re
);
2165 if (nhg
&& nhg
->nexthop
)
2166 copy_nexthops(&(ctx
->u
.pw
.nhg
.nexthop
),
2167 nhg
->nexthop
, NULL
);
2169 route_unlock_node(rn
);
2177 * dplane_ctx_rule_init_single() - Initialize a dataplane representation of a
2180 * @dplane_rule: Dataplane internal representation of a rule
2183 static void dplane_ctx_rule_init_single(struct dplane_ctx_rule
*dplane_rule
,
2184 struct zebra_pbr_rule
*rule
)
2186 dplane_rule
->priority
= rule
->rule
.priority
;
2187 dplane_rule
->table
= rule
->rule
.action
.table
;
2189 dplane_rule
->filter_bm
= rule
->rule
.filter
.filter_bm
;
2190 dplane_rule
->fwmark
= rule
->rule
.filter
.fwmark
;
2191 dplane_rule
->dsfield
= rule
->rule
.filter
.dsfield
;
2192 prefix_copy(&(dplane_rule
->dst_ip
), &rule
->rule
.filter
.dst_ip
);
2193 prefix_copy(&(dplane_rule
->src_ip
), &rule
->rule
.filter
.src_ip
);
2197 * dplane_ctx_rule_init() - Initialize a context block for a PBR rule update.
2199 * @ctx: Dataplane context to init
2200 * @op: Operation being performed
2201 * @new_rule: PBR rule
2203 * Return: Result status
2205 static int dplane_ctx_rule_init(struct zebra_dplane_ctx
*ctx
,
2206 enum dplane_op_e op
,
2207 struct zebra_pbr_rule
*new_rule
,
2208 struct zebra_pbr_rule
*old_rule
)
2210 if (IS_ZEBRA_DEBUG_DPLANE_DETAIL
) {
2211 char buf1
[PREFIX_STRLEN
];
2212 char buf2
[PREFIX_STRLEN
];
2215 "init dplane ctx %s: IF %s(%u) Prio %u Fwmark %u Src %s Dst %s Table %u",
2216 dplane_op2str(op
), new_rule
->ifname
,
2217 new_rule
->rule
.ifindex
, new_rule
->rule
.priority
,
2218 new_rule
->rule
.filter
.fwmark
,
2219 prefix2str(&new_rule
->rule
.filter
.src_ip
, buf1
,
2221 prefix2str(&new_rule
->rule
.filter
.dst_ip
, buf2
,
2223 new_rule
->rule
.action
.table
);
2227 ctx
->zd_status
= ZEBRA_DPLANE_REQUEST_SUCCESS
;
2229 dplane_ctx_ns_init(ctx
, zebra_ns_lookup(NS_DEFAULT
),
2230 op
== DPLANE_OP_RULE_UPDATE
);
2231 ctx
->zd_is_update
= (op
== DPLANE_OP_RULE_UPDATE
);
2233 ctx
->zd_vrf_id
= new_rule
->vrf_id
;
2234 memcpy(ctx
->zd_ifname
, new_rule
->ifname
, sizeof(new_rule
->ifname
));
2235 ctx
->zd_ifindex
= new_rule
->rule
.ifindex
;
2237 ctx
->u
.rule
.sock
= new_rule
->sock
;
2238 ctx
->u
.rule
.unique
= new_rule
->rule
.unique
;
2239 ctx
->u
.rule
.seq
= new_rule
->rule
.seq
;
2241 dplane_ctx_rule_init_single(&ctx
->u
.rule
.new, new_rule
);
2242 if (op
== DPLANE_OP_RULE_UPDATE
)
2243 dplane_ctx_rule_init_single(&ctx
->u
.rule
.old
, old_rule
);
2249 * Enqueue a new update,
2250 * and ensure an event is active for the dataplane pthread.
2252 static int dplane_update_enqueue(struct zebra_dplane_ctx
*ctx
)
2255 uint32_t high
, curr
;
2257 /* Enqueue for processing by the dataplane pthread */
2260 TAILQ_INSERT_TAIL(&zdplane_info
.dg_update_ctx_q
, ctx
,
2265 curr
= atomic_fetch_add_explicit(
2266 &(zdplane_info
.dg_routes_queued
),
2267 1, memory_order_seq_cst
);
2269 curr
++; /* We got the pre-incremented value */
2271 /* Maybe update high-water counter also */
2272 high
= atomic_load_explicit(&zdplane_info
.dg_routes_queued_max
,
2273 memory_order_seq_cst
);
2274 while (high
< curr
) {
2275 if (atomic_compare_exchange_weak_explicit(
2276 &zdplane_info
.dg_routes_queued_max
,
2278 memory_order_seq_cst
,
2279 memory_order_seq_cst
))
2283 /* Ensure that an event for the dataplane thread is active */
2284 ret
= dplane_provider_work_ready();
2290 * Utility that prepares a route update and enqueues it for processing
2292 static enum zebra_dplane_result
2293 dplane_route_update_internal(struct route_node
*rn
,
2294 struct route_entry
*re
,
2295 struct route_entry
*old_re
,
2296 enum dplane_op_e op
)
2298 enum zebra_dplane_result result
= ZEBRA_DPLANE_REQUEST_FAILURE
;
2300 struct zebra_dplane_ctx
*ctx
= NULL
;
2302 /* Obtain context block */
2303 ctx
= dplane_ctx_alloc();
2305 /* Init context with info from zebra data structs */
2306 ret
= dplane_ctx_route_init(ctx
, op
, rn
, re
);
2308 /* Capture some extra info for update case
2309 * where there's a different 'old' route.
2311 if ((op
== DPLANE_OP_ROUTE_UPDATE
) &&
2312 old_re
&& (old_re
!= re
)) {
2313 ctx
->zd_is_update
= true;
2315 old_re
->dplane_sequence
=
2316 zebra_router_get_next_sequence();
2317 ctx
->zd_old_seq
= old_re
->dplane_sequence
;
2319 ctx
->u
.rinfo
.zd_old_tag
= old_re
->tag
;
2320 ctx
->u
.rinfo
.zd_old_type
= old_re
->type
;
2321 ctx
->u
.rinfo
.zd_old_instance
= old_re
->instance
;
2322 ctx
->u
.rinfo
.zd_old_distance
= old_re
->distance
;
2323 ctx
->u
.rinfo
.zd_old_metric
= old_re
->metric
;
2325 #ifndef HAVE_NETLINK
2326 /* For bsd, capture previous re's nexthops too, sigh.
2327 * We'll need these to do per-nexthop deletes.
2329 copy_nexthops(&(ctx
->u
.rinfo
.zd_old_ng
.nexthop
),
2330 old_re
->nhe
->nhg
.nexthop
, NULL
);
2332 if (zebra_nhg_get_backup_nhg(old_re
->nhe
) != NULL
) {
2333 struct nexthop_group
*nhg
;
2334 struct nexthop
**nh
;
2336 nhg
= zebra_nhg_get_backup_nhg(old_re
->nhe
);
2337 nh
= &(ctx
->u
.rinfo
.old_backup_ng
.nexthop
);
2340 copy_nexthops(nh
, nhg
->nexthop
, NULL
);
2342 #endif /* !HAVE_NETLINK */
2345 /* Enqueue context for processing */
2346 ret
= dplane_update_enqueue(ctx
);
2349 /* Update counter */
2350 atomic_fetch_add_explicit(&zdplane_info
.dg_routes_in
, 1,
2351 memory_order_relaxed
);
2354 result
= ZEBRA_DPLANE_REQUEST_QUEUED
;
2356 atomic_fetch_add_explicit(&zdplane_info
.dg_route_errors
, 1,
2357 memory_order_relaxed
);
2359 dplane_ctx_free(&ctx
);
2366 * dplane_nexthop_update_internal() - Helper for enqueuing nexthop changes
2368 * @nhe: Nexthop group hash entry where the change occured
2369 * @op: The operation to be enqued
2371 * Return: Result of the change
2373 static enum zebra_dplane_result
2374 dplane_nexthop_update_internal(struct nhg_hash_entry
*nhe
, enum dplane_op_e op
)
2376 enum zebra_dplane_result result
= ZEBRA_DPLANE_REQUEST_FAILURE
;
2378 struct zebra_dplane_ctx
*ctx
= NULL
;
2380 /* Obtain context block */
2381 ctx
= dplane_ctx_alloc();
2387 ret
= dplane_ctx_nexthop_init(ctx
, op
, nhe
);
2389 ret
= dplane_update_enqueue(ctx
);
2392 /* Update counter */
2393 atomic_fetch_add_explicit(&zdplane_info
.dg_nexthops_in
, 1,
2394 memory_order_relaxed
);
2397 result
= ZEBRA_DPLANE_REQUEST_QUEUED
;
2399 atomic_fetch_add_explicit(&zdplane_info
.dg_nexthop_errors
, 1,
2400 memory_order_relaxed
);
2402 dplane_ctx_free(&ctx
);
2409 * Enqueue a route 'add' for the dataplane.
2411 enum zebra_dplane_result
dplane_route_add(struct route_node
*rn
,
2412 struct route_entry
*re
)
2414 enum zebra_dplane_result ret
= ZEBRA_DPLANE_REQUEST_FAILURE
;
2416 if (rn
== NULL
|| re
== NULL
)
2419 ret
= dplane_route_update_internal(rn
, re
, NULL
,
2420 DPLANE_OP_ROUTE_INSTALL
);
2427 * Enqueue a route update for the dataplane.
2429 enum zebra_dplane_result
dplane_route_update(struct route_node
*rn
,
2430 struct route_entry
*re
,
2431 struct route_entry
*old_re
)
2433 enum zebra_dplane_result ret
= ZEBRA_DPLANE_REQUEST_FAILURE
;
2435 if (rn
== NULL
|| re
== NULL
)
2438 ret
= dplane_route_update_internal(rn
, re
, old_re
,
2439 DPLANE_OP_ROUTE_UPDATE
);
2445 * Enqueue a route removal for the dataplane.
2447 enum zebra_dplane_result
dplane_route_delete(struct route_node
*rn
,
2448 struct route_entry
*re
)
2450 enum zebra_dplane_result ret
= ZEBRA_DPLANE_REQUEST_FAILURE
;
2452 if (rn
== NULL
|| re
== NULL
)
2455 ret
= dplane_route_update_internal(rn
, re
, NULL
,
2456 DPLANE_OP_ROUTE_DELETE
);
2463 * Notify the dplane when system/connected routes change.
2465 enum zebra_dplane_result
dplane_sys_route_add(struct route_node
*rn
,
2466 struct route_entry
*re
)
2468 enum zebra_dplane_result ret
= ZEBRA_DPLANE_REQUEST_FAILURE
;
2470 /* Ignore this event unless a provider plugin has requested it. */
2471 if (!zdplane_info
.dg_sys_route_notifs
) {
2472 ret
= ZEBRA_DPLANE_REQUEST_SUCCESS
;
2476 if (rn
== NULL
|| re
== NULL
)
2479 ret
= dplane_route_update_internal(rn
, re
, NULL
,
2480 DPLANE_OP_SYS_ROUTE_ADD
);
2487 * Notify the dplane when system/connected routes are deleted.
2489 enum zebra_dplane_result
dplane_sys_route_del(struct route_node
*rn
,
2490 struct route_entry
*re
)
2492 enum zebra_dplane_result ret
= ZEBRA_DPLANE_REQUEST_FAILURE
;
2494 /* Ignore this event unless a provider plugin has requested it. */
2495 if (!zdplane_info
.dg_sys_route_notifs
) {
2496 ret
= ZEBRA_DPLANE_REQUEST_SUCCESS
;
2500 if (rn
== NULL
|| re
== NULL
)
2503 ret
= dplane_route_update_internal(rn
, re
, NULL
,
2504 DPLANE_OP_SYS_ROUTE_DELETE
);
2511 * Update from an async notification, to bring other fibs up-to-date.
2513 enum zebra_dplane_result
2514 dplane_route_notif_update(struct route_node
*rn
,
2515 struct route_entry
*re
,
2516 enum dplane_op_e op
,
2517 struct zebra_dplane_ctx
*ctx
)
2519 enum zebra_dplane_result result
= ZEBRA_DPLANE_REQUEST_FAILURE
;
2521 struct zebra_dplane_ctx
*new_ctx
= NULL
;
2522 struct nexthop
*nexthop
;
2523 struct nexthop_group
*nhg
;
2525 if (rn
== NULL
|| re
== NULL
)
2528 new_ctx
= dplane_ctx_alloc();
2529 if (new_ctx
== NULL
)
2532 /* Init context with info from zebra data structs */
2533 dplane_ctx_route_init(new_ctx
, op
, rn
, re
);
2535 /* For add/update, need to adjust the nexthops so that we match
2536 * the notification state, which may not be the route-entry/RIB
2539 if (op
== DPLANE_OP_ROUTE_UPDATE
||
2540 op
== DPLANE_OP_ROUTE_INSTALL
) {
2542 nexthops_free(new_ctx
->u
.rinfo
.zd_ng
.nexthop
);
2543 new_ctx
->u
.rinfo
.zd_ng
.nexthop
= NULL
;
2545 nhg
= rib_get_fib_nhg(re
);
2546 if (nhg
&& nhg
->nexthop
)
2547 copy_nexthops(&(new_ctx
->u
.rinfo
.zd_ng
.nexthop
),
2548 nhg
->nexthop
, NULL
);
2550 /* Check for installed backup nexthops also */
2551 nhg
= rib_get_fib_backup_nhg(re
);
2552 if (nhg
&& nhg
->nexthop
) {
2553 copy_nexthops(&(new_ctx
->u
.rinfo
.zd_ng
.nexthop
),
2554 nhg
->nexthop
, NULL
);
2557 for (ALL_NEXTHOPS(new_ctx
->u
.rinfo
.zd_ng
, nexthop
))
2558 UNSET_FLAG(nexthop
->flags
, NEXTHOP_FLAG_FIB
);
2562 /* Capture info about the source of the notification, in 'ctx' */
2563 dplane_ctx_set_notif_provider(new_ctx
,
2564 dplane_ctx_get_notif_provider(ctx
));
2566 ret
= dplane_update_enqueue(new_ctx
);
2570 result
= ZEBRA_DPLANE_REQUEST_QUEUED
;
2572 dplane_ctx_free(&new_ctx
);
2578 * Enqueue a nexthop add for the dataplane.
2580 enum zebra_dplane_result
dplane_nexthop_add(struct nhg_hash_entry
*nhe
)
2582 enum zebra_dplane_result ret
= ZEBRA_DPLANE_REQUEST_FAILURE
;
2585 ret
= dplane_nexthop_update_internal(nhe
, DPLANE_OP_NH_INSTALL
);
2590 * Enqueue a nexthop update for the dataplane.
2592 * Might not need this func since zebra's nexthop objects should be immutable?
2594 enum zebra_dplane_result
dplane_nexthop_update(struct nhg_hash_entry
*nhe
)
2596 enum zebra_dplane_result ret
= ZEBRA_DPLANE_REQUEST_FAILURE
;
2599 ret
= dplane_nexthop_update_internal(nhe
, DPLANE_OP_NH_UPDATE
);
2604 * Enqueue a nexthop removal for the dataplane.
2606 enum zebra_dplane_result
dplane_nexthop_delete(struct nhg_hash_entry
*nhe
)
2608 enum zebra_dplane_result ret
= ZEBRA_DPLANE_REQUEST_FAILURE
;
2611 ret
= dplane_nexthop_update_internal(nhe
, DPLANE_OP_NH_DELETE
);
2617 * Enqueue LSP add for the dataplane.
2619 enum zebra_dplane_result
dplane_lsp_add(zebra_lsp_t
*lsp
)
2621 enum zebra_dplane_result ret
=
2622 lsp_update_internal(lsp
, DPLANE_OP_LSP_INSTALL
);
2628 * Enqueue LSP update for the dataplane.
2630 enum zebra_dplane_result
dplane_lsp_update(zebra_lsp_t
*lsp
)
2632 enum zebra_dplane_result ret
=
2633 lsp_update_internal(lsp
, DPLANE_OP_LSP_UPDATE
);
2639 * Enqueue LSP delete for the dataplane.
2641 enum zebra_dplane_result
dplane_lsp_delete(zebra_lsp_t
*lsp
)
2643 enum zebra_dplane_result ret
=
2644 lsp_update_internal(lsp
, DPLANE_OP_LSP_DELETE
);
2649 /* Update or un-install resulting from an async notification */
2650 enum zebra_dplane_result
2651 dplane_lsp_notif_update(zebra_lsp_t
*lsp
,
2652 enum dplane_op_e op
,
2653 struct zebra_dplane_ctx
*notif_ctx
)
2655 enum zebra_dplane_result result
= ZEBRA_DPLANE_REQUEST_FAILURE
;
2657 struct zebra_dplane_ctx
*ctx
= NULL
;
2658 struct nhlfe_list_head
*head
;
2659 zebra_nhlfe_t
*nhlfe
, *new_nhlfe
;
2661 /* Obtain context block */
2662 ctx
= dplane_ctx_alloc();
2668 /* Copy info from zebra LSP */
2669 ret
= dplane_ctx_lsp_init(ctx
, op
, lsp
);
2673 /* Add any installed backup nhlfes */
2674 head
= &(ctx
->u
.lsp
.backup_nhlfe_list
);
2675 frr_each(nhlfe_list
, head
, nhlfe
) {
2677 if (CHECK_FLAG(nhlfe
->flags
, NHLFE_FLAG_INSTALLED
) &&
2678 CHECK_FLAG(nhlfe
->nexthop
->flags
, NEXTHOP_FLAG_FIB
)) {
2679 new_nhlfe
= zebra_mpls_lsp_add_nh(&(ctx
->u
.lsp
),
2683 /* Need to copy flags too */
2684 new_nhlfe
->flags
= nhlfe
->flags
;
2685 new_nhlfe
->nexthop
->flags
= nhlfe
->nexthop
->flags
;
2689 /* Capture info about the source of the notification */
2690 dplane_ctx_set_notif_provider(
2692 dplane_ctx_get_notif_provider(notif_ctx
));
2694 ret
= dplane_update_enqueue(ctx
);
2697 /* Update counter */
2698 atomic_fetch_add_explicit(&zdplane_info
.dg_lsps_in
, 1,
2699 memory_order_relaxed
);
2702 result
= ZEBRA_DPLANE_REQUEST_QUEUED
;
2704 atomic_fetch_add_explicit(&zdplane_info
.dg_lsp_errors
, 1,
2705 memory_order_relaxed
);
2707 dplane_ctx_free(&ctx
);
2713 * Enqueue pseudowire install for the dataplane.
2715 enum zebra_dplane_result
dplane_pw_install(struct zebra_pw
*pw
)
2717 return pw_update_internal(pw
, DPLANE_OP_PW_INSTALL
);
2721 * Enqueue pseudowire un-install for the dataplane.
2723 enum zebra_dplane_result
dplane_pw_uninstall(struct zebra_pw
*pw
)
2725 return pw_update_internal(pw
, DPLANE_OP_PW_UNINSTALL
);
2729 * Common internal LSP update utility
2731 static enum zebra_dplane_result
lsp_update_internal(zebra_lsp_t
*lsp
,
2732 enum dplane_op_e op
)
2734 enum zebra_dplane_result result
= ZEBRA_DPLANE_REQUEST_FAILURE
;
2736 struct zebra_dplane_ctx
*ctx
= NULL
;
2738 /* Obtain context block */
2739 ctx
= dplane_ctx_alloc();
2741 ret
= dplane_ctx_lsp_init(ctx
, op
, lsp
);
2745 ret
= dplane_update_enqueue(ctx
);
2748 /* Update counter */
2749 atomic_fetch_add_explicit(&zdplane_info
.dg_lsps_in
, 1,
2750 memory_order_relaxed
);
2753 result
= ZEBRA_DPLANE_REQUEST_QUEUED
;
2755 atomic_fetch_add_explicit(&zdplane_info
.dg_lsp_errors
, 1,
2756 memory_order_relaxed
);
2757 dplane_ctx_free(&ctx
);
2764 * Internal, common handler for pseudowire updates.
2766 static enum zebra_dplane_result
pw_update_internal(struct zebra_pw
*pw
,
2767 enum dplane_op_e op
)
2769 enum zebra_dplane_result result
= ZEBRA_DPLANE_REQUEST_FAILURE
;
2771 struct zebra_dplane_ctx
*ctx
= NULL
;
2773 ctx
= dplane_ctx_alloc();
2775 ret
= dplane_ctx_pw_init(ctx
, op
, pw
);
2779 ret
= dplane_update_enqueue(ctx
);
2782 /* Update counter */
2783 atomic_fetch_add_explicit(&zdplane_info
.dg_pws_in
, 1,
2784 memory_order_relaxed
);
2787 result
= ZEBRA_DPLANE_REQUEST_QUEUED
;
2789 atomic_fetch_add_explicit(&zdplane_info
.dg_pw_errors
, 1,
2790 memory_order_relaxed
);
2791 dplane_ctx_free(&ctx
);
2798 * Enqueue interface address add for the dataplane.
2800 enum zebra_dplane_result
dplane_intf_addr_set(const struct interface
*ifp
,
2801 const struct connected
*ifc
)
2803 #if !defined(HAVE_NETLINK) && defined(HAVE_STRUCT_IFALIASREQ)
2804 /* Extra checks for this OS path. */
2806 /* Don't configure PtP addresses on broadcast ifs or reverse */
2807 if (!(ifp
->flags
& IFF_POINTOPOINT
) != !CONNECTED_PEER(ifc
)) {
2808 if (IS_ZEBRA_DEBUG_KERNEL
|| IS_ZEBRA_DEBUG_DPLANE
)
2809 zlog_debug("Failed to set intf addr: mismatch p2p and connected");
2811 return ZEBRA_DPLANE_REQUEST_FAILURE
;
2814 /* Ensure that no existing installed v4 route conflicts with
2815 * the new interface prefix. This check must be done in the
2816 * zebra pthread context, and any route delete (if needed)
2817 * is enqueued before the interface address programming attempt.
2819 if (ifc
->address
->family
== AF_INET
) {
2820 struct prefix_ipv4
*p
;
2822 p
= (struct prefix_ipv4
*)ifc
->address
;
2823 rib_lookup_and_pushup(p
, ifp
->vrf_id
);
2827 return intf_addr_update_internal(ifp
, ifc
, DPLANE_OP_ADDR_INSTALL
);
2831 * Enqueue interface address remove/uninstall for the dataplane.
2833 enum zebra_dplane_result
dplane_intf_addr_unset(const struct interface
*ifp
,
2834 const struct connected
*ifc
)
2836 return intf_addr_update_internal(ifp
, ifc
, DPLANE_OP_ADDR_UNINSTALL
);
2839 static enum zebra_dplane_result
intf_addr_update_internal(
2840 const struct interface
*ifp
, const struct connected
*ifc
,
2841 enum dplane_op_e op
)
2843 enum zebra_dplane_result result
= ZEBRA_DPLANE_REQUEST_FAILURE
;
2845 struct zebra_dplane_ctx
*ctx
= NULL
;
2846 struct zebra_ns
*zns
;
2848 if (IS_ZEBRA_DEBUG_DPLANE_DETAIL
) {
2849 char addr_str
[PREFIX_STRLEN
];
2851 prefix2str(ifc
->address
, addr_str
, sizeof(addr_str
));
2853 zlog_debug("init intf ctx %s: idx %d, addr %u:%s",
2854 dplane_op2str(op
), ifp
->ifindex
, ifp
->vrf_id
,
2858 ctx
= dplane_ctx_alloc();
2861 ctx
->zd_status
= ZEBRA_DPLANE_REQUEST_SUCCESS
;
2862 ctx
->zd_vrf_id
= ifp
->vrf_id
;
2864 zns
= zebra_ns_lookup(ifp
->vrf_id
);
2865 dplane_ctx_ns_init(ctx
, zns
, false);
2867 /* Init the interface-addr-specific area */
2868 memset(&ctx
->u
.intf
, 0, sizeof(ctx
->u
.intf
));
2870 strlcpy(ctx
->zd_ifname
, ifp
->name
, sizeof(ctx
->zd_ifname
));
2871 ctx
->zd_ifindex
= ifp
->ifindex
;
2872 ctx
->u
.intf
.prefix
= *(ifc
->address
);
2874 if (if_is_broadcast(ifp
))
2875 ctx
->u
.intf
.flags
|= DPLANE_INTF_BROADCAST
;
2877 if (CONNECTED_PEER(ifc
)) {
2878 ctx
->u
.intf
.dest_prefix
= *(ifc
->destination
);
2879 ctx
->u
.intf
.flags
|=
2880 (DPLANE_INTF_CONNECTED
| DPLANE_INTF_HAS_DEST
);
2883 if (CHECK_FLAG(ifc
->flags
, ZEBRA_IFA_SECONDARY
))
2884 ctx
->u
.intf
.flags
|= DPLANE_INTF_SECONDARY
;
2889 ctx
->u
.intf
.flags
|= DPLANE_INTF_HAS_LABEL
;
2891 /* Use embedded buffer if it's adequate; else allocate. */
2892 len
= strlen(ifc
->label
);
2894 if (len
< sizeof(ctx
->u
.intf
.label_buf
)) {
2895 strlcpy(ctx
->u
.intf
.label_buf
, ifc
->label
,
2896 sizeof(ctx
->u
.intf
.label_buf
));
2897 ctx
->u
.intf
.label
= ctx
->u
.intf
.label_buf
;
2899 ctx
->u
.intf
.label
= strdup(ifc
->label
);
2903 ret
= dplane_update_enqueue(ctx
);
2905 /* Increment counter */
2906 atomic_fetch_add_explicit(&zdplane_info
.dg_intf_addrs_in
, 1,
2907 memory_order_relaxed
);
2910 result
= ZEBRA_DPLANE_REQUEST_QUEUED
;
2913 atomic_fetch_add_explicit(&zdplane_info
.dg_intf_addr_errors
,
2914 1, memory_order_relaxed
);
2915 dplane_ctx_free(&ctx
);
2922 * Enqueue vxlan/evpn mac add (or update).
2924 enum zebra_dplane_result
dplane_rem_mac_add(const struct interface
*ifp
,
2925 const struct interface
*bridge_ifp
,
2927 const struct ethaddr
*mac
,
2928 struct in_addr vtep_ip
,
2933 enum zebra_dplane_result result
;
2934 uint32_t update_flags
= 0;
2936 update_flags
|= DPLANE_MAC_REMOTE
;
2938 update_flags
|= DPLANE_MAC_WAS_STATIC
;
2940 /* Use common helper api */
2941 result
= mac_update_common(DPLANE_OP_MAC_INSTALL
, ifp
, bridge_ifp
,
2942 vid
, mac
, vtep_ip
, sticky
, nhg_id
, update_flags
);
2947 * Enqueue vxlan/evpn mac delete.
2949 enum zebra_dplane_result
dplane_rem_mac_del(const struct interface
*ifp
,
2950 const struct interface
*bridge_ifp
,
2952 const struct ethaddr
*mac
,
2953 struct in_addr vtep_ip
)
2955 enum zebra_dplane_result result
;
2956 uint32_t update_flags
= 0;
2958 update_flags
|= DPLANE_MAC_REMOTE
;
2960 /* Use common helper api */
2961 result
= mac_update_common(DPLANE_OP_MAC_DELETE
, ifp
, bridge_ifp
,
2962 vid
, mac
, vtep_ip
, false, 0, update_flags
);
2967 * Enqueue local mac add (or update).
2969 enum zebra_dplane_result
dplane_local_mac_add(const struct interface
*ifp
,
2970 const struct interface
*bridge_ifp
,
2972 const struct ethaddr
*mac
,
2974 uint32_t set_static
,
2975 uint32_t set_inactive
)
2977 enum zebra_dplane_result result
;
2978 uint32_t update_flags
= 0;
2979 struct in_addr vtep_ip
;
2982 update_flags
|= DPLANE_MAC_SET_STATIC
;
2985 update_flags
|= DPLANE_MAC_SET_INACTIVE
;
2989 /* Use common helper api */
2990 result
= mac_update_common(DPLANE_OP_MAC_INSTALL
, ifp
, bridge_ifp
,
2991 vid
, mac
, vtep_ip
, sticky
, 0,
2997 * Public api to init an empty context - either newly-allocated or
2998 * reset/cleared - for a MAC update.
3000 void dplane_mac_init(struct zebra_dplane_ctx
*ctx
,
3001 const struct interface
*ifp
,
3002 const struct interface
*br_ifp
,
3004 const struct ethaddr
*mac
,
3005 struct in_addr vtep_ip
,
3008 uint32_t update_flags
)
3010 struct zebra_ns
*zns
;
3012 ctx
->zd_status
= ZEBRA_DPLANE_REQUEST_SUCCESS
;
3013 ctx
->zd_vrf_id
= ifp
->vrf_id
;
3015 zns
= zebra_ns_lookup(ifp
->vrf_id
);
3016 dplane_ctx_ns_init(ctx
, zns
, false);
3018 strlcpy(ctx
->zd_ifname
, ifp
->name
, sizeof(ctx
->zd_ifname
));
3019 ctx
->zd_ifindex
= ifp
->ifindex
;
3021 /* Init the mac-specific data area */
3022 memset(&ctx
->u
.macinfo
, 0, sizeof(ctx
->u
.macinfo
));
3024 ctx
->u
.macinfo
.br_ifindex
= br_ifp
->ifindex
;
3025 ctx
->u
.macinfo
.vtep_ip
= vtep_ip
;
3026 ctx
->u
.macinfo
.mac
= *mac
;
3027 ctx
->u
.macinfo
.vid
= vid
;
3028 ctx
->u
.macinfo
.is_sticky
= sticky
;
3029 ctx
->u
.macinfo
.nhg_id
= nhg_id
;
3030 ctx
->u
.macinfo
.update_flags
= update_flags
;
3034 * Common helper api for MAC address/vxlan updates
3036 static enum zebra_dplane_result
3037 mac_update_common(enum dplane_op_e op
,
3038 const struct interface
*ifp
,
3039 const struct interface
*br_ifp
,
3041 const struct ethaddr
*mac
,
3042 struct in_addr vtep_ip
,
3045 uint32_t update_flags
)
3047 enum zebra_dplane_result result
= ZEBRA_DPLANE_REQUEST_FAILURE
;
3049 struct zebra_dplane_ctx
*ctx
= NULL
;
3051 if (IS_ZEBRA_DEBUG_DPLANE_DETAIL
) {
3052 char buf1
[ETHER_ADDR_STRLEN
], buf2
[PREFIX_STRLEN
];
3054 zlog_debug("init mac ctx %s: mac %s, ifp %s, vtep %s",
3056 prefix_mac2str(mac
, buf1
, sizeof(buf1
)),
3058 inet_ntop(AF_INET
, &vtep_ip
, buf2
, sizeof(buf2
)));
3061 ctx
= dplane_ctx_alloc();
3064 /* Common init for the ctx */
3065 dplane_mac_init(ctx
, ifp
, br_ifp
, vid
, mac
, vtep_ip
, sticky
,
3066 nhg_id
, update_flags
);
3068 /* Enqueue for processing on the dplane pthread */
3069 ret
= dplane_update_enqueue(ctx
);
3071 /* Increment counter */
3072 atomic_fetch_add_explicit(&zdplane_info
.dg_macs_in
, 1,
3073 memory_order_relaxed
);
3076 result
= ZEBRA_DPLANE_REQUEST_QUEUED
;
3079 atomic_fetch_add_explicit(&zdplane_info
.dg_mac_errors
, 1,
3080 memory_order_relaxed
);
3081 dplane_ctx_free(&ctx
);
3088 * Enqueue evpn neighbor add for the dataplane.
3090 enum zebra_dplane_result
dplane_rem_neigh_add(const struct interface
*ifp
,
3091 const struct ipaddr
*ip
,
3092 const struct ethaddr
*mac
,
3093 uint32_t flags
, bool was_static
)
3095 enum zebra_dplane_result result
= ZEBRA_DPLANE_REQUEST_FAILURE
;
3096 uint32_t update_flags
= 0;
3098 update_flags
|= DPLANE_NEIGH_REMOTE
;
3101 update_flags
|= DPLANE_NEIGH_WAS_STATIC
;
3103 result
= neigh_update_internal(DPLANE_OP_NEIGH_INSTALL
,
3104 ifp
, mac
, ip
, flags
, DPLANE_NUD_NOARP
,
3111 * Enqueue local neighbor add for the dataplane.
3113 enum zebra_dplane_result
dplane_local_neigh_add(const struct interface
*ifp
,
3114 const struct ipaddr
*ip
,
3115 const struct ethaddr
*mac
,
3116 bool set_router
, bool set_static
,
3119 enum zebra_dplane_result result
= ZEBRA_DPLANE_REQUEST_FAILURE
;
3120 uint32_t update_flags
= 0;
3125 update_flags
|= DPLANE_NEIGH_SET_STATIC
;
3128 update_flags
|= DPLANE_NEIGH_SET_INACTIVE
;
3129 state
= DPLANE_NUD_STALE
;
3131 state
= DPLANE_NUD_REACHABLE
;
3135 ntf
|= DPLANE_NTF_ROUTER
;
3137 result
= neigh_update_internal(DPLANE_OP_NEIGH_INSTALL
,
3139 state
, update_flags
);
3145 * Enqueue evpn neighbor delete for the dataplane.
3147 enum zebra_dplane_result
dplane_rem_neigh_delete(const struct interface
*ifp
,
3148 const struct ipaddr
*ip
)
3150 enum zebra_dplane_result result
;
3151 uint32_t update_flags
= 0;
3153 update_flags
|= DPLANE_NEIGH_REMOTE
;
3155 result
= neigh_update_internal(DPLANE_OP_NEIGH_DELETE
,
3156 ifp
, NULL
, ip
, 0, 0, update_flags
);
3162 * Enqueue evpn VTEP add for the dataplane.
3164 enum zebra_dplane_result
dplane_vtep_add(const struct interface
*ifp
,
3165 const struct in_addr
*ip
,
3168 enum zebra_dplane_result result
;
3169 struct ethaddr mac
= { {0, 0, 0, 0, 0, 0} };
3172 if (IS_ZEBRA_DEBUG_VXLAN
)
3173 zlog_debug("Install %s into flood list for VNI %u intf %s(%u)",
3174 inet_ntoa(*ip
), vni
, ifp
->name
, ifp
->ifindex
);
3176 SET_IPADDR_V4(&addr
);
3177 addr
.ipaddr_v4
= *ip
;
3179 result
= neigh_update_internal(DPLANE_OP_VTEP_ADD
,
3180 ifp
, &mac
, &addr
, 0, 0, 0);
3186 * Enqueue evpn VTEP add for the dataplane.
3188 enum zebra_dplane_result
dplane_vtep_delete(const struct interface
*ifp
,
3189 const struct in_addr
*ip
,
3192 enum zebra_dplane_result result
;
3193 struct ethaddr mac
= { {0, 0, 0, 0, 0, 0} };
3196 if (IS_ZEBRA_DEBUG_VXLAN
)
3198 "Uninstall %s from flood list for VNI %u intf %s(%u)",
3199 inet_ntoa(*ip
), vni
, ifp
->name
, ifp
->ifindex
);
3201 SET_IPADDR_V4(&addr
);
3202 addr
.ipaddr_v4
= *ip
;
3204 result
= neigh_update_internal(DPLANE_OP_VTEP_DELETE
,
3205 ifp
, &mac
, &addr
, 0, 0, 0);
3210 enum zebra_dplane_result
dplane_neigh_discover(const struct interface
*ifp
,
3211 const struct ipaddr
*ip
)
3213 enum zebra_dplane_result result
;
3215 result
= neigh_update_internal(DPLANE_OP_NEIGH_DISCOVER
, ifp
, NULL
, ip
,
3216 DPLANE_NTF_USE
, DPLANE_NUD_INCOMPLETE
, 0);
3222 * Common helper api for neighbor updates
3224 static enum zebra_dplane_result
3225 neigh_update_internal(enum dplane_op_e op
,
3226 const struct interface
*ifp
,
3227 const struct ethaddr
*mac
,
3228 const struct ipaddr
*ip
,
3229 uint32_t flags
, uint16_t state
,
3230 uint32_t update_flags
)
3232 enum zebra_dplane_result result
= ZEBRA_DPLANE_REQUEST_FAILURE
;
3234 struct zebra_dplane_ctx
*ctx
= NULL
;
3235 struct zebra_ns
*zns
;
3237 if (IS_ZEBRA_DEBUG_DPLANE_DETAIL
) {
3238 char buf1
[ETHER_ADDR_STRLEN
], buf2
[PREFIX_STRLEN
];
3240 zlog_debug("init neigh ctx %s: ifp %s, mac %s, ip %s",
3241 dplane_op2str(op
), ifp
->name
,
3242 prefix_mac2str(mac
, buf1
, sizeof(buf1
)),
3243 ipaddr2str(ip
, buf2
, sizeof(buf2
)));
3246 ctx
= dplane_ctx_alloc();
3249 ctx
->zd_status
= ZEBRA_DPLANE_REQUEST_SUCCESS
;
3250 ctx
->zd_vrf_id
= ifp
->vrf_id
;
3252 zns
= zebra_ns_lookup(ifp
->vrf_id
);
3253 dplane_ctx_ns_init(ctx
, zns
, false);
3255 strlcpy(ctx
->zd_ifname
, ifp
->name
, sizeof(ctx
->zd_ifname
));
3256 ctx
->zd_ifindex
= ifp
->ifindex
;
3258 /* Init the neighbor-specific data area */
3259 memset(&ctx
->u
.neigh
, 0, sizeof(ctx
->u
.neigh
));
3261 ctx
->u
.neigh
.ip_addr
= *ip
;
3263 ctx
->u
.neigh
.mac
= *mac
;
3264 ctx
->u
.neigh
.flags
= flags
;
3265 ctx
->u
.neigh
.state
= state
;
3266 ctx
->u
.neigh
.update_flags
= update_flags
;
3268 /* Enqueue for processing on the dplane pthread */
3269 ret
= dplane_update_enqueue(ctx
);
3271 /* Increment counter */
3272 atomic_fetch_add_explicit(&zdplane_info
.dg_neighs_in
, 1,
3273 memory_order_relaxed
);
3276 result
= ZEBRA_DPLANE_REQUEST_QUEUED
;
3279 atomic_fetch_add_explicit(&zdplane_info
.dg_neigh_errors
, 1,
3280 memory_order_relaxed
);
3281 dplane_ctx_free(&ctx
);
3288 * Common helper api for PBR rule updates
3290 static enum zebra_dplane_result
3291 rule_update_internal(enum dplane_op_e op
, struct zebra_pbr_rule
*new_rule
,
3292 struct zebra_pbr_rule
*old_rule
)
3294 enum zebra_dplane_result result
= ZEBRA_DPLANE_REQUEST_FAILURE
;
3295 struct zebra_dplane_ctx
*ctx
;
3298 ctx
= dplane_ctx_alloc();
3300 ret
= dplane_ctx_rule_init(ctx
, op
, new_rule
, old_rule
);
3304 ret
= dplane_update_enqueue(ctx
);
3307 atomic_fetch_add_explicit(&zdplane_info
.dg_rules_in
, 1,
3308 memory_order_relaxed
);
3311 result
= ZEBRA_DPLANE_REQUEST_QUEUED
;
3313 atomic_fetch_add_explicit(&zdplane_info
.dg_rule_errors
, 1,
3314 memory_order_relaxed
);
3315 dplane_ctx_free(&ctx
);
3321 enum zebra_dplane_result
dplane_pbr_rule_add(struct zebra_pbr_rule
*rule
)
3323 return rule_update_internal(DPLANE_OP_RULE_ADD
, rule
, NULL
);
3326 enum zebra_dplane_result
dplane_pbr_rule_delete(struct zebra_pbr_rule
*rule
)
3328 return rule_update_internal(DPLANE_OP_RULE_DELETE
, rule
, NULL
);
3331 enum zebra_dplane_result
dplane_pbr_rule_update(struct zebra_pbr_rule
*old_rule
,
3332 struct zebra_pbr_rule
*new_rule
)
3334 return rule_update_internal(DPLANE_OP_RULE_UPDATE
, new_rule
, old_rule
);
3338 * Handler for 'show dplane'
3340 int dplane_show_helper(struct vty
*vty
, bool detailed
)
3342 uint64_t queued
, queue_max
, limit
, errs
, incoming
, yields
,
3345 /* Using atomics because counters are being changed in different
3348 incoming
= atomic_load_explicit(&zdplane_info
.dg_routes_in
,
3349 memory_order_relaxed
);
3350 limit
= atomic_load_explicit(&zdplane_info
.dg_max_queued_updates
,
3351 memory_order_relaxed
);
3352 queued
= atomic_load_explicit(&zdplane_info
.dg_routes_queued
,
3353 memory_order_relaxed
);
3354 queue_max
= atomic_load_explicit(&zdplane_info
.dg_routes_queued_max
,
3355 memory_order_relaxed
);
3356 errs
= atomic_load_explicit(&zdplane_info
.dg_route_errors
,
3357 memory_order_relaxed
);
3358 yields
= atomic_load_explicit(&zdplane_info
.dg_update_yields
,
3359 memory_order_relaxed
);
3360 other_errs
= atomic_load_explicit(&zdplane_info
.dg_other_errors
,
3361 memory_order_relaxed
);
3363 vty_out(vty
, "Zebra dataplane:\nRoute updates: %"PRIu64
"\n",
3365 vty_out(vty
, "Route update errors: %"PRIu64
"\n", errs
);
3366 vty_out(vty
, "Other errors : %"PRIu64
"\n", other_errs
);
3367 vty_out(vty
, "Route update queue limit: %"PRIu64
"\n", limit
);
3368 vty_out(vty
, "Route update queue depth: %"PRIu64
"\n", queued
);
3369 vty_out(vty
, "Route update queue max: %"PRIu64
"\n", queue_max
);
3370 vty_out(vty
, "Dplane update yields: %"PRIu64
"\n", yields
);
3372 incoming
= atomic_load_explicit(&zdplane_info
.dg_lsps_in
,
3373 memory_order_relaxed
);
3374 errs
= atomic_load_explicit(&zdplane_info
.dg_lsp_errors
,
3375 memory_order_relaxed
);
3376 vty_out(vty
, "LSP updates: %"PRIu64
"\n", incoming
);
3377 vty_out(vty
, "LSP update errors: %"PRIu64
"\n", errs
);
3379 incoming
= atomic_load_explicit(&zdplane_info
.dg_pws_in
,
3380 memory_order_relaxed
);
3381 errs
= atomic_load_explicit(&zdplane_info
.dg_pw_errors
,
3382 memory_order_relaxed
);
3383 vty_out(vty
, "PW updates: %"PRIu64
"\n", incoming
);
3384 vty_out(vty
, "PW update errors: %"PRIu64
"\n", errs
);
3386 incoming
= atomic_load_explicit(&zdplane_info
.dg_intf_addrs_in
,
3387 memory_order_relaxed
);
3388 errs
= atomic_load_explicit(&zdplane_info
.dg_intf_addr_errors
,
3389 memory_order_relaxed
);
3390 vty_out(vty
, "Intf addr updates: %"PRIu64
"\n", incoming
);
3391 vty_out(vty
, "Intf addr errors: %"PRIu64
"\n", errs
);
3393 incoming
= atomic_load_explicit(&zdplane_info
.dg_macs_in
,
3394 memory_order_relaxed
);
3395 errs
= atomic_load_explicit(&zdplane_info
.dg_mac_errors
,
3396 memory_order_relaxed
);
3397 vty_out(vty
, "EVPN MAC updates: %"PRIu64
"\n", incoming
);
3398 vty_out(vty
, "EVPN MAC errors: %"PRIu64
"\n", errs
);
3400 incoming
= atomic_load_explicit(&zdplane_info
.dg_neighs_in
,
3401 memory_order_relaxed
);
3402 errs
= atomic_load_explicit(&zdplane_info
.dg_neigh_errors
,
3403 memory_order_relaxed
);
3404 vty_out(vty
, "EVPN neigh updates: %"PRIu64
"\n", incoming
);
3405 vty_out(vty
, "EVPN neigh errors: %"PRIu64
"\n", errs
);
3407 incoming
= atomic_load_explicit(&zdplane_info
.dg_rules_in
,
3408 memory_order_relaxed
);
3409 errs
= atomic_load_explicit(&zdplane_info
.dg_rule_errors
,
3410 memory_order_relaxed
);
3411 vty_out(vty
, "Rule updates: %" PRIu64
"\n", incoming
);
3412 vty_out(vty
, "Rule errors: %" PRIu64
"\n", errs
);
3418 * Handler for 'show dplane providers'
3420 int dplane_show_provs_helper(struct vty
*vty
, bool detailed
)
3422 struct zebra_dplane_provider
*prov
;
3423 uint64_t in
, in_max
, out
, out_max
;
3425 vty_out(vty
, "Zebra dataplane providers:\n");
3428 prov
= TAILQ_FIRST(&zdplane_info
.dg_providers_q
);
3431 /* Show counters, useful info from each registered provider */
3434 in
= atomic_load_explicit(&prov
->dp_in_counter
,
3435 memory_order_relaxed
);
3436 in_max
= atomic_load_explicit(&prov
->dp_in_max
,
3437 memory_order_relaxed
);
3438 out
= atomic_load_explicit(&prov
->dp_out_counter
,
3439 memory_order_relaxed
);
3440 out_max
= atomic_load_explicit(&prov
->dp_out_max
,
3441 memory_order_relaxed
);
3444 "%s (%u): in: %" PRIu64
", q_max: %" PRIu64
3445 ", out: %" PRIu64
", q_max: %" PRIu64
"\n",
3446 prov
->dp_name
, prov
->dp_id
, in
, in_max
, out
, out_max
);
3449 prov
= TAILQ_NEXT(prov
, dp_prov_link
);
3457 * Helper for 'show run' etc.
3459 int dplane_config_write_helper(struct vty
*vty
)
3461 if (zdplane_info
.dg_max_queued_updates
!= DPLANE_DEFAULT_MAX_QUEUED
)
3462 vty_out(vty
, "zebra dplane limit %u\n",
3463 zdplane_info
.dg_max_queued_updates
);
3469 * Provider registration
3471 int dplane_provider_register(const char *name
,
3472 enum dplane_provider_prio prio
,
3474 int (*start_fp
)(struct zebra_dplane_provider
*),
3475 int (*fp
)(struct zebra_dplane_provider
*),
3476 int (*fini_fp
)(struct zebra_dplane_provider
*,
3479 struct zebra_dplane_provider
**prov_p
)
3482 struct zebra_dplane_provider
*p
= NULL
, *last
;
3490 if (prio
<= DPLANE_PRIO_NONE
||
3491 prio
> DPLANE_PRIO_LAST
) {
3496 /* Allocate and init new provider struct */
3497 p
= XCALLOC(MTYPE_DP_PROV
, sizeof(struct zebra_dplane_provider
));
3499 pthread_mutex_init(&(p
->dp_mutex
), NULL
);
3500 TAILQ_INIT(&(p
->dp_ctx_in_q
));
3501 TAILQ_INIT(&(p
->dp_ctx_out_q
));
3503 p
->dp_flags
= flags
;
3504 p
->dp_priority
= prio
;
3506 p
->dp_start
= start_fp
;
3507 p
->dp_fini
= fini_fp
;
3510 /* Lock - the dplane pthread may be running */
3513 p
->dp_id
= ++zdplane_info
.dg_provider_id
;
3516 strlcpy(p
->dp_name
, name
, DPLANE_PROVIDER_NAMELEN
);
3518 snprintf(p
->dp_name
, DPLANE_PROVIDER_NAMELEN
,
3519 "provider-%u", p
->dp_id
);
3521 /* Insert into list ordered by priority */
3522 TAILQ_FOREACH(last
, &zdplane_info
.dg_providers_q
, dp_prov_link
) {
3523 if (last
->dp_priority
> p
->dp_priority
)
3528 TAILQ_INSERT_BEFORE(last
, p
, dp_prov_link
);
3530 TAILQ_INSERT_TAIL(&zdplane_info
.dg_providers_q
, p
,
3536 if (IS_ZEBRA_DEBUG_DPLANE
)
3537 zlog_debug("dplane: registered new provider '%s' (%u), prio %d",
3538 p
->dp_name
, p
->dp_id
, p
->dp_priority
);
3547 /* Accessors for provider attributes */
3548 const char *dplane_provider_get_name(const struct zebra_dplane_provider
*prov
)
3550 return prov
->dp_name
;
3553 uint32_t dplane_provider_get_id(const struct zebra_dplane_provider
*prov
)
3558 void *dplane_provider_get_data(const struct zebra_dplane_provider
*prov
)
3560 return prov
->dp_data
;
3563 int dplane_provider_get_work_limit(const struct zebra_dplane_provider
*prov
)
3565 return zdplane_info
.dg_updates_per_cycle
;
3568 /* Lock/unlock a provider's mutex - iff the provider was registered with
3569 * the THREADED flag.
3571 void dplane_provider_lock(struct zebra_dplane_provider
*prov
)
3573 if (dplane_provider_is_threaded(prov
))
3574 DPLANE_PROV_LOCK(prov
);
3577 void dplane_provider_unlock(struct zebra_dplane_provider
*prov
)
3579 if (dplane_provider_is_threaded(prov
))
3580 DPLANE_PROV_UNLOCK(prov
);
3584 * Dequeue and maintain associated counter
3586 struct zebra_dplane_ctx
*dplane_provider_dequeue_in_ctx(
3587 struct zebra_dplane_provider
*prov
)
3589 struct zebra_dplane_ctx
*ctx
= NULL
;
3591 dplane_provider_lock(prov
);
3593 ctx
= TAILQ_FIRST(&(prov
->dp_ctx_in_q
));
3595 TAILQ_REMOVE(&(prov
->dp_ctx_in_q
), ctx
, zd_q_entries
);
3597 atomic_fetch_sub_explicit(&prov
->dp_in_queued
, 1,
3598 memory_order_relaxed
);
3601 dplane_provider_unlock(prov
);
3607 * Dequeue work to a list, return count
3609 int dplane_provider_dequeue_in_list(struct zebra_dplane_provider
*prov
,
3610 struct dplane_ctx_q
*listp
)
3613 struct zebra_dplane_ctx
*ctx
;
3615 limit
= zdplane_info
.dg_updates_per_cycle
;
3617 dplane_provider_lock(prov
);
3619 for (ret
= 0; ret
< limit
; ret
++) {
3620 ctx
= TAILQ_FIRST(&(prov
->dp_ctx_in_q
));
3622 TAILQ_REMOVE(&(prov
->dp_ctx_in_q
), ctx
, zd_q_entries
);
3624 TAILQ_INSERT_TAIL(listp
, ctx
, zd_q_entries
);
3631 atomic_fetch_sub_explicit(&prov
->dp_in_queued
, ret
,
3632 memory_order_relaxed
);
3634 dplane_provider_unlock(prov
);
3640 * Enqueue and maintain associated counter
3642 void dplane_provider_enqueue_out_ctx(struct zebra_dplane_provider
*prov
,
3643 struct zebra_dplane_ctx
*ctx
)
3645 dplane_provider_lock(prov
);
3647 TAILQ_INSERT_TAIL(&(prov
->dp_ctx_out_q
), ctx
,
3650 dplane_provider_unlock(prov
);
3652 atomic_fetch_add_explicit(&(prov
->dp_out_counter
), 1,
3653 memory_order_relaxed
);
3657 * Accessor for provider object
3659 bool dplane_provider_is_threaded(const struct zebra_dplane_provider
*prov
)
3661 return (prov
->dp_flags
& DPLANE_PROV_FLAG_THREADED
);
3665 * Internal helper that copies information from a zebra ns object; this is
3666 * called in the zebra main pthread context as part of dplane ctx init.
3668 static void dplane_info_from_zns(struct zebra_dplane_info
*ns_info
,
3669 struct zebra_ns
*zns
)
3671 ns_info
->ns_id
= zns
->ns_id
;
3673 #if defined(HAVE_NETLINK)
3674 ns_info
->is_cmd
= true;
3675 ns_info
->nls
= zns
->netlink_dplane
;
3676 #endif /* NETLINK */
3680 * Provider api to signal that work/events are available
3681 * for the dataplane pthread.
3683 int dplane_provider_work_ready(void)
3685 /* Note that during zebra startup, we may be offered work before
3686 * the dataplane pthread (and thread-master) are ready. We want to
3687 * enqueue the work, but the event-scheduling machinery may not be
3690 if (zdplane_info
.dg_run
) {
3691 thread_add_event(zdplane_info
.dg_master
,
3692 dplane_thread_loop
, NULL
, 0,
3693 &zdplane_info
.dg_t_update
);
3700 * Enqueue a context directly to zebra main.
3702 void dplane_provider_enqueue_to_zebra(struct zebra_dplane_ctx
*ctx
)
3704 struct dplane_ctx_q temp_list
;
3706 /* Zebra's api takes a list, so we need to use a temporary list */
3707 TAILQ_INIT(&temp_list
);
3709 TAILQ_INSERT_TAIL(&temp_list
, ctx
, zd_q_entries
);
3710 (zdplane_info
.dg_results_cb
)(&temp_list
);
3714 * Kernel dataplane provider
3717 static void kernel_dplane_log_detail(struct zebra_dplane_ctx
*ctx
)
3719 char buf
[PREFIX_STRLEN
];
3721 switch (dplane_ctx_get_op(ctx
)) {
3723 case DPLANE_OP_ROUTE_INSTALL
:
3724 case DPLANE_OP_ROUTE_UPDATE
:
3725 case DPLANE_OP_ROUTE_DELETE
:
3726 prefix2str(dplane_ctx_get_dest(ctx
), buf
, sizeof(buf
));
3728 zlog_debug("%u:%s Dplane route update ctx %p op %s",
3729 dplane_ctx_get_vrf(ctx
), buf
, ctx
,
3730 dplane_op2str(dplane_ctx_get_op(ctx
)));
3733 case DPLANE_OP_NH_INSTALL
:
3734 case DPLANE_OP_NH_UPDATE
:
3735 case DPLANE_OP_NH_DELETE
:
3736 zlog_debug("ID (%u) Dplane nexthop update ctx %p op %s",
3737 dplane_ctx_get_nhe_id(ctx
), ctx
,
3738 dplane_op2str(dplane_ctx_get_op(ctx
)));
3741 case DPLANE_OP_LSP_INSTALL
:
3742 case DPLANE_OP_LSP_UPDATE
:
3743 case DPLANE_OP_LSP_DELETE
:
3746 case DPLANE_OP_PW_INSTALL
:
3747 case DPLANE_OP_PW_UNINSTALL
:
3748 zlog_debug("Dplane pw %s: op %s af %d loc: %u rem: %u",
3749 dplane_ctx_get_ifname(ctx
),
3750 dplane_op2str(ctx
->zd_op
), dplane_ctx_get_pw_af(ctx
),
3751 dplane_ctx_get_pw_local_label(ctx
),
3752 dplane_ctx_get_pw_remote_label(ctx
));
3755 case DPLANE_OP_ADDR_INSTALL
:
3756 case DPLANE_OP_ADDR_UNINSTALL
:
3757 prefix2str(dplane_ctx_get_intf_addr(ctx
), buf
, sizeof(buf
));
3759 zlog_debug("Dplane intf %s, idx %u, addr %s",
3760 dplane_op2str(dplane_ctx_get_op(ctx
)),
3761 dplane_ctx_get_ifindex(ctx
), buf
);
3764 case DPLANE_OP_MAC_INSTALL
:
3765 case DPLANE_OP_MAC_DELETE
:
3766 prefix_mac2str(dplane_ctx_mac_get_addr(ctx
), buf
,
3769 zlog_debug("Dplane %s, mac %s, ifindex %u",
3770 dplane_op2str(dplane_ctx_get_op(ctx
)),
3771 buf
, dplane_ctx_get_ifindex(ctx
));
3774 case DPLANE_OP_NEIGH_INSTALL
:
3775 case DPLANE_OP_NEIGH_UPDATE
:
3776 case DPLANE_OP_NEIGH_DELETE
:
3777 case DPLANE_OP_VTEP_ADD
:
3778 case DPLANE_OP_VTEP_DELETE
:
3779 case DPLANE_OP_NEIGH_DISCOVER
:
3780 ipaddr2str(dplane_ctx_neigh_get_ipaddr(ctx
), buf
,
3783 zlog_debug("Dplane %s, ip %s, ifindex %u",
3784 dplane_op2str(dplane_ctx_get_op(ctx
)),
3785 buf
, dplane_ctx_get_ifindex(ctx
));
3788 case DPLANE_OP_RULE_ADD
:
3789 case DPLANE_OP_RULE_DELETE
:
3790 case DPLANE_OP_RULE_UPDATE
:
3791 zlog_debug("Dplane rule update op %s, if %s(%u), ctx %p",
3792 dplane_op2str(dplane_ctx_get_op(ctx
)),
3793 dplane_ctx_get_ifname(ctx
),
3794 dplane_ctx_get_ifindex(ctx
), ctx
);
3797 case DPLANE_OP_SYS_ROUTE_ADD
:
3798 case DPLANE_OP_SYS_ROUTE_DELETE
:
3799 case DPLANE_OP_ROUTE_NOTIFY
:
3800 case DPLANE_OP_LSP_NOTIFY
:
3802 case DPLANE_OP_NONE
:
3807 static void kernel_dplane_handle_result(struct zebra_dplane_ctx
*ctx
)
3809 enum zebra_dplane_result res
= dplane_ctx_get_status(ctx
);
3811 switch (dplane_ctx_get_op(ctx
)) {
3813 case DPLANE_OP_ROUTE_INSTALL
:
3814 case DPLANE_OP_ROUTE_UPDATE
:
3815 case DPLANE_OP_ROUTE_DELETE
:
3816 if (res
!= ZEBRA_DPLANE_REQUEST_SUCCESS
)
3817 atomic_fetch_add_explicit(&zdplane_info
.dg_route_errors
,
3818 1, memory_order_relaxed
);
3820 if ((dplane_ctx_get_op(ctx
) != DPLANE_OP_ROUTE_DELETE
)
3821 && (res
== ZEBRA_DPLANE_REQUEST_SUCCESS
)) {
3822 struct nexthop
*nexthop
;
3824 /* Update installed nexthops to signal which have been
3827 for (ALL_NEXTHOPS_PTR(dplane_ctx_get_ng(ctx
),
3829 if (CHECK_FLAG(nexthop
->flags
,
3830 NEXTHOP_FLAG_RECURSIVE
))
3833 if (CHECK_FLAG(nexthop
->flags
,
3834 NEXTHOP_FLAG_ACTIVE
)) {
3835 SET_FLAG(nexthop
->flags
,
3842 case DPLANE_OP_NH_INSTALL
:
3843 case DPLANE_OP_NH_UPDATE
:
3844 case DPLANE_OP_NH_DELETE
:
3845 if (res
!= ZEBRA_DPLANE_REQUEST_SUCCESS
)
3846 atomic_fetch_add_explicit(
3847 &zdplane_info
.dg_nexthop_errors
, 1,
3848 memory_order_relaxed
);
3851 case DPLANE_OP_LSP_INSTALL
:
3852 case DPLANE_OP_LSP_UPDATE
:
3853 case DPLANE_OP_LSP_DELETE
:
3854 if (res
!= ZEBRA_DPLANE_REQUEST_SUCCESS
)
3855 atomic_fetch_add_explicit(&zdplane_info
.dg_lsp_errors
,
3856 1, memory_order_relaxed
);
3859 case DPLANE_OP_PW_INSTALL
:
3860 case DPLANE_OP_PW_UNINSTALL
:
3861 if (res
!= ZEBRA_DPLANE_REQUEST_SUCCESS
)
3862 atomic_fetch_add_explicit(&zdplane_info
.dg_pw_errors
, 1,
3863 memory_order_relaxed
);
3866 case DPLANE_OP_ADDR_INSTALL
:
3867 case DPLANE_OP_ADDR_UNINSTALL
:
3868 if (res
!= ZEBRA_DPLANE_REQUEST_SUCCESS
)
3869 atomic_fetch_add_explicit(
3870 &zdplane_info
.dg_intf_addr_errors
, 1,
3871 memory_order_relaxed
);
3874 case DPLANE_OP_MAC_INSTALL
:
3875 case DPLANE_OP_MAC_DELETE
:
3876 if (res
!= ZEBRA_DPLANE_REQUEST_SUCCESS
)
3877 atomic_fetch_add_explicit(&zdplane_info
.dg_mac_errors
,
3878 1, memory_order_relaxed
);
3881 case DPLANE_OP_NEIGH_INSTALL
:
3882 case DPLANE_OP_NEIGH_UPDATE
:
3883 case DPLANE_OP_NEIGH_DELETE
:
3884 case DPLANE_OP_VTEP_ADD
:
3885 case DPLANE_OP_VTEP_DELETE
:
3886 case DPLANE_OP_NEIGH_DISCOVER
:
3887 if (res
!= ZEBRA_DPLANE_REQUEST_SUCCESS
)
3888 atomic_fetch_add_explicit(&zdplane_info
.dg_neigh_errors
,
3889 1, memory_order_relaxed
);
3892 case DPLANE_OP_RULE_ADD
:
3893 case DPLANE_OP_RULE_DELETE
:
3894 case DPLANE_OP_RULE_UPDATE
:
3895 if (res
!= ZEBRA_DPLANE_REQUEST_SUCCESS
)
3896 atomic_fetch_add_explicit(&zdplane_info
.dg_rule_errors
,
3897 1, memory_order_relaxed
);
3900 /* Ignore 'notifications' - no-op */
3901 case DPLANE_OP_SYS_ROUTE_ADD
:
3902 case DPLANE_OP_SYS_ROUTE_DELETE
:
3903 case DPLANE_OP_ROUTE_NOTIFY
:
3904 case DPLANE_OP_LSP_NOTIFY
:
3907 case DPLANE_OP_NONE
:
3908 if (res
!= ZEBRA_DPLANE_REQUEST_SUCCESS
)
3909 atomic_fetch_add_explicit(&zdplane_info
.dg_other_errors
,
3910 1, memory_order_relaxed
);
3916 * Kernel provider callback
3918 static int kernel_dplane_process_func(struct zebra_dplane_provider
*prov
)
3920 struct zebra_dplane_ctx
*ctx
, *tctx
;
3921 struct dplane_ctx_q work_list
;
3924 TAILQ_INIT(&work_list
);
3926 limit
= dplane_provider_get_work_limit(prov
);
3928 if (IS_ZEBRA_DEBUG_DPLANE_DETAIL
)
3929 zlog_debug("dplane provider '%s': processing",
3930 dplane_provider_get_name(prov
));
3932 for (counter
= 0; counter
< limit
; counter
++) {
3933 ctx
= dplane_provider_dequeue_in_ctx(prov
);
3937 if (IS_ZEBRA_DEBUG_DPLANE_DETAIL
)
3938 kernel_dplane_log_detail(ctx
);
3940 TAILQ_INSERT_TAIL(&work_list
, ctx
, zd_q_entries
);
3943 kernel_update_multi(&work_list
);
3945 TAILQ_FOREACH_SAFE (ctx
, &work_list
, zd_q_entries
, tctx
) {
3946 kernel_dplane_handle_result(ctx
);
3948 TAILQ_REMOVE(&work_list
, ctx
, zd_q_entries
);
3949 dplane_provider_enqueue_out_ctx(prov
, ctx
);
3952 /* Ensure that we'll run the work loop again if there's still
3955 if (counter
>= limit
) {
3956 if (IS_ZEBRA_DEBUG_DPLANE_DETAIL
)
3957 zlog_debug("dplane provider '%s' reached max updates %d",
3958 dplane_provider_get_name(prov
), counter
);
3960 atomic_fetch_add_explicit(&zdplane_info
.dg_update_yields
,
3961 1, memory_order_relaxed
);
3963 dplane_provider_work_ready();
3969 #ifdef DPLANE_TEST_PROVIDER
3972 * Test dataplane provider plugin
3976 * Test provider process callback
3978 static int test_dplane_process_func(struct zebra_dplane_provider
*prov
)
3980 struct zebra_dplane_ctx
*ctx
;
3983 /* Just moving from 'in' queue to 'out' queue */
3985 if (IS_ZEBRA_DEBUG_DPLANE_DETAIL
)
3986 zlog_debug("dplane provider '%s': processing",
3987 dplane_provider_get_name(prov
));
3989 limit
= dplane_provider_get_work_limit(prov
);
3991 for (counter
= 0; counter
< limit
; counter
++) {
3992 ctx
= dplane_provider_dequeue_in_ctx(prov
);
3996 if (IS_ZEBRA_DEBUG_DPLANE_DETAIL
)
3997 zlog_debug("dplane provider '%s': op %s",
3998 dplane_provider_get_name(prov
),
3999 dplane_op2str(dplane_ctx_get_op(ctx
)));
4001 dplane_ctx_set_status(ctx
, ZEBRA_DPLANE_REQUEST_SUCCESS
);
4003 dplane_provider_enqueue_out_ctx(prov
, ctx
);
4006 if (IS_ZEBRA_DEBUG_DPLANE_DETAIL
)
4007 zlog_debug("dplane provider '%s': processed %d",
4008 dplane_provider_get_name(prov
), counter
);
4010 /* Ensure that we'll run the work loop again if there's still
4013 if (counter
>= limit
)
4014 dplane_provider_work_ready();
4020 * Test provider shutdown/fini callback
4022 static int test_dplane_shutdown_func(struct zebra_dplane_provider
*prov
,
4025 if (IS_ZEBRA_DEBUG_DPLANE
)
4026 zlog_debug("dplane provider '%s': %sshutdown",
4027 dplane_provider_get_name(prov
),
4028 early
? "early " : "");
4032 #endif /* DPLANE_TEST_PROVIDER */
4035 * Register default kernel provider
4037 static void dplane_provider_init(void)
4041 ret
= dplane_provider_register("Kernel",
4043 DPLANE_PROV_FLAGS_DEFAULT
, NULL
,
4044 kernel_dplane_process_func
,
4049 zlog_err("Unable to register kernel dplane provider: %d",
4052 #ifdef DPLANE_TEST_PROVIDER
4053 /* Optional test provider ... */
4054 ret
= dplane_provider_register("Test",
4055 DPLANE_PRIO_PRE_KERNEL
,
4056 DPLANE_PROV_FLAGS_DEFAULT
, NULL
,
4057 test_dplane_process_func
,
4058 test_dplane_shutdown_func
,
4059 NULL
/* data */, NULL
);
4062 zlog_err("Unable to register test dplane provider: %d",
4064 #endif /* DPLANE_TEST_PROVIDER */
4067 /* Indicates zebra shutdown/exit is in progress. Some operations may be
4068 * simplified or skipped during shutdown processing.
4070 bool dplane_is_in_shutdown(void)
4072 return zdplane_info
.dg_is_shutdown
;
4076 * Early or pre-shutdown, de-init notification api. This runs pretty
4077 * early during zebra shutdown, as a signal to stop new work and prepare
4078 * for updates generated by shutdown/cleanup activity, as zebra tries to
4079 * remove everything it's responsible for.
4080 * NB: This runs in the main zebra pthread context.
4082 void zebra_dplane_pre_finish(void)
4084 struct zebra_dplane_provider
*prov
;
4086 if (IS_ZEBRA_DEBUG_DPLANE
)
4087 zlog_debug("Zebra dataplane pre-finish called");
4089 zdplane_info
.dg_is_shutdown
= true;
4091 /* Notify provider(s) of pending shutdown. */
4092 TAILQ_FOREACH(prov
, &zdplane_info
.dg_providers_q
, dp_prov_link
) {
4093 if (prov
->dp_fini
== NULL
)
4096 prov
->dp_fini(prov
, true /* early */);
4101 * Utility to determine whether work remains enqueued within the dplane;
4102 * used during system shutdown processing.
4104 static bool dplane_work_pending(void)
4107 struct zebra_dplane_ctx
*ctx
;
4108 struct zebra_dplane_provider
*prov
;
4110 /* TODO -- just checking incoming/pending work for now, must check
4115 ctx
= TAILQ_FIRST(&zdplane_info
.dg_update_ctx_q
);
4116 prov
= TAILQ_FIRST(&zdplane_info
.dg_providers_q
);
4127 dplane_provider_lock(prov
);
4129 ctx
= TAILQ_FIRST(&(prov
->dp_ctx_in_q
));
4131 ctx
= TAILQ_FIRST(&(prov
->dp_ctx_out_q
));
4133 dplane_provider_unlock(prov
);
4139 prov
= TAILQ_NEXT(prov
, dp_prov_link
);
4151 * Shutdown-time intermediate callback, used to determine when all pending
4152 * in-flight updates are done. If there's still work to do, reschedules itself.
4153 * If all work is done, schedules an event to the main zebra thread for
4154 * final zebra shutdown.
4155 * This runs in the dplane pthread context.
4157 static int dplane_check_shutdown_status(struct thread
*event
)
4159 if (IS_ZEBRA_DEBUG_DPLANE
)
4160 zlog_debug("Zebra dataplane shutdown status check called");
4162 if (dplane_work_pending()) {
4163 /* Reschedule dplane check on a short timer */
4164 thread_add_timer_msec(zdplane_info
.dg_master
,
4165 dplane_check_shutdown_status
,
4167 &zdplane_info
.dg_t_shutdown_check
);
4169 /* TODO - give up and stop waiting after a short time? */
4172 /* We appear to be done - schedule a final callback event
4173 * for the zebra main pthread.
4175 thread_add_event(zrouter
.master
, zebra_finalize
, NULL
, 0, NULL
);
4182 * Shutdown, de-init api. This runs pretty late during shutdown,
4183 * after zebra has tried to free/remove/uninstall all routes during shutdown.
4184 * At this point, dplane work may still remain to be done, so we can't just
4185 * blindly terminate. If there's still work to do, we'll periodically check
4186 * and when done, we'll enqueue a task to the zebra main thread for final
4187 * termination processing.
4189 * NB: This runs in the main zebra thread context.
4191 void zebra_dplane_finish(void)
4193 if (IS_ZEBRA_DEBUG_DPLANE
)
4194 zlog_debug("Zebra dataplane fini called");
4196 thread_add_event(zdplane_info
.dg_master
,
4197 dplane_check_shutdown_status
, NULL
, 0,
4198 &zdplane_info
.dg_t_shutdown_check
);
4202 * Main dataplane pthread event loop. The thread takes new incoming work
4203 * and offers it to the first provider. It then iterates through the
4204 * providers, taking complete work from each one and offering it
4205 * to the next in order. At each step, a limited number of updates are
4206 * processed during a cycle in order to provide some fairness.
4208 * This loop through the providers is only run once, so that the dataplane
4209 * pthread can look for other pending work - such as i/o work on behalf of
4212 static int dplane_thread_loop(struct thread
*event
)
4214 struct dplane_ctx_q work_list
;
4215 struct dplane_ctx_q error_list
;
4216 struct zebra_dplane_provider
*prov
;
4217 struct zebra_dplane_ctx
*ctx
, *tctx
;
4218 int limit
, counter
, error_counter
;
4219 uint64_t curr
, high
;
4221 /* Capture work limit per cycle */
4222 limit
= zdplane_info
.dg_updates_per_cycle
;
4224 /* Init temporary lists used to move contexts among providers */
4225 TAILQ_INIT(&work_list
);
4226 TAILQ_INIT(&error_list
);
4229 /* Check for zebra shutdown */
4230 if (!zdplane_info
.dg_run
)
4233 /* Dequeue some incoming work from zebra (if any) onto the temporary
4238 /* Locate initial registered provider */
4239 prov
= TAILQ_FIRST(&zdplane_info
.dg_providers_q
);
4241 /* Move new work from incoming list to temp list */
4242 for (counter
= 0; counter
< limit
; counter
++) {
4243 ctx
= TAILQ_FIRST(&zdplane_info
.dg_update_ctx_q
);
4245 TAILQ_REMOVE(&zdplane_info
.dg_update_ctx_q
, ctx
,
4248 ctx
->zd_provider
= prov
->dp_id
;
4250 TAILQ_INSERT_TAIL(&work_list
, ctx
, zd_q_entries
);
4258 atomic_fetch_sub_explicit(&zdplane_info
.dg_routes_queued
, counter
,
4259 memory_order_relaxed
);
4261 if (IS_ZEBRA_DEBUG_DPLANE_DETAIL
)
4262 zlog_debug("dplane: incoming new work counter: %d", counter
);
4264 /* Iterate through the registered providers, offering new incoming
4265 * work. If the provider has outgoing work in its queue, take that
4266 * work for the next provider
4270 /* At each iteration, the temporary work list has 'counter'
4273 if (IS_ZEBRA_DEBUG_DPLANE_DETAIL
)
4274 zlog_debug("dplane enqueues %d new work to provider '%s'",
4275 counter
, dplane_provider_get_name(prov
));
4277 /* Capture current provider id in each context; check for
4280 TAILQ_FOREACH_SAFE(ctx
, &work_list
, zd_q_entries
, tctx
) {
4281 if (dplane_ctx_get_status(ctx
) ==
4282 ZEBRA_DPLANE_REQUEST_SUCCESS
) {
4283 ctx
->zd_provider
= prov
->dp_id
;
4286 * TODO -- improve error-handling: recirc
4287 * errors backwards so that providers can
4288 * 'undo' their work (if they want to)
4291 /* Move to error list; will be returned
4294 TAILQ_REMOVE(&work_list
, ctx
, zd_q_entries
);
4295 TAILQ_INSERT_TAIL(&error_list
,
4301 /* Enqueue new work to the provider */
4302 dplane_provider_lock(prov
);
4304 if (TAILQ_FIRST(&work_list
))
4305 TAILQ_CONCAT(&(prov
->dp_ctx_in_q
), &work_list
,
4308 atomic_fetch_add_explicit(&prov
->dp_in_counter
, counter
,
4309 memory_order_relaxed
);
4310 atomic_fetch_add_explicit(&prov
->dp_in_queued
, counter
,
4311 memory_order_relaxed
);
4312 curr
= atomic_load_explicit(&prov
->dp_in_queued
,
4313 memory_order_relaxed
);
4314 high
= atomic_load_explicit(&prov
->dp_in_max
,
4315 memory_order_relaxed
);
4317 atomic_store_explicit(&prov
->dp_in_max
, curr
,
4318 memory_order_relaxed
);
4320 dplane_provider_unlock(prov
);
4322 /* Reset the temp list (though the 'concat' may have done this
4323 * already), and the counter
4325 TAILQ_INIT(&work_list
);
4328 /* Call into the provider code. Note that this is
4329 * unconditional: we offer to do work even if we don't enqueue
4332 (*prov
->dp_fp
)(prov
);
4334 /* Check for zebra shutdown */
4335 if (!zdplane_info
.dg_run
)
4338 /* Dequeue completed work from the provider */
4339 dplane_provider_lock(prov
);
4341 while (counter
< limit
) {
4342 ctx
= TAILQ_FIRST(&(prov
->dp_ctx_out_q
));
4344 TAILQ_REMOVE(&(prov
->dp_ctx_out_q
), ctx
,
4347 TAILQ_INSERT_TAIL(&work_list
,
4354 dplane_provider_unlock(prov
);
4356 if (IS_ZEBRA_DEBUG_DPLANE_DETAIL
)
4357 zlog_debug("dplane dequeues %d completed work from provider %s",
4358 counter
, dplane_provider_get_name(prov
));
4360 /* Locate next provider */
4362 prov
= TAILQ_NEXT(prov
, dp_prov_link
);
4366 /* After all providers have been serviced, enqueue any completed
4367 * work and any errors back to zebra so it can process the results.
4369 if (IS_ZEBRA_DEBUG_DPLANE_DETAIL
)
4370 zlog_debug("dplane has %d completed, %d errors, for zebra main",
4371 counter
, error_counter
);
4374 * Hand lists through the api to zebra main,
4375 * to reduce the number of lock/unlock cycles
4378 /* Call through to zebra main */
4379 (zdplane_info
.dg_results_cb
)(&error_list
);
4381 TAILQ_INIT(&error_list
);
4383 /* Call through to zebra main */
4384 (zdplane_info
.dg_results_cb
)(&work_list
);
4386 TAILQ_INIT(&work_list
);
4393 * Final phase of shutdown, after all work enqueued to dplane has been
4394 * processed. This is called from the zebra main pthread context.
4396 void zebra_dplane_shutdown(void)
4398 struct zebra_dplane_provider
*dp
;
4400 if (IS_ZEBRA_DEBUG_DPLANE
)
4401 zlog_debug("Zebra dataplane shutdown called");
4403 /* Stop dplane thread, if it's running */
4405 zdplane_info
.dg_run
= false;
4407 if (zdplane_info
.dg_t_update
)
4408 thread_cancel_async(zdplane_info
.dg_t_update
->master
,
4409 &zdplane_info
.dg_t_update
, NULL
);
4411 frr_pthread_stop(zdplane_info
.dg_pthread
, NULL
);
4413 /* Destroy pthread */
4414 frr_pthread_destroy(zdplane_info
.dg_pthread
);
4415 zdplane_info
.dg_pthread
= NULL
;
4416 zdplane_info
.dg_master
= NULL
;
4418 /* Notify provider(s) of final shutdown.
4419 * Note that this call is in the main pthread, so providers must
4420 * be prepared for that.
4422 TAILQ_FOREACH(dp
, &zdplane_info
.dg_providers_q
, dp_prov_link
) {
4423 if (dp
->dp_fini
== NULL
)
4426 dp
->dp_fini(dp
, false);
4429 /* TODO -- Clean-up provider objects */
4431 /* TODO -- Clean queue(s), free memory */
4435 * Initialize the dataplane module during startup, internal/private version
4437 static void zebra_dplane_init_internal(void)
4439 memset(&zdplane_info
, 0, sizeof(zdplane_info
));
4441 pthread_mutex_init(&zdplane_info
.dg_mutex
, NULL
);
4443 TAILQ_INIT(&zdplane_info
.dg_update_ctx_q
);
4444 TAILQ_INIT(&zdplane_info
.dg_providers_q
);
4446 zdplane_info
.dg_updates_per_cycle
= DPLANE_DEFAULT_NEW_WORK
;
4448 zdplane_info
.dg_max_queued_updates
= DPLANE_DEFAULT_MAX_QUEUED
;
4450 /* Register default kernel 'provider' during init */
4451 dplane_provider_init();
4455 * Start the dataplane pthread. This step needs to be run later than the
4456 * 'init' step, in case zebra has fork-ed.
4458 void zebra_dplane_start(void)
4460 struct zebra_dplane_provider
*prov
;
4461 struct frr_pthread_attr pattr
= {
4462 .start
= frr_pthread_attr_default
.start
,
4463 .stop
= frr_pthread_attr_default
.stop
4466 /* Start dataplane pthread */
4468 zdplane_info
.dg_pthread
= frr_pthread_new(&pattr
, "Zebra dplane thread",
4471 zdplane_info
.dg_master
= zdplane_info
.dg_pthread
->master
;
4473 zdplane_info
.dg_run
= true;
4475 /* Enqueue an initial event for the dataplane pthread */
4476 thread_add_event(zdplane_info
.dg_master
, dplane_thread_loop
, NULL
, 0,
4477 &zdplane_info
.dg_t_update
);
4479 /* Call start callbacks for registered providers */
4482 prov
= TAILQ_FIRST(&zdplane_info
.dg_providers_q
);
4488 (prov
->dp_start
)(prov
);
4490 /* Locate next provider */
4492 prov
= TAILQ_NEXT(prov
, dp_prov_link
);
4496 frr_pthread_run(zdplane_info
.dg_pthread
, NULL
);
4500 * Initialize the dataplane module at startup; called by zebra rib_init()
4502 void zebra_dplane_init(int (*results_fp
)(struct dplane_ctx_q
*))
4504 zebra_dplane_init_internal();
4505 zdplane_info
.dg_results_cb
= results_fp
;