2 * Zebra dataplane layer.
3 * Copyright (c) 2018 Volta Networks, Inc.
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; see the file COPYING; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24 #include "lib/libfrr.h"
25 #include "lib/debug.h"
26 #include "lib/frratomic.h"
27 #include "lib/frr_pthread.h"
28 #include "lib/memory.h"
29 #include "lib/queue.h"
30 #include "lib/zebra.h"
31 #include "zebra/zebra_router.h"
32 #include "zebra/zebra_dplane.h"
33 #include "zebra/zebra_vxlan_private.h"
34 #include "zebra/zebra_mpls.h"
36 #include "zebra/debug.h"
37 #include "zebra/zebra_pbr.h"
41 DEFINE_MTYPE_STATIC(ZEBRA
, DP_CTX
, "Zebra DPlane Ctx");
42 DEFINE_MTYPE_STATIC(ZEBRA
, DP_INTF
, "Zebra DPlane Intf");
43 DEFINE_MTYPE_STATIC(ZEBRA
, DP_PROV
, "Zebra DPlane Provider");
44 DEFINE_MTYPE_STATIC(ZEBRA
, DP_NETFILTER
, "Zebra Netfilter Internal Object");
45 DEFINE_MTYPE_STATIC(ZEBRA
, DP_NS
, "DPlane NSes");
51 /* Control for collection of extra interface info with route updates; a plugin
52 * can enable the extra info via a dplane api.
54 static bool dplane_collect_extra_intf_info
;
56 /* Enable test dataplane provider */
57 /*#define DPLANE_TEST_PROVIDER 1 */
59 /* Default value for max queued incoming updates */
60 const uint32_t DPLANE_DEFAULT_MAX_QUEUED
= 200;
62 /* Default value for new work per cycle */
63 const uint32_t DPLANE_DEFAULT_NEW_WORK
= 100;
65 /* Validation check macro for context blocks */
66 /* #define DPLANE_DEBUG 1 */
70 # define DPLANE_CTX_VALID(p) \
75 # define DPLANE_CTX_VALID(p)
77 #endif /* DPLANE_DEBUG */
80 * Nexthop information captured for nexthop/nexthop group updates
82 struct dplane_nexthop_info
{
89 struct nexthop_group ng
;
90 struct nh_grp nh_grp
[MULTIPATH_NUM
];
95 * Optional extra info about interfaces used in route updates' nexthops.
97 struct dplane_intf_extra
{
103 TAILQ_ENTRY(dplane_intf_extra
) link
;
107 * Route information captured for route updates.
109 struct dplane_route_info
{
111 /* Dest and (optional) source prefixes */
112 struct prefix zd_dest
;
113 struct prefix zd_src
;
122 route_tag_t zd_old_tag
;
124 uint32_t zd_old_metric
;
126 uint16_t zd_instance
;
127 uint16_t zd_old_instance
;
130 uint8_t zd_old_distance
;
133 uint32_t zd_nexthop_mtu
;
135 /* Nexthop hash entry info */
136 struct dplane_nexthop_info nhe
;
140 struct nexthop_group zd_ng
;
142 /* Backup nexthops (if present) */
143 struct nexthop_group backup_ng
;
145 /* "Previous" nexthops, used only in route updates without netlink */
146 struct nexthop_group zd_old_ng
;
147 struct nexthop_group old_backup_ng
;
149 /* Optional list of extra interface info */
150 TAILQ_HEAD(dp_intf_extra_q
, dplane_intf_extra
) intf_extra_q
;
154 * Pseudowire info for the dataplane
156 struct dplane_pw_info
{
163 mpls_label_t local_label
;
164 mpls_label_t remote_label
;
166 /* Nexthops that are valid and installed */
167 struct nexthop_group fib_nhg
;
169 /* Primary and backup nexthop sets, copied from the resolving route. */
170 struct nexthop_group primary_nhg
;
171 struct nexthop_group backup_nhg
;
173 union pw_protocol_fields fields
;
177 * Bridge port info for the dataplane
179 struct dplane_br_port_info
{
180 uint32_t sph_filter_cnt
;
181 struct in_addr sph_filters
[ES_VTEP_MAX_CNT
];
182 /* DPLANE_BR_PORT_XXX - see zebra_dplane.h*/
184 uint32_t backup_nhg_id
;
188 * Interface/prefix info for the dataplane
190 struct dplane_intf_info
{
195 #define DPLANE_INTF_CONNECTED (1 << 0) /* Connected peer, p2p */
196 #define DPLANE_INTF_SECONDARY (1 << 1)
197 #define DPLANE_INTF_BROADCAST (1 << 2)
198 #define DPLANE_INTF_HAS_DEST DPLANE_INTF_CONNECTED
199 #define DPLANE_INTF_HAS_LABEL (1 << 4)
201 /* Interface address/prefix */
202 struct prefix prefix
;
204 /* Dest address, for p2p, or broadcast prefix */
205 struct prefix dest_prefix
;
212 * EVPN MAC address info for the dataplane.
214 struct dplane_mac_info
{
216 ifindex_t br_ifindex
;
218 struct in_addr vtep_ip
;
221 uint32_t update_flags
;
225 * Neighbor info for the dataplane
227 struct dplane_neigh_info
{
228 struct ipaddr ip_addr
;
231 struct ipaddr ip_addr
;
235 uint32_t update_flags
;
241 struct dplane_neigh_table
{
244 uint32_t ucast_probes
;
245 uint32_t mcast_probes
;
249 * Policy based routing rule info for the dataplane
251 struct dplane_ctx_rule
{
254 /* The route table pointed by this rule */
257 /* Filter criteria */
261 struct prefix src_ip
;
262 struct prefix dst_ip
;
266 uint16_t action_vlan_id
;
267 uint16_t action_vlan_flags
;
269 uint32_t action_queue_id
;
271 char ifname
[INTERFACE_NAMSIZ
+ 1];
274 struct dplane_rule_info
{
276 * Originating zclient sock fd, so we can know who to send
284 struct dplane_ctx_rule
new;
285 struct dplane_ctx_rule old
;
288 struct dplane_gre_ctx
{
289 uint32_t link_ifindex
;
291 struct zebra_l2info_gre info
;
294 * The context block used to exchange info about route updates across
295 * the boundary between the zebra main context (and pthread) and the
296 * dataplane layer (and pthread).
298 struct zebra_dplane_ctx
{
301 enum dplane_op_e zd_op
;
303 /* Status on return */
304 enum zebra_dplane_result zd_status
;
306 /* Dplane provider id */
307 uint32_t zd_provider
;
309 /* Flags - used by providers, e.g. */
317 /* Some updates may be generated by notifications: allow the
318 * plugin to notice and ignore results from its own notifications.
320 uint32_t zd_notif_provider
;
322 /* TODO -- internal/sub-operation status? */
323 enum zebra_dplane_result zd_remote_status
;
324 enum zebra_dplane_result zd_kernel_status
;
327 uint32_t zd_table_id
;
329 char zd_ifname
[INTERFACE_NAMSIZ
];
330 ifindex_t zd_ifindex
;
332 /* Support info for different kinds of updates */
334 struct dplane_route_info rinfo
;
335 struct zebra_lsp lsp
;
336 struct dplane_pw_info pw
;
337 struct dplane_br_port_info br_port
;
338 struct dplane_intf_info intf
;
339 struct dplane_mac_info macinfo
;
340 struct dplane_neigh_info neigh
;
341 struct dplane_rule_info rule
;
342 struct zebra_pbr_iptable iptable
;
343 struct zebra_pbr_ipset ipset
;
345 struct zebra_pbr_ipset_entry entry
;
346 struct zebra_pbr_ipset_info info
;
348 struct dplane_neigh_table neightable
;
349 struct dplane_gre_ctx gre
;
352 /* Namespace info, used especially for netlink kernel communication */
353 struct zebra_dplane_info zd_ns_info
;
355 /* Embedded list linkage */
356 TAILQ_ENTRY(zebra_dplane_ctx
) zd_q_entries
;
359 /* Flag that can be set by a pre-kernel provider as a signal that an update
360 * should bypass the kernel.
362 #define DPLANE_CTX_FLAG_NO_KERNEL 0x01
366 * Registration block for one dataplane provider.
368 struct zebra_dplane_provider
{
370 char dp_name
[DPLANE_PROVIDER_NAMELEN
+ 1];
372 /* Priority, for ordering among providers */
379 pthread_mutex_t dp_mutex
;
381 /* Plugin-provided extra data */
387 int (*dp_start
)(struct zebra_dplane_provider
*prov
);
389 int (*dp_fp
)(struct zebra_dplane_provider
*prov
);
391 int (*dp_fini
)(struct zebra_dplane_provider
*prov
, bool early_p
);
393 _Atomic
uint32_t dp_in_counter
;
394 _Atomic
uint32_t dp_in_queued
;
395 _Atomic
uint32_t dp_in_max
;
396 _Atomic
uint32_t dp_out_counter
;
397 _Atomic
uint32_t dp_out_queued
;
398 _Atomic
uint32_t dp_out_max
;
399 _Atomic
uint32_t dp_error_counter
;
401 /* Queue of contexts inbound to the provider */
402 struct dplane_ctx_q dp_ctx_in_q
;
404 /* Queue of completed contexts outbound from the provider back
405 * towards the dataplane module.
407 struct dplane_ctx_q dp_ctx_out_q
;
409 /* Embedded list linkage for provider objects */
410 TAILQ_ENTRY(zebra_dplane_provider
) dp_prov_link
;
413 /* Declare types for list of zns info objects */
414 PREDECL_DLIST(zns_info_list
);
416 struct dplane_zns_info
{
417 struct zebra_dplane_info info
;
420 struct thread
*t_read
;
423 struct zns_info_list_item link
;
429 static struct zebra_dplane_globals
{
430 /* Mutex to control access to dataplane components */
431 pthread_mutex_t dg_mutex
;
433 /* Results callback registered by zebra 'core' */
434 int (*dg_results_cb
)(struct dplane_ctx_q
*ctxlist
);
436 /* Sentinel for beginning of shutdown */
437 volatile bool dg_is_shutdown
;
439 /* Sentinel for end of shutdown */
440 volatile bool dg_run
;
442 /* Update context queue inbound to the dataplane */
443 TAILQ_HEAD(zdg_ctx_q
, zebra_dplane_ctx
) dg_update_ctx_q
;
445 /* Ordered list of providers */
446 TAILQ_HEAD(zdg_prov_q
, zebra_dplane_provider
) dg_providers_q
;
448 /* List of info about each zns */
449 struct zns_info_list_head dg_zns_list
;
451 /* Counter used to assign internal ids to providers */
452 uint32_t dg_provider_id
;
454 /* Limit number of pending, unprocessed updates */
455 _Atomic
uint32_t dg_max_queued_updates
;
457 /* Control whether system route notifications should be produced. */
458 bool dg_sys_route_notifs
;
460 /* Limit number of new updates dequeued at once, to pace an
463 uint32_t dg_updates_per_cycle
;
465 _Atomic
uint32_t dg_routes_in
;
466 _Atomic
uint32_t dg_routes_queued
;
467 _Atomic
uint32_t dg_routes_queued_max
;
468 _Atomic
uint32_t dg_route_errors
;
469 _Atomic
uint32_t dg_other_errors
;
471 _Atomic
uint32_t dg_nexthops_in
;
472 _Atomic
uint32_t dg_nexthop_errors
;
474 _Atomic
uint32_t dg_lsps_in
;
475 _Atomic
uint32_t dg_lsp_errors
;
477 _Atomic
uint32_t dg_pws_in
;
478 _Atomic
uint32_t dg_pw_errors
;
480 _Atomic
uint32_t dg_br_port_in
;
481 _Atomic
uint32_t dg_br_port_errors
;
483 _Atomic
uint32_t dg_intf_addrs_in
;
484 _Atomic
uint32_t dg_intf_addr_errors
;
486 _Atomic
uint32_t dg_macs_in
;
487 _Atomic
uint32_t dg_mac_errors
;
489 _Atomic
uint32_t dg_neighs_in
;
490 _Atomic
uint32_t dg_neigh_errors
;
492 _Atomic
uint32_t dg_rules_in
;
493 _Atomic
uint32_t dg_rule_errors
;
495 _Atomic
uint32_t dg_update_yields
;
497 _Atomic
uint32_t dg_iptable_in
;
498 _Atomic
uint32_t dg_iptable_errors
;
500 _Atomic
uint32_t dg_ipset_in
;
501 _Atomic
uint32_t dg_ipset_errors
;
502 _Atomic
uint32_t dg_ipset_entry_in
;
503 _Atomic
uint32_t dg_ipset_entry_errors
;
505 _Atomic
uint32_t dg_neightable_in
;
506 _Atomic
uint32_t dg_neightable_errors
;
508 _Atomic
uint32_t dg_gre_set_in
;
509 _Atomic
uint32_t dg_gre_set_errors
;
511 /* Dataplane pthread */
512 struct frr_pthread
*dg_pthread
;
514 /* Event-delivery context 'master' for the dplane */
515 struct thread_master
*dg_master
;
517 /* Event/'thread' pointer for queued updates */
518 struct thread
*dg_t_update
;
520 /* Event pointer for pending shutdown check loop */
521 struct thread
*dg_t_shutdown_check
;
525 /* Instantiate zns list type */
526 DECLARE_DLIST(zns_info_list
, struct dplane_zns_info
, link
);
529 * Lock and unlock for interactions with the zebra 'core' pthread
531 #define DPLANE_LOCK() pthread_mutex_lock(&zdplane_info.dg_mutex)
532 #define DPLANE_UNLOCK() pthread_mutex_unlock(&zdplane_info.dg_mutex)
536 * Lock and unlock for individual providers
538 #define DPLANE_PROV_LOCK(p) pthread_mutex_lock(&((p)->dp_mutex))
539 #define DPLANE_PROV_UNLOCK(p) pthread_mutex_unlock(&((p)->dp_mutex))
542 static int dplane_thread_loop(struct thread
*event
);
543 static void dplane_info_from_zns(struct zebra_dplane_info
*ns_info
,
544 struct zebra_ns
*zns
);
545 static enum zebra_dplane_result
lsp_update_internal(struct zebra_lsp
*lsp
,
546 enum dplane_op_e op
);
547 static enum zebra_dplane_result
pw_update_internal(struct zebra_pw
*pw
,
548 enum dplane_op_e op
);
549 static enum zebra_dplane_result
intf_addr_update_internal(
550 const struct interface
*ifp
, const struct connected
*ifc
,
551 enum dplane_op_e op
);
552 static enum zebra_dplane_result
mac_update_common(
553 enum dplane_op_e op
, const struct interface
*ifp
,
554 const struct interface
*br_ifp
,
555 vlanid_t vid
, const struct ethaddr
*mac
,
556 struct in_addr vtep_ip
, bool sticky
, uint32_t nhg_id
,
557 uint32_t update_flags
);
558 static enum zebra_dplane_result
559 neigh_update_internal(enum dplane_op_e op
, const struct interface
*ifp
,
560 const void *link
, int link_family
,
561 const struct ipaddr
*ip
, uint32_t flags
, uint16_t state
,
562 uint32_t update_flags
, int protocol
);
568 /* Obtain thread_master for dataplane thread */
569 struct thread_master
*dplane_get_thread_master(void)
571 return zdplane_info
.dg_master
;
575 * Allocate a dataplane update context
577 struct zebra_dplane_ctx
*dplane_ctx_alloc(void)
579 struct zebra_dplane_ctx
*p
;
581 /* TODO -- just alloc'ing memory, but would like to maintain
584 p
= XCALLOC(MTYPE_DP_CTX
, sizeof(struct zebra_dplane_ctx
));
589 /* Enable system route notifications */
590 void dplane_enable_sys_route_notifs(void)
592 zdplane_info
.dg_sys_route_notifs
= true;
596 * Clean up dependent/internal allocations inside a context object
598 static void dplane_ctx_free_internal(struct zebra_dplane_ctx
*ctx
)
600 struct dplane_intf_extra
*if_extra
, *if_tmp
;
603 * Some internal allocations may need to be freed, depending on
604 * the type of info captured in the ctx.
606 switch (ctx
->zd_op
) {
607 case DPLANE_OP_ROUTE_INSTALL
:
608 case DPLANE_OP_ROUTE_UPDATE
:
609 case DPLANE_OP_ROUTE_DELETE
:
610 case DPLANE_OP_SYS_ROUTE_ADD
:
611 case DPLANE_OP_SYS_ROUTE_DELETE
:
612 case DPLANE_OP_ROUTE_NOTIFY
:
614 /* Free allocated nexthops */
615 if (ctx
->u
.rinfo
.zd_ng
.nexthop
) {
616 /* This deals with recursive nexthops too */
617 nexthops_free(ctx
->u
.rinfo
.zd_ng
.nexthop
);
619 ctx
->u
.rinfo
.zd_ng
.nexthop
= NULL
;
622 /* Free backup info also (if present) */
623 if (ctx
->u
.rinfo
.backup_ng
.nexthop
) {
624 /* This deals with recursive nexthops too */
625 nexthops_free(ctx
->u
.rinfo
.backup_ng
.nexthop
);
627 ctx
->u
.rinfo
.backup_ng
.nexthop
= NULL
;
630 if (ctx
->u
.rinfo
.zd_old_ng
.nexthop
) {
631 /* This deals with recursive nexthops too */
632 nexthops_free(ctx
->u
.rinfo
.zd_old_ng
.nexthop
);
634 ctx
->u
.rinfo
.zd_old_ng
.nexthop
= NULL
;
637 if (ctx
->u
.rinfo
.old_backup_ng
.nexthop
) {
638 /* This deals with recursive nexthops too */
639 nexthops_free(ctx
->u
.rinfo
.old_backup_ng
.nexthop
);
641 ctx
->u
.rinfo
.old_backup_ng
.nexthop
= NULL
;
644 /* Optional extra interface info */
645 TAILQ_FOREACH_SAFE(if_extra
, &ctx
->u
.rinfo
.intf_extra_q
,
647 TAILQ_REMOVE(&ctx
->u
.rinfo
.intf_extra_q
, if_extra
,
649 XFREE(MTYPE_DP_INTF
, if_extra
);
654 case DPLANE_OP_NH_INSTALL
:
655 case DPLANE_OP_NH_UPDATE
:
656 case DPLANE_OP_NH_DELETE
: {
657 if (ctx
->u
.rinfo
.nhe
.ng
.nexthop
) {
658 /* This deals with recursive nexthops too */
659 nexthops_free(ctx
->u
.rinfo
.nhe
.ng
.nexthop
);
661 ctx
->u
.rinfo
.nhe
.ng
.nexthop
= NULL
;
666 case DPLANE_OP_LSP_INSTALL
:
667 case DPLANE_OP_LSP_UPDATE
:
668 case DPLANE_OP_LSP_DELETE
:
669 case DPLANE_OP_LSP_NOTIFY
:
671 struct zebra_nhlfe
*nhlfe
;
673 /* Unlink and free allocated NHLFEs */
674 frr_each_safe(nhlfe_list
, &ctx
->u
.lsp
.nhlfe_list
, nhlfe
) {
675 nhlfe_list_del(&ctx
->u
.lsp
.nhlfe_list
, nhlfe
);
676 zebra_mpls_nhlfe_free(nhlfe
);
679 /* Unlink and free allocated backup NHLFEs, if present */
680 frr_each_safe(nhlfe_list
,
681 &(ctx
->u
.lsp
.backup_nhlfe_list
), nhlfe
) {
682 nhlfe_list_del(&ctx
->u
.lsp
.backup_nhlfe_list
,
684 zebra_mpls_nhlfe_free(nhlfe
);
687 /* Clear pointers in lsp struct, in case we're caching
688 * free context structs.
690 nhlfe_list_init(&ctx
->u
.lsp
.nhlfe_list
);
691 ctx
->u
.lsp
.best_nhlfe
= NULL
;
692 nhlfe_list_init(&ctx
->u
.lsp
.backup_nhlfe_list
);
697 case DPLANE_OP_PW_INSTALL
:
698 case DPLANE_OP_PW_UNINSTALL
:
699 /* Free allocated nexthops */
700 if (ctx
->u
.pw
.fib_nhg
.nexthop
) {
701 /* This deals with recursive nexthops too */
702 nexthops_free(ctx
->u
.pw
.fib_nhg
.nexthop
);
704 ctx
->u
.pw
.fib_nhg
.nexthop
= NULL
;
706 if (ctx
->u
.pw
.primary_nhg
.nexthop
) {
707 nexthops_free(ctx
->u
.pw
.primary_nhg
.nexthop
);
709 ctx
->u
.pw
.primary_nhg
.nexthop
= NULL
;
711 if (ctx
->u
.pw
.backup_nhg
.nexthop
) {
712 nexthops_free(ctx
->u
.pw
.backup_nhg
.nexthop
);
714 ctx
->u
.pw
.backup_nhg
.nexthop
= NULL
;
718 case DPLANE_OP_ADDR_INSTALL
:
719 case DPLANE_OP_ADDR_UNINSTALL
:
720 case DPLANE_OP_INTF_ADDR_ADD
:
721 case DPLANE_OP_INTF_ADDR_DEL
:
722 /* Maybe free label string, if allocated */
723 if (ctx
->u
.intf
.label
!= NULL
&&
724 ctx
->u
.intf
.label
!= ctx
->u
.intf
.label_buf
) {
725 free(ctx
->u
.intf
.label
);
726 ctx
->u
.intf
.label
= NULL
;
730 case DPLANE_OP_MAC_INSTALL
:
731 case DPLANE_OP_MAC_DELETE
:
732 case DPLANE_OP_NEIGH_INSTALL
:
733 case DPLANE_OP_NEIGH_UPDATE
:
734 case DPLANE_OP_NEIGH_DELETE
:
735 case DPLANE_OP_VTEP_ADD
:
736 case DPLANE_OP_VTEP_DELETE
:
737 case DPLANE_OP_RULE_ADD
:
738 case DPLANE_OP_RULE_DELETE
:
739 case DPLANE_OP_RULE_UPDATE
:
740 case DPLANE_OP_NEIGH_DISCOVER
:
741 case DPLANE_OP_BR_PORT_UPDATE
:
742 case DPLANE_OP_NEIGH_IP_INSTALL
:
743 case DPLANE_OP_NEIGH_IP_DELETE
:
745 case DPLANE_OP_IPSET_ADD
:
746 case DPLANE_OP_IPSET_DELETE
:
749 case DPLANE_OP_IPSET_ENTRY_ADD
:
750 case DPLANE_OP_IPSET_ENTRY_DELETE
:
752 case DPLANE_OP_NEIGH_TABLE_UPDATE
:
754 case DPLANE_OP_IPTABLE_ADD
:
755 case DPLANE_OP_IPTABLE_DELETE
:
756 if (ctx
->u
.iptable
.interface_name_list
) {
757 struct listnode
*node
, *nnode
;
760 for (ALL_LIST_ELEMENTS(
761 ctx
->u
.iptable
.interface_name_list
, node
,
764 ctx
->u
.iptable
.interface_name_list
,
766 XFREE(MTYPE_DP_NETFILTER
, ifname
);
768 list_delete(&ctx
->u
.iptable
.interface_name_list
);
771 case DPLANE_OP_GRE_SET
:
777 * Free a dataplane results context.
779 static void dplane_ctx_free(struct zebra_dplane_ctx
**pctx
)
784 DPLANE_CTX_VALID(*pctx
);
786 /* TODO -- just freeing memory, but would like to maintain
790 /* Some internal allocations may need to be freed, depending on
791 * the type of info captured in the ctx.
793 dplane_ctx_free_internal(*pctx
);
795 XFREE(MTYPE_DP_CTX
, *pctx
);
799 * Reset an allocated context object for re-use. All internal allocations are
800 * freed and the context is memset.
802 void dplane_ctx_reset(struct zebra_dplane_ctx
*ctx
)
804 dplane_ctx_free_internal(ctx
);
805 memset(ctx
, 0, sizeof(*ctx
));
809 * Return a context block to the dplane module after processing
811 void dplane_ctx_fini(struct zebra_dplane_ctx
**pctx
)
813 /* TODO -- maintain pool; for now, just free */
814 dplane_ctx_free(pctx
);
817 /* Enqueue a context block */
818 void dplane_ctx_enqueue_tail(struct dplane_ctx_q
*q
,
819 const struct zebra_dplane_ctx
*ctx
)
821 TAILQ_INSERT_TAIL(q
, (struct zebra_dplane_ctx
*)ctx
, zd_q_entries
);
824 /* Append a list of context blocks to another list */
825 void dplane_ctx_list_append(struct dplane_ctx_q
*to_list
,
826 struct dplane_ctx_q
*from_list
)
828 if (TAILQ_FIRST(from_list
)) {
829 TAILQ_CONCAT(to_list
, from_list
, zd_q_entries
);
831 /* And clear 'from' list */
832 TAILQ_INIT(from_list
);
836 struct zebra_dplane_ctx
*dplane_ctx_get_head(struct dplane_ctx_q
*q
)
838 struct zebra_dplane_ctx
*ctx
= TAILQ_FIRST(q
);
843 /* Dequeue a context block from the head of a list */
844 struct zebra_dplane_ctx
*dplane_ctx_dequeue(struct dplane_ctx_q
*q
)
846 struct zebra_dplane_ctx
*ctx
= TAILQ_FIRST(q
);
849 TAILQ_REMOVE(q
, ctx
, zd_q_entries
);
855 * Accessors for information from the context object
857 enum zebra_dplane_result
dplane_ctx_get_status(
858 const struct zebra_dplane_ctx
*ctx
)
860 DPLANE_CTX_VALID(ctx
);
862 return ctx
->zd_status
;
865 void dplane_ctx_set_status(struct zebra_dplane_ctx
*ctx
,
866 enum zebra_dplane_result status
)
868 DPLANE_CTX_VALID(ctx
);
870 ctx
->zd_status
= status
;
873 /* Retrieve last/current provider id */
874 uint32_t dplane_ctx_get_provider(const struct zebra_dplane_ctx
*ctx
)
876 DPLANE_CTX_VALID(ctx
);
877 return ctx
->zd_provider
;
880 /* Providers run before the kernel can control whether a kernel
881 * update should be done.
883 void dplane_ctx_set_skip_kernel(struct zebra_dplane_ctx
*ctx
)
885 DPLANE_CTX_VALID(ctx
);
887 SET_FLAG(ctx
->zd_flags
, DPLANE_CTX_FLAG_NO_KERNEL
);
890 bool dplane_ctx_is_skip_kernel(const struct zebra_dplane_ctx
*ctx
)
892 DPLANE_CTX_VALID(ctx
);
894 return CHECK_FLAG(ctx
->zd_flags
, DPLANE_CTX_FLAG_NO_KERNEL
);
897 void dplane_ctx_set_op(struct zebra_dplane_ctx
*ctx
, enum dplane_op_e op
)
899 DPLANE_CTX_VALID(ctx
);
903 enum dplane_op_e
dplane_ctx_get_op(const struct zebra_dplane_ctx
*ctx
)
905 DPLANE_CTX_VALID(ctx
);
910 const char *dplane_op2str(enum dplane_op_e op
)
912 const char *ret
= "UNKNOWN";
920 case DPLANE_OP_ROUTE_INSTALL
:
921 ret
= "ROUTE_INSTALL";
923 case DPLANE_OP_ROUTE_UPDATE
:
924 ret
= "ROUTE_UPDATE";
926 case DPLANE_OP_ROUTE_DELETE
:
927 ret
= "ROUTE_DELETE";
929 case DPLANE_OP_ROUTE_NOTIFY
:
930 ret
= "ROUTE_NOTIFY";
934 case DPLANE_OP_NH_INSTALL
:
937 case DPLANE_OP_NH_UPDATE
:
940 case DPLANE_OP_NH_DELETE
:
944 case DPLANE_OP_LSP_INSTALL
:
947 case DPLANE_OP_LSP_UPDATE
:
950 case DPLANE_OP_LSP_DELETE
:
953 case DPLANE_OP_LSP_NOTIFY
:
957 case DPLANE_OP_PW_INSTALL
:
960 case DPLANE_OP_PW_UNINSTALL
:
961 ret
= "PW_UNINSTALL";
964 case DPLANE_OP_SYS_ROUTE_ADD
:
965 ret
= "SYS_ROUTE_ADD";
967 case DPLANE_OP_SYS_ROUTE_DELETE
:
968 ret
= "SYS_ROUTE_DEL";
971 case DPLANE_OP_BR_PORT_UPDATE
:
972 ret
= "BR_PORT_UPDATE";
975 case DPLANE_OP_ADDR_INSTALL
:
976 ret
= "ADDR_INSTALL";
978 case DPLANE_OP_ADDR_UNINSTALL
:
979 ret
= "ADDR_UNINSTALL";
982 case DPLANE_OP_MAC_INSTALL
:
985 case DPLANE_OP_MAC_DELETE
:
989 case DPLANE_OP_NEIGH_INSTALL
:
990 ret
= "NEIGH_INSTALL";
992 case DPLANE_OP_NEIGH_UPDATE
:
993 ret
= "NEIGH_UPDATE";
995 case DPLANE_OP_NEIGH_DELETE
:
996 ret
= "NEIGH_DELETE";
998 case DPLANE_OP_VTEP_ADD
:
1001 case DPLANE_OP_VTEP_DELETE
:
1002 ret
= "VTEP_DELETE";
1005 case DPLANE_OP_RULE_ADD
:
1008 case DPLANE_OP_RULE_DELETE
:
1009 ret
= "RULE_DELETE";
1011 case DPLANE_OP_RULE_UPDATE
:
1012 ret
= "RULE_UPDATE";
1015 case DPLANE_OP_NEIGH_DISCOVER
:
1016 ret
= "NEIGH_DISCOVER";
1019 case DPLANE_OP_IPTABLE_ADD
:
1020 ret
= "IPTABLE_ADD";
1022 case DPLANE_OP_IPTABLE_DELETE
:
1023 ret
= "IPTABLE_DELETE";
1025 case DPLANE_OP_IPSET_ADD
:
1028 case DPLANE_OP_IPSET_DELETE
:
1029 ret
= "IPSET_DELETE";
1031 case DPLANE_OP_IPSET_ENTRY_ADD
:
1032 ret
= "IPSET_ENTRY_ADD";
1034 case DPLANE_OP_IPSET_ENTRY_DELETE
:
1035 ret
= "IPSET_ENTRY_DELETE";
1037 case DPLANE_OP_NEIGH_IP_INSTALL
:
1038 ret
= "NEIGH_IP_INSTALL";
1040 case DPLANE_OP_NEIGH_IP_DELETE
:
1041 ret
= "NEIGH_IP_DELETE";
1043 case DPLANE_OP_NEIGH_TABLE_UPDATE
:
1044 ret
= "NEIGH_TABLE_UPDATE";
1047 case DPLANE_OP_GRE_SET
:
1051 case DPLANE_OP_INTF_ADDR_ADD
:
1052 return "INTF_ADDR_ADD";
1054 case DPLANE_OP_INTF_ADDR_DEL
:
1055 return "INTF_ADDR_DEL";
1061 const char *dplane_res2str(enum zebra_dplane_result res
)
1063 const char *ret
= "<Unknown>";
1066 case ZEBRA_DPLANE_REQUEST_FAILURE
:
1069 case ZEBRA_DPLANE_REQUEST_QUEUED
:
1072 case ZEBRA_DPLANE_REQUEST_SUCCESS
:
1080 void dplane_ctx_set_dest(struct zebra_dplane_ctx
*ctx
,
1081 const struct prefix
*dest
)
1083 DPLANE_CTX_VALID(ctx
);
1085 prefix_copy(&(ctx
->u
.rinfo
.zd_dest
), dest
);
1088 const struct prefix
*dplane_ctx_get_dest(const struct zebra_dplane_ctx
*ctx
)
1090 DPLANE_CTX_VALID(ctx
);
1092 return &(ctx
->u
.rinfo
.zd_dest
);
1095 void dplane_ctx_set_src(struct zebra_dplane_ctx
*ctx
, const struct prefix
*src
)
1097 DPLANE_CTX_VALID(ctx
);
1100 prefix_copy(&(ctx
->u
.rinfo
.zd_src
), src
);
1102 memset(&(ctx
->u
.rinfo
.zd_src
), 0, sizeof(struct prefix
));
1105 /* Source prefix is a little special - return NULL for "no src prefix" */
1106 const struct prefix
*dplane_ctx_get_src(const struct zebra_dplane_ctx
*ctx
)
1108 DPLANE_CTX_VALID(ctx
);
1110 if (ctx
->u
.rinfo
.zd_src
.prefixlen
== 0 &&
1111 IN6_IS_ADDR_UNSPECIFIED(&(ctx
->u
.rinfo
.zd_src
.u
.prefix6
))) {
1114 return &(ctx
->u
.rinfo
.zd_src
);
1118 bool dplane_ctx_is_update(const struct zebra_dplane_ctx
*ctx
)
1120 DPLANE_CTX_VALID(ctx
);
1122 return ctx
->zd_is_update
;
1125 uint32_t dplane_ctx_get_seq(const struct zebra_dplane_ctx
*ctx
)
1127 DPLANE_CTX_VALID(ctx
);
1132 uint32_t dplane_ctx_get_old_seq(const struct zebra_dplane_ctx
*ctx
)
1134 DPLANE_CTX_VALID(ctx
);
1136 return ctx
->zd_old_seq
;
1139 void dplane_ctx_set_vrf(struct zebra_dplane_ctx
*ctx
, vrf_id_t vrf
)
1141 DPLANE_CTX_VALID(ctx
);
1143 ctx
->zd_vrf_id
= vrf
;
1146 vrf_id_t
dplane_ctx_get_vrf(const struct zebra_dplane_ctx
*ctx
)
1148 DPLANE_CTX_VALID(ctx
);
1150 return ctx
->zd_vrf_id
;
1153 /* In some paths we have only a namespace id */
1154 void dplane_ctx_set_ns_id(struct zebra_dplane_ctx
*ctx
, ns_id_t nsid
)
1156 DPLANE_CTX_VALID(ctx
);
1158 ctx
->zd_ns_info
.ns_id
= nsid
;
1161 ns_id_t
dplane_ctx_get_ns_id(const struct zebra_dplane_ctx
*ctx
)
1163 DPLANE_CTX_VALID(ctx
);
1165 return ctx
->zd_ns_info
.ns_id
;
1168 bool dplane_ctx_is_from_notif(const struct zebra_dplane_ctx
*ctx
)
1170 DPLANE_CTX_VALID(ctx
);
1172 return (ctx
->zd_notif_provider
!= 0);
1175 uint32_t dplane_ctx_get_notif_provider(const struct zebra_dplane_ctx
*ctx
)
1177 DPLANE_CTX_VALID(ctx
);
1179 return ctx
->zd_notif_provider
;
1182 void dplane_ctx_set_notif_provider(struct zebra_dplane_ctx
*ctx
,
1185 DPLANE_CTX_VALID(ctx
);
1187 ctx
->zd_notif_provider
= id
;
1190 const char *dplane_ctx_get_ifname(const struct zebra_dplane_ctx
*ctx
)
1192 DPLANE_CTX_VALID(ctx
);
1194 return ctx
->zd_ifname
;
1197 void dplane_ctx_set_ifname(struct zebra_dplane_ctx
*ctx
, const char *ifname
)
1199 DPLANE_CTX_VALID(ctx
);
1204 strlcpy(ctx
->zd_ifname
, ifname
, sizeof(ctx
->zd_ifname
));
1207 ifindex_t
dplane_ctx_get_ifindex(const struct zebra_dplane_ctx
*ctx
)
1209 DPLANE_CTX_VALID(ctx
);
1211 return ctx
->zd_ifindex
;
1214 void dplane_ctx_set_ifindex(struct zebra_dplane_ctx
*ctx
, ifindex_t ifindex
)
1216 DPLANE_CTX_VALID(ctx
);
1218 ctx
->zd_ifindex
= ifindex
;
1221 void dplane_ctx_set_type(struct zebra_dplane_ctx
*ctx
, int type
)
1223 DPLANE_CTX_VALID(ctx
);
1225 ctx
->u
.rinfo
.zd_type
= type
;
1228 int dplane_ctx_get_type(const struct zebra_dplane_ctx
*ctx
)
1230 DPLANE_CTX_VALID(ctx
);
1232 return ctx
->u
.rinfo
.zd_type
;
1235 int dplane_ctx_get_old_type(const struct zebra_dplane_ctx
*ctx
)
1237 DPLANE_CTX_VALID(ctx
);
1239 return ctx
->u
.rinfo
.zd_old_type
;
1242 void dplane_ctx_set_afi(struct zebra_dplane_ctx
*ctx
, afi_t afi
)
1244 DPLANE_CTX_VALID(ctx
);
1246 ctx
->u
.rinfo
.zd_afi
= afi
;
1249 afi_t
dplane_ctx_get_afi(const struct zebra_dplane_ctx
*ctx
)
1251 DPLANE_CTX_VALID(ctx
);
1253 return ctx
->u
.rinfo
.zd_afi
;
1256 void dplane_ctx_set_safi(struct zebra_dplane_ctx
*ctx
, safi_t safi
)
1258 DPLANE_CTX_VALID(ctx
);
1260 ctx
->u
.rinfo
.zd_safi
= safi
;
1263 safi_t
dplane_ctx_get_safi(const struct zebra_dplane_ctx
*ctx
)
1265 DPLANE_CTX_VALID(ctx
);
1267 return ctx
->u
.rinfo
.zd_safi
;
1270 void dplane_ctx_set_table(struct zebra_dplane_ctx
*ctx
, uint32_t table
)
1272 DPLANE_CTX_VALID(ctx
);
1274 ctx
->zd_table_id
= table
;
1277 uint32_t dplane_ctx_get_table(const struct zebra_dplane_ctx
*ctx
)
1279 DPLANE_CTX_VALID(ctx
);
1281 return ctx
->zd_table_id
;
1284 route_tag_t
dplane_ctx_get_tag(const struct zebra_dplane_ctx
*ctx
)
1286 DPLANE_CTX_VALID(ctx
);
1288 return ctx
->u
.rinfo
.zd_tag
;
1291 void dplane_ctx_set_tag(struct zebra_dplane_ctx
*ctx
, route_tag_t tag
)
1293 DPLANE_CTX_VALID(ctx
);
1295 ctx
->u
.rinfo
.zd_tag
= tag
;
1298 route_tag_t
dplane_ctx_get_old_tag(const struct zebra_dplane_ctx
*ctx
)
1300 DPLANE_CTX_VALID(ctx
);
1302 return ctx
->u
.rinfo
.zd_old_tag
;
1305 uint16_t dplane_ctx_get_instance(const struct zebra_dplane_ctx
*ctx
)
1307 DPLANE_CTX_VALID(ctx
);
1309 return ctx
->u
.rinfo
.zd_instance
;
1312 void dplane_ctx_set_instance(struct zebra_dplane_ctx
*ctx
, uint16_t instance
)
1314 DPLANE_CTX_VALID(ctx
);
1316 ctx
->u
.rinfo
.zd_instance
= instance
;
1319 uint16_t dplane_ctx_get_old_instance(const struct zebra_dplane_ctx
*ctx
)
1321 DPLANE_CTX_VALID(ctx
);
1323 return ctx
->u
.rinfo
.zd_old_instance
;
1326 uint32_t dplane_ctx_get_metric(const struct zebra_dplane_ctx
*ctx
)
1328 DPLANE_CTX_VALID(ctx
);
1330 return ctx
->u
.rinfo
.zd_metric
;
1333 uint32_t dplane_ctx_get_old_metric(const struct zebra_dplane_ctx
*ctx
)
1335 DPLANE_CTX_VALID(ctx
);
1337 return ctx
->u
.rinfo
.zd_old_metric
;
1340 uint32_t dplane_ctx_get_mtu(const struct zebra_dplane_ctx
*ctx
)
1342 DPLANE_CTX_VALID(ctx
);
1344 return ctx
->u
.rinfo
.zd_mtu
;
1347 uint32_t dplane_ctx_get_nh_mtu(const struct zebra_dplane_ctx
*ctx
)
1349 DPLANE_CTX_VALID(ctx
);
1351 return ctx
->u
.rinfo
.zd_nexthop_mtu
;
1354 uint8_t dplane_ctx_get_distance(const struct zebra_dplane_ctx
*ctx
)
1356 DPLANE_CTX_VALID(ctx
);
1358 return ctx
->u
.rinfo
.zd_distance
;
1361 void dplane_ctx_set_distance(struct zebra_dplane_ctx
*ctx
, uint8_t distance
)
1363 DPLANE_CTX_VALID(ctx
);
1365 ctx
->u
.rinfo
.zd_distance
= distance
;
1368 uint8_t dplane_ctx_get_old_distance(const struct zebra_dplane_ctx
*ctx
)
1370 DPLANE_CTX_VALID(ctx
);
1372 return ctx
->u
.rinfo
.zd_old_distance
;
1376 * Set the nexthops associated with a context: note that processing code
1377 * may well expect that nexthops are in canonical (sorted) order, so we
1378 * will enforce that here.
1380 void dplane_ctx_set_nexthops(struct zebra_dplane_ctx
*ctx
, struct nexthop
*nh
)
1382 DPLANE_CTX_VALID(ctx
);
1384 if (ctx
->u
.rinfo
.zd_ng
.nexthop
) {
1385 nexthops_free(ctx
->u
.rinfo
.zd_ng
.nexthop
);
1386 ctx
->u
.rinfo
.zd_ng
.nexthop
= NULL
;
1388 nexthop_group_copy_nh_sorted(&(ctx
->u
.rinfo
.zd_ng
), nh
);
1392 * Set the list of backup nexthops; their ordering is preserved (they're not
1395 void dplane_ctx_set_backup_nhg(struct zebra_dplane_ctx
*ctx
,
1396 const struct nexthop_group
*nhg
)
1398 struct nexthop
*nh
, *last_nh
, *nexthop
;
1400 DPLANE_CTX_VALID(ctx
);
1402 if (ctx
->u
.rinfo
.backup_ng
.nexthop
) {
1403 nexthops_free(ctx
->u
.rinfo
.backup_ng
.nexthop
);
1404 ctx
->u
.rinfo
.backup_ng
.nexthop
= NULL
;
1409 /* Be careful to preserve the order of the backup list */
1410 for (nh
= nhg
->nexthop
; nh
; nh
= nh
->next
) {
1411 nexthop
= nexthop_dup(nh
, NULL
);
1414 NEXTHOP_APPEND(last_nh
, nexthop
);
1416 ctx
->u
.rinfo
.backup_ng
.nexthop
= nexthop
;
1422 uint32_t dplane_ctx_get_nhg_id(const struct zebra_dplane_ctx
*ctx
)
1424 DPLANE_CTX_VALID(ctx
);
1425 return ctx
->u
.rinfo
.zd_nhg_id
;
1428 const struct nexthop_group
*dplane_ctx_get_ng(
1429 const struct zebra_dplane_ctx
*ctx
)
1431 DPLANE_CTX_VALID(ctx
);
1433 return &(ctx
->u
.rinfo
.zd_ng
);
1436 const struct nexthop_group
*
1437 dplane_ctx_get_backup_ng(const struct zebra_dplane_ctx
*ctx
)
1439 DPLANE_CTX_VALID(ctx
);
1441 return &(ctx
->u
.rinfo
.backup_ng
);
1444 const struct nexthop_group
*
1445 dplane_ctx_get_old_ng(const struct zebra_dplane_ctx
*ctx
)
1447 DPLANE_CTX_VALID(ctx
);
1449 return &(ctx
->u
.rinfo
.zd_old_ng
);
1452 const struct nexthop_group
*
1453 dplane_ctx_get_old_backup_ng(const struct zebra_dplane_ctx
*ctx
)
1455 DPLANE_CTX_VALID(ctx
);
1457 return &(ctx
->u
.rinfo
.old_backup_ng
);
1460 const struct zebra_dplane_info
*dplane_ctx_get_ns(
1461 const struct zebra_dplane_ctx
*ctx
)
1463 DPLANE_CTX_VALID(ctx
);
1465 return &(ctx
->zd_ns_info
);
1468 int dplane_ctx_get_ns_sock(const struct zebra_dplane_ctx
*ctx
)
1470 DPLANE_CTX_VALID(ctx
);
1473 return ctx
->zd_ns_info
.sock
;
1479 /* Accessors for nexthop information */
1480 uint32_t dplane_ctx_get_nhe_id(const struct zebra_dplane_ctx
*ctx
)
1482 DPLANE_CTX_VALID(ctx
);
1483 return ctx
->u
.rinfo
.nhe
.id
;
1486 uint32_t dplane_ctx_get_old_nhe_id(const struct zebra_dplane_ctx
*ctx
)
1488 DPLANE_CTX_VALID(ctx
);
1489 return ctx
->u
.rinfo
.nhe
.old_id
;
1492 afi_t
dplane_ctx_get_nhe_afi(const struct zebra_dplane_ctx
*ctx
)
1494 DPLANE_CTX_VALID(ctx
);
1495 return ctx
->u
.rinfo
.nhe
.afi
;
1498 vrf_id_t
dplane_ctx_get_nhe_vrf_id(const struct zebra_dplane_ctx
*ctx
)
1500 DPLANE_CTX_VALID(ctx
);
1501 return ctx
->u
.rinfo
.nhe
.vrf_id
;
1504 int dplane_ctx_get_nhe_type(const struct zebra_dplane_ctx
*ctx
)
1506 DPLANE_CTX_VALID(ctx
);
1507 return ctx
->u
.rinfo
.nhe
.type
;
1510 const struct nexthop_group
*
1511 dplane_ctx_get_nhe_ng(const struct zebra_dplane_ctx
*ctx
)
1513 DPLANE_CTX_VALID(ctx
);
1514 return &(ctx
->u
.rinfo
.nhe
.ng
);
1517 const struct nh_grp
*
1518 dplane_ctx_get_nhe_nh_grp(const struct zebra_dplane_ctx
*ctx
)
1520 DPLANE_CTX_VALID(ctx
);
1521 return ctx
->u
.rinfo
.nhe
.nh_grp
;
1524 uint8_t dplane_ctx_get_nhe_nh_grp_count(const struct zebra_dplane_ctx
*ctx
)
1526 DPLANE_CTX_VALID(ctx
);
1527 return ctx
->u
.rinfo
.nhe
.nh_grp_count
;
1530 /* Accessors for LSP information */
1532 mpls_label_t
dplane_ctx_get_in_label(const struct zebra_dplane_ctx
*ctx
)
1534 DPLANE_CTX_VALID(ctx
);
1536 return ctx
->u
.lsp
.ile
.in_label
;
1539 void dplane_ctx_set_in_label(struct zebra_dplane_ctx
*ctx
, mpls_label_t label
)
1541 DPLANE_CTX_VALID(ctx
);
1543 ctx
->u
.lsp
.ile
.in_label
= label
;
1546 uint8_t dplane_ctx_get_addr_family(const struct zebra_dplane_ctx
*ctx
)
1548 DPLANE_CTX_VALID(ctx
);
1550 return ctx
->u
.lsp
.addr_family
;
1553 void dplane_ctx_set_addr_family(struct zebra_dplane_ctx
*ctx
,
1556 DPLANE_CTX_VALID(ctx
);
1558 ctx
->u
.lsp
.addr_family
= family
;
1561 uint32_t dplane_ctx_get_lsp_flags(const struct zebra_dplane_ctx
*ctx
)
1563 DPLANE_CTX_VALID(ctx
);
1565 return ctx
->u
.lsp
.flags
;
1568 void dplane_ctx_set_lsp_flags(struct zebra_dplane_ctx
*ctx
,
1571 DPLANE_CTX_VALID(ctx
);
1573 ctx
->u
.lsp
.flags
= flags
;
1576 const struct nhlfe_list_head
*dplane_ctx_get_nhlfe_list(
1577 const struct zebra_dplane_ctx
*ctx
)
1579 DPLANE_CTX_VALID(ctx
);
1580 return &(ctx
->u
.lsp
.nhlfe_list
);
1583 const struct nhlfe_list_head
*dplane_ctx_get_backup_nhlfe_list(
1584 const struct zebra_dplane_ctx
*ctx
)
1586 DPLANE_CTX_VALID(ctx
);
1587 return &(ctx
->u
.lsp
.backup_nhlfe_list
);
1590 struct zebra_nhlfe
*dplane_ctx_add_nhlfe(struct zebra_dplane_ctx
*ctx
,
1591 enum lsp_types_t lsp_type
,
1592 enum nexthop_types_t nh_type
,
1593 const union g_addr
*gate
,
1594 ifindex_t ifindex
, uint8_t num_labels
,
1595 mpls_label_t
*out_labels
)
1597 struct zebra_nhlfe
*nhlfe
;
1599 DPLANE_CTX_VALID(ctx
);
1601 nhlfe
= zebra_mpls_lsp_add_nhlfe(&(ctx
->u
.lsp
),
1602 lsp_type
, nh_type
, gate
,
1603 ifindex
, num_labels
, out_labels
);
1608 struct zebra_nhlfe
*dplane_ctx_add_backup_nhlfe(
1609 struct zebra_dplane_ctx
*ctx
, enum lsp_types_t lsp_type
,
1610 enum nexthop_types_t nh_type
, const union g_addr
*gate
,
1611 ifindex_t ifindex
, uint8_t num_labels
, mpls_label_t
*out_labels
)
1613 struct zebra_nhlfe
*nhlfe
;
1615 DPLANE_CTX_VALID(ctx
);
1617 nhlfe
= zebra_mpls_lsp_add_backup_nhlfe(&(ctx
->u
.lsp
),
1618 lsp_type
, nh_type
, gate
,
1619 ifindex
, num_labels
,
1625 const struct zebra_nhlfe
*
1626 dplane_ctx_get_best_nhlfe(const struct zebra_dplane_ctx
*ctx
)
1628 DPLANE_CTX_VALID(ctx
);
1630 return ctx
->u
.lsp
.best_nhlfe
;
1633 const struct zebra_nhlfe
*
1634 dplane_ctx_set_best_nhlfe(struct zebra_dplane_ctx
*ctx
,
1635 struct zebra_nhlfe
*nhlfe
)
1637 DPLANE_CTX_VALID(ctx
);
1639 ctx
->u
.lsp
.best_nhlfe
= nhlfe
;
1640 return ctx
->u
.lsp
.best_nhlfe
;
1643 uint32_t dplane_ctx_get_lsp_num_ecmp(const struct zebra_dplane_ctx
*ctx
)
1645 DPLANE_CTX_VALID(ctx
);
1647 return ctx
->u
.lsp
.num_ecmp
;
1650 mpls_label_t
dplane_ctx_get_pw_local_label(const struct zebra_dplane_ctx
*ctx
)
1652 DPLANE_CTX_VALID(ctx
);
1654 return ctx
->u
.pw
.local_label
;
1657 mpls_label_t
dplane_ctx_get_pw_remote_label(const struct zebra_dplane_ctx
*ctx
)
1659 DPLANE_CTX_VALID(ctx
);
1661 return ctx
->u
.pw
.remote_label
;
1664 int dplane_ctx_get_pw_type(const struct zebra_dplane_ctx
*ctx
)
1666 DPLANE_CTX_VALID(ctx
);
1668 return ctx
->u
.pw
.type
;
1671 int dplane_ctx_get_pw_af(const struct zebra_dplane_ctx
*ctx
)
1673 DPLANE_CTX_VALID(ctx
);
1675 return ctx
->u
.pw
.af
;
1678 uint32_t dplane_ctx_get_pw_flags(const struct zebra_dplane_ctx
*ctx
)
1680 DPLANE_CTX_VALID(ctx
);
1682 return ctx
->u
.pw
.flags
;
1685 int dplane_ctx_get_pw_status(const struct zebra_dplane_ctx
*ctx
)
1687 DPLANE_CTX_VALID(ctx
);
1689 return ctx
->u
.pw
.status
;
1692 void dplane_ctx_set_pw_status(struct zebra_dplane_ctx
*ctx
, int status
)
1694 DPLANE_CTX_VALID(ctx
);
1696 ctx
->u
.pw
.status
= status
;
1699 const union g_addr
*dplane_ctx_get_pw_dest(
1700 const struct zebra_dplane_ctx
*ctx
)
1702 DPLANE_CTX_VALID(ctx
);
1704 return &(ctx
->u
.pw
.dest
);
1707 const union pw_protocol_fields
*dplane_ctx_get_pw_proto(
1708 const struct zebra_dplane_ctx
*ctx
)
1710 DPLANE_CTX_VALID(ctx
);
1712 return &(ctx
->u
.pw
.fields
);
1715 const struct nexthop_group
*
1716 dplane_ctx_get_pw_nhg(const struct zebra_dplane_ctx
*ctx
)
1718 DPLANE_CTX_VALID(ctx
);
1720 return &(ctx
->u
.pw
.fib_nhg
);
1723 const struct nexthop_group
*
1724 dplane_ctx_get_pw_primary_nhg(const struct zebra_dplane_ctx
*ctx
)
1726 DPLANE_CTX_VALID(ctx
);
1728 return &(ctx
->u
.pw
.primary_nhg
);
1731 const struct nexthop_group
*
1732 dplane_ctx_get_pw_backup_nhg(const struct zebra_dplane_ctx
*ctx
)
1734 DPLANE_CTX_VALID(ctx
);
1736 return &(ctx
->u
.pw
.backup_nhg
);
1739 /* Accessors for interface information */
1740 uint32_t dplane_ctx_get_intf_metric(const struct zebra_dplane_ctx
*ctx
)
1742 DPLANE_CTX_VALID(ctx
);
1744 return ctx
->u
.intf
.metric
;
1747 void dplane_ctx_set_intf_metric(struct zebra_dplane_ctx
*ctx
, uint32_t metric
)
1749 DPLANE_CTX_VALID(ctx
);
1751 ctx
->u
.intf
.metric
= metric
;
1754 /* Is interface addr p2p? */
1755 bool dplane_ctx_intf_is_connected(const struct zebra_dplane_ctx
*ctx
)
1757 DPLANE_CTX_VALID(ctx
);
1759 return (ctx
->u
.intf
.flags
& DPLANE_INTF_CONNECTED
);
1762 bool dplane_ctx_intf_is_secondary(const struct zebra_dplane_ctx
*ctx
)
1764 DPLANE_CTX_VALID(ctx
);
1766 return (ctx
->u
.intf
.flags
& DPLANE_INTF_SECONDARY
);
1769 bool dplane_ctx_intf_is_broadcast(const struct zebra_dplane_ctx
*ctx
)
1771 DPLANE_CTX_VALID(ctx
);
1773 return (ctx
->u
.intf
.flags
& DPLANE_INTF_BROADCAST
);
1776 void dplane_ctx_intf_set_connected(struct zebra_dplane_ctx
*ctx
)
1778 DPLANE_CTX_VALID(ctx
);
1780 ctx
->u
.intf
.flags
|= DPLANE_INTF_CONNECTED
;
1783 void dplane_ctx_intf_set_secondary(struct zebra_dplane_ctx
*ctx
)
1785 DPLANE_CTX_VALID(ctx
);
1787 ctx
->u
.intf
.flags
|= DPLANE_INTF_SECONDARY
;
1790 void dplane_ctx_intf_set_broadcast(struct zebra_dplane_ctx
*ctx
)
1792 DPLANE_CTX_VALID(ctx
);
1794 ctx
->u
.intf
.flags
|= DPLANE_INTF_BROADCAST
;
1797 const struct prefix
*dplane_ctx_get_intf_addr(
1798 const struct zebra_dplane_ctx
*ctx
)
1800 DPLANE_CTX_VALID(ctx
);
1802 return &(ctx
->u
.intf
.prefix
);
1805 void dplane_ctx_set_intf_addr(struct zebra_dplane_ctx
*ctx
,
1806 const struct prefix
*p
)
1808 DPLANE_CTX_VALID(ctx
);
1810 prefix_copy(&(ctx
->u
.intf
.prefix
), p
);
1813 bool dplane_ctx_intf_has_dest(const struct zebra_dplane_ctx
*ctx
)
1815 DPLANE_CTX_VALID(ctx
);
1817 return (ctx
->u
.intf
.flags
& DPLANE_INTF_HAS_DEST
);
1820 const struct prefix
*dplane_ctx_get_intf_dest(
1821 const struct zebra_dplane_ctx
*ctx
)
1823 DPLANE_CTX_VALID(ctx
);
1825 return &(ctx
->u
.intf
.dest_prefix
);
1828 void dplane_ctx_set_intf_dest(struct zebra_dplane_ctx
*ctx
,
1829 const struct prefix
*p
)
1831 DPLANE_CTX_VALID(ctx
);
1833 prefix_copy(&(ctx
->u
.intf
.dest_prefix
), p
);
1836 bool dplane_ctx_intf_has_label(const struct zebra_dplane_ctx
*ctx
)
1838 DPLANE_CTX_VALID(ctx
);
1840 return (ctx
->u
.intf
.flags
& DPLANE_INTF_HAS_LABEL
);
1843 const char *dplane_ctx_get_intf_label(const struct zebra_dplane_ctx
*ctx
)
1845 DPLANE_CTX_VALID(ctx
);
1847 return ctx
->u
.intf
.label
;
1850 void dplane_ctx_set_intf_label(struct zebra_dplane_ctx
*ctx
, const char *label
)
1854 DPLANE_CTX_VALID(ctx
);
1856 if (ctx
->u
.intf
.label
&& ctx
->u
.intf
.label
!= ctx
->u
.intf
.label_buf
)
1857 free(ctx
->u
.intf
.label
);
1859 ctx
->u
.intf
.label
= NULL
;
1862 ctx
->u
.intf
.flags
|= DPLANE_INTF_HAS_LABEL
;
1864 /* Use embedded buffer if it's adequate; else allocate. */
1865 len
= strlen(label
);
1867 if (len
< sizeof(ctx
->u
.intf
.label_buf
)) {
1868 strlcpy(ctx
->u
.intf
.label_buf
, label
,
1869 sizeof(ctx
->u
.intf
.label_buf
));
1870 ctx
->u
.intf
.label
= ctx
->u
.intf
.label_buf
;
1872 ctx
->u
.intf
.label
= strdup(label
);
1875 ctx
->u
.intf
.flags
&= ~DPLANE_INTF_HAS_LABEL
;
1879 /* Accessors for MAC information */
1880 vlanid_t
dplane_ctx_mac_get_vlan(const struct zebra_dplane_ctx
*ctx
)
1882 DPLANE_CTX_VALID(ctx
);
1883 return ctx
->u
.macinfo
.vid
;
1886 bool dplane_ctx_mac_is_sticky(const struct zebra_dplane_ctx
*ctx
)
1888 DPLANE_CTX_VALID(ctx
);
1889 return ctx
->u
.macinfo
.is_sticky
;
1892 uint32_t dplane_ctx_mac_get_nhg_id(const struct zebra_dplane_ctx
*ctx
)
1894 DPLANE_CTX_VALID(ctx
);
1895 return ctx
->u
.macinfo
.nhg_id
;
1898 uint32_t dplane_ctx_mac_get_update_flags(const struct zebra_dplane_ctx
*ctx
)
1900 DPLANE_CTX_VALID(ctx
);
1901 return ctx
->u
.macinfo
.update_flags
;
1904 const struct ethaddr
*dplane_ctx_mac_get_addr(
1905 const struct zebra_dplane_ctx
*ctx
)
1907 DPLANE_CTX_VALID(ctx
);
1908 return &(ctx
->u
.macinfo
.mac
);
1911 const struct in_addr
*dplane_ctx_mac_get_vtep_ip(
1912 const struct zebra_dplane_ctx
*ctx
)
1914 DPLANE_CTX_VALID(ctx
);
1915 return &(ctx
->u
.macinfo
.vtep_ip
);
1918 ifindex_t
dplane_ctx_mac_get_br_ifindex(const struct zebra_dplane_ctx
*ctx
)
1920 DPLANE_CTX_VALID(ctx
);
1921 return ctx
->u
.macinfo
.br_ifindex
;
1924 /* Accessors for neighbor information */
1925 const struct ipaddr
*dplane_ctx_neigh_get_ipaddr(
1926 const struct zebra_dplane_ctx
*ctx
)
1928 DPLANE_CTX_VALID(ctx
);
1929 return &(ctx
->u
.neigh
.ip_addr
);
1932 const struct ipaddr
*
1933 dplane_ctx_neigh_get_link_ip(const struct zebra_dplane_ctx
*ctx
)
1935 DPLANE_CTX_VALID(ctx
);
1936 return &(ctx
->u
.neigh
.link
.ip_addr
);
1939 const struct ethaddr
*dplane_ctx_neigh_get_mac(
1940 const struct zebra_dplane_ctx
*ctx
)
1942 DPLANE_CTX_VALID(ctx
);
1943 return &(ctx
->u
.neigh
.link
.mac
);
1946 uint32_t dplane_ctx_neigh_get_flags(const struct zebra_dplane_ctx
*ctx
)
1948 DPLANE_CTX_VALID(ctx
);
1949 return ctx
->u
.neigh
.flags
;
1952 uint16_t dplane_ctx_neigh_get_state(const struct zebra_dplane_ctx
*ctx
)
1954 DPLANE_CTX_VALID(ctx
);
1955 return ctx
->u
.neigh
.state
;
1958 uint32_t dplane_ctx_neigh_get_update_flags(const struct zebra_dplane_ctx
*ctx
)
1960 DPLANE_CTX_VALID(ctx
);
1961 return ctx
->u
.neigh
.update_flags
;
1964 /* Accessor for GRE set */
1966 dplane_ctx_gre_get_link_ifindex(const struct zebra_dplane_ctx
*ctx
)
1968 DPLANE_CTX_VALID(ctx
);
1970 return ctx
->u
.gre
.link_ifindex
;
1974 dplane_ctx_gre_get_mtu(const struct zebra_dplane_ctx
*ctx
)
1976 DPLANE_CTX_VALID(ctx
);
1978 return ctx
->u
.gre
.mtu
;
1981 const struct zebra_l2info_gre
*
1982 dplane_ctx_gre_get_info(const struct zebra_dplane_ctx
*ctx
)
1984 DPLANE_CTX_VALID(ctx
);
1986 return &ctx
->u
.gre
.info
;
1989 /* Accessors for PBR rule information */
1990 int dplane_ctx_rule_get_sock(const struct zebra_dplane_ctx
*ctx
)
1992 DPLANE_CTX_VALID(ctx
);
1994 return ctx
->u
.rule
.sock
;
1997 const char *dplane_ctx_rule_get_ifname(const struct zebra_dplane_ctx
*ctx
)
1999 DPLANE_CTX_VALID(ctx
);
2001 return ctx
->u
.rule
.new.ifname
;
2004 int dplane_ctx_rule_get_unique(const struct zebra_dplane_ctx
*ctx
)
2006 DPLANE_CTX_VALID(ctx
);
2008 return ctx
->u
.rule
.unique
;
2011 int dplane_ctx_rule_get_seq(const struct zebra_dplane_ctx
*ctx
)
2013 DPLANE_CTX_VALID(ctx
);
2015 return ctx
->u
.rule
.seq
;
2018 uint32_t dplane_ctx_rule_get_priority(const struct zebra_dplane_ctx
*ctx
)
2020 DPLANE_CTX_VALID(ctx
);
2022 return ctx
->u
.rule
.new.priority
;
2025 uint32_t dplane_ctx_rule_get_old_priority(const struct zebra_dplane_ctx
*ctx
)
2027 DPLANE_CTX_VALID(ctx
);
2029 return ctx
->u
.rule
.old
.priority
;
2032 uint32_t dplane_ctx_rule_get_table(const struct zebra_dplane_ctx
*ctx
)
2034 DPLANE_CTX_VALID(ctx
);
2036 return ctx
->u
.rule
.new.table
;
2039 uint32_t dplane_ctx_rule_get_old_table(const struct zebra_dplane_ctx
*ctx
)
2041 DPLANE_CTX_VALID(ctx
);
2043 return ctx
->u
.rule
.old
.table
;
2046 uint32_t dplane_ctx_rule_get_filter_bm(const struct zebra_dplane_ctx
*ctx
)
2048 DPLANE_CTX_VALID(ctx
);
2050 return ctx
->u
.rule
.new.filter_bm
;
2053 uint32_t dplane_ctx_rule_get_old_filter_bm(const struct zebra_dplane_ctx
*ctx
)
2055 DPLANE_CTX_VALID(ctx
);
2057 return ctx
->u
.rule
.old
.filter_bm
;
2060 uint32_t dplane_ctx_rule_get_fwmark(const struct zebra_dplane_ctx
*ctx
)
2062 DPLANE_CTX_VALID(ctx
);
2064 return ctx
->u
.rule
.new.fwmark
;
2067 uint32_t dplane_ctx_rule_get_old_fwmark(const struct zebra_dplane_ctx
*ctx
)
2069 DPLANE_CTX_VALID(ctx
);
2071 return ctx
->u
.rule
.old
.fwmark
;
2074 uint8_t dplane_ctx_rule_get_ipproto(const struct zebra_dplane_ctx
*ctx
)
2076 DPLANE_CTX_VALID(ctx
);
2078 return ctx
->u
.rule
.new.ip_proto
;
2081 uint8_t dplane_ctx_rule_get_old_ipproto(const struct zebra_dplane_ctx
*ctx
)
2083 DPLANE_CTX_VALID(ctx
);
2085 return ctx
->u
.rule
.old
.ip_proto
;
2088 uint8_t dplane_ctx_rule_get_dsfield(const struct zebra_dplane_ctx
*ctx
)
2090 DPLANE_CTX_VALID(ctx
);
2092 return ctx
->u
.rule
.new.dsfield
;
2095 uint8_t dplane_ctx_rule_get_old_dsfield(const struct zebra_dplane_ctx
*ctx
)
2097 DPLANE_CTX_VALID(ctx
);
2099 return ctx
->u
.rule
.old
.dsfield
;
2102 const struct prefix
*
2103 dplane_ctx_rule_get_src_ip(const struct zebra_dplane_ctx
*ctx
)
2105 DPLANE_CTX_VALID(ctx
);
2107 return &(ctx
->u
.rule
.new.src_ip
);
2110 const struct prefix
*
2111 dplane_ctx_rule_get_old_src_ip(const struct zebra_dplane_ctx
*ctx
)
2113 DPLANE_CTX_VALID(ctx
);
2115 return &(ctx
->u
.rule
.old
.src_ip
);
2118 const struct prefix
*
2119 dplane_ctx_rule_get_dst_ip(const struct zebra_dplane_ctx
*ctx
)
2121 DPLANE_CTX_VALID(ctx
);
2123 return &(ctx
->u
.rule
.new.dst_ip
);
2126 const struct prefix
*
2127 dplane_ctx_rule_get_old_dst_ip(const struct zebra_dplane_ctx
*ctx
)
2129 DPLANE_CTX_VALID(ctx
);
2131 return &(ctx
->u
.rule
.old
.dst_ip
);
2134 uint32_t dplane_ctx_get_br_port_flags(const struct zebra_dplane_ctx
*ctx
)
2136 DPLANE_CTX_VALID(ctx
);
2138 return ctx
->u
.br_port
.flags
;
2142 dplane_ctx_get_br_port_sph_filter_cnt(const struct zebra_dplane_ctx
*ctx
)
2144 DPLANE_CTX_VALID(ctx
);
2146 return ctx
->u
.br_port
.sph_filter_cnt
;
2149 const struct in_addr
*
2150 dplane_ctx_get_br_port_sph_filters(const struct zebra_dplane_ctx
*ctx
)
2152 DPLANE_CTX_VALID(ctx
);
2154 return ctx
->u
.br_port
.sph_filters
;
2158 dplane_ctx_get_br_port_backup_nhg_id(const struct zebra_dplane_ctx
*ctx
)
2160 DPLANE_CTX_VALID(ctx
);
2162 return ctx
->u
.br_port
.backup_nhg_id
;
2165 /* Accessors for PBR iptable information */
2166 void dplane_ctx_get_pbr_iptable(const struct zebra_dplane_ctx
*ctx
,
2167 struct zebra_pbr_iptable
*table
)
2169 DPLANE_CTX_VALID(ctx
);
2171 memcpy(table
, &ctx
->u
.iptable
, sizeof(struct zebra_pbr_iptable
));
2174 void dplane_ctx_get_pbr_ipset(const struct zebra_dplane_ctx
*ctx
,
2175 struct zebra_pbr_ipset
*ipset
)
2177 DPLANE_CTX_VALID(ctx
);
2181 if (ctx
->zd_op
== DPLANE_OP_IPSET_ENTRY_ADD
||
2182 ctx
->zd_op
== DPLANE_OP_IPSET_ENTRY_DELETE
) {
2183 memset(ipset
, 0, sizeof(struct zebra_pbr_ipset
));
2184 ipset
->type
= ctx
->u
.ipset_entry
.info
.type
;
2185 ipset
->family
= ctx
->u
.ipset_entry
.info
.family
;
2186 memcpy(&ipset
->ipset_name
, &ctx
->u
.ipset_entry
.info
.ipset_name
,
2187 ZEBRA_IPSET_NAME_SIZE
);
2189 memcpy(ipset
, &ctx
->u
.ipset
, sizeof(struct zebra_pbr_ipset
));
2192 void dplane_ctx_get_pbr_ipset_entry(const struct zebra_dplane_ctx
*ctx
,
2193 struct zebra_pbr_ipset_entry
*entry
)
2195 DPLANE_CTX_VALID(ctx
);
2199 memcpy(entry
, &ctx
->u
.ipset_entry
.entry
, sizeof(struct zebra_pbr_ipset_entry
));
2203 * End of dplane context accessors
2206 /* Optional extra info about interfaces in nexthops - a plugin must enable
2209 const struct dplane_intf_extra
*
2210 dplane_ctx_get_intf_extra(const struct zebra_dplane_ctx
*ctx
)
2212 return TAILQ_FIRST(&ctx
->u
.rinfo
.intf_extra_q
);
2215 const struct dplane_intf_extra
*
2216 dplane_ctx_intf_extra_next(const struct zebra_dplane_ctx
*ctx
,
2217 const struct dplane_intf_extra
*ptr
)
2219 return TAILQ_NEXT(ptr
, link
);
2222 vrf_id_t
dplane_intf_extra_get_vrfid(const struct dplane_intf_extra
*ptr
)
2227 uint32_t dplane_intf_extra_get_ifindex(const struct dplane_intf_extra
*ptr
)
2229 return ptr
->ifindex
;
2232 uint32_t dplane_intf_extra_get_flags(const struct dplane_intf_extra
*ptr
)
2237 uint32_t dplane_intf_extra_get_status(const struct dplane_intf_extra
*ptr
)
2242 uint8_t dplane_ctx_neightable_get_family(const struct zebra_dplane_ctx
*ctx
)
2244 DPLANE_CTX_VALID(ctx
);
2246 return ctx
->u
.neightable
.family
;
2250 dplane_ctx_neightable_get_app_probes(const struct zebra_dplane_ctx
*ctx
)
2252 DPLANE_CTX_VALID(ctx
);
2254 return ctx
->u
.neightable
.app_probes
;
2258 dplane_ctx_neightable_get_ucast_probes(const struct zebra_dplane_ctx
*ctx
)
2260 DPLANE_CTX_VALID(ctx
);
2262 return ctx
->u
.neightable
.ucast_probes
;
2266 dplane_ctx_neightable_get_mcast_probes(const struct zebra_dplane_ctx
*ctx
)
2268 DPLANE_CTX_VALID(ctx
);
2270 return ctx
->u
.neightable
.mcast_probes
;
2274 * End of interface extra info accessors
2278 * Retrieve the limit on the number of pending, unprocessed updates.
2280 uint32_t dplane_get_in_queue_limit(void)
2282 return atomic_load_explicit(&zdplane_info
.dg_max_queued_updates
,
2283 memory_order_relaxed
);
2287 * Configure limit on the number of pending, queued updates.
2289 void dplane_set_in_queue_limit(uint32_t limit
, bool set
)
2291 /* Reset to default on 'unset' */
2293 limit
= DPLANE_DEFAULT_MAX_QUEUED
;
2295 atomic_store_explicit(&zdplane_info
.dg_max_queued_updates
, limit
,
2296 memory_order_relaxed
);
2300 * Retrieve the current queue depth of incoming, unprocessed updates
2302 uint32_t dplane_get_in_queue_len(void)
2304 return atomic_load_explicit(&zdplane_info
.dg_routes_queued
,
2305 memory_order_seq_cst
);
2309 * Common dataplane context init with zebra namespace info.
2311 static int dplane_ctx_ns_init(struct zebra_dplane_ctx
*ctx
,
2312 struct zebra_ns
*zns
,
2315 dplane_info_from_zns(&(ctx
->zd_ns_info
), zns
);
2317 ctx
->zd_is_update
= is_update
;
2319 #if defined(HAVE_NETLINK)
2320 /* Increment message counter after copying to context struct - may need
2321 * two messages in some 'update' cases.
2324 zns
->netlink_dplane_out
.seq
+= 2;
2326 zns
->netlink_dplane_out
.seq
++;
2327 #endif /* HAVE_NETLINK */
2333 * Initialize a context block for a route update from zebra data structs.
2335 int dplane_ctx_route_init(struct zebra_dplane_ctx
*ctx
, enum dplane_op_e op
,
2336 struct route_node
*rn
, struct route_entry
*re
)
2339 const struct route_table
*table
= NULL
;
2340 const struct rib_table_info
*info
;
2341 const struct prefix
*p
, *src_p
;
2342 struct zebra_ns
*zns
;
2343 struct zebra_vrf
*zvrf
;
2344 struct nexthop
*nexthop
;
2345 struct zebra_l3vni
*zl3vni
;
2346 const struct interface
*ifp
;
2347 struct dplane_intf_extra
*if_extra
;
2349 if (!ctx
|| !rn
|| !re
)
2352 TAILQ_INIT(&ctx
->u
.rinfo
.intf_extra_q
);
2355 ctx
->zd_status
= ZEBRA_DPLANE_REQUEST_SUCCESS
;
2357 ctx
->u
.rinfo
.zd_type
= re
->type
;
2358 ctx
->u
.rinfo
.zd_old_type
= re
->type
;
2360 /* Prefixes: dest, and optional source */
2361 srcdest_rnode_prefixes(rn
, &p
, &src_p
);
2363 prefix_copy(&(ctx
->u
.rinfo
.zd_dest
), p
);
2366 prefix_copy(&(ctx
->u
.rinfo
.zd_src
), src_p
);
2368 memset(&(ctx
->u
.rinfo
.zd_src
), 0, sizeof(ctx
->u
.rinfo
.zd_src
));
2370 ctx
->zd_table_id
= re
->table
;
2372 ctx
->u
.rinfo
.zd_metric
= re
->metric
;
2373 ctx
->u
.rinfo
.zd_old_metric
= re
->metric
;
2374 ctx
->zd_vrf_id
= re
->vrf_id
;
2375 ctx
->u
.rinfo
.zd_mtu
= re
->mtu
;
2376 ctx
->u
.rinfo
.zd_nexthop_mtu
= re
->nexthop_mtu
;
2377 ctx
->u
.rinfo
.zd_instance
= re
->instance
;
2378 ctx
->u
.rinfo
.zd_tag
= re
->tag
;
2379 ctx
->u
.rinfo
.zd_old_tag
= re
->tag
;
2380 ctx
->u
.rinfo
.zd_distance
= re
->distance
;
2382 table
= srcdest_rnode_table(rn
);
2385 ctx
->u
.rinfo
.zd_afi
= info
->afi
;
2386 ctx
->u
.rinfo
.zd_safi
= info
->safi
;
2388 /* Copy nexthops; recursive info is included too */
2389 copy_nexthops(&(ctx
->u
.rinfo
.zd_ng
.nexthop
),
2390 re
->nhe
->nhg
.nexthop
, NULL
);
2391 ctx
->u
.rinfo
.zd_nhg_id
= re
->nhe
->id
;
2393 /* Copy backup nexthop info, if present */
2394 if (re
->nhe
->backup_info
&& re
->nhe
->backup_info
->nhe
) {
2395 copy_nexthops(&(ctx
->u
.rinfo
.backup_ng
.nexthop
),
2396 re
->nhe
->backup_info
->nhe
->nhg
.nexthop
, NULL
);
2400 * Ensure that the dplane nexthops' flags are clear and copy
2401 * encapsulation information.
2403 for (ALL_NEXTHOPS(ctx
->u
.rinfo
.zd_ng
, nexthop
)) {
2404 UNSET_FLAG(nexthop
->flags
, NEXTHOP_FLAG_FIB
);
2406 /* Optionally capture extra interface info while we're in the
2407 * main zebra pthread - a plugin has to ask for this info.
2409 if (dplane_collect_extra_intf_info
) {
2410 ifp
= if_lookup_by_index(nexthop
->ifindex
,
2416 sizeof(struct dplane_intf_extra
));
2417 if_extra
->vrf_id
= nexthop
->vrf_id
;
2418 if_extra
->ifindex
= nexthop
->ifindex
;
2419 if_extra
->flags
= ifp
->flags
;
2420 if_extra
->status
= ifp
->status
;
2422 TAILQ_INSERT_TAIL(&ctx
->u
.rinfo
.intf_extra_q
,
2427 /* Check for available evpn encapsulations. */
2428 if (!CHECK_FLAG(re
->flags
, ZEBRA_FLAG_EVPN_ROUTE
))
2431 zl3vni
= zl3vni_from_vrf(nexthop
->vrf_id
);
2432 if (zl3vni
&& is_l3vni_oper_up(zl3vni
)) {
2433 nexthop
->nh_encap_type
= NET_VXLAN
;
2434 nexthop
->nh_encap
.vni
= zl3vni
->vni
;
2438 /* Don't need some info when capturing a system notification */
2439 if (op
== DPLANE_OP_SYS_ROUTE_ADD
||
2440 op
== DPLANE_OP_SYS_ROUTE_DELETE
) {
2445 /* Extract ns info - can't use pointers to 'core' structs */
2446 zvrf
= vrf_info_lookup(re
->vrf_id
);
2448 dplane_ctx_ns_init(ctx
, zns
, (op
== DPLANE_OP_ROUTE_UPDATE
));
2452 struct nhg_hash_entry
*nhe
= zebra_nhg_resolve(re
->nhe
);
2454 ctx
->u
.rinfo
.nhe
.id
= nhe
->id
;
2455 ctx
->u
.rinfo
.nhe
.old_id
= 0;
2457 * Check if the nhe is installed/queued before doing anything
2460 * If its a delete we only use the prefix anyway, so this only
2461 * matters for INSTALL/UPDATE.
2463 if (zebra_nhg_kernel_nexthops_enabled()
2464 && (((op
== DPLANE_OP_ROUTE_INSTALL
)
2465 || (op
== DPLANE_OP_ROUTE_UPDATE
))
2466 && !CHECK_FLAG(nhe
->flags
, NEXTHOP_GROUP_INSTALLED
)
2467 && !CHECK_FLAG(nhe
->flags
, NEXTHOP_GROUP_QUEUED
))) {
2472 re
->nhe_installed_id
= nhe
->id
;
2474 #endif /* HAVE_NETLINK */
2476 /* Trying out the sequence number idea, so we can try to detect
2477 * when a result is stale.
2479 re
->dplane_sequence
= zebra_router_get_next_sequence();
2480 ctx
->zd_seq
= re
->dplane_sequence
;
2489 * dplane_ctx_nexthop_init() - Initialize a context block for a nexthop update
2491 * @ctx: Dataplane context to init
2492 * @op: Operation being performed
2493 * @nhe: Nexthop group hash entry
2495 * Return: Result status
2497 int dplane_ctx_nexthop_init(struct zebra_dplane_ctx
*ctx
, enum dplane_op_e op
,
2498 struct nhg_hash_entry
*nhe
)
2500 struct zebra_vrf
*zvrf
= NULL
;
2501 struct zebra_ns
*zns
= NULL
;
2508 ctx
->zd_status
= ZEBRA_DPLANE_REQUEST_SUCCESS
;
2510 /* Copy over nhe info */
2511 ctx
->u
.rinfo
.nhe
.id
= nhe
->id
;
2512 ctx
->u
.rinfo
.nhe
.afi
= nhe
->afi
;
2513 ctx
->u
.rinfo
.nhe
.vrf_id
= nhe
->vrf_id
;
2514 ctx
->u
.rinfo
.nhe
.type
= nhe
->type
;
2516 nexthop_group_copy(&(ctx
->u
.rinfo
.nhe
.ng
), &(nhe
->nhg
));
2518 /* If this is a group, convert it to a grp array of ids */
2519 if (!zebra_nhg_depends_is_empty(nhe
)
2520 && !CHECK_FLAG(nhe
->flags
, NEXTHOP_GROUP_RECURSIVE
))
2521 ctx
->u
.rinfo
.nhe
.nh_grp_count
= zebra_nhg_nhe2grp(
2522 ctx
->u
.rinfo
.nhe
.nh_grp
, nhe
, MULTIPATH_NUM
);
2524 zvrf
= vrf_info_lookup(nhe
->vrf_id
);
2527 * Fallback to default namespace if the vrf got ripped out from under
2530 zns
= zvrf
? zvrf
->zns
: zebra_ns_lookup(NS_DEFAULT
);
2533 * TODO: Might not need to mark this as an update, since
2534 * it probably won't require two messages
2536 dplane_ctx_ns_init(ctx
, zns
, (op
== DPLANE_OP_NH_UPDATE
));
2545 * Capture information for an LSP update in a dplane context.
2547 int dplane_ctx_lsp_init(struct zebra_dplane_ctx
*ctx
, enum dplane_op_e op
,
2548 struct zebra_lsp
*lsp
)
2551 struct zebra_nhlfe
*nhlfe
, *new_nhlfe
;
2554 ctx
->zd_status
= ZEBRA_DPLANE_REQUEST_SUCCESS
;
2556 /* Capture namespace info */
2557 dplane_ctx_ns_init(ctx
, zebra_ns_lookup(NS_DEFAULT
),
2558 (op
== DPLANE_OP_LSP_UPDATE
));
2560 memset(&ctx
->u
.lsp
, 0, sizeof(ctx
->u
.lsp
));
2562 nhlfe_list_init(&(ctx
->u
.lsp
.nhlfe_list
));
2563 nhlfe_list_init(&(ctx
->u
.lsp
.backup_nhlfe_list
));
2565 /* This may be called to create/init a dplane context, not necessarily
2566 * to copy an lsp object.
2573 if (IS_ZEBRA_DEBUG_DPLANE_DETAIL
)
2574 zlog_debug("init dplane ctx %s: in-label %u ecmp# %d",
2575 dplane_op2str(op
), lsp
->ile
.in_label
,
2578 ctx
->u
.lsp
.ile
= lsp
->ile
;
2579 ctx
->u
.lsp
.addr_family
= lsp
->addr_family
;
2580 ctx
->u
.lsp
.num_ecmp
= lsp
->num_ecmp
;
2581 ctx
->u
.lsp
.flags
= lsp
->flags
;
2583 /* Copy source LSP's nhlfes, and capture 'best' nhlfe */
2584 frr_each(nhlfe_list
, &lsp
->nhlfe_list
, nhlfe
) {
2585 /* Not sure if this is meaningful... */
2586 if (nhlfe
->nexthop
== NULL
)
2589 new_nhlfe
= zebra_mpls_lsp_add_nh(&(ctx
->u
.lsp
), nhlfe
->type
,
2591 if (new_nhlfe
== NULL
|| new_nhlfe
->nexthop
== NULL
) {
2596 /* Need to copy flags and backup info too */
2597 new_nhlfe
->flags
= nhlfe
->flags
;
2598 new_nhlfe
->nexthop
->flags
= nhlfe
->nexthop
->flags
;
2600 if (CHECK_FLAG(new_nhlfe
->nexthop
->flags
,
2601 NEXTHOP_FLAG_HAS_BACKUP
)) {
2602 new_nhlfe
->nexthop
->backup_num
=
2603 nhlfe
->nexthop
->backup_num
;
2604 memcpy(new_nhlfe
->nexthop
->backup_idx
,
2605 nhlfe
->nexthop
->backup_idx
,
2606 new_nhlfe
->nexthop
->backup_num
);
2609 if (nhlfe
== lsp
->best_nhlfe
)
2610 ctx
->u
.lsp
.best_nhlfe
= new_nhlfe
;
2616 /* Capture backup nhlfes/nexthops */
2617 frr_each(nhlfe_list
, &lsp
->backup_nhlfe_list
, nhlfe
) {
2618 /* Not sure if this is meaningful... */
2619 if (nhlfe
->nexthop
== NULL
)
2622 new_nhlfe
= zebra_mpls_lsp_add_backup_nh(&(ctx
->u
.lsp
),
2625 if (new_nhlfe
== NULL
|| new_nhlfe
->nexthop
== NULL
) {
2630 /* Need to copy flags too */
2631 new_nhlfe
->flags
= nhlfe
->flags
;
2632 new_nhlfe
->nexthop
->flags
= nhlfe
->nexthop
->flags
;
2635 /* On error the ctx will be cleaned-up, so we don't need to
2636 * deal with any allocated nhlfe or nexthop structs here.
2644 * Capture information for an LSP update in a dplane context.
2646 static int dplane_ctx_pw_init(struct zebra_dplane_ctx
*ctx
,
2647 enum dplane_op_e op
,
2648 struct zebra_pw
*pw
)
2653 struct route_table
*table
;
2654 struct route_node
*rn
;
2655 struct route_entry
*re
;
2656 const struct nexthop_group
*nhg
;
2657 struct nexthop
*nh
, *newnh
, *last_nh
;
2659 if (IS_ZEBRA_DEBUG_DPLANE_DETAIL
)
2660 zlog_debug("init dplane ctx %s: pw '%s', loc %u, rem %u",
2661 dplane_op2str(op
), pw
->ifname
, pw
->local_label
,
2665 ctx
->zd_status
= ZEBRA_DPLANE_REQUEST_SUCCESS
;
2667 /* Capture namespace info: no netlink support as of 12/18,
2668 * but just in case...
2670 dplane_ctx_ns_init(ctx
, zebra_ns_lookup(NS_DEFAULT
), false);
2672 memset(&ctx
->u
.pw
, 0, sizeof(ctx
->u
.pw
));
2674 /* This name appears to be c-string, so we use string copy. */
2675 strlcpy(ctx
->zd_ifname
, pw
->ifname
, sizeof(ctx
->zd_ifname
));
2677 ctx
->zd_vrf_id
= pw
->vrf_id
;
2678 ctx
->zd_ifindex
= pw
->ifindex
;
2679 ctx
->u
.pw
.type
= pw
->type
;
2680 ctx
->u
.pw
.af
= pw
->af
;
2681 ctx
->u
.pw
.local_label
= pw
->local_label
;
2682 ctx
->u
.pw
.remote_label
= pw
->remote_label
;
2683 ctx
->u
.pw
.flags
= pw
->flags
;
2685 ctx
->u
.pw
.dest
= pw
->nexthop
;
2687 ctx
->u
.pw
.fields
= pw
->data
;
2689 /* Capture nexthop info for the pw destination. We need to look
2690 * up and use zebra datastructs, but we're running in the zebra
2691 * pthread here so that should be ok.
2693 memcpy(&p
.u
, &pw
->nexthop
, sizeof(pw
->nexthop
));
2695 p
.prefixlen
= ((pw
->af
== AF_INET
) ? IPV4_MAX_BITLEN
: IPV6_MAX_BITLEN
);
2697 afi
= (pw
->af
== AF_INET
) ? AFI_IP
: AFI_IP6
;
2698 table
= zebra_vrf_table(afi
, SAFI_UNICAST
, pw
->vrf_id
);
2702 rn
= route_node_match(table
, &p
);
2707 RNODE_FOREACH_RE(rn
, re
) {
2708 if (CHECK_FLAG(re
->flags
, ZEBRA_FLAG_SELECTED
))
2713 /* We'll capture a 'fib' list of nexthops that meet our
2714 * criteria: installed, and labelled.
2716 nhg
= rib_get_fib_nhg(re
);
2719 if (nhg
&& nhg
->nexthop
) {
2720 for (ALL_NEXTHOPS_PTR(nhg
, nh
)) {
2721 if (!CHECK_FLAG(nh
->flags
, NEXTHOP_FLAG_ACTIVE
)
2722 || CHECK_FLAG(nh
->flags
,
2723 NEXTHOP_FLAG_RECURSIVE
)
2724 || nh
->nh_label
== NULL
)
2727 newnh
= nexthop_dup(nh
, NULL
);
2730 NEXTHOP_APPEND(last_nh
, newnh
);
2732 ctx
->u
.pw
.fib_nhg
.nexthop
= newnh
;
2737 /* Include any installed backup nexthops also. */
2738 nhg
= rib_get_fib_backup_nhg(re
);
2739 if (nhg
&& nhg
->nexthop
) {
2740 for (ALL_NEXTHOPS_PTR(nhg
, nh
)) {
2741 if (!CHECK_FLAG(nh
->flags
, NEXTHOP_FLAG_ACTIVE
)
2742 || CHECK_FLAG(nh
->flags
,
2743 NEXTHOP_FLAG_RECURSIVE
)
2744 || nh
->nh_label
== NULL
)
2747 newnh
= nexthop_dup(nh
, NULL
);
2750 NEXTHOP_APPEND(last_nh
, newnh
);
2752 ctx
->u
.pw
.fib_nhg
.nexthop
= newnh
;
2757 /* Copy primary nexthops; recursive info is included too */
2758 assert(re
->nhe
!= NULL
); /* SA warning */
2759 copy_nexthops(&(ctx
->u
.pw
.primary_nhg
.nexthop
),
2760 re
->nhe
->nhg
.nexthop
, NULL
);
2761 ctx
->u
.pw
.nhg_id
= re
->nhe
->id
;
2763 /* Copy backup nexthop info, if present */
2764 if (re
->nhe
->backup_info
&& re
->nhe
->backup_info
->nhe
) {
2765 copy_nexthops(&(ctx
->u
.pw
.backup_nhg
.nexthop
),
2766 re
->nhe
->backup_info
->nhe
->nhg
.nexthop
,
2770 route_unlock_node(rn
);
2779 * dplane_ctx_rule_init_single() - Initialize a dataplane representation of a
2782 * @dplane_rule: Dataplane internal representation of a rule
2785 static void dplane_ctx_rule_init_single(struct dplane_ctx_rule
*dplane_rule
,
2786 struct zebra_pbr_rule
*rule
)
2788 dplane_rule
->priority
= rule
->rule
.priority
;
2789 dplane_rule
->table
= rule
->rule
.action
.table
;
2791 dplane_rule
->filter_bm
= rule
->rule
.filter
.filter_bm
;
2792 dplane_rule
->fwmark
= rule
->rule
.filter
.fwmark
;
2793 dplane_rule
->dsfield
= rule
->rule
.filter
.dsfield
;
2794 dplane_rule
->ip_proto
= rule
->rule
.filter
.ip_proto
;
2795 prefix_copy(&(dplane_rule
->dst_ip
), &rule
->rule
.filter
.dst_ip
);
2796 prefix_copy(&(dplane_rule
->src_ip
), &rule
->rule
.filter
.src_ip
);
2798 dplane_rule
->action_pcp
= rule
->rule
.action
.pcp
;
2799 dplane_rule
->action_vlan_flags
= rule
->rule
.action
.vlan_flags
;
2800 dplane_rule
->action_vlan_id
= rule
->rule
.action
.vlan_id
;
2801 dplane_rule
->action_queue_id
= rule
->rule
.action
.queue_id
;
2803 strlcpy(dplane_rule
->ifname
, rule
->ifname
, INTERFACE_NAMSIZ
);
2807 * dplane_ctx_rule_init() - Initialize a context block for a PBR rule update.
2809 * @ctx: Dataplane context to init
2810 * @op: Operation being performed
2811 * @new_rule: PBR rule
2813 * Return: Result status
2815 static int dplane_ctx_rule_init(struct zebra_dplane_ctx
*ctx
,
2816 enum dplane_op_e op
,
2817 struct zebra_pbr_rule
*new_rule
,
2818 struct zebra_pbr_rule
*old_rule
)
2820 if (IS_ZEBRA_DEBUG_DPLANE_DETAIL
)
2822 "init dplane ctx %s: IF %s Prio %u Fwmark %u Src %pFX Dst %pFX Table %u",
2823 dplane_op2str(op
), new_rule
->ifname
,
2824 new_rule
->rule
.priority
, new_rule
->rule
.filter
.fwmark
,
2825 &new_rule
->rule
.filter
.src_ip
,
2826 &new_rule
->rule
.filter
.dst_ip
,
2827 new_rule
->rule
.action
.table
);
2830 ctx
->zd_status
= ZEBRA_DPLANE_REQUEST_SUCCESS
;
2832 dplane_ctx_ns_init(ctx
, zebra_ns_lookup(NS_DEFAULT
),
2833 op
== DPLANE_OP_RULE_UPDATE
);
2835 ctx
->zd_vrf_id
= new_rule
->vrf_id
;
2836 strlcpy(ctx
->zd_ifname
, new_rule
->ifname
, sizeof(ctx
->zd_ifname
));
2838 ctx
->u
.rule
.sock
= new_rule
->sock
;
2839 ctx
->u
.rule
.unique
= new_rule
->rule
.unique
;
2840 ctx
->u
.rule
.seq
= new_rule
->rule
.seq
;
2842 dplane_ctx_rule_init_single(&ctx
->u
.rule
.new, new_rule
);
2843 if (op
== DPLANE_OP_RULE_UPDATE
)
2844 dplane_ctx_rule_init_single(&ctx
->u
.rule
.old
, old_rule
);
2850 * dplane_ctx_iptable_init() - Initialize a context block for a PBR iptable
2853 * @ctx: Dataplane context to init
2854 * @op: Operation being performed
2855 * @new_rule: PBR iptable
2857 * Return: Result status
2859 static int dplane_ctx_iptable_init(struct zebra_dplane_ctx
*ctx
,
2860 enum dplane_op_e op
,
2861 struct zebra_pbr_iptable
*iptable
)
2864 struct listnode
*node
;
2866 if (IS_ZEBRA_DEBUG_DPLANE_DETAIL
) {
2868 "init dplane ctx %s: Unique %u Fwmark %u Family %s Action %s",
2869 dplane_op2str(op
), iptable
->unique
, iptable
->fwmark
,
2870 family2str(iptable
->family
),
2871 iptable
->action
== ZEBRA_IPTABLES_DROP
? "Drop"
2876 ctx
->zd_status
= ZEBRA_DPLANE_REQUEST_SUCCESS
;
2878 dplane_ctx_ns_init(ctx
, zebra_ns_lookup(NS_DEFAULT
), false);
2880 ctx
->zd_vrf_id
= iptable
->vrf_id
;
2881 memcpy(&ctx
->u
.iptable
, iptable
, sizeof(struct zebra_pbr_iptable
));
2882 ctx
->u
.iptable
.interface_name_list
= NULL
;
2883 if (iptable
->nb_interface
> 0) {
2884 ctx
->u
.iptable
.interface_name_list
= list_new();
2885 for (ALL_LIST_ELEMENTS_RO(iptable
->interface_name_list
, node
,
2887 listnode_add(ctx
->u
.iptable
.interface_name_list
,
2888 XSTRDUP(MTYPE_DP_NETFILTER
, ifname
));
2895 * dplane_ctx_ipset_init() - Initialize a context block for a PBR ipset update.
2897 * @ctx: Dataplane context to init
2898 * @op: Operation being performed
2899 * @new_rule: PBR ipset
2901 * Return: Result status
2903 static int dplane_ctx_ipset_init(struct zebra_dplane_ctx
*ctx
,
2904 enum dplane_op_e op
,
2905 struct zebra_pbr_ipset
*ipset
)
2907 if (IS_ZEBRA_DEBUG_DPLANE_DETAIL
) {
2908 zlog_debug("init dplane ctx %s: %s Unique %u Family %s Type %s",
2909 dplane_op2str(op
), ipset
->ipset_name
, ipset
->unique
,
2910 family2str(ipset
->family
),
2911 zebra_pbr_ipset_type2str(ipset
->type
));
2915 ctx
->zd_status
= ZEBRA_DPLANE_REQUEST_SUCCESS
;
2917 dplane_ctx_ns_init(ctx
, zebra_ns_lookup(NS_DEFAULT
), false);
2919 ctx
->zd_vrf_id
= ipset
->vrf_id
;
2921 memcpy(&ctx
->u
.ipset
, ipset
, sizeof(struct zebra_pbr_ipset
));
2926 * dplane_ctx_ipset_entry_init() - Initialize a context block for a PBR ipset
2929 * @ctx: Dataplane context to init
2930 * @op: Operation being performed
2931 * @new_rule: PBR ipset
2933 * Return: Result status
2936 dplane_ctx_ipset_entry_init(struct zebra_dplane_ctx
*ctx
, enum dplane_op_e op
,
2937 struct zebra_pbr_ipset_entry
*ipset_entry
)
2939 struct zebra_pbr_ipset
*ipset
;
2941 ipset
= ipset_entry
->backpointer
;
2942 if (IS_ZEBRA_DEBUG_DPLANE_DETAIL
) {
2943 zlog_debug("init dplane ctx %s: %s Unique %u filter %u",
2944 dplane_op2str(op
), ipset
->ipset_name
,
2945 ipset_entry
->unique
, ipset_entry
->filter_bm
);
2949 ctx
->zd_status
= ZEBRA_DPLANE_REQUEST_SUCCESS
;
2951 dplane_ctx_ns_init(ctx
, zebra_ns_lookup(NS_DEFAULT
), false);
2953 ctx
->zd_vrf_id
= ipset
->vrf_id
;
2955 memcpy(&ctx
->u
.ipset_entry
.entry
, ipset_entry
,
2956 sizeof(struct zebra_pbr_ipset_entry
));
2957 ctx
->u
.ipset_entry
.entry
.backpointer
= NULL
;
2958 ctx
->u
.ipset_entry
.info
.type
= ipset
->type
;
2959 ctx
->u
.ipset_entry
.info
.family
= ipset
->family
;
2960 memcpy(&ctx
->u
.ipset_entry
.info
.ipset_name
, &ipset
->ipset_name
,
2961 ZEBRA_IPSET_NAME_SIZE
);
2968 * Enqueue a new update,
2969 * and ensure an event is active for the dataplane pthread.
2971 static int dplane_update_enqueue(struct zebra_dplane_ctx
*ctx
)
2974 uint32_t high
, curr
;
2976 /* Enqueue for processing by the dataplane pthread */
2979 TAILQ_INSERT_TAIL(&zdplane_info
.dg_update_ctx_q
, ctx
,
2984 curr
= atomic_fetch_add_explicit(
2985 &(zdplane_info
.dg_routes_queued
),
2986 1, memory_order_seq_cst
);
2988 curr
++; /* We got the pre-incremented value */
2990 /* Maybe update high-water counter also */
2991 high
= atomic_load_explicit(&zdplane_info
.dg_routes_queued_max
,
2992 memory_order_seq_cst
);
2993 while (high
< curr
) {
2994 if (atomic_compare_exchange_weak_explicit(
2995 &zdplane_info
.dg_routes_queued_max
,
2997 memory_order_seq_cst
,
2998 memory_order_seq_cst
))
3002 /* Ensure that an event for the dataplane thread is active */
3003 ret
= dplane_provider_work_ready();
3009 * Utility that prepares a route update and enqueues it for processing
3011 static enum zebra_dplane_result
3012 dplane_route_update_internal(struct route_node
*rn
,
3013 struct route_entry
*re
,
3014 struct route_entry
*old_re
,
3015 enum dplane_op_e op
)
3017 enum zebra_dplane_result result
= ZEBRA_DPLANE_REQUEST_FAILURE
;
3019 struct zebra_dplane_ctx
*ctx
= NULL
;
3021 /* Obtain context block */
3022 ctx
= dplane_ctx_alloc();
3024 /* Init context with info from zebra data structs */
3025 ret
= dplane_ctx_route_init(ctx
, op
, rn
, re
);
3027 /* Capture some extra info for update case
3028 * where there's a different 'old' route.
3030 if ((op
== DPLANE_OP_ROUTE_UPDATE
) &&
3031 old_re
&& (old_re
!= re
)) {
3033 old_re
->dplane_sequence
=
3034 zebra_router_get_next_sequence();
3035 ctx
->zd_old_seq
= old_re
->dplane_sequence
;
3037 ctx
->u
.rinfo
.zd_old_tag
= old_re
->tag
;
3038 ctx
->u
.rinfo
.zd_old_type
= old_re
->type
;
3039 ctx
->u
.rinfo
.zd_old_instance
= old_re
->instance
;
3040 ctx
->u
.rinfo
.zd_old_distance
= old_re
->distance
;
3041 ctx
->u
.rinfo
.zd_old_metric
= old_re
->metric
;
3042 ctx
->u
.rinfo
.nhe
.old_id
= old_re
->nhe
->id
;
3044 #ifndef HAVE_NETLINK
3045 /* For bsd, capture previous re's nexthops too, sigh.
3046 * We'll need these to do per-nexthop deletes.
3048 copy_nexthops(&(ctx
->u
.rinfo
.zd_old_ng
.nexthop
),
3049 old_re
->nhe
->nhg
.nexthop
, NULL
);
3051 if (zebra_nhg_get_backup_nhg(old_re
->nhe
) != NULL
) {
3052 struct nexthop_group
*nhg
;
3053 struct nexthop
**nh
;
3055 nhg
= zebra_nhg_get_backup_nhg(old_re
->nhe
);
3056 nh
= &(ctx
->u
.rinfo
.old_backup_ng
.nexthop
);
3059 copy_nexthops(nh
, nhg
->nexthop
, NULL
);
3061 #endif /* !HAVE_NETLINK */
3065 * If the old and new context type, and nexthop group id
3066 * are the same there is no need to send down a route replace
3067 * as that we know we have sent a nexthop group replace
3068 * or an upper level protocol has sent us the exact
3071 if ((dplane_ctx_get_type(ctx
) == dplane_ctx_get_old_type(ctx
))
3072 && (dplane_ctx_get_nhe_id(ctx
)
3073 == dplane_ctx_get_old_nhe_id(ctx
))
3074 && (dplane_ctx_get_nhe_id(ctx
) >= ZEBRA_NHG_PROTO_LOWER
)) {
3075 struct nexthop
*nexthop
;
3077 if (IS_ZEBRA_DEBUG_DPLANE
)
3079 "%s: Ignoring Route exactly the same",
3082 for (ALL_NEXTHOPS_PTR(dplane_ctx_get_ng(ctx
),
3084 if (CHECK_FLAG(nexthop
->flags
,
3085 NEXTHOP_FLAG_RECURSIVE
))
3088 if (CHECK_FLAG(nexthop
->flags
,
3089 NEXTHOP_FLAG_ACTIVE
))
3090 SET_FLAG(nexthop
->flags
,
3094 dplane_ctx_free(&ctx
);
3095 return ZEBRA_DPLANE_REQUEST_SUCCESS
;
3098 /* Enqueue context for processing */
3099 ret
= dplane_update_enqueue(ctx
);
3102 /* Update counter */
3103 atomic_fetch_add_explicit(&zdplane_info
.dg_routes_in
, 1,
3104 memory_order_relaxed
);
3107 result
= ZEBRA_DPLANE_REQUEST_QUEUED
;
3109 atomic_fetch_add_explicit(&zdplane_info
.dg_route_errors
, 1,
3110 memory_order_relaxed
);
3112 dplane_ctx_free(&ctx
);
3119 * dplane_nexthop_update_internal() - Helper for enqueuing nexthop changes
3121 * @nhe: Nexthop group hash entry where the change occured
3122 * @op: The operation to be enqued
3124 * Return: Result of the change
3126 static enum zebra_dplane_result
3127 dplane_nexthop_update_internal(struct nhg_hash_entry
*nhe
, enum dplane_op_e op
)
3129 enum zebra_dplane_result result
= ZEBRA_DPLANE_REQUEST_FAILURE
;
3131 struct zebra_dplane_ctx
*ctx
= NULL
;
3133 /* Obtain context block */
3134 ctx
= dplane_ctx_alloc();
3140 ret
= dplane_ctx_nexthop_init(ctx
, op
, nhe
);
3142 ret
= dplane_update_enqueue(ctx
);
3145 /* Update counter */
3146 atomic_fetch_add_explicit(&zdplane_info
.dg_nexthops_in
, 1,
3147 memory_order_relaxed
);
3150 result
= ZEBRA_DPLANE_REQUEST_QUEUED
;
3152 atomic_fetch_add_explicit(&zdplane_info
.dg_nexthop_errors
, 1,
3153 memory_order_relaxed
);
3155 dplane_ctx_free(&ctx
);
3162 * Enqueue a route 'add' for the dataplane.
3164 enum zebra_dplane_result
dplane_route_add(struct route_node
*rn
,
3165 struct route_entry
*re
)
3167 enum zebra_dplane_result ret
= ZEBRA_DPLANE_REQUEST_FAILURE
;
3169 if (rn
== NULL
|| re
== NULL
)
3172 ret
= dplane_route_update_internal(rn
, re
, NULL
,
3173 DPLANE_OP_ROUTE_INSTALL
);
3180 * Enqueue a route update for the dataplane.
3182 enum zebra_dplane_result
dplane_route_update(struct route_node
*rn
,
3183 struct route_entry
*re
,
3184 struct route_entry
*old_re
)
3186 enum zebra_dplane_result ret
= ZEBRA_DPLANE_REQUEST_FAILURE
;
3188 if (rn
== NULL
|| re
== NULL
)
3191 ret
= dplane_route_update_internal(rn
, re
, old_re
,
3192 DPLANE_OP_ROUTE_UPDATE
);
3198 * Enqueue a route removal for the dataplane.
3200 enum zebra_dplane_result
dplane_route_delete(struct route_node
*rn
,
3201 struct route_entry
*re
)
3203 enum zebra_dplane_result ret
= ZEBRA_DPLANE_REQUEST_FAILURE
;
3205 if (rn
== NULL
|| re
== NULL
)
3208 ret
= dplane_route_update_internal(rn
, re
, NULL
,
3209 DPLANE_OP_ROUTE_DELETE
);
3216 * Notify the dplane when system/connected routes change.
3218 enum zebra_dplane_result
dplane_sys_route_add(struct route_node
*rn
,
3219 struct route_entry
*re
)
3221 enum zebra_dplane_result ret
= ZEBRA_DPLANE_REQUEST_FAILURE
;
3223 /* Ignore this event unless a provider plugin has requested it. */
3224 if (!zdplane_info
.dg_sys_route_notifs
) {
3225 ret
= ZEBRA_DPLANE_REQUEST_SUCCESS
;
3229 if (rn
== NULL
|| re
== NULL
)
3232 ret
= dplane_route_update_internal(rn
, re
, NULL
,
3233 DPLANE_OP_SYS_ROUTE_ADD
);
3240 * Notify the dplane when system/connected routes are deleted.
3242 enum zebra_dplane_result
dplane_sys_route_del(struct route_node
*rn
,
3243 struct route_entry
*re
)
3245 enum zebra_dplane_result ret
= ZEBRA_DPLANE_REQUEST_FAILURE
;
3247 /* Ignore this event unless a provider plugin has requested it. */
3248 if (!zdplane_info
.dg_sys_route_notifs
) {
3249 ret
= ZEBRA_DPLANE_REQUEST_SUCCESS
;
3253 if (rn
== NULL
|| re
== NULL
)
3256 ret
= dplane_route_update_internal(rn
, re
, NULL
,
3257 DPLANE_OP_SYS_ROUTE_DELETE
);
3264 * Update from an async notification, to bring other fibs up-to-date.
3266 enum zebra_dplane_result
3267 dplane_route_notif_update(struct route_node
*rn
,
3268 struct route_entry
*re
,
3269 enum dplane_op_e op
,
3270 struct zebra_dplane_ctx
*ctx
)
3272 enum zebra_dplane_result result
= ZEBRA_DPLANE_REQUEST_FAILURE
;
3274 struct zebra_dplane_ctx
*new_ctx
= NULL
;
3275 struct nexthop
*nexthop
;
3276 struct nexthop_group
*nhg
;
3278 if (rn
== NULL
|| re
== NULL
)
3281 new_ctx
= dplane_ctx_alloc();
3282 if (new_ctx
== NULL
)
3285 /* Init context with info from zebra data structs */
3286 dplane_ctx_route_init(new_ctx
, op
, rn
, re
);
3288 /* For add/update, need to adjust the nexthops so that we match
3289 * the notification state, which may not be the route-entry/RIB
3292 if (op
== DPLANE_OP_ROUTE_UPDATE
||
3293 op
== DPLANE_OP_ROUTE_INSTALL
) {
3295 nexthops_free(new_ctx
->u
.rinfo
.zd_ng
.nexthop
);
3296 new_ctx
->u
.rinfo
.zd_ng
.nexthop
= NULL
;
3298 nhg
= rib_get_fib_nhg(re
);
3299 if (nhg
&& nhg
->nexthop
)
3300 copy_nexthops(&(new_ctx
->u
.rinfo
.zd_ng
.nexthop
),
3301 nhg
->nexthop
, NULL
);
3303 /* Check for installed backup nexthops also */
3304 nhg
= rib_get_fib_backup_nhg(re
);
3305 if (nhg
&& nhg
->nexthop
) {
3306 copy_nexthops(&(new_ctx
->u
.rinfo
.zd_ng
.nexthop
),
3307 nhg
->nexthop
, NULL
);
3310 for (ALL_NEXTHOPS(new_ctx
->u
.rinfo
.zd_ng
, nexthop
))
3311 UNSET_FLAG(nexthop
->flags
, NEXTHOP_FLAG_FIB
);
3315 /* Capture info about the source of the notification, in 'ctx' */
3316 dplane_ctx_set_notif_provider(new_ctx
,
3317 dplane_ctx_get_notif_provider(ctx
));
3319 ret
= dplane_update_enqueue(new_ctx
);
3323 result
= ZEBRA_DPLANE_REQUEST_QUEUED
;
3325 dplane_ctx_free(&new_ctx
);
3331 * Enqueue a nexthop add for the dataplane.
3333 enum zebra_dplane_result
dplane_nexthop_add(struct nhg_hash_entry
*nhe
)
3335 enum zebra_dplane_result ret
= ZEBRA_DPLANE_REQUEST_FAILURE
;
3338 ret
= dplane_nexthop_update_internal(nhe
, DPLANE_OP_NH_INSTALL
);
3343 * Enqueue a nexthop update for the dataplane.
3345 * Might not need this func since zebra's nexthop objects should be immutable?
3347 enum zebra_dplane_result
dplane_nexthop_update(struct nhg_hash_entry
*nhe
)
3349 enum zebra_dplane_result ret
= ZEBRA_DPLANE_REQUEST_FAILURE
;
3352 ret
= dplane_nexthop_update_internal(nhe
, DPLANE_OP_NH_UPDATE
);
3357 * Enqueue a nexthop removal for the dataplane.
3359 enum zebra_dplane_result
dplane_nexthop_delete(struct nhg_hash_entry
*nhe
)
3361 enum zebra_dplane_result ret
= ZEBRA_DPLANE_REQUEST_FAILURE
;
3364 ret
= dplane_nexthop_update_internal(nhe
, DPLANE_OP_NH_DELETE
);
3370 * Enqueue LSP add for the dataplane.
3372 enum zebra_dplane_result
dplane_lsp_add(struct zebra_lsp
*lsp
)
3374 enum zebra_dplane_result ret
=
3375 lsp_update_internal(lsp
, DPLANE_OP_LSP_INSTALL
);
3381 * Enqueue LSP update for the dataplane.
3383 enum zebra_dplane_result
dplane_lsp_update(struct zebra_lsp
*lsp
)
3385 enum zebra_dplane_result ret
=
3386 lsp_update_internal(lsp
, DPLANE_OP_LSP_UPDATE
);
3392 * Enqueue LSP delete for the dataplane.
3394 enum zebra_dplane_result
dplane_lsp_delete(struct zebra_lsp
*lsp
)
3396 enum zebra_dplane_result ret
=
3397 lsp_update_internal(lsp
, DPLANE_OP_LSP_DELETE
);
3402 /* Update or un-install resulting from an async notification */
3403 enum zebra_dplane_result
3404 dplane_lsp_notif_update(struct zebra_lsp
*lsp
, enum dplane_op_e op
,
3405 struct zebra_dplane_ctx
*notif_ctx
)
3407 enum zebra_dplane_result result
= ZEBRA_DPLANE_REQUEST_FAILURE
;
3409 struct zebra_dplane_ctx
*ctx
= NULL
;
3410 struct nhlfe_list_head
*head
;
3411 struct zebra_nhlfe
*nhlfe
, *new_nhlfe
;
3413 /* Obtain context block */
3414 ctx
= dplane_ctx_alloc();
3420 /* Copy info from zebra LSP */
3421 ret
= dplane_ctx_lsp_init(ctx
, op
, lsp
);
3425 /* Add any installed backup nhlfes */
3426 head
= &(ctx
->u
.lsp
.backup_nhlfe_list
);
3427 frr_each(nhlfe_list
, head
, nhlfe
) {
3429 if (CHECK_FLAG(nhlfe
->flags
, NHLFE_FLAG_INSTALLED
) &&
3430 CHECK_FLAG(nhlfe
->nexthop
->flags
, NEXTHOP_FLAG_FIB
)) {
3431 new_nhlfe
= zebra_mpls_lsp_add_nh(&(ctx
->u
.lsp
),
3435 /* Need to copy flags too */
3436 new_nhlfe
->flags
= nhlfe
->flags
;
3437 new_nhlfe
->nexthop
->flags
= nhlfe
->nexthop
->flags
;
3441 /* Capture info about the source of the notification */
3442 dplane_ctx_set_notif_provider(
3444 dplane_ctx_get_notif_provider(notif_ctx
));
3446 ret
= dplane_update_enqueue(ctx
);
3449 /* Update counter */
3450 atomic_fetch_add_explicit(&zdplane_info
.dg_lsps_in
, 1,
3451 memory_order_relaxed
);
3454 result
= ZEBRA_DPLANE_REQUEST_QUEUED
;
3456 atomic_fetch_add_explicit(&zdplane_info
.dg_lsp_errors
, 1,
3457 memory_order_relaxed
);
3459 dplane_ctx_free(&ctx
);
3465 * Enqueue pseudowire install for the dataplane.
3467 enum zebra_dplane_result
dplane_pw_install(struct zebra_pw
*pw
)
3469 return pw_update_internal(pw
, DPLANE_OP_PW_INSTALL
);
3473 * Enqueue pseudowire un-install for the dataplane.
3475 enum zebra_dplane_result
dplane_pw_uninstall(struct zebra_pw
*pw
)
3477 return pw_update_internal(pw
, DPLANE_OP_PW_UNINSTALL
);
3481 * Common internal LSP update utility
3483 static enum zebra_dplane_result
lsp_update_internal(struct zebra_lsp
*lsp
,
3484 enum dplane_op_e op
)
3486 enum zebra_dplane_result result
= ZEBRA_DPLANE_REQUEST_FAILURE
;
3488 struct zebra_dplane_ctx
*ctx
= NULL
;
3490 /* Obtain context block */
3491 ctx
= dplane_ctx_alloc();
3493 ret
= dplane_ctx_lsp_init(ctx
, op
, lsp
);
3497 ret
= dplane_update_enqueue(ctx
);
3500 /* Update counter */
3501 atomic_fetch_add_explicit(&zdplane_info
.dg_lsps_in
, 1,
3502 memory_order_relaxed
);
3505 result
= ZEBRA_DPLANE_REQUEST_QUEUED
;
3507 atomic_fetch_add_explicit(&zdplane_info
.dg_lsp_errors
, 1,
3508 memory_order_relaxed
);
3509 dplane_ctx_free(&ctx
);
3516 * Internal, common handler for pseudowire updates.
3518 static enum zebra_dplane_result
pw_update_internal(struct zebra_pw
*pw
,
3519 enum dplane_op_e op
)
3521 enum zebra_dplane_result result
= ZEBRA_DPLANE_REQUEST_FAILURE
;
3523 struct zebra_dplane_ctx
*ctx
= NULL
;
3525 ctx
= dplane_ctx_alloc();
3527 ret
= dplane_ctx_pw_init(ctx
, op
, pw
);
3531 ret
= dplane_update_enqueue(ctx
);
3534 /* Update counter */
3535 atomic_fetch_add_explicit(&zdplane_info
.dg_pws_in
, 1,
3536 memory_order_relaxed
);
3539 result
= ZEBRA_DPLANE_REQUEST_QUEUED
;
3541 atomic_fetch_add_explicit(&zdplane_info
.dg_pw_errors
, 1,
3542 memory_order_relaxed
);
3543 dplane_ctx_free(&ctx
);
3550 * Enqueue access br_port update.
3552 enum zebra_dplane_result
3553 dplane_br_port_update(const struct interface
*ifp
, bool non_df
,
3554 uint32_t sph_filter_cnt
,
3555 const struct in_addr
*sph_filters
, uint32_t backup_nhg_id
)
3557 enum zebra_dplane_result result
= ZEBRA_DPLANE_REQUEST_FAILURE
;
3560 struct zebra_dplane_ctx
*ctx
= NULL
;
3561 struct zebra_ns
*zns
;
3562 enum dplane_op_e op
= DPLANE_OP_BR_PORT_UPDATE
;
3565 flags
|= DPLANE_BR_PORT_NON_DF
;
3567 if (IS_ZEBRA_DEBUG_DPLANE_DETAIL
|| IS_ZEBRA_DEBUG_EVPN_MH_ES
) {
3569 char vtep_str
[ES_VTEP_LIST_STR_SZ
];
3572 for (i
= 0; i
< sph_filter_cnt
; ++i
) {
3573 snprintfrr(vtep_str
+ strlen(vtep_str
),
3574 sizeof(vtep_str
) - strlen(vtep_str
), "%pI4 ",
3578 "init br_port ctx %s: ifp %s, flags 0x%x backup_nhg 0x%x sph %s",
3579 dplane_op2str(op
), ifp
->name
, flags
, backup_nhg_id
,
3583 ctx
= dplane_ctx_alloc();
3586 ctx
->zd_status
= ZEBRA_DPLANE_REQUEST_SUCCESS
;
3587 ctx
->zd_vrf_id
= ifp
->vrf
->vrf_id
;
3589 zns
= zebra_ns_lookup(ifp
->vrf
->vrf_id
);
3590 dplane_ctx_ns_init(ctx
, zns
, false);
3592 ctx
->zd_ifindex
= ifp
->ifindex
;
3593 strlcpy(ctx
->zd_ifname
, ifp
->name
, sizeof(ctx
->zd_ifname
));
3595 /* Init the br-port-specific data area */
3596 memset(&ctx
->u
.br_port
, 0, sizeof(ctx
->u
.br_port
));
3598 ctx
->u
.br_port
.flags
= flags
;
3599 ctx
->u
.br_port
.backup_nhg_id
= backup_nhg_id
;
3600 ctx
->u
.br_port
.sph_filter_cnt
= sph_filter_cnt
;
3601 memcpy(ctx
->u
.br_port
.sph_filters
, sph_filters
,
3602 sizeof(ctx
->u
.br_port
.sph_filters
[0]) * sph_filter_cnt
);
3604 /* Enqueue for processing on the dplane pthread */
3605 ret
= dplane_update_enqueue(ctx
);
3607 /* Increment counter */
3608 atomic_fetch_add_explicit(&zdplane_info
.dg_br_port_in
, 1,
3609 memory_order_relaxed
);
3612 result
= ZEBRA_DPLANE_REQUEST_QUEUED
;
3615 atomic_fetch_add_explicit(&zdplane_info
.dg_br_port_errors
, 1,
3616 memory_order_relaxed
);
3617 dplane_ctx_free(&ctx
);
3624 * Enqueue interface address add for the dataplane.
3626 enum zebra_dplane_result
dplane_intf_addr_set(const struct interface
*ifp
,
3627 const struct connected
*ifc
)
3629 #if !defined(HAVE_NETLINK) && defined(HAVE_STRUCT_IFALIASREQ)
3630 /* Extra checks for this OS path. */
3632 /* Don't configure PtP addresses on broadcast ifs or reverse */
3633 if (!(ifp
->flags
& IFF_POINTOPOINT
) != !CONNECTED_PEER(ifc
)) {
3634 if (IS_ZEBRA_DEBUG_KERNEL
|| IS_ZEBRA_DEBUG_DPLANE
)
3635 zlog_debug("Failed to set intf addr: mismatch p2p and connected");
3637 return ZEBRA_DPLANE_REQUEST_FAILURE
;
3641 return intf_addr_update_internal(ifp
, ifc
, DPLANE_OP_ADDR_INSTALL
);
3645 * Enqueue interface address remove/uninstall for the dataplane.
3647 enum zebra_dplane_result
dplane_intf_addr_unset(const struct interface
*ifp
,
3648 const struct connected
*ifc
)
3650 return intf_addr_update_internal(ifp
, ifc
, DPLANE_OP_ADDR_UNINSTALL
);
3653 static enum zebra_dplane_result
intf_addr_update_internal(
3654 const struct interface
*ifp
, const struct connected
*ifc
,
3655 enum dplane_op_e op
)
3657 enum zebra_dplane_result result
= ZEBRA_DPLANE_REQUEST_FAILURE
;
3659 struct zebra_dplane_ctx
*ctx
= NULL
;
3660 struct zebra_ns
*zns
;
3662 if (IS_ZEBRA_DEBUG_DPLANE_DETAIL
)
3663 zlog_debug("init intf ctx %s: idx %d, addr %u:%pFX",
3664 dplane_op2str(op
), ifp
->ifindex
, ifp
->vrf
->vrf_id
,
3667 ctx
= dplane_ctx_alloc();
3670 ctx
->zd_status
= ZEBRA_DPLANE_REQUEST_SUCCESS
;
3671 ctx
->zd_vrf_id
= ifp
->vrf
->vrf_id
;
3673 zns
= zebra_ns_lookup(ifp
->vrf
->vrf_id
);
3674 dplane_ctx_ns_init(ctx
, zns
, false);
3676 /* Init the interface-addr-specific area */
3677 memset(&ctx
->u
.intf
, 0, sizeof(ctx
->u
.intf
));
3679 strlcpy(ctx
->zd_ifname
, ifp
->name
, sizeof(ctx
->zd_ifname
));
3680 ctx
->zd_ifindex
= ifp
->ifindex
;
3681 ctx
->u
.intf
.prefix
= *(ifc
->address
);
3683 if (if_is_broadcast(ifp
))
3684 ctx
->u
.intf
.flags
|= DPLANE_INTF_BROADCAST
;
3686 if (CONNECTED_PEER(ifc
)) {
3687 ctx
->u
.intf
.dest_prefix
= *(ifc
->destination
);
3688 ctx
->u
.intf
.flags
|=
3689 (DPLANE_INTF_CONNECTED
| DPLANE_INTF_HAS_DEST
);
3692 if (CHECK_FLAG(ifc
->flags
, ZEBRA_IFA_SECONDARY
))
3693 ctx
->u
.intf
.flags
|= DPLANE_INTF_SECONDARY
;
3698 ctx
->u
.intf
.flags
|= DPLANE_INTF_HAS_LABEL
;
3700 /* Use embedded buffer if it's adequate; else allocate. */
3701 len
= strlen(ifc
->label
);
3703 if (len
< sizeof(ctx
->u
.intf
.label_buf
)) {
3704 strlcpy(ctx
->u
.intf
.label_buf
, ifc
->label
,
3705 sizeof(ctx
->u
.intf
.label_buf
));
3706 ctx
->u
.intf
.label
= ctx
->u
.intf
.label_buf
;
3708 ctx
->u
.intf
.label
= strdup(ifc
->label
);
3712 ret
= dplane_update_enqueue(ctx
);
3714 /* Increment counter */
3715 atomic_fetch_add_explicit(&zdplane_info
.dg_intf_addrs_in
, 1,
3716 memory_order_relaxed
);
3719 result
= ZEBRA_DPLANE_REQUEST_QUEUED
;
3722 atomic_fetch_add_explicit(&zdplane_info
.dg_intf_addr_errors
,
3723 1, memory_order_relaxed
);
3724 dplane_ctx_free(&ctx
);
3731 * Enqueue vxlan/evpn mac add (or update).
3733 enum zebra_dplane_result
dplane_rem_mac_add(const struct interface
*ifp
,
3734 const struct interface
*bridge_ifp
,
3736 const struct ethaddr
*mac
,
3737 struct in_addr vtep_ip
,
3742 enum zebra_dplane_result result
;
3743 uint32_t update_flags
= 0;
3745 update_flags
|= DPLANE_MAC_REMOTE
;
3747 update_flags
|= DPLANE_MAC_WAS_STATIC
;
3749 /* Use common helper api */
3750 result
= mac_update_common(DPLANE_OP_MAC_INSTALL
, ifp
, bridge_ifp
,
3751 vid
, mac
, vtep_ip
, sticky
, nhg_id
, update_flags
);
3756 * Enqueue vxlan/evpn mac delete.
3758 enum zebra_dplane_result
dplane_rem_mac_del(const struct interface
*ifp
,
3759 const struct interface
*bridge_ifp
,
3761 const struct ethaddr
*mac
,
3762 struct in_addr vtep_ip
)
3764 enum zebra_dplane_result result
;
3765 uint32_t update_flags
= 0;
3767 update_flags
|= DPLANE_MAC_REMOTE
;
3769 /* Use common helper api */
3770 result
= mac_update_common(DPLANE_OP_MAC_DELETE
, ifp
, bridge_ifp
,
3771 vid
, mac
, vtep_ip
, false, 0, update_flags
);
3776 * API to configure link local with either MAC address or IP information
3778 enum zebra_dplane_result
dplane_neigh_ip_update(enum dplane_op_e op
,
3779 const struct interface
*ifp
,
3780 struct ipaddr
*link_ip
,
3782 uint32_t ndm_state
, int protocol
)
3784 enum zebra_dplane_result result
= ZEBRA_DPLANE_REQUEST_FAILURE
;
3786 uint32_t update_flags
;
3788 if (IS_ZEBRA_DEBUG_DPLANE_DETAIL
)
3789 zlog_debug("%s: init link ctx %s: ifp %s, link_ip %pIA ip %pIA",
3790 __func__
, dplane_op2str(op
), ifp
->name
, link_ip
, ip
);
3792 if (ndm_state
== ZEBRA_NEIGH_STATE_REACHABLE
)
3793 state
= DPLANE_NUD_REACHABLE
;
3794 else if (ndm_state
== ZEBRA_NEIGH_STATE_FAILED
)
3795 state
= DPLANE_NUD_FAILED
;
3797 update_flags
= DPLANE_NEIGH_NO_EXTENSION
;
3799 result
= neigh_update_internal(op
, ifp
, (const void *)link_ip
,
3800 ipaddr_family(link_ip
), ip
, 0, state
,
3801 update_flags
, protocol
);
3807 * Enqueue local mac add (or update).
3809 enum zebra_dplane_result
dplane_local_mac_add(const struct interface
*ifp
,
3810 const struct interface
*bridge_ifp
,
3812 const struct ethaddr
*mac
,
3814 uint32_t set_static
,
3815 uint32_t set_inactive
)
3817 enum zebra_dplane_result result
;
3818 uint32_t update_flags
= 0;
3819 struct in_addr vtep_ip
;
3822 update_flags
|= DPLANE_MAC_SET_STATIC
;
3825 update_flags
|= DPLANE_MAC_SET_INACTIVE
;
3829 /* Use common helper api */
3830 result
= mac_update_common(DPLANE_OP_MAC_INSTALL
, ifp
, bridge_ifp
,
3831 vid
, mac
, vtep_ip
, sticky
, 0,
3837 * Enqueue local mac del
3839 enum zebra_dplane_result
3840 dplane_local_mac_del(const struct interface
*ifp
,
3841 const struct interface
*bridge_ifp
, vlanid_t vid
,
3842 const struct ethaddr
*mac
)
3844 enum zebra_dplane_result result
;
3845 struct in_addr vtep_ip
;
3849 /* Use common helper api */
3850 result
= mac_update_common(DPLANE_OP_MAC_DELETE
, ifp
, bridge_ifp
, vid
,
3851 mac
, vtep_ip
, false, 0, 0);
3855 * Public api to init an empty context - either newly-allocated or
3856 * reset/cleared - for a MAC update.
3858 void dplane_mac_init(struct zebra_dplane_ctx
*ctx
,
3859 const struct interface
*ifp
,
3860 const struct interface
*br_ifp
,
3862 const struct ethaddr
*mac
,
3863 struct in_addr vtep_ip
,
3866 uint32_t update_flags
)
3868 struct zebra_ns
*zns
;
3870 ctx
->zd_status
= ZEBRA_DPLANE_REQUEST_SUCCESS
;
3871 ctx
->zd_vrf_id
= ifp
->vrf
->vrf_id
;
3873 zns
= zebra_ns_lookup(ifp
->vrf
->vrf_id
);
3874 dplane_ctx_ns_init(ctx
, zns
, false);
3876 strlcpy(ctx
->zd_ifname
, ifp
->name
, sizeof(ctx
->zd_ifname
));
3877 ctx
->zd_ifindex
= ifp
->ifindex
;
3879 /* Init the mac-specific data area */
3880 memset(&ctx
->u
.macinfo
, 0, sizeof(ctx
->u
.macinfo
));
3882 ctx
->u
.macinfo
.br_ifindex
= br_ifp
->ifindex
;
3883 ctx
->u
.macinfo
.vtep_ip
= vtep_ip
;
3884 ctx
->u
.macinfo
.mac
= *mac
;
3885 ctx
->u
.macinfo
.vid
= vid
;
3886 ctx
->u
.macinfo
.is_sticky
= sticky
;
3887 ctx
->u
.macinfo
.nhg_id
= nhg_id
;
3888 ctx
->u
.macinfo
.update_flags
= update_flags
;
3892 * Common helper api for MAC address/vxlan updates
3894 static enum zebra_dplane_result
3895 mac_update_common(enum dplane_op_e op
,
3896 const struct interface
*ifp
,
3897 const struct interface
*br_ifp
,
3899 const struct ethaddr
*mac
,
3900 struct in_addr vtep_ip
,
3903 uint32_t update_flags
)
3905 enum zebra_dplane_result result
= ZEBRA_DPLANE_REQUEST_FAILURE
;
3907 struct zebra_dplane_ctx
*ctx
= NULL
;
3909 if (IS_ZEBRA_DEBUG_DPLANE_DETAIL
)
3910 zlog_debug("init mac ctx %s: mac %pEA, ifp %s, vtep %pI4",
3911 dplane_op2str(op
), mac
, ifp
->name
, &vtep_ip
);
3913 ctx
= dplane_ctx_alloc();
3916 /* Common init for the ctx */
3917 dplane_mac_init(ctx
, ifp
, br_ifp
, vid
, mac
, vtep_ip
, sticky
,
3918 nhg_id
, update_flags
);
3920 /* Enqueue for processing on the dplane pthread */
3921 ret
= dplane_update_enqueue(ctx
);
3923 /* Increment counter */
3924 atomic_fetch_add_explicit(&zdplane_info
.dg_macs_in
, 1,
3925 memory_order_relaxed
);
3928 result
= ZEBRA_DPLANE_REQUEST_QUEUED
;
3931 atomic_fetch_add_explicit(&zdplane_info
.dg_mac_errors
, 1,
3932 memory_order_relaxed
);
3933 dplane_ctx_free(&ctx
);
3940 * Enqueue evpn neighbor add for the dataplane.
3942 enum zebra_dplane_result
dplane_rem_neigh_add(const struct interface
*ifp
,
3943 const struct ipaddr
*ip
,
3944 const struct ethaddr
*mac
,
3945 uint32_t flags
, bool was_static
)
3947 enum zebra_dplane_result result
= ZEBRA_DPLANE_REQUEST_FAILURE
;
3948 uint32_t update_flags
= 0;
3950 update_flags
|= DPLANE_NEIGH_REMOTE
;
3953 update_flags
|= DPLANE_NEIGH_WAS_STATIC
;
3955 result
= neigh_update_internal(
3956 DPLANE_OP_NEIGH_INSTALL
, ifp
, (const void *)mac
, AF_ETHERNET
,
3957 ip
, flags
, DPLANE_NUD_NOARP
, update_flags
, 0);
3963 * Enqueue local neighbor add for the dataplane.
3965 enum zebra_dplane_result
dplane_local_neigh_add(const struct interface
*ifp
,
3966 const struct ipaddr
*ip
,
3967 const struct ethaddr
*mac
,
3968 bool set_router
, bool set_static
,
3971 enum zebra_dplane_result result
= ZEBRA_DPLANE_REQUEST_FAILURE
;
3972 uint32_t update_flags
= 0;
3977 update_flags
|= DPLANE_NEIGH_SET_STATIC
;
3980 update_flags
|= DPLANE_NEIGH_SET_INACTIVE
;
3981 state
= DPLANE_NUD_STALE
;
3983 state
= DPLANE_NUD_REACHABLE
;
3987 ntf
|= DPLANE_NTF_ROUTER
;
3989 result
= neigh_update_internal(DPLANE_OP_NEIGH_INSTALL
, ifp
,
3990 (const void *)mac
, AF_ETHERNET
, ip
, ntf
,
3991 state
, update_flags
, 0);
3997 * Enqueue evpn neighbor delete for the dataplane.
3999 enum zebra_dplane_result
dplane_rem_neigh_delete(const struct interface
*ifp
,
4000 const struct ipaddr
*ip
)
4002 enum zebra_dplane_result result
;
4003 uint32_t update_flags
= 0;
4005 update_flags
|= DPLANE_NEIGH_REMOTE
;
4007 result
= neigh_update_internal(DPLANE_OP_NEIGH_DELETE
, ifp
, NULL
,
4008 AF_ETHERNET
, ip
, 0, 0, update_flags
, 0);
4014 * Enqueue evpn VTEP add for the dataplane.
4016 enum zebra_dplane_result
dplane_vtep_add(const struct interface
*ifp
,
4017 const struct in_addr
*ip
,
4020 enum zebra_dplane_result result
;
4021 struct ethaddr mac
= { {0, 0, 0, 0, 0, 0} };
4024 if (IS_ZEBRA_DEBUG_VXLAN
)
4025 zlog_debug("Install %pI4 into flood list for VNI %u intf %s(%u)",
4026 ip
, vni
, ifp
->name
, ifp
->ifindex
);
4028 SET_IPADDR_V4(&addr
);
4029 addr
.ipaddr_v4
= *ip
;
4031 result
= neigh_update_internal(DPLANE_OP_VTEP_ADD
, ifp
, &mac
,
4032 AF_ETHERNET
, &addr
, 0, 0, 0, 0);
4038 * Enqueue evpn VTEP add for the dataplane.
4040 enum zebra_dplane_result
dplane_vtep_delete(const struct interface
*ifp
,
4041 const struct in_addr
*ip
,
4044 enum zebra_dplane_result result
;
4045 struct ethaddr mac
= { {0, 0, 0, 0, 0, 0} };
4048 if (IS_ZEBRA_DEBUG_VXLAN
)
4050 "Uninstall %pI4 from flood list for VNI %u intf %s(%u)",
4051 ip
, vni
, ifp
->name
, ifp
->ifindex
);
4053 SET_IPADDR_V4(&addr
);
4054 addr
.ipaddr_v4
= *ip
;
4056 result
= neigh_update_internal(DPLANE_OP_VTEP_DELETE
, ifp
,
4057 (const void *)&mac
, AF_ETHERNET
, &addr
,
4063 enum zebra_dplane_result
dplane_neigh_discover(const struct interface
*ifp
,
4064 const struct ipaddr
*ip
)
4066 enum zebra_dplane_result result
;
4068 result
= neigh_update_internal(DPLANE_OP_NEIGH_DISCOVER
, ifp
, NULL
,
4069 AF_ETHERNET
, ip
, DPLANE_NTF_USE
,
4070 DPLANE_NUD_INCOMPLETE
, 0, 0);
4075 enum zebra_dplane_result
dplane_neigh_table_update(const struct interface
*ifp
,
4076 const uint8_t family
,
4077 const uint32_t app_probes
,
4078 const uint32_t ucast_probes
,
4079 const uint32_t mcast_probes
)
4081 enum zebra_dplane_result result
= ZEBRA_DPLANE_REQUEST_FAILURE
;
4083 struct zebra_dplane_ctx
*ctx
= NULL
;
4084 struct zebra_ns
*zns
;
4085 enum dplane_op_e op
= DPLANE_OP_NEIGH_TABLE_UPDATE
;
4087 if (IS_ZEBRA_DEBUG_DPLANE_DETAIL
) {
4088 zlog_debug("set neigh ctx %s: ifp %s, family %s",
4089 dplane_op2str(op
), ifp
->name
, family2str(family
));
4092 ctx
= dplane_ctx_alloc();
4095 ctx
->zd_status
= ZEBRA_DPLANE_REQUEST_SUCCESS
;
4096 ctx
->zd_vrf_id
= ifp
->vrf
->vrf_id
;
4098 zns
= zebra_ns_lookup(ifp
->vrf
->vrf_id
);
4099 dplane_ctx_ns_init(ctx
, zns
, false);
4101 strlcpy(ctx
->zd_ifname
, ifp
->name
, sizeof(ctx
->zd_ifname
));
4102 ctx
->zd_ifindex
= ifp
->ifindex
;
4104 /* Init the neighbor-specific data area */
4105 memset(&ctx
->u
.neightable
, 0, sizeof(ctx
->u
.neightable
));
4107 ctx
->u
.neightable
.family
= family
;
4108 ctx
->u
.neightable
.app_probes
= app_probes
;
4109 ctx
->u
.neightable
.ucast_probes
= ucast_probes
;
4110 ctx
->u
.neightable
.mcast_probes
= mcast_probes
;
4112 /* Enqueue for processing on the dplane pthread */
4113 ret
= dplane_update_enqueue(ctx
);
4115 /* Increment counter */
4116 atomic_fetch_add_explicit(&zdplane_info
.dg_neightable_in
, 1,
4117 memory_order_relaxed
);
4120 result
= ZEBRA_DPLANE_REQUEST_QUEUED
;
4123 atomic_fetch_add_explicit(&zdplane_info
.dg_neightable_errors
, 1,
4124 memory_order_relaxed
);
4125 dplane_ctx_free(&ctx
);
4132 * Common helper api for neighbor updates
4134 static enum zebra_dplane_result
4135 neigh_update_internal(enum dplane_op_e op
, const struct interface
*ifp
,
4136 const void *link
, const int link_family
,
4137 const struct ipaddr
*ip
, uint32_t flags
, uint16_t state
,
4138 uint32_t update_flags
, int protocol
)
4140 enum zebra_dplane_result result
= ZEBRA_DPLANE_REQUEST_FAILURE
;
4142 struct zebra_dplane_ctx
*ctx
= NULL
;
4143 struct zebra_ns
*zns
;
4144 const struct ethaddr
*mac
= NULL
;
4145 const struct ipaddr
*link_ip
= NULL
;
4147 if (link_family
== AF_ETHERNET
)
4148 mac
= (const struct ethaddr
*)link
;
4150 link_ip
= (const struct ipaddr
*)link
;
4152 if (IS_ZEBRA_DEBUG_DPLANE_DETAIL
) {
4153 char buf1
[PREFIX_STRLEN
];
4156 if (link_family
== AF_ETHERNET
)
4157 prefix_mac2str(mac
, buf1
, sizeof(buf1
));
4159 ipaddr2str(link_ip
, buf1
, sizeof(buf1
));
4160 zlog_debug("init neigh ctx %s: ifp %s, %s %s, ip %pIA",
4161 dplane_op2str(op
), ifp
->name
,
4162 link_family
== AF_ETHERNET
? "mac " : "link ",
4166 ctx
= dplane_ctx_alloc();
4169 ctx
->zd_status
= ZEBRA_DPLANE_REQUEST_SUCCESS
;
4170 ctx
->zd_vrf_id
= ifp
->vrf
->vrf_id
;
4171 dplane_ctx_set_type(ctx
, protocol
);
4173 zns
= zebra_ns_lookup(ifp
->vrf
->vrf_id
);
4174 dplane_ctx_ns_init(ctx
, zns
, false);
4176 strlcpy(ctx
->zd_ifname
, ifp
->name
, sizeof(ctx
->zd_ifname
));
4177 ctx
->zd_ifindex
= ifp
->ifindex
;
4179 /* Init the neighbor-specific data area */
4180 memset(&ctx
->u
.neigh
, 0, sizeof(ctx
->u
.neigh
));
4182 ctx
->u
.neigh
.ip_addr
= *ip
;
4184 ctx
->u
.neigh
.link
.mac
= *mac
;
4186 ctx
->u
.neigh
.link
.ip_addr
= *link_ip
;
4188 ctx
->u
.neigh
.flags
= flags
;
4189 ctx
->u
.neigh
.state
= state
;
4190 ctx
->u
.neigh
.update_flags
= update_flags
;
4192 /* Enqueue for processing on the dplane pthread */
4193 ret
= dplane_update_enqueue(ctx
);
4195 /* Increment counter */
4196 atomic_fetch_add_explicit(&zdplane_info
.dg_neighs_in
, 1,
4197 memory_order_relaxed
);
4200 result
= ZEBRA_DPLANE_REQUEST_QUEUED
;
4203 atomic_fetch_add_explicit(&zdplane_info
.dg_neigh_errors
, 1,
4204 memory_order_relaxed
);
4205 dplane_ctx_free(&ctx
);
4212 * Common helper api for PBR rule updates
4214 static enum zebra_dplane_result
4215 rule_update_internal(enum dplane_op_e op
, struct zebra_pbr_rule
*new_rule
,
4216 struct zebra_pbr_rule
*old_rule
)
4218 enum zebra_dplane_result result
= ZEBRA_DPLANE_REQUEST_FAILURE
;
4219 struct zebra_dplane_ctx
*ctx
;
4222 ctx
= dplane_ctx_alloc();
4224 ret
= dplane_ctx_rule_init(ctx
, op
, new_rule
, old_rule
);
4228 ret
= dplane_update_enqueue(ctx
);
4231 atomic_fetch_add_explicit(&zdplane_info
.dg_rules_in
, 1,
4232 memory_order_relaxed
);
4235 result
= ZEBRA_DPLANE_REQUEST_QUEUED
;
4237 atomic_fetch_add_explicit(&zdplane_info
.dg_rule_errors
, 1,
4238 memory_order_relaxed
);
4239 dplane_ctx_free(&ctx
);
4245 enum zebra_dplane_result
dplane_pbr_rule_add(struct zebra_pbr_rule
*rule
)
4247 return rule_update_internal(DPLANE_OP_RULE_ADD
, rule
, NULL
);
4250 enum zebra_dplane_result
dplane_pbr_rule_delete(struct zebra_pbr_rule
*rule
)
4252 return rule_update_internal(DPLANE_OP_RULE_DELETE
, rule
, NULL
);
4255 enum zebra_dplane_result
dplane_pbr_rule_update(struct zebra_pbr_rule
*old_rule
,
4256 struct zebra_pbr_rule
*new_rule
)
4258 return rule_update_internal(DPLANE_OP_RULE_UPDATE
, new_rule
, old_rule
);
4261 * Common helper api for iptable updates
4263 static enum zebra_dplane_result
4264 iptable_update_internal(enum dplane_op_e op
, struct zebra_pbr_iptable
*iptable
)
4266 enum zebra_dplane_result result
= ZEBRA_DPLANE_REQUEST_FAILURE
;
4267 struct zebra_dplane_ctx
*ctx
;
4270 ctx
= dplane_ctx_alloc();
4272 ret
= dplane_ctx_iptable_init(ctx
, op
, iptable
);
4276 ret
= dplane_update_enqueue(ctx
);
4279 atomic_fetch_add_explicit(&zdplane_info
.dg_iptable_in
, 1,
4280 memory_order_relaxed
);
4283 result
= ZEBRA_DPLANE_REQUEST_QUEUED
;
4285 atomic_fetch_add_explicit(&zdplane_info
.dg_iptable_errors
, 1,
4286 memory_order_relaxed
);
4287 dplane_ctx_free(&ctx
);
4293 enum zebra_dplane_result
4294 dplane_pbr_iptable_add(struct zebra_pbr_iptable
*iptable
)
4296 return iptable_update_internal(DPLANE_OP_IPTABLE_ADD
, iptable
);
4299 enum zebra_dplane_result
4300 dplane_pbr_iptable_delete(struct zebra_pbr_iptable
*iptable
)
4302 return iptable_update_internal(DPLANE_OP_IPTABLE_DELETE
, iptable
);
4306 * Common helper api for ipset updates
4308 static enum zebra_dplane_result
4309 ipset_update_internal(enum dplane_op_e op
, struct zebra_pbr_ipset
*ipset
)
4311 enum zebra_dplane_result result
= ZEBRA_DPLANE_REQUEST_FAILURE
;
4312 struct zebra_dplane_ctx
*ctx
;
4315 ctx
= dplane_ctx_alloc();
4317 ret
= dplane_ctx_ipset_init(ctx
, op
, ipset
);
4321 ret
= dplane_update_enqueue(ctx
);
4324 atomic_fetch_add_explicit(&zdplane_info
.dg_ipset_in
, 1,
4325 memory_order_relaxed
);
4328 result
= ZEBRA_DPLANE_REQUEST_QUEUED
;
4330 atomic_fetch_add_explicit(&zdplane_info
.dg_ipset_errors
, 1,
4331 memory_order_relaxed
);
4332 dplane_ctx_free(&ctx
);
4338 enum zebra_dplane_result
dplane_pbr_ipset_add(struct zebra_pbr_ipset
*ipset
)
4340 return ipset_update_internal(DPLANE_OP_IPSET_ADD
, ipset
);
4343 enum zebra_dplane_result
dplane_pbr_ipset_delete(struct zebra_pbr_ipset
*ipset
)
4345 return ipset_update_internal(DPLANE_OP_IPSET_DELETE
, ipset
);
4349 * Common helper api for ipset updates
4351 static enum zebra_dplane_result
4352 ipset_entry_update_internal(enum dplane_op_e op
,
4353 struct zebra_pbr_ipset_entry
*ipset_entry
)
4355 enum zebra_dplane_result result
= ZEBRA_DPLANE_REQUEST_FAILURE
;
4356 struct zebra_dplane_ctx
*ctx
;
4359 ctx
= dplane_ctx_alloc();
4361 ret
= dplane_ctx_ipset_entry_init(ctx
, op
, ipset_entry
);
4365 ret
= dplane_update_enqueue(ctx
);
4368 atomic_fetch_add_explicit(&zdplane_info
.dg_ipset_entry_in
, 1,
4369 memory_order_relaxed
);
4372 result
= ZEBRA_DPLANE_REQUEST_QUEUED
;
4374 atomic_fetch_add_explicit(&zdplane_info
.dg_ipset_entry_errors
,
4375 1, memory_order_relaxed
);
4376 dplane_ctx_free(&ctx
);
4382 enum zebra_dplane_result
4383 dplane_pbr_ipset_entry_add(struct zebra_pbr_ipset_entry
*ipset
)
4385 return ipset_entry_update_internal(DPLANE_OP_IPSET_ENTRY_ADD
, ipset
);
4388 enum zebra_dplane_result
4389 dplane_pbr_ipset_entry_delete(struct zebra_pbr_ipset_entry
*ipset
)
4391 return ipset_entry_update_internal(DPLANE_OP_IPSET_ENTRY_DELETE
, ipset
);
4395 * Common helper api for GRE set
4397 enum zebra_dplane_result
4398 dplane_gre_set(struct interface
*ifp
, struct interface
*ifp_link
,
4399 unsigned int mtu
, const struct zebra_l2info_gre
*gre_info
)
4401 enum zebra_dplane_result result
= ZEBRA_DPLANE_REQUEST_FAILURE
;
4402 struct zebra_dplane_ctx
*ctx
;
4403 enum dplane_op_e op
= DPLANE_OP_GRE_SET
;
4405 struct zebra_ns
*zns
;
4407 ctx
= dplane_ctx_alloc();
4412 if (IS_ZEBRA_DEBUG_DPLANE_DETAIL
) {
4413 zlog_debug("init dplane ctx %s: if %s link %s%s",
4414 dplane_op2str(op
), ifp
->name
,
4415 ifp_link
? "set" : "unset", ifp_link
?
4416 ifp_link
->name
: "");
4420 ctx
->zd_status
= ZEBRA_DPLANE_REQUEST_SUCCESS
;
4421 zns
= zebra_ns_lookup(ifp
->vrf
->vrf_id
);
4424 dplane_ctx_ns_init(ctx
, zns
, false);
4426 dplane_ctx_set_ifname(ctx
, ifp
->name
);
4427 ctx
->zd_vrf_id
= ifp
->vrf
->vrf_id
;
4428 ctx
->zd_ifindex
= ifp
->ifindex
;
4430 ctx
->u
.gre
.link_ifindex
= ifp_link
->ifindex
;
4432 ctx
->u
.gre
.link_ifindex
= 0;
4434 memcpy(&ctx
->u
.gre
.info
, gre_info
, sizeof(ctx
->u
.gre
.info
));
4435 ctx
->u
.gre
.mtu
= mtu
;
4437 ctx
->zd_status
= ZEBRA_DPLANE_REQUEST_SUCCESS
;
4439 /* Enqueue context for processing */
4440 ret
= dplane_update_enqueue(ctx
);
4442 /* Update counter */
4443 atomic_fetch_add_explicit(&zdplane_info
.dg_gre_set_in
, 1,
4444 memory_order_relaxed
);
4447 result
= ZEBRA_DPLANE_REQUEST_QUEUED
;
4449 atomic_fetch_add_explicit(
4450 &zdplane_info
.dg_gre_set_errors
, 1,
4451 memory_order_relaxed
);
4453 dplane_ctx_free(&ctx
);
4454 result
= ZEBRA_DPLANE_REQUEST_FAILURE
;
4460 * Handler for 'show dplane'
4462 int dplane_show_helper(struct vty
*vty
, bool detailed
)
4464 uint64_t queued
, queue_max
, limit
, errs
, incoming
, yields
,
4467 /* Using atomics because counters are being changed in different
4470 incoming
= atomic_load_explicit(&zdplane_info
.dg_routes_in
,
4471 memory_order_relaxed
);
4472 limit
= atomic_load_explicit(&zdplane_info
.dg_max_queued_updates
,
4473 memory_order_relaxed
);
4474 queued
= atomic_load_explicit(&zdplane_info
.dg_routes_queued
,
4475 memory_order_relaxed
);
4476 queue_max
= atomic_load_explicit(&zdplane_info
.dg_routes_queued_max
,
4477 memory_order_relaxed
);
4478 errs
= atomic_load_explicit(&zdplane_info
.dg_route_errors
,
4479 memory_order_relaxed
);
4480 yields
= atomic_load_explicit(&zdplane_info
.dg_update_yields
,
4481 memory_order_relaxed
);
4482 other_errs
= atomic_load_explicit(&zdplane_info
.dg_other_errors
,
4483 memory_order_relaxed
);
4485 vty_out(vty
, "Zebra dataplane:\nRoute updates: %"PRIu64
"\n",
4487 vty_out(vty
, "Route update errors: %"PRIu64
"\n", errs
);
4488 vty_out(vty
, "Other errors : %"PRIu64
"\n", other_errs
);
4489 vty_out(vty
, "Route update queue limit: %"PRIu64
"\n", limit
);
4490 vty_out(vty
, "Route update queue depth: %"PRIu64
"\n", queued
);
4491 vty_out(vty
, "Route update queue max: %"PRIu64
"\n", queue_max
);
4492 vty_out(vty
, "Dplane update yields: %"PRIu64
"\n", yields
);
4494 incoming
= atomic_load_explicit(&zdplane_info
.dg_lsps_in
,
4495 memory_order_relaxed
);
4496 errs
= atomic_load_explicit(&zdplane_info
.dg_lsp_errors
,
4497 memory_order_relaxed
);
4498 vty_out(vty
, "LSP updates: %"PRIu64
"\n", incoming
);
4499 vty_out(vty
, "LSP update errors: %"PRIu64
"\n", errs
);
4501 incoming
= atomic_load_explicit(&zdplane_info
.dg_pws_in
,
4502 memory_order_relaxed
);
4503 errs
= atomic_load_explicit(&zdplane_info
.dg_pw_errors
,
4504 memory_order_relaxed
);
4505 vty_out(vty
, "PW updates: %"PRIu64
"\n", incoming
);
4506 vty_out(vty
, "PW update errors: %"PRIu64
"\n", errs
);
4508 incoming
= atomic_load_explicit(&zdplane_info
.dg_intf_addrs_in
,
4509 memory_order_relaxed
);
4510 errs
= atomic_load_explicit(&zdplane_info
.dg_intf_addr_errors
,
4511 memory_order_relaxed
);
4512 vty_out(vty
, "Intf addr updates: %"PRIu64
"\n", incoming
);
4513 vty_out(vty
, "Intf addr errors: %"PRIu64
"\n", errs
);
4515 incoming
= atomic_load_explicit(&zdplane_info
.dg_macs_in
,
4516 memory_order_relaxed
);
4517 errs
= atomic_load_explicit(&zdplane_info
.dg_mac_errors
,
4518 memory_order_relaxed
);
4519 vty_out(vty
, "EVPN MAC updates: %"PRIu64
"\n", incoming
);
4520 vty_out(vty
, "EVPN MAC errors: %"PRIu64
"\n", errs
);
4522 incoming
= atomic_load_explicit(&zdplane_info
.dg_neighs_in
,
4523 memory_order_relaxed
);
4524 errs
= atomic_load_explicit(&zdplane_info
.dg_neigh_errors
,
4525 memory_order_relaxed
);
4526 vty_out(vty
, "EVPN neigh updates: %"PRIu64
"\n", incoming
);
4527 vty_out(vty
, "EVPN neigh errors: %"PRIu64
"\n", errs
);
4529 incoming
= atomic_load_explicit(&zdplane_info
.dg_rules_in
,
4530 memory_order_relaxed
);
4531 errs
= atomic_load_explicit(&zdplane_info
.dg_rule_errors
,
4532 memory_order_relaxed
);
4533 vty_out(vty
, "Rule updates: %" PRIu64
"\n", incoming
);
4534 vty_out(vty
, "Rule errors: %" PRIu64
"\n", errs
);
4536 incoming
= atomic_load_explicit(&zdplane_info
.dg_br_port_in
,
4537 memory_order_relaxed
);
4538 errs
= atomic_load_explicit(&zdplane_info
.dg_br_port_errors
,
4539 memory_order_relaxed
);
4540 vty_out(vty
, "Bridge port updates: %" PRIu64
"\n", incoming
);
4541 vty_out(vty
, "Bridge port errors: %" PRIu64
"\n", errs
);
4543 incoming
= atomic_load_explicit(&zdplane_info
.dg_iptable_in
,
4544 memory_order_relaxed
);
4545 errs
= atomic_load_explicit(&zdplane_info
.dg_iptable_errors
,
4546 memory_order_relaxed
);
4547 vty_out(vty
, "IPtable updates: %" PRIu64
"\n", incoming
);
4548 vty_out(vty
, "IPtable errors: %" PRIu64
"\n", errs
);
4549 incoming
= atomic_load_explicit(&zdplane_info
.dg_ipset_in
,
4550 memory_order_relaxed
);
4551 errs
= atomic_load_explicit(&zdplane_info
.dg_ipset_errors
,
4552 memory_order_relaxed
);
4553 vty_out(vty
, "IPset updates: %" PRIu64
"\n", incoming
);
4554 vty_out(vty
, "IPset errors: %" PRIu64
"\n", errs
);
4555 incoming
= atomic_load_explicit(&zdplane_info
.dg_ipset_entry_in
,
4556 memory_order_relaxed
);
4557 errs
= atomic_load_explicit(&zdplane_info
.dg_ipset_entry_errors
,
4558 memory_order_relaxed
);
4559 vty_out(vty
, "IPset entry updates: %" PRIu64
"\n", incoming
);
4560 vty_out(vty
, "IPset entry errors: %" PRIu64
"\n", errs
);
4562 incoming
= atomic_load_explicit(&zdplane_info
.dg_neightable_in
,
4563 memory_order_relaxed
);
4564 errs
= atomic_load_explicit(&zdplane_info
.dg_neightable_errors
,
4565 memory_order_relaxed
);
4566 vty_out(vty
, "Neighbor Table updates: %"PRIu64
"\n", incoming
);
4567 vty_out(vty
, "Neighbor Table errors: %"PRIu64
"\n", errs
);
4569 incoming
= atomic_load_explicit(&zdplane_info
.dg_gre_set_in
,
4570 memory_order_relaxed
);
4571 errs
= atomic_load_explicit(&zdplane_info
.dg_gre_set_errors
,
4572 memory_order_relaxed
);
4573 vty_out(vty
, "GRE set updates: %"PRIu64
"\n", incoming
);
4574 vty_out(vty
, "GRE set errors: %"PRIu64
"\n", errs
);
4579 * Handler for 'show dplane providers'
4581 int dplane_show_provs_helper(struct vty
*vty
, bool detailed
)
4583 struct zebra_dplane_provider
*prov
;
4584 uint64_t in
, in_q
, in_max
, out
, out_q
, out_max
;
4586 vty_out(vty
, "Zebra dataplane providers:\n");
4589 prov
= TAILQ_FIRST(&zdplane_info
.dg_providers_q
);
4592 /* Show counters, useful info from each registered provider */
4595 in
= atomic_load_explicit(&prov
->dp_in_counter
,
4596 memory_order_relaxed
);
4597 in_q
= atomic_load_explicit(&prov
->dp_in_queued
,
4598 memory_order_relaxed
);
4599 in_max
= atomic_load_explicit(&prov
->dp_in_max
,
4600 memory_order_relaxed
);
4601 out
= atomic_load_explicit(&prov
->dp_out_counter
,
4602 memory_order_relaxed
);
4603 out_q
= atomic_load_explicit(&prov
->dp_out_queued
,
4604 memory_order_relaxed
);
4605 out_max
= atomic_load_explicit(&prov
->dp_out_max
,
4606 memory_order_relaxed
);
4608 vty_out(vty
, "%s (%u): in: %"PRIu64
", q: %"PRIu64
", q_max: %"PRIu64
", out: %"PRIu64
", q: %"PRIu64
", q_max: %"PRIu64
"\n",
4609 prov
->dp_name
, prov
->dp_id
, in
, in_q
, in_max
,
4610 out
, out_q
, out_max
);
4613 prov
= TAILQ_NEXT(prov
, dp_prov_link
);
4621 * Helper for 'show run' etc.
4623 int dplane_config_write_helper(struct vty
*vty
)
4625 if (zdplane_info
.dg_max_queued_updates
!= DPLANE_DEFAULT_MAX_QUEUED
)
4626 vty_out(vty
, "zebra dplane limit %u\n",
4627 zdplane_info
.dg_max_queued_updates
);
4633 * Provider registration
4635 int dplane_provider_register(const char *name
,
4636 enum dplane_provider_prio prio
,
4638 int (*start_fp
)(struct zebra_dplane_provider
*),
4639 int (*fp
)(struct zebra_dplane_provider
*),
4640 int (*fini_fp
)(struct zebra_dplane_provider
*,
4643 struct zebra_dplane_provider
**prov_p
)
4646 struct zebra_dplane_provider
*p
= NULL
, *last
;
4654 if (prio
<= DPLANE_PRIO_NONE
||
4655 prio
> DPLANE_PRIO_LAST
) {
4660 /* Allocate and init new provider struct */
4661 p
= XCALLOC(MTYPE_DP_PROV
, sizeof(struct zebra_dplane_provider
));
4663 pthread_mutex_init(&(p
->dp_mutex
), NULL
);
4664 TAILQ_INIT(&(p
->dp_ctx_in_q
));
4665 TAILQ_INIT(&(p
->dp_ctx_out_q
));
4667 p
->dp_flags
= flags
;
4668 p
->dp_priority
= prio
;
4670 p
->dp_start
= start_fp
;
4671 p
->dp_fini
= fini_fp
;
4674 /* Lock - the dplane pthread may be running */
4677 p
->dp_id
= ++zdplane_info
.dg_provider_id
;
4680 strlcpy(p
->dp_name
, name
, DPLANE_PROVIDER_NAMELEN
);
4682 snprintf(p
->dp_name
, DPLANE_PROVIDER_NAMELEN
,
4683 "provider-%u", p
->dp_id
);
4685 /* Insert into list ordered by priority */
4686 TAILQ_FOREACH(last
, &zdplane_info
.dg_providers_q
, dp_prov_link
) {
4687 if (last
->dp_priority
> p
->dp_priority
)
4692 TAILQ_INSERT_BEFORE(last
, p
, dp_prov_link
);
4694 TAILQ_INSERT_TAIL(&zdplane_info
.dg_providers_q
, p
,
4700 if (IS_ZEBRA_DEBUG_DPLANE
)
4701 zlog_debug("dplane: registered new provider '%s' (%u), prio %d",
4702 p
->dp_name
, p
->dp_id
, p
->dp_priority
);
4711 /* Accessors for provider attributes */
4712 const char *dplane_provider_get_name(const struct zebra_dplane_provider
*prov
)
4714 return prov
->dp_name
;
4717 uint32_t dplane_provider_get_id(const struct zebra_dplane_provider
*prov
)
4722 void *dplane_provider_get_data(const struct zebra_dplane_provider
*prov
)
4724 return prov
->dp_data
;
4727 int dplane_provider_get_work_limit(const struct zebra_dplane_provider
*prov
)
4729 return zdplane_info
.dg_updates_per_cycle
;
4732 /* Lock/unlock a provider's mutex - iff the provider was registered with
4733 * the THREADED flag.
4735 void dplane_provider_lock(struct zebra_dplane_provider
*prov
)
4737 if (dplane_provider_is_threaded(prov
))
4738 DPLANE_PROV_LOCK(prov
);
4741 void dplane_provider_unlock(struct zebra_dplane_provider
*prov
)
4743 if (dplane_provider_is_threaded(prov
))
4744 DPLANE_PROV_UNLOCK(prov
);
4748 * Dequeue and maintain associated counter
4750 struct zebra_dplane_ctx
*dplane_provider_dequeue_in_ctx(
4751 struct zebra_dplane_provider
*prov
)
4753 struct zebra_dplane_ctx
*ctx
= NULL
;
4755 dplane_provider_lock(prov
);
4757 ctx
= TAILQ_FIRST(&(prov
->dp_ctx_in_q
));
4759 TAILQ_REMOVE(&(prov
->dp_ctx_in_q
), ctx
, zd_q_entries
);
4761 atomic_fetch_sub_explicit(&prov
->dp_in_queued
, 1,
4762 memory_order_relaxed
);
4765 dplane_provider_unlock(prov
);
4771 * Dequeue work to a list, return count
4773 int dplane_provider_dequeue_in_list(struct zebra_dplane_provider
*prov
,
4774 struct dplane_ctx_q
*listp
)
4777 struct zebra_dplane_ctx
*ctx
;
4779 limit
= zdplane_info
.dg_updates_per_cycle
;
4781 dplane_provider_lock(prov
);
4783 for (ret
= 0; ret
< limit
; ret
++) {
4784 ctx
= TAILQ_FIRST(&(prov
->dp_ctx_in_q
));
4786 TAILQ_REMOVE(&(prov
->dp_ctx_in_q
), ctx
, zd_q_entries
);
4788 TAILQ_INSERT_TAIL(listp
, ctx
, zd_q_entries
);
4795 atomic_fetch_sub_explicit(&prov
->dp_in_queued
, ret
,
4796 memory_order_relaxed
);
4798 dplane_provider_unlock(prov
);
4803 uint32_t dplane_provider_out_ctx_queue_len(struct zebra_dplane_provider
*prov
)
4805 return atomic_load_explicit(&(prov
->dp_out_counter
),
4806 memory_order_relaxed
);
4810 * Enqueue and maintain associated counter
4812 void dplane_provider_enqueue_out_ctx(struct zebra_dplane_provider
*prov
,
4813 struct zebra_dplane_ctx
*ctx
)
4815 uint64_t curr
, high
;
4817 dplane_provider_lock(prov
);
4819 TAILQ_INSERT_TAIL(&(prov
->dp_ctx_out_q
), ctx
,
4822 /* Maintain out-queue counters */
4823 atomic_fetch_add_explicit(&(prov
->dp_out_queued
), 1,
4824 memory_order_relaxed
);
4825 curr
= atomic_load_explicit(&prov
->dp_out_queued
,
4826 memory_order_relaxed
);
4827 high
= atomic_load_explicit(&prov
->dp_out_max
,
4828 memory_order_relaxed
);
4830 atomic_store_explicit(&prov
->dp_out_max
, curr
,
4831 memory_order_relaxed
);
4833 dplane_provider_unlock(prov
);
4835 atomic_fetch_add_explicit(&(prov
->dp_out_counter
), 1,
4836 memory_order_relaxed
);
4840 * Accessor for provider object
4842 bool dplane_provider_is_threaded(const struct zebra_dplane_provider
*prov
)
4844 return (prov
->dp_flags
& DPLANE_PROV_FLAG_THREADED
);
4848 * Internal helper that copies information from a zebra ns object; this is
4849 * called in the zebra main pthread context as part of dplane ctx init.
4851 static void dplane_info_from_zns(struct zebra_dplane_info
*ns_info
,
4852 struct zebra_ns
*zns
)
4854 ns_info
->ns_id
= zns
->ns_id
;
4856 #if defined(HAVE_NETLINK)
4857 ns_info
->is_cmd
= true;
4858 ns_info
->sock
= zns
->netlink_dplane_out
.sock
;
4859 #endif /* NETLINK */
4864 * Callback when an OS (netlink) incoming event read is ready. This runs
4865 * in the dplane pthread.
4867 static int dplane_incoming_read(struct thread
*event
)
4869 struct dplane_zns_info
*zi
= THREAD_ARG(event
);
4871 kernel_dplane_read(&zi
->info
);
4873 /* Re-start read task */
4874 thread_add_read(zdplane_info
.dg_master
, dplane_incoming_read
, zi
,
4875 zi
->info
.sock
, &zi
->t_read
);
4879 #endif /* HAVE_NETLINK */
4882 * Notify dplane when namespaces are enabled and disabled. The dplane
4883 * needs to start and stop reading incoming events from the zns. In the
4884 * common case where vrfs are _not_ namespaces, there will only be one
4887 * This is called in the main pthread.
4889 void zebra_dplane_ns_enable(struct zebra_ns
*zns
, bool enabled
)
4891 struct dplane_zns_info
*zi
;
4893 if (IS_ZEBRA_DEBUG_DPLANE
)
4894 zlog_debug("%s: %s for nsid %u", __func__
,
4895 (enabled
? "ENABLED" : "DISABLED"), zns
->ns_id
);
4897 /* Search for an existing zns info entry */
4898 frr_each (zns_info_list
, &zdplane_info
.dg_zns_list
, zi
) {
4899 if (zi
->info
.ns_id
== zns
->ns_id
)
4904 /* Create a new entry if necessary; start reading. */
4906 zi
= XCALLOC(MTYPE_DP_NS
, sizeof(*zi
));
4908 zi
->info
.ns_id
= zns
->ns_id
;
4910 zns_info_list_add_tail(&zdplane_info
.dg_zns_list
, zi
);
4912 if (IS_ZEBRA_DEBUG_DPLANE
)
4913 zlog_debug("%s: nsid %u, new zi %p", __func__
,
4917 /* Make sure we're up-to-date with the zns object */
4918 #if defined(HAVE_NETLINK)
4919 zi
->info
.is_cmd
= false;
4920 zi
->info
.sock
= zns
->netlink_dplane_in
.sock
;
4922 /* Start read task for the dplane pthread. */
4923 if (zdplane_info
.dg_master
)
4924 thread_add_read(zdplane_info
.dg_master
,
4925 dplane_incoming_read
, zi
, zi
->info
.sock
,
4929 if (IS_ZEBRA_DEBUG_DPLANE
)
4930 zlog_debug("%s: nsid %u, deleting zi %p", __func__
,
4933 /* Stop reading, free memory */
4934 zns_info_list_del(&zdplane_info
.dg_zns_list
, zi
);
4936 if (zdplane_info
.dg_master
)
4937 thread_cancel_async(zdplane_info
.dg_master
, &zi
->t_read
,
4940 XFREE(MTYPE_DP_NS
, zi
);
4945 * Provider api to signal that work/events are available
4946 * for the dataplane pthread.
4948 int dplane_provider_work_ready(void)
4950 /* Note that during zebra startup, we may be offered work before
4951 * the dataplane pthread (and thread-master) are ready. We want to
4952 * enqueue the work, but the event-scheduling machinery may not be
4955 if (zdplane_info
.dg_run
) {
4956 thread_add_event(zdplane_info
.dg_master
,
4957 dplane_thread_loop
, NULL
, 0,
4958 &zdplane_info
.dg_t_update
);
4965 * Enqueue a context directly to zebra main.
4967 void dplane_provider_enqueue_to_zebra(struct zebra_dplane_ctx
*ctx
)
4969 struct dplane_ctx_q temp_list
;
4971 /* Zebra's api takes a list, so we need to use a temporary list */
4972 TAILQ_INIT(&temp_list
);
4974 TAILQ_INSERT_TAIL(&temp_list
, ctx
, zd_q_entries
);
4975 (zdplane_info
.dg_results_cb
)(&temp_list
);
4979 * Kernel dataplane provider
4982 static void kernel_dplane_log_detail(struct zebra_dplane_ctx
*ctx
)
4984 char buf
[PREFIX_STRLEN
];
4986 switch (dplane_ctx_get_op(ctx
)) {
4988 case DPLANE_OP_ROUTE_INSTALL
:
4989 case DPLANE_OP_ROUTE_UPDATE
:
4990 case DPLANE_OP_ROUTE_DELETE
:
4991 zlog_debug("%u:%pFX Dplane route update ctx %p op %s",
4992 dplane_ctx_get_vrf(ctx
), dplane_ctx_get_dest(ctx
),
4993 ctx
, dplane_op2str(dplane_ctx_get_op(ctx
)));
4996 case DPLANE_OP_NH_INSTALL
:
4997 case DPLANE_OP_NH_UPDATE
:
4998 case DPLANE_OP_NH_DELETE
:
4999 zlog_debug("ID (%u) Dplane nexthop update ctx %p op %s",
5000 dplane_ctx_get_nhe_id(ctx
), ctx
,
5001 dplane_op2str(dplane_ctx_get_op(ctx
)));
5004 case DPLANE_OP_LSP_INSTALL
:
5005 case DPLANE_OP_LSP_UPDATE
:
5006 case DPLANE_OP_LSP_DELETE
:
5009 case DPLANE_OP_PW_INSTALL
:
5010 case DPLANE_OP_PW_UNINSTALL
:
5011 zlog_debug("Dplane pw %s: op %s af %d loc: %u rem: %u",
5012 dplane_ctx_get_ifname(ctx
),
5013 dplane_op2str(ctx
->zd_op
), dplane_ctx_get_pw_af(ctx
),
5014 dplane_ctx_get_pw_local_label(ctx
),
5015 dplane_ctx_get_pw_remote_label(ctx
));
5018 case DPLANE_OP_ADDR_INSTALL
:
5019 case DPLANE_OP_ADDR_UNINSTALL
:
5020 zlog_debug("Dplane intf %s, idx %u, addr %pFX",
5021 dplane_op2str(dplane_ctx_get_op(ctx
)),
5022 dplane_ctx_get_ifindex(ctx
),
5023 dplane_ctx_get_intf_addr(ctx
));
5026 case DPLANE_OP_MAC_INSTALL
:
5027 case DPLANE_OP_MAC_DELETE
:
5028 prefix_mac2str(dplane_ctx_mac_get_addr(ctx
), buf
,
5031 zlog_debug("Dplane %s, mac %s, ifindex %u",
5032 dplane_op2str(dplane_ctx_get_op(ctx
)),
5033 buf
, dplane_ctx_get_ifindex(ctx
));
5036 case DPLANE_OP_NEIGH_INSTALL
:
5037 case DPLANE_OP_NEIGH_UPDATE
:
5038 case DPLANE_OP_NEIGH_DELETE
:
5039 case DPLANE_OP_VTEP_ADD
:
5040 case DPLANE_OP_VTEP_DELETE
:
5041 case DPLANE_OP_NEIGH_DISCOVER
:
5042 case DPLANE_OP_NEIGH_IP_INSTALL
:
5043 case DPLANE_OP_NEIGH_IP_DELETE
:
5044 ipaddr2str(dplane_ctx_neigh_get_ipaddr(ctx
), buf
,
5047 zlog_debug("Dplane %s, ip %s, ifindex %u",
5048 dplane_op2str(dplane_ctx_get_op(ctx
)),
5049 buf
, dplane_ctx_get_ifindex(ctx
));
5052 case DPLANE_OP_RULE_ADD
:
5053 case DPLANE_OP_RULE_DELETE
:
5054 case DPLANE_OP_RULE_UPDATE
:
5055 zlog_debug("Dplane rule update op %s, if %s(%u), ctx %p",
5056 dplane_op2str(dplane_ctx_get_op(ctx
)),
5057 dplane_ctx_get_ifname(ctx
),
5058 dplane_ctx_get_ifindex(ctx
), ctx
);
5061 case DPLANE_OP_SYS_ROUTE_ADD
:
5062 case DPLANE_OP_SYS_ROUTE_DELETE
:
5063 case DPLANE_OP_ROUTE_NOTIFY
:
5064 case DPLANE_OP_LSP_NOTIFY
:
5065 case DPLANE_OP_BR_PORT_UPDATE
:
5067 case DPLANE_OP_NONE
:
5070 case DPLANE_OP_IPTABLE_ADD
:
5071 case DPLANE_OP_IPTABLE_DELETE
: {
5072 struct zebra_pbr_iptable ipt
;
5074 dplane_ctx_get_pbr_iptable(ctx
, &ipt
);
5075 zlog_debug("Dplane iptable update op %s, unique(%u), ctx %p",
5076 dplane_op2str(dplane_ctx_get_op(ctx
)), ipt
.unique
,
5079 case DPLANE_OP_IPSET_ADD
:
5080 case DPLANE_OP_IPSET_DELETE
: {
5081 struct zebra_pbr_ipset ipset
;
5083 dplane_ctx_get_pbr_ipset(ctx
, &ipset
);
5084 zlog_debug("Dplane ipset update op %s, unique(%u), ctx %p",
5085 dplane_op2str(dplane_ctx_get_op(ctx
)), ipset
.unique
,
5088 case DPLANE_OP_IPSET_ENTRY_ADD
:
5089 case DPLANE_OP_IPSET_ENTRY_DELETE
: {
5090 struct zebra_pbr_ipset_entry ipent
;
5092 dplane_ctx_get_pbr_ipset_entry(ctx
, &ipent
);
5094 "Dplane ipset entry update op %s, unique(%u), ctx %p",
5095 dplane_op2str(dplane_ctx_get_op(ctx
)), ipent
.unique
,
5098 case DPLANE_OP_NEIGH_TABLE_UPDATE
:
5099 zlog_debug("Dplane neigh table op %s, ifp %s, family %s",
5100 dplane_op2str(dplane_ctx_get_op(ctx
)),
5101 dplane_ctx_get_ifname(ctx
),
5102 family2str(dplane_ctx_neightable_get_family(ctx
)));
5104 case DPLANE_OP_GRE_SET
:
5105 zlog_debug("Dplane gre set op %s, ifp %s, link %u",
5106 dplane_op2str(dplane_ctx_get_op(ctx
)),
5107 dplane_ctx_get_ifname(ctx
),
5108 ctx
->u
.gre
.link_ifindex
);
5111 case DPLANE_OP_INTF_ADDR_ADD
:
5112 case DPLANE_OP_INTF_ADDR_DEL
:
5113 zlog_debug("Dplane incoming op %s, intf %s, addr %pFX",
5114 dplane_op2str(dplane_ctx_get_op(ctx
)),
5115 dplane_ctx_get_ifname(ctx
),
5116 dplane_ctx_get_intf_addr(ctx
));
5121 static void kernel_dplane_handle_result(struct zebra_dplane_ctx
*ctx
)
5123 enum zebra_dplane_result res
= dplane_ctx_get_status(ctx
);
5125 switch (dplane_ctx_get_op(ctx
)) {
5127 case DPLANE_OP_ROUTE_INSTALL
:
5128 case DPLANE_OP_ROUTE_UPDATE
:
5129 case DPLANE_OP_ROUTE_DELETE
:
5130 if (res
!= ZEBRA_DPLANE_REQUEST_SUCCESS
)
5131 atomic_fetch_add_explicit(&zdplane_info
.dg_route_errors
,
5132 1, memory_order_relaxed
);
5134 if ((dplane_ctx_get_op(ctx
) != DPLANE_OP_ROUTE_DELETE
)
5135 && (res
== ZEBRA_DPLANE_REQUEST_SUCCESS
)) {
5136 struct nexthop
*nexthop
;
5138 /* Update installed nexthops to signal which have been
5141 for (ALL_NEXTHOPS_PTR(dplane_ctx_get_ng(ctx
),
5143 if (CHECK_FLAG(nexthop
->flags
,
5144 NEXTHOP_FLAG_RECURSIVE
))
5147 if (CHECK_FLAG(nexthop
->flags
,
5148 NEXTHOP_FLAG_ACTIVE
)) {
5149 SET_FLAG(nexthop
->flags
,
5156 case DPLANE_OP_NH_INSTALL
:
5157 case DPLANE_OP_NH_UPDATE
:
5158 case DPLANE_OP_NH_DELETE
:
5159 if (res
!= ZEBRA_DPLANE_REQUEST_SUCCESS
)
5160 atomic_fetch_add_explicit(
5161 &zdplane_info
.dg_nexthop_errors
, 1,
5162 memory_order_relaxed
);
5165 case DPLANE_OP_LSP_INSTALL
:
5166 case DPLANE_OP_LSP_UPDATE
:
5167 case DPLANE_OP_LSP_DELETE
:
5168 if (res
!= ZEBRA_DPLANE_REQUEST_SUCCESS
)
5169 atomic_fetch_add_explicit(&zdplane_info
.dg_lsp_errors
,
5170 1, memory_order_relaxed
);
5173 case DPLANE_OP_PW_INSTALL
:
5174 case DPLANE_OP_PW_UNINSTALL
:
5175 if (res
!= ZEBRA_DPLANE_REQUEST_SUCCESS
)
5176 atomic_fetch_add_explicit(&zdplane_info
.dg_pw_errors
, 1,
5177 memory_order_relaxed
);
5180 case DPLANE_OP_ADDR_INSTALL
:
5181 case DPLANE_OP_ADDR_UNINSTALL
:
5182 if (res
!= ZEBRA_DPLANE_REQUEST_SUCCESS
)
5183 atomic_fetch_add_explicit(
5184 &zdplane_info
.dg_intf_addr_errors
, 1,
5185 memory_order_relaxed
);
5188 case DPLANE_OP_MAC_INSTALL
:
5189 case DPLANE_OP_MAC_DELETE
:
5190 if (res
!= ZEBRA_DPLANE_REQUEST_SUCCESS
)
5191 atomic_fetch_add_explicit(&zdplane_info
.dg_mac_errors
,
5192 1, memory_order_relaxed
);
5195 case DPLANE_OP_NEIGH_INSTALL
:
5196 case DPLANE_OP_NEIGH_UPDATE
:
5197 case DPLANE_OP_NEIGH_DELETE
:
5198 case DPLANE_OP_VTEP_ADD
:
5199 case DPLANE_OP_VTEP_DELETE
:
5200 case DPLANE_OP_NEIGH_DISCOVER
:
5201 case DPLANE_OP_NEIGH_IP_INSTALL
:
5202 case DPLANE_OP_NEIGH_IP_DELETE
:
5203 if (res
!= ZEBRA_DPLANE_REQUEST_SUCCESS
)
5204 atomic_fetch_add_explicit(&zdplane_info
.dg_neigh_errors
,
5205 1, memory_order_relaxed
);
5208 case DPLANE_OP_RULE_ADD
:
5209 case DPLANE_OP_RULE_DELETE
:
5210 case DPLANE_OP_RULE_UPDATE
:
5211 if (res
!= ZEBRA_DPLANE_REQUEST_SUCCESS
)
5212 atomic_fetch_add_explicit(&zdplane_info
.dg_rule_errors
,
5213 1, memory_order_relaxed
);
5216 case DPLANE_OP_IPTABLE_ADD
:
5217 case DPLANE_OP_IPTABLE_DELETE
:
5218 if (res
!= ZEBRA_DPLANE_REQUEST_SUCCESS
)
5219 atomic_fetch_add_explicit(
5220 &zdplane_info
.dg_iptable_errors
, 1,
5221 memory_order_relaxed
);
5224 case DPLANE_OP_IPSET_ADD
:
5225 case DPLANE_OP_IPSET_DELETE
:
5226 if (res
!= ZEBRA_DPLANE_REQUEST_SUCCESS
)
5227 atomic_fetch_add_explicit(&zdplane_info
.dg_ipset_errors
,
5228 1, memory_order_relaxed
);
5231 case DPLANE_OP_IPSET_ENTRY_ADD
:
5232 case DPLANE_OP_IPSET_ENTRY_DELETE
:
5233 if (res
!= ZEBRA_DPLANE_REQUEST_SUCCESS
)
5234 atomic_fetch_add_explicit(
5235 &zdplane_info
.dg_ipset_entry_errors
, 1,
5236 memory_order_relaxed
);
5239 case DPLANE_OP_NEIGH_TABLE_UPDATE
:
5240 if (res
!= ZEBRA_DPLANE_REQUEST_SUCCESS
)
5241 atomic_fetch_add_explicit(
5242 &zdplane_info
.dg_neightable_errors
, 1,
5243 memory_order_relaxed
);
5246 case DPLANE_OP_GRE_SET
:
5247 if (res
!= ZEBRA_DPLANE_REQUEST_SUCCESS
)
5248 atomic_fetch_add_explicit(
5249 &zdplane_info
.dg_gre_set_errors
, 1,
5250 memory_order_relaxed
);
5252 /* Ignore 'notifications' - no-op */
5253 case DPLANE_OP_SYS_ROUTE_ADD
:
5254 case DPLANE_OP_SYS_ROUTE_DELETE
:
5255 case DPLANE_OP_ROUTE_NOTIFY
:
5256 case DPLANE_OP_LSP_NOTIFY
:
5257 case DPLANE_OP_BR_PORT_UPDATE
:
5260 /* TODO -- error counters for incoming events? */
5261 case DPLANE_OP_INTF_ADDR_ADD
:
5262 case DPLANE_OP_INTF_ADDR_DEL
:
5265 case DPLANE_OP_NONE
:
5266 if (res
!= ZEBRA_DPLANE_REQUEST_SUCCESS
)
5267 atomic_fetch_add_explicit(&zdplane_info
.dg_other_errors
,
5268 1, memory_order_relaxed
);
5273 static void kernel_dplane_process_iptable(struct zebra_dplane_provider
*prov
,
5274 struct zebra_dplane_ctx
*ctx
)
5276 zebra_pbr_process_iptable(ctx
);
5277 dplane_provider_enqueue_out_ctx(prov
, ctx
);
5280 static void kernel_dplane_process_ipset(struct zebra_dplane_provider
*prov
,
5281 struct zebra_dplane_ctx
*ctx
)
5283 zebra_pbr_process_ipset(ctx
);
5284 dplane_provider_enqueue_out_ctx(prov
, ctx
);
5288 kernel_dplane_process_ipset_entry(struct zebra_dplane_provider
*prov
,
5289 struct zebra_dplane_ctx
*ctx
)
5291 zebra_pbr_process_ipset_entry(ctx
);
5292 dplane_provider_enqueue_out_ctx(prov
, ctx
);
5296 * Kernel provider callback
5298 static int kernel_dplane_process_func(struct zebra_dplane_provider
*prov
)
5300 struct zebra_dplane_ctx
*ctx
, *tctx
;
5301 struct dplane_ctx_q work_list
;
5304 TAILQ_INIT(&work_list
);
5306 limit
= dplane_provider_get_work_limit(prov
);
5308 if (IS_ZEBRA_DEBUG_DPLANE_DETAIL
)
5309 zlog_debug("dplane provider '%s': processing",
5310 dplane_provider_get_name(prov
));
5312 for (counter
= 0; counter
< limit
; counter
++) {
5313 ctx
= dplane_provider_dequeue_in_ctx(prov
);
5316 if (IS_ZEBRA_DEBUG_DPLANE_DETAIL
)
5317 kernel_dplane_log_detail(ctx
);
5319 if ((dplane_ctx_get_op(ctx
) == DPLANE_OP_IPTABLE_ADD
5320 || dplane_ctx_get_op(ctx
) == DPLANE_OP_IPTABLE_DELETE
))
5321 kernel_dplane_process_iptable(prov
, ctx
);
5322 else if ((dplane_ctx_get_op(ctx
) == DPLANE_OP_IPSET_ADD
5323 || dplane_ctx_get_op(ctx
) == DPLANE_OP_IPSET_DELETE
))
5324 kernel_dplane_process_ipset(prov
, ctx
);
5325 else if ((dplane_ctx_get_op(ctx
) == DPLANE_OP_IPSET_ENTRY_ADD
5326 || dplane_ctx_get_op(ctx
)
5327 == DPLANE_OP_IPSET_ENTRY_DELETE
))
5328 kernel_dplane_process_ipset_entry(prov
, ctx
);
5330 TAILQ_INSERT_TAIL(&work_list
, ctx
, zd_q_entries
);
5333 kernel_update_multi(&work_list
);
5335 TAILQ_FOREACH_SAFE (ctx
, &work_list
, zd_q_entries
, tctx
) {
5336 kernel_dplane_handle_result(ctx
);
5338 TAILQ_REMOVE(&work_list
, ctx
, zd_q_entries
);
5339 dplane_provider_enqueue_out_ctx(prov
, ctx
);
5342 /* Ensure that we'll run the work loop again if there's still
5345 if (counter
>= limit
) {
5346 if (IS_ZEBRA_DEBUG_DPLANE_DETAIL
)
5347 zlog_debug("dplane provider '%s' reached max updates %d",
5348 dplane_provider_get_name(prov
), counter
);
5350 atomic_fetch_add_explicit(&zdplane_info
.dg_update_yields
,
5351 1, memory_order_relaxed
);
5353 dplane_provider_work_ready();
5359 #ifdef DPLANE_TEST_PROVIDER
5362 * Test dataplane provider plugin
5366 * Test provider process callback
5368 static int test_dplane_process_func(struct zebra_dplane_provider
*prov
)
5370 struct zebra_dplane_ctx
*ctx
;
5373 /* Just moving from 'in' queue to 'out' queue */
5375 if (IS_ZEBRA_DEBUG_DPLANE_DETAIL
)
5376 zlog_debug("dplane provider '%s': processing",
5377 dplane_provider_get_name(prov
));
5379 limit
= dplane_provider_get_work_limit(prov
);
5381 for (counter
= 0; counter
< limit
; counter
++) {
5382 ctx
= dplane_provider_dequeue_in_ctx(prov
);
5386 if (IS_ZEBRA_DEBUG_DPLANE_DETAIL
)
5387 zlog_debug("dplane provider '%s': op %s",
5388 dplane_provider_get_name(prov
),
5389 dplane_op2str(dplane_ctx_get_op(ctx
)));
5391 dplane_ctx_set_status(ctx
, ZEBRA_DPLANE_REQUEST_SUCCESS
);
5393 dplane_provider_enqueue_out_ctx(prov
, ctx
);
5396 if (IS_ZEBRA_DEBUG_DPLANE_DETAIL
)
5397 zlog_debug("dplane provider '%s': processed %d",
5398 dplane_provider_get_name(prov
), counter
);
5400 /* Ensure that we'll run the work loop again if there's still
5403 if (counter
>= limit
)
5404 dplane_provider_work_ready();
5410 * Test provider shutdown/fini callback
5412 static int test_dplane_shutdown_func(struct zebra_dplane_provider
*prov
,
5415 if (IS_ZEBRA_DEBUG_DPLANE
)
5416 zlog_debug("dplane provider '%s': %sshutdown",
5417 dplane_provider_get_name(prov
),
5418 early
? "early " : "");
5422 #endif /* DPLANE_TEST_PROVIDER */
5425 * Register default kernel provider
5427 static void dplane_provider_init(void)
5431 ret
= dplane_provider_register("Kernel",
5433 DPLANE_PROV_FLAGS_DEFAULT
, NULL
,
5434 kernel_dplane_process_func
,
5439 zlog_err("Unable to register kernel dplane provider: %d",
5442 #ifdef DPLANE_TEST_PROVIDER
5443 /* Optional test provider ... */
5444 ret
= dplane_provider_register("Test",
5445 DPLANE_PRIO_PRE_KERNEL
,
5446 DPLANE_PROV_FLAGS_DEFAULT
, NULL
,
5447 test_dplane_process_func
,
5448 test_dplane_shutdown_func
,
5449 NULL
/* data */, NULL
);
5452 zlog_err("Unable to register test dplane provider: %d",
5454 #endif /* DPLANE_TEST_PROVIDER */
5458 * Allow zebra code to walk the queue of pending contexts, evaluate each one
5459 * using a callback function. If the function returns 'true', the context
5460 * will be dequeued and freed without being processed.
5462 int dplane_clean_ctx_queue(bool (*context_cb
)(struct zebra_dplane_ctx
*ctx
,
5463 void *arg
), void *val
)
5465 struct zebra_dplane_ctx
*ctx
, *temp
;
5466 struct dplane_ctx_q work_list
;
5468 TAILQ_INIT(&work_list
);
5470 if (context_cb
== NULL
)
5473 /* Walk the pending context queue under the dplane lock. */
5476 TAILQ_FOREACH_SAFE(ctx
, &zdplane_info
.dg_update_ctx_q
, zd_q_entries
,
5478 if (context_cb(ctx
, val
)) {
5479 TAILQ_REMOVE(&zdplane_info
.dg_update_ctx_q
, ctx
,
5481 TAILQ_INSERT_TAIL(&work_list
, ctx
, zd_q_entries
);
5487 /* Now free any contexts selected by the caller, without holding
5490 TAILQ_FOREACH_SAFE(ctx
, &work_list
, zd_q_entries
, temp
) {
5491 TAILQ_REMOVE(&work_list
, ctx
, zd_q_entries
);
5492 dplane_ctx_fini(&ctx
);
5500 /* Indicates zebra shutdown/exit is in progress. Some operations may be
5501 * simplified or skipped during shutdown processing.
5503 bool dplane_is_in_shutdown(void)
5505 return zdplane_info
.dg_is_shutdown
;
5509 * Enable collection of extra info about interfaces in route updates.
5511 void dplane_enable_intf_extra_info(void)
5513 dplane_collect_extra_intf_info
= true;
5517 * Early or pre-shutdown, de-init notification api. This runs pretty
5518 * early during zebra shutdown, as a signal to stop new work and prepare
5519 * for updates generated by shutdown/cleanup activity, as zebra tries to
5520 * remove everything it's responsible for.
5521 * NB: This runs in the main zebra pthread context.
5523 void zebra_dplane_pre_finish(void)
5525 struct zebra_dplane_provider
*prov
;
5527 if (IS_ZEBRA_DEBUG_DPLANE
)
5528 zlog_debug("Zebra dataplane pre-finish called");
5530 zdplane_info
.dg_is_shutdown
= true;
5532 /* Notify provider(s) of pending shutdown. */
5533 TAILQ_FOREACH(prov
, &zdplane_info
.dg_providers_q
, dp_prov_link
) {
5534 if (prov
->dp_fini
== NULL
)
5537 prov
->dp_fini(prov
, true /* early */);
5542 * Utility to determine whether work remains enqueued within the dplane;
5543 * used during system shutdown processing.
5545 static bool dplane_work_pending(void)
5548 struct zebra_dplane_ctx
*ctx
;
5549 struct zebra_dplane_provider
*prov
;
5551 /* TODO -- just checking incoming/pending work for now, must check
5556 ctx
= TAILQ_FIRST(&zdplane_info
.dg_update_ctx_q
);
5557 prov
= TAILQ_FIRST(&zdplane_info
.dg_providers_q
);
5568 dplane_provider_lock(prov
);
5570 ctx
= TAILQ_FIRST(&(prov
->dp_ctx_in_q
));
5572 ctx
= TAILQ_FIRST(&(prov
->dp_ctx_out_q
));
5574 dplane_provider_unlock(prov
);
5580 prov
= TAILQ_NEXT(prov
, dp_prov_link
);
5592 * Shutdown-time intermediate callback, used to determine when all pending
5593 * in-flight updates are done. If there's still work to do, reschedules itself.
5594 * If all work is done, schedules an event to the main zebra thread for
5595 * final zebra shutdown.
5596 * This runs in the dplane pthread context.
5598 static int dplane_check_shutdown_status(struct thread
*event
)
5600 struct dplane_zns_info
*zi
;
5602 if (IS_ZEBRA_DEBUG_DPLANE
)
5603 zlog_debug("Zebra dataplane shutdown status check called");
5605 /* Remove any zns info entries as we stop the dplane pthread. */
5606 frr_each_safe (zns_info_list
, &zdplane_info
.dg_zns_list
, zi
) {
5607 zns_info_list_del(&zdplane_info
.dg_zns_list
, zi
);
5609 if (zdplane_info
.dg_master
)
5610 thread_cancel(&zi
->t_read
);
5612 XFREE(MTYPE_DP_NS
, zi
);
5615 if (dplane_work_pending()) {
5616 /* Reschedule dplane check on a short timer */
5617 thread_add_timer_msec(zdplane_info
.dg_master
,
5618 dplane_check_shutdown_status
,
5620 &zdplane_info
.dg_t_shutdown_check
);
5622 /* TODO - give up and stop waiting after a short time? */
5625 /* We appear to be done - schedule a final callback event
5626 * for the zebra main pthread.
5628 thread_add_event(zrouter
.master
, zebra_finalize
, NULL
, 0, NULL
);
5635 * Shutdown, de-init api. This runs pretty late during shutdown,
5636 * after zebra has tried to free/remove/uninstall all routes during shutdown.
5637 * At this point, dplane work may still remain to be done, so we can't just
5638 * blindly terminate. If there's still work to do, we'll periodically check
5639 * and when done, we'll enqueue a task to the zebra main thread for final
5640 * termination processing.
5642 * NB: This runs in the main zebra thread context.
5644 void zebra_dplane_finish(void)
5646 if (IS_ZEBRA_DEBUG_DPLANE
)
5647 zlog_debug("Zebra dataplane fini called");
5649 thread_add_event(zdplane_info
.dg_master
,
5650 dplane_check_shutdown_status
, NULL
, 0,
5651 &zdplane_info
.dg_t_shutdown_check
);
5655 * Main dataplane pthread event loop. The thread takes new incoming work
5656 * and offers it to the first provider. It then iterates through the
5657 * providers, taking complete work from each one and offering it
5658 * to the next in order. At each step, a limited number of updates are
5659 * processed during a cycle in order to provide some fairness.
5661 * This loop through the providers is only run once, so that the dataplane
5662 * pthread can look for other pending work - such as i/o work on behalf of
5665 static int dplane_thread_loop(struct thread
*event
)
5667 struct dplane_ctx_q work_list
;
5668 struct dplane_ctx_q error_list
;
5669 struct zebra_dplane_provider
*prov
;
5670 struct zebra_dplane_ctx
*ctx
, *tctx
;
5671 int limit
, counter
, error_counter
;
5672 uint64_t curr
, high
;
5673 bool reschedule
= false;
5675 /* Capture work limit per cycle */
5676 limit
= zdplane_info
.dg_updates_per_cycle
;
5678 /* Init temporary lists used to move contexts among providers */
5679 TAILQ_INIT(&work_list
);
5680 TAILQ_INIT(&error_list
);
5683 /* Check for zebra shutdown */
5684 if (!zdplane_info
.dg_run
)
5687 /* Dequeue some incoming work from zebra (if any) onto the temporary
5692 /* Locate initial registered provider */
5693 prov
= TAILQ_FIRST(&zdplane_info
.dg_providers_q
);
5695 /* Move new work from incoming list to temp list */
5696 for (counter
= 0; counter
< limit
; counter
++) {
5697 ctx
= TAILQ_FIRST(&zdplane_info
.dg_update_ctx_q
);
5699 TAILQ_REMOVE(&zdplane_info
.dg_update_ctx_q
, ctx
,
5702 ctx
->zd_provider
= prov
->dp_id
;
5704 TAILQ_INSERT_TAIL(&work_list
, ctx
, zd_q_entries
);
5712 atomic_fetch_sub_explicit(&zdplane_info
.dg_routes_queued
, counter
,
5713 memory_order_relaxed
);
5715 if (IS_ZEBRA_DEBUG_DPLANE_DETAIL
)
5716 zlog_debug("dplane: incoming new work counter: %d", counter
);
5718 /* Iterate through the registered providers, offering new incoming
5719 * work. If the provider has outgoing work in its queue, take that
5720 * work for the next provider
5724 /* At each iteration, the temporary work list has 'counter'
5727 if (IS_ZEBRA_DEBUG_DPLANE_DETAIL
)
5728 zlog_debug("dplane enqueues %d new work to provider '%s'",
5729 counter
, dplane_provider_get_name(prov
));
5731 /* Capture current provider id in each context; check for
5734 TAILQ_FOREACH_SAFE(ctx
, &work_list
, zd_q_entries
, tctx
) {
5735 if (dplane_ctx_get_status(ctx
) ==
5736 ZEBRA_DPLANE_REQUEST_SUCCESS
) {
5737 ctx
->zd_provider
= prov
->dp_id
;
5740 * TODO -- improve error-handling: recirc
5741 * errors backwards so that providers can
5742 * 'undo' their work (if they want to)
5745 /* Move to error list; will be returned
5748 TAILQ_REMOVE(&work_list
, ctx
, zd_q_entries
);
5749 TAILQ_INSERT_TAIL(&error_list
,
5755 /* Enqueue new work to the provider */
5756 dplane_provider_lock(prov
);
5758 if (TAILQ_FIRST(&work_list
))
5759 TAILQ_CONCAT(&(prov
->dp_ctx_in_q
), &work_list
,
5762 atomic_fetch_add_explicit(&prov
->dp_in_counter
, counter
,
5763 memory_order_relaxed
);
5764 atomic_fetch_add_explicit(&prov
->dp_in_queued
, counter
,
5765 memory_order_relaxed
);
5766 curr
= atomic_load_explicit(&prov
->dp_in_queued
,
5767 memory_order_relaxed
);
5768 high
= atomic_load_explicit(&prov
->dp_in_max
,
5769 memory_order_relaxed
);
5771 atomic_store_explicit(&prov
->dp_in_max
, curr
,
5772 memory_order_relaxed
);
5774 dplane_provider_unlock(prov
);
5776 /* Reset the temp list (though the 'concat' may have done this
5777 * already), and the counter
5779 TAILQ_INIT(&work_list
);
5782 /* Call into the provider code. Note that this is
5783 * unconditional: we offer to do work even if we don't enqueue
5786 (*prov
->dp_fp
)(prov
);
5788 /* Check for zebra shutdown */
5789 if (!zdplane_info
.dg_run
)
5792 /* Dequeue completed work from the provider */
5793 dplane_provider_lock(prov
);
5795 while (counter
< limit
) {
5796 ctx
= TAILQ_FIRST(&(prov
->dp_ctx_out_q
));
5798 TAILQ_REMOVE(&(prov
->dp_ctx_out_q
), ctx
,
5801 TAILQ_INSERT_TAIL(&work_list
,
5808 dplane_provider_unlock(prov
);
5810 if (counter
>= limit
)
5813 if (IS_ZEBRA_DEBUG_DPLANE_DETAIL
)
5814 zlog_debug("dplane dequeues %d completed work from provider %s",
5815 counter
, dplane_provider_get_name(prov
));
5817 /* Locate next provider */
5819 prov
= TAILQ_NEXT(prov
, dp_prov_link
);
5824 * We hit the work limit while processing at least one provider's
5825 * output queue - ensure we come back and finish it.
5828 dplane_provider_work_ready();
5830 /* After all providers have been serviced, enqueue any completed
5831 * work and any errors back to zebra so it can process the results.
5833 if (IS_ZEBRA_DEBUG_DPLANE_DETAIL
)
5834 zlog_debug("dplane has %d completed, %d errors, for zebra main",
5835 counter
, error_counter
);
5838 * Hand lists through the api to zebra main,
5839 * to reduce the number of lock/unlock cycles
5842 /* Call through to zebra main */
5843 (zdplane_info
.dg_results_cb
)(&error_list
);
5845 TAILQ_INIT(&error_list
);
5847 /* Call through to zebra main */
5848 (zdplane_info
.dg_results_cb
)(&work_list
);
5850 TAILQ_INIT(&work_list
);
5857 * Final phase of shutdown, after all work enqueued to dplane has been
5858 * processed. This is called from the zebra main pthread context.
5860 void zebra_dplane_shutdown(void)
5862 struct zebra_dplane_provider
*dp
;
5864 if (IS_ZEBRA_DEBUG_DPLANE
)
5865 zlog_debug("Zebra dataplane shutdown called");
5867 /* Stop dplane thread, if it's running */
5869 zdplane_info
.dg_run
= false;
5871 if (zdplane_info
.dg_t_update
)
5872 thread_cancel_async(zdplane_info
.dg_t_update
->master
,
5873 &zdplane_info
.dg_t_update
, NULL
);
5875 frr_pthread_stop(zdplane_info
.dg_pthread
, NULL
);
5877 /* Destroy pthread */
5878 frr_pthread_destroy(zdplane_info
.dg_pthread
);
5879 zdplane_info
.dg_pthread
= NULL
;
5880 zdplane_info
.dg_master
= NULL
;
5882 /* Notify provider(s) of final shutdown.
5883 * Note that this call is in the main pthread, so providers must
5884 * be prepared for that.
5886 TAILQ_FOREACH(dp
, &zdplane_info
.dg_providers_q
, dp_prov_link
) {
5887 if (dp
->dp_fini
== NULL
)
5890 dp
->dp_fini(dp
, false);
5893 /* TODO -- Clean-up provider objects */
5895 /* TODO -- Clean queue(s), free memory */
5899 * Initialize the dataplane module during startup, internal/private version
5901 static void zebra_dplane_init_internal(void)
5903 memset(&zdplane_info
, 0, sizeof(zdplane_info
));
5905 pthread_mutex_init(&zdplane_info
.dg_mutex
, NULL
);
5907 TAILQ_INIT(&zdplane_info
.dg_update_ctx_q
);
5908 TAILQ_INIT(&zdplane_info
.dg_providers_q
);
5909 zns_info_list_init(&zdplane_info
.dg_zns_list
);
5911 zdplane_info
.dg_updates_per_cycle
= DPLANE_DEFAULT_NEW_WORK
;
5913 zdplane_info
.dg_max_queued_updates
= DPLANE_DEFAULT_MAX_QUEUED
;
5915 /* Register default kernel 'provider' during init */
5916 dplane_provider_init();
5920 * Start the dataplane pthread. This step needs to be run later than the
5921 * 'init' step, in case zebra has fork-ed.
5923 void zebra_dplane_start(void)
5925 struct dplane_zns_info
*zi
;
5926 struct zebra_dplane_provider
*prov
;
5927 struct frr_pthread_attr pattr
= {
5928 .start
= frr_pthread_attr_default
.start
,
5929 .stop
= frr_pthread_attr_default
.stop
5932 /* Start dataplane pthread */
5934 zdplane_info
.dg_pthread
= frr_pthread_new(&pattr
, "Zebra dplane thread",
5937 zdplane_info
.dg_master
= zdplane_info
.dg_pthread
->master
;
5939 zdplane_info
.dg_run
= true;
5941 /* Enqueue an initial event for the dataplane pthread */
5942 thread_add_event(zdplane_info
.dg_master
, dplane_thread_loop
, NULL
, 0,
5943 &zdplane_info
.dg_t_update
);
5945 /* Enqueue reads if necessary */
5946 frr_each (zns_info_list
, &zdplane_info
.dg_zns_list
, zi
) {
5947 #if defined(HAVE_NETLINK)
5948 thread_add_read(zdplane_info
.dg_master
, dplane_incoming_read
,
5949 zi
, zi
->info
.sock
, &zi
->t_read
);
5953 /* Call start callbacks for registered providers */
5956 prov
= TAILQ_FIRST(&zdplane_info
.dg_providers_q
);
5962 (prov
->dp_start
)(prov
);
5964 /* Locate next provider */
5966 prov
= TAILQ_NEXT(prov
, dp_prov_link
);
5970 frr_pthread_run(zdplane_info
.dg_pthread
, NULL
);
5974 * Initialize the dataplane module at startup; called by zebra rib_init()
5976 void zebra_dplane_init(int (*results_fp
)(struct dplane_ctx_q
*))
5978 zebra_dplane_init_internal();
5979 zdplane_info
.dg_results_cb
= results_fp
;