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
;
213 char ifname
[INTERFACE_NAMSIZ
+ 1];
216 struct dplane_rule_info
{
218 * Originating zclient sock fd, so we can know who to send
226 struct dplane_ctx_rule
new;
227 struct dplane_ctx_rule old
;
231 * The context block used to exchange info about route updates across
232 * the boundary between the zebra main context (and pthread) and the
233 * dataplane layer (and pthread).
235 struct zebra_dplane_ctx
{
238 enum dplane_op_e zd_op
;
240 /* Status on return */
241 enum zebra_dplane_result zd_status
;
243 /* Dplane provider id */
244 uint32_t zd_provider
;
246 /* Flags - used by providers, e.g. */
254 /* Some updates may be generated by notifications: allow the
255 * plugin to notice and ignore results from its own notifications.
257 uint32_t zd_notif_provider
;
259 /* TODO -- internal/sub-operation status? */
260 enum zebra_dplane_result zd_remote_status
;
261 enum zebra_dplane_result zd_kernel_status
;
264 uint32_t zd_table_id
;
266 char zd_ifname
[INTERFACE_NAMSIZ
];
267 ifindex_t zd_ifindex
;
269 /* Support info for different kinds of updates */
271 struct dplane_route_info rinfo
;
273 struct dplane_pw_info pw
;
274 struct dplane_intf_info intf
;
275 struct dplane_mac_info macinfo
;
276 struct dplane_neigh_info neigh
;
277 struct dplane_rule_info rule
;
280 /* Namespace info, used especially for netlink kernel communication */
281 struct zebra_dplane_info zd_ns_info
;
283 /* Embedded list linkage */
284 TAILQ_ENTRY(zebra_dplane_ctx
) zd_q_entries
;
287 /* Flag that can be set by a pre-kernel provider as a signal that an update
288 * should bypass the kernel.
290 #define DPLANE_CTX_FLAG_NO_KERNEL 0x01
294 * Registration block for one dataplane provider.
296 struct zebra_dplane_provider
{
298 char dp_name
[DPLANE_PROVIDER_NAMELEN
+ 1];
300 /* Priority, for ordering among providers */
307 pthread_mutex_t dp_mutex
;
309 /* Plugin-provided extra data */
315 int (*dp_start
)(struct zebra_dplane_provider
*prov
);
317 int (*dp_fp
)(struct zebra_dplane_provider
*prov
);
319 int (*dp_fini
)(struct zebra_dplane_provider
*prov
, bool early_p
);
321 _Atomic
uint32_t dp_in_counter
;
322 _Atomic
uint32_t dp_in_queued
;
323 _Atomic
uint32_t dp_in_max
;
324 _Atomic
uint32_t dp_out_counter
;
325 _Atomic
uint32_t dp_out_queued
;
326 _Atomic
uint32_t dp_out_max
;
327 _Atomic
uint32_t dp_error_counter
;
329 /* Queue of contexts inbound to the provider */
330 struct dplane_ctx_q dp_ctx_in_q
;
332 /* Queue of completed contexts outbound from the provider back
333 * towards the dataplane module.
335 struct dplane_ctx_q dp_ctx_out_q
;
337 /* Embedded list linkage for provider objects */
338 TAILQ_ENTRY(zebra_dplane_provider
) dp_prov_link
;
344 static struct zebra_dplane_globals
{
345 /* Mutex to control access to dataplane components */
346 pthread_mutex_t dg_mutex
;
348 /* Results callback registered by zebra 'core' */
349 int (*dg_results_cb
)(struct dplane_ctx_q
*ctxlist
);
351 /* Sentinel for beginning of shutdown */
352 volatile bool dg_is_shutdown
;
354 /* Sentinel for end of shutdown */
355 volatile bool dg_run
;
357 /* Update context queue inbound to the dataplane */
358 TAILQ_HEAD(zdg_ctx_q
, zebra_dplane_ctx
) dg_update_ctx_q
;
360 /* Ordered list of providers */
361 TAILQ_HEAD(zdg_prov_q
, zebra_dplane_provider
) dg_providers_q
;
363 /* Counter used to assign internal ids to providers */
364 uint32_t dg_provider_id
;
366 /* Limit number of pending, unprocessed updates */
367 _Atomic
uint32_t dg_max_queued_updates
;
369 /* Control whether system route notifications should be produced. */
370 bool dg_sys_route_notifs
;
372 /* Limit number of new updates dequeued at once, to pace an
375 uint32_t dg_updates_per_cycle
;
377 _Atomic
uint32_t dg_routes_in
;
378 _Atomic
uint32_t dg_routes_queued
;
379 _Atomic
uint32_t dg_routes_queued_max
;
380 _Atomic
uint32_t dg_route_errors
;
381 _Atomic
uint32_t dg_other_errors
;
383 _Atomic
uint32_t dg_nexthops_in
;
384 _Atomic
uint32_t dg_nexthop_errors
;
386 _Atomic
uint32_t dg_lsps_in
;
387 _Atomic
uint32_t dg_lsp_errors
;
389 _Atomic
uint32_t dg_pws_in
;
390 _Atomic
uint32_t dg_pw_errors
;
392 _Atomic
uint32_t dg_intf_addrs_in
;
393 _Atomic
uint32_t dg_intf_addr_errors
;
395 _Atomic
uint32_t dg_macs_in
;
396 _Atomic
uint32_t dg_mac_errors
;
398 _Atomic
uint32_t dg_neighs_in
;
399 _Atomic
uint32_t dg_neigh_errors
;
401 _Atomic
uint32_t dg_rules_in
;
402 _Atomic
uint32_t dg_rule_errors
;
404 _Atomic
uint32_t dg_update_yields
;
406 /* Dataplane pthread */
407 struct frr_pthread
*dg_pthread
;
409 /* Event-delivery context 'master' for the dplane */
410 struct thread_master
*dg_master
;
412 /* Event/'thread' pointer for queued updates */
413 struct thread
*dg_t_update
;
415 /* Event pointer for pending shutdown check loop */
416 struct thread
*dg_t_shutdown_check
;
421 * Lock and unlock for interactions with the zebra 'core' pthread
423 #define DPLANE_LOCK() pthread_mutex_lock(&zdplane_info.dg_mutex)
424 #define DPLANE_UNLOCK() pthread_mutex_unlock(&zdplane_info.dg_mutex)
428 * Lock and unlock for individual providers
430 #define DPLANE_PROV_LOCK(p) pthread_mutex_lock(&((p)->dp_mutex))
431 #define DPLANE_PROV_UNLOCK(p) pthread_mutex_unlock(&((p)->dp_mutex))
434 static int dplane_thread_loop(struct thread
*event
);
435 static void dplane_info_from_zns(struct zebra_dplane_info
*ns_info
,
436 struct zebra_ns
*zns
);
437 static enum zebra_dplane_result
lsp_update_internal(zebra_lsp_t
*lsp
,
438 enum dplane_op_e op
);
439 static enum zebra_dplane_result
pw_update_internal(struct zebra_pw
*pw
,
440 enum dplane_op_e op
);
441 static enum zebra_dplane_result
intf_addr_update_internal(
442 const struct interface
*ifp
, const struct connected
*ifc
,
443 enum dplane_op_e op
);
444 static enum zebra_dplane_result
mac_update_common(
445 enum dplane_op_e op
, const struct interface
*ifp
,
446 const struct interface
*br_ifp
,
447 vlanid_t vid
, const struct ethaddr
*mac
,
448 struct in_addr vtep_ip
, bool sticky
, uint32_t nhg_id
,
449 uint32_t update_flags
);
450 static enum zebra_dplane_result
neigh_update_internal(
452 const struct interface
*ifp
,
453 const struct ethaddr
*mac
,
454 const struct ipaddr
*ip
,
455 uint32_t flags
, uint16_t state
, uint32_t update_flags
);
461 /* Obtain thread_master for dataplane thread */
462 struct thread_master
*dplane_get_thread_master(void)
464 return zdplane_info
.dg_master
;
468 * Allocate a dataplane update context
470 struct zebra_dplane_ctx
*dplane_ctx_alloc(void)
472 struct zebra_dplane_ctx
*p
;
474 /* TODO -- just alloc'ing memory, but would like to maintain
477 p
= XCALLOC(MTYPE_DP_CTX
, sizeof(struct zebra_dplane_ctx
));
482 /* Enable system route notifications */
483 void dplane_enable_sys_route_notifs(void)
485 zdplane_info
.dg_sys_route_notifs
= true;
489 * Clean up dependent/internal allocations inside a context object
491 static void dplane_ctx_free_internal(struct zebra_dplane_ctx
*ctx
)
494 * Some internal allocations may need to be freed, depending on
495 * the type of info captured in the ctx.
497 switch (ctx
->zd_op
) {
498 case DPLANE_OP_ROUTE_INSTALL
:
499 case DPLANE_OP_ROUTE_UPDATE
:
500 case DPLANE_OP_ROUTE_DELETE
:
501 case DPLANE_OP_SYS_ROUTE_ADD
:
502 case DPLANE_OP_SYS_ROUTE_DELETE
:
503 case DPLANE_OP_ROUTE_NOTIFY
:
505 /* Free allocated nexthops */
506 if (ctx
->u
.rinfo
.zd_ng
.nexthop
) {
507 /* This deals with recursive nexthops too */
508 nexthops_free(ctx
->u
.rinfo
.zd_ng
.nexthop
);
510 ctx
->u
.rinfo
.zd_ng
.nexthop
= NULL
;
513 /* Free backup info also (if present) */
514 if (ctx
->u
.rinfo
.backup_ng
.nexthop
) {
515 /* This deals with recursive nexthops too */
516 nexthops_free(ctx
->u
.rinfo
.backup_ng
.nexthop
);
518 ctx
->u
.rinfo
.backup_ng
.nexthop
= NULL
;
521 if (ctx
->u
.rinfo
.zd_old_ng
.nexthop
) {
522 /* This deals with recursive nexthops too */
523 nexthops_free(ctx
->u
.rinfo
.zd_old_ng
.nexthop
);
525 ctx
->u
.rinfo
.zd_old_ng
.nexthop
= NULL
;
528 if (ctx
->u
.rinfo
.old_backup_ng
.nexthop
) {
529 /* This deals with recursive nexthops too */
530 nexthops_free(ctx
->u
.rinfo
.old_backup_ng
.nexthop
);
532 ctx
->u
.rinfo
.old_backup_ng
.nexthop
= NULL
;
537 case DPLANE_OP_NH_INSTALL
:
538 case DPLANE_OP_NH_UPDATE
:
539 case DPLANE_OP_NH_DELETE
: {
540 if (ctx
->u
.rinfo
.nhe
.ng
.nexthop
) {
541 /* This deals with recursive nexthops too */
542 nexthops_free(ctx
->u
.rinfo
.nhe
.ng
.nexthop
);
544 ctx
->u
.rinfo
.nhe
.ng
.nexthop
= NULL
;
549 case DPLANE_OP_LSP_INSTALL
:
550 case DPLANE_OP_LSP_UPDATE
:
551 case DPLANE_OP_LSP_DELETE
:
552 case DPLANE_OP_LSP_NOTIFY
:
554 zebra_nhlfe_t
*nhlfe
;
556 /* Unlink and free allocated NHLFEs */
557 frr_each_safe(nhlfe_list
, &ctx
->u
.lsp
.nhlfe_list
, nhlfe
) {
558 nhlfe_list_del(&ctx
->u
.lsp
.nhlfe_list
, nhlfe
);
559 zebra_mpls_nhlfe_free(nhlfe
);
562 /* Unlink and free allocated backup NHLFEs, if present */
563 frr_each_safe(nhlfe_list
,
564 &(ctx
->u
.lsp
.backup_nhlfe_list
), nhlfe
) {
565 nhlfe_list_del(&ctx
->u
.lsp
.backup_nhlfe_list
,
567 zebra_mpls_nhlfe_free(nhlfe
);
570 /* Clear pointers in lsp struct, in case we're caching
571 * free context structs.
573 nhlfe_list_init(&ctx
->u
.lsp
.nhlfe_list
);
574 ctx
->u
.lsp
.best_nhlfe
= NULL
;
575 nhlfe_list_init(&ctx
->u
.lsp
.backup_nhlfe_list
);
580 case DPLANE_OP_PW_INSTALL
:
581 case DPLANE_OP_PW_UNINSTALL
:
582 /* Free allocated nexthops */
583 if (ctx
->u
.pw
.nhg
.nexthop
) {
584 /* This deals with recursive nexthops too */
585 nexthops_free(ctx
->u
.pw
.nhg
.nexthop
);
587 ctx
->u
.pw
.nhg
.nexthop
= NULL
;
591 case DPLANE_OP_ADDR_INSTALL
:
592 case DPLANE_OP_ADDR_UNINSTALL
:
593 /* Maybe free label string, if allocated */
594 if (ctx
->u
.intf
.label
!= NULL
&&
595 ctx
->u
.intf
.label
!= ctx
->u
.intf
.label_buf
) {
596 free(ctx
->u
.intf
.label
);
597 ctx
->u
.intf
.label
= NULL
;
601 case DPLANE_OP_MAC_INSTALL
:
602 case DPLANE_OP_MAC_DELETE
:
603 case DPLANE_OP_NEIGH_INSTALL
:
604 case DPLANE_OP_NEIGH_UPDATE
:
605 case DPLANE_OP_NEIGH_DELETE
:
606 case DPLANE_OP_VTEP_ADD
:
607 case DPLANE_OP_VTEP_DELETE
:
608 case DPLANE_OP_RULE_ADD
:
609 case DPLANE_OP_RULE_DELETE
:
610 case DPLANE_OP_RULE_UPDATE
:
611 case DPLANE_OP_NEIGH_DISCOVER
:
618 * Free a dataplane results context.
620 static void dplane_ctx_free(struct zebra_dplane_ctx
**pctx
)
625 DPLANE_CTX_VALID(*pctx
);
627 /* TODO -- just freeing memory, but would like to maintain
631 /* Some internal allocations may need to be freed, depending on
632 * the type of info captured in the ctx.
634 dplane_ctx_free_internal(*pctx
);
636 XFREE(MTYPE_DP_CTX
, *pctx
);
640 * Reset an allocated context object for re-use. All internal allocations are
641 * freed and the context is memset.
643 void dplane_ctx_reset(struct zebra_dplane_ctx
*ctx
)
645 dplane_ctx_free_internal(ctx
);
646 memset(ctx
, 0, sizeof(*ctx
));
650 * Return a context block to the dplane module after processing
652 void dplane_ctx_fini(struct zebra_dplane_ctx
**pctx
)
654 /* TODO -- maintain pool; for now, just free */
655 dplane_ctx_free(pctx
);
658 /* Enqueue a context block */
659 void dplane_ctx_enqueue_tail(struct dplane_ctx_q
*q
,
660 const struct zebra_dplane_ctx
*ctx
)
662 TAILQ_INSERT_TAIL(q
, (struct zebra_dplane_ctx
*)ctx
, zd_q_entries
);
665 /* Append a list of context blocks to another list */
666 void dplane_ctx_list_append(struct dplane_ctx_q
*to_list
,
667 struct dplane_ctx_q
*from_list
)
669 if (TAILQ_FIRST(from_list
)) {
670 TAILQ_CONCAT(to_list
, from_list
, zd_q_entries
);
672 /* And clear 'from' list */
673 TAILQ_INIT(from_list
);
677 /* Dequeue a context block from the head of a list */
678 struct zebra_dplane_ctx
*dplane_ctx_dequeue(struct dplane_ctx_q
*q
)
680 struct zebra_dplane_ctx
*ctx
= TAILQ_FIRST(q
);
683 TAILQ_REMOVE(q
, ctx
, zd_q_entries
);
689 * Accessors for information from the context object
691 enum zebra_dplane_result
dplane_ctx_get_status(
692 const struct zebra_dplane_ctx
*ctx
)
694 DPLANE_CTX_VALID(ctx
);
696 return ctx
->zd_status
;
699 void dplane_ctx_set_status(struct zebra_dplane_ctx
*ctx
,
700 enum zebra_dplane_result status
)
702 DPLANE_CTX_VALID(ctx
);
704 ctx
->zd_status
= status
;
707 /* Retrieve last/current provider id */
708 uint32_t dplane_ctx_get_provider(const struct zebra_dplane_ctx
*ctx
)
710 DPLANE_CTX_VALID(ctx
);
711 return ctx
->zd_provider
;
714 /* Providers run before the kernel can control whether a kernel
715 * update should be done.
717 void dplane_ctx_set_skip_kernel(struct zebra_dplane_ctx
*ctx
)
719 DPLANE_CTX_VALID(ctx
);
721 SET_FLAG(ctx
->zd_flags
, DPLANE_CTX_FLAG_NO_KERNEL
);
724 bool dplane_ctx_is_skip_kernel(const struct zebra_dplane_ctx
*ctx
)
726 DPLANE_CTX_VALID(ctx
);
728 return CHECK_FLAG(ctx
->zd_flags
, DPLANE_CTX_FLAG_NO_KERNEL
);
731 void dplane_ctx_set_op(struct zebra_dplane_ctx
*ctx
, enum dplane_op_e op
)
733 DPLANE_CTX_VALID(ctx
);
737 enum dplane_op_e
dplane_ctx_get_op(const struct zebra_dplane_ctx
*ctx
)
739 DPLANE_CTX_VALID(ctx
);
744 const char *dplane_op2str(enum dplane_op_e op
)
746 const char *ret
= "UNKNOWN";
754 case DPLANE_OP_ROUTE_INSTALL
:
755 ret
= "ROUTE_INSTALL";
757 case DPLANE_OP_ROUTE_UPDATE
:
758 ret
= "ROUTE_UPDATE";
760 case DPLANE_OP_ROUTE_DELETE
:
761 ret
= "ROUTE_DELETE";
763 case DPLANE_OP_ROUTE_NOTIFY
:
764 ret
= "ROUTE_NOTIFY";
768 case DPLANE_OP_NH_INSTALL
:
771 case DPLANE_OP_NH_UPDATE
:
774 case DPLANE_OP_NH_DELETE
:
778 case DPLANE_OP_LSP_INSTALL
:
781 case DPLANE_OP_LSP_UPDATE
:
784 case DPLANE_OP_LSP_DELETE
:
787 case DPLANE_OP_LSP_NOTIFY
:
791 case DPLANE_OP_PW_INSTALL
:
794 case DPLANE_OP_PW_UNINSTALL
:
795 ret
= "PW_UNINSTALL";
798 case DPLANE_OP_SYS_ROUTE_ADD
:
799 ret
= "SYS_ROUTE_ADD";
801 case DPLANE_OP_SYS_ROUTE_DELETE
:
802 ret
= "SYS_ROUTE_DEL";
805 case DPLANE_OP_ADDR_INSTALL
:
806 ret
= "ADDR_INSTALL";
808 case DPLANE_OP_ADDR_UNINSTALL
:
809 ret
= "ADDR_UNINSTALL";
812 case DPLANE_OP_MAC_INSTALL
:
815 case DPLANE_OP_MAC_DELETE
:
819 case DPLANE_OP_NEIGH_INSTALL
:
820 ret
= "NEIGH_INSTALL";
822 case DPLANE_OP_NEIGH_UPDATE
:
823 ret
= "NEIGH_UPDATE";
825 case DPLANE_OP_NEIGH_DELETE
:
826 ret
= "NEIGH_DELETE";
828 case DPLANE_OP_VTEP_ADD
:
831 case DPLANE_OP_VTEP_DELETE
:
835 case DPLANE_OP_RULE_ADD
:
838 case DPLANE_OP_RULE_DELETE
:
841 case DPLANE_OP_RULE_UPDATE
:
845 case DPLANE_OP_NEIGH_DISCOVER
:
846 ret
= "NEIGH_DISCOVER";
853 const char *dplane_res2str(enum zebra_dplane_result res
)
855 const char *ret
= "<Unknown>";
858 case ZEBRA_DPLANE_REQUEST_FAILURE
:
861 case ZEBRA_DPLANE_REQUEST_QUEUED
:
864 case ZEBRA_DPLANE_REQUEST_SUCCESS
:
872 void dplane_ctx_set_dest(struct zebra_dplane_ctx
*ctx
,
873 const struct prefix
*dest
)
875 DPLANE_CTX_VALID(ctx
);
877 prefix_copy(&(ctx
->u
.rinfo
.zd_dest
), dest
);
880 const struct prefix
*dplane_ctx_get_dest(const struct zebra_dplane_ctx
*ctx
)
882 DPLANE_CTX_VALID(ctx
);
884 return &(ctx
->u
.rinfo
.zd_dest
);
887 void dplane_ctx_set_src(struct zebra_dplane_ctx
*ctx
, const struct prefix
*src
)
889 DPLANE_CTX_VALID(ctx
);
892 prefix_copy(&(ctx
->u
.rinfo
.zd_src
), src
);
894 memset(&(ctx
->u
.rinfo
.zd_src
), 0, sizeof(struct prefix
));
897 /* Source prefix is a little special - return NULL for "no src prefix" */
898 const struct prefix
*dplane_ctx_get_src(const struct zebra_dplane_ctx
*ctx
)
900 DPLANE_CTX_VALID(ctx
);
902 if (ctx
->u
.rinfo
.zd_src
.prefixlen
== 0 &&
903 IN6_IS_ADDR_UNSPECIFIED(&(ctx
->u
.rinfo
.zd_src
.u
.prefix6
))) {
906 return &(ctx
->u
.rinfo
.zd_src
);
910 bool dplane_ctx_is_update(const struct zebra_dplane_ctx
*ctx
)
912 DPLANE_CTX_VALID(ctx
);
914 return ctx
->zd_is_update
;
917 uint32_t dplane_ctx_get_seq(const struct zebra_dplane_ctx
*ctx
)
919 DPLANE_CTX_VALID(ctx
);
924 uint32_t dplane_ctx_get_old_seq(const struct zebra_dplane_ctx
*ctx
)
926 DPLANE_CTX_VALID(ctx
);
928 return ctx
->zd_old_seq
;
931 void dplane_ctx_set_vrf(struct zebra_dplane_ctx
*ctx
, vrf_id_t vrf
)
933 DPLANE_CTX_VALID(ctx
);
935 ctx
->zd_vrf_id
= vrf
;
938 vrf_id_t
dplane_ctx_get_vrf(const struct zebra_dplane_ctx
*ctx
)
940 DPLANE_CTX_VALID(ctx
);
942 return ctx
->zd_vrf_id
;
945 bool dplane_ctx_is_from_notif(const struct zebra_dplane_ctx
*ctx
)
947 DPLANE_CTX_VALID(ctx
);
949 return (ctx
->zd_notif_provider
!= 0);
952 uint32_t dplane_ctx_get_notif_provider(const struct zebra_dplane_ctx
*ctx
)
954 DPLANE_CTX_VALID(ctx
);
956 return ctx
->zd_notif_provider
;
959 void dplane_ctx_set_notif_provider(struct zebra_dplane_ctx
*ctx
,
962 DPLANE_CTX_VALID(ctx
);
964 ctx
->zd_notif_provider
= id
;
967 const char *dplane_ctx_get_ifname(const struct zebra_dplane_ctx
*ctx
)
969 DPLANE_CTX_VALID(ctx
);
971 return ctx
->zd_ifname
;
974 void dplane_ctx_set_ifname(struct zebra_dplane_ctx
*ctx
, const char *ifname
)
976 DPLANE_CTX_VALID(ctx
);
981 strlcpy(ctx
->zd_ifname
, ifname
, sizeof(ctx
->zd_ifname
));
984 ifindex_t
dplane_ctx_get_ifindex(const struct zebra_dplane_ctx
*ctx
)
986 DPLANE_CTX_VALID(ctx
);
988 return ctx
->zd_ifindex
;
991 void dplane_ctx_set_type(struct zebra_dplane_ctx
*ctx
, int type
)
993 DPLANE_CTX_VALID(ctx
);
995 ctx
->u
.rinfo
.zd_type
= type
;
998 int dplane_ctx_get_type(const struct zebra_dplane_ctx
*ctx
)
1000 DPLANE_CTX_VALID(ctx
);
1002 return ctx
->u
.rinfo
.zd_type
;
1005 int dplane_ctx_get_old_type(const struct zebra_dplane_ctx
*ctx
)
1007 DPLANE_CTX_VALID(ctx
);
1009 return ctx
->u
.rinfo
.zd_old_type
;
1012 void dplane_ctx_set_afi(struct zebra_dplane_ctx
*ctx
, afi_t afi
)
1014 DPLANE_CTX_VALID(ctx
);
1016 ctx
->u
.rinfo
.zd_afi
= afi
;
1019 afi_t
dplane_ctx_get_afi(const struct zebra_dplane_ctx
*ctx
)
1021 DPLANE_CTX_VALID(ctx
);
1023 return ctx
->u
.rinfo
.zd_afi
;
1026 void dplane_ctx_set_safi(struct zebra_dplane_ctx
*ctx
, safi_t safi
)
1028 DPLANE_CTX_VALID(ctx
);
1030 ctx
->u
.rinfo
.zd_safi
= safi
;
1033 safi_t
dplane_ctx_get_safi(const struct zebra_dplane_ctx
*ctx
)
1035 DPLANE_CTX_VALID(ctx
);
1037 return ctx
->u
.rinfo
.zd_safi
;
1040 void dplane_ctx_set_table(struct zebra_dplane_ctx
*ctx
, uint32_t table
)
1042 DPLANE_CTX_VALID(ctx
);
1044 ctx
->zd_table_id
= table
;
1047 uint32_t dplane_ctx_get_table(const struct zebra_dplane_ctx
*ctx
)
1049 DPLANE_CTX_VALID(ctx
);
1051 return ctx
->zd_table_id
;
1054 route_tag_t
dplane_ctx_get_tag(const struct zebra_dplane_ctx
*ctx
)
1056 DPLANE_CTX_VALID(ctx
);
1058 return ctx
->u
.rinfo
.zd_tag
;
1061 void dplane_ctx_set_tag(struct zebra_dplane_ctx
*ctx
, route_tag_t tag
)
1063 DPLANE_CTX_VALID(ctx
);
1065 ctx
->u
.rinfo
.zd_tag
= tag
;
1068 route_tag_t
dplane_ctx_get_old_tag(const struct zebra_dplane_ctx
*ctx
)
1070 DPLANE_CTX_VALID(ctx
);
1072 return ctx
->u
.rinfo
.zd_old_tag
;
1075 uint16_t dplane_ctx_get_instance(const struct zebra_dplane_ctx
*ctx
)
1077 DPLANE_CTX_VALID(ctx
);
1079 return ctx
->u
.rinfo
.zd_instance
;
1082 void dplane_ctx_set_instance(struct zebra_dplane_ctx
*ctx
, uint16_t instance
)
1084 DPLANE_CTX_VALID(ctx
);
1086 ctx
->u
.rinfo
.zd_instance
= instance
;
1089 uint16_t dplane_ctx_get_old_instance(const struct zebra_dplane_ctx
*ctx
)
1091 DPLANE_CTX_VALID(ctx
);
1093 return ctx
->u
.rinfo
.zd_old_instance
;
1096 uint32_t dplane_ctx_get_metric(const struct zebra_dplane_ctx
*ctx
)
1098 DPLANE_CTX_VALID(ctx
);
1100 return ctx
->u
.rinfo
.zd_metric
;
1103 uint32_t dplane_ctx_get_old_metric(const struct zebra_dplane_ctx
*ctx
)
1105 DPLANE_CTX_VALID(ctx
);
1107 return ctx
->u
.rinfo
.zd_old_metric
;
1110 uint32_t dplane_ctx_get_mtu(const struct zebra_dplane_ctx
*ctx
)
1112 DPLANE_CTX_VALID(ctx
);
1114 return ctx
->u
.rinfo
.zd_mtu
;
1117 uint32_t dplane_ctx_get_nh_mtu(const struct zebra_dplane_ctx
*ctx
)
1119 DPLANE_CTX_VALID(ctx
);
1121 return ctx
->u
.rinfo
.zd_nexthop_mtu
;
1124 uint8_t dplane_ctx_get_distance(const struct zebra_dplane_ctx
*ctx
)
1126 DPLANE_CTX_VALID(ctx
);
1128 return ctx
->u
.rinfo
.zd_distance
;
1131 void dplane_ctx_set_distance(struct zebra_dplane_ctx
*ctx
, uint8_t distance
)
1133 DPLANE_CTX_VALID(ctx
);
1135 ctx
->u
.rinfo
.zd_distance
= distance
;
1138 uint8_t dplane_ctx_get_old_distance(const struct zebra_dplane_ctx
*ctx
)
1140 DPLANE_CTX_VALID(ctx
);
1142 return ctx
->u
.rinfo
.zd_old_distance
;
1146 * Set the nexthops associated with a context: note that processing code
1147 * may well expect that nexthops are in canonical (sorted) order, so we
1148 * will enforce that here.
1150 void dplane_ctx_set_nexthops(struct zebra_dplane_ctx
*ctx
, struct nexthop
*nh
)
1152 DPLANE_CTX_VALID(ctx
);
1154 if (ctx
->u
.rinfo
.zd_ng
.nexthop
) {
1155 nexthops_free(ctx
->u
.rinfo
.zd_ng
.nexthop
);
1156 ctx
->u
.rinfo
.zd_ng
.nexthop
= NULL
;
1158 nexthop_group_copy_nh_sorted(&(ctx
->u
.rinfo
.zd_ng
), nh
);
1162 * Set the list of backup nexthops; their ordering is preserved (they're not
1165 void dplane_ctx_set_backup_nhg(struct zebra_dplane_ctx
*ctx
,
1166 const struct nexthop_group
*nhg
)
1168 struct nexthop
*nh
, *last_nh
, *nexthop
;
1170 DPLANE_CTX_VALID(ctx
);
1172 if (ctx
->u
.rinfo
.backup_ng
.nexthop
) {
1173 nexthops_free(ctx
->u
.rinfo
.backup_ng
.nexthop
);
1174 ctx
->u
.rinfo
.backup_ng
.nexthop
= NULL
;
1179 /* Be careful to preserve the order of the backup list */
1180 for (nh
= nhg
->nexthop
; nh
; nh
= nh
->next
) {
1181 nexthop
= nexthop_dup(nh
, NULL
);
1184 NEXTHOP_APPEND(last_nh
, nexthop
);
1186 ctx
->u
.rinfo
.backup_ng
.nexthop
= nexthop
;
1192 uint32_t dplane_ctx_get_nhg_id(const struct zebra_dplane_ctx
*ctx
)
1194 DPLANE_CTX_VALID(ctx
);
1195 return ctx
->u
.rinfo
.zd_nhg_id
;
1198 const struct nexthop_group
*dplane_ctx_get_ng(
1199 const struct zebra_dplane_ctx
*ctx
)
1201 DPLANE_CTX_VALID(ctx
);
1203 return &(ctx
->u
.rinfo
.zd_ng
);
1206 const struct nexthop_group
*
1207 dplane_ctx_get_backup_ng(const struct zebra_dplane_ctx
*ctx
)
1209 DPLANE_CTX_VALID(ctx
);
1211 return &(ctx
->u
.rinfo
.backup_ng
);
1214 const struct nexthop_group
*
1215 dplane_ctx_get_old_ng(const struct zebra_dplane_ctx
*ctx
)
1217 DPLANE_CTX_VALID(ctx
);
1219 return &(ctx
->u
.rinfo
.zd_old_ng
);
1222 const struct nexthop_group
*
1223 dplane_ctx_get_old_backup_ng(const struct zebra_dplane_ctx
*ctx
)
1225 DPLANE_CTX_VALID(ctx
);
1227 return &(ctx
->u
.rinfo
.old_backup_ng
);
1230 const struct zebra_dplane_info
*dplane_ctx_get_ns(
1231 const struct zebra_dplane_ctx
*ctx
)
1233 DPLANE_CTX_VALID(ctx
);
1235 return &(ctx
->zd_ns_info
);
1238 /* Accessors for nexthop information */
1239 uint32_t dplane_ctx_get_nhe_id(const struct zebra_dplane_ctx
*ctx
)
1241 DPLANE_CTX_VALID(ctx
);
1242 return ctx
->u
.rinfo
.nhe
.id
;
1245 afi_t
dplane_ctx_get_nhe_afi(const struct zebra_dplane_ctx
*ctx
)
1247 DPLANE_CTX_VALID(ctx
);
1248 return ctx
->u
.rinfo
.nhe
.afi
;
1251 vrf_id_t
dplane_ctx_get_nhe_vrf_id(const struct zebra_dplane_ctx
*ctx
)
1253 DPLANE_CTX_VALID(ctx
);
1254 return ctx
->u
.rinfo
.nhe
.vrf_id
;
1257 int dplane_ctx_get_nhe_type(const struct zebra_dplane_ctx
*ctx
)
1259 DPLANE_CTX_VALID(ctx
);
1260 return ctx
->u
.rinfo
.nhe
.type
;
1263 const struct nexthop_group
*
1264 dplane_ctx_get_nhe_ng(const struct zebra_dplane_ctx
*ctx
)
1266 DPLANE_CTX_VALID(ctx
);
1267 return &(ctx
->u
.rinfo
.nhe
.ng
);
1270 const struct nh_grp
*
1271 dplane_ctx_get_nhe_nh_grp(const struct zebra_dplane_ctx
*ctx
)
1273 DPLANE_CTX_VALID(ctx
);
1274 return ctx
->u
.rinfo
.nhe
.nh_grp
;
1277 uint8_t dplane_ctx_get_nhe_nh_grp_count(const struct zebra_dplane_ctx
*ctx
)
1279 DPLANE_CTX_VALID(ctx
);
1280 return ctx
->u
.rinfo
.nhe
.nh_grp_count
;
1283 /* Accessors for LSP information */
1285 mpls_label_t
dplane_ctx_get_in_label(const struct zebra_dplane_ctx
*ctx
)
1287 DPLANE_CTX_VALID(ctx
);
1289 return ctx
->u
.lsp
.ile
.in_label
;
1292 void dplane_ctx_set_in_label(struct zebra_dplane_ctx
*ctx
, mpls_label_t label
)
1294 DPLANE_CTX_VALID(ctx
);
1296 ctx
->u
.lsp
.ile
.in_label
= label
;
1299 uint8_t dplane_ctx_get_addr_family(const struct zebra_dplane_ctx
*ctx
)
1301 DPLANE_CTX_VALID(ctx
);
1303 return ctx
->u
.lsp
.addr_family
;
1306 void dplane_ctx_set_addr_family(struct zebra_dplane_ctx
*ctx
,
1309 DPLANE_CTX_VALID(ctx
);
1311 ctx
->u
.lsp
.addr_family
= family
;
1314 uint32_t dplane_ctx_get_lsp_flags(const struct zebra_dplane_ctx
*ctx
)
1316 DPLANE_CTX_VALID(ctx
);
1318 return ctx
->u
.lsp
.flags
;
1321 void dplane_ctx_set_lsp_flags(struct zebra_dplane_ctx
*ctx
,
1324 DPLANE_CTX_VALID(ctx
);
1326 ctx
->u
.lsp
.flags
= flags
;
1329 const struct nhlfe_list_head
*dplane_ctx_get_nhlfe_list(
1330 const struct zebra_dplane_ctx
*ctx
)
1332 DPLANE_CTX_VALID(ctx
);
1333 return &(ctx
->u
.lsp
.nhlfe_list
);
1336 const struct nhlfe_list_head
*dplane_ctx_get_backup_nhlfe_list(
1337 const struct zebra_dplane_ctx
*ctx
)
1339 DPLANE_CTX_VALID(ctx
);
1340 return &(ctx
->u
.lsp
.backup_nhlfe_list
);
1343 zebra_nhlfe_t
*dplane_ctx_add_nhlfe(struct zebra_dplane_ctx
*ctx
,
1344 enum lsp_types_t lsp_type
,
1345 enum nexthop_types_t nh_type
,
1346 const union g_addr
*gate
,
1349 mpls_label_t
*out_labels
)
1351 zebra_nhlfe_t
*nhlfe
;
1353 DPLANE_CTX_VALID(ctx
);
1355 nhlfe
= zebra_mpls_lsp_add_nhlfe(&(ctx
->u
.lsp
),
1356 lsp_type
, nh_type
, gate
,
1357 ifindex
, num_labels
, out_labels
);
1362 zebra_nhlfe_t
*dplane_ctx_add_backup_nhlfe(struct zebra_dplane_ctx
*ctx
,
1363 enum lsp_types_t lsp_type
,
1364 enum nexthop_types_t nh_type
,
1365 const union g_addr
*gate
,
1368 mpls_label_t
*out_labels
)
1370 zebra_nhlfe_t
*nhlfe
;
1372 DPLANE_CTX_VALID(ctx
);
1374 nhlfe
= zebra_mpls_lsp_add_backup_nhlfe(&(ctx
->u
.lsp
),
1375 lsp_type
, nh_type
, gate
,
1376 ifindex
, num_labels
,
1382 const zebra_nhlfe_t
*
1383 dplane_ctx_get_best_nhlfe(const struct zebra_dplane_ctx
*ctx
)
1385 DPLANE_CTX_VALID(ctx
);
1387 return ctx
->u
.lsp
.best_nhlfe
;
1390 const zebra_nhlfe_t
*
1391 dplane_ctx_set_best_nhlfe(struct zebra_dplane_ctx
*ctx
,
1392 zebra_nhlfe_t
*nhlfe
)
1394 DPLANE_CTX_VALID(ctx
);
1396 ctx
->u
.lsp
.best_nhlfe
= nhlfe
;
1397 return ctx
->u
.lsp
.best_nhlfe
;
1400 uint32_t dplane_ctx_get_lsp_num_ecmp(const struct zebra_dplane_ctx
*ctx
)
1402 DPLANE_CTX_VALID(ctx
);
1404 return ctx
->u
.lsp
.num_ecmp
;
1407 mpls_label_t
dplane_ctx_get_pw_local_label(const struct zebra_dplane_ctx
*ctx
)
1409 DPLANE_CTX_VALID(ctx
);
1411 return ctx
->u
.pw
.local_label
;
1414 mpls_label_t
dplane_ctx_get_pw_remote_label(const struct zebra_dplane_ctx
*ctx
)
1416 DPLANE_CTX_VALID(ctx
);
1418 return ctx
->u
.pw
.remote_label
;
1421 int dplane_ctx_get_pw_type(const struct zebra_dplane_ctx
*ctx
)
1423 DPLANE_CTX_VALID(ctx
);
1425 return ctx
->u
.pw
.type
;
1428 int dplane_ctx_get_pw_af(const struct zebra_dplane_ctx
*ctx
)
1430 DPLANE_CTX_VALID(ctx
);
1432 return ctx
->u
.pw
.af
;
1435 uint32_t dplane_ctx_get_pw_flags(const struct zebra_dplane_ctx
*ctx
)
1437 DPLANE_CTX_VALID(ctx
);
1439 return ctx
->u
.pw
.flags
;
1442 int dplane_ctx_get_pw_status(const struct zebra_dplane_ctx
*ctx
)
1444 DPLANE_CTX_VALID(ctx
);
1446 return ctx
->u
.pw
.status
;
1449 void dplane_ctx_set_pw_status(struct zebra_dplane_ctx
*ctx
, int status
)
1451 DPLANE_CTX_VALID(ctx
);
1453 ctx
->u
.pw
.status
= status
;
1456 const union g_addr
*dplane_ctx_get_pw_dest(
1457 const struct zebra_dplane_ctx
*ctx
)
1459 DPLANE_CTX_VALID(ctx
);
1461 return &(ctx
->u
.pw
.dest
);
1464 const union pw_protocol_fields
*dplane_ctx_get_pw_proto(
1465 const struct zebra_dplane_ctx
*ctx
)
1467 DPLANE_CTX_VALID(ctx
);
1469 return &(ctx
->u
.pw
.fields
);
1472 const struct nexthop_group
*
1473 dplane_ctx_get_pw_nhg(const struct zebra_dplane_ctx
*ctx
)
1475 DPLANE_CTX_VALID(ctx
);
1477 return &(ctx
->u
.pw
.nhg
);
1480 /* Accessors for interface information */
1481 uint32_t dplane_ctx_get_intf_metric(const struct zebra_dplane_ctx
*ctx
)
1483 DPLANE_CTX_VALID(ctx
);
1485 return ctx
->u
.intf
.metric
;
1488 /* Is interface addr p2p? */
1489 bool dplane_ctx_intf_is_connected(const struct zebra_dplane_ctx
*ctx
)
1491 DPLANE_CTX_VALID(ctx
);
1493 return (ctx
->u
.intf
.flags
& DPLANE_INTF_CONNECTED
);
1496 bool dplane_ctx_intf_is_secondary(const struct zebra_dplane_ctx
*ctx
)
1498 DPLANE_CTX_VALID(ctx
);
1500 return (ctx
->u
.intf
.flags
& DPLANE_INTF_SECONDARY
);
1503 bool dplane_ctx_intf_is_broadcast(const struct zebra_dplane_ctx
*ctx
)
1505 DPLANE_CTX_VALID(ctx
);
1507 return (ctx
->u
.intf
.flags
& DPLANE_INTF_BROADCAST
);
1510 const struct prefix
*dplane_ctx_get_intf_addr(
1511 const struct zebra_dplane_ctx
*ctx
)
1513 DPLANE_CTX_VALID(ctx
);
1515 return &(ctx
->u
.intf
.prefix
);
1518 bool dplane_ctx_intf_has_dest(const struct zebra_dplane_ctx
*ctx
)
1520 DPLANE_CTX_VALID(ctx
);
1522 return (ctx
->u
.intf
.flags
& DPLANE_INTF_HAS_DEST
);
1525 const struct prefix
*dplane_ctx_get_intf_dest(
1526 const struct zebra_dplane_ctx
*ctx
)
1528 DPLANE_CTX_VALID(ctx
);
1530 if (ctx
->u
.intf
.flags
& DPLANE_INTF_HAS_DEST
)
1531 return &(ctx
->u
.intf
.dest_prefix
);
1536 bool dplane_ctx_intf_has_label(const struct zebra_dplane_ctx
*ctx
)
1538 DPLANE_CTX_VALID(ctx
);
1540 return (ctx
->u
.intf
.flags
& DPLANE_INTF_HAS_LABEL
);
1543 const char *dplane_ctx_get_intf_label(const struct zebra_dplane_ctx
*ctx
)
1545 DPLANE_CTX_VALID(ctx
);
1547 return ctx
->u
.intf
.label
;
1550 /* Accessors for MAC information */
1551 vlanid_t
dplane_ctx_mac_get_vlan(const struct zebra_dplane_ctx
*ctx
)
1553 DPLANE_CTX_VALID(ctx
);
1554 return ctx
->u
.macinfo
.vid
;
1557 bool dplane_ctx_mac_is_sticky(const struct zebra_dplane_ctx
*ctx
)
1559 DPLANE_CTX_VALID(ctx
);
1560 return ctx
->u
.macinfo
.is_sticky
;
1563 uint32_t dplane_ctx_mac_get_nhg_id(const struct zebra_dplane_ctx
*ctx
)
1565 DPLANE_CTX_VALID(ctx
);
1566 return ctx
->u
.macinfo
.nhg_id
;
1569 uint32_t dplane_ctx_mac_get_update_flags(const struct zebra_dplane_ctx
*ctx
)
1571 DPLANE_CTX_VALID(ctx
);
1572 return ctx
->u
.macinfo
.update_flags
;
1575 const struct ethaddr
*dplane_ctx_mac_get_addr(
1576 const struct zebra_dplane_ctx
*ctx
)
1578 DPLANE_CTX_VALID(ctx
);
1579 return &(ctx
->u
.macinfo
.mac
);
1582 const struct in_addr
*dplane_ctx_mac_get_vtep_ip(
1583 const struct zebra_dplane_ctx
*ctx
)
1585 DPLANE_CTX_VALID(ctx
);
1586 return &(ctx
->u
.macinfo
.vtep_ip
);
1589 ifindex_t
dplane_ctx_mac_get_br_ifindex(const struct zebra_dplane_ctx
*ctx
)
1591 DPLANE_CTX_VALID(ctx
);
1592 return ctx
->u
.macinfo
.br_ifindex
;
1595 /* Accessors for neighbor information */
1596 const struct ipaddr
*dplane_ctx_neigh_get_ipaddr(
1597 const struct zebra_dplane_ctx
*ctx
)
1599 DPLANE_CTX_VALID(ctx
);
1600 return &(ctx
->u
.neigh
.ip_addr
);
1603 const struct ethaddr
*dplane_ctx_neigh_get_mac(
1604 const struct zebra_dplane_ctx
*ctx
)
1606 DPLANE_CTX_VALID(ctx
);
1607 return &(ctx
->u
.neigh
.mac
);
1610 uint32_t dplane_ctx_neigh_get_flags(const struct zebra_dplane_ctx
*ctx
)
1612 DPLANE_CTX_VALID(ctx
);
1613 return ctx
->u
.neigh
.flags
;
1616 uint16_t dplane_ctx_neigh_get_state(const struct zebra_dplane_ctx
*ctx
)
1618 DPLANE_CTX_VALID(ctx
);
1619 return ctx
->u
.neigh
.state
;
1622 uint32_t dplane_ctx_neigh_get_update_flags(const struct zebra_dplane_ctx
*ctx
)
1624 DPLANE_CTX_VALID(ctx
);
1625 return ctx
->u
.neigh
.update_flags
;
1628 /* Accessors for PBR rule information */
1629 int dplane_ctx_rule_get_sock(const struct zebra_dplane_ctx
*ctx
)
1631 DPLANE_CTX_VALID(ctx
);
1633 return ctx
->u
.rule
.sock
;
1636 const char *dplane_ctx_rule_get_ifname(const struct zebra_dplane_ctx
*ctx
)
1638 DPLANE_CTX_VALID(ctx
);
1640 return ctx
->u
.rule
.new.ifname
;
1643 int dplane_ctx_rule_get_unique(const struct zebra_dplane_ctx
*ctx
)
1645 DPLANE_CTX_VALID(ctx
);
1647 return ctx
->u
.rule
.unique
;
1650 int dplane_ctx_rule_get_seq(const struct zebra_dplane_ctx
*ctx
)
1652 DPLANE_CTX_VALID(ctx
);
1654 return ctx
->u
.rule
.seq
;
1657 uint32_t dplane_ctx_rule_get_priority(const struct zebra_dplane_ctx
*ctx
)
1659 DPLANE_CTX_VALID(ctx
);
1661 return ctx
->u
.rule
.new.priority
;
1664 uint32_t dplane_ctx_rule_get_old_priority(const struct zebra_dplane_ctx
*ctx
)
1666 DPLANE_CTX_VALID(ctx
);
1668 return ctx
->u
.rule
.old
.priority
;
1671 uint32_t dplane_ctx_rule_get_table(const struct zebra_dplane_ctx
*ctx
)
1673 DPLANE_CTX_VALID(ctx
);
1675 return ctx
->u
.rule
.new.table
;
1678 uint32_t dplane_ctx_rule_get_old_table(const struct zebra_dplane_ctx
*ctx
)
1680 DPLANE_CTX_VALID(ctx
);
1682 return ctx
->u
.rule
.old
.table
;
1685 uint32_t dplane_ctx_rule_get_filter_bm(const struct zebra_dplane_ctx
*ctx
)
1687 DPLANE_CTX_VALID(ctx
);
1689 return ctx
->u
.rule
.new.filter_bm
;
1692 uint32_t dplane_ctx_rule_get_old_filter_bm(const struct zebra_dplane_ctx
*ctx
)
1694 DPLANE_CTX_VALID(ctx
);
1696 return ctx
->u
.rule
.old
.filter_bm
;
1699 uint32_t dplane_ctx_rule_get_fwmark(const struct zebra_dplane_ctx
*ctx
)
1701 DPLANE_CTX_VALID(ctx
);
1703 return ctx
->u
.rule
.new.fwmark
;
1706 uint32_t dplane_ctx_rule_get_old_fwmark(const struct zebra_dplane_ctx
*ctx
)
1708 DPLANE_CTX_VALID(ctx
);
1710 return ctx
->u
.rule
.old
.fwmark
;
1713 uint8_t dplane_ctx_rule_get_dsfield(const struct zebra_dplane_ctx
*ctx
)
1715 DPLANE_CTX_VALID(ctx
);
1717 return ctx
->u
.rule
.new.dsfield
;
1720 uint8_t dplane_ctx_rule_get_old_dsfield(const struct zebra_dplane_ctx
*ctx
)
1722 DPLANE_CTX_VALID(ctx
);
1724 return ctx
->u
.rule
.old
.dsfield
;
1727 const struct prefix
*
1728 dplane_ctx_rule_get_src_ip(const struct zebra_dplane_ctx
*ctx
)
1730 DPLANE_CTX_VALID(ctx
);
1732 return &(ctx
->u
.rule
.new.src_ip
);
1735 const struct prefix
*
1736 dplane_ctx_rule_get_old_src_ip(const struct zebra_dplane_ctx
*ctx
)
1738 DPLANE_CTX_VALID(ctx
);
1740 return &(ctx
->u
.rule
.old
.src_ip
);
1743 const struct prefix
*
1744 dplane_ctx_rule_get_dst_ip(const struct zebra_dplane_ctx
*ctx
)
1746 DPLANE_CTX_VALID(ctx
);
1748 return &(ctx
->u
.rule
.new.dst_ip
);
1751 const struct prefix
*
1752 dplane_ctx_rule_get_old_dst_ip(const struct zebra_dplane_ctx
*ctx
)
1754 DPLANE_CTX_VALID(ctx
);
1756 return &(ctx
->u
.rule
.old
.dst_ip
);
1760 * End of dplane context accessors
1765 * Retrieve the limit on the number of pending, unprocessed updates.
1767 uint32_t dplane_get_in_queue_limit(void)
1769 return atomic_load_explicit(&zdplane_info
.dg_max_queued_updates
,
1770 memory_order_relaxed
);
1774 * Configure limit on the number of pending, queued updates.
1776 void dplane_set_in_queue_limit(uint32_t limit
, bool set
)
1778 /* Reset to default on 'unset' */
1780 limit
= DPLANE_DEFAULT_MAX_QUEUED
;
1782 atomic_store_explicit(&zdplane_info
.dg_max_queued_updates
, limit
,
1783 memory_order_relaxed
);
1787 * Retrieve the current queue depth of incoming, unprocessed updates
1789 uint32_t dplane_get_in_queue_len(void)
1791 return atomic_load_explicit(&zdplane_info
.dg_routes_queued
,
1792 memory_order_seq_cst
);
1796 * Common dataplane context init with zebra namespace info.
1798 static int dplane_ctx_ns_init(struct zebra_dplane_ctx
*ctx
,
1799 struct zebra_ns
*zns
,
1802 dplane_info_from_zns(&(ctx
->zd_ns_info
), zns
);
1804 #if defined(HAVE_NETLINK)
1805 /* Increment message counter after copying to context struct - may need
1806 * two messages in some 'update' cases.
1809 zns
->netlink_dplane
.seq
+= 2;
1811 zns
->netlink_dplane
.seq
++;
1812 #endif /* HAVE_NETLINK */
1818 * Initialize a context block for a route update from zebra data structs.
1820 int dplane_ctx_route_init(struct zebra_dplane_ctx
*ctx
, enum dplane_op_e op
,
1821 struct route_node
*rn
, struct route_entry
*re
)
1824 const struct route_table
*table
= NULL
;
1825 const struct rib_table_info
*info
;
1826 const struct prefix
*p
, *src_p
;
1827 struct zebra_ns
*zns
;
1828 struct zebra_vrf
*zvrf
;
1829 struct nexthop
*nexthop
;
1830 zebra_l3vni_t
*zl3vni
;
1832 if (!ctx
|| !rn
|| !re
)
1836 ctx
->zd_status
= ZEBRA_DPLANE_REQUEST_SUCCESS
;
1838 ctx
->u
.rinfo
.zd_type
= re
->type
;
1839 ctx
->u
.rinfo
.zd_old_type
= re
->type
;
1841 /* Prefixes: dest, and optional source */
1842 srcdest_rnode_prefixes(rn
, &p
, &src_p
);
1844 prefix_copy(&(ctx
->u
.rinfo
.zd_dest
), p
);
1847 prefix_copy(&(ctx
->u
.rinfo
.zd_src
), src_p
);
1849 memset(&(ctx
->u
.rinfo
.zd_src
), 0, sizeof(ctx
->u
.rinfo
.zd_src
));
1851 ctx
->zd_table_id
= re
->table
;
1853 ctx
->u
.rinfo
.zd_metric
= re
->metric
;
1854 ctx
->u
.rinfo
.zd_old_metric
= re
->metric
;
1855 ctx
->zd_vrf_id
= re
->vrf_id
;
1856 ctx
->u
.rinfo
.zd_mtu
= re
->mtu
;
1857 ctx
->u
.rinfo
.zd_nexthop_mtu
= re
->nexthop_mtu
;
1858 ctx
->u
.rinfo
.zd_instance
= re
->instance
;
1859 ctx
->u
.rinfo
.zd_tag
= re
->tag
;
1860 ctx
->u
.rinfo
.zd_old_tag
= re
->tag
;
1861 ctx
->u
.rinfo
.zd_distance
= re
->distance
;
1863 table
= srcdest_rnode_table(rn
);
1866 ctx
->u
.rinfo
.zd_afi
= info
->afi
;
1867 ctx
->u
.rinfo
.zd_safi
= info
->safi
;
1869 /* Copy nexthops; recursive info is included too */
1870 copy_nexthops(&(ctx
->u
.rinfo
.zd_ng
.nexthop
),
1871 re
->nhe
->nhg
.nexthop
, NULL
);
1872 ctx
->u
.rinfo
.zd_nhg_id
= re
->nhe
->id
;
1874 /* Copy backup nexthop info, if present */
1875 if (re
->nhe
->backup_info
&& re
->nhe
->backup_info
->nhe
) {
1876 copy_nexthops(&(ctx
->u
.rinfo
.backup_ng
.nexthop
),
1877 re
->nhe
->backup_info
->nhe
->nhg
.nexthop
, NULL
);
1881 * Ensure that the dplane nexthops' flags are clear and copy
1882 * encapsulation information.
1884 for (ALL_NEXTHOPS(ctx
->u
.rinfo
.zd_ng
, nexthop
)) {
1885 UNSET_FLAG(nexthop
->flags
, NEXTHOP_FLAG_FIB
);
1887 /* Check for available encapsulations. */
1888 if (!CHECK_FLAG(re
->flags
, ZEBRA_FLAG_EVPN_ROUTE
))
1891 zl3vni
= zl3vni_from_vrf(nexthop
->vrf_id
);
1892 if (zl3vni
&& is_l3vni_oper_up(zl3vni
)) {
1893 nexthop
->nh_encap_type
= NET_VXLAN
;
1894 nexthop
->nh_encap
.vni
= zl3vni
->vni
;
1898 /* Don't need some info when capturing a system notification */
1899 if (op
== DPLANE_OP_SYS_ROUTE_ADD
||
1900 op
== DPLANE_OP_SYS_ROUTE_DELETE
) {
1905 /* Extract ns info - can't use pointers to 'core' structs */
1906 zvrf
= vrf_info_lookup(re
->vrf_id
);
1908 dplane_ctx_ns_init(ctx
, zns
, (op
== DPLANE_OP_ROUTE_UPDATE
));
1912 struct nhg_hash_entry
*nhe
= zebra_nhg_resolve(re
->nhe
);
1914 ctx
->u
.rinfo
.nhe
.id
= nhe
->id
;
1916 * Check if the nhe is installed/queued before doing anything
1919 * If its a delete we only use the prefix anyway, so this only
1920 * matters for INSTALL/UPDATE.
1922 if (zebra_nhg_kernel_nexthops_enabled()
1923 && (((op
== DPLANE_OP_ROUTE_INSTALL
)
1924 || (op
== DPLANE_OP_ROUTE_UPDATE
))
1925 && !CHECK_FLAG(nhe
->flags
, NEXTHOP_GROUP_INSTALLED
)
1926 && !CHECK_FLAG(nhe
->flags
, NEXTHOP_GROUP_QUEUED
))) {
1931 #endif /* HAVE_NETLINK */
1933 /* Trying out the sequence number idea, so we can try to detect
1934 * when a result is stale.
1936 re
->dplane_sequence
= zebra_router_get_next_sequence();
1937 ctx
->zd_seq
= re
->dplane_sequence
;
1946 * dplane_ctx_nexthop_init() - Initialize a context block for a nexthop update
1948 * @ctx: Dataplane context to init
1949 * @op: Operation being performed
1950 * @nhe: Nexthop group hash entry
1952 * Return: Result status
1954 int dplane_ctx_nexthop_init(struct zebra_dplane_ctx
*ctx
, enum dplane_op_e op
,
1955 struct nhg_hash_entry
*nhe
)
1957 struct zebra_vrf
*zvrf
= NULL
;
1958 struct zebra_ns
*zns
= NULL
;
1965 ctx
->zd_status
= ZEBRA_DPLANE_REQUEST_SUCCESS
;
1967 /* Copy over nhe info */
1968 ctx
->u
.rinfo
.nhe
.id
= nhe
->id
;
1969 ctx
->u
.rinfo
.nhe
.afi
= nhe
->afi
;
1970 ctx
->u
.rinfo
.nhe
.vrf_id
= nhe
->vrf_id
;
1971 ctx
->u
.rinfo
.nhe
.type
= nhe
->type
;
1973 nexthop_group_copy(&(ctx
->u
.rinfo
.nhe
.ng
), &(nhe
->nhg
));
1975 /* If this is a group, convert it to a grp array of ids */
1976 if (!zebra_nhg_depends_is_empty(nhe
)
1977 && !CHECK_FLAG(nhe
->flags
, NEXTHOP_GROUP_RECURSIVE
))
1978 ctx
->u
.rinfo
.nhe
.nh_grp_count
= zebra_nhg_nhe2grp(
1979 ctx
->u
.rinfo
.nhe
.nh_grp
, nhe
, MULTIPATH_NUM
);
1981 zvrf
= vrf_info_lookup(nhe
->vrf_id
);
1984 * Fallback to default namespace if the vrf got ripped out from under
1987 zns
= zvrf
? zvrf
->zns
: zebra_ns_lookup(NS_DEFAULT
);
1990 * TODO: Might not need to mark this as an update, since
1991 * it probably won't require two messages
1993 dplane_ctx_ns_init(ctx
, zns
, (op
== DPLANE_OP_NH_UPDATE
));
1994 ctx
->zd_is_update
= (op
== DPLANE_OP_NH_UPDATE
);
2003 * Capture information for an LSP update in a dplane context.
2005 int dplane_ctx_lsp_init(struct zebra_dplane_ctx
*ctx
, enum dplane_op_e op
,
2009 zebra_nhlfe_t
*nhlfe
, *new_nhlfe
;
2012 ctx
->zd_status
= ZEBRA_DPLANE_REQUEST_SUCCESS
;
2014 /* Capture namespace info */
2015 dplane_ctx_ns_init(ctx
, zebra_ns_lookup(NS_DEFAULT
),
2016 (op
== DPLANE_OP_LSP_UPDATE
));
2017 ctx
->zd_is_update
= (op
== DPLANE_OP_LSP_UPDATE
);
2019 memset(&ctx
->u
.lsp
, 0, sizeof(ctx
->u
.lsp
));
2021 nhlfe_list_init(&(ctx
->u
.lsp
.nhlfe_list
));
2022 nhlfe_list_init(&(ctx
->u
.lsp
.backup_nhlfe_list
));
2024 /* This may be called to create/init a dplane context, not necessarily
2025 * to copy an lsp object.
2032 if (IS_ZEBRA_DEBUG_DPLANE_DETAIL
)
2033 zlog_debug("init dplane ctx %s: in-label %u ecmp# %d",
2034 dplane_op2str(op
), lsp
->ile
.in_label
,
2037 ctx
->u
.lsp
.ile
= lsp
->ile
;
2038 ctx
->u
.lsp
.addr_family
= lsp
->addr_family
;
2039 ctx
->u
.lsp
.num_ecmp
= lsp
->num_ecmp
;
2040 ctx
->u
.lsp
.flags
= lsp
->flags
;
2042 /* Copy source LSP's nhlfes, and capture 'best' nhlfe */
2043 frr_each(nhlfe_list
, &lsp
->nhlfe_list
, nhlfe
) {
2044 /* Not sure if this is meaningful... */
2045 if (nhlfe
->nexthop
== NULL
)
2048 new_nhlfe
= zebra_mpls_lsp_add_nh(&(ctx
->u
.lsp
), nhlfe
->type
,
2050 if (new_nhlfe
== NULL
|| new_nhlfe
->nexthop
== NULL
) {
2055 /* Need to copy flags and backup info too */
2056 new_nhlfe
->flags
= nhlfe
->flags
;
2057 new_nhlfe
->nexthop
->flags
= nhlfe
->nexthop
->flags
;
2059 if (CHECK_FLAG(new_nhlfe
->nexthop
->flags
,
2060 NEXTHOP_FLAG_HAS_BACKUP
)) {
2061 new_nhlfe
->nexthop
->backup_num
=
2062 nhlfe
->nexthop
->backup_num
;
2063 memcpy(new_nhlfe
->nexthop
->backup_idx
,
2064 nhlfe
->nexthop
->backup_idx
,
2065 new_nhlfe
->nexthop
->backup_num
);
2068 if (nhlfe
== lsp
->best_nhlfe
)
2069 ctx
->u
.lsp
.best_nhlfe
= new_nhlfe
;
2075 /* Capture backup nhlfes/nexthops */
2076 frr_each(nhlfe_list
, &lsp
->backup_nhlfe_list
, nhlfe
) {
2077 /* Not sure if this is meaningful... */
2078 if (nhlfe
->nexthop
== NULL
)
2081 new_nhlfe
= zebra_mpls_lsp_add_backup_nh(&(ctx
->u
.lsp
),
2084 if (new_nhlfe
== NULL
|| new_nhlfe
->nexthop
== NULL
) {
2089 /* Need to copy flags too */
2090 new_nhlfe
->flags
= nhlfe
->flags
;
2091 new_nhlfe
->nexthop
->flags
= nhlfe
->nexthop
->flags
;
2094 /* On error the ctx will be cleaned-up, so we don't need to
2095 * deal with any allocated nhlfe or nexthop structs here.
2103 * Capture information for an LSP update in a dplane context.
2105 static int dplane_ctx_pw_init(struct zebra_dplane_ctx
*ctx
,
2106 enum dplane_op_e op
,
2107 struct zebra_pw
*pw
)
2111 struct route_table
*table
;
2112 struct route_node
*rn
;
2113 struct route_entry
*re
;
2114 const struct nexthop_group
*nhg
;
2116 if (IS_ZEBRA_DEBUG_DPLANE_DETAIL
)
2117 zlog_debug("init dplane ctx %s: pw '%s', loc %u, rem %u",
2118 dplane_op2str(op
), pw
->ifname
, pw
->local_label
,
2122 ctx
->zd_status
= ZEBRA_DPLANE_REQUEST_SUCCESS
;
2124 /* Capture namespace info: no netlink support as of 12/18,
2125 * but just in case...
2127 dplane_ctx_ns_init(ctx
, zebra_ns_lookup(NS_DEFAULT
), false);
2129 memset(&ctx
->u
.pw
, 0, sizeof(ctx
->u
.pw
));
2131 /* This name appears to be c-string, so we use string copy. */
2132 strlcpy(ctx
->zd_ifname
, pw
->ifname
, sizeof(ctx
->zd_ifname
));
2134 ctx
->zd_vrf_id
= pw
->vrf_id
;
2135 ctx
->zd_ifindex
= pw
->ifindex
;
2136 ctx
->u
.pw
.type
= pw
->type
;
2137 ctx
->u
.pw
.af
= pw
->af
;
2138 ctx
->u
.pw
.local_label
= pw
->local_label
;
2139 ctx
->u
.pw
.remote_label
= pw
->remote_label
;
2140 ctx
->u
.pw
.flags
= pw
->flags
;
2142 ctx
->u
.pw
.dest
= pw
->nexthop
;
2144 ctx
->u
.pw
.fields
= pw
->data
;
2146 /* Capture nexthop info for the pw destination. We need to look
2147 * up and use zebra datastructs, but we're running in the zebra
2148 * pthread here so that should be ok.
2150 memcpy(&p
.u
, &pw
->nexthop
, sizeof(pw
->nexthop
));
2152 p
.prefixlen
= ((pw
->af
== AF_INET
) ?
2153 IPV4_MAX_PREFIXLEN
: IPV6_MAX_PREFIXLEN
);
2155 afi
= (pw
->af
== AF_INET
) ? AFI_IP
: AFI_IP6
;
2156 table
= zebra_vrf_table(afi
, SAFI_UNICAST
, pw
->vrf_id
);
2158 rn
= route_node_match(table
, &p
);
2160 RNODE_FOREACH_RE(rn
, re
) {
2161 if (CHECK_FLAG(re
->flags
, ZEBRA_FLAG_SELECTED
))
2166 nhg
= rib_get_fib_nhg(re
);
2167 if (nhg
&& nhg
->nexthop
)
2168 copy_nexthops(&(ctx
->u
.pw
.nhg
.nexthop
),
2169 nhg
->nexthop
, NULL
);
2171 /* Include any installed backup nexthops */
2172 nhg
= rib_get_fib_backup_nhg(re
);
2173 if (nhg
&& nhg
->nexthop
)
2174 copy_nexthops(&(ctx
->u
.pw
.nhg
.nexthop
),
2175 nhg
->nexthop
, NULL
);
2177 route_unlock_node(rn
);
2185 * dplane_ctx_rule_init_single() - Initialize a dataplane representation of a
2188 * @dplane_rule: Dataplane internal representation of a rule
2191 static void dplane_ctx_rule_init_single(struct dplane_ctx_rule
*dplane_rule
,
2192 struct zebra_pbr_rule
*rule
)
2194 dplane_rule
->priority
= rule
->rule
.priority
;
2195 dplane_rule
->table
= rule
->rule
.action
.table
;
2197 dplane_rule
->filter_bm
= rule
->rule
.filter
.filter_bm
;
2198 dplane_rule
->fwmark
= rule
->rule
.filter
.fwmark
;
2199 dplane_rule
->dsfield
= rule
->rule
.filter
.dsfield
;
2200 prefix_copy(&(dplane_rule
->dst_ip
), &rule
->rule
.filter
.dst_ip
);
2201 prefix_copy(&(dplane_rule
->src_ip
), &rule
->rule
.filter
.src_ip
);
2202 strlcpy(dplane_rule
->ifname
, rule
->ifname
, INTERFACE_NAMSIZ
);
2206 * dplane_ctx_rule_init() - Initialize a context block for a PBR rule update.
2208 * @ctx: Dataplane context to init
2209 * @op: Operation being performed
2210 * @new_rule: PBR rule
2212 * Return: Result status
2214 static int dplane_ctx_rule_init(struct zebra_dplane_ctx
*ctx
,
2215 enum dplane_op_e op
,
2216 struct zebra_pbr_rule
*new_rule
,
2217 struct zebra_pbr_rule
*old_rule
)
2219 if (IS_ZEBRA_DEBUG_DPLANE_DETAIL
) {
2220 char buf1
[PREFIX_STRLEN
];
2221 char buf2
[PREFIX_STRLEN
];
2224 "init dplane ctx %s: IF %s Prio %u Fwmark %u Src %s Dst %s Table %u",
2225 dplane_op2str(op
), new_rule
->ifname
,
2226 new_rule
->rule
.priority
, new_rule
->rule
.filter
.fwmark
,
2227 prefix2str(&new_rule
->rule
.filter
.src_ip
, buf1
,
2229 prefix2str(&new_rule
->rule
.filter
.dst_ip
, buf2
,
2231 new_rule
->rule
.action
.table
);
2235 ctx
->zd_status
= ZEBRA_DPLANE_REQUEST_SUCCESS
;
2237 dplane_ctx_ns_init(ctx
, zebra_ns_lookup(NS_DEFAULT
),
2238 op
== DPLANE_OP_RULE_UPDATE
);
2239 ctx
->zd_is_update
= (op
== DPLANE_OP_RULE_UPDATE
);
2241 ctx
->zd_vrf_id
= new_rule
->vrf_id
;
2242 memcpy(ctx
->zd_ifname
, new_rule
->ifname
, sizeof(new_rule
->ifname
));
2244 ctx
->u
.rule
.sock
= new_rule
->sock
;
2245 ctx
->u
.rule
.unique
= new_rule
->rule
.unique
;
2246 ctx
->u
.rule
.seq
= new_rule
->rule
.seq
;
2248 dplane_ctx_rule_init_single(&ctx
->u
.rule
.new, new_rule
);
2249 if (op
== DPLANE_OP_RULE_UPDATE
)
2250 dplane_ctx_rule_init_single(&ctx
->u
.rule
.old
, old_rule
);
2256 * Enqueue a new update,
2257 * and ensure an event is active for the dataplane pthread.
2259 static int dplane_update_enqueue(struct zebra_dplane_ctx
*ctx
)
2262 uint32_t high
, curr
;
2264 /* Enqueue for processing by the dataplane pthread */
2267 TAILQ_INSERT_TAIL(&zdplane_info
.dg_update_ctx_q
, ctx
,
2272 curr
= atomic_fetch_add_explicit(
2273 &(zdplane_info
.dg_routes_queued
),
2274 1, memory_order_seq_cst
);
2276 curr
++; /* We got the pre-incremented value */
2278 /* Maybe update high-water counter also */
2279 high
= atomic_load_explicit(&zdplane_info
.dg_routes_queued_max
,
2280 memory_order_seq_cst
);
2281 while (high
< curr
) {
2282 if (atomic_compare_exchange_weak_explicit(
2283 &zdplane_info
.dg_routes_queued_max
,
2285 memory_order_seq_cst
,
2286 memory_order_seq_cst
))
2290 /* Ensure that an event for the dataplane thread is active */
2291 ret
= dplane_provider_work_ready();
2297 * Utility that prepares a route update and enqueues it for processing
2299 static enum zebra_dplane_result
2300 dplane_route_update_internal(struct route_node
*rn
,
2301 struct route_entry
*re
,
2302 struct route_entry
*old_re
,
2303 enum dplane_op_e op
)
2305 enum zebra_dplane_result result
= ZEBRA_DPLANE_REQUEST_FAILURE
;
2307 struct zebra_dplane_ctx
*ctx
= NULL
;
2309 /* Obtain context block */
2310 ctx
= dplane_ctx_alloc();
2312 /* Init context with info from zebra data structs */
2313 ret
= dplane_ctx_route_init(ctx
, op
, rn
, re
);
2315 /* Capture some extra info for update case
2316 * where there's a different 'old' route.
2318 if ((op
== DPLANE_OP_ROUTE_UPDATE
) &&
2319 old_re
&& (old_re
!= re
)) {
2320 ctx
->zd_is_update
= true;
2322 old_re
->dplane_sequence
=
2323 zebra_router_get_next_sequence();
2324 ctx
->zd_old_seq
= old_re
->dplane_sequence
;
2326 ctx
->u
.rinfo
.zd_old_tag
= old_re
->tag
;
2327 ctx
->u
.rinfo
.zd_old_type
= old_re
->type
;
2328 ctx
->u
.rinfo
.zd_old_instance
= old_re
->instance
;
2329 ctx
->u
.rinfo
.zd_old_distance
= old_re
->distance
;
2330 ctx
->u
.rinfo
.zd_old_metric
= old_re
->metric
;
2332 #ifndef HAVE_NETLINK
2333 /* For bsd, capture previous re's nexthops too, sigh.
2334 * We'll need these to do per-nexthop deletes.
2336 copy_nexthops(&(ctx
->u
.rinfo
.zd_old_ng
.nexthop
),
2337 old_re
->nhe
->nhg
.nexthop
, NULL
);
2339 if (zebra_nhg_get_backup_nhg(old_re
->nhe
) != NULL
) {
2340 struct nexthop_group
*nhg
;
2341 struct nexthop
**nh
;
2343 nhg
= zebra_nhg_get_backup_nhg(old_re
->nhe
);
2344 nh
= &(ctx
->u
.rinfo
.old_backup_ng
.nexthop
);
2347 copy_nexthops(nh
, nhg
->nexthop
, NULL
);
2349 #endif /* !HAVE_NETLINK */
2352 /* Enqueue context for processing */
2353 ret
= dplane_update_enqueue(ctx
);
2356 /* Update counter */
2357 atomic_fetch_add_explicit(&zdplane_info
.dg_routes_in
, 1,
2358 memory_order_relaxed
);
2361 result
= ZEBRA_DPLANE_REQUEST_QUEUED
;
2363 atomic_fetch_add_explicit(&zdplane_info
.dg_route_errors
, 1,
2364 memory_order_relaxed
);
2366 dplane_ctx_free(&ctx
);
2373 * dplane_nexthop_update_internal() - Helper for enqueuing nexthop changes
2375 * @nhe: Nexthop group hash entry where the change occured
2376 * @op: The operation to be enqued
2378 * Return: Result of the change
2380 static enum zebra_dplane_result
2381 dplane_nexthop_update_internal(struct nhg_hash_entry
*nhe
, enum dplane_op_e op
)
2383 enum zebra_dplane_result result
= ZEBRA_DPLANE_REQUEST_FAILURE
;
2385 struct zebra_dplane_ctx
*ctx
= NULL
;
2387 /* Obtain context block */
2388 ctx
= dplane_ctx_alloc();
2394 ret
= dplane_ctx_nexthop_init(ctx
, op
, nhe
);
2396 ret
= dplane_update_enqueue(ctx
);
2399 /* Update counter */
2400 atomic_fetch_add_explicit(&zdplane_info
.dg_nexthops_in
, 1,
2401 memory_order_relaxed
);
2404 result
= ZEBRA_DPLANE_REQUEST_QUEUED
;
2406 atomic_fetch_add_explicit(&zdplane_info
.dg_nexthop_errors
, 1,
2407 memory_order_relaxed
);
2409 dplane_ctx_free(&ctx
);
2416 * Enqueue a route 'add' for the dataplane.
2418 enum zebra_dplane_result
dplane_route_add(struct route_node
*rn
,
2419 struct route_entry
*re
)
2421 enum zebra_dplane_result ret
= ZEBRA_DPLANE_REQUEST_FAILURE
;
2423 if (rn
== NULL
|| re
== NULL
)
2426 ret
= dplane_route_update_internal(rn
, re
, NULL
,
2427 DPLANE_OP_ROUTE_INSTALL
);
2434 * Enqueue a route update for the dataplane.
2436 enum zebra_dplane_result
dplane_route_update(struct route_node
*rn
,
2437 struct route_entry
*re
,
2438 struct route_entry
*old_re
)
2440 enum zebra_dplane_result ret
= ZEBRA_DPLANE_REQUEST_FAILURE
;
2442 if (rn
== NULL
|| re
== NULL
)
2445 ret
= dplane_route_update_internal(rn
, re
, old_re
,
2446 DPLANE_OP_ROUTE_UPDATE
);
2452 * Enqueue a route removal for the dataplane.
2454 enum zebra_dplane_result
dplane_route_delete(struct route_node
*rn
,
2455 struct route_entry
*re
)
2457 enum zebra_dplane_result ret
= ZEBRA_DPLANE_REQUEST_FAILURE
;
2459 if (rn
== NULL
|| re
== NULL
)
2462 ret
= dplane_route_update_internal(rn
, re
, NULL
,
2463 DPLANE_OP_ROUTE_DELETE
);
2470 * Notify the dplane when system/connected routes change.
2472 enum zebra_dplane_result
dplane_sys_route_add(struct route_node
*rn
,
2473 struct route_entry
*re
)
2475 enum zebra_dplane_result ret
= ZEBRA_DPLANE_REQUEST_FAILURE
;
2477 /* Ignore this event unless a provider plugin has requested it. */
2478 if (!zdplane_info
.dg_sys_route_notifs
) {
2479 ret
= ZEBRA_DPLANE_REQUEST_SUCCESS
;
2483 if (rn
== NULL
|| re
== NULL
)
2486 ret
= dplane_route_update_internal(rn
, re
, NULL
,
2487 DPLANE_OP_SYS_ROUTE_ADD
);
2494 * Notify the dplane when system/connected routes are deleted.
2496 enum zebra_dplane_result
dplane_sys_route_del(struct route_node
*rn
,
2497 struct route_entry
*re
)
2499 enum zebra_dplane_result ret
= ZEBRA_DPLANE_REQUEST_FAILURE
;
2501 /* Ignore this event unless a provider plugin has requested it. */
2502 if (!zdplane_info
.dg_sys_route_notifs
) {
2503 ret
= ZEBRA_DPLANE_REQUEST_SUCCESS
;
2507 if (rn
== NULL
|| re
== NULL
)
2510 ret
= dplane_route_update_internal(rn
, re
, NULL
,
2511 DPLANE_OP_SYS_ROUTE_DELETE
);
2518 * Update from an async notification, to bring other fibs up-to-date.
2520 enum zebra_dplane_result
2521 dplane_route_notif_update(struct route_node
*rn
,
2522 struct route_entry
*re
,
2523 enum dplane_op_e op
,
2524 struct zebra_dplane_ctx
*ctx
)
2526 enum zebra_dplane_result result
= ZEBRA_DPLANE_REQUEST_FAILURE
;
2528 struct zebra_dplane_ctx
*new_ctx
= NULL
;
2529 struct nexthop
*nexthop
;
2530 struct nexthop_group
*nhg
;
2532 if (rn
== NULL
|| re
== NULL
)
2535 new_ctx
= dplane_ctx_alloc();
2536 if (new_ctx
== NULL
)
2539 /* Init context with info from zebra data structs */
2540 dplane_ctx_route_init(new_ctx
, op
, rn
, re
);
2542 /* For add/update, need to adjust the nexthops so that we match
2543 * the notification state, which may not be the route-entry/RIB
2546 if (op
== DPLANE_OP_ROUTE_UPDATE
||
2547 op
== DPLANE_OP_ROUTE_INSTALL
) {
2549 nexthops_free(new_ctx
->u
.rinfo
.zd_ng
.nexthop
);
2550 new_ctx
->u
.rinfo
.zd_ng
.nexthop
= NULL
;
2552 nhg
= rib_get_fib_nhg(re
);
2553 if (nhg
&& nhg
->nexthop
)
2554 copy_nexthops(&(new_ctx
->u
.rinfo
.zd_ng
.nexthop
),
2555 nhg
->nexthop
, NULL
);
2557 /* Check for installed backup nexthops also */
2558 nhg
= rib_get_fib_backup_nhg(re
);
2559 if (nhg
&& nhg
->nexthop
) {
2560 copy_nexthops(&(new_ctx
->u
.rinfo
.zd_ng
.nexthop
),
2561 nhg
->nexthop
, NULL
);
2564 for (ALL_NEXTHOPS(new_ctx
->u
.rinfo
.zd_ng
, nexthop
))
2565 UNSET_FLAG(nexthop
->flags
, NEXTHOP_FLAG_FIB
);
2569 /* Capture info about the source of the notification, in 'ctx' */
2570 dplane_ctx_set_notif_provider(new_ctx
,
2571 dplane_ctx_get_notif_provider(ctx
));
2573 ret
= dplane_update_enqueue(new_ctx
);
2577 result
= ZEBRA_DPLANE_REQUEST_QUEUED
;
2579 dplane_ctx_free(&new_ctx
);
2585 * Enqueue a nexthop add for the dataplane.
2587 enum zebra_dplane_result
dplane_nexthop_add(struct nhg_hash_entry
*nhe
)
2589 enum zebra_dplane_result ret
= ZEBRA_DPLANE_REQUEST_FAILURE
;
2592 ret
= dplane_nexthop_update_internal(nhe
, DPLANE_OP_NH_INSTALL
);
2597 * Enqueue a nexthop update for the dataplane.
2599 * Might not need this func since zebra's nexthop objects should be immutable?
2601 enum zebra_dplane_result
dplane_nexthop_update(struct nhg_hash_entry
*nhe
)
2603 enum zebra_dplane_result ret
= ZEBRA_DPLANE_REQUEST_FAILURE
;
2606 ret
= dplane_nexthop_update_internal(nhe
, DPLANE_OP_NH_UPDATE
);
2611 * Enqueue a nexthop removal for the dataplane.
2613 enum zebra_dplane_result
dplane_nexthop_delete(struct nhg_hash_entry
*nhe
)
2615 enum zebra_dplane_result ret
= ZEBRA_DPLANE_REQUEST_FAILURE
;
2618 ret
= dplane_nexthop_update_internal(nhe
, DPLANE_OP_NH_DELETE
);
2624 * Enqueue LSP add for the dataplane.
2626 enum zebra_dplane_result
dplane_lsp_add(zebra_lsp_t
*lsp
)
2628 enum zebra_dplane_result ret
=
2629 lsp_update_internal(lsp
, DPLANE_OP_LSP_INSTALL
);
2635 * Enqueue LSP update for the dataplane.
2637 enum zebra_dplane_result
dplane_lsp_update(zebra_lsp_t
*lsp
)
2639 enum zebra_dplane_result ret
=
2640 lsp_update_internal(lsp
, DPLANE_OP_LSP_UPDATE
);
2646 * Enqueue LSP delete for the dataplane.
2648 enum zebra_dplane_result
dplane_lsp_delete(zebra_lsp_t
*lsp
)
2650 enum zebra_dplane_result ret
=
2651 lsp_update_internal(lsp
, DPLANE_OP_LSP_DELETE
);
2656 /* Update or un-install resulting from an async notification */
2657 enum zebra_dplane_result
2658 dplane_lsp_notif_update(zebra_lsp_t
*lsp
,
2659 enum dplane_op_e op
,
2660 struct zebra_dplane_ctx
*notif_ctx
)
2662 enum zebra_dplane_result result
= ZEBRA_DPLANE_REQUEST_FAILURE
;
2664 struct zebra_dplane_ctx
*ctx
= NULL
;
2665 struct nhlfe_list_head
*head
;
2666 zebra_nhlfe_t
*nhlfe
, *new_nhlfe
;
2668 /* Obtain context block */
2669 ctx
= dplane_ctx_alloc();
2675 /* Copy info from zebra LSP */
2676 ret
= dplane_ctx_lsp_init(ctx
, op
, lsp
);
2680 /* Add any installed backup nhlfes */
2681 head
= &(ctx
->u
.lsp
.backup_nhlfe_list
);
2682 frr_each(nhlfe_list
, head
, nhlfe
) {
2684 if (CHECK_FLAG(nhlfe
->flags
, NHLFE_FLAG_INSTALLED
) &&
2685 CHECK_FLAG(nhlfe
->nexthop
->flags
, NEXTHOP_FLAG_FIB
)) {
2686 new_nhlfe
= zebra_mpls_lsp_add_nh(&(ctx
->u
.lsp
),
2690 /* Need to copy flags too */
2691 new_nhlfe
->flags
= nhlfe
->flags
;
2692 new_nhlfe
->nexthop
->flags
= nhlfe
->nexthop
->flags
;
2696 /* Capture info about the source of the notification */
2697 dplane_ctx_set_notif_provider(
2699 dplane_ctx_get_notif_provider(notif_ctx
));
2701 ret
= dplane_update_enqueue(ctx
);
2704 /* Update counter */
2705 atomic_fetch_add_explicit(&zdplane_info
.dg_lsps_in
, 1,
2706 memory_order_relaxed
);
2709 result
= ZEBRA_DPLANE_REQUEST_QUEUED
;
2711 atomic_fetch_add_explicit(&zdplane_info
.dg_lsp_errors
, 1,
2712 memory_order_relaxed
);
2714 dplane_ctx_free(&ctx
);
2720 * Enqueue pseudowire install for the dataplane.
2722 enum zebra_dplane_result
dplane_pw_install(struct zebra_pw
*pw
)
2724 return pw_update_internal(pw
, DPLANE_OP_PW_INSTALL
);
2728 * Enqueue pseudowire un-install for the dataplane.
2730 enum zebra_dplane_result
dplane_pw_uninstall(struct zebra_pw
*pw
)
2732 return pw_update_internal(pw
, DPLANE_OP_PW_UNINSTALL
);
2736 * Common internal LSP update utility
2738 static enum zebra_dplane_result
lsp_update_internal(zebra_lsp_t
*lsp
,
2739 enum dplane_op_e op
)
2741 enum zebra_dplane_result result
= ZEBRA_DPLANE_REQUEST_FAILURE
;
2743 struct zebra_dplane_ctx
*ctx
= NULL
;
2745 /* Obtain context block */
2746 ctx
= dplane_ctx_alloc();
2748 ret
= dplane_ctx_lsp_init(ctx
, op
, lsp
);
2752 ret
= dplane_update_enqueue(ctx
);
2755 /* Update counter */
2756 atomic_fetch_add_explicit(&zdplane_info
.dg_lsps_in
, 1,
2757 memory_order_relaxed
);
2760 result
= ZEBRA_DPLANE_REQUEST_QUEUED
;
2762 atomic_fetch_add_explicit(&zdplane_info
.dg_lsp_errors
, 1,
2763 memory_order_relaxed
);
2764 dplane_ctx_free(&ctx
);
2771 * Internal, common handler for pseudowire updates.
2773 static enum zebra_dplane_result
pw_update_internal(struct zebra_pw
*pw
,
2774 enum dplane_op_e op
)
2776 enum zebra_dplane_result result
= ZEBRA_DPLANE_REQUEST_FAILURE
;
2778 struct zebra_dplane_ctx
*ctx
= NULL
;
2780 ctx
= dplane_ctx_alloc();
2782 ret
= dplane_ctx_pw_init(ctx
, op
, pw
);
2786 ret
= dplane_update_enqueue(ctx
);
2789 /* Update counter */
2790 atomic_fetch_add_explicit(&zdplane_info
.dg_pws_in
, 1,
2791 memory_order_relaxed
);
2794 result
= ZEBRA_DPLANE_REQUEST_QUEUED
;
2796 atomic_fetch_add_explicit(&zdplane_info
.dg_pw_errors
, 1,
2797 memory_order_relaxed
);
2798 dplane_ctx_free(&ctx
);
2805 * Enqueue interface address add for the dataplane.
2807 enum zebra_dplane_result
dplane_intf_addr_set(const struct interface
*ifp
,
2808 const struct connected
*ifc
)
2810 #if !defined(HAVE_NETLINK) && defined(HAVE_STRUCT_IFALIASREQ)
2811 /* Extra checks for this OS path. */
2813 /* Don't configure PtP addresses on broadcast ifs or reverse */
2814 if (!(ifp
->flags
& IFF_POINTOPOINT
) != !CONNECTED_PEER(ifc
)) {
2815 if (IS_ZEBRA_DEBUG_KERNEL
|| IS_ZEBRA_DEBUG_DPLANE
)
2816 zlog_debug("Failed to set intf addr: mismatch p2p and connected");
2818 return ZEBRA_DPLANE_REQUEST_FAILURE
;
2821 /* Ensure that no existing installed v4 route conflicts with
2822 * the new interface prefix. This check must be done in the
2823 * zebra pthread context, and any route delete (if needed)
2824 * is enqueued before the interface address programming attempt.
2826 if (ifc
->address
->family
== AF_INET
) {
2827 struct prefix_ipv4
*p
;
2829 p
= (struct prefix_ipv4
*)ifc
->address
;
2830 rib_lookup_and_pushup(p
, ifp
->vrf_id
);
2834 return intf_addr_update_internal(ifp
, ifc
, DPLANE_OP_ADDR_INSTALL
);
2838 * Enqueue interface address remove/uninstall for the dataplane.
2840 enum zebra_dplane_result
dplane_intf_addr_unset(const struct interface
*ifp
,
2841 const struct connected
*ifc
)
2843 return intf_addr_update_internal(ifp
, ifc
, DPLANE_OP_ADDR_UNINSTALL
);
2846 static enum zebra_dplane_result
intf_addr_update_internal(
2847 const struct interface
*ifp
, const struct connected
*ifc
,
2848 enum dplane_op_e op
)
2850 enum zebra_dplane_result result
= ZEBRA_DPLANE_REQUEST_FAILURE
;
2852 struct zebra_dplane_ctx
*ctx
= NULL
;
2853 struct zebra_ns
*zns
;
2855 if (IS_ZEBRA_DEBUG_DPLANE_DETAIL
) {
2856 char addr_str
[PREFIX_STRLEN
];
2858 prefix2str(ifc
->address
, addr_str
, sizeof(addr_str
));
2860 zlog_debug("init intf ctx %s: idx %d, addr %u:%s",
2861 dplane_op2str(op
), ifp
->ifindex
, ifp
->vrf_id
,
2865 ctx
= dplane_ctx_alloc();
2868 ctx
->zd_status
= ZEBRA_DPLANE_REQUEST_SUCCESS
;
2869 ctx
->zd_vrf_id
= ifp
->vrf_id
;
2871 zns
= zebra_ns_lookup(ifp
->vrf_id
);
2872 dplane_ctx_ns_init(ctx
, zns
, false);
2874 /* Init the interface-addr-specific area */
2875 memset(&ctx
->u
.intf
, 0, sizeof(ctx
->u
.intf
));
2877 strlcpy(ctx
->zd_ifname
, ifp
->name
, sizeof(ctx
->zd_ifname
));
2878 ctx
->zd_ifindex
= ifp
->ifindex
;
2879 ctx
->u
.intf
.prefix
= *(ifc
->address
);
2881 if (if_is_broadcast(ifp
))
2882 ctx
->u
.intf
.flags
|= DPLANE_INTF_BROADCAST
;
2884 if (CONNECTED_PEER(ifc
)) {
2885 ctx
->u
.intf
.dest_prefix
= *(ifc
->destination
);
2886 ctx
->u
.intf
.flags
|=
2887 (DPLANE_INTF_CONNECTED
| DPLANE_INTF_HAS_DEST
);
2890 if (CHECK_FLAG(ifc
->flags
, ZEBRA_IFA_SECONDARY
))
2891 ctx
->u
.intf
.flags
|= DPLANE_INTF_SECONDARY
;
2896 ctx
->u
.intf
.flags
|= DPLANE_INTF_HAS_LABEL
;
2898 /* Use embedded buffer if it's adequate; else allocate. */
2899 len
= strlen(ifc
->label
);
2901 if (len
< sizeof(ctx
->u
.intf
.label_buf
)) {
2902 strlcpy(ctx
->u
.intf
.label_buf
, ifc
->label
,
2903 sizeof(ctx
->u
.intf
.label_buf
));
2904 ctx
->u
.intf
.label
= ctx
->u
.intf
.label_buf
;
2906 ctx
->u
.intf
.label
= strdup(ifc
->label
);
2910 ret
= dplane_update_enqueue(ctx
);
2912 /* Increment counter */
2913 atomic_fetch_add_explicit(&zdplane_info
.dg_intf_addrs_in
, 1,
2914 memory_order_relaxed
);
2917 result
= ZEBRA_DPLANE_REQUEST_QUEUED
;
2920 atomic_fetch_add_explicit(&zdplane_info
.dg_intf_addr_errors
,
2921 1, memory_order_relaxed
);
2922 dplane_ctx_free(&ctx
);
2929 * Enqueue vxlan/evpn mac add (or update).
2931 enum zebra_dplane_result
dplane_rem_mac_add(const struct interface
*ifp
,
2932 const struct interface
*bridge_ifp
,
2934 const struct ethaddr
*mac
,
2935 struct in_addr vtep_ip
,
2940 enum zebra_dplane_result result
;
2941 uint32_t update_flags
= 0;
2943 update_flags
|= DPLANE_MAC_REMOTE
;
2945 update_flags
|= DPLANE_MAC_WAS_STATIC
;
2947 /* Use common helper api */
2948 result
= mac_update_common(DPLANE_OP_MAC_INSTALL
, ifp
, bridge_ifp
,
2949 vid
, mac
, vtep_ip
, sticky
, nhg_id
, update_flags
);
2954 * Enqueue vxlan/evpn mac delete.
2956 enum zebra_dplane_result
dplane_rem_mac_del(const struct interface
*ifp
,
2957 const struct interface
*bridge_ifp
,
2959 const struct ethaddr
*mac
,
2960 struct in_addr vtep_ip
)
2962 enum zebra_dplane_result result
;
2963 uint32_t update_flags
= 0;
2965 update_flags
|= DPLANE_MAC_REMOTE
;
2967 /* Use common helper api */
2968 result
= mac_update_common(DPLANE_OP_MAC_DELETE
, ifp
, bridge_ifp
,
2969 vid
, mac
, vtep_ip
, false, 0, update_flags
);
2974 * Enqueue local mac add (or update).
2976 enum zebra_dplane_result
dplane_local_mac_add(const struct interface
*ifp
,
2977 const struct interface
*bridge_ifp
,
2979 const struct ethaddr
*mac
,
2981 uint32_t set_static
,
2982 uint32_t set_inactive
)
2984 enum zebra_dplane_result result
;
2985 uint32_t update_flags
= 0;
2986 struct in_addr vtep_ip
;
2989 update_flags
|= DPLANE_MAC_SET_STATIC
;
2992 update_flags
|= DPLANE_MAC_SET_INACTIVE
;
2996 /* Use common helper api */
2997 result
= mac_update_common(DPLANE_OP_MAC_INSTALL
, ifp
, bridge_ifp
,
2998 vid
, mac
, vtep_ip
, sticky
, 0,
3004 * Public api to init an empty context - either newly-allocated or
3005 * reset/cleared - for a MAC update.
3007 void dplane_mac_init(struct zebra_dplane_ctx
*ctx
,
3008 const struct interface
*ifp
,
3009 const struct interface
*br_ifp
,
3011 const struct ethaddr
*mac
,
3012 struct in_addr vtep_ip
,
3015 uint32_t update_flags
)
3017 struct zebra_ns
*zns
;
3019 ctx
->zd_status
= ZEBRA_DPLANE_REQUEST_SUCCESS
;
3020 ctx
->zd_vrf_id
= ifp
->vrf_id
;
3022 zns
= zebra_ns_lookup(ifp
->vrf_id
);
3023 dplane_ctx_ns_init(ctx
, zns
, false);
3025 strlcpy(ctx
->zd_ifname
, ifp
->name
, sizeof(ctx
->zd_ifname
));
3026 ctx
->zd_ifindex
= ifp
->ifindex
;
3028 /* Init the mac-specific data area */
3029 memset(&ctx
->u
.macinfo
, 0, sizeof(ctx
->u
.macinfo
));
3031 ctx
->u
.macinfo
.br_ifindex
= br_ifp
->ifindex
;
3032 ctx
->u
.macinfo
.vtep_ip
= vtep_ip
;
3033 ctx
->u
.macinfo
.mac
= *mac
;
3034 ctx
->u
.macinfo
.vid
= vid
;
3035 ctx
->u
.macinfo
.is_sticky
= sticky
;
3036 ctx
->u
.macinfo
.nhg_id
= nhg_id
;
3037 ctx
->u
.macinfo
.update_flags
= update_flags
;
3041 * Common helper api for MAC address/vxlan updates
3043 static enum zebra_dplane_result
3044 mac_update_common(enum dplane_op_e op
,
3045 const struct interface
*ifp
,
3046 const struct interface
*br_ifp
,
3048 const struct ethaddr
*mac
,
3049 struct in_addr vtep_ip
,
3052 uint32_t update_flags
)
3054 enum zebra_dplane_result result
= ZEBRA_DPLANE_REQUEST_FAILURE
;
3056 struct zebra_dplane_ctx
*ctx
= NULL
;
3058 if (IS_ZEBRA_DEBUG_DPLANE_DETAIL
) {
3059 char buf1
[ETHER_ADDR_STRLEN
], buf2
[PREFIX_STRLEN
];
3061 zlog_debug("init mac ctx %s: mac %s, ifp %s, vtep %s",
3063 prefix_mac2str(mac
, buf1
, sizeof(buf1
)),
3065 inet_ntop(AF_INET
, &vtep_ip
, buf2
, sizeof(buf2
)));
3068 ctx
= dplane_ctx_alloc();
3071 /* Common init for the ctx */
3072 dplane_mac_init(ctx
, ifp
, br_ifp
, vid
, mac
, vtep_ip
, sticky
,
3073 nhg_id
, update_flags
);
3075 /* Enqueue for processing on the dplane pthread */
3076 ret
= dplane_update_enqueue(ctx
);
3078 /* Increment counter */
3079 atomic_fetch_add_explicit(&zdplane_info
.dg_macs_in
, 1,
3080 memory_order_relaxed
);
3083 result
= ZEBRA_DPLANE_REQUEST_QUEUED
;
3086 atomic_fetch_add_explicit(&zdplane_info
.dg_mac_errors
, 1,
3087 memory_order_relaxed
);
3088 dplane_ctx_free(&ctx
);
3095 * Enqueue evpn neighbor add for the dataplane.
3097 enum zebra_dplane_result
dplane_rem_neigh_add(const struct interface
*ifp
,
3098 const struct ipaddr
*ip
,
3099 const struct ethaddr
*mac
,
3100 uint32_t flags
, bool was_static
)
3102 enum zebra_dplane_result result
= ZEBRA_DPLANE_REQUEST_FAILURE
;
3103 uint32_t update_flags
= 0;
3105 update_flags
|= DPLANE_NEIGH_REMOTE
;
3108 update_flags
|= DPLANE_NEIGH_WAS_STATIC
;
3110 result
= neigh_update_internal(DPLANE_OP_NEIGH_INSTALL
,
3111 ifp
, mac
, ip
, flags
, DPLANE_NUD_NOARP
,
3118 * Enqueue local neighbor add for the dataplane.
3120 enum zebra_dplane_result
dplane_local_neigh_add(const struct interface
*ifp
,
3121 const struct ipaddr
*ip
,
3122 const struct ethaddr
*mac
,
3123 bool set_router
, bool set_static
,
3126 enum zebra_dplane_result result
= ZEBRA_DPLANE_REQUEST_FAILURE
;
3127 uint32_t update_flags
= 0;
3132 update_flags
|= DPLANE_NEIGH_SET_STATIC
;
3135 update_flags
|= DPLANE_NEIGH_SET_INACTIVE
;
3136 state
= DPLANE_NUD_STALE
;
3138 state
= DPLANE_NUD_REACHABLE
;
3142 ntf
|= DPLANE_NTF_ROUTER
;
3144 result
= neigh_update_internal(DPLANE_OP_NEIGH_INSTALL
,
3146 state
, update_flags
);
3152 * Enqueue evpn neighbor delete for the dataplane.
3154 enum zebra_dplane_result
dplane_rem_neigh_delete(const struct interface
*ifp
,
3155 const struct ipaddr
*ip
)
3157 enum zebra_dplane_result result
;
3158 uint32_t update_flags
= 0;
3160 update_flags
|= DPLANE_NEIGH_REMOTE
;
3162 result
= neigh_update_internal(DPLANE_OP_NEIGH_DELETE
,
3163 ifp
, NULL
, ip
, 0, 0, update_flags
);
3169 * Enqueue evpn VTEP add for the dataplane.
3171 enum zebra_dplane_result
dplane_vtep_add(const struct interface
*ifp
,
3172 const struct in_addr
*ip
,
3175 enum zebra_dplane_result result
;
3176 struct ethaddr mac
= { {0, 0, 0, 0, 0, 0} };
3179 if (IS_ZEBRA_DEBUG_VXLAN
)
3180 zlog_debug("Install %s into flood list for VNI %u intf %s(%u)",
3181 inet_ntoa(*ip
), vni
, ifp
->name
, ifp
->ifindex
);
3183 SET_IPADDR_V4(&addr
);
3184 addr
.ipaddr_v4
= *ip
;
3186 result
= neigh_update_internal(DPLANE_OP_VTEP_ADD
,
3187 ifp
, &mac
, &addr
, 0, 0, 0);
3193 * Enqueue evpn VTEP add for the dataplane.
3195 enum zebra_dplane_result
dplane_vtep_delete(const struct interface
*ifp
,
3196 const struct in_addr
*ip
,
3199 enum zebra_dplane_result result
;
3200 struct ethaddr mac
= { {0, 0, 0, 0, 0, 0} };
3203 if (IS_ZEBRA_DEBUG_VXLAN
)
3205 "Uninstall %s from flood list for VNI %u intf %s(%u)",
3206 inet_ntoa(*ip
), vni
, ifp
->name
, ifp
->ifindex
);
3208 SET_IPADDR_V4(&addr
);
3209 addr
.ipaddr_v4
= *ip
;
3211 result
= neigh_update_internal(DPLANE_OP_VTEP_DELETE
,
3212 ifp
, &mac
, &addr
, 0, 0, 0);
3217 enum zebra_dplane_result
dplane_neigh_discover(const struct interface
*ifp
,
3218 const struct ipaddr
*ip
)
3220 enum zebra_dplane_result result
;
3222 result
= neigh_update_internal(DPLANE_OP_NEIGH_DISCOVER
, ifp
, NULL
, ip
,
3223 DPLANE_NTF_USE
, DPLANE_NUD_INCOMPLETE
, 0);
3229 * Common helper api for neighbor updates
3231 static enum zebra_dplane_result
3232 neigh_update_internal(enum dplane_op_e op
,
3233 const struct interface
*ifp
,
3234 const struct ethaddr
*mac
,
3235 const struct ipaddr
*ip
,
3236 uint32_t flags
, uint16_t state
,
3237 uint32_t update_flags
)
3239 enum zebra_dplane_result result
= ZEBRA_DPLANE_REQUEST_FAILURE
;
3241 struct zebra_dplane_ctx
*ctx
= NULL
;
3242 struct zebra_ns
*zns
;
3244 if (IS_ZEBRA_DEBUG_DPLANE_DETAIL
) {
3245 char buf1
[ETHER_ADDR_STRLEN
], buf2
[PREFIX_STRLEN
];
3247 zlog_debug("init neigh ctx %s: ifp %s, mac %s, ip %s",
3248 dplane_op2str(op
), ifp
->name
,
3249 prefix_mac2str(mac
, buf1
, sizeof(buf1
)),
3250 ipaddr2str(ip
, buf2
, sizeof(buf2
)));
3253 ctx
= dplane_ctx_alloc();
3256 ctx
->zd_status
= ZEBRA_DPLANE_REQUEST_SUCCESS
;
3257 ctx
->zd_vrf_id
= ifp
->vrf_id
;
3259 zns
= zebra_ns_lookup(ifp
->vrf_id
);
3260 dplane_ctx_ns_init(ctx
, zns
, false);
3262 strlcpy(ctx
->zd_ifname
, ifp
->name
, sizeof(ctx
->zd_ifname
));
3263 ctx
->zd_ifindex
= ifp
->ifindex
;
3265 /* Init the neighbor-specific data area */
3266 memset(&ctx
->u
.neigh
, 0, sizeof(ctx
->u
.neigh
));
3268 ctx
->u
.neigh
.ip_addr
= *ip
;
3270 ctx
->u
.neigh
.mac
= *mac
;
3271 ctx
->u
.neigh
.flags
= flags
;
3272 ctx
->u
.neigh
.state
= state
;
3273 ctx
->u
.neigh
.update_flags
= update_flags
;
3275 /* Enqueue for processing on the dplane pthread */
3276 ret
= dplane_update_enqueue(ctx
);
3278 /* Increment counter */
3279 atomic_fetch_add_explicit(&zdplane_info
.dg_neighs_in
, 1,
3280 memory_order_relaxed
);
3283 result
= ZEBRA_DPLANE_REQUEST_QUEUED
;
3286 atomic_fetch_add_explicit(&zdplane_info
.dg_neigh_errors
, 1,
3287 memory_order_relaxed
);
3288 dplane_ctx_free(&ctx
);
3295 * Common helper api for PBR rule updates
3297 static enum zebra_dplane_result
3298 rule_update_internal(enum dplane_op_e op
, struct zebra_pbr_rule
*new_rule
,
3299 struct zebra_pbr_rule
*old_rule
)
3301 enum zebra_dplane_result result
= ZEBRA_DPLANE_REQUEST_FAILURE
;
3302 struct zebra_dplane_ctx
*ctx
;
3305 ctx
= dplane_ctx_alloc();
3307 ret
= dplane_ctx_rule_init(ctx
, op
, new_rule
, old_rule
);
3311 ret
= dplane_update_enqueue(ctx
);
3314 atomic_fetch_add_explicit(&zdplane_info
.dg_rules_in
, 1,
3315 memory_order_relaxed
);
3318 result
= ZEBRA_DPLANE_REQUEST_QUEUED
;
3320 atomic_fetch_add_explicit(&zdplane_info
.dg_rule_errors
, 1,
3321 memory_order_relaxed
);
3322 dplane_ctx_free(&ctx
);
3328 enum zebra_dplane_result
dplane_pbr_rule_add(struct zebra_pbr_rule
*rule
)
3330 return rule_update_internal(DPLANE_OP_RULE_ADD
, rule
, NULL
);
3333 enum zebra_dplane_result
dplane_pbr_rule_delete(struct zebra_pbr_rule
*rule
)
3335 return rule_update_internal(DPLANE_OP_RULE_DELETE
, rule
, NULL
);
3338 enum zebra_dplane_result
dplane_pbr_rule_update(struct zebra_pbr_rule
*old_rule
,
3339 struct zebra_pbr_rule
*new_rule
)
3341 return rule_update_internal(DPLANE_OP_RULE_UPDATE
, new_rule
, old_rule
);
3345 * Handler for 'show dplane'
3347 int dplane_show_helper(struct vty
*vty
, bool detailed
)
3349 uint64_t queued
, queue_max
, limit
, errs
, incoming
, yields
,
3352 /* Using atomics because counters are being changed in different
3355 incoming
= atomic_load_explicit(&zdplane_info
.dg_routes_in
,
3356 memory_order_relaxed
);
3357 limit
= atomic_load_explicit(&zdplane_info
.dg_max_queued_updates
,
3358 memory_order_relaxed
);
3359 queued
= atomic_load_explicit(&zdplane_info
.dg_routes_queued
,
3360 memory_order_relaxed
);
3361 queue_max
= atomic_load_explicit(&zdplane_info
.dg_routes_queued_max
,
3362 memory_order_relaxed
);
3363 errs
= atomic_load_explicit(&zdplane_info
.dg_route_errors
,
3364 memory_order_relaxed
);
3365 yields
= atomic_load_explicit(&zdplane_info
.dg_update_yields
,
3366 memory_order_relaxed
);
3367 other_errs
= atomic_load_explicit(&zdplane_info
.dg_other_errors
,
3368 memory_order_relaxed
);
3370 vty_out(vty
, "Zebra dataplane:\nRoute updates: %"PRIu64
"\n",
3372 vty_out(vty
, "Route update errors: %"PRIu64
"\n", errs
);
3373 vty_out(vty
, "Other errors : %"PRIu64
"\n", other_errs
);
3374 vty_out(vty
, "Route update queue limit: %"PRIu64
"\n", limit
);
3375 vty_out(vty
, "Route update queue depth: %"PRIu64
"\n", queued
);
3376 vty_out(vty
, "Route update queue max: %"PRIu64
"\n", queue_max
);
3377 vty_out(vty
, "Dplane update yields: %"PRIu64
"\n", yields
);
3379 incoming
= atomic_load_explicit(&zdplane_info
.dg_lsps_in
,
3380 memory_order_relaxed
);
3381 errs
= atomic_load_explicit(&zdplane_info
.dg_lsp_errors
,
3382 memory_order_relaxed
);
3383 vty_out(vty
, "LSP updates: %"PRIu64
"\n", incoming
);
3384 vty_out(vty
, "LSP update errors: %"PRIu64
"\n", errs
);
3386 incoming
= atomic_load_explicit(&zdplane_info
.dg_pws_in
,
3387 memory_order_relaxed
);
3388 errs
= atomic_load_explicit(&zdplane_info
.dg_pw_errors
,
3389 memory_order_relaxed
);
3390 vty_out(vty
, "PW updates: %"PRIu64
"\n", incoming
);
3391 vty_out(vty
, "PW update errors: %"PRIu64
"\n", errs
);
3393 incoming
= atomic_load_explicit(&zdplane_info
.dg_intf_addrs_in
,
3394 memory_order_relaxed
);
3395 errs
= atomic_load_explicit(&zdplane_info
.dg_intf_addr_errors
,
3396 memory_order_relaxed
);
3397 vty_out(vty
, "Intf addr updates: %"PRIu64
"\n", incoming
);
3398 vty_out(vty
, "Intf addr errors: %"PRIu64
"\n", errs
);
3400 incoming
= atomic_load_explicit(&zdplane_info
.dg_macs_in
,
3401 memory_order_relaxed
);
3402 errs
= atomic_load_explicit(&zdplane_info
.dg_mac_errors
,
3403 memory_order_relaxed
);
3404 vty_out(vty
, "EVPN MAC updates: %"PRIu64
"\n", incoming
);
3405 vty_out(vty
, "EVPN MAC errors: %"PRIu64
"\n", errs
);
3407 incoming
= atomic_load_explicit(&zdplane_info
.dg_neighs_in
,
3408 memory_order_relaxed
);
3409 errs
= atomic_load_explicit(&zdplane_info
.dg_neigh_errors
,
3410 memory_order_relaxed
);
3411 vty_out(vty
, "EVPN neigh updates: %"PRIu64
"\n", incoming
);
3412 vty_out(vty
, "EVPN neigh errors: %"PRIu64
"\n", errs
);
3414 incoming
= atomic_load_explicit(&zdplane_info
.dg_rules_in
,
3415 memory_order_relaxed
);
3416 errs
= atomic_load_explicit(&zdplane_info
.dg_rule_errors
,
3417 memory_order_relaxed
);
3418 vty_out(vty
, "Rule updates: %" PRIu64
"\n", incoming
);
3419 vty_out(vty
, "Rule errors: %" PRIu64
"\n", errs
);
3425 * Handler for 'show dplane providers'
3427 int dplane_show_provs_helper(struct vty
*vty
, bool detailed
)
3429 struct zebra_dplane_provider
*prov
;
3430 uint64_t in
, in_max
, out
, out_max
;
3432 vty_out(vty
, "Zebra dataplane providers:\n");
3435 prov
= TAILQ_FIRST(&zdplane_info
.dg_providers_q
);
3438 /* Show counters, useful info from each registered provider */
3441 in
= atomic_load_explicit(&prov
->dp_in_counter
,
3442 memory_order_relaxed
);
3443 in_max
= atomic_load_explicit(&prov
->dp_in_max
,
3444 memory_order_relaxed
);
3445 out
= atomic_load_explicit(&prov
->dp_out_counter
,
3446 memory_order_relaxed
);
3447 out_max
= atomic_load_explicit(&prov
->dp_out_max
,
3448 memory_order_relaxed
);
3451 "%s (%u): in: %" PRIu64
", q_max: %" PRIu64
3452 ", out: %" PRIu64
", q_max: %" PRIu64
"\n",
3453 prov
->dp_name
, prov
->dp_id
, in
, in_max
, out
, out_max
);
3456 prov
= TAILQ_NEXT(prov
, dp_prov_link
);
3464 * Helper for 'show run' etc.
3466 int dplane_config_write_helper(struct vty
*vty
)
3468 if (zdplane_info
.dg_max_queued_updates
!= DPLANE_DEFAULT_MAX_QUEUED
)
3469 vty_out(vty
, "zebra dplane limit %u\n",
3470 zdplane_info
.dg_max_queued_updates
);
3476 * Provider registration
3478 int dplane_provider_register(const char *name
,
3479 enum dplane_provider_prio prio
,
3481 int (*start_fp
)(struct zebra_dplane_provider
*),
3482 int (*fp
)(struct zebra_dplane_provider
*),
3483 int (*fini_fp
)(struct zebra_dplane_provider
*,
3486 struct zebra_dplane_provider
**prov_p
)
3489 struct zebra_dplane_provider
*p
= NULL
, *last
;
3497 if (prio
<= DPLANE_PRIO_NONE
||
3498 prio
> DPLANE_PRIO_LAST
) {
3503 /* Allocate and init new provider struct */
3504 p
= XCALLOC(MTYPE_DP_PROV
, sizeof(struct zebra_dplane_provider
));
3506 pthread_mutex_init(&(p
->dp_mutex
), NULL
);
3507 TAILQ_INIT(&(p
->dp_ctx_in_q
));
3508 TAILQ_INIT(&(p
->dp_ctx_out_q
));
3510 p
->dp_flags
= flags
;
3511 p
->dp_priority
= prio
;
3513 p
->dp_start
= start_fp
;
3514 p
->dp_fini
= fini_fp
;
3517 /* Lock - the dplane pthread may be running */
3520 p
->dp_id
= ++zdplane_info
.dg_provider_id
;
3523 strlcpy(p
->dp_name
, name
, DPLANE_PROVIDER_NAMELEN
);
3525 snprintf(p
->dp_name
, DPLANE_PROVIDER_NAMELEN
,
3526 "provider-%u", p
->dp_id
);
3528 /* Insert into list ordered by priority */
3529 TAILQ_FOREACH(last
, &zdplane_info
.dg_providers_q
, dp_prov_link
) {
3530 if (last
->dp_priority
> p
->dp_priority
)
3535 TAILQ_INSERT_BEFORE(last
, p
, dp_prov_link
);
3537 TAILQ_INSERT_TAIL(&zdplane_info
.dg_providers_q
, p
,
3543 if (IS_ZEBRA_DEBUG_DPLANE
)
3544 zlog_debug("dplane: registered new provider '%s' (%u), prio %d",
3545 p
->dp_name
, p
->dp_id
, p
->dp_priority
);
3554 /* Accessors for provider attributes */
3555 const char *dplane_provider_get_name(const struct zebra_dplane_provider
*prov
)
3557 return prov
->dp_name
;
3560 uint32_t dplane_provider_get_id(const struct zebra_dplane_provider
*prov
)
3565 void *dplane_provider_get_data(const struct zebra_dplane_provider
*prov
)
3567 return prov
->dp_data
;
3570 int dplane_provider_get_work_limit(const struct zebra_dplane_provider
*prov
)
3572 return zdplane_info
.dg_updates_per_cycle
;
3575 /* Lock/unlock a provider's mutex - iff the provider was registered with
3576 * the THREADED flag.
3578 void dplane_provider_lock(struct zebra_dplane_provider
*prov
)
3580 if (dplane_provider_is_threaded(prov
))
3581 DPLANE_PROV_LOCK(prov
);
3584 void dplane_provider_unlock(struct zebra_dplane_provider
*prov
)
3586 if (dplane_provider_is_threaded(prov
))
3587 DPLANE_PROV_UNLOCK(prov
);
3591 * Dequeue and maintain associated counter
3593 struct zebra_dplane_ctx
*dplane_provider_dequeue_in_ctx(
3594 struct zebra_dplane_provider
*prov
)
3596 struct zebra_dplane_ctx
*ctx
= NULL
;
3598 dplane_provider_lock(prov
);
3600 ctx
= TAILQ_FIRST(&(prov
->dp_ctx_in_q
));
3602 TAILQ_REMOVE(&(prov
->dp_ctx_in_q
), ctx
, zd_q_entries
);
3604 atomic_fetch_sub_explicit(&prov
->dp_in_queued
, 1,
3605 memory_order_relaxed
);
3608 dplane_provider_unlock(prov
);
3614 * Dequeue work to a list, return count
3616 int dplane_provider_dequeue_in_list(struct zebra_dplane_provider
*prov
,
3617 struct dplane_ctx_q
*listp
)
3620 struct zebra_dplane_ctx
*ctx
;
3622 limit
= zdplane_info
.dg_updates_per_cycle
;
3624 dplane_provider_lock(prov
);
3626 for (ret
= 0; ret
< limit
; ret
++) {
3627 ctx
= TAILQ_FIRST(&(prov
->dp_ctx_in_q
));
3629 TAILQ_REMOVE(&(prov
->dp_ctx_in_q
), ctx
, zd_q_entries
);
3631 TAILQ_INSERT_TAIL(listp
, ctx
, zd_q_entries
);
3638 atomic_fetch_sub_explicit(&prov
->dp_in_queued
, ret
,
3639 memory_order_relaxed
);
3641 dplane_provider_unlock(prov
);
3647 * Enqueue and maintain associated counter
3649 void dplane_provider_enqueue_out_ctx(struct zebra_dplane_provider
*prov
,
3650 struct zebra_dplane_ctx
*ctx
)
3652 dplane_provider_lock(prov
);
3654 TAILQ_INSERT_TAIL(&(prov
->dp_ctx_out_q
), ctx
,
3657 dplane_provider_unlock(prov
);
3659 atomic_fetch_add_explicit(&(prov
->dp_out_counter
), 1,
3660 memory_order_relaxed
);
3664 * Accessor for provider object
3666 bool dplane_provider_is_threaded(const struct zebra_dplane_provider
*prov
)
3668 return (prov
->dp_flags
& DPLANE_PROV_FLAG_THREADED
);
3672 * Internal helper that copies information from a zebra ns object; this is
3673 * called in the zebra main pthread context as part of dplane ctx init.
3675 static void dplane_info_from_zns(struct zebra_dplane_info
*ns_info
,
3676 struct zebra_ns
*zns
)
3678 ns_info
->ns_id
= zns
->ns_id
;
3680 #if defined(HAVE_NETLINK)
3681 ns_info
->is_cmd
= true;
3682 ns_info
->nls
= zns
->netlink_dplane
;
3683 #endif /* NETLINK */
3687 * Provider api to signal that work/events are available
3688 * for the dataplane pthread.
3690 int dplane_provider_work_ready(void)
3692 /* Note that during zebra startup, we may be offered work before
3693 * the dataplane pthread (and thread-master) are ready. We want to
3694 * enqueue the work, but the event-scheduling machinery may not be
3697 if (zdplane_info
.dg_run
) {
3698 thread_add_event(zdplane_info
.dg_master
,
3699 dplane_thread_loop
, NULL
, 0,
3700 &zdplane_info
.dg_t_update
);
3707 * Enqueue a context directly to zebra main.
3709 void dplane_provider_enqueue_to_zebra(struct zebra_dplane_ctx
*ctx
)
3711 struct dplane_ctx_q temp_list
;
3713 /* Zebra's api takes a list, so we need to use a temporary list */
3714 TAILQ_INIT(&temp_list
);
3716 TAILQ_INSERT_TAIL(&temp_list
, ctx
, zd_q_entries
);
3717 (zdplane_info
.dg_results_cb
)(&temp_list
);
3721 * Kernel dataplane provider
3724 static void kernel_dplane_log_detail(struct zebra_dplane_ctx
*ctx
)
3726 char buf
[PREFIX_STRLEN
];
3728 switch (dplane_ctx_get_op(ctx
)) {
3730 case DPLANE_OP_ROUTE_INSTALL
:
3731 case DPLANE_OP_ROUTE_UPDATE
:
3732 case DPLANE_OP_ROUTE_DELETE
:
3733 prefix2str(dplane_ctx_get_dest(ctx
), buf
, sizeof(buf
));
3735 zlog_debug("%u:%s Dplane route update ctx %p op %s",
3736 dplane_ctx_get_vrf(ctx
), buf
, ctx
,
3737 dplane_op2str(dplane_ctx_get_op(ctx
)));
3740 case DPLANE_OP_NH_INSTALL
:
3741 case DPLANE_OP_NH_UPDATE
:
3742 case DPLANE_OP_NH_DELETE
:
3743 zlog_debug("ID (%u) Dplane nexthop update ctx %p op %s",
3744 dplane_ctx_get_nhe_id(ctx
), ctx
,
3745 dplane_op2str(dplane_ctx_get_op(ctx
)));
3748 case DPLANE_OP_LSP_INSTALL
:
3749 case DPLANE_OP_LSP_UPDATE
:
3750 case DPLANE_OP_LSP_DELETE
:
3753 case DPLANE_OP_PW_INSTALL
:
3754 case DPLANE_OP_PW_UNINSTALL
:
3755 zlog_debug("Dplane pw %s: op %s af %d loc: %u rem: %u",
3756 dplane_ctx_get_ifname(ctx
),
3757 dplane_op2str(ctx
->zd_op
), dplane_ctx_get_pw_af(ctx
),
3758 dplane_ctx_get_pw_local_label(ctx
),
3759 dplane_ctx_get_pw_remote_label(ctx
));
3762 case DPLANE_OP_ADDR_INSTALL
:
3763 case DPLANE_OP_ADDR_UNINSTALL
:
3764 prefix2str(dplane_ctx_get_intf_addr(ctx
), buf
, sizeof(buf
));
3766 zlog_debug("Dplane intf %s, idx %u, addr %s",
3767 dplane_op2str(dplane_ctx_get_op(ctx
)),
3768 dplane_ctx_get_ifindex(ctx
), buf
);
3771 case DPLANE_OP_MAC_INSTALL
:
3772 case DPLANE_OP_MAC_DELETE
:
3773 prefix_mac2str(dplane_ctx_mac_get_addr(ctx
), buf
,
3776 zlog_debug("Dplane %s, mac %s, ifindex %u",
3777 dplane_op2str(dplane_ctx_get_op(ctx
)),
3778 buf
, dplane_ctx_get_ifindex(ctx
));
3781 case DPLANE_OP_NEIGH_INSTALL
:
3782 case DPLANE_OP_NEIGH_UPDATE
:
3783 case DPLANE_OP_NEIGH_DELETE
:
3784 case DPLANE_OP_VTEP_ADD
:
3785 case DPLANE_OP_VTEP_DELETE
:
3786 case DPLANE_OP_NEIGH_DISCOVER
:
3787 ipaddr2str(dplane_ctx_neigh_get_ipaddr(ctx
), buf
,
3790 zlog_debug("Dplane %s, ip %s, ifindex %u",
3791 dplane_op2str(dplane_ctx_get_op(ctx
)),
3792 buf
, dplane_ctx_get_ifindex(ctx
));
3795 case DPLANE_OP_RULE_ADD
:
3796 case DPLANE_OP_RULE_DELETE
:
3797 case DPLANE_OP_RULE_UPDATE
:
3798 zlog_debug("Dplane rule update op %s, if %s(%u), ctx %p",
3799 dplane_op2str(dplane_ctx_get_op(ctx
)),
3800 dplane_ctx_get_ifname(ctx
),
3801 dplane_ctx_get_ifindex(ctx
), ctx
);
3804 case DPLANE_OP_SYS_ROUTE_ADD
:
3805 case DPLANE_OP_SYS_ROUTE_DELETE
:
3806 case DPLANE_OP_ROUTE_NOTIFY
:
3807 case DPLANE_OP_LSP_NOTIFY
:
3809 case DPLANE_OP_NONE
:
3814 static void kernel_dplane_handle_result(struct zebra_dplane_ctx
*ctx
)
3816 enum zebra_dplane_result res
= dplane_ctx_get_status(ctx
);
3818 switch (dplane_ctx_get_op(ctx
)) {
3820 case DPLANE_OP_ROUTE_INSTALL
:
3821 case DPLANE_OP_ROUTE_UPDATE
:
3822 case DPLANE_OP_ROUTE_DELETE
:
3823 if (res
!= ZEBRA_DPLANE_REQUEST_SUCCESS
)
3824 atomic_fetch_add_explicit(&zdplane_info
.dg_route_errors
,
3825 1, memory_order_relaxed
);
3827 if ((dplane_ctx_get_op(ctx
) != DPLANE_OP_ROUTE_DELETE
)
3828 && (res
== ZEBRA_DPLANE_REQUEST_SUCCESS
)) {
3829 struct nexthop
*nexthop
;
3831 /* Update installed nexthops to signal which have been
3834 for (ALL_NEXTHOPS_PTR(dplane_ctx_get_ng(ctx
),
3836 if (CHECK_FLAG(nexthop
->flags
,
3837 NEXTHOP_FLAG_RECURSIVE
))
3840 if (CHECK_FLAG(nexthop
->flags
,
3841 NEXTHOP_FLAG_ACTIVE
)) {
3842 SET_FLAG(nexthop
->flags
,
3849 case DPLANE_OP_NH_INSTALL
:
3850 case DPLANE_OP_NH_UPDATE
:
3851 case DPLANE_OP_NH_DELETE
:
3852 if (res
!= ZEBRA_DPLANE_REQUEST_SUCCESS
)
3853 atomic_fetch_add_explicit(
3854 &zdplane_info
.dg_nexthop_errors
, 1,
3855 memory_order_relaxed
);
3858 case DPLANE_OP_LSP_INSTALL
:
3859 case DPLANE_OP_LSP_UPDATE
:
3860 case DPLANE_OP_LSP_DELETE
:
3861 if (res
!= ZEBRA_DPLANE_REQUEST_SUCCESS
)
3862 atomic_fetch_add_explicit(&zdplane_info
.dg_lsp_errors
,
3863 1, memory_order_relaxed
);
3866 case DPLANE_OP_PW_INSTALL
:
3867 case DPLANE_OP_PW_UNINSTALL
:
3868 if (res
!= ZEBRA_DPLANE_REQUEST_SUCCESS
)
3869 atomic_fetch_add_explicit(&zdplane_info
.dg_pw_errors
, 1,
3870 memory_order_relaxed
);
3873 case DPLANE_OP_ADDR_INSTALL
:
3874 case DPLANE_OP_ADDR_UNINSTALL
:
3875 if (res
!= ZEBRA_DPLANE_REQUEST_SUCCESS
)
3876 atomic_fetch_add_explicit(
3877 &zdplane_info
.dg_intf_addr_errors
, 1,
3878 memory_order_relaxed
);
3881 case DPLANE_OP_MAC_INSTALL
:
3882 case DPLANE_OP_MAC_DELETE
:
3883 if (res
!= ZEBRA_DPLANE_REQUEST_SUCCESS
)
3884 atomic_fetch_add_explicit(&zdplane_info
.dg_mac_errors
,
3885 1, memory_order_relaxed
);
3888 case DPLANE_OP_NEIGH_INSTALL
:
3889 case DPLANE_OP_NEIGH_UPDATE
:
3890 case DPLANE_OP_NEIGH_DELETE
:
3891 case DPLANE_OP_VTEP_ADD
:
3892 case DPLANE_OP_VTEP_DELETE
:
3893 case DPLANE_OP_NEIGH_DISCOVER
:
3894 if (res
!= ZEBRA_DPLANE_REQUEST_SUCCESS
)
3895 atomic_fetch_add_explicit(&zdplane_info
.dg_neigh_errors
,
3896 1, memory_order_relaxed
);
3899 case DPLANE_OP_RULE_ADD
:
3900 case DPLANE_OP_RULE_DELETE
:
3901 case DPLANE_OP_RULE_UPDATE
:
3902 if (res
!= ZEBRA_DPLANE_REQUEST_SUCCESS
)
3903 atomic_fetch_add_explicit(&zdplane_info
.dg_rule_errors
,
3904 1, memory_order_relaxed
);
3907 /* Ignore 'notifications' - no-op */
3908 case DPLANE_OP_SYS_ROUTE_ADD
:
3909 case DPLANE_OP_SYS_ROUTE_DELETE
:
3910 case DPLANE_OP_ROUTE_NOTIFY
:
3911 case DPLANE_OP_LSP_NOTIFY
:
3914 case DPLANE_OP_NONE
:
3915 if (res
!= ZEBRA_DPLANE_REQUEST_SUCCESS
)
3916 atomic_fetch_add_explicit(&zdplane_info
.dg_other_errors
,
3917 1, memory_order_relaxed
);
3923 * Kernel provider callback
3925 static int kernel_dplane_process_func(struct zebra_dplane_provider
*prov
)
3927 struct zebra_dplane_ctx
*ctx
, *tctx
;
3928 struct dplane_ctx_q work_list
;
3931 TAILQ_INIT(&work_list
);
3933 limit
= dplane_provider_get_work_limit(prov
);
3935 if (IS_ZEBRA_DEBUG_DPLANE_DETAIL
)
3936 zlog_debug("dplane provider '%s': processing",
3937 dplane_provider_get_name(prov
));
3939 for (counter
= 0; counter
< limit
; counter
++) {
3940 ctx
= dplane_provider_dequeue_in_ctx(prov
);
3944 if (IS_ZEBRA_DEBUG_DPLANE_DETAIL
)
3945 kernel_dplane_log_detail(ctx
);
3947 TAILQ_INSERT_TAIL(&work_list
, ctx
, zd_q_entries
);
3950 kernel_update_multi(&work_list
);
3952 TAILQ_FOREACH_SAFE (ctx
, &work_list
, zd_q_entries
, tctx
) {
3953 kernel_dplane_handle_result(ctx
);
3955 TAILQ_REMOVE(&work_list
, ctx
, zd_q_entries
);
3956 dplane_provider_enqueue_out_ctx(prov
, ctx
);
3959 /* Ensure that we'll run the work loop again if there's still
3962 if (counter
>= limit
) {
3963 if (IS_ZEBRA_DEBUG_DPLANE_DETAIL
)
3964 zlog_debug("dplane provider '%s' reached max updates %d",
3965 dplane_provider_get_name(prov
), counter
);
3967 atomic_fetch_add_explicit(&zdplane_info
.dg_update_yields
,
3968 1, memory_order_relaxed
);
3970 dplane_provider_work_ready();
3976 #ifdef DPLANE_TEST_PROVIDER
3979 * Test dataplane provider plugin
3983 * Test provider process callback
3985 static int test_dplane_process_func(struct zebra_dplane_provider
*prov
)
3987 struct zebra_dplane_ctx
*ctx
;
3990 /* Just moving from 'in' queue to 'out' queue */
3992 if (IS_ZEBRA_DEBUG_DPLANE_DETAIL
)
3993 zlog_debug("dplane provider '%s': processing",
3994 dplane_provider_get_name(prov
));
3996 limit
= dplane_provider_get_work_limit(prov
);
3998 for (counter
= 0; counter
< limit
; counter
++) {
3999 ctx
= dplane_provider_dequeue_in_ctx(prov
);
4003 if (IS_ZEBRA_DEBUG_DPLANE_DETAIL
)
4004 zlog_debug("dplane provider '%s': op %s",
4005 dplane_provider_get_name(prov
),
4006 dplane_op2str(dplane_ctx_get_op(ctx
)));
4008 dplane_ctx_set_status(ctx
, ZEBRA_DPLANE_REQUEST_SUCCESS
);
4010 dplane_provider_enqueue_out_ctx(prov
, ctx
);
4013 if (IS_ZEBRA_DEBUG_DPLANE_DETAIL
)
4014 zlog_debug("dplane provider '%s': processed %d",
4015 dplane_provider_get_name(prov
), counter
);
4017 /* Ensure that we'll run the work loop again if there's still
4020 if (counter
>= limit
)
4021 dplane_provider_work_ready();
4027 * Test provider shutdown/fini callback
4029 static int test_dplane_shutdown_func(struct zebra_dplane_provider
*prov
,
4032 if (IS_ZEBRA_DEBUG_DPLANE
)
4033 zlog_debug("dplane provider '%s': %sshutdown",
4034 dplane_provider_get_name(prov
),
4035 early
? "early " : "");
4039 #endif /* DPLANE_TEST_PROVIDER */
4042 * Register default kernel provider
4044 static void dplane_provider_init(void)
4048 ret
= dplane_provider_register("Kernel",
4050 DPLANE_PROV_FLAGS_DEFAULT
, NULL
,
4051 kernel_dplane_process_func
,
4056 zlog_err("Unable to register kernel dplane provider: %d",
4059 #ifdef DPLANE_TEST_PROVIDER
4060 /* Optional test provider ... */
4061 ret
= dplane_provider_register("Test",
4062 DPLANE_PRIO_PRE_KERNEL
,
4063 DPLANE_PROV_FLAGS_DEFAULT
, NULL
,
4064 test_dplane_process_func
,
4065 test_dplane_shutdown_func
,
4066 NULL
/* data */, NULL
);
4069 zlog_err("Unable to register test dplane provider: %d",
4071 #endif /* DPLANE_TEST_PROVIDER */
4074 /* Indicates zebra shutdown/exit is in progress. Some operations may be
4075 * simplified or skipped during shutdown processing.
4077 bool dplane_is_in_shutdown(void)
4079 return zdplane_info
.dg_is_shutdown
;
4083 * Early or pre-shutdown, de-init notification api. This runs pretty
4084 * early during zebra shutdown, as a signal to stop new work and prepare
4085 * for updates generated by shutdown/cleanup activity, as zebra tries to
4086 * remove everything it's responsible for.
4087 * NB: This runs in the main zebra pthread context.
4089 void zebra_dplane_pre_finish(void)
4091 struct zebra_dplane_provider
*prov
;
4093 if (IS_ZEBRA_DEBUG_DPLANE
)
4094 zlog_debug("Zebra dataplane pre-finish called");
4096 zdplane_info
.dg_is_shutdown
= true;
4098 /* Notify provider(s) of pending shutdown. */
4099 TAILQ_FOREACH(prov
, &zdplane_info
.dg_providers_q
, dp_prov_link
) {
4100 if (prov
->dp_fini
== NULL
)
4103 prov
->dp_fini(prov
, true /* early */);
4108 * Utility to determine whether work remains enqueued within the dplane;
4109 * used during system shutdown processing.
4111 static bool dplane_work_pending(void)
4114 struct zebra_dplane_ctx
*ctx
;
4115 struct zebra_dplane_provider
*prov
;
4117 /* TODO -- just checking incoming/pending work for now, must check
4122 ctx
= TAILQ_FIRST(&zdplane_info
.dg_update_ctx_q
);
4123 prov
= TAILQ_FIRST(&zdplane_info
.dg_providers_q
);
4134 dplane_provider_lock(prov
);
4136 ctx
= TAILQ_FIRST(&(prov
->dp_ctx_in_q
));
4138 ctx
= TAILQ_FIRST(&(prov
->dp_ctx_out_q
));
4140 dplane_provider_unlock(prov
);
4146 prov
= TAILQ_NEXT(prov
, dp_prov_link
);
4158 * Shutdown-time intermediate callback, used to determine when all pending
4159 * in-flight updates are done. If there's still work to do, reschedules itself.
4160 * If all work is done, schedules an event to the main zebra thread for
4161 * final zebra shutdown.
4162 * This runs in the dplane pthread context.
4164 static int dplane_check_shutdown_status(struct thread
*event
)
4166 if (IS_ZEBRA_DEBUG_DPLANE
)
4167 zlog_debug("Zebra dataplane shutdown status check called");
4169 if (dplane_work_pending()) {
4170 /* Reschedule dplane check on a short timer */
4171 thread_add_timer_msec(zdplane_info
.dg_master
,
4172 dplane_check_shutdown_status
,
4174 &zdplane_info
.dg_t_shutdown_check
);
4176 /* TODO - give up and stop waiting after a short time? */
4179 /* We appear to be done - schedule a final callback event
4180 * for the zebra main pthread.
4182 thread_add_event(zrouter
.master
, zebra_finalize
, NULL
, 0, NULL
);
4189 * Shutdown, de-init api. This runs pretty late during shutdown,
4190 * after zebra has tried to free/remove/uninstall all routes during shutdown.
4191 * At this point, dplane work may still remain to be done, so we can't just
4192 * blindly terminate. If there's still work to do, we'll periodically check
4193 * and when done, we'll enqueue a task to the zebra main thread for final
4194 * termination processing.
4196 * NB: This runs in the main zebra thread context.
4198 void zebra_dplane_finish(void)
4200 if (IS_ZEBRA_DEBUG_DPLANE
)
4201 zlog_debug("Zebra dataplane fini called");
4203 thread_add_event(zdplane_info
.dg_master
,
4204 dplane_check_shutdown_status
, NULL
, 0,
4205 &zdplane_info
.dg_t_shutdown_check
);
4209 * Main dataplane pthread event loop. The thread takes new incoming work
4210 * and offers it to the first provider. It then iterates through the
4211 * providers, taking complete work from each one and offering it
4212 * to the next in order. At each step, a limited number of updates are
4213 * processed during a cycle in order to provide some fairness.
4215 * This loop through the providers is only run once, so that the dataplane
4216 * pthread can look for other pending work - such as i/o work on behalf of
4219 static int dplane_thread_loop(struct thread
*event
)
4221 struct dplane_ctx_q work_list
;
4222 struct dplane_ctx_q error_list
;
4223 struct zebra_dplane_provider
*prov
;
4224 struct zebra_dplane_ctx
*ctx
, *tctx
;
4225 int limit
, counter
, error_counter
;
4226 uint64_t curr
, high
;
4228 /* Capture work limit per cycle */
4229 limit
= zdplane_info
.dg_updates_per_cycle
;
4231 /* Init temporary lists used to move contexts among providers */
4232 TAILQ_INIT(&work_list
);
4233 TAILQ_INIT(&error_list
);
4236 /* Check for zebra shutdown */
4237 if (!zdplane_info
.dg_run
)
4240 /* Dequeue some incoming work from zebra (if any) onto the temporary
4245 /* Locate initial registered provider */
4246 prov
= TAILQ_FIRST(&zdplane_info
.dg_providers_q
);
4248 /* Move new work from incoming list to temp list */
4249 for (counter
= 0; counter
< limit
; counter
++) {
4250 ctx
= TAILQ_FIRST(&zdplane_info
.dg_update_ctx_q
);
4252 TAILQ_REMOVE(&zdplane_info
.dg_update_ctx_q
, ctx
,
4255 ctx
->zd_provider
= prov
->dp_id
;
4257 TAILQ_INSERT_TAIL(&work_list
, ctx
, zd_q_entries
);
4265 atomic_fetch_sub_explicit(&zdplane_info
.dg_routes_queued
, counter
,
4266 memory_order_relaxed
);
4268 if (IS_ZEBRA_DEBUG_DPLANE_DETAIL
)
4269 zlog_debug("dplane: incoming new work counter: %d", counter
);
4271 /* Iterate through the registered providers, offering new incoming
4272 * work. If the provider has outgoing work in its queue, take that
4273 * work for the next provider
4277 /* At each iteration, the temporary work list has 'counter'
4280 if (IS_ZEBRA_DEBUG_DPLANE_DETAIL
)
4281 zlog_debug("dplane enqueues %d new work to provider '%s'",
4282 counter
, dplane_provider_get_name(prov
));
4284 /* Capture current provider id in each context; check for
4287 TAILQ_FOREACH_SAFE(ctx
, &work_list
, zd_q_entries
, tctx
) {
4288 if (dplane_ctx_get_status(ctx
) ==
4289 ZEBRA_DPLANE_REQUEST_SUCCESS
) {
4290 ctx
->zd_provider
= prov
->dp_id
;
4293 * TODO -- improve error-handling: recirc
4294 * errors backwards so that providers can
4295 * 'undo' their work (if they want to)
4298 /* Move to error list; will be returned
4301 TAILQ_REMOVE(&work_list
, ctx
, zd_q_entries
);
4302 TAILQ_INSERT_TAIL(&error_list
,
4308 /* Enqueue new work to the provider */
4309 dplane_provider_lock(prov
);
4311 if (TAILQ_FIRST(&work_list
))
4312 TAILQ_CONCAT(&(prov
->dp_ctx_in_q
), &work_list
,
4315 atomic_fetch_add_explicit(&prov
->dp_in_counter
, counter
,
4316 memory_order_relaxed
);
4317 atomic_fetch_add_explicit(&prov
->dp_in_queued
, counter
,
4318 memory_order_relaxed
);
4319 curr
= atomic_load_explicit(&prov
->dp_in_queued
,
4320 memory_order_relaxed
);
4321 high
= atomic_load_explicit(&prov
->dp_in_max
,
4322 memory_order_relaxed
);
4324 atomic_store_explicit(&prov
->dp_in_max
, curr
,
4325 memory_order_relaxed
);
4327 dplane_provider_unlock(prov
);
4329 /* Reset the temp list (though the 'concat' may have done this
4330 * already), and the counter
4332 TAILQ_INIT(&work_list
);
4335 /* Call into the provider code. Note that this is
4336 * unconditional: we offer to do work even if we don't enqueue
4339 (*prov
->dp_fp
)(prov
);
4341 /* Check for zebra shutdown */
4342 if (!zdplane_info
.dg_run
)
4345 /* Dequeue completed work from the provider */
4346 dplane_provider_lock(prov
);
4348 while (counter
< limit
) {
4349 ctx
= TAILQ_FIRST(&(prov
->dp_ctx_out_q
));
4351 TAILQ_REMOVE(&(prov
->dp_ctx_out_q
), ctx
,
4354 TAILQ_INSERT_TAIL(&work_list
,
4361 dplane_provider_unlock(prov
);
4363 if (IS_ZEBRA_DEBUG_DPLANE_DETAIL
)
4364 zlog_debug("dplane dequeues %d completed work from provider %s",
4365 counter
, dplane_provider_get_name(prov
));
4367 /* Locate next provider */
4369 prov
= TAILQ_NEXT(prov
, dp_prov_link
);
4373 /* After all providers have been serviced, enqueue any completed
4374 * work and any errors back to zebra so it can process the results.
4376 if (IS_ZEBRA_DEBUG_DPLANE_DETAIL
)
4377 zlog_debug("dplane has %d completed, %d errors, for zebra main",
4378 counter
, error_counter
);
4381 * Hand lists through the api to zebra main,
4382 * to reduce the number of lock/unlock cycles
4385 /* Call through to zebra main */
4386 (zdplane_info
.dg_results_cb
)(&error_list
);
4388 TAILQ_INIT(&error_list
);
4390 /* Call through to zebra main */
4391 (zdplane_info
.dg_results_cb
)(&work_list
);
4393 TAILQ_INIT(&work_list
);
4400 * Final phase of shutdown, after all work enqueued to dplane has been
4401 * processed. This is called from the zebra main pthread context.
4403 void zebra_dplane_shutdown(void)
4405 struct zebra_dplane_provider
*dp
;
4407 if (IS_ZEBRA_DEBUG_DPLANE
)
4408 zlog_debug("Zebra dataplane shutdown called");
4410 /* Stop dplane thread, if it's running */
4412 zdplane_info
.dg_run
= false;
4414 if (zdplane_info
.dg_t_update
)
4415 thread_cancel_async(zdplane_info
.dg_t_update
->master
,
4416 &zdplane_info
.dg_t_update
, NULL
);
4418 frr_pthread_stop(zdplane_info
.dg_pthread
, NULL
);
4420 /* Destroy pthread */
4421 frr_pthread_destroy(zdplane_info
.dg_pthread
);
4422 zdplane_info
.dg_pthread
= NULL
;
4423 zdplane_info
.dg_master
= NULL
;
4425 /* Notify provider(s) of final shutdown.
4426 * Note that this call is in the main pthread, so providers must
4427 * be prepared for that.
4429 TAILQ_FOREACH(dp
, &zdplane_info
.dg_providers_q
, dp_prov_link
) {
4430 if (dp
->dp_fini
== NULL
)
4433 dp
->dp_fini(dp
, false);
4436 /* TODO -- Clean-up provider objects */
4438 /* TODO -- Clean queue(s), free memory */
4442 * Initialize the dataplane module during startup, internal/private version
4444 static void zebra_dplane_init_internal(void)
4446 memset(&zdplane_info
, 0, sizeof(zdplane_info
));
4448 pthread_mutex_init(&zdplane_info
.dg_mutex
, NULL
);
4450 TAILQ_INIT(&zdplane_info
.dg_update_ctx_q
);
4451 TAILQ_INIT(&zdplane_info
.dg_providers_q
);
4453 zdplane_info
.dg_updates_per_cycle
= DPLANE_DEFAULT_NEW_WORK
;
4455 zdplane_info
.dg_max_queued_updates
= DPLANE_DEFAULT_MAX_QUEUED
;
4457 /* Register default kernel 'provider' during init */
4458 dplane_provider_init();
4462 * Start the dataplane pthread. This step needs to be run later than the
4463 * 'init' step, in case zebra has fork-ed.
4465 void zebra_dplane_start(void)
4467 struct zebra_dplane_provider
*prov
;
4468 struct frr_pthread_attr pattr
= {
4469 .start
= frr_pthread_attr_default
.start
,
4470 .stop
= frr_pthread_attr_default
.stop
4473 /* Start dataplane pthread */
4475 zdplane_info
.dg_pthread
= frr_pthread_new(&pattr
, "Zebra dplane thread",
4478 zdplane_info
.dg_master
= zdplane_info
.dg_pthread
->master
;
4480 zdplane_info
.dg_run
= true;
4482 /* Enqueue an initial event for the dataplane pthread */
4483 thread_add_event(zdplane_info
.dg_master
, dplane_thread_loop
, NULL
, 0,
4484 &zdplane_info
.dg_t_update
);
4486 /* Call start callbacks for registered providers */
4489 prov
= TAILQ_FIRST(&zdplane_info
.dg_providers_q
);
4495 (prov
->dp_start
)(prov
);
4497 /* Locate next provider */
4499 prov
= TAILQ_NEXT(prov
, dp_prov_link
);
4503 frr_pthread_run(zdplane_info
.dg_pthread
, NULL
);
4507 * Initialize the dataplane module at startup; called by zebra rib_init()
4509 void zebra_dplane_init(int (*results_fp
)(struct dplane_ctx_q
*))
4511 zebra_dplane_init_internal();
4512 zdplane_info
.dg_results_cb
= results_fp
;