1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Zebra dataplane layer.
4 * Copyright (c) 2018 Volta Networks, Inc.
11 #include "lib/libfrr.h"
12 #include "lib/debug.h"
13 #include "lib/frratomic.h"
14 #include "lib/frr_pthread.h"
15 #include "lib/memory.h"
16 #include "lib/zebra.h"
17 #include "zebra/netconf_netlink.h"
18 #include "zebra/zebra_router.h"
19 #include "zebra/zebra_dplane.h"
20 #include "zebra/zebra_vxlan_private.h"
21 #include "zebra/zebra_mpls.h"
23 #include "zebra/debug.h"
24 #include "zebra/zebra_pbr.h"
25 #include "zebra/zebra_neigh.h"
26 #include "zebra/zebra_tc.h"
30 DEFINE_MTYPE_STATIC(ZEBRA
, DP_CTX
, "Zebra DPlane Ctx");
31 DEFINE_MTYPE_STATIC(ZEBRA
, DP_INTF
, "Zebra DPlane Intf");
32 DEFINE_MTYPE_STATIC(ZEBRA
, DP_PROV
, "Zebra DPlane Provider");
33 DEFINE_MTYPE_STATIC(ZEBRA
, DP_NETFILTER
, "Zebra Netfilter Internal Object");
34 DEFINE_MTYPE_STATIC(ZEBRA
, DP_NS
, "DPlane NSes");
40 /* Control for collection of extra interface info with route updates; a plugin
41 * can enable the extra info via a dplane api.
43 static bool dplane_collect_extra_intf_info
;
45 /* Enable test dataplane provider */
46 /*#define DPLANE_TEST_PROVIDER 1 */
48 /* Default value for max queued incoming updates */
49 const uint32_t DPLANE_DEFAULT_MAX_QUEUED
= 200;
51 /* Default value for new work per cycle */
52 const uint32_t DPLANE_DEFAULT_NEW_WORK
= 100;
54 /* Validation check macro for context blocks */
55 /* #define DPLANE_DEBUG 1 */
59 # define DPLANE_CTX_VALID(p) \
64 # define DPLANE_CTX_VALID(p)
66 #endif /* DPLANE_DEBUG */
69 * Nexthop information captured for nexthop/nexthop group updates
71 struct dplane_nexthop_info
{
78 struct nexthop_group ng
;
79 struct nh_grp nh_grp
[MULTIPATH_NUM
];
84 * Optional extra info about interfaces used in route updates' nexthops.
86 struct dplane_intf_extra
{
92 struct dplane_intf_extra_list_item dlink
;
96 * Route information captured for route updates.
98 struct dplane_route_info
{
100 /* Dest and (optional) source prefixes */
101 struct prefix zd_dest
;
102 struct prefix zd_src
;
111 route_tag_t zd_old_tag
;
113 uint32_t zd_old_metric
;
115 uint16_t zd_instance
;
116 uint16_t zd_old_instance
;
119 uint8_t zd_old_distance
;
122 uint32_t zd_nexthop_mtu
;
126 /* Nexthop hash entry info */
127 struct dplane_nexthop_info nhe
;
131 struct nexthop_group zd_ng
;
133 /* Backup nexthops (if present) */
134 struct nexthop_group backup_ng
;
136 /* "Previous" nexthops, used only in route updates without netlink */
137 struct nexthop_group zd_old_ng
;
138 struct nexthop_group old_backup_ng
;
140 /* Optional list of extra interface info */
141 struct dplane_intf_extra_list_head intf_extra_list
;
145 * Pseudowire info for the dataplane
147 struct dplane_pw_info
{
154 mpls_label_t local_label
;
155 mpls_label_t remote_label
;
157 /* Nexthops that are valid and installed */
158 struct nexthop_group fib_nhg
;
160 /* Primary and backup nexthop sets, copied from the resolving route. */
161 struct nexthop_group primary_nhg
;
162 struct nexthop_group backup_nhg
;
164 union pw_protocol_fields fields
;
168 * Bridge port info for the dataplane
170 struct dplane_br_port_info
{
171 uint32_t sph_filter_cnt
;
172 struct in_addr sph_filters
[ES_VTEP_MAX_CNT
];
173 /* DPLANE_BR_PORT_XXX - see zebra_dplane.h*/
175 uint32_t backup_nhg_id
;
179 * Interface/prefix info for the dataplane
181 struct dplane_intf_info
{
189 #define DPLANE_INTF_CONNECTED (1 << 0) /* Connected peer, p2p */
190 #define DPLANE_INTF_SECONDARY (1 << 1)
191 #define DPLANE_INTF_BROADCAST (1 << 2)
192 #define DPLANE_INTF_HAS_DEST DPLANE_INTF_CONNECTED
193 #define DPLANE_INTF_HAS_LABEL (1 << 4)
195 /* Interface address/prefix */
196 struct prefix prefix
;
198 /* Dest address, for p2p, or broadcast prefix */
199 struct prefix dest_prefix
;
206 * EVPN MAC address info for the dataplane.
208 struct dplane_mac_info
{
210 ifindex_t br_ifindex
;
212 struct in_addr vtep_ip
;
215 uint32_t update_flags
;
219 * Neighbor info for the dataplane
221 struct dplane_neigh_info
{
222 struct ipaddr ip_addr
;
225 struct ipaddr ip_addr
;
229 uint32_t update_flags
;
235 struct dplane_neigh_table
{
238 uint32_t ucast_probes
;
239 uint32_t mcast_probes
;
243 * Policy based routing rule info for the dataplane
245 struct dplane_ctx_rule
{
248 /* The route table pointed by this rule */
251 /* Filter criteria */
255 struct prefix src_ip
;
256 struct prefix dst_ip
;
262 uint16_t action_vlan_id
;
263 uint16_t action_vlan_flags
;
265 uint32_t action_queue_id
;
267 char ifname
[INTERFACE_NAMSIZ
+ 1];
271 intptr_t dp_flow_ptr
;
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
;
296 * Network interface configuration info - aligned with netlink's NETCONF
297 * info. The flags values are public, in the dplane.h file...
299 struct dplane_netconf_info
{
300 enum dplane_netconf_status_e mpls_val
;
301 enum dplane_netconf_status_e mcast_val
;
302 enum dplane_netconf_status_e linkdown_val
;
305 struct dplane_tc_qdisc_info
{
306 enum tc_qdisc_kind kind
;
307 const char *kind_str
;
310 struct dplane_tc_class_info
{
312 enum tc_qdisc_kind kind
;
313 const char *kind_str
;
318 struct dplane_tc_filter_info
{
321 enum tc_filter_kind kind
;
322 const char *kind_str
;
326 struct prefix src_ip
;
327 struct prefix dst_ip
;
328 uint16_t src_port_min
;
329 uint16_t src_port_max
;
330 uint16_t dst_port_min
;
331 uint16_t dst_port_max
;
333 uint8_t dsfield_mask
;
338 * The context block used to exchange info about route updates across
339 * the boundary between the zebra main context (and pthread) and the
340 * dataplane layer (and pthread).
342 struct zebra_dplane_ctx
{
345 enum dplane_op_e zd_op
;
347 /* Status on return */
348 enum zebra_dplane_result zd_status
;
350 /* Dplane provider id */
351 uint32_t zd_provider
;
353 /* Flags - used by providers, e.g. */
361 /* Some updates may be generated by notifications: allow the
362 * plugin to notice and ignore results from its own notifications.
364 uint32_t zd_notif_provider
;
366 /* TODO -- internal/sub-operation status? */
367 enum zebra_dplane_result zd_remote_status
;
368 enum zebra_dplane_result zd_kernel_status
;
371 uint32_t zd_table_id
;
373 char zd_ifname
[INTERFACE_NAMSIZ
];
374 ifindex_t zd_ifindex
;
376 /* Support info for different kinds of updates */
378 struct dplane_route_info rinfo
;
379 struct zebra_lsp lsp
;
380 struct dplane_pw_info pw
;
381 struct dplane_br_port_info br_port
;
382 struct dplane_intf_info intf
;
383 struct dplane_mac_info macinfo
;
384 struct dplane_neigh_info neigh
;
385 struct dplane_rule_info rule
;
386 struct dplane_tc_qdisc_info tc_qdisc
;
387 struct dplane_tc_class_info tc_class
;
388 struct dplane_tc_filter_info tc_filter
;
389 struct zebra_pbr_iptable iptable
;
390 struct zebra_pbr_ipset ipset
;
392 struct zebra_pbr_ipset_entry entry
;
393 struct zebra_pbr_ipset_info info
;
395 struct dplane_neigh_table neightable
;
396 struct dplane_gre_ctx gre
;
397 struct dplane_netconf_info netconf
;
400 /* Namespace info, used especially for netlink kernel communication */
401 struct zebra_dplane_info zd_ns_info
;
403 /* Embedded list linkage */
404 struct dplane_ctx_list_item zd_entries
;
407 /* Flag that can be set by a pre-kernel provider as a signal that an update
408 * should bypass the kernel.
410 #define DPLANE_CTX_FLAG_NO_KERNEL 0x01
412 /* List types declared now that the structs involved are defined. */
413 DECLARE_DLIST(dplane_ctx_list
, struct zebra_dplane_ctx
, zd_entries
);
414 DECLARE_DLIST(dplane_intf_extra_list
, struct dplane_intf_extra
, dlink
);
416 /* List for dplane plugins/providers */
417 PREDECL_DLIST(dplane_prov_list
);
420 * Registration block for one dataplane provider.
422 struct zebra_dplane_provider
{
424 char dp_name
[DPLANE_PROVIDER_NAMELEN
+ 1];
426 /* Priority, for ordering among providers */
433 pthread_mutex_t dp_mutex
;
435 /* Plugin-provided extra data */
441 int (*dp_start
)(struct zebra_dplane_provider
*prov
);
443 int (*dp_fp
)(struct zebra_dplane_provider
*prov
);
445 int (*dp_fini
)(struct zebra_dplane_provider
*prov
, bool early_p
);
447 _Atomic
uint32_t dp_in_counter
;
448 _Atomic
uint32_t dp_in_queued
;
449 _Atomic
uint32_t dp_in_max
;
450 _Atomic
uint32_t dp_out_counter
;
451 _Atomic
uint32_t dp_out_queued
;
452 _Atomic
uint32_t dp_out_max
;
453 _Atomic
uint32_t dp_error_counter
;
455 /* Queue of contexts inbound to the provider */
456 struct dplane_ctx_list_head dp_ctx_in_list
;
458 /* Queue of completed contexts outbound from the provider back
459 * towards the dataplane module.
461 struct dplane_ctx_list_head dp_ctx_out_list
;
463 /* Embedded list linkage for provider objects */
464 struct dplane_prov_list_item dp_link
;
467 /* Declare list of providers/plugins */
468 DECLARE_DLIST(dplane_prov_list
, struct zebra_dplane_provider
, dp_link
);
470 /* Declare types for list of zns info objects */
471 PREDECL_DLIST(zns_info_list
);
473 struct dplane_zns_info
{
474 struct zebra_dplane_info info
;
476 /* Request data from the OS */
477 struct thread
*t_request
;
480 struct thread
*t_read
;
483 struct zns_info_list_item link
;
489 static struct zebra_dplane_globals
{
490 /* Mutex to control access to dataplane components */
491 pthread_mutex_t dg_mutex
;
493 /* Results callback registered by zebra 'core' */
494 int (*dg_results_cb
)(struct dplane_ctx_list_head
*ctxlist
);
496 /* Sentinel for beginning of shutdown */
497 volatile bool dg_is_shutdown
;
499 /* Sentinel for end of shutdown */
500 volatile bool dg_run
;
502 /* Update context queue inbound to the dataplane */
503 struct dplane_ctx_list_head dg_update_list
;
505 /* Ordered list of providers */
506 struct dplane_prov_list_head dg_providers
;
508 /* List of info about each zns */
509 struct zns_info_list_head dg_zns_list
;
511 /* Counter used to assign internal ids to providers */
512 uint32_t dg_provider_id
;
514 /* Limit number of pending, unprocessed updates */
515 _Atomic
uint32_t dg_max_queued_updates
;
517 /* Control whether system route notifications should be produced. */
518 bool dg_sys_route_notifs
;
520 /* Limit number of new updates dequeued at once, to pace an
523 uint32_t dg_updates_per_cycle
;
525 _Atomic
uint32_t dg_routes_in
;
526 _Atomic
uint32_t dg_routes_queued
;
527 _Atomic
uint32_t dg_routes_queued_max
;
528 _Atomic
uint32_t dg_route_errors
;
529 _Atomic
uint32_t dg_other_errors
;
531 _Atomic
uint32_t dg_nexthops_in
;
532 _Atomic
uint32_t dg_nexthop_errors
;
534 _Atomic
uint32_t dg_lsps_in
;
535 _Atomic
uint32_t dg_lsp_errors
;
537 _Atomic
uint32_t dg_pws_in
;
538 _Atomic
uint32_t dg_pw_errors
;
540 _Atomic
uint32_t dg_br_port_in
;
541 _Atomic
uint32_t dg_br_port_errors
;
543 _Atomic
uint32_t dg_intf_addrs_in
;
544 _Atomic
uint32_t dg_intf_addr_errors
;
545 _Atomic
uint32_t dg_intf_changes
;
546 _Atomic
uint32_t dg_intf_changes_errors
;
548 _Atomic
uint32_t dg_macs_in
;
549 _Atomic
uint32_t dg_mac_errors
;
551 _Atomic
uint32_t dg_neighs_in
;
552 _Atomic
uint32_t dg_neigh_errors
;
554 _Atomic
uint32_t dg_rules_in
;
555 _Atomic
uint32_t dg_rule_errors
;
557 _Atomic
uint32_t dg_update_yields
;
559 _Atomic
uint32_t dg_iptable_in
;
560 _Atomic
uint32_t dg_iptable_errors
;
562 _Atomic
uint32_t dg_ipset_in
;
563 _Atomic
uint32_t dg_ipset_errors
;
564 _Atomic
uint32_t dg_ipset_entry_in
;
565 _Atomic
uint32_t dg_ipset_entry_errors
;
567 _Atomic
uint32_t dg_neightable_in
;
568 _Atomic
uint32_t dg_neightable_errors
;
570 _Atomic
uint32_t dg_gre_set_in
;
571 _Atomic
uint32_t dg_gre_set_errors
;
573 _Atomic
uint32_t dg_intfs_in
;
574 _Atomic
uint32_t dg_intf_errors
;
576 _Atomic
uint32_t dg_tcs_in
;
577 _Atomic
uint32_t dg_tcs_errors
;
579 /* Dataplane pthread */
580 struct frr_pthread
*dg_pthread
;
582 /* Event-delivery context 'master' for the dplane */
583 struct thread_master
*dg_master
;
585 /* Event/'thread' pointer for queued updates */
586 struct thread
*dg_t_update
;
588 /* Event pointer for pending shutdown check loop */
589 struct thread
*dg_t_shutdown_check
;
593 /* Instantiate zns list type */
594 DECLARE_DLIST(zns_info_list
, struct dplane_zns_info
, link
);
597 * Lock and unlock for interactions with the zebra 'core' pthread
599 #define DPLANE_LOCK() pthread_mutex_lock(&zdplane_info.dg_mutex)
600 #define DPLANE_UNLOCK() pthread_mutex_unlock(&zdplane_info.dg_mutex)
604 * Lock and unlock for individual providers
606 #define DPLANE_PROV_LOCK(p) pthread_mutex_lock(&((p)->dp_mutex))
607 #define DPLANE_PROV_UNLOCK(p) pthread_mutex_unlock(&((p)->dp_mutex))
610 static void dplane_thread_loop(struct thread
*event
);
611 static enum zebra_dplane_result
lsp_update_internal(struct zebra_lsp
*lsp
,
612 enum dplane_op_e op
);
613 static enum zebra_dplane_result
pw_update_internal(struct zebra_pw
*pw
,
614 enum dplane_op_e op
);
615 static enum zebra_dplane_result
intf_addr_update_internal(
616 const struct interface
*ifp
, const struct connected
*ifc
,
617 enum dplane_op_e op
);
618 static enum zebra_dplane_result
mac_update_common(
619 enum dplane_op_e op
, const struct interface
*ifp
,
620 const struct interface
*br_ifp
,
621 vlanid_t vid
, const struct ethaddr
*mac
,
622 struct in_addr vtep_ip
, bool sticky
, uint32_t nhg_id
,
623 uint32_t update_flags
);
624 static enum zebra_dplane_result
625 neigh_update_internal(enum dplane_op_e op
, const struct interface
*ifp
,
626 const void *link
, int link_family
,
627 const struct ipaddr
*ip
, uint32_t flags
, uint16_t state
,
628 uint32_t update_flags
, int protocol
);
634 /* Obtain thread_master for dataplane thread */
635 struct thread_master
*dplane_get_thread_master(void)
637 return zdplane_info
.dg_master
;
641 * Allocate a dataplane update context
643 struct zebra_dplane_ctx
*dplane_ctx_alloc(void)
645 struct zebra_dplane_ctx
*p
;
647 /* TODO -- just alloc'ing memory, but would like to maintain
650 p
= XCALLOC(MTYPE_DP_CTX
, sizeof(struct zebra_dplane_ctx
));
655 /* Enable system route notifications */
656 void dplane_enable_sys_route_notifs(void)
658 zdplane_info
.dg_sys_route_notifs
= true;
662 * Clean up dependent/internal allocations inside a context object
664 static void dplane_ctx_free_internal(struct zebra_dplane_ctx
*ctx
)
666 struct dplane_intf_extra
*if_extra
;
669 * Some internal allocations may need to be freed, depending on
670 * the type of info captured in the ctx.
672 switch (ctx
->zd_op
) {
673 case DPLANE_OP_ROUTE_INSTALL
:
674 case DPLANE_OP_ROUTE_UPDATE
:
675 case DPLANE_OP_ROUTE_DELETE
:
676 case DPLANE_OP_SYS_ROUTE_ADD
:
677 case DPLANE_OP_SYS_ROUTE_DELETE
:
678 case DPLANE_OP_ROUTE_NOTIFY
:
680 /* Free allocated nexthops */
681 if (ctx
->u
.rinfo
.zd_ng
.nexthop
) {
682 /* This deals with recursive nexthops too */
683 nexthops_free(ctx
->u
.rinfo
.zd_ng
.nexthop
);
685 ctx
->u
.rinfo
.zd_ng
.nexthop
= NULL
;
688 /* Free backup info also (if present) */
689 if (ctx
->u
.rinfo
.backup_ng
.nexthop
) {
690 /* This deals with recursive nexthops too */
691 nexthops_free(ctx
->u
.rinfo
.backup_ng
.nexthop
);
693 ctx
->u
.rinfo
.backup_ng
.nexthop
= NULL
;
696 if (ctx
->u
.rinfo
.zd_old_ng
.nexthop
) {
697 /* This deals with recursive nexthops too */
698 nexthops_free(ctx
->u
.rinfo
.zd_old_ng
.nexthop
);
700 ctx
->u
.rinfo
.zd_old_ng
.nexthop
= NULL
;
703 if (ctx
->u
.rinfo
.old_backup_ng
.nexthop
) {
704 /* This deals with recursive nexthops too */
705 nexthops_free(ctx
->u
.rinfo
.old_backup_ng
.nexthop
);
707 ctx
->u
.rinfo
.old_backup_ng
.nexthop
= NULL
;
710 /* Optional extra interface info */
711 while ((if_extra
= dplane_intf_extra_list_pop(
712 &ctx
->u
.rinfo
.intf_extra_list
)))
713 XFREE(MTYPE_DP_INTF
, if_extra
);
717 case DPLANE_OP_NH_INSTALL
:
718 case DPLANE_OP_NH_UPDATE
:
719 case DPLANE_OP_NH_DELETE
: {
720 if (ctx
->u
.rinfo
.nhe
.ng
.nexthop
) {
721 /* This deals with recursive nexthops too */
722 nexthops_free(ctx
->u
.rinfo
.nhe
.ng
.nexthop
);
724 ctx
->u
.rinfo
.nhe
.ng
.nexthop
= NULL
;
729 case DPLANE_OP_LSP_INSTALL
:
730 case DPLANE_OP_LSP_UPDATE
:
731 case DPLANE_OP_LSP_DELETE
:
732 case DPLANE_OP_LSP_NOTIFY
:
734 struct zebra_nhlfe
*nhlfe
;
736 /* Unlink and free allocated NHLFEs */
737 frr_each_safe(nhlfe_list
, &ctx
->u
.lsp
.nhlfe_list
, nhlfe
) {
738 nhlfe_list_del(&ctx
->u
.lsp
.nhlfe_list
, nhlfe
);
739 zebra_mpls_nhlfe_free(nhlfe
);
742 /* Unlink and free allocated backup NHLFEs, if present */
743 frr_each_safe(nhlfe_list
,
744 &(ctx
->u
.lsp
.backup_nhlfe_list
), nhlfe
) {
745 nhlfe_list_del(&ctx
->u
.lsp
.backup_nhlfe_list
,
747 zebra_mpls_nhlfe_free(nhlfe
);
750 /* Clear pointers in lsp struct, in case we're caching
751 * free context structs.
753 nhlfe_list_init(&ctx
->u
.lsp
.nhlfe_list
);
754 ctx
->u
.lsp
.best_nhlfe
= NULL
;
755 nhlfe_list_init(&ctx
->u
.lsp
.backup_nhlfe_list
);
760 case DPLANE_OP_PW_INSTALL
:
761 case DPLANE_OP_PW_UNINSTALL
:
762 /* Free allocated nexthops */
763 if (ctx
->u
.pw
.fib_nhg
.nexthop
) {
764 /* This deals with recursive nexthops too */
765 nexthops_free(ctx
->u
.pw
.fib_nhg
.nexthop
);
767 ctx
->u
.pw
.fib_nhg
.nexthop
= NULL
;
769 if (ctx
->u
.pw
.primary_nhg
.nexthop
) {
770 nexthops_free(ctx
->u
.pw
.primary_nhg
.nexthop
);
772 ctx
->u
.pw
.primary_nhg
.nexthop
= NULL
;
774 if (ctx
->u
.pw
.backup_nhg
.nexthop
) {
775 nexthops_free(ctx
->u
.pw
.backup_nhg
.nexthop
);
777 ctx
->u
.pw
.backup_nhg
.nexthop
= NULL
;
781 case DPLANE_OP_ADDR_INSTALL
:
782 case DPLANE_OP_ADDR_UNINSTALL
:
783 case DPLANE_OP_INTF_ADDR_ADD
:
784 case DPLANE_OP_INTF_ADDR_DEL
:
785 /* Maybe free label string, if allocated */
786 if (ctx
->u
.intf
.label
!= NULL
&&
787 ctx
->u
.intf
.label
!= ctx
->u
.intf
.label_buf
) {
788 XFREE(MTYPE_DP_CTX
, ctx
->u
.intf
.label
);
789 ctx
->u
.intf
.label
= NULL
;
793 case DPLANE_OP_MAC_INSTALL
:
794 case DPLANE_OP_MAC_DELETE
:
795 case DPLANE_OP_NEIGH_INSTALL
:
796 case DPLANE_OP_NEIGH_UPDATE
:
797 case DPLANE_OP_NEIGH_DELETE
:
798 case DPLANE_OP_VTEP_ADD
:
799 case DPLANE_OP_VTEP_DELETE
:
800 case DPLANE_OP_RULE_ADD
:
801 case DPLANE_OP_RULE_DELETE
:
802 case DPLANE_OP_RULE_UPDATE
:
803 case DPLANE_OP_NEIGH_DISCOVER
:
804 case DPLANE_OP_BR_PORT_UPDATE
:
805 case DPLANE_OP_NEIGH_IP_INSTALL
:
806 case DPLANE_OP_NEIGH_IP_DELETE
:
808 case DPLANE_OP_IPSET_ADD
:
809 case DPLANE_OP_IPSET_DELETE
:
810 case DPLANE_OP_INTF_INSTALL
:
811 case DPLANE_OP_INTF_UPDATE
:
812 case DPLANE_OP_INTF_DELETE
:
813 case DPLANE_OP_TC_QDISC_INSTALL
:
814 case DPLANE_OP_TC_QDISC_UNINSTALL
:
815 case DPLANE_OP_TC_CLASS_ADD
:
816 case DPLANE_OP_TC_CLASS_DELETE
:
817 case DPLANE_OP_TC_CLASS_UPDATE
:
818 case DPLANE_OP_TC_FILTER_ADD
:
819 case DPLANE_OP_TC_FILTER_DELETE
:
820 case DPLANE_OP_TC_FILTER_UPDATE
:
823 case DPLANE_OP_IPSET_ENTRY_ADD
:
824 case DPLANE_OP_IPSET_ENTRY_DELETE
:
826 case DPLANE_OP_NEIGH_TABLE_UPDATE
:
828 case DPLANE_OP_IPTABLE_ADD
:
829 case DPLANE_OP_IPTABLE_DELETE
:
830 if (ctx
->u
.iptable
.interface_name_list
)
831 list_delete(&ctx
->u
.iptable
.interface_name_list
);
833 case DPLANE_OP_GRE_SET
:
834 case DPLANE_OP_INTF_NETCONFIG
:
840 * Free a dataplane results context.
842 static void dplane_ctx_free(struct zebra_dplane_ctx
**pctx
)
847 DPLANE_CTX_VALID(*pctx
);
849 /* TODO -- just freeing memory, but would like to maintain
853 /* Some internal allocations may need to be freed, depending on
854 * the type of info captured in the ctx.
856 dplane_ctx_free_internal(*pctx
);
858 XFREE(MTYPE_DP_CTX
, *pctx
);
862 * Reset an allocated context object for re-use. All internal allocations are
863 * freed and the context is memset.
865 void dplane_ctx_reset(struct zebra_dplane_ctx
*ctx
)
867 dplane_ctx_free_internal(ctx
);
868 memset(ctx
, 0, sizeof(*ctx
));
872 * Return a context block to the dplane module after processing
874 void dplane_ctx_fini(struct zebra_dplane_ctx
**pctx
)
876 /* TODO -- maintain pool; for now, just free */
877 dplane_ctx_free(pctx
);
880 /* Init a list of contexts */
881 void dplane_ctx_q_init(struct dplane_ctx_list_head
*q
)
883 dplane_ctx_list_init(q
);
886 /* Enqueue a context block */
887 void dplane_ctx_enqueue_tail(struct dplane_ctx_list_head
*list
,
888 const struct zebra_dplane_ctx
*ctx
)
890 dplane_ctx_list_add_tail(list
, (struct zebra_dplane_ctx
*)ctx
);
893 /* Append a list of context blocks to another list */
894 void dplane_ctx_list_append(struct dplane_ctx_list_head
*to_list
,
895 struct dplane_ctx_list_head
*from_list
)
897 struct zebra_dplane_ctx
*ctx
;
899 while ((ctx
= dplane_ctx_list_pop(from_list
)) != NULL
)
900 dplane_ctx_list_add_tail(to_list
, ctx
);
903 struct zebra_dplane_ctx
*dplane_ctx_get_head(struct dplane_ctx_list_head
*q
)
905 struct zebra_dplane_ctx
*ctx
= dplane_ctx_list_first(q
);
910 /* Dequeue a context block from the head of a list */
911 struct zebra_dplane_ctx
*dplane_ctx_dequeue(struct dplane_ctx_list_head
*q
)
913 struct zebra_dplane_ctx
*ctx
= dplane_ctx_list_pop(q
);
919 * Accessors for information from the context object
921 enum zebra_dplane_result
dplane_ctx_get_status(
922 const struct zebra_dplane_ctx
*ctx
)
924 DPLANE_CTX_VALID(ctx
);
926 return ctx
->zd_status
;
929 void dplane_ctx_set_status(struct zebra_dplane_ctx
*ctx
,
930 enum zebra_dplane_result status
)
932 DPLANE_CTX_VALID(ctx
);
934 ctx
->zd_status
= status
;
937 /* Retrieve last/current provider id */
938 uint32_t dplane_ctx_get_provider(const struct zebra_dplane_ctx
*ctx
)
940 DPLANE_CTX_VALID(ctx
);
941 return ctx
->zd_provider
;
944 /* Providers run before the kernel can control whether a kernel
945 * update should be done.
947 void dplane_ctx_set_skip_kernel(struct zebra_dplane_ctx
*ctx
)
949 DPLANE_CTX_VALID(ctx
);
951 SET_FLAG(ctx
->zd_flags
, DPLANE_CTX_FLAG_NO_KERNEL
);
954 bool dplane_ctx_is_skip_kernel(const struct zebra_dplane_ctx
*ctx
)
956 DPLANE_CTX_VALID(ctx
);
958 return CHECK_FLAG(ctx
->zd_flags
, DPLANE_CTX_FLAG_NO_KERNEL
);
961 void dplane_ctx_set_op(struct zebra_dplane_ctx
*ctx
, enum dplane_op_e op
)
963 DPLANE_CTX_VALID(ctx
);
967 enum dplane_op_e
dplane_ctx_get_op(const struct zebra_dplane_ctx
*ctx
)
969 DPLANE_CTX_VALID(ctx
);
974 const char *dplane_op2str(enum dplane_op_e op
)
976 const char *ret
= "UNKNOWN";
984 case DPLANE_OP_ROUTE_INSTALL
:
985 ret
= "ROUTE_INSTALL";
987 case DPLANE_OP_ROUTE_UPDATE
:
988 ret
= "ROUTE_UPDATE";
990 case DPLANE_OP_ROUTE_DELETE
:
991 ret
= "ROUTE_DELETE";
993 case DPLANE_OP_ROUTE_NOTIFY
:
994 ret
= "ROUTE_NOTIFY";
998 case DPLANE_OP_NH_INSTALL
:
1001 case DPLANE_OP_NH_UPDATE
:
1004 case DPLANE_OP_NH_DELETE
:
1008 case DPLANE_OP_LSP_INSTALL
:
1009 ret
= "LSP_INSTALL";
1011 case DPLANE_OP_LSP_UPDATE
:
1014 case DPLANE_OP_LSP_DELETE
:
1017 case DPLANE_OP_LSP_NOTIFY
:
1021 case DPLANE_OP_PW_INSTALL
:
1024 case DPLANE_OP_PW_UNINSTALL
:
1025 ret
= "PW_UNINSTALL";
1028 case DPLANE_OP_SYS_ROUTE_ADD
:
1029 ret
= "SYS_ROUTE_ADD";
1031 case DPLANE_OP_SYS_ROUTE_DELETE
:
1032 ret
= "SYS_ROUTE_DEL";
1035 case DPLANE_OP_BR_PORT_UPDATE
:
1036 ret
= "BR_PORT_UPDATE";
1039 case DPLANE_OP_ADDR_INSTALL
:
1040 ret
= "ADDR_INSTALL";
1042 case DPLANE_OP_ADDR_UNINSTALL
:
1043 ret
= "ADDR_UNINSTALL";
1046 case DPLANE_OP_MAC_INSTALL
:
1047 ret
= "MAC_INSTALL";
1049 case DPLANE_OP_MAC_DELETE
:
1053 case DPLANE_OP_NEIGH_INSTALL
:
1054 ret
= "NEIGH_INSTALL";
1056 case DPLANE_OP_NEIGH_UPDATE
:
1057 ret
= "NEIGH_UPDATE";
1059 case DPLANE_OP_NEIGH_DELETE
:
1060 ret
= "NEIGH_DELETE";
1062 case DPLANE_OP_VTEP_ADD
:
1065 case DPLANE_OP_VTEP_DELETE
:
1066 ret
= "VTEP_DELETE";
1069 case DPLANE_OP_RULE_ADD
:
1072 case DPLANE_OP_RULE_DELETE
:
1073 ret
= "RULE_DELETE";
1075 case DPLANE_OP_RULE_UPDATE
:
1076 ret
= "RULE_UPDATE";
1079 case DPLANE_OP_NEIGH_DISCOVER
:
1080 ret
= "NEIGH_DISCOVER";
1083 case DPLANE_OP_IPTABLE_ADD
:
1084 ret
= "IPTABLE_ADD";
1086 case DPLANE_OP_IPTABLE_DELETE
:
1087 ret
= "IPTABLE_DELETE";
1089 case DPLANE_OP_IPSET_ADD
:
1092 case DPLANE_OP_IPSET_DELETE
:
1093 ret
= "IPSET_DELETE";
1095 case DPLANE_OP_IPSET_ENTRY_ADD
:
1096 ret
= "IPSET_ENTRY_ADD";
1098 case DPLANE_OP_IPSET_ENTRY_DELETE
:
1099 ret
= "IPSET_ENTRY_DELETE";
1101 case DPLANE_OP_NEIGH_IP_INSTALL
:
1102 ret
= "NEIGH_IP_INSTALL";
1104 case DPLANE_OP_NEIGH_IP_DELETE
:
1105 ret
= "NEIGH_IP_DELETE";
1107 case DPLANE_OP_NEIGH_TABLE_UPDATE
:
1108 ret
= "NEIGH_TABLE_UPDATE";
1111 case DPLANE_OP_GRE_SET
:
1115 case DPLANE_OP_INTF_ADDR_ADD
:
1116 return "INTF_ADDR_ADD";
1118 case DPLANE_OP_INTF_ADDR_DEL
:
1119 return "INTF_ADDR_DEL";
1121 case DPLANE_OP_INTF_NETCONFIG
:
1122 return "INTF_NETCONFIG";
1124 case DPLANE_OP_INTF_INSTALL
:
1125 ret
= "INTF_INSTALL";
1127 case DPLANE_OP_INTF_UPDATE
:
1128 ret
= "INTF_UPDATE";
1130 case DPLANE_OP_INTF_DELETE
:
1131 ret
= "INTF_DELETE";
1134 case DPLANE_OP_TC_QDISC_INSTALL
:
1135 ret
= "TC_QDISC_INSTALL";
1137 case DPLANE_OP_TC_QDISC_UNINSTALL
:
1138 ret
= "TC_QDISC_UNINSTALL";
1140 case DPLANE_OP_TC_CLASS_ADD
:
1141 ret
= "TC_CLASS_ADD";
1143 case DPLANE_OP_TC_CLASS_DELETE
:
1144 ret
= "TC_CLASS_DELETE";
1146 case DPLANE_OP_TC_CLASS_UPDATE
:
1147 ret
= "TC_CLASS_UPDATE";
1149 case DPLANE_OP_TC_FILTER_ADD
:
1150 ret
= "TC_FILTER_ADD";
1152 case DPLANE_OP_TC_FILTER_DELETE
:
1153 ret
= "TC_FILTER_DELETE";
1155 case DPLANE_OP_TC_FILTER_UPDATE
:
1156 ret
= "TC__FILTER_UPDATE";
1163 const char *dplane_res2str(enum zebra_dplane_result res
)
1165 const char *ret
= "<Unknown>";
1168 case ZEBRA_DPLANE_REQUEST_FAILURE
:
1171 case ZEBRA_DPLANE_REQUEST_QUEUED
:
1174 case ZEBRA_DPLANE_REQUEST_SUCCESS
:
1182 void dplane_ctx_set_dest(struct zebra_dplane_ctx
*ctx
,
1183 const struct prefix
*dest
)
1185 DPLANE_CTX_VALID(ctx
);
1187 prefix_copy(&(ctx
->u
.rinfo
.zd_dest
), dest
);
1190 const struct prefix
*dplane_ctx_get_dest(const struct zebra_dplane_ctx
*ctx
)
1192 DPLANE_CTX_VALID(ctx
);
1194 return &(ctx
->u
.rinfo
.zd_dest
);
1197 void dplane_ctx_set_src(struct zebra_dplane_ctx
*ctx
, const struct prefix
*src
)
1199 DPLANE_CTX_VALID(ctx
);
1202 prefix_copy(&(ctx
->u
.rinfo
.zd_src
), src
);
1204 memset(&(ctx
->u
.rinfo
.zd_src
), 0, sizeof(struct prefix
));
1207 /* Source prefix is a little special - return NULL for "no src prefix" */
1208 const struct prefix
*dplane_ctx_get_src(const struct zebra_dplane_ctx
*ctx
)
1210 DPLANE_CTX_VALID(ctx
);
1212 if (ctx
->u
.rinfo
.zd_src
.prefixlen
== 0 &&
1213 IN6_IS_ADDR_UNSPECIFIED(&(ctx
->u
.rinfo
.zd_src
.u
.prefix6
))) {
1216 return &(ctx
->u
.rinfo
.zd_src
);
1220 bool dplane_ctx_is_update(const struct zebra_dplane_ctx
*ctx
)
1222 DPLANE_CTX_VALID(ctx
);
1224 return ctx
->zd_is_update
;
1227 uint32_t dplane_ctx_get_seq(const struct zebra_dplane_ctx
*ctx
)
1229 DPLANE_CTX_VALID(ctx
);
1234 uint32_t dplane_ctx_get_old_seq(const struct zebra_dplane_ctx
*ctx
)
1236 DPLANE_CTX_VALID(ctx
);
1238 return ctx
->zd_old_seq
;
1241 void dplane_ctx_set_vrf(struct zebra_dplane_ctx
*ctx
, vrf_id_t vrf
)
1243 DPLANE_CTX_VALID(ctx
);
1245 ctx
->zd_vrf_id
= vrf
;
1248 vrf_id_t
dplane_ctx_get_vrf(const struct zebra_dplane_ctx
*ctx
)
1250 DPLANE_CTX_VALID(ctx
);
1252 return ctx
->zd_vrf_id
;
1255 /* In some paths we have only a namespace id */
1256 void dplane_ctx_set_ns_id(struct zebra_dplane_ctx
*ctx
, ns_id_t nsid
)
1258 DPLANE_CTX_VALID(ctx
);
1260 ctx
->zd_ns_info
.ns_id
= nsid
;
1263 ns_id_t
dplane_ctx_get_ns_id(const struct zebra_dplane_ctx
*ctx
)
1265 DPLANE_CTX_VALID(ctx
);
1267 return ctx
->zd_ns_info
.ns_id
;
1270 bool dplane_ctx_is_from_notif(const struct zebra_dplane_ctx
*ctx
)
1272 DPLANE_CTX_VALID(ctx
);
1274 return (ctx
->zd_notif_provider
!= 0);
1277 uint32_t dplane_ctx_get_notif_provider(const struct zebra_dplane_ctx
*ctx
)
1279 DPLANE_CTX_VALID(ctx
);
1281 return ctx
->zd_notif_provider
;
1284 void dplane_ctx_set_notif_provider(struct zebra_dplane_ctx
*ctx
,
1287 DPLANE_CTX_VALID(ctx
);
1289 ctx
->zd_notif_provider
= id
;
1292 const char *dplane_ctx_get_ifname(const struct zebra_dplane_ctx
*ctx
)
1294 DPLANE_CTX_VALID(ctx
);
1296 return ctx
->zd_ifname
;
1299 void dplane_ctx_set_ifname(struct zebra_dplane_ctx
*ctx
, const char *ifname
)
1301 DPLANE_CTX_VALID(ctx
);
1306 strlcpy(ctx
->zd_ifname
, ifname
, sizeof(ctx
->zd_ifname
));
1309 ifindex_t
dplane_ctx_get_ifindex(const struct zebra_dplane_ctx
*ctx
)
1311 DPLANE_CTX_VALID(ctx
);
1313 return ctx
->zd_ifindex
;
1316 void dplane_ctx_set_ifindex(struct zebra_dplane_ctx
*ctx
, ifindex_t ifindex
)
1318 DPLANE_CTX_VALID(ctx
);
1320 ctx
->zd_ifindex
= ifindex
;
1323 void dplane_ctx_set_type(struct zebra_dplane_ctx
*ctx
, int type
)
1325 DPLANE_CTX_VALID(ctx
);
1327 ctx
->u
.rinfo
.zd_type
= type
;
1330 int dplane_ctx_get_type(const struct zebra_dplane_ctx
*ctx
)
1332 DPLANE_CTX_VALID(ctx
);
1334 return ctx
->u
.rinfo
.zd_type
;
1337 int dplane_ctx_get_old_type(const struct zebra_dplane_ctx
*ctx
)
1339 DPLANE_CTX_VALID(ctx
);
1341 return ctx
->u
.rinfo
.zd_old_type
;
1344 void dplane_ctx_set_afi(struct zebra_dplane_ctx
*ctx
, afi_t afi
)
1346 DPLANE_CTX_VALID(ctx
);
1348 ctx
->u
.rinfo
.zd_afi
= afi
;
1351 afi_t
dplane_ctx_get_afi(const struct zebra_dplane_ctx
*ctx
)
1353 DPLANE_CTX_VALID(ctx
);
1355 return ctx
->u
.rinfo
.zd_afi
;
1358 void dplane_ctx_set_safi(struct zebra_dplane_ctx
*ctx
, safi_t safi
)
1360 DPLANE_CTX_VALID(ctx
);
1362 ctx
->u
.rinfo
.zd_safi
= safi
;
1365 safi_t
dplane_ctx_get_safi(const struct zebra_dplane_ctx
*ctx
)
1367 DPLANE_CTX_VALID(ctx
);
1369 return ctx
->u
.rinfo
.zd_safi
;
1372 void dplane_ctx_set_table(struct zebra_dplane_ctx
*ctx
, uint32_t table
)
1374 DPLANE_CTX_VALID(ctx
);
1376 ctx
->zd_table_id
= table
;
1379 uint32_t dplane_ctx_get_table(const struct zebra_dplane_ctx
*ctx
)
1381 DPLANE_CTX_VALID(ctx
);
1383 return ctx
->zd_table_id
;
1386 route_tag_t
dplane_ctx_get_tag(const struct zebra_dplane_ctx
*ctx
)
1388 DPLANE_CTX_VALID(ctx
);
1390 return ctx
->u
.rinfo
.zd_tag
;
1393 void dplane_ctx_set_tag(struct zebra_dplane_ctx
*ctx
, route_tag_t tag
)
1395 DPLANE_CTX_VALID(ctx
);
1397 ctx
->u
.rinfo
.zd_tag
= tag
;
1400 route_tag_t
dplane_ctx_get_old_tag(const struct zebra_dplane_ctx
*ctx
)
1402 DPLANE_CTX_VALID(ctx
);
1404 return ctx
->u
.rinfo
.zd_old_tag
;
1407 uint16_t dplane_ctx_get_instance(const struct zebra_dplane_ctx
*ctx
)
1409 DPLANE_CTX_VALID(ctx
);
1411 return ctx
->u
.rinfo
.zd_instance
;
1414 void dplane_ctx_set_instance(struct zebra_dplane_ctx
*ctx
, uint16_t instance
)
1416 DPLANE_CTX_VALID(ctx
);
1418 ctx
->u
.rinfo
.zd_instance
= instance
;
1421 uint16_t dplane_ctx_get_old_instance(const struct zebra_dplane_ctx
*ctx
)
1423 DPLANE_CTX_VALID(ctx
);
1425 return ctx
->u
.rinfo
.zd_old_instance
;
1428 uint32_t dplane_ctx_get_flags(const struct zebra_dplane_ctx
*ctx
)
1430 DPLANE_CTX_VALID(ctx
);
1432 return ctx
->u
.rinfo
.zd_flags
;
1435 void dplane_ctx_set_flags(struct zebra_dplane_ctx
*ctx
, uint32_t flags
)
1437 DPLANE_CTX_VALID(ctx
);
1439 ctx
->u
.rinfo
.zd_flags
= flags
;
1442 uint32_t dplane_ctx_get_metric(const struct zebra_dplane_ctx
*ctx
)
1444 DPLANE_CTX_VALID(ctx
);
1446 return ctx
->u
.rinfo
.zd_metric
;
1449 uint32_t dplane_ctx_get_old_metric(const struct zebra_dplane_ctx
*ctx
)
1451 DPLANE_CTX_VALID(ctx
);
1453 return ctx
->u
.rinfo
.zd_old_metric
;
1456 uint32_t dplane_ctx_get_mtu(const struct zebra_dplane_ctx
*ctx
)
1458 DPLANE_CTX_VALID(ctx
);
1460 return ctx
->u
.rinfo
.zd_mtu
;
1463 uint32_t dplane_ctx_get_nh_mtu(const struct zebra_dplane_ctx
*ctx
)
1465 DPLANE_CTX_VALID(ctx
);
1467 return ctx
->u
.rinfo
.zd_nexthop_mtu
;
1470 uint8_t dplane_ctx_get_distance(const struct zebra_dplane_ctx
*ctx
)
1472 DPLANE_CTX_VALID(ctx
);
1474 return ctx
->u
.rinfo
.zd_distance
;
1477 void dplane_ctx_set_distance(struct zebra_dplane_ctx
*ctx
, uint8_t distance
)
1479 DPLANE_CTX_VALID(ctx
);
1481 ctx
->u
.rinfo
.zd_distance
= distance
;
1484 uint8_t dplane_ctx_get_old_distance(const struct zebra_dplane_ctx
*ctx
)
1486 DPLANE_CTX_VALID(ctx
);
1488 return ctx
->u
.rinfo
.zd_old_distance
;
1491 int dplane_ctx_tc_qdisc_get_kind(const struct zebra_dplane_ctx
*ctx
)
1493 DPLANE_CTX_VALID(ctx
);
1495 return ctx
->u
.tc_qdisc
.kind
;
1498 const char *dplane_ctx_tc_qdisc_get_kind_str(const struct zebra_dplane_ctx
*ctx
)
1500 DPLANE_CTX_VALID(ctx
);
1502 return ctx
->u
.tc_qdisc
.kind_str
;
1505 uint32_t dplane_ctx_tc_class_get_handle(const struct zebra_dplane_ctx
*ctx
)
1507 DPLANE_CTX_VALID(ctx
);
1509 return ctx
->u
.tc_class
.handle
;
1512 int dplane_ctx_tc_class_get_kind(const struct zebra_dplane_ctx
*ctx
)
1514 DPLANE_CTX_VALID(ctx
);
1516 return ctx
->u
.tc_class
.kind
;
1519 const char *dplane_ctx_tc_class_get_kind_str(const struct zebra_dplane_ctx
*ctx
)
1521 DPLANE_CTX_VALID(ctx
);
1523 return ctx
->u
.tc_class
.kind_str
;
1526 uint64_t dplane_ctx_tc_class_get_rate(const struct zebra_dplane_ctx
*ctx
)
1528 DPLANE_CTX_VALID(ctx
);
1530 return ctx
->u
.tc_class
.rate
;
1533 uint64_t dplane_ctx_tc_class_get_ceil(const struct zebra_dplane_ctx
*ctx
)
1535 DPLANE_CTX_VALID(ctx
);
1537 return ctx
->u
.tc_class
.ceil
;
1540 int dplane_ctx_tc_filter_get_kind(const struct zebra_dplane_ctx
*ctx
)
1542 DPLANE_CTX_VALID(ctx
);
1544 return ctx
->u
.tc_filter
.kind
;
1548 dplane_ctx_tc_filter_get_kind_str(const struct zebra_dplane_ctx
*ctx
)
1550 DPLANE_CTX_VALID(ctx
);
1552 return ctx
->u
.tc_filter
.kind_str
;
1555 uint32_t dplane_ctx_tc_filter_get_priority(const struct zebra_dplane_ctx
*ctx
)
1557 DPLANE_CTX_VALID(ctx
);
1559 return ctx
->u
.tc_filter
.priority
;
1562 uint32_t dplane_ctx_tc_filter_get_handle(const struct zebra_dplane_ctx
*ctx
)
1564 DPLANE_CTX_VALID(ctx
);
1566 return ctx
->u
.tc_filter
.handle
;
1569 uint16_t dplane_ctx_tc_filter_get_eth_proto(const struct zebra_dplane_ctx
*ctx
)
1571 DPLANE_CTX_VALID(ctx
);
1573 return ctx
->u
.tc_filter
.eth_proto
;
1576 uint32_t dplane_ctx_tc_filter_get_filter_bm(const struct zebra_dplane_ctx
*ctx
)
1578 DPLANE_CTX_VALID(ctx
);
1580 return ctx
->u
.tc_filter
.filter_bm
;
1583 const struct prefix
*
1584 dplane_ctx_tc_filter_get_src_ip(const struct zebra_dplane_ctx
*ctx
)
1586 DPLANE_CTX_VALID(ctx
);
1588 return &ctx
->u
.tc_filter
.src_ip
;
1592 dplane_ctx_tc_filter_get_src_port_min(const struct zebra_dplane_ctx
*ctx
)
1594 DPLANE_CTX_VALID(ctx
);
1596 return ctx
->u
.tc_filter
.src_port_min
;
1601 dplane_ctx_tc_filter_get_src_port_max(const struct zebra_dplane_ctx
*ctx
)
1603 DPLANE_CTX_VALID(ctx
);
1605 return ctx
->u
.tc_filter
.src_port_max
;
1608 const struct prefix
*
1609 dplane_ctx_tc_filter_get_dst_ip(const struct zebra_dplane_ctx
*ctx
)
1611 DPLANE_CTX_VALID(ctx
);
1613 return &ctx
->u
.tc_filter
.dst_ip
;
1617 dplane_ctx_tc_filter_get_dst_port_min(const struct zebra_dplane_ctx
*ctx
)
1619 DPLANE_CTX_VALID(ctx
);
1621 return ctx
->u
.tc_filter
.dst_port_min
;
1626 dplane_ctx_tc_filter_get_dst_port_max(const struct zebra_dplane_ctx
*ctx
)
1628 DPLANE_CTX_VALID(ctx
);
1630 return ctx
->u
.tc_filter
.dst_port_max
;
1633 uint8_t dplane_ctx_tc_filter_get_ip_proto(const struct zebra_dplane_ctx
*ctx
)
1635 DPLANE_CTX_VALID(ctx
);
1637 return ctx
->u
.tc_filter
.ip_proto
;
1640 uint8_t dplane_ctx_tc_filter_get_dsfield(const struct zebra_dplane_ctx
*ctx
)
1642 DPLANE_CTX_VALID(ctx
);
1644 return ctx
->u
.tc_filter
.dsfield
;
1648 dplane_ctx_tc_filter_get_dsfield_mask(const struct zebra_dplane_ctx
*ctx
)
1650 DPLANE_CTX_VALID(ctx
);
1652 return ctx
->u
.tc_filter
.dsfield_mask
;
1655 uint32_t dplane_ctx_tc_filter_get_classid(const struct zebra_dplane_ctx
*ctx
)
1657 DPLANE_CTX_VALID(ctx
);
1659 return ctx
->u
.tc_filter
.classid
;
1663 * Set the nexthops associated with a context: note that processing code
1664 * may well expect that nexthops are in canonical (sorted) order, so we
1665 * will enforce that here.
1667 void dplane_ctx_set_nexthops(struct zebra_dplane_ctx
*ctx
, struct nexthop
*nh
)
1669 DPLANE_CTX_VALID(ctx
);
1671 if (ctx
->u
.rinfo
.zd_ng
.nexthop
) {
1672 nexthops_free(ctx
->u
.rinfo
.zd_ng
.nexthop
);
1673 ctx
->u
.rinfo
.zd_ng
.nexthop
= NULL
;
1675 nexthop_group_copy_nh_sorted(&(ctx
->u
.rinfo
.zd_ng
), nh
);
1679 * Set the list of backup nexthops; their ordering is preserved (they're not
1682 void dplane_ctx_set_backup_nhg(struct zebra_dplane_ctx
*ctx
,
1683 const struct nexthop_group
*nhg
)
1685 struct nexthop
*nh
, *last_nh
, *nexthop
;
1687 DPLANE_CTX_VALID(ctx
);
1689 if (ctx
->u
.rinfo
.backup_ng
.nexthop
) {
1690 nexthops_free(ctx
->u
.rinfo
.backup_ng
.nexthop
);
1691 ctx
->u
.rinfo
.backup_ng
.nexthop
= NULL
;
1696 /* Be careful to preserve the order of the backup list */
1697 for (nh
= nhg
->nexthop
; nh
; nh
= nh
->next
) {
1698 nexthop
= nexthop_dup(nh
, NULL
);
1701 NEXTHOP_APPEND(last_nh
, nexthop
);
1703 ctx
->u
.rinfo
.backup_ng
.nexthop
= nexthop
;
1709 uint32_t dplane_ctx_get_nhg_id(const struct zebra_dplane_ctx
*ctx
)
1711 DPLANE_CTX_VALID(ctx
);
1712 return ctx
->u
.rinfo
.zd_nhg_id
;
1715 const struct nexthop_group
*dplane_ctx_get_ng(
1716 const struct zebra_dplane_ctx
*ctx
)
1718 DPLANE_CTX_VALID(ctx
);
1720 return &(ctx
->u
.rinfo
.zd_ng
);
1723 const struct nexthop_group
*
1724 dplane_ctx_get_backup_ng(const struct zebra_dplane_ctx
*ctx
)
1726 DPLANE_CTX_VALID(ctx
);
1728 return &(ctx
->u
.rinfo
.backup_ng
);
1731 const struct nexthop_group
*
1732 dplane_ctx_get_old_ng(const struct zebra_dplane_ctx
*ctx
)
1734 DPLANE_CTX_VALID(ctx
);
1736 return &(ctx
->u
.rinfo
.zd_old_ng
);
1739 const struct nexthop_group
*
1740 dplane_ctx_get_old_backup_ng(const struct zebra_dplane_ctx
*ctx
)
1742 DPLANE_CTX_VALID(ctx
);
1744 return &(ctx
->u
.rinfo
.old_backup_ng
);
1747 const struct zebra_dplane_info
*dplane_ctx_get_ns(
1748 const struct zebra_dplane_ctx
*ctx
)
1750 DPLANE_CTX_VALID(ctx
);
1752 return &(ctx
->zd_ns_info
);
1755 int dplane_ctx_get_ns_sock(const struct zebra_dplane_ctx
*ctx
)
1757 DPLANE_CTX_VALID(ctx
);
1760 return ctx
->zd_ns_info
.sock
;
1766 /* Accessors for nexthop information */
1767 uint32_t dplane_ctx_get_nhe_id(const struct zebra_dplane_ctx
*ctx
)
1769 DPLANE_CTX_VALID(ctx
);
1770 return ctx
->u
.rinfo
.nhe
.id
;
1773 uint32_t dplane_ctx_get_old_nhe_id(const struct zebra_dplane_ctx
*ctx
)
1775 DPLANE_CTX_VALID(ctx
);
1776 return ctx
->u
.rinfo
.nhe
.old_id
;
1779 afi_t
dplane_ctx_get_nhe_afi(const struct zebra_dplane_ctx
*ctx
)
1781 DPLANE_CTX_VALID(ctx
);
1782 return ctx
->u
.rinfo
.nhe
.afi
;
1785 vrf_id_t
dplane_ctx_get_nhe_vrf_id(const struct zebra_dplane_ctx
*ctx
)
1787 DPLANE_CTX_VALID(ctx
);
1788 return ctx
->u
.rinfo
.nhe
.vrf_id
;
1791 int dplane_ctx_get_nhe_type(const struct zebra_dplane_ctx
*ctx
)
1793 DPLANE_CTX_VALID(ctx
);
1794 return ctx
->u
.rinfo
.nhe
.type
;
1797 const struct nexthop_group
*
1798 dplane_ctx_get_nhe_ng(const struct zebra_dplane_ctx
*ctx
)
1800 DPLANE_CTX_VALID(ctx
);
1801 return &(ctx
->u
.rinfo
.nhe
.ng
);
1804 const struct nh_grp
*
1805 dplane_ctx_get_nhe_nh_grp(const struct zebra_dplane_ctx
*ctx
)
1807 DPLANE_CTX_VALID(ctx
);
1808 return ctx
->u
.rinfo
.nhe
.nh_grp
;
1811 uint8_t dplane_ctx_get_nhe_nh_grp_count(const struct zebra_dplane_ctx
*ctx
)
1813 DPLANE_CTX_VALID(ctx
);
1814 return ctx
->u
.rinfo
.nhe
.nh_grp_count
;
1817 /* Accessors for LSP information */
1819 mpls_label_t
dplane_ctx_get_in_label(const struct zebra_dplane_ctx
*ctx
)
1821 DPLANE_CTX_VALID(ctx
);
1823 return ctx
->u
.lsp
.ile
.in_label
;
1826 void dplane_ctx_set_in_label(struct zebra_dplane_ctx
*ctx
, mpls_label_t label
)
1828 DPLANE_CTX_VALID(ctx
);
1830 ctx
->u
.lsp
.ile
.in_label
= label
;
1833 uint8_t dplane_ctx_get_addr_family(const struct zebra_dplane_ctx
*ctx
)
1835 DPLANE_CTX_VALID(ctx
);
1837 return ctx
->u
.lsp
.addr_family
;
1840 void dplane_ctx_set_addr_family(struct zebra_dplane_ctx
*ctx
,
1843 DPLANE_CTX_VALID(ctx
);
1845 ctx
->u
.lsp
.addr_family
= family
;
1848 uint32_t dplane_ctx_get_lsp_flags(const struct zebra_dplane_ctx
*ctx
)
1850 DPLANE_CTX_VALID(ctx
);
1852 return ctx
->u
.lsp
.flags
;
1855 void dplane_ctx_set_lsp_flags(struct zebra_dplane_ctx
*ctx
,
1858 DPLANE_CTX_VALID(ctx
);
1860 ctx
->u
.lsp
.flags
= flags
;
1863 const struct nhlfe_list_head
*dplane_ctx_get_nhlfe_list(
1864 const struct zebra_dplane_ctx
*ctx
)
1866 DPLANE_CTX_VALID(ctx
);
1867 return &(ctx
->u
.lsp
.nhlfe_list
);
1870 const struct nhlfe_list_head
*dplane_ctx_get_backup_nhlfe_list(
1871 const struct zebra_dplane_ctx
*ctx
)
1873 DPLANE_CTX_VALID(ctx
);
1874 return &(ctx
->u
.lsp
.backup_nhlfe_list
);
1877 struct zebra_nhlfe
*dplane_ctx_add_nhlfe(struct zebra_dplane_ctx
*ctx
,
1878 enum lsp_types_t lsp_type
,
1879 enum nexthop_types_t nh_type
,
1880 const union g_addr
*gate
,
1881 ifindex_t ifindex
, uint8_t num_labels
,
1882 mpls_label_t
*out_labels
)
1884 struct zebra_nhlfe
*nhlfe
;
1886 DPLANE_CTX_VALID(ctx
);
1888 nhlfe
= zebra_mpls_lsp_add_nhlfe(&(ctx
->u
.lsp
),
1889 lsp_type
, nh_type
, gate
,
1890 ifindex
, num_labels
, out_labels
);
1895 struct zebra_nhlfe
*dplane_ctx_add_backup_nhlfe(
1896 struct zebra_dplane_ctx
*ctx
, enum lsp_types_t lsp_type
,
1897 enum nexthop_types_t nh_type
, const union g_addr
*gate
,
1898 ifindex_t ifindex
, uint8_t num_labels
, mpls_label_t
*out_labels
)
1900 struct zebra_nhlfe
*nhlfe
;
1902 DPLANE_CTX_VALID(ctx
);
1904 nhlfe
= zebra_mpls_lsp_add_backup_nhlfe(&(ctx
->u
.lsp
),
1905 lsp_type
, nh_type
, gate
,
1906 ifindex
, num_labels
,
1912 const struct zebra_nhlfe
*
1913 dplane_ctx_get_best_nhlfe(const struct zebra_dplane_ctx
*ctx
)
1915 DPLANE_CTX_VALID(ctx
);
1917 return ctx
->u
.lsp
.best_nhlfe
;
1920 const struct zebra_nhlfe
*
1921 dplane_ctx_set_best_nhlfe(struct zebra_dplane_ctx
*ctx
,
1922 struct zebra_nhlfe
*nhlfe
)
1924 DPLANE_CTX_VALID(ctx
);
1926 ctx
->u
.lsp
.best_nhlfe
= nhlfe
;
1927 return ctx
->u
.lsp
.best_nhlfe
;
1930 uint32_t dplane_ctx_get_lsp_num_ecmp(const struct zebra_dplane_ctx
*ctx
)
1932 DPLANE_CTX_VALID(ctx
);
1934 return ctx
->u
.lsp
.num_ecmp
;
1937 mpls_label_t
dplane_ctx_get_pw_local_label(const struct zebra_dplane_ctx
*ctx
)
1939 DPLANE_CTX_VALID(ctx
);
1941 return ctx
->u
.pw
.local_label
;
1944 mpls_label_t
dplane_ctx_get_pw_remote_label(const struct zebra_dplane_ctx
*ctx
)
1946 DPLANE_CTX_VALID(ctx
);
1948 return ctx
->u
.pw
.remote_label
;
1951 int dplane_ctx_get_pw_type(const struct zebra_dplane_ctx
*ctx
)
1953 DPLANE_CTX_VALID(ctx
);
1955 return ctx
->u
.pw
.type
;
1958 int dplane_ctx_get_pw_af(const struct zebra_dplane_ctx
*ctx
)
1960 DPLANE_CTX_VALID(ctx
);
1962 return ctx
->u
.pw
.af
;
1965 uint32_t dplane_ctx_get_pw_flags(const struct zebra_dplane_ctx
*ctx
)
1967 DPLANE_CTX_VALID(ctx
);
1969 return ctx
->u
.pw
.flags
;
1972 int dplane_ctx_get_pw_status(const struct zebra_dplane_ctx
*ctx
)
1974 DPLANE_CTX_VALID(ctx
);
1976 return ctx
->u
.pw
.status
;
1979 void dplane_ctx_set_pw_status(struct zebra_dplane_ctx
*ctx
, int status
)
1981 DPLANE_CTX_VALID(ctx
);
1983 ctx
->u
.pw
.status
= status
;
1986 const union g_addr
*dplane_ctx_get_pw_dest(
1987 const struct zebra_dplane_ctx
*ctx
)
1989 DPLANE_CTX_VALID(ctx
);
1991 return &(ctx
->u
.pw
.dest
);
1994 const union pw_protocol_fields
*dplane_ctx_get_pw_proto(
1995 const struct zebra_dplane_ctx
*ctx
)
1997 DPLANE_CTX_VALID(ctx
);
1999 return &(ctx
->u
.pw
.fields
);
2002 const struct nexthop_group
*
2003 dplane_ctx_get_pw_nhg(const struct zebra_dplane_ctx
*ctx
)
2005 DPLANE_CTX_VALID(ctx
);
2007 return &(ctx
->u
.pw
.fib_nhg
);
2010 const struct nexthop_group
*
2011 dplane_ctx_get_pw_primary_nhg(const struct zebra_dplane_ctx
*ctx
)
2013 DPLANE_CTX_VALID(ctx
);
2015 return &(ctx
->u
.pw
.primary_nhg
);
2018 const struct nexthop_group
*
2019 dplane_ctx_get_pw_backup_nhg(const struct zebra_dplane_ctx
*ctx
)
2021 DPLANE_CTX_VALID(ctx
);
2023 return &(ctx
->u
.pw
.backup_nhg
);
2026 /* Accessors for interface information */
2027 uint32_t dplane_ctx_get_intf_metric(const struct zebra_dplane_ctx
*ctx
)
2029 DPLANE_CTX_VALID(ctx
);
2031 return ctx
->u
.intf
.metric
;
2034 void dplane_ctx_set_intf_metric(struct zebra_dplane_ctx
*ctx
, uint32_t metric
)
2036 DPLANE_CTX_VALID(ctx
);
2038 ctx
->u
.intf
.metric
= metric
;
2041 uint32_t dplane_ctx_get_intf_pd_reason_val(const struct zebra_dplane_ctx
*ctx
)
2043 DPLANE_CTX_VALID(ctx
);
2045 return ctx
->u
.intf
.pd_reason_val
;
2048 void dplane_ctx_set_intf_pd_reason_val(struct zebra_dplane_ctx
*ctx
, bool val
)
2050 DPLANE_CTX_VALID(ctx
);
2052 ctx
->u
.intf
.pd_reason_val
= val
;
2055 bool dplane_ctx_intf_is_protodown(const struct zebra_dplane_ctx
*ctx
)
2057 DPLANE_CTX_VALID(ctx
);
2059 return ctx
->u
.intf
.protodown
;
2062 /* Is interface addr p2p? */
2063 bool dplane_ctx_intf_is_connected(const struct zebra_dplane_ctx
*ctx
)
2065 DPLANE_CTX_VALID(ctx
);
2067 return (ctx
->u
.intf
.flags
& DPLANE_INTF_CONNECTED
);
2070 bool dplane_ctx_intf_is_secondary(const struct zebra_dplane_ctx
*ctx
)
2072 DPLANE_CTX_VALID(ctx
);
2074 return (ctx
->u
.intf
.flags
& DPLANE_INTF_SECONDARY
);
2077 bool dplane_ctx_intf_is_broadcast(const struct zebra_dplane_ctx
*ctx
)
2079 DPLANE_CTX_VALID(ctx
);
2081 return (ctx
->u
.intf
.flags
& DPLANE_INTF_BROADCAST
);
2084 void dplane_ctx_intf_set_connected(struct zebra_dplane_ctx
*ctx
)
2086 DPLANE_CTX_VALID(ctx
);
2088 ctx
->u
.intf
.flags
|= DPLANE_INTF_CONNECTED
;
2091 void dplane_ctx_intf_set_secondary(struct zebra_dplane_ctx
*ctx
)
2093 DPLANE_CTX_VALID(ctx
);
2095 ctx
->u
.intf
.flags
|= DPLANE_INTF_SECONDARY
;
2098 void dplane_ctx_intf_set_broadcast(struct zebra_dplane_ctx
*ctx
)
2100 DPLANE_CTX_VALID(ctx
);
2102 ctx
->u
.intf
.flags
|= DPLANE_INTF_BROADCAST
;
2105 const struct prefix
*dplane_ctx_get_intf_addr(
2106 const struct zebra_dplane_ctx
*ctx
)
2108 DPLANE_CTX_VALID(ctx
);
2110 return &(ctx
->u
.intf
.prefix
);
2113 void dplane_ctx_set_intf_addr(struct zebra_dplane_ctx
*ctx
,
2114 const struct prefix
*p
)
2116 DPLANE_CTX_VALID(ctx
);
2118 prefix_copy(&(ctx
->u
.intf
.prefix
), p
);
2121 bool dplane_ctx_intf_has_dest(const struct zebra_dplane_ctx
*ctx
)
2123 DPLANE_CTX_VALID(ctx
);
2125 return (ctx
->u
.intf
.flags
& DPLANE_INTF_HAS_DEST
);
2128 const struct prefix
*dplane_ctx_get_intf_dest(
2129 const struct zebra_dplane_ctx
*ctx
)
2131 DPLANE_CTX_VALID(ctx
);
2133 return &(ctx
->u
.intf
.dest_prefix
);
2136 void dplane_ctx_set_intf_dest(struct zebra_dplane_ctx
*ctx
,
2137 const struct prefix
*p
)
2139 DPLANE_CTX_VALID(ctx
);
2141 prefix_copy(&(ctx
->u
.intf
.dest_prefix
), p
);
2144 bool dplane_ctx_intf_has_label(const struct zebra_dplane_ctx
*ctx
)
2146 DPLANE_CTX_VALID(ctx
);
2148 return (ctx
->u
.intf
.flags
& DPLANE_INTF_HAS_LABEL
);
2151 const char *dplane_ctx_get_intf_label(const struct zebra_dplane_ctx
*ctx
)
2153 DPLANE_CTX_VALID(ctx
);
2155 return ctx
->u
.intf
.label
;
2158 void dplane_ctx_set_intf_label(struct zebra_dplane_ctx
*ctx
, const char *label
)
2162 DPLANE_CTX_VALID(ctx
);
2164 if (ctx
->u
.intf
.label
&& ctx
->u
.intf
.label
!= ctx
->u
.intf
.label_buf
)
2165 XFREE(MTYPE_DP_CTX
, ctx
->u
.intf
.label
);
2167 ctx
->u
.intf
.label
= NULL
;
2170 ctx
->u
.intf
.flags
|= DPLANE_INTF_HAS_LABEL
;
2172 /* Use embedded buffer if it's adequate; else allocate. */
2173 len
= strlen(label
);
2175 if (len
< sizeof(ctx
->u
.intf
.label_buf
)) {
2176 strlcpy(ctx
->u
.intf
.label_buf
, label
,
2177 sizeof(ctx
->u
.intf
.label_buf
));
2178 ctx
->u
.intf
.label
= ctx
->u
.intf
.label_buf
;
2180 ctx
->u
.intf
.label
= XSTRDUP(MTYPE_DP_CTX
, label
);
2183 ctx
->u
.intf
.flags
&= ~DPLANE_INTF_HAS_LABEL
;
2187 /* Accessors for MAC information */
2188 vlanid_t
dplane_ctx_mac_get_vlan(const struct zebra_dplane_ctx
*ctx
)
2190 DPLANE_CTX_VALID(ctx
);
2191 return ctx
->u
.macinfo
.vid
;
2194 bool dplane_ctx_mac_is_sticky(const struct zebra_dplane_ctx
*ctx
)
2196 DPLANE_CTX_VALID(ctx
);
2197 return ctx
->u
.macinfo
.is_sticky
;
2200 uint32_t dplane_ctx_mac_get_nhg_id(const struct zebra_dplane_ctx
*ctx
)
2202 DPLANE_CTX_VALID(ctx
);
2203 return ctx
->u
.macinfo
.nhg_id
;
2206 uint32_t dplane_ctx_mac_get_update_flags(const struct zebra_dplane_ctx
*ctx
)
2208 DPLANE_CTX_VALID(ctx
);
2209 return ctx
->u
.macinfo
.update_flags
;
2212 const struct ethaddr
*dplane_ctx_mac_get_addr(
2213 const struct zebra_dplane_ctx
*ctx
)
2215 DPLANE_CTX_VALID(ctx
);
2216 return &(ctx
->u
.macinfo
.mac
);
2219 const struct in_addr
*dplane_ctx_mac_get_vtep_ip(
2220 const struct zebra_dplane_ctx
*ctx
)
2222 DPLANE_CTX_VALID(ctx
);
2223 return &(ctx
->u
.macinfo
.vtep_ip
);
2226 ifindex_t
dplane_ctx_mac_get_br_ifindex(const struct zebra_dplane_ctx
*ctx
)
2228 DPLANE_CTX_VALID(ctx
);
2229 return ctx
->u
.macinfo
.br_ifindex
;
2232 /* Accessors for neighbor information */
2233 const struct ipaddr
*dplane_ctx_neigh_get_ipaddr(
2234 const struct zebra_dplane_ctx
*ctx
)
2236 DPLANE_CTX_VALID(ctx
);
2237 return &(ctx
->u
.neigh
.ip_addr
);
2240 const struct ipaddr
*
2241 dplane_ctx_neigh_get_link_ip(const struct zebra_dplane_ctx
*ctx
)
2243 DPLANE_CTX_VALID(ctx
);
2244 return &(ctx
->u
.neigh
.link
.ip_addr
);
2247 const struct ethaddr
*dplane_ctx_neigh_get_mac(
2248 const struct zebra_dplane_ctx
*ctx
)
2250 DPLANE_CTX_VALID(ctx
);
2251 return &(ctx
->u
.neigh
.link
.mac
);
2254 uint32_t dplane_ctx_neigh_get_flags(const struct zebra_dplane_ctx
*ctx
)
2256 DPLANE_CTX_VALID(ctx
);
2257 return ctx
->u
.neigh
.flags
;
2260 uint16_t dplane_ctx_neigh_get_state(const struct zebra_dplane_ctx
*ctx
)
2262 DPLANE_CTX_VALID(ctx
);
2263 return ctx
->u
.neigh
.state
;
2266 uint32_t dplane_ctx_neigh_get_update_flags(const struct zebra_dplane_ctx
*ctx
)
2268 DPLANE_CTX_VALID(ctx
);
2269 return ctx
->u
.neigh
.update_flags
;
2272 /* Accessor for GRE set */
2274 dplane_ctx_gre_get_link_ifindex(const struct zebra_dplane_ctx
*ctx
)
2276 DPLANE_CTX_VALID(ctx
);
2278 return ctx
->u
.gre
.link_ifindex
;
2282 dplane_ctx_gre_get_mtu(const struct zebra_dplane_ctx
*ctx
)
2284 DPLANE_CTX_VALID(ctx
);
2286 return ctx
->u
.gre
.mtu
;
2289 const struct zebra_l2info_gre
*
2290 dplane_ctx_gre_get_info(const struct zebra_dplane_ctx
*ctx
)
2292 DPLANE_CTX_VALID(ctx
);
2294 return &ctx
->u
.gre
.info
;
2297 /* Accessors for PBR rule information */
2298 int dplane_ctx_rule_get_sock(const struct zebra_dplane_ctx
*ctx
)
2300 DPLANE_CTX_VALID(ctx
);
2302 return ctx
->u
.rule
.sock
;
2305 const char *dplane_ctx_rule_get_ifname(const struct zebra_dplane_ctx
*ctx
)
2307 DPLANE_CTX_VALID(ctx
);
2309 return ctx
->u
.rule
.new.ifname
;
2312 int dplane_ctx_rule_get_unique(const struct zebra_dplane_ctx
*ctx
)
2314 DPLANE_CTX_VALID(ctx
);
2316 return ctx
->u
.rule
.unique
;
2319 int dplane_ctx_rule_get_seq(const struct zebra_dplane_ctx
*ctx
)
2321 DPLANE_CTX_VALID(ctx
);
2323 return ctx
->u
.rule
.seq
;
2326 uint32_t dplane_ctx_rule_get_priority(const struct zebra_dplane_ctx
*ctx
)
2328 DPLANE_CTX_VALID(ctx
);
2330 return ctx
->u
.rule
.new.priority
;
2333 uint32_t dplane_ctx_rule_get_old_priority(const struct zebra_dplane_ctx
*ctx
)
2335 DPLANE_CTX_VALID(ctx
);
2337 return ctx
->u
.rule
.old
.priority
;
2340 uint32_t dplane_ctx_rule_get_table(const struct zebra_dplane_ctx
*ctx
)
2342 DPLANE_CTX_VALID(ctx
);
2344 return ctx
->u
.rule
.new.table
;
2347 uint32_t dplane_ctx_rule_get_old_table(const struct zebra_dplane_ctx
*ctx
)
2349 DPLANE_CTX_VALID(ctx
);
2351 return ctx
->u
.rule
.old
.table
;
2354 uint32_t dplane_ctx_rule_get_filter_bm(const struct zebra_dplane_ctx
*ctx
)
2356 DPLANE_CTX_VALID(ctx
);
2358 return ctx
->u
.rule
.new.filter_bm
;
2361 uint32_t dplane_ctx_rule_get_old_filter_bm(const struct zebra_dplane_ctx
*ctx
)
2363 DPLANE_CTX_VALID(ctx
);
2365 return ctx
->u
.rule
.old
.filter_bm
;
2368 uint32_t dplane_ctx_rule_get_fwmark(const struct zebra_dplane_ctx
*ctx
)
2370 DPLANE_CTX_VALID(ctx
);
2372 return ctx
->u
.rule
.new.fwmark
;
2375 uint32_t dplane_ctx_rule_get_old_fwmark(const struct zebra_dplane_ctx
*ctx
)
2377 DPLANE_CTX_VALID(ctx
);
2379 return ctx
->u
.rule
.old
.fwmark
;
2382 uint8_t dplane_ctx_rule_get_ipproto(const struct zebra_dplane_ctx
*ctx
)
2384 DPLANE_CTX_VALID(ctx
);
2386 return ctx
->u
.rule
.new.ip_proto
;
2389 uint8_t dplane_ctx_rule_get_old_ipproto(const struct zebra_dplane_ctx
*ctx
)
2391 DPLANE_CTX_VALID(ctx
);
2393 return ctx
->u
.rule
.old
.ip_proto
;
2396 uint16_t dplane_ctx_rule_get_src_port(const struct zebra_dplane_ctx
*ctx
)
2398 DPLANE_CTX_VALID(ctx
);
2400 return ctx
->u
.rule
.new.src_port
;
2403 uint16_t dplane_ctx_rule_get_old_src_port(const struct zebra_dplane_ctx
*ctx
)
2405 DPLANE_CTX_VALID(ctx
);
2407 return ctx
->u
.rule
.old
.src_port
;
2410 uint16_t dplane_ctx_rule_get_dst_port(const struct zebra_dplane_ctx
*ctx
)
2412 DPLANE_CTX_VALID(ctx
);
2414 return ctx
->u
.rule
.new.dst_port
;
2417 uint16_t dplane_ctx_rule_get_old_dst_port(const struct zebra_dplane_ctx
*ctx
)
2419 DPLANE_CTX_VALID(ctx
);
2421 return ctx
->u
.rule
.old
.dst_port
;
2424 uint8_t dplane_ctx_rule_get_dsfield(const struct zebra_dplane_ctx
*ctx
)
2426 DPLANE_CTX_VALID(ctx
);
2428 return ctx
->u
.rule
.new.dsfield
;
2431 uint8_t dplane_ctx_rule_get_old_dsfield(const struct zebra_dplane_ctx
*ctx
)
2433 DPLANE_CTX_VALID(ctx
);
2435 return ctx
->u
.rule
.old
.dsfield
;
2438 const struct prefix
*
2439 dplane_ctx_rule_get_src_ip(const struct zebra_dplane_ctx
*ctx
)
2441 DPLANE_CTX_VALID(ctx
);
2443 return &(ctx
->u
.rule
.new.src_ip
);
2446 const struct prefix
*
2447 dplane_ctx_rule_get_old_src_ip(const struct zebra_dplane_ctx
*ctx
)
2449 DPLANE_CTX_VALID(ctx
);
2451 return &(ctx
->u
.rule
.old
.src_ip
);
2454 const struct prefix
*
2455 dplane_ctx_rule_get_dst_ip(const struct zebra_dplane_ctx
*ctx
)
2457 DPLANE_CTX_VALID(ctx
);
2459 return &(ctx
->u
.rule
.new.dst_ip
);
2462 const struct prefix
*
2463 dplane_ctx_rule_get_old_dst_ip(const struct zebra_dplane_ctx
*ctx
)
2465 DPLANE_CTX_VALID(ctx
);
2467 return &(ctx
->u
.rule
.old
.dst_ip
);
2470 uint32_t dplane_ctx_get_br_port_flags(const struct zebra_dplane_ctx
*ctx
)
2472 DPLANE_CTX_VALID(ctx
);
2474 return ctx
->u
.br_port
.flags
;
2478 dplane_ctx_get_br_port_sph_filter_cnt(const struct zebra_dplane_ctx
*ctx
)
2480 DPLANE_CTX_VALID(ctx
);
2482 return ctx
->u
.br_port
.sph_filter_cnt
;
2485 const struct in_addr
*
2486 dplane_ctx_get_br_port_sph_filters(const struct zebra_dplane_ctx
*ctx
)
2488 DPLANE_CTX_VALID(ctx
);
2490 return ctx
->u
.br_port
.sph_filters
;
2494 dplane_ctx_get_br_port_backup_nhg_id(const struct zebra_dplane_ctx
*ctx
)
2496 DPLANE_CTX_VALID(ctx
);
2498 return ctx
->u
.br_port
.backup_nhg_id
;
2501 /* Accessors for PBR iptable information */
2502 void dplane_ctx_get_pbr_iptable(const struct zebra_dplane_ctx
*ctx
,
2503 struct zebra_pbr_iptable
*table
)
2505 DPLANE_CTX_VALID(ctx
);
2507 memcpy(table
, &ctx
->u
.iptable
, sizeof(struct zebra_pbr_iptable
));
2510 void dplane_ctx_get_pbr_ipset(const struct zebra_dplane_ctx
*ctx
,
2511 struct zebra_pbr_ipset
*ipset
)
2513 DPLANE_CTX_VALID(ctx
);
2517 if (ctx
->zd_op
== DPLANE_OP_IPSET_ENTRY_ADD
||
2518 ctx
->zd_op
== DPLANE_OP_IPSET_ENTRY_DELETE
) {
2519 memset(ipset
, 0, sizeof(struct zebra_pbr_ipset
));
2520 ipset
->type
= ctx
->u
.ipset_entry
.info
.type
;
2521 ipset
->family
= ctx
->u
.ipset_entry
.info
.family
;
2522 memcpy(&ipset
->ipset_name
, &ctx
->u
.ipset_entry
.info
.ipset_name
,
2523 ZEBRA_IPSET_NAME_SIZE
);
2525 memcpy(ipset
, &ctx
->u
.ipset
, sizeof(struct zebra_pbr_ipset
));
2528 void dplane_ctx_get_pbr_ipset_entry(const struct zebra_dplane_ctx
*ctx
,
2529 struct zebra_pbr_ipset_entry
*entry
)
2531 DPLANE_CTX_VALID(ctx
);
2535 memcpy(entry
, &ctx
->u
.ipset_entry
.entry
, sizeof(struct zebra_pbr_ipset_entry
));
2538 const struct ethaddr
*
2539 dplane_ctx_rule_get_smac(const struct zebra_dplane_ctx
*ctx
)
2541 DPLANE_CTX_VALID(ctx
);
2543 return &(ctx
->u
.rule
.new.smac
);
2546 const struct ethaddr
*
2547 dplane_ctx_rule_get_dmac(const struct zebra_dplane_ctx
*ctx
)
2549 DPLANE_CTX_VALID(ctx
);
2551 return &(ctx
->u
.rule
.new.dmac
);
2554 int dplane_ctx_rule_get_out_ifindex(const struct zebra_dplane_ctx
*ctx
)
2556 DPLANE_CTX_VALID(ctx
);
2558 return ctx
->u
.rule
.new.out_ifindex
;
2561 intptr_t dplane_ctx_rule_get_old_dp_flow_ptr(const struct zebra_dplane_ctx
*ctx
)
2563 DPLANE_CTX_VALID(ctx
);
2565 return ctx
->u
.rule
.old
.dp_flow_ptr
;
2568 intptr_t dplane_ctx_rule_get_dp_flow_ptr(const struct zebra_dplane_ctx
*ctx
)
2570 DPLANE_CTX_VALID(ctx
);
2572 return ctx
->u
.rule
.new.dp_flow_ptr
;
2575 void dplane_ctx_rule_set_dp_flow_ptr(struct zebra_dplane_ctx
*ctx
,
2576 intptr_t dp_flow_ptr
)
2578 DPLANE_CTX_VALID(ctx
);
2580 ctx
->u
.rule
.new.dp_flow_ptr
= dp_flow_ptr
;
2584 * End of dplane context accessors
2587 /* Optional extra info about interfaces in nexthops - a plugin must enable
2590 const struct dplane_intf_extra
*
2591 dplane_ctx_get_intf_extra(const struct zebra_dplane_ctx
*ctx
)
2593 return dplane_intf_extra_list_const_first(
2594 &ctx
->u
.rinfo
.intf_extra_list
);
2597 const struct dplane_intf_extra
*
2598 dplane_ctx_intf_extra_next(const struct zebra_dplane_ctx
*ctx
,
2599 const struct dplane_intf_extra
*ptr
)
2601 return dplane_intf_extra_list_const_next(&ctx
->u
.rinfo
.intf_extra_list
,
2605 vrf_id_t
dplane_intf_extra_get_vrfid(const struct dplane_intf_extra
*ptr
)
2610 uint32_t dplane_intf_extra_get_ifindex(const struct dplane_intf_extra
*ptr
)
2612 return ptr
->ifindex
;
2615 uint32_t dplane_intf_extra_get_flags(const struct dplane_intf_extra
*ptr
)
2620 uint32_t dplane_intf_extra_get_status(const struct dplane_intf_extra
*ptr
)
2626 * End of interface extra info accessors
2629 uint8_t dplane_ctx_neightable_get_family(const struct zebra_dplane_ctx
*ctx
)
2631 DPLANE_CTX_VALID(ctx
);
2633 return ctx
->u
.neightable
.family
;
2637 dplane_ctx_neightable_get_app_probes(const struct zebra_dplane_ctx
*ctx
)
2639 DPLANE_CTX_VALID(ctx
);
2641 return ctx
->u
.neightable
.app_probes
;
2645 dplane_ctx_neightable_get_ucast_probes(const struct zebra_dplane_ctx
*ctx
)
2647 DPLANE_CTX_VALID(ctx
);
2649 return ctx
->u
.neightable
.ucast_probes
;
2653 dplane_ctx_neightable_get_mcast_probes(const struct zebra_dplane_ctx
*ctx
)
2655 DPLANE_CTX_VALID(ctx
);
2657 return ctx
->u
.neightable
.mcast_probes
;
2660 enum dplane_netconf_status_e
2661 dplane_ctx_get_netconf_mpls(const struct zebra_dplane_ctx
*ctx
)
2663 DPLANE_CTX_VALID(ctx
);
2665 return ctx
->u
.netconf
.mpls_val
;
2668 enum dplane_netconf_status_e
2669 dplane_ctx_get_netconf_mcast(const struct zebra_dplane_ctx
*ctx
)
2671 DPLANE_CTX_VALID(ctx
);
2673 return ctx
->u
.netconf
.mcast_val
;
2676 enum dplane_netconf_status_e
2677 dplane_ctx_get_netconf_linkdown(const struct zebra_dplane_ctx
*ctx
)
2679 DPLANE_CTX_VALID(ctx
);
2681 return ctx
->u
.netconf
.linkdown_val
;
2684 void dplane_ctx_set_netconf_mpls(struct zebra_dplane_ctx
*ctx
,
2685 enum dplane_netconf_status_e val
)
2687 DPLANE_CTX_VALID(ctx
);
2689 ctx
->u
.netconf
.mpls_val
= val
;
2692 void dplane_ctx_set_netconf_mcast(struct zebra_dplane_ctx
*ctx
,
2693 enum dplane_netconf_status_e val
)
2695 DPLANE_CTX_VALID(ctx
);
2697 ctx
->u
.netconf
.mcast_val
= val
;
2700 void dplane_ctx_set_netconf_linkdown(struct zebra_dplane_ctx
*ctx
,
2701 enum dplane_netconf_status_e val
)
2703 DPLANE_CTX_VALID(ctx
);
2705 ctx
->u
.netconf
.linkdown_val
= val
;
2710 * Retrieve the limit on the number of pending, unprocessed updates.
2712 uint32_t dplane_get_in_queue_limit(void)
2714 return atomic_load_explicit(&zdplane_info
.dg_max_queued_updates
,
2715 memory_order_relaxed
);
2719 * Configure limit on the number of pending, queued updates.
2721 void dplane_set_in_queue_limit(uint32_t limit
, bool set
)
2723 /* Reset to default on 'unset' */
2725 limit
= DPLANE_DEFAULT_MAX_QUEUED
;
2727 atomic_store_explicit(&zdplane_info
.dg_max_queued_updates
, limit
,
2728 memory_order_relaxed
);
2732 * Retrieve the current queue depth of incoming, unprocessed updates
2734 uint32_t dplane_get_in_queue_len(void)
2736 return atomic_load_explicit(&zdplane_info
.dg_routes_queued
,
2737 memory_order_seq_cst
);
2741 * Internal helper that copies information from a zebra ns object; this is
2742 * called in the zebra main pthread context as part of dplane ctx init.
2744 static void ctx_info_from_zns(struct zebra_dplane_info
*ns_info
,
2745 struct zebra_ns
*zns
)
2747 ns_info
->ns_id
= zns
->ns_id
;
2749 #if defined(HAVE_NETLINK)
2750 ns_info
->is_cmd
= true;
2751 ns_info
->sock
= zns
->netlink_dplane_out
.sock
;
2752 ns_info
->seq
= zns
->netlink_dplane_out
.seq
;
2753 #endif /* NETLINK */
2757 * Common dataplane context init with zebra namespace info.
2759 static int dplane_ctx_ns_init(struct zebra_dplane_ctx
*ctx
,
2760 struct zebra_ns
*zns
,
2763 ctx_info_from_zns(&(ctx
->zd_ns_info
), zns
); /* */
2765 ctx
->zd_is_update
= is_update
;
2767 #if defined(HAVE_NETLINK)
2768 /* Increment message counter after copying to context struct - may need
2769 * two messages in some 'update' cases.
2772 zns
->netlink_dplane_out
.seq
+= 2;
2774 zns
->netlink_dplane_out
.seq
++;
2775 #endif /* HAVE_NETLINK */
2780 int dplane_ctx_route_init_basic(struct zebra_dplane_ctx
*ctx
,
2781 enum dplane_op_e op
, struct route_entry
*re
,
2782 const struct prefix
*p
,
2783 const struct prefix_ipv6
*src_p
, afi_t afi
,
2791 dplane_intf_extra_list_init(&ctx
->u
.rinfo
.intf_extra_list
);
2794 ctx
->zd_status
= ZEBRA_DPLANE_REQUEST_SUCCESS
;
2796 ctx
->u
.rinfo
.zd_type
= re
->type
;
2797 ctx
->u
.rinfo
.zd_old_type
= re
->type
;
2799 prefix_copy(&(ctx
->u
.rinfo
.zd_dest
), p
);
2802 prefix_copy(&(ctx
->u
.rinfo
.zd_src
), src_p
);
2804 memset(&(ctx
->u
.rinfo
.zd_src
), 0, sizeof(ctx
->u
.rinfo
.zd_src
));
2806 ctx
->zd_table_id
= re
->table
;
2808 ctx
->u
.rinfo
.zd_flags
= re
->flags
;
2809 ctx
->u
.rinfo
.zd_metric
= re
->metric
;
2810 ctx
->u
.rinfo
.zd_old_metric
= re
->metric
;
2811 ctx
->zd_vrf_id
= re
->vrf_id
;
2812 ctx
->u
.rinfo
.zd_mtu
= re
->mtu
;
2813 ctx
->u
.rinfo
.zd_nexthop_mtu
= re
->nexthop_mtu
;
2814 ctx
->u
.rinfo
.zd_instance
= re
->instance
;
2815 ctx
->u
.rinfo
.zd_tag
= re
->tag
;
2816 ctx
->u
.rinfo
.zd_old_tag
= re
->tag
;
2817 ctx
->u
.rinfo
.zd_distance
= re
->distance
;
2819 ctx
->u
.rinfo
.zd_afi
= afi
;
2820 ctx
->u
.rinfo
.zd_safi
= safi
;
2826 * Initialize a context block for a route update from zebra data structs.
2828 int dplane_ctx_route_init(struct zebra_dplane_ctx
*ctx
, enum dplane_op_e op
,
2829 struct route_node
*rn
, struct route_entry
*re
)
2832 const struct route_table
*table
= NULL
;
2833 const struct rib_table_info
*info
;
2834 const struct prefix
*p
;
2835 const struct prefix_ipv6
*src_p
;
2836 struct zebra_ns
*zns
;
2837 struct zebra_vrf
*zvrf
;
2838 struct nexthop
*nexthop
;
2839 struct zebra_l3vni
*zl3vni
;
2840 const struct interface
*ifp
;
2841 struct dplane_intf_extra
*if_extra
;
2843 if (!ctx
|| !rn
|| !re
)
2847 * Let's grab the data from the route_node
2848 * so that we can call a helper function
2851 /* Prefixes: dest, and optional source */
2852 srcdest_rnode_prefixes(rn
, &p
, (const struct prefix
**)&src_p
);
2853 table
= srcdest_rnode_table(rn
);
2856 if (dplane_ctx_route_init_basic(ctx
, op
, re
, p
, src_p
, info
->afi
,
2860 /* Copy nexthops; recursive info is included too */
2861 copy_nexthops(&(ctx
->u
.rinfo
.zd_ng
.nexthop
),
2862 re
->nhe
->nhg
.nexthop
, NULL
);
2863 ctx
->u
.rinfo
.zd_nhg_id
= re
->nhe
->id
;
2865 /* Copy backup nexthop info, if present */
2866 if (re
->nhe
->backup_info
&& re
->nhe
->backup_info
->nhe
) {
2867 copy_nexthops(&(ctx
->u
.rinfo
.backup_ng
.nexthop
),
2868 re
->nhe
->backup_info
->nhe
->nhg
.nexthop
, NULL
);
2872 * Ensure that the dplane nexthops' flags are clear and copy
2873 * encapsulation information.
2875 for (ALL_NEXTHOPS(ctx
->u
.rinfo
.zd_ng
, nexthop
)) {
2876 UNSET_FLAG(nexthop
->flags
, NEXTHOP_FLAG_FIB
);
2878 /* Optionally capture extra interface info while we're in the
2879 * main zebra pthread - a plugin has to ask for this info.
2881 if (dplane_collect_extra_intf_info
) {
2882 ifp
= if_lookup_by_index(nexthop
->ifindex
,
2888 sizeof(struct dplane_intf_extra
));
2889 if_extra
->vrf_id
= nexthop
->vrf_id
;
2890 if_extra
->ifindex
= nexthop
->ifindex
;
2891 if_extra
->flags
= ifp
->flags
;
2892 if_extra
->status
= ifp
->status
;
2894 dplane_intf_extra_list_add_tail(
2895 &ctx
->u
.rinfo
.intf_extra_list
,
2900 /* Check for available evpn encapsulations. */
2901 if (!CHECK_FLAG(nexthop
->flags
, NEXTHOP_FLAG_EVPN
))
2904 zl3vni
= zl3vni_from_vrf(nexthop
->vrf_id
);
2905 if (zl3vni
&& is_l3vni_oper_up(zl3vni
)) {
2906 nexthop
->nh_encap_type
= NET_VXLAN
;
2907 nexthop
->nh_encap
.vni
= zl3vni
->vni
;
2911 /* Don't need some info when capturing a system notification */
2912 if (op
== DPLANE_OP_SYS_ROUTE_ADD
||
2913 op
== DPLANE_OP_SYS_ROUTE_DELETE
) {
2917 /* Extract ns info - can't use pointers to 'core' structs */
2918 zvrf
= vrf_info_lookup(re
->vrf_id
);
2920 dplane_ctx_ns_init(ctx
, zns
, (op
== DPLANE_OP_ROUTE_UPDATE
));
2924 struct nhg_hash_entry
*nhe
= zebra_nhg_resolve(re
->nhe
);
2926 ctx
->u
.rinfo
.nhe
.id
= nhe
->id
;
2927 ctx
->u
.rinfo
.nhe
.old_id
= 0;
2929 * Check if the nhe is installed/queued before doing anything
2932 * If its a delete we only use the prefix anyway, so this only
2933 * matters for INSTALL/UPDATE.
2935 if (zebra_nhg_kernel_nexthops_enabled() &&
2936 (((op
== DPLANE_OP_ROUTE_INSTALL
) ||
2937 (op
== DPLANE_OP_ROUTE_UPDATE
)) &&
2938 !CHECK_FLAG(nhe
->flags
, NEXTHOP_GROUP_INSTALLED
) &&
2939 !CHECK_FLAG(nhe
->flags
, NEXTHOP_GROUP_QUEUED
)))
2942 re
->nhe_installed_id
= nhe
->id
;
2944 #endif /* HAVE_NETLINK */
2946 /* Trying out the sequence number idea, so we can try to detect
2947 * when a result is stale.
2949 re
->dplane_sequence
= zebra_router_get_next_sequence();
2950 ctx
->zd_seq
= re
->dplane_sequence
;
2955 static int dplane_ctx_tc_qdisc_init(struct zebra_dplane_ctx
*ctx
,
2956 enum dplane_op_e op
,
2957 const struct zebra_tc_qdisc
*qdisc
)
2961 struct zebra_ns
*zns
= NULL
;
2964 ctx
->zd_status
= ZEBRA_DPLANE_REQUEST_SUCCESS
;
2965 ctx
->zd_ifindex
= qdisc
->qdisc
.ifindex
;
2966 ctx
->u
.tc_qdisc
.kind
= qdisc
->qdisc
.kind
;
2967 ctx
->u
.tc_qdisc
.kind_str
= tc_qdisc_kind2str(qdisc
->qdisc
.kind
);
2969 /* TODO: init traffic control qdisc */
2970 zns
= zebra_ns_lookup(NS_DEFAULT
);
2972 dplane_ctx_ns_init(ctx
, zns
, true);
2979 static int dplane_ctx_tc_class_init(struct zebra_dplane_ctx
*ctx
,
2980 enum dplane_op_e op
,
2981 struct zebra_tc_class
*class)
2985 struct zebra_ns
*zns
= NULL
;
2988 ctx
->zd_status
= ZEBRA_DPLANE_REQUEST_SUCCESS
;
2989 ctx
->zd_ifindex
= class->class.ifindex
;
2991 ctx
->u
.tc_class
.handle
= class->class.handle
;
2992 ctx
->u
.tc_class
.kind
= class->class.kind
;
2993 ctx
->u
.tc_class
.kind_str
= tc_qdisc_kind2str(class->class.kind
);
2994 ctx
->u
.tc_class
.rate
= class->class.u
.htb
.rate
;
2995 ctx
->u
.tc_class
.ceil
= class->class.u
.htb
.ceil
;
2997 zns
= zebra_ns_lookup(NS_DEFAULT
);
2999 dplane_ctx_ns_init(ctx
, zns
, true);
3006 static int dplane_ctx_tc_filter_init(struct zebra_dplane_ctx
*ctx
,
3007 enum dplane_op_e op
,
3008 struct zebra_tc_filter
*filter
)
3012 struct zebra_ns
*zns
= NULL
;
3015 ctx
->zd_status
= ZEBRA_DPLANE_REQUEST_SUCCESS
;
3016 ctx
->zd_ifindex
= filter
->filter
.ifindex
;
3018 ctx
->u
.tc_filter
.eth_proto
= filter
->filter
.protocol
;
3019 ctx
->u
.tc_filter
.ip_proto
= filter
->filter
.u
.flower
.ip_proto
;
3021 ctx
->u
.tc_filter
.kind
= filter
->filter
.kind
;
3022 ctx
->u
.tc_filter
.kind_str
= tc_filter_kind2str(filter
->filter
.kind
);
3024 ctx
->u
.tc_filter
.filter_bm
= filter
->filter
.u
.flower
.filter_bm
;
3025 prefix_copy(&ctx
->u
.tc_filter
.src_ip
, &filter
->filter
.u
.flower
.src_ip
);
3026 ctx
->u
.tc_filter
.src_port_min
= filter
->filter
.u
.flower
.src_port_min
;
3027 ctx
->u
.tc_filter
.src_port_max
= filter
->filter
.u
.flower
.src_port_max
;
3028 prefix_copy(&ctx
->u
.tc_filter
.dst_ip
, &filter
->filter
.u
.flower
.dst_ip
);
3029 ctx
->u
.tc_filter
.dst_port_min
= filter
->filter
.u
.flower
.dst_port_min
;
3030 ctx
->u
.tc_filter
.dst_port_max
= filter
->filter
.u
.flower
.dst_port_max
;
3031 ctx
->u
.tc_filter
.dsfield
= filter
->filter
.u
.flower
.dsfield
;
3032 ctx
->u
.tc_filter
.dsfield_mask
= filter
->filter
.u
.flower
.dsfield_mask
;
3033 ctx
->u
.tc_filter
.classid
= filter
->filter
.u
.flower
.classid
;
3035 ctx
->u
.tc_filter
.priority
= filter
->filter
.priority
;
3036 ctx
->u
.tc_filter
.handle
= filter
->filter
.handle
;
3038 zns
= zebra_ns_lookup(NS_DEFAULT
);
3040 dplane_ctx_ns_init(ctx
, zns
, true);
3048 * dplane_ctx_nexthop_init() - Initialize a context block for a nexthop update
3050 * @ctx: Dataplane context to init
3051 * @op: Operation being performed
3052 * @nhe: Nexthop group hash entry
3054 * Return: Result status
3056 int dplane_ctx_nexthop_init(struct zebra_dplane_ctx
*ctx
, enum dplane_op_e op
,
3057 struct nhg_hash_entry
*nhe
)
3059 struct zebra_vrf
*zvrf
= NULL
;
3060 struct zebra_ns
*zns
= NULL
;
3067 ctx
->zd_status
= ZEBRA_DPLANE_REQUEST_SUCCESS
;
3069 /* Copy over nhe info */
3070 ctx
->u
.rinfo
.nhe
.id
= nhe
->id
;
3071 ctx
->u
.rinfo
.nhe
.afi
= nhe
->afi
;
3072 ctx
->u
.rinfo
.nhe
.vrf_id
= nhe
->vrf_id
;
3073 ctx
->u
.rinfo
.nhe
.type
= nhe
->type
;
3075 nexthop_group_copy(&(ctx
->u
.rinfo
.nhe
.ng
), &(nhe
->nhg
));
3077 /* If this is a group, convert it to a grp array of ids */
3078 if (!zebra_nhg_depends_is_empty(nhe
)
3079 && !CHECK_FLAG(nhe
->flags
, NEXTHOP_GROUP_RECURSIVE
))
3080 ctx
->u
.rinfo
.nhe
.nh_grp_count
= zebra_nhg_nhe2grp(
3081 ctx
->u
.rinfo
.nhe
.nh_grp
, nhe
, MULTIPATH_NUM
);
3083 zvrf
= vrf_info_lookup(nhe
->vrf_id
);
3086 * Fallback to default namespace if the vrf got ripped out from under
3089 zns
= zvrf
? zvrf
->zns
: zebra_ns_lookup(NS_DEFAULT
);
3092 * TODO: Might not need to mark this as an update, since
3093 * it probably won't require two messages
3095 dplane_ctx_ns_init(ctx
, zns
, (op
== DPLANE_OP_NH_UPDATE
));
3103 * dplane_ctx_intf_init() - Initialize a context block for a interface update
3105 * @ctx: Dataplane context to init
3106 * @op: Operation being performed
3109 * Return: Result status
3111 int dplane_ctx_intf_init(struct zebra_dplane_ctx
*ctx
, enum dplane_op_e op
,
3112 const struct interface
*ifp
)
3114 struct zebra_ns
*zns
;
3115 struct zebra_if
*zif
;
3117 bool set_pdown
, unset_pdown
;
3123 ctx
->zd_status
= ZEBRA_DPLANE_REQUEST_SUCCESS
;
3124 ctx
->zd_vrf_id
= ifp
->vrf
->vrf_id
;
3126 strlcpy(ctx
->zd_ifname
, ifp
->name
, sizeof(ctx
->zd_ifname
));
3127 ctx
->zd_ifindex
= ifp
->ifindex
;
3129 zns
= zebra_ns_lookup(ifp
->vrf
->vrf_id
);
3130 dplane_ctx_ns_init(ctx
, zns
, false);
3133 /* Copy over ifp info */
3134 ctx
->u
.intf
.metric
= ifp
->metric
;
3135 ctx
->u
.intf
.flags
= ifp
->flags
;
3137 /* Copy over extra zebra info, if available */
3138 zif
= (struct zebra_if
*)ifp
->info
;
3141 set_pdown
= !!(zif
->flags
& ZIF_FLAG_SET_PROTODOWN
);
3142 unset_pdown
= !!(zif
->flags
& ZIF_FLAG_UNSET_PROTODOWN
);
3144 if (zif
->protodown_rc
&&
3145 ZEBRA_IF_IS_PROTODOWN_ONLY_EXTERNAL(zif
) == false)
3146 ctx
->u
.intf
.pd_reason_val
= true;
3149 * See if we have new protodown state to set, otherwise keep
3153 ctx
->u
.intf
.protodown
= true;
3154 else if (unset_pdown
)
3155 ctx
->u
.intf
.protodown
= false;
3157 ctx
->u
.intf
.protodown
= !!ZEBRA_IF_IS_PROTODOWN(zif
);
3160 dplane_ctx_ns_init(ctx
, zns
, (op
== DPLANE_OP_INTF_UPDATE
));
3161 ctx
->zd_is_update
= (op
== DPLANE_OP_INTF_UPDATE
);
3169 * Capture information for an LSP update in a dplane context.
3171 int dplane_ctx_lsp_init(struct zebra_dplane_ctx
*ctx
, enum dplane_op_e op
,
3172 struct zebra_lsp
*lsp
)
3175 struct zebra_nhlfe
*nhlfe
, *new_nhlfe
;
3178 ctx
->zd_status
= ZEBRA_DPLANE_REQUEST_SUCCESS
;
3180 /* Capture namespace info */
3181 dplane_ctx_ns_init(ctx
, zebra_ns_lookup(NS_DEFAULT
),
3182 (op
== DPLANE_OP_LSP_UPDATE
));
3184 memset(&ctx
->u
.lsp
, 0, sizeof(ctx
->u
.lsp
));
3186 nhlfe_list_init(&(ctx
->u
.lsp
.nhlfe_list
));
3187 nhlfe_list_init(&(ctx
->u
.lsp
.backup_nhlfe_list
));
3189 /* This may be called to create/init a dplane context, not necessarily
3190 * to copy an lsp object.
3195 if (IS_ZEBRA_DEBUG_DPLANE_DETAIL
)
3196 zlog_debug("init dplane ctx %s: in-label %u ecmp# %d",
3197 dplane_op2str(op
), lsp
->ile
.in_label
,
3200 ctx
->u
.lsp
.ile
= lsp
->ile
;
3201 ctx
->u
.lsp
.addr_family
= lsp
->addr_family
;
3202 ctx
->u
.lsp
.num_ecmp
= lsp
->num_ecmp
;
3203 ctx
->u
.lsp
.flags
= lsp
->flags
;
3205 /* Copy source LSP's nhlfes, and capture 'best' nhlfe */
3206 frr_each(nhlfe_list
, &lsp
->nhlfe_list
, nhlfe
) {
3207 /* Not sure if this is meaningful... */
3208 if (nhlfe
->nexthop
== NULL
)
3211 new_nhlfe
= zebra_mpls_lsp_add_nh(&(ctx
->u
.lsp
), nhlfe
->type
,
3213 if (new_nhlfe
== NULL
|| new_nhlfe
->nexthop
== NULL
) {
3218 /* Need to copy flags and backup info too */
3219 new_nhlfe
->flags
= nhlfe
->flags
;
3220 new_nhlfe
->nexthop
->flags
= nhlfe
->nexthop
->flags
;
3222 if (CHECK_FLAG(new_nhlfe
->nexthop
->flags
,
3223 NEXTHOP_FLAG_HAS_BACKUP
)) {
3224 new_nhlfe
->nexthop
->backup_num
=
3225 nhlfe
->nexthop
->backup_num
;
3226 memcpy(new_nhlfe
->nexthop
->backup_idx
,
3227 nhlfe
->nexthop
->backup_idx
,
3228 new_nhlfe
->nexthop
->backup_num
);
3231 if (nhlfe
== lsp
->best_nhlfe
)
3232 ctx
->u
.lsp
.best_nhlfe
= new_nhlfe
;
3238 /* Capture backup nhlfes/nexthops */
3239 frr_each(nhlfe_list
, &lsp
->backup_nhlfe_list
, nhlfe
) {
3240 /* Not sure if this is meaningful... */
3241 if (nhlfe
->nexthop
== NULL
)
3244 new_nhlfe
= zebra_mpls_lsp_add_backup_nh(&(ctx
->u
.lsp
),
3247 if (new_nhlfe
== NULL
|| new_nhlfe
->nexthop
== NULL
) {
3252 /* Need to copy flags too */
3253 new_nhlfe
->flags
= nhlfe
->flags
;
3254 new_nhlfe
->nexthop
->flags
= nhlfe
->nexthop
->flags
;
3261 * Capture information for an LSP update in a dplane context.
3263 static int dplane_ctx_pw_init(struct zebra_dplane_ctx
*ctx
,
3264 enum dplane_op_e op
,
3265 struct zebra_pw
*pw
)
3270 struct route_table
*table
;
3271 struct route_node
*rn
;
3272 struct route_entry
*re
;
3273 const struct nexthop_group
*nhg
;
3274 struct nexthop
*nh
, *newnh
, *last_nh
;
3276 if (IS_ZEBRA_DEBUG_DPLANE_DETAIL
)
3277 zlog_debug("init dplane ctx %s: pw '%s', loc %u, rem %u",
3278 dplane_op2str(op
), pw
->ifname
, pw
->local_label
,
3282 ctx
->zd_status
= ZEBRA_DPLANE_REQUEST_SUCCESS
;
3284 /* Capture namespace info: no netlink support as of 12/18,
3285 * but just in case...
3287 dplane_ctx_ns_init(ctx
, zebra_ns_lookup(NS_DEFAULT
), false);
3289 memset(&ctx
->u
.pw
, 0, sizeof(ctx
->u
.pw
));
3291 /* This name appears to be c-string, so we use string copy. */
3292 strlcpy(ctx
->zd_ifname
, pw
->ifname
, sizeof(ctx
->zd_ifname
));
3294 ctx
->zd_vrf_id
= pw
->vrf_id
;
3295 ctx
->zd_ifindex
= pw
->ifindex
;
3296 ctx
->u
.pw
.type
= pw
->type
;
3297 ctx
->u
.pw
.af
= pw
->af
;
3298 ctx
->u
.pw
.local_label
= pw
->local_label
;
3299 ctx
->u
.pw
.remote_label
= pw
->remote_label
;
3300 ctx
->u
.pw
.flags
= pw
->flags
;
3302 ctx
->u
.pw
.dest
= pw
->nexthop
;
3304 ctx
->u
.pw
.fields
= pw
->data
;
3306 /* Capture nexthop info for the pw destination. We need to look
3307 * up and use zebra datastructs, but we're running in the zebra
3308 * pthread here so that should be ok.
3310 memcpy(&p
.u
, &pw
->nexthop
, sizeof(pw
->nexthop
));
3312 p
.prefixlen
= ((pw
->af
== AF_INET
) ? IPV4_MAX_BITLEN
: IPV6_MAX_BITLEN
);
3314 afi
= (pw
->af
== AF_INET
) ? AFI_IP
: AFI_IP6
;
3315 table
= zebra_vrf_table(afi
, SAFI_UNICAST
, pw
->vrf_id
);
3319 rn
= route_node_match(table
, &p
);
3324 RNODE_FOREACH_RE(rn
, re
) {
3325 if (CHECK_FLAG(re
->flags
, ZEBRA_FLAG_SELECTED
))
3330 /* We'll capture a 'fib' list of nexthops that meet our
3331 * criteria: installed, and labelled.
3333 nhg
= rib_get_fib_nhg(re
);
3336 if (nhg
&& nhg
->nexthop
) {
3337 for (ALL_NEXTHOPS_PTR(nhg
, nh
)) {
3338 if (!CHECK_FLAG(nh
->flags
, NEXTHOP_FLAG_ACTIVE
)
3339 || CHECK_FLAG(nh
->flags
,
3340 NEXTHOP_FLAG_RECURSIVE
)
3341 || nh
->nh_label
== NULL
)
3344 newnh
= nexthop_dup(nh
, NULL
);
3347 NEXTHOP_APPEND(last_nh
, newnh
);
3349 ctx
->u
.pw
.fib_nhg
.nexthop
= newnh
;
3354 /* Include any installed backup nexthops also. */
3355 nhg
= rib_get_fib_backup_nhg(re
);
3356 if (nhg
&& nhg
->nexthop
) {
3357 for (ALL_NEXTHOPS_PTR(nhg
, nh
)) {
3358 if (!CHECK_FLAG(nh
->flags
, NEXTHOP_FLAG_ACTIVE
)
3359 || CHECK_FLAG(nh
->flags
,
3360 NEXTHOP_FLAG_RECURSIVE
)
3361 || nh
->nh_label
== NULL
)
3364 newnh
= nexthop_dup(nh
, NULL
);
3367 NEXTHOP_APPEND(last_nh
, newnh
);
3369 ctx
->u
.pw
.fib_nhg
.nexthop
= newnh
;
3374 /* Copy primary nexthops; recursive info is included too */
3375 assert(re
->nhe
!= NULL
); /* SA warning */
3376 copy_nexthops(&(ctx
->u
.pw
.primary_nhg
.nexthop
),
3377 re
->nhe
->nhg
.nexthop
, NULL
);
3378 ctx
->u
.pw
.nhg_id
= re
->nhe
->id
;
3380 /* Copy backup nexthop info, if present */
3381 if (re
->nhe
->backup_info
&& re
->nhe
->backup_info
->nhe
) {
3382 copy_nexthops(&(ctx
->u
.pw
.backup_nhg
.nexthop
),
3383 re
->nhe
->backup_info
->nhe
->nhg
.nexthop
,
3387 route_unlock_node(rn
);
3393 * dplane_ctx_rule_init_single() - Initialize a dataplane representation of a
3396 * @dplane_rule: Dataplane internal representation of a rule
3399 static void dplane_ctx_rule_init_single(struct dplane_ctx_rule
*dplane_rule
,
3400 struct zebra_pbr_rule
*rule
)
3402 struct zebra_neigh_ent
*n
;
3404 dplane_rule
->priority
= rule
->rule
.priority
;
3405 dplane_rule
->table
= rule
->rule
.action
.table
;
3407 dplane_rule
->filter_bm
= rule
->rule
.filter
.filter_bm
;
3408 dplane_rule
->fwmark
= rule
->rule
.filter
.fwmark
;
3409 dplane_rule
->dsfield
= rule
->rule
.filter
.dsfield
;
3410 dplane_rule
->ip_proto
= rule
->rule
.filter
.ip_proto
;
3411 dplane_rule
->src_port
= rule
->rule
.filter
.src_port
;
3412 dplane_rule
->dst_port
= rule
->rule
.filter
.dst_port
;
3413 prefix_copy(&(dplane_rule
->dst_ip
), &rule
->rule
.filter
.dst_ip
);
3414 prefix_copy(&(dplane_rule
->src_ip
), &rule
->rule
.filter
.src_ip
);
3416 dplane_rule
->action_pcp
= rule
->rule
.action
.pcp
;
3417 dplane_rule
->action_vlan_flags
= rule
->rule
.action
.vlan_flags
;
3418 dplane_rule
->action_vlan_id
= rule
->rule
.action
.vlan_id
;
3419 dplane_rule
->action_queue_id
= rule
->rule
.action
.queue_id
;
3421 strlcpy(dplane_rule
->ifname
, rule
->ifname
, INTERFACE_NAMSIZ
);
3422 dplane_rule
->dp_flow_ptr
= rule
->action
.dp_flow_ptr
;
3423 n
= rule
->action
.neigh
;
3424 if (n
&& (n
->flags
& ZEBRA_NEIGH_ENT_ACTIVE
)) {
3425 struct interface
*ifp
= if_lookup_by_index_per_ns(
3426 zebra_ns_lookup(NS_DEFAULT
), n
->ifindex
);
3428 dplane_rule
->out_ifindex
= n
->ifindex
;
3429 memcpy(&dplane_rule
->dmac
, &n
->mac
, ETH_ALEN
);
3430 memcpy(&dplane_rule
->smac
, ifp
->hw_addr
, ETH_ALEN
);
3432 dplane_rule
->out_ifindex
= 0;
3438 * dplane_ctx_rule_init() - Initialize a context block for a PBR rule update.
3440 * @ctx: Dataplane context to init
3441 * @op: Operation being performed
3442 * @new_rule: PBR rule
3444 * Return: Result status
3446 static int dplane_ctx_rule_init(struct zebra_dplane_ctx
*ctx
,
3447 enum dplane_op_e op
,
3448 struct zebra_pbr_rule
*new_rule
,
3449 struct zebra_pbr_rule
*old_rule
)
3451 if (IS_ZEBRA_DEBUG_DPLANE_DETAIL
)
3453 "init dplane ctx %s: IF %s Prio %u Fwmark %u Src %pFX Dst %pFX Table %u",
3454 dplane_op2str(op
), new_rule
->ifname
,
3455 new_rule
->rule
.priority
, new_rule
->rule
.filter
.fwmark
,
3456 &new_rule
->rule
.filter
.src_ip
,
3457 &new_rule
->rule
.filter
.dst_ip
,
3458 new_rule
->rule
.action
.table
);
3461 ctx
->zd_status
= ZEBRA_DPLANE_REQUEST_SUCCESS
;
3463 dplane_ctx_ns_init(ctx
, zebra_ns_lookup(NS_DEFAULT
),
3464 op
== DPLANE_OP_RULE_UPDATE
);
3466 ctx
->zd_vrf_id
= new_rule
->vrf_id
;
3467 strlcpy(ctx
->zd_ifname
, new_rule
->ifname
, sizeof(ctx
->zd_ifname
));
3469 ctx
->u
.rule
.sock
= new_rule
->sock
;
3470 ctx
->u
.rule
.unique
= new_rule
->rule
.unique
;
3471 ctx
->u
.rule
.seq
= new_rule
->rule
.seq
;
3473 dplane_ctx_rule_init_single(&ctx
->u
.rule
.new, new_rule
);
3474 if (op
== DPLANE_OP_RULE_UPDATE
) {
3475 dplane_ctx_rule_init_single(&ctx
->u
.rule
.old
, old_rule
);
3476 /* clear the dp_flow_ptr in the old_rule - it is about to be
3479 old_rule
->action
.dp_flow_ptr
= (intptr_t)NULL
;
3485 static void zebra_dplane_interface_name_list_deletion(void *data
)
3487 XFREE(MTYPE_DP_NETFILTER
, data
);
3491 * dplane_ctx_iptable_init() - Initialize a context block for a PBR iptable
3494 * @ctx: Dataplane context to init
3495 * @op: Operation being performed
3496 * @new_rule: PBR iptable
3498 * Return: Result status
3500 static int dplane_ctx_iptable_init(struct zebra_dplane_ctx
*ctx
,
3501 enum dplane_op_e op
,
3502 struct zebra_pbr_iptable
*iptable
)
3505 struct listnode
*node
;
3507 if (IS_ZEBRA_DEBUG_DPLANE_DETAIL
) {
3509 "init dplane ctx %s: Unique %u Fwmark %u Family %s Action %s",
3510 dplane_op2str(op
), iptable
->unique
, iptable
->fwmark
,
3511 family2str(iptable
->family
),
3512 iptable
->action
== ZEBRA_IPTABLES_DROP
? "Drop"
3517 ctx
->zd_status
= ZEBRA_DPLANE_REQUEST_SUCCESS
;
3519 dplane_ctx_ns_init(ctx
, zebra_ns_lookup(NS_DEFAULT
), false);
3521 ctx
->zd_vrf_id
= iptable
->vrf_id
;
3522 memcpy(&ctx
->u
.iptable
, iptable
, sizeof(struct zebra_pbr_iptable
));
3523 if (iptable
->nb_interface
> 0) {
3524 ctx
->u
.iptable
.interface_name_list
= list_new();
3525 ctx
->u
.iptable
.interface_name_list
->del
=
3526 zebra_dplane_interface_name_list_deletion
;
3527 for (ALL_LIST_ELEMENTS_RO(iptable
->interface_name_list
, node
,
3529 listnode_add(ctx
->u
.iptable
.interface_name_list
,
3530 XSTRDUP(MTYPE_DP_NETFILTER
, ifname
));
3537 * dplane_ctx_ipset_init() - Initialize a context block for a PBR ipset update.
3539 * @ctx: Dataplane context to init
3540 * @op: Operation being performed
3541 * @new_rule: PBR ipset
3543 * Return: Result status
3545 static int dplane_ctx_ipset_init(struct zebra_dplane_ctx
*ctx
,
3546 enum dplane_op_e op
,
3547 struct zebra_pbr_ipset
*ipset
)
3549 if (IS_ZEBRA_DEBUG_DPLANE_DETAIL
) {
3550 zlog_debug("init dplane ctx %s: %s Unique %u Family %s Type %s",
3551 dplane_op2str(op
), ipset
->ipset_name
, ipset
->unique
,
3552 family2str(ipset
->family
),
3553 zebra_pbr_ipset_type2str(ipset
->type
));
3557 ctx
->zd_status
= ZEBRA_DPLANE_REQUEST_SUCCESS
;
3559 dplane_ctx_ns_init(ctx
, zebra_ns_lookup(NS_DEFAULT
), false);
3561 ctx
->zd_vrf_id
= ipset
->vrf_id
;
3563 memcpy(&ctx
->u
.ipset
, ipset
, sizeof(struct zebra_pbr_ipset
));
3568 * dplane_ctx_ipset_entry_init() - Initialize a context block for a PBR ipset
3571 * @ctx: Dataplane context to init
3572 * @op: Operation being performed
3573 * @new_rule: PBR ipset
3575 * Return: Result status
3578 dplane_ctx_ipset_entry_init(struct zebra_dplane_ctx
*ctx
, enum dplane_op_e op
,
3579 struct zebra_pbr_ipset_entry
*ipset_entry
)
3581 struct zebra_pbr_ipset
*ipset
;
3583 ipset
= ipset_entry
->backpointer
;
3584 if (IS_ZEBRA_DEBUG_DPLANE_DETAIL
) {
3585 zlog_debug("init dplane ctx %s: %s Unique %u filter %u",
3586 dplane_op2str(op
), ipset
->ipset_name
,
3587 ipset_entry
->unique
, ipset_entry
->filter_bm
);
3591 ctx
->zd_status
= ZEBRA_DPLANE_REQUEST_SUCCESS
;
3593 dplane_ctx_ns_init(ctx
, zebra_ns_lookup(NS_DEFAULT
), false);
3595 ctx
->zd_vrf_id
= ipset
->vrf_id
;
3597 memcpy(&ctx
->u
.ipset_entry
.entry
, ipset_entry
,
3598 sizeof(struct zebra_pbr_ipset_entry
));
3599 ctx
->u
.ipset_entry
.entry
.backpointer
= NULL
;
3600 ctx
->u
.ipset_entry
.info
.type
= ipset
->type
;
3601 ctx
->u
.ipset_entry
.info
.family
= ipset
->family
;
3602 memcpy(&ctx
->u
.ipset_entry
.info
.ipset_name
, &ipset
->ipset_name
,
3603 ZEBRA_IPSET_NAME_SIZE
);
3610 * Enqueue a new update,
3611 * and ensure an event is active for the dataplane pthread.
3613 static int dplane_update_enqueue(struct zebra_dplane_ctx
*ctx
)
3616 uint32_t high
, curr
;
3618 /* Enqueue for processing by the dataplane pthread */
3621 dplane_ctx_list_add_tail(&zdplane_info
.dg_update_list
, ctx
);
3625 curr
= atomic_fetch_add_explicit(
3626 &(zdplane_info
.dg_routes_queued
),
3627 1, memory_order_seq_cst
);
3629 curr
++; /* We got the pre-incremented value */
3631 /* Maybe update high-water counter also */
3632 high
= atomic_load_explicit(&zdplane_info
.dg_routes_queued_max
,
3633 memory_order_seq_cst
);
3634 while (high
< curr
) {
3635 if (atomic_compare_exchange_weak_explicit(
3636 &zdplane_info
.dg_routes_queued_max
,
3638 memory_order_seq_cst
,
3639 memory_order_seq_cst
))
3643 /* Ensure that an event for the dataplane thread is active */
3644 ret
= dplane_provider_work_ready();
3650 * Utility that prepares a route update and enqueues it for processing
3652 static enum zebra_dplane_result
3653 dplane_route_update_internal(struct route_node
*rn
,
3654 struct route_entry
*re
,
3655 struct route_entry
*old_re
,
3656 enum dplane_op_e op
)
3658 enum zebra_dplane_result result
= ZEBRA_DPLANE_REQUEST_FAILURE
;
3660 struct zebra_dplane_ctx
*ctx
= NULL
;
3662 /* Obtain context block */
3663 ctx
= dplane_ctx_alloc();
3665 /* Init context with info from zebra data structs */
3666 ret
= dplane_ctx_route_init(ctx
, op
, rn
, re
);
3668 /* Capture some extra info for update case
3669 * where there's a different 'old' route.
3671 if ((op
== DPLANE_OP_ROUTE_UPDATE
) &&
3672 old_re
&& (old_re
!= re
)) {
3674 old_re
->dplane_sequence
=
3675 zebra_router_get_next_sequence();
3676 ctx
->zd_old_seq
= old_re
->dplane_sequence
;
3678 ctx
->u
.rinfo
.zd_old_tag
= old_re
->tag
;
3679 ctx
->u
.rinfo
.zd_old_type
= old_re
->type
;
3680 ctx
->u
.rinfo
.zd_old_instance
= old_re
->instance
;
3681 ctx
->u
.rinfo
.zd_old_distance
= old_re
->distance
;
3682 ctx
->u
.rinfo
.zd_old_metric
= old_re
->metric
;
3683 ctx
->u
.rinfo
.nhe
.old_id
= old_re
->nhe
->id
;
3685 #ifndef HAVE_NETLINK
3686 /* For bsd, capture previous re's nexthops too, sigh.
3687 * We'll need these to do per-nexthop deletes.
3689 copy_nexthops(&(ctx
->u
.rinfo
.zd_old_ng
.nexthop
),
3690 old_re
->nhe
->nhg
.nexthop
, NULL
);
3692 if (zebra_nhg_get_backup_nhg(old_re
->nhe
) != NULL
) {
3693 struct nexthop_group
*nhg
;
3694 struct nexthop
**nh
;
3696 nhg
= zebra_nhg_get_backup_nhg(old_re
->nhe
);
3697 nh
= &(ctx
->u
.rinfo
.old_backup_ng
.nexthop
);
3700 copy_nexthops(nh
, nhg
->nexthop
, NULL
);
3702 #endif /* !HAVE_NETLINK */
3706 * If the old and new context type, and nexthop group id
3707 * are the same there is no need to send down a route replace
3708 * as that we know we have sent a nexthop group replace
3709 * or an upper level protocol has sent us the exact
3712 if ((dplane_ctx_get_type(ctx
) == dplane_ctx_get_old_type(ctx
))
3713 && (dplane_ctx_get_nhe_id(ctx
)
3714 == dplane_ctx_get_old_nhe_id(ctx
))
3715 && (dplane_ctx_get_nhe_id(ctx
) >= ZEBRA_NHG_PROTO_LOWER
)) {
3716 struct nexthop
*nexthop
;
3718 if (IS_ZEBRA_DEBUG_DPLANE
)
3720 "%s: Ignoring Route exactly the same",
3723 for (ALL_NEXTHOPS_PTR(dplane_ctx_get_ng(ctx
),
3725 if (CHECK_FLAG(nexthop
->flags
,
3726 NEXTHOP_FLAG_RECURSIVE
))
3729 if (CHECK_FLAG(nexthop
->flags
,
3730 NEXTHOP_FLAG_ACTIVE
))
3731 SET_FLAG(nexthop
->flags
,
3735 dplane_ctx_free(&ctx
);
3736 return ZEBRA_DPLANE_REQUEST_SUCCESS
;
3739 /* Enqueue context for processing */
3740 ret
= dplane_update_enqueue(ctx
);
3743 /* Update counter */
3744 atomic_fetch_add_explicit(&zdplane_info
.dg_routes_in
, 1,
3745 memory_order_relaxed
);
3748 result
= ZEBRA_DPLANE_REQUEST_QUEUED
;
3750 atomic_fetch_add_explicit(&zdplane_info
.dg_route_errors
, 1,
3751 memory_order_relaxed
);
3753 dplane_ctx_free(&ctx
);
3759 static enum zebra_dplane_result
3760 tc_qdisc_update_internal(enum dplane_op_e op
,
3761 const struct zebra_tc_qdisc
*qdisc
)
3763 enum zebra_dplane_result result
= ZEBRA_DPLANE_REQUEST_FAILURE
;
3765 struct zebra_dplane_ctx
*ctx
= NULL
;
3767 /* Obtain context block */
3768 ctx
= dplane_ctx_alloc();
3775 /* Init context with info from zebra data structs */
3776 ret
= dplane_ctx_tc_qdisc_init(ctx
, op
, qdisc
);
3779 ret
= dplane_update_enqueue(ctx
);
3782 /* Update counter */
3783 atomic_fetch_add_explicit(&zdplane_info
.dg_tcs_in
, 1,
3784 memory_order_relaxed
);
3786 result
= ZEBRA_DPLANE_REQUEST_QUEUED
;
3788 atomic_fetch_add_explicit(&zdplane_info
.dg_tcs_errors
, 1,
3789 memory_order_relaxed
);
3791 dplane_ctx_free(&ctx
);
3797 static enum zebra_dplane_result
3798 tc_class_update_internal(enum dplane_op_e op
, struct zebra_tc_class
*class)
3800 enum zebra_dplane_result result
= ZEBRA_DPLANE_REQUEST_FAILURE
;
3802 struct zebra_dplane_ctx
*ctx
= NULL
;
3804 /* Obtain context block */
3805 ctx
= dplane_ctx_alloc();
3812 /* Init context with info from zebra data structs */
3813 ret
= dplane_ctx_tc_class_init(ctx
, op
, class);
3816 ret
= dplane_update_enqueue(ctx
);
3819 /* Update counter */
3820 atomic_fetch_add_explicit(&zdplane_info
.dg_tcs_in
, 1,
3821 memory_order_relaxed
);
3823 result
= ZEBRA_DPLANE_REQUEST_QUEUED
;
3825 atomic_fetch_add_explicit(&zdplane_info
.dg_tcs_errors
, 1,
3826 memory_order_relaxed
);
3828 dplane_ctx_free(&ctx
);
3834 static enum zebra_dplane_result
3835 tc_filter_update_internal(enum dplane_op_e op
, struct zebra_tc_filter
*filter
)
3837 enum zebra_dplane_result result
= ZEBRA_DPLANE_REQUEST_FAILURE
;
3839 struct zebra_dplane_ctx
*ctx
= NULL
;
3841 /* Obtain context block */
3842 ctx
= dplane_ctx_alloc();
3849 /* Init context with info from zebra data structs */
3850 ret
= dplane_ctx_tc_filter_init(ctx
, op
, filter
);
3853 ret
= dplane_update_enqueue(ctx
);
3856 /* Update counter */
3857 atomic_fetch_add_explicit(&zdplane_info
.dg_tcs_in
, 1,
3858 memory_order_relaxed
);
3860 result
= ZEBRA_DPLANE_REQUEST_QUEUED
;
3862 atomic_fetch_add_explicit(&zdplane_info
.dg_tcs_errors
, 1,
3863 memory_order_relaxed
);
3865 dplane_ctx_free(&ctx
);
3871 enum zebra_dplane_result
dplane_tc_qdisc_install(struct zebra_tc_qdisc
*qdisc
)
3873 return tc_qdisc_update_internal(DPLANE_OP_TC_QDISC_INSTALL
, qdisc
);
3876 enum zebra_dplane_result
dplane_tc_qdisc_uninstall(struct zebra_tc_qdisc
*qdisc
)
3878 return tc_qdisc_update_internal(DPLANE_OP_TC_QDISC_UNINSTALL
, qdisc
);
3881 enum zebra_dplane_result
dplane_tc_class_add(struct zebra_tc_class
*class)
3883 return tc_class_update_internal(DPLANE_OP_TC_CLASS_ADD
, class);
3886 enum zebra_dplane_result
dplane_tc_class_delete(struct zebra_tc_class
*class)
3888 return tc_class_update_internal(DPLANE_OP_TC_CLASS_DELETE
, class);
3891 enum zebra_dplane_result
dplane_tc_class_update(struct zebra_tc_class
*class)
3893 return tc_class_update_internal(DPLANE_OP_TC_CLASS_UPDATE
, class);
3896 enum zebra_dplane_result
dplane_tc_filter_add(struct zebra_tc_filter
*filter
)
3898 return tc_filter_update_internal(DPLANE_OP_TC_FILTER_ADD
, filter
);
3901 enum zebra_dplane_result
dplane_tc_filter_delete(struct zebra_tc_filter
*filter
)
3903 return tc_filter_update_internal(DPLANE_OP_TC_FILTER_DELETE
, filter
);
3906 enum zebra_dplane_result
dplane_tc_filter_update(struct zebra_tc_filter
*filter
)
3908 return tc_filter_update_internal(DPLANE_OP_TC_FILTER_UPDATE
, filter
);
3912 * dplane_nexthop_update_internal() - Helper for enqueuing nexthop changes
3914 * @nhe: Nexthop group hash entry where the change occured
3915 * @op: The operation to be enqued
3917 * Return: Result of the change
3919 static enum zebra_dplane_result
3920 dplane_nexthop_update_internal(struct nhg_hash_entry
*nhe
, enum dplane_op_e op
)
3922 enum zebra_dplane_result result
= ZEBRA_DPLANE_REQUEST_FAILURE
;
3924 struct zebra_dplane_ctx
*ctx
= NULL
;
3926 /* Obtain context block */
3927 ctx
= dplane_ctx_alloc();
3933 ret
= dplane_ctx_nexthop_init(ctx
, op
, nhe
);
3935 ret
= dplane_update_enqueue(ctx
);
3938 /* Update counter */
3939 atomic_fetch_add_explicit(&zdplane_info
.dg_nexthops_in
, 1,
3940 memory_order_relaxed
);
3943 result
= ZEBRA_DPLANE_REQUEST_QUEUED
;
3945 atomic_fetch_add_explicit(&zdplane_info
.dg_nexthop_errors
, 1,
3946 memory_order_relaxed
);
3948 dplane_ctx_free(&ctx
);
3955 * Enqueue a route 'add' for the dataplane.
3957 enum zebra_dplane_result
dplane_route_add(struct route_node
*rn
,
3958 struct route_entry
*re
)
3960 enum zebra_dplane_result ret
= ZEBRA_DPLANE_REQUEST_FAILURE
;
3962 if (rn
== NULL
|| re
== NULL
)
3965 ret
= dplane_route_update_internal(rn
, re
, NULL
,
3966 DPLANE_OP_ROUTE_INSTALL
);
3972 * Enqueue a route update for the dataplane.
3974 enum zebra_dplane_result
dplane_route_update(struct route_node
*rn
,
3975 struct route_entry
*re
,
3976 struct route_entry
*old_re
)
3978 enum zebra_dplane_result ret
= ZEBRA_DPLANE_REQUEST_FAILURE
;
3980 if (rn
== NULL
|| re
== NULL
)
3983 ret
= dplane_route_update_internal(rn
, re
, old_re
,
3984 DPLANE_OP_ROUTE_UPDATE
);
3990 * Enqueue a route removal for the dataplane.
3992 enum zebra_dplane_result
dplane_route_delete(struct route_node
*rn
,
3993 struct route_entry
*re
)
3995 enum zebra_dplane_result ret
= ZEBRA_DPLANE_REQUEST_FAILURE
;
3997 if (rn
== NULL
|| re
== NULL
)
4000 ret
= dplane_route_update_internal(rn
, re
, NULL
,
4001 DPLANE_OP_ROUTE_DELETE
);
4007 * Notify the dplane when system/connected routes change.
4009 enum zebra_dplane_result
dplane_sys_route_add(struct route_node
*rn
,
4010 struct route_entry
*re
)
4012 enum zebra_dplane_result ret
= ZEBRA_DPLANE_REQUEST_FAILURE
;
4014 /* Ignore this event unless a provider plugin has requested it. */
4015 if (!zdplane_info
.dg_sys_route_notifs
)
4016 return ZEBRA_DPLANE_REQUEST_SUCCESS
;
4019 if (rn
== NULL
|| re
== NULL
)
4022 ret
= dplane_route_update_internal(rn
, re
, NULL
,
4023 DPLANE_OP_SYS_ROUTE_ADD
);
4029 * Notify the dplane when system/connected routes are deleted.
4031 enum zebra_dplane_result
dplane_sys_route_del(struct route_node
*rn
,
4032 struct route_entry
*re
)
4034 enum zebra_dplane_result ret
= ZEBRA_DPLANE_REQUEST_FAILURE
;
4036 /* Ignore this event unless a provider plugin has requested it. */
4037 if (!zdplane_info
.dg_sys_route_notifs
)
4038 return ZEBRA_DPLANE_REQUEST_SUCCESS
;
4040 if (rn
== NULL
|| re
== NULL
)
4043 ret
= dplane_route_update_internal(rn
, re
, NULL
,
4044 DPLANE_OP_SYS_ROUTE_DELETE
);
4050 * Update from an async notification, to bring other fibs up-to-date.
4052 enum zebra_dplane_result
4053 dplane_route_notif_update(struct route_node
*rn
,
4054 struct route_entry
*re
,
4055 enum dplane_op_e op
,
4056 struct zebra_dplane_ctx
*ctx
)
4058 enum zebra_dplane_result result
= ZEBRA_DPLANE_REQUEST_FAILURE
;
4060 struct zebra_dplane_ctx
*new_ctx
= NULL
;
4061 struct nexthop
*nexthop
;
4062 struct nexthop_group
*nhg
;
4064 if (rn
== NULL
|| re
== NULL
)
4067 new_ctx
= dplane_ctx_alloc();
4068 if (new_ctx
== NULL
)
4071 /* Init context with info from zebra data structs */
4072 dplane_ctx_route_init(new_ctx
, op
, rn
, re
);
4074 /* For add/update, need to adjust the nexthops so that we match
4075 * the notification state, which may not be the route-entry/RIB
4078 if (op
== DPLANE_OP_ROUTE_UPDATE
||
4079 op
== DPLANE_OP_ROUTE_INSTALL
) {
4081 nexthops_free(new_ctx
->u
.rinfo
.zd_ng
.nexthop
);
4082 new_ctx
->u
.rinfo
.zd_ng
.nexthop
= NULL
;
4084 nhg
= rib_get_fib_nhg(re
);
4085 if (nhg
&& nhg
->nexthop
)
4086 copy_nexthops(&(new_ctx
->u
.rinfo
.zd_ng
.nexthop
),
4087 nhg
->nexthop
, NULL
);
4089 /* Check for installed backup nexthops also */
4090 nhg
= rib_get_fib_backup_nhg(re
);
4091 if (nhg
&& nhg
->nexthop
) {
4092 copy_nexthops(&(new_ctx
->u
.rinfo
.zd_ng
.nexthop
),
4093 nhg
->nexthop
, NULL
);
4096 for (ALL_NEXTHOPS(new_ctx
->u
.rinfo
.zd_ng
, nexthop
))
4097 UNSET_FLAG(nexthop
->flags
, NEXTHOP_FLAG_FIB
);
4101 /* Capture info about the source of the notification, in 'ctx' */
4102 dplane_ctx_set_notif_provider(new_ctx
,
4103 dplane_ctx_get_notif_provider(ctx
));
4105 ret
= dplane_update_enqueue(new_ctx
);
4109 result
= ZEBRA_DPLANE_REQUEST_QUEUED
;
4111 dplane_ctx_free(&new_ctx
);
4117 * Enqueue a nexthop add for the dataplane.
4119 enum zebra_dplane_result
dplane_nexthop_add(struct nhg_hash_entry
*nhe
)
4121 enum zebra_dplane_result ret
= ZEBRA_DPLANE_REQUEST_FAILURE
;
4124 ret
= dplane_nexthop_update_internal(nhe
, DPLANE_OP_NH_INSTALL
);
4129 * Enqueue a nexthop update for the dataplane.
4131 * Might not need this func since zebra's nexthop objects should be immutable?
4133 enum zebra_dplane_result
dplane_nexthop_update(struct nhg_hash_entry
*nhe
)
4135 enum zebra_dplane_result ret
= ZEBRA_DPLANE_REQUEST_FAILURE
;
4138 ret
= dplane_nexthop_update_internal(nhe
, DPLANE_OP_NH_UPDATE
);
4143 * Enqueue a nexthop removal for the dataplane.
4145 enum zebra_dplane_result
dplane_nexthop_delete(struct nhg_hash_entry
*nhe
)
4147 enum zebra_dplane_result ret
= ZEBRA_DPLANE_REQUEST_FAILURE
;
4150 ret
= dplane_nexthop_update_internal(nhe
, DPLANE_OP_NH_DELETE
);
4156 * Enqueue LSP add for the dataplane.
4158 enum zebra_dplane_result
dplane_lsp_add(struct zebra_lsp
*lsp
)
4160 enum zebra_dplane_result ret
=
4161 lsp_update_internal(lsp
, DPLANE_OP_LSP_INSTALL
);
4167 * Enqueue LSP update for the dataplane.
4169 enum zebra_dplane_result
dplane_lsp_update(struct zebra_lsp
*lsp
)
4171 enum zebra_dplane_result ret
=
4172 lsp_update_internal(lsp
, DPLANE_OP_LSP_UPDATE
);
4178 * Enqueue LSP delete for the dataplane.
4180 enum zebra_dplane_result
dplane_lsp_delete(struct zebra_lsp
*lsp
)
4182 enum zebra_dplane_result ret
=
4183 lsp_update_internal(lsp
, DPLANE_OP_LSP_DELETE
);
4188 /* Update or un-install resulting from an async notification */
4189 enum zebra_dplane_result
4190 dplane_lsp_notif_update(struct zebra_lsp
*lsp
, enum dplane_op_e op
,
4191 struct zebra_dplane_ctx
*notif_ctx
)
4193 enum zebra_dplane_result result
= ZEBRA_DPLANE_REQUEST_FAILURE
;
4195 struct zebra_dplane_ctx
*ctx
= NULL
;
4196 struct nhlfe_list_head
*head
;
4197 struct zebra_nhlfe
*nhlfe
, *new_nhlfe
;
4199 /* Obtain context block */
4200 ctx
= dplane_ctx_alloc();
4206 /* Copy info from zebra LSP */
4207 ret
= dplane_ctx_lsp_init(ctx
, op
, lsp
);
4211 /* Add any installed backup nhlfes */
4212 head
= &(ctx
->u
.lsp
.backup_nhlfe_list
);
4213 frr_each(nhlfe_list
, head
, nhlfe
) {
4215 if (CHECK_FLAG(nhlfe
->flags
, NHLFE_FLAG_INSTALLED
) &&
4216 CHECK_FLAG(nhlfe
->nexthop
->flags
, NEXTHOP_FLAG_FIB
)) {
4217 new_nhlfe
= zebra_mpls_lsp_add_nh(&(ctx
->u
.lsp
),
4221 /* Need to copy flags too */
4222 new_nhlfe
->flags
= nhlfe
->flags
;
4223 new_nhlfe
->nexthop
->flags
= nhlfe
->nexthop
->flags
;
4227 /* Capture info about the source of the notification */
4228 dplane_ctx_set_notif_provider(
4230 dplane_ctx_get_notif_provider(notif_ctx
));
4232 ret
= dplane_update_enqueue(ctx
);
4235 /* Update counter */
4236 atomic_fetch_add_explicit(&zdplane_info
.dg_lsps_in
, 1,
4237 memory_order_relaxed
);
4240 result
= ZEBRA_DPLANE_REQUEST_QUEUED
;
4242 atomic_fetch_add_explicit(&zdplane_info
.dg_lsp_errors
, 1,
4243 memory_order_relaxed
);
4245 dplane_ctx_free(&ctx
);
4251 * Enqueue pseudowire install for the dataplane.
4253 enum zebra_dplane_result
dplane_pw_install(struct zebra_pw
*pw
)
4255 return pw_update_internal(pw
, DPLANE_OP_PW_INSTALL
);
4259 * Enqueue pseudowire un-install for the dataplane.
4261 enum zebra_dplane_result
dplane_pw_uninstall(struct zebra_pw
*pw
)
4263 return pw_update_internal(pw
, DPLANE_OP_PW_UNINSTALL
);
4267 * Common internal LSP update utility
4269 static enum zebra_dplane_result
lsp_update_internal(struct zebra_lsp
*lsp
,
4270 enum dplane_op_e op
)
4272 enum zebra_dplane_result result
= ZEBRA_DPLANE_REQUEST_FAILURE
;
4274 struct zebra_dplane_ctx
*ctx
= NULL
;
4276 /* Obtain context block */
4277 ctx
= dplane_ctx_alloc();
4279 ret
= dplane_ctx_lsp_init(ctx
, op
, lsp
);
4283 ret
= dplane_update_enqueue(ctx
);
4286 /* Update counter */
4287 atomic_fetch_add_explicit(&zdplane_info
.dg_lsps_in
, 1,
4288 memory_order_relaxed
);
4291 result
= ZEBRA_DPLANE_REQUEST_QUEUED
;
4293 atomic_fetch_add_explicit(&zdplane_info
.dg_lsp_errors
, 1,
4294 memory_order_relaxed
);
4295 dplane_ctx_free(&ctx
);
4302 * Internal, common handler for pseudowire updates.
4304 static enum zebra_dplane_result
pw_update_internal(struct zebra_pw
*pw
,
4305 enum dplane_op_e op
)
4307 enum zebra_dplane_result result
= ZEBRA_DPLANE_REQUEST_FAILURE
;
4309 struct zebra_dplane_ctx
*ctx
= NULL
;
4311 ctx
= dplane_ctx_alloc();
4313 ret
= dplane_ctx_pw_init(ctx
, op
, pw
);
4317 ret
= dplane_update_enqueue(ctx
);
4320 /* Update counter */
4321 atomic_fetch_add_explicit(&zdplane_info
.dg_pws_in
, 1,
4322 memory_order_relaxed
);
4325 result
= ZEBRA_DPLANE_REQUEST_QUEUED
;
4327 atomic_fetch_add_explicit(&zdplane_info
.dg_pw_errors
, 1,
4328 memory_order_relaxed
);
4329 dplane_ctx_free(&ctx
);
4336 * Enqueue access br_port update.
4338 enum zebra_dplane_result
4339 dplane_br_port_update(const struct interface
*ifp
, bool non_df
,
4340 uint32_t sph_filter_cnt
,
4341 const struct in_addr
*sph_filters
, uint32_t backup_nhg_id
)
4343 enum zebra_dplane_result result
= ZEBRA_DPLANE_REQUEST_FAILURE
;
4346 struct zebra_dplane_ctx
*ctx
= NULL
;
4347 struct zebra_ns
*zns
;
4348 enum dplane_op_e op
= DPLANE_OP_BR_PORT_UPDATE
;
4351 flags
|= DPLANE_BR_PORT_NON_DF
;
4353 if (IS_ZEBRA_DEBUG_DPLANE_DETAIL
|| IS_ZEBRA_DEBUG_EVPN_MH_ES
) {
4355 char vtep_str
[ES_VTEP_LIST_STR_SZ
];
4358 for (i
= 0; i
< sph_filter_cnt
; ++i
) {
4359 snprintfrr(vtep_str
+ strlen(vtep_str
),
4360 sizeof(vtep_str
) - strlen(vtep_str
), "%pI4 ",
4364 "init br_port ctx %s: ifp %s, flags 0x%x backup_nhg 0x%x sph %s",
4365 dplane_op2str(op
), ifp
->name
, flags
, backup_nhg_id
,
4369 ctx
= dplane_ctx_alloc();
4372 ctx
->zd_status
= ZEBRA_DPLANE_REQUEST_SUCCESS
;
4373 ctx
->zd_vrf_id
= ifp
->vrf
->vrf_id
;
4375 zns
= zebra_ns_lookup(ifp
->vrf
->vrf_id
);
4376 dplane_ctx_ns_init(ctx
, zns
, false);
4378 ctx
->zd_ifindex
= ifp
->ifindex
;
4379 strlcpy(ctx
->zd_ifname
, ifp
->name
, sizeof(ctx
->zd_ifname
));
4381 /* Init the br-port-specific data area */
4382 memset(&ctx
->u
.br_port
, 0, sizeof(ctx
->u
.br_port
));
4384 ctx
->u
.br_port
.flags
= flags
;
4385 ctx
->u
.br_port
.backup_nhg_id
= backup_nhg_id
;
4386 ctx
->u
.br_port
.sph_filter_cnt
= sph_filter_cnt
;
4387 memcpy(ctx
->u
.br_port
.sph_filters
, sph_filters
,
4388 sizeof(ctx
->u
.br_port
.sph_filters
[0]) * sph_filter_cnt
);
4390 /* Enqueue for processing on the dplane pthread */
4391 ret
= dplane_update_enqueue(ctx
);
4393 /* Increment counter */
4394 atomic_fetch_add_explicit(&zdplane_info
.dg_br_port_in
, 1,
4395 memory_order_relaxed
);
4398 result
= ZEBRA_DPLANE_REQUEST_QUEUED
;
4401 atomic_fetch_add_explicit(&zdplane_info
.dg_br_port_errors
, 1,
4402 memory_order_relaxed
);
4403 dplane_ctx_free(&ctx
);
4409 enum zebra_dplane_result
4410 dplane_intf_mpls_modify_state(const struct interface
*ifp
, bool set
)
4412 enum zebra_dplane_result result
= ZEBRA_DPLANE_REQUEST_FAILURE
;
4413 struct zebra_dplane_ctx
*ctx
;
4414 struct zebra_ns
*zns
;
4417 ctx
= dplane_ctx_alloc();
4418 ctx
->zd_op
= DPLANE_OP_INTF_NETCONFIG
;
4419 ctx
->zd_status
= ZEBRA_DPLANE_REQUEST_SUCCESS
;
4420 ctx
->zd_vrf_id
= ifp
->vrf
->vrf_id
;
4421 strlcpy(ctx
->zd_ifname
, ifp
->name
, sizeof(ctx
->zd_ifname
));
4423 zns
= zebra_ns_lookup(ifp
->vrf
->vrf_id
);
4424 dplane_ctx_ns_init(ctx
, zns
, false);
4426 ctx
->zd_ifindex
= ifp
->ifindex
;
4428 dplane_ctx_set_netconf_mpls(ctx
, DPLANE_NETCONF_STATUS_ENABLED
);
4430 dplane_ctx_set_netconf_mpls(ctx
,
4431 DPLANE_NETCONF_STATUS_DISABLED
);
4432 /* Increment counter */
4433 atomic_fetch_add_explicit(&zdplane_info
.dg_intf_changes
, 1,
4434 memory_order_relaxed
);
4436 ret
= dplane_update_enqueue(ctx
);
4439 result
= ZEBRA_DPLANE_REQUEST_QUEUED
;
4442 atomic_fetch_add_explicit(&zdplane_info
.dg_intf_changes_errors
,
4443 1, memory_order_relaxed
);
4444 dplane_ctx_free(&ctx
);
4451 * Enqueue interface address add for the dataplane.
4453 enum zebra_dplane_result
dplane_intf_addr_set(const struct interface
*ifp
,
4454 const struct connected
*ifc
)
4456 #if !defined(HAVE_NETLINK) && defined(HAVE_STRUCT_IFALIASREQ)
4457 /* Extra checks for this OS path. */
4459 /* Don't configure PtP addresses on broadcast ifs or reverse */
4460 if (!(ifp
->flags
& IFF_POINTOPOINT
) != !CONNECTED_PEER(ifc
)) {
4461 if (IS_ZEBRA_DEBUG_KERNEL
|| IS_ZEBRA_DEBUG_DPLANE
)
4462 zlog_debug("Failed to set intf addr: mismatch p2p and connected");
4464 return ZEBRA_DPLANE_REQUEST_FAILURE
;
4468 return intf_addr_update_internal(ifp
, ifc
, DPLANE_OP_ADDR_INSTALL
);
4472 * Enqueue interface address remove/uninstall for the dataplane.
4474 enum zebra_dplane_result
dplane_intf_addr_unset(const struct interface
*ifp
,
4475 const struct connected
*ifc
)
4477 return intf_addr_update_internal(ifp
, ifc
, DPLANE_OP_ADDR_UNINSTALL
);
4480 static enum zebra_dplane_result
intf_addr_update_internal(
4481 const struct interface
*ifp
, const struct connected
*ifc
,
4482 enum dplane_op_e op
)
4484 enum zebra_dplane_result result
= ZEBRA_DPLANE_REQUEST_FAILURE
;
4486 struct zebra_dplane_ctx
*ctx
= NULL
;
4487 struct zebra_ns
*zns
;
4489 if (IS_ZEBRA_DEBUG_DPLANE_DETAIL
)
4490 zlog_debug("init intf ctx %s: idx %d, addr %u:%pFX",
4491 dplane_op2str(op
), ifp
->ifindex
, ifp
->vrf
->vrf_id
,
4494 ctx
= dplane_ctx_alloc();
4497 ctx
->zd_status
= ZEBRA_DPLANE_REQUEST_SUCCESS
;
4498 ctx
->zd_vrf_id
= ifp
->vrf
->vrf_id
;
4500 zns
= zebra_ns_lookup(ifp
->vrf
->vrf_id
);
4501 dplane_ctx_ns_init(ctx
, zns
, false);
4503 /* Init the interface-addr-specific area */
4504 memset(&ctx
->u
.intf
, 0, sizeof(ctx
->u
.intf
));
4506 strlcpy(ctx
->zd_ifname
, ifp
->name
, sizeof(ctx
->zd_ifname
));
4507 ctx
->zd_ifindex
= ifp
->ifindex
;
4508 ctx
->u
.intf
.prefix
= *(ifc
->address
);
4510 if (if_is_broadcast(ifp
))
4511 ctx
->u
.intf
.flags
|= DPLANE_INTF_BROADCAST
;
4513 if (CONNECTED_PEER(ifc
)) {
4514 ctx
->u
.intf
.dest_prefix
= *(ifc
->destination
);
4515 ctx
->u
.intf
.flags
|=
4516 (DPLANE_INTF_CONNECTED
| DPLANE_INTF_HAS_DEST
);
4519 if (CHECK_FLAG(ifc
->flags
, ZEBRA_IFA_SECONDARY
))
4520 ctx
->u
.intf
.flags
|= DPLANE_INTF_SECONDARY
;
4525 ctx
->u
.intf
.flags
|= DPLANE_INTF_HAS_LABEL
;
4527 /* Use embedded buffer if it's adequate; else allocate. */
4528 len
= strlen(ifc
->label
);
4530 if (len
< sizeof(ctx
->u
.intf
.label_buf
)) {
4531 strlcpy(ctx
->u
.intf
.label_buf
, ifc
->label
,
4532 sizeof(ctx
->u
.intf
.label_buf
));
4533 ctx
->u
.intf
.label
= ctx
->u
.intf
.label_buf
;
4535 ctx
->u
.intf
.label
= XSTRDUP(MTYPE_DP_CTX
, ifc
->label
);
4539 ret
= dplane_update_enqueue(ctx
);
4541 /* Increment counter */
4542 atomic_fetch_add_explicit(&zdplane_info
.dg_intf_addrs_in
, 1,
4543 memory_order_relaxed
);
4546 result
= ZEBRA_DPLANE_REQUEST_QUEUED
;
4549 atomic_fetch_add_explicit(&zdplane_info
.dg_intf_addr_errors
,
4550 1, memory_order_relaxed
);
4551 dplane_ctx_free(&ctx
);
4558 * dplane_intf_update_internal() - Helper for enqueuing interface changes
4560 * @ifp: Interface where the change occured
4561 * @op: The operation to be enqued
4563 * Return: Result of the change
4565 static enum zebra_dplane_result
4566 dplane_intf_update_internal(const struct interface
*ifp
, enum dplane_op_e op
)
4568 enum zebra_dplane_result result
= ZEBRA_DPLANE_REQUEST_FAILURE
;
4570 struct zebra_dplane_ctx
*ctx
= NULL
;
4572 /* Obtain context block */
4573 ctx
= dplane_ctx_alloc();
4579 ret
= dplane_ctx_intf_init(ctx
, op
, ifp
);
4581 ret
= dplane_update_enqueue(ctx
);
4584 /* Update counter */
4585 atomic_fetch_add_explicit(&zdplane_info
.dg_intfs_in
, 1,
4586 memory_order_relaxed
);
4589 result
= ZEBRA_DPLANE_REQUEST_QUEUED
;
4591 atomic_fetch_add_explicit(&zdplane_info
.dg_intf_errors
, 1,
4592 memory_order_relaxed
);
4594 dplane_ctx_free(&ctx
);
4601 * Enqueue a interface add for the dataplane.
4603 enum zebra_dplane_result
dplane_intf_add(const struct interface
*ifp
)
4605 enum zebra_dplane_result ret
= ZEBRA_DPLANE_REQUEST_FAILURE
;
4608 ret
= dplane_intf_update_internal(ifp
, DPLANE_OP_INTF_INSTALL
);
4613 * Enqueue a interface update for the dataplane.
4615 enum zebra_dplane_result
dplane_intf_update(const struct interface
*ifp
)
4617 enum zebra_dplane_result ret
= ZEBRA_DPLANE_REQUEST_FAILURE
;
4620 ret
= dplane_intf_update_internal(ifp
, DPLANE_OP_INTF_UPDATE
);
4625 * Enqueue a interface delete for the dataplane.
4627 enum zebra_dplane_result
dplane_intf_delete(const struct interface
*ifp
)
4629 enum zebra_dplane_result ret
= ZEBRA_DPLANE_REQUEST_FAILURE
;
4632 ret
= dplane_intf_update_internal(ifp
, DPLANE_OP_INTF_DELETE
);
4637 * Enqueue vxlan/evpn mac add (or update).
4639 enum zebra_dplane_result
dplane_rem_mac_add(const struct interface
*ifp
,
4640 const struct interface
*bridge_ifp
,
4642 const struct ethaddr
*mac
,
4643 struct in_addr vtep_ip
,
4648 enum zebra_dplane_result result
;
4649 uint32_t update_flags
= 0;
4651 update_flags
|= DPLANE_MAC_REMOTE
;
4653 update_flags
|= DPLANE_MAC_WAS_STATIC
;
4655 /* Use common helper api */
4656 result
= mac_update_common(DPLANE_OP_MAC_INSTALL
, ifp
, bridge_ifp
,
4657 vid
, mac
, vtep_ip
, sticky
, nhg_id
, update_flags
);
4662 * Enqueue vxlan/evpn mac delete.
4664 enum zebra_dplane_result
dplane_rem_mac_del(const struct interface
*ifp
,
4665 const struct interface
*bridge_ifp
,
4667 const struct ethaddr
*mac
,
4668 struct in_addr vtep_ip
)
4670 enum zebra_dplane_result result
;
4671 uint32_t update_flags
= 0;
4673 update_flags
|= DPLANE_MAC_REMOTE
;
4675 /* Use common helper api */
4676 result
= mac_update_common(DPLANE_OP_MAC_DELETE
, ifp
, bridge_ifp
,
4677 vid
, mac
, vtep_ip
, false, 0, update_flags
);
4682 * API to configure link local with either MAC address or IP information
4684 enum zebra_dplane_result
dplane_neigh_ip_update(enum dplane_op_e op
,
4685 const struct interface
*ifp
,
4686 struct ipaddr
*link_ip
,
4688 uint32_t ndm_state
, int protocol
)
4690 enum zebra_dplane_result result
= ZEBRA_DPLANE_REQUEST_FAILURE
;
4692 uint32_t update_flags
;
4694 if (IS_ZEBRA_DEBUG_DPLANE_DETAIL
)
4695 zlog_debug("%s: init link ctx %s: ifp %s, link_ip %pIA ip %pIA",
4696 __func__
, dplane_op2str(op
), ifp
->name
, link_ip
, ip
);
4698 if (ndm_state
== ZEBRA_NEIGH_STATE_REACHABLE
)
4699 state
= DPLANE_NUD_REACHABLE
;
4700 else if (ndm_state
== ZEBRA_NEIGH_STATE_FAILED
)
4701 state
= DPLANE_NUD_FAILED
;
4703 update_flags
= DPLANE_NEIGH_NO_EXTENSION
;
4705 result
= neigh_update_internal(op
, ifp
, (const void *)link_ip
,
4706 ipaddr_family(link_ip
), ip
, 0, state
,
4707 update_flags
, protocol
);
4713 * Enqueue local mac add (or update).
4715 enum zebra_dplane_result
dplane_local_mac_add(const struct interface
*ifp
,
4716 const struct interface
*bridge_ifp
,
4718 const struct ethaddr
*mac
,
4720 uint32_t set_static
,
4721 uint32_t set_inactive
)
4723 enum zebra_dplane_result result
;
4724 uint32_t update_flags
= 0;
4725 struct in_addr vtep_ip
;
4728 update_flags
|= DPLANE_MAC_SET_STATIC
;
4731 update_flags
|= DPLANE_MAC_SET_INACTIVE
;
4735 /* Use common helper api */
4736 result
= mac_update_common(DPLANE_OP_MAC_INSTALL
, ifp
, bridge_ifp
,
4737 vid
, mac
, vtep_ip
, sticky
, 0,
4743 * Enqueue local mac del
4745 enum zebra_dplane_result
4746 dplane_local_mac_del(const struct interface
*ifp
,
4747 const struct interface
*bridge_ifp
, vlanid_t vid
,
4748 const struct ethaddr
*mac
)
4750 enum zebra_dplane_result result
;
4751 struct in_addr vtep_ip
;
4755 /* Use common helper api */
4756 result
= mac_update_common(DPLANE_OP_MAC_DELETE
, ifp
, bridge_ifp
, vid
,
4757 mac
, vtep_ip
, false, 0, 0);
4761 * Public api to init an empty context - either newly-allocated or
4762 * reset/cleared - for a MAC update.
4764 void dplane_mac_init(struct zebra_dplane_ctx
*ctx
,
4765 const struct interface
*ifp
,
4766 const struct interface
*br_ifp
,
4768 const struct ethaddr
*mac
,
4769 struct in_addr vtep_ip
,
4772 uint32_t update_flags
)
4774 struct zebra_ns
*zns
;
4776 ctx
->zd_status
= ZEBRA_DPLANE_REQUEST_SUCCESS
;
4777 ctx
->zd_vrf_id
= ifp
->vrf
->vrf_id
;
4779 zns
= zebra_ns_lookup(ifp
->vrf
->vrf_id
);
4780 dplane_ctx_ns_init(ctx
, zns
, false);
4782 strlcpy(ctx
->zd_ifname
, ifp
->name
, sizeof(ctx
->zd_ifname
));
4783 ctx
->zd_ifindex
= ifp
->ifindex
;
4785 /* Init the mac-specific data area */
4786 memset(&ctx
->u
.macinfo
, 0, sizeof(ctx
->u
.macinfo
));
4788 ctx
->u
.macinfo
.br_ifindex
= br_ifp
->ifindex
;
4789 ctx
->u
.macinfo
.vtep_ip
= vtep_ip
;
4790 ctx
->u
.macinfo
.mac
= *mac
;
4791 ctx
->u
.macinfo
.vid
= vid
;
4792 ctx
->u
.macinfo
.is_sticky
= sticky
;
4793 ctx
->u
.macinfo
.nhg_id
= nhg_id
;
4794 ctx
->u
.macinfo
.update_flags
= update_flags
;
4798 * Common helper api for MAC address/vxlan updates
4800 static enum zebra_dplane_result
4801 mac_update_common(enum dplane_op_e op
,
4802 const struct interface
*ifp
,
4803 const struct interface
*br_ifp
,
4805 const struct ethaddr
*mac
,
4806 struct in_addr vtep_ip
,
4809 uint32_t update_flags
)
4811 enum zebra_dplane_result result
= ZEBRA_DPLANE_REQUEST_FAILURE
;
4813 struct zebra_dplane_ctx
*ctx
= NULL
;
4815 if (IS_ZEBRA_DEBUG_DPLANE_DETAIL
)
4816 zlog_debug("init mac ctx %s: mac %pEA, ifp %s, vtep %pI4",
4817 dplane_op2str(op
), mac
, ifp
->name
, &vtep_ip
);
4819 ctx
= dplane_ctx_alloc();
4822 /* Common init for the ctx */
4823 dplane_mac_init(ctx
, ifp
, br_ifp
, vid
, mac
, vtep_ip
, sticky
,
4824 nhg_id
, update_flags
);
4826 /* Enqueue for processing on the dplane pthread */
4827 ret
= dplane_update_enqueue(ctx
);
4829 /* Increment counter */
4830 atomic_fetch_add_explicit(&zdplane_info
.dg_macs_in
, 1,
4831 memory_order_relaxed
);
4834 result
= ZEBRA_DPLANE_REQUEST_QUEUED
;
4837 atomic_fetch_add_explicit(&zdplane_info
.dg_mac_errors
, 1,
4838 memory_order_relaxed
);
4839 dplane_ctx_free(&ctx
);
4846 * Enqueue evpn neighbor add for the dataplane.
4848 enum zebra_dplane_result
dplane_rem_neigh_add(const struct interface
*ifp
,
4849 const struct ipaddr
*ip
,
4850 const struct ethaddr
*mac
,
4851 uint32_t flags
, bool was_static
)
4853 enum zebra_dplane_result result
= ZEBRA_DPLANE_REQUEST_FAILURE
;
4854 uint32_t update_flags
= 0;
4856 update_flags
|= DPLANE_NEIGH_REMOTE
;
4859 update_flags
|= DPLANE_NEIGH_WAS_STATIC
;
4861 result
= neigh_update_internal(
4862 DPLANE_OP_NEIGH_INSTALL
, ifp
, (const void *)mac
, AF_ETHERNET
,
4863 ip
, flags
, DPLANE_NUD_NOARP
, update_flags
, 0);
4869 * Enqueue local neighbor add for the dataplane.
4871 enum zebra_dplane_result
dplane_local_neigh_add(const struct interface
*ifp
,
4872 const struct ipaddr
*ip
,
4873 const struct ethaddr
*mac
,
4874 bool set_router
, bool set_static
,
4877 enum zebra_dplane_result result
= ZEBRA_DPLANE_REQUEST_FAILURE
;
4878 uint32_t update_flags
= 0;
4883 update_flags
|= DPLANE_NEIGH_SET_STATIC
;
4886 update_flags
|= DPLANE_NEIGH_SET_INACTIVE
;
4887 state
= DPLANE_NUD_STALE
;
4889 state
= DPLANE_NUD_REACHABLE
;
4893 ntf
|= DPLANE_NTF_ROUTER
;
4895 result
= neigh_update_internal(DPLANE_OP_NEIGH_INSTALL
, ifp
,
4896 (const void *)mac
, AF_ETHERNET
, ip
, ntf
,
4897 state
, update_flags
, 0);
4903 * Enqueue evpn neighbor delete for the dataplane.
4905 enum zebra_dplane_result
dplane_rem_neigh_delete(const struct interface
*ifp
,
4906 const struct ipaddr
*ip
)
4908 enum zebra_dplane_result result
;
4909 uint32_t update_flags
= 0;
4911 update_flags
|= DPLANE_NEIGH_REMOTE
;
4913 result
= neigh_update_internal(DPLANE_OP_NEIGH_DELETE
, ifp
, NULL
,
4914 AF_ETHERNET
, ip
, 0, 0, update_flags
, 0);
4920 * Enqueue evpn VTEP add for the dataplane.
4922 enum zebra_dplane_result
dplane_vtep_add(const struct interface
*ifp
,
4923 const struct in_addr
*ip
,
4926 enum zebra_dplane_result result
;
4927 struct ethaddr mac
= { {0, 0, 0, 0, 0, 0} };
4930 if (IS_ZEBRA_DEBUG_VXLAN
)
4931 zlog_debug("Install %pI4 into flood list for VNI %u intf %s(%u)",
4932 ip
, vni
, ifp
->name
, ifp
->ifindex
);
4934 SET_IPADDR_V4(&addr
);
4935 addr
.ipaddr_v4
= *ip
;
4937 result
= neigh_update_internal(DPLANE_OP_VTEP_ADD
, ifp
, &mac
,
4938 AF_ETHERNET
, &addr
, 0, 0, 0, 0);
4944 * Enqueue evpn VTEP add for the dataplane.
4946 enum zebra_dplane_result
dplane_vtep_delete(const struct interface
*ifp
,
4947 const struct in_addr
*ip
,
4950 enum zebra_dplane_result result
;
4951 struct ethaddr mac
= { {0, 0, 0, 0, 0, 0} };
4954 if (IS_ZEBRA_DEBUG_VXLAN
)
4956 "Uninstall %pI4 from flood list for VNI %u intf %s(%u)",
4957 ip
, vni
, ifp
->name
, ifp
->ifindex
);
4959 SET_IPADDR_V4(&addr
);
4960 addr
.ipaddr_v4
= *ip
;
4962 result
= neigh_update_internal(DPLANE_OP_VTEP_DELETE
, ifp
,
4963 (const void *)&mac
, AF_ETHERNET
, &addr
,
4969 enum zebra_dplane_result
dplane_neigh_discover(const struct interface
*ifp
,
4970 const struct ipaddr
*ip
)
4972 enum zebra_dplane_result result
;
4974 result
= neigh_update_internal(DPLANE_OP_NEIGH_DISCOVER
, ifp
, NULL
,
4975 AF_ETHERNET
, ip
, DPLANE_NTF_USE
,
4976 DPLANE_NUD_INCOMPLETE
, 0, 0);
4981 enum zebra_dplane_result
dplane_neigh_table_update(const struct interface
*ifp
,
4982 const uint8_t family
,
4983 const uint32_t app_probes
,
4984 const uint32_t ucast_probes
,
4985 const uint32_t mcast_probes
)
4987 enum zebra_dplane_result result
= ZEBRA_DPLANE_REQUEST_FAILURE
;
4989 struct zebra_dplane_ctx
*ctx
= NULL
;
4990 struct zebra_ns
*zns
;
4991 enum dplane_op_e op
= DPLANE_OP_NEIGH_TABLE_UPDATE
;
4993 if (IS_ZEBRA_DEBUG_DPLANE_DETAIL
) {
4994 zlog_debug("set neigh ctx %s: ifp %s, family %s",
4995 dplane_op2str(op
), ifp
->name
, family2str(family
));
4998 ctx
= dplane_ctx_alloc();
5001 ctx
->zd_status
= ZEBRA_DPLANE_REQUEST_SUCCESS
;
5002 ctx
->zd_vrf_id
= ifp
->vrf
->vrf_id
;
5004 zns
= zebra_ns_lookup(ifp
->vrf
->vrf_id
);
5005 dplane_ctx_ns_init(ctx
, zns
, false);
5007 strlcpy(ctx
->zd_ifname
, ifp
->name
, sizeof(ctx
->zd_ifname
));
5008 ctx
->zd_ifindex
= ifp
->ifindex
;
5010 /* Init the neighbor-specific data area */
5011 memset(&ctx
->u
.neightable
, 0, sizeof(ctx
->u
.neightable
));
5013 ctx
->u
.neightable
.family
= family
;
5014 ctx
->u
.neightable
.app_probes
= app_probes
;
5015 ctx
->u
.neightable
.ucast_probes
= ucast_probes
;
5016 ctx
->u
.neightable
.mcast_probes
= mcast_probes
;
5018 /* Enqueue for processing on the dplane pthread */
5019 ret
= dplane_update_enqueue(ctx
);
5021 /* Increment counter */
5022 atomic_fetch_add_explicit(&zdplane_info
.dg_neightable_in
, 1,
5023 memory_order_relaxed
);
5026 result
= ZEBRA_DPLANE_REQUEST_QUEUED
;
5029 atomic_fetch_add_explicit(&zdplane_info
.dg_neightable_errors
, 1,
5030 memory_order_relaxed
);
5031 dplane_ctx_free(&ctx
);
5038 * Common helper api for neighbor updates
5040 static enum zebra_dplane_result
5041 neigh_update_internal(enum dplane_op_e op
, const struct interface
*ifp
,
5042 const void *link
, const int link_family
,
5043 const struct ipaddr
*ip
, uint32_t flags
, uint16_t state
,
5044 uint32_t update_flags
, int protocol
)
5046 enum zebra_dplane_result result
= ZEBRA_DPLANE_REQUEST_FAILURE
;
5048 struct zebra_dplane_ctx
*ctx
= NULL
;
5049 struct zebra_ns
*zns
;
5050 const struct ethaddr
*mac
= NULL
;
5051 const struct ipaddr
*link_ip
= NULL
;
5053 if (link_family
== AF_ETHERNET
)
5054 mac
= (const struct ethaddr
*)link
;
5056 link_ip
= (const struct ipaddr
*)link
;
5058 if (IS_ZEBRA_DEBUG_DPLANE_DETAIL
) {
5059 char buf1
[PREFIX_STRLEN
];
5062 if (link_family
== AF_ETHERNET
)
5063 prefix_mac2str(mac
, buf1
, sizeof(buf1
));
5065 ipaddr2str(link_ip
, buf1
, sizeof(buf1
));
5066 zlog_debug("init neigh ctx %s: ifp %s, %s %s, ip %pIA",
5067 dplane_op2str(op
), ifp
->name
,
5068 link_family
== AF_ETHERNET
? "mac" : "link", buf1
,
5072 ctx
= dplane_ctx_alloc();
5075 ctx
->zd_status
= ZEBRA_DPLANE_REQUEST_SUCCESS
;
5076 ctx
->zd_vrf_id
= ifp
->vrf
->vrf_id
;
5077 dplane_ctx_set_type(ctx
, protocol
);
5079 zns
= zebra_ns_lookup(ifp
->vrf
->vrf_id
);
5080 dplane_ctx_ns_init(ctx
, zns
, false);
5082 strlcpy(ctx
->zd_ifname
, ifp
->name
, sizeof(ctx
->zd_ifname
));
5083 ctx
->zd_ifindex
= ifp
->ifindex
;
5085 /* Init the neighbor-specific data area */
5086 memset(&ctx
->u
.neigh
, 0, sizeof(ctx
->u
.neigh
));
5088 ctx
->u
.neigh
.ip_addr
= *ip
;
5090 ctx
->u
.neigh
.link
.mac
= *mac
;
5092 ctx
->u
.neigh
.link
.ip_addr
= *link_ip
;
5094 ctx
->u
.neigh
.flags
= flags
;
5095 ctx
->u
.neigh
.state
= state
;
5096 ctx
->u
.neigh
.update_flags
= update_flags
;
5098 /* Enqueue for processing on the dplane pthread */
5099 ret
= dplane_update_enqueue(ctx
);
5101 /* Increment counter */
5102 atomic_fetch_add_explicit(&zdplane_info
.dg_neighs_in
, 1,
5103 memory_order_relaxed
);
5106 result
= ZEBRA_DPLANE_REQUEST_QUEUED
;
5109 atomic_fetch_add_explicit(&zdplane_info
.dg_neigh_errors
, 1,
5110 memory_order_relaxed
);
5111 dplane_ctx_free(&ctx
);
5118 * Common helper api for PBR rule updates
5120 static enum zebra_dplane_result
5121 rule_update_internal(enum dplane_op_e op
, struct zebra_pbr_rule
*new_rule
,
5122 struct zebra_pbr_rule
*old_rule
)
5124 enum zebra_dplane_result result
= ZEBRA_DPLANE_REQUEST_FAILURE
;
5125 struct zebra_dplane_ctx
*ctx
;
5128 ctx
= dplane_ctx_alloc();
5130 ret
= dplane_ctx_rule_init(ctx
, op
, new_rule
, old_rule
);
5134 ret
= dplane_update_enqueue(ctx
);
5137 atomic_fetch_add_explicit(&zdplane_info
.dg_rules_in
, 1,
5138 memory_order_relaxed
);
5141 result
= ZEBRA_DPLANE_REQUEST_QUEUED
;
5143 atomic_fetch_add_explicit(&zdplane_info
.dg_rule_errors
, 1,
5144 memory_order_relaxed
);
5145 dplane_ctx_free(&ctx
);
5151 enum zebra_dplane_result
dplane_pbr_rule_add(struct zebra_pbr_rule
*rule
)
5153 return rule_update_internal(DPLANE_OP_RULE_ADD
, rule
, NULL
);
5156 enum zebra_dplane_result
dplane_pbr_rule_delete(struct zebra_pbr_rule
*rule
)
5158 return rule_update_internal(DPLANE_OP_RULE_DELETE
, rule
, NULL
);
5161 enum zebra_dplane_result
dplane_pbr_rule_update(struct zebra_pbr_rule
*old_rule
,
5162 struct zebra_pbr_rule
*new_rule
)
5164 return rule_update_internal(DPLANE_OP_RULE_UPDATE
, new_rule
, old_rule
);
5167 * Common helper api for iptable updates
5169 static enum zebra_dplane_result
5170 iptable_update_internal(enum dplane_op_e op
, struct zebra_pbr_iptable
*iptable
)
5172 enum zebra_dplane_result result
= ZEBRA_DPLANE_REQUEST_FAILURE
;
5173 struct zebra_dplane_ctx
*ctx
;
5176 if ((op
== DPLANE_OP_IPTABLE_ADD
&&
5177 CHECK_FLAG(iptable
->internal_flags
, IPTABLE_INSTALL_QUEUED
)) ||
5178 (op
== DPLANE_OP_IPTABLE_DELETE
&&
5179 CHECK_FLAG(iptable
->internal_flags
, IPTABLE_UNINSTALL_QUEUED
))) {
5180 if (IS_ZEBRA_DEBUG_DPLANE_DETAIL
)
5182 "update dplane ctx %s: iptable %s already in progress",
5183 dplane_op2str(op
), iptable
->ipset_name
);
5187 ctx
= dplane_ctx_alloc();
5189 ret
= dplane_ctx_iptable_init(ctx
, op
, iptable
);
5193 ret
= dplane_update_enqueue(ctx
);
5196 atomic_fetch_add_explicit(&zdplane_info
.dg_iptable_in
, 1,
5197 memory_order_relaxed
);
5200 result
= ZEBRA_DPLANE_REQUEST_QUEUED
;
5201 if (op
== DPLANE_OP_IPTABLE_ADD
)
5202 SET_FLAG(iptable
->internal_flags
,
5203 IPTABLE_INSTALL_QUEUED
);
5205 SET_FLAG(iptable
->internal_flags
,
5206 IPTABLE_UNINSTALL_QUEUED
);
5208 atomic_fetch_add_explicit(&zdplane_info
.dg_iptable_errors
, 1,
5209 memory_order_relaxed
);
5210 dplane_ctx_free(&ctx
);
5215 enum zebra_dplane_result
5216 dplane_pbr_iptable_add(struct zebra_pbr_iptable
*iptable
)
5218 return iptable_update_internal(DPLANE_OP_IPTABLE_ADD
, iptable
);
5221 enum zebra_dplane_result
5222 dplane_pbr_iptable_delete(struct zebra_pbr_iptable
*iptable
)
5224 return iptable_update_internal(DPLANE_OP_IPTABLE_DELETE
, iptable
);
5228 * Common helper api for ipset updates
5230 static enum zebra_dplane_result
5231 ipset_update_internal(enum dplane_op_e op
, struct zebra_pbr_ipset
*ipset
)
5233 enum zebra_dplane_result result
= ZEBRA_DPLANE_REQUEST_FAILURE
;
5234 struct zebra_dplane_ctx
*ctx
;
5237 ctx
= dplane_ctx_alloc();
5239 ret
= dplane_ctx_ipset_init(ctx
, op
, ipset
);
5243 ret
= dplane_update_enqueue(ctx
);
5246 atomic_fetch_add_explicit(&zdplane_info
.dg_ipset_in
, 1,
5247 memory_order_relaxed
);
5250 result
= ZEBRA_DPLANE_REQUEST_QUEUED
;
5252 atomic_fetch_add_explicit(&zdplane_info
.dg_ipset_errors
, 1,
5253 memory_order_relaxed
);
5254 dplane_ctx_free(&ctx
);
5260 enum zebra_dplane_result
dplane_pbr_ipset_add(struct zebra_pbr_ipset
*ipset
)
5262 return ipset_update_internal(DPLANE_OP_IPSET_ADD
, ipset
);
5265 enum zebra_dplane_result
dplane_pbr_ipset_delete(struct zebra_pbr_ipset
*ipset
)
5267 return ipset_update_internal(DPLANE_OP_IPSET_DELETE
, ipset
);
5271 * Common helper api for ipset updates
5273 static enum zebra_dplane_result
5274 ipset_entry_update_internal(enum dplane_op_e op
,
5275 struct zebra_pbr_ipset_entry
*ipset_entry
)
5277 enum zebra_dplane_result result
= ZEBRA_DPLANE_REQUEST_FAILURE
;
5278 struct zebra_dplane_ctx
*ctx
;
5281 ctx
= dplane_ctx_alloc();
5283 ret
= dplane_ctx_ipset_entry_init(ctx
, op
, ipset_entry
);
5287 ret
= dplane_update_enqueue(ctx
);
5290 atomic_fetch_add_explicit(&zdplane_info
.dg_ipset_entry_in
, 1,
5291 memory_order_relaxed
);
5294 result
= ZEBRA_DPLANE_REQUEST_QUEUED
;
5296 atomic_fetch_add_explicit(&zdplane_info
.dg_ipset_entry_errors
,
5297 1, memory_order_relaxed
);
5298 dplane_ctx_free(&ctx
);
5304 enum zebra_dplane_result
5305 dplane_pbr_ipset_entry_add(struct zebra_pbr_ipset_entry
*ipset
)
5307 return ipset_entry_update_internal(DPLANE_OP_IPSET_ENTRY_ADD
, ipset
);
5310 enum zebra_dplane_result
5311 dplane_pbr_ipset_entry_delete(struct zebra_pbr_ipset_entry
*ipset
)
5313 return ipset_entry_update_internal(DPLANE_OP_IPSET_ENTRY_DELETE
, ipset
);
5317 * Common helper api for GRE set
5319 enum zebra_dplane_result
5320 dplane_gre_set(struct interface
*ifp
, struct interface
*ifp_link
,
5321 unsigned int mtu
, const struct zebra_l2info_gre
*gre_info
)
5323 enum zebra_dplane_result result
= ZEBRA_DPLANE_REQUEST_FAILURE
;
5324 struct zebra_dplane_ctx
*ctx
;
5325 enum dplane_op_e op
= DPLANE_OP_GRE_SET
;
5327 struct zebra_ns
*zns
;
5329 ctx
= dplane_ctx_alloc();
5334 if (IS_ZEBRA_DEBUG_DPLANE_DETAIL
) {
5335 zlog_debug("init dplane ctx %s: if %s link %s%s",
5336 dplane_op2str(op
), ifp
->name
,
5337 ifp_link
? "set" : "unset", ifp_link
?
5338 ifp_link
->name
: "");
5342 ctx
->zd_status
= ZEBRA_DPLANE_REQUEST_SUCCESS
;
5343 zns
= zebra_ns_lookup(ifp
->vrf
->vrf_id
);
5346 dplane_ctx_ns_init(ctx
, zns
, false);
5348 dplane_ctx_set_ifname(ctx
, ifp
->name
);
5349 ctx
->zd_vrf_id
= ifp
->vrf
->vrf_id
;
5350 ctx
->zd_ifindex
= ifp
->ifindex
;
5352 ctx
->u
.gre
.link_ifindex
= ifp_link
->ifindex
;
5354 ctx
->u
.gre
.link_ifindex
= 0;
5356 memcpy(&ctx
->u
.gre
.info
, gre_info
, sizeof(ctx
->u
.gre
.info
));
5357 ctx
->u
.gre
.mtu
= mtu
;
5359 ctx
->zd_status
= ZEBRA_DPLANE_REQUEST_SUCCESS
;
5361 /* Enqueue context for processing */
5362 ret
= dplane_update_enqueue(ctx
);
5364 /* Update counter */
5365 atomic_fetch_add_explicit(&zdplane_info
.dg_gre_set_in
, 1,
5366 memory_order_relaxed
);
5369 result
= ZEBRA_DPLANE_REQUEST_QUEUED
;
5371 atomic_fetch_add_explicit(
5372 &zdplane_info
.dg_gre_set_errors
, 1,
5373 memory_order_relaxed
);
5375 dplane_ctx_free(&ctx
);
5376 result
= ZEBRA_DPLANE_REQUEST_FAILURE
;
5382 * Handler for 'show dplane'
5384 int dplane_show_helper(struct vty
*vty
, bool detailed
)
5386 uint64_t queued
, queue_max
, limit
, errs
, incoming
, yields
,
5389 /* Using atomics because counters are being changed in different
5392 incoming
= atomic_load_explicit(&zdplane_info
.dg_routes_in
,
5393 memory_order_relaxed
);
5394 limit
= atomic_load_explicit(&zdplane_info
.dg_max_queued_updates
,
5395 memory_order_relaxed
);
5396 queued
= atomic_load_explicit(&zdplane_info
.dg_routes_queued
,
5397 memory_order_relaxed
);
5398 queue_max
= atomic_load_explicit(&zdplane_info
.dg_routes_queued_max
,
5399 memory_order_relaxed
);
5400 errs
= atomic_load_explicit(&zdplane_info
.dg_route_errors
,
5401 memory_order_relaxed
);
5402 yields
= atomic_load_explicit(&zdplane_info
.dg_update_yields
,
5403 memory_order_relaxed
);
5404 other_errs
= atomic_load_explicit(&zdplane_info
.dg_other_errors
,
5405 memory_order_relaxed
);
5407 vty_out(vty
, "Zebra dataplane:\nRoute updates: %"PRIu64
"\n",
5409 vty_out(vty
, "Route update errors: %"PRIu64
"\n", errs
);
5410 vty_out(vty
, "Other errors : %"PRIu64
"\n", other_errs
);
5411 vty_out(vty
, "Route update queue limit: %"PRIu64
"\n", limit
);
5412 vty_out(vty
, "Route update queue depth: %"PRIu64
"\n", queued
);
5413 vty_out(vty
, "Route update queue max: %"PRIu64
"\n", queue_max
);
5414 vty_out(vty
, "Dplane update yields: %"PRIu64
"\n", yields
);
5416 incoming
= atomic_load_explicit(&zdplane_info
.dg_lsps_in
,
5417 memory_order_relaxed
);
5418 errs
= atomic_load_explicit(&zdplane_info
.dg_lsp_errors
,
5419 memory_order_relaxed
);
5420 vty_out(vty
, "LSP updates: %"PRIu64
"\n", incoming
);
5421 vty_out(vty
, "LSP update errors: %"PRIu64
"\n", errs
);
5423 incoming
= atomic_load_explicit(&zdplane_info
.dg_pws_in
,
5424 memory_order_relaxed
);
5425 errs
= atomic_load_explicit(&zdplane_info
.dg_pw_errors
,
5426 memory_order_relaxed
);
5427 vty_out(vty
, "PW updates: %"PRIu64
"\n", incoming
);
5428 vty_out(vty
, "PW update errors: %"PRIu64
"\n", errs
);
5430 incoming
= atomic_load_explicit(&zdplane_info
.dg_intf_addrs_in
,
5431 memory_order_relaxed
);
5432 errs
= atomic_load_explicit(&zdplane_info
.dg_intf_addr_errors
,
5433 memory_order_relaxed
);
5434 vty_out(vty
, "Intf addr updates: %"PRIu64
"\n", incoming
);
5435 vty_out(vty
, "Intf addr errors: %"PRIu64
"\n", errs
);
5437 incoming
= atomic_load_explicit(&zdplane_info
.dg_intf_changes
,
5438 memory_order_relaxed
);
5439 errs
= atomic_load_explicit(&zdplane_info
.dg_intf_changes_errors
,
5440 memory_order_relaxed
);
5441 vty_out(vty
, "Intf change updates: %" PRIu64
"\n", incoming
);
5442 vty_out(vty
, "Intf change errors: %" PRIu64
"\n", errs
);
5444 incoming
= atomic_load_explicit(&zdplane_info
.dg_macs_in
,
5445 memory_order_relaxed
);
5446 errs
= atomic_load_explicit(&zdplane_info
.dg_mac_errors
,
5447 memory_order_relaxed
);
5448 vty_out(vty
, "EVPN MAC updates: %"PRIu64
"\n", incoming
);
5449 vty_out(vty
, "EVPN MAC errors: %"PRIu64
"\n", errs
);
5451 incoming
= atomic_load_explicit(&zdplane_info
.dg_neighs_in
,
5452 memory_order_relaxed
);
5453 errs
= atomic_load_explicit(&zdplane_info
.dg_neigh_errors
,
5454 memory_order_relaxed
);
5455 vty_out(vty
, "EVPN neigh updates: %"PRIu64
"\n", incoming
);
5456 vty_out(vty
, "EVPN neigh errors: %"PRIu64
"\n", errs
);
5458 incoming
= atomic_load_explicit(&zdplane_info
.dg_rules_in
,
5459 memory_order_relaxed
);
5460 errs
= atomic_load_explicit(&zdplane_info
.dg_rule_errors
,
5461 memory_order_relaxed
);
5462 vty_out(vty
, "Rule updates: %" PRIu64
"\n", incoming
);
5463 vty_out(vty
, "Rule errors: %" PRIu64
"\n", errs
);
5465 incoming
= atomic_load_explicit(&zdplane_info
.dg_br_port_in
,
5466 memory_order_relaxed
);
5467 errs
= atomic_load_explicit(&zdplane_info
.dg_br_port_errors
,
5468 memory_order_relaxed
);
5469 vty_out(vty
, "Bridge port updates: %" PRIu64
"\n", incoming
);
5470 vty_out(vty
, "Bridge port errors: %" PRIu64
"\n", errs
);
5472 incoming
= atomic_load_explicit(&zdplane_info
.dg_iptable_in
,
5473 memory_order_relaxed
);
5474 errs
= atomic_load_explicit(&zdplane_info
.dg_iptable_errors
,
5475 memory_order_relaxed
);
5476 vty_out(vty
, "IPtable updates: %" PRIu64
"\n", incoming
);
5477 vty_out(vty
, "IPtable errors: %" PRIu64
"\n", errs
);
5478 incoming
= atomic_load_explicit(&zdplane_info
.dg_ipset_in
,
5479 memory_order_relaxed
);
5480 errs
= atomic_load_explicit(&zdplane_info
.dg_ipset_errors
,
5481 memory_order_relaxed
);
5482 vty_out(vty
, "IPset updates: %" PRIu64
"\n", incoming
);
5483 vty_out(vty
, "IPset errors: %" PRIu64
"\n", errs
);
5484 incoming
= atomic_load_explicit(&zdplane_info
.dg_ipset_entry_in
,
5485 memory_order_relaxed
);
5486 errs
= atomic_load_explicit(&zdplane_info
.dg_ipset_entry_errors
,
5487 memory_order_relaxed
);
5488 vty_out(vty
, "IPset entry updates: %" PRIu64
"\n", incoming
);
5489 vty_out(vty
, "IPset entry errors: %" PRIu64
"\n", errs
);
5491 incoming
= atomic_load_explicit(&zdplane_info
.dg_neightable_in
,
5492 memory_order_relaxed
);
5493 errs
= atomic_load_explicit(&zdplane_info
.dg_neightable_errors
,
5494 memory_order_relaxed
);
5495 vty_out(vty
, "Neighbor Table updates: %"PRIu64
"\n", incoming
);
5496 vty_out(vty
, "Neighbor Table errors: %"PRIu64
"\n", errs
);
5498 incoming
= atomic_load_explicit(&zdplane_info
.dg_gre_set_in
,
5499 memory_order_relaxed
);
5500 errs
= atomic_load_explicit(&zdplane_info
.dg_gre_set_errors
,
5501 memory_order_relaxed
);
5502 vty_out(vty
, "GRE set updates: %"PRIu64
"\n", incoming
);
5503 vty_out(vty
, "GRE set errors: %"PRIu64
"\n", errs
);
5508 * Handler for 'show dplane providers'
5510 int dplane_show_provs_helper(struct vty
*vty
, bool detailed
)
5512 struct zebra_dplane_provider
*prov
;
5513 uint64_t in
, in_q
, in_max
, out
, out_q
, out_max
;
5515 vty_out(vty
, "Zebra dataplane providers:\n");
5518 prov
= dplane_prov_list_first(&zdplane_info
.dg_providers
);
5521 /* Show counters, useful info from each registered provider */
5524 in
= atomic_load_explicit(&prov
->dp_in_counter
,
5525 memory_order_relaxed
);
5526 in_q
= atomic_load_explicit(&prov
->dp_in_queued
,
5527 memory_order_relaxed
);
5528 in_max
= atomic_load_explicit(&prov
->dp_in_max
,
5529 memory_order_relaxed
);
5530 out
= atomic_load_explicit(&prov
->dp_out_counter
,
5531 memory_order_relaxed
);
5532 out_q
= atomic_load_explicit(&prov
->dp_out_queued
,
5533 memory_order_relaxed
);
5534 out_max
= atomic_load_explicit(&prov
->dp_out_max
,
5535 memory_order_relaxed
);
5537 vty_out(vty
, "%s (%u): in: %"PRIu64
", q: %"PRIu64
", q_max: %"PRIu64
", out: %"PRIu64
", q: %"PRIu64
", q_max: %"PRIu64
"\n",
5538 prov
->dp_name
, prov
->dp_id
, in
, in_q
, in_max
,
5539 out
, out_q
, out_max
);
5541 prov
= dplane_prov_list_next(&zdplane_info
.dg_providers
, prov
);
5548 * Helper for 'show run' etc.
5550 int dplane_config_write_helper(struct vty
*vty
)
5552 if (zdplane_info
.dg_max_queued_updates
!= DPLANE_DEFAULT_MAX_QUEUED
)
5553 vty_out(vty
, "zebra dplane limit %u\n",
5554 zdplane_info
.dg_max_queued_updates
);
5560 * Provider registration
5562 int dplane_provider_register(const char *name
,
5563 enum dplane_provider_prio prio
,
5565 int (*start_fp
)(struct zebra_dplane_provider
*),
5566 int (*fp
)(struct zebra_dplane_provider
*),
5567 int (*fini_fp
)(struct zebra_dplane_provider
*,
5570 struct zebra_dplane_provider
**prov_p
)
5573 struct zebra_dplane_provider
*p
= NULL
, *last
;
5581 if (prio
<= DPLANE_PRIO_NONE
||
5582 prio
> DPLANE_PRIO_LAST
) {
5587 /* Allocate and init new provider struct */
5588 p
= XCALLOC(MTYPE_DP_PROV
, sizeof(struct zebra_dplane_provider
));
5590 pthread_mutex_init(&(p
->dp_mutex
), NULL
);
5591 dplane_ctx_list_init(&p
->dp_ctx_in_list
);
5592 dplane_ctx_list_init(&p
->dp_ctx_out_list
);
5594 p
->dp_flags
= flags
;
5595 p
->dp_priority
= prio
;
5597 p
->dp_start
= start_fp
;
5598 p
->dp_fini
= fini_fp
;
5601 /* Lock - the dplane pthread may be running */
5604 p
->dp_id
= ++zdplane_info
.dg_provider_id
;
5607 strlcpy(p
->dp_name
, name
, DPLANE_PROVIDER_NAMELEN
);
5609 snprintf(p
->dp_name
, DPLANE_PROVIDER_NAMELEN
,
5610 "provider-%u", p
->dp_id
);
5612 /* Insert into list ordered by priority */
5613 frr_each (dplane_prov_list
, &zdplane_info
.dg_providers
, last
) {
5614 if (last
->dp_priority
> p
->dp_priority
)
5619 dplane_prov_list_add_after(&zdplane_info
.dg_providers
, last
, p
);
5621 dplane_prov_list_add_tail(&zdplane_info
.dg_providers
, p
);
5626 if (IS_ZEBRA_DEBUG_DPLANE
)
5627 zlog_debug("dplane: registered new provider '%s' (%u), prio %d",
5628 p
->dp_name
, p
->dp_id
, p
->dp_priority
);
5637 /* Accessors for provider attributes */
5638 const char *dplane_provider_get_name(const struct zebra_dplane_provider
*prov
)
5640 return prov
->dp_name
;
5643 uint32_t dplane_provider_get_id(const struct zebra_dplane_provider
*prov
)
5648 void *dplane_provider_get_data(const struct zebra_dplane_provider
*prov
)
5650 return prov
->dp_data
;
5653 int dplane_provider_get_work_limit(const struct zebra_dplane_provider
*prov
)
5655 return zdplane_info
.dg_updates_per_cycle
;
5658 /* Lock/unlock a provider's mutex - iff the provider was registered with
5659 * the THREADED flag.
5661 void dplane_provider_lock(struct zebra_dplane_provider
*prov
)
5663 if (dplane_provider_is_threaded(prov
))
5664 DPLANE_PROV_LOCK(prov
);
5667 void dplane_provider_unlock(struct zebra_dplane_provider
*prov
)
5669 if (dplane_provider_is_threaded(prov
))
5670 DPLANE_PROV_UNLOCK(prov
);
5674 * Dequeue and maintain associated counter
5676 struct zebra_dplane_ctx
*dplane_provider_dequeue_in_ctx(
5677 struct zebra_dplane_provider
*prov
)
5679 struct zebra_dplane_ctx
*ctx
= NULL
;
5681 dplane_provider_lock(prov
);
5683 ctx
= dplane_ctx_list_pop(&(prov
->dp_ctx_in_list
));
5685 atomic_fetch_sub_explicit(&prov
->dp_in_queued
, 1,
5686 memory_order_relaxed
);
5689 dplane_provider_unlock(prov
);
5695 * Dequeue work to a list, return count
5697 int dplane_provider_dequeue_in_list(struct zebra_dplane_provider
*prov
,
5698 struct dplane_ctx_list_head
*listp
)
5701 struct zebra_dplane_ctx
*ctx
;
5703 limit
= zdplane_info
.dg_updates_per_cycle
;
5705 dplane_provider_lock(prov
);
5707 for (ret
= 0; ret
< limit
; ret
++) {
5708 ctx
= dplane_ctx_list_pop(&(prov
->dp_ctx_in_list
));
5710 dplane_ctx_list_add_tail(listp
, ctx
);
5716 atomic_fetch_sub_explicit(&prov
->dp_in_queued
, ret
,
5717 memory_order_relaxed
);
5719 dplane_provider_unlock(prov
);
5724 uint32_t dplane_provider_out_ctx_queue_len(struct zebra_dplane_provider
*prov
)
5726 return atomic_load_explicit(&(prov
->dp_out_counter
),
5727 memory_order_relaxed
);
5731 * Enqueue and maintain associated counter
5733 void dplane_provider_enqueue_out_ctx(struct zebra_dplane_provider
*prov
,
5734 struct zebra_dplane_ctx
*ctx
)
5736 uint64_t curr
, high
;
5738 dplane_provider_lock(prov
);
5740 dplane_ctx_list_add_tail(&(prov
->dp_ctx_out_list
), ctx
);
5742 /* Maintain out-queue counters */
5743 atomic_fetch_add_explicit(&(prov
->dp_out_queued
), 1,
5744 memory_order_relaxed
);
5745 curr
= atomic_load_explicit(&prov
->dp_out_queued
,
5746 memory_order_relaxed
);
5747 high
= atomic_load_explicit(&prov
->dp_out_max
,
5748 memory_order_relaxed
);
5750 atomic_store_explicit(&prov
->dp_out_max
, curr
,
5751 memory_order_relaxed
);
5753 dplane_provider_unlock(prov
);
5755 atomic_fetch_add_explicit(&(prov
->dp_out_counter
), 1,
5756 memory_order_relaxed
);
5760 * Accessor for provider object
5762 bool dplane_provider_is_threaded(const struct zebra_dplane_provider
*prov
)
5764 return (prov
->dp_flags
& DPLANE_PROV_FLAG_THREADED
);
5769 * Callback when an OS (netlink) incoming event read is ready. This runs
5770 * in the dplane pthread.
5772 static void dplane_incoming_read(struct thread
*event
)
5774 struct dplane_zns_info
*zi
= THREAD_ARG(event
);
5776 kernel_dplane_read(&zi
->info
);
5778 /* Re-start read task */
5779 thread_add_read(zdplane_info
.dg_master
, dplane_incoming_read
, zi
,
5780 zi
->info
.sock
, &zi
->t_read
);
5784 * Callback in the dataplane pthread that requests info from the OS and
5785 * initiates netlink reads.
5787 static void dplane_incoming_request(struct thread
*event
)
5789 struct dplane_zns_info
*zi
= THREAD_ARG(event
);
5791 /* Start read task */
5792 thread_add_read(zdplane_info
.dg_master
, dplane_incoming_read
, zi
,
5793 zi
->info
.sock
, &zi
->t_read
);
5796 netlink_request_netconf(zi
->info
.sock
);
5800 * Initiate requests for existing info from the OS. This is called by the
5801 * main pthread, but we want all activity on the dplane netlink socket to
5802 * take place on the dplane pthread, so we schedule an event to accomplish
5805 static void dplane_kernel_info_request(struct dplane_zns_info
*zi
)
5807 /* If we happen to encounter an enabled zns before the dplane
5808 * pthread is running, we'll initiate this later on.
5810 if (zdplane_info
.dg_master
)
5811 thread_add_event(zdplane_info
.dg_master
,
5812 dplane_incoming_request
, zi
, 0,
5816 #endif /* HAVE_NETLINK */
5819 * Notify dplane when namespaces are enabled and disabled. The dplane
5820 * needs to start and stop reading incoming events from the zns. In the
5821 * common case where vrfs are _not_ namespaces, there will only be one
5824 * This is called in the main pthread.
5826 void zebra_dplane_ns_enable(struct zebra_ns
*zns
, bool enabled
)
5828 struct dplane_zns_info
*zi
;
5830 if (IS_ZEBRA_DEBUG_DPLANE
)
5831 zlog_debug("%s: %s for nsid %u", __func__
,
5832 (enabled
? "ENABLED" : "DISABLED"), zns
->ns_id
);
5834 /* Search for an existing zns info entry */
5835 frr_each (zns_info_list
, &zdplane_info
.dg_zns_list
, zi
) {
5836 if (zi
->info
.ns_id
== zns
->ns_id
)
5841 /* Create a new entry if necessary; start reading. */
5843 zi
= XCALLOC(MTYPE_DP_NS
, sizeof(*zi
));
5845 zi
->info
.ns_id
= zns
->ns_id
;
5847 zns_info_list_add_tail(&zdplane_info
.dg_zns_list
, zi
);
5849 if (IS_ZEBRA_DEBUG_DPLANE
)
5850 zlog_debug("%s: nsid %u, new zi %p", __func__
,
5854 /* Make sure we're up-to-date with the zns object */
5855 #if defined(HAVE_NETLINK)
5856 zi
->info
.is_cmd
= false;
5857 zi
->info
.sock
= zns
->netlink_dplane_in
.sock
;
5859 /* Initiate requests for existing info from the OS, and
5860 * begin reading from the netlink socket.
5862 dplane_kernel_info_request(zi
);
5865 if (IS_ZEBRA_DEBUG_DPLANE
)
5866 zlog_debug("%s: nsid %u, deleting zi %p", __func__
,
5869 /* Stop reading, free memory */
5870 zns_info_list_del(&zdplane_info
.dg_zns_list
, zi
);
5872 /* Stop any outstanding tasks */
5873 if (zdplane_info
.dg_master
) {
5874 thread_cancel_async(zdplane_info
.dg_master
,
5875 &zi
->t_request
, NULL
);
5877 thread_cancel_async(zdplane_info
.dg_master
, &zi
->t_read
,
5881 XFREE(MTYPE_DP_NS
, zi
);
5886 * Provider api to signal that work/events are available
5887 * for the dataplane pthread.
5889 int dplane_provider_work_ready(void)
5891 /* Note that during zebra startup, we may be offered work before
5892 * the dataplane pthread (and thread-master) are ready. We want to
5893 * enqueue the work, but the event-scheduling machinery may not be
5896 if (zdplane_info
.dg_run
) {
5897 thread_add_event(zdplane_info
.dg_master
,
5898 dplane_thread_loop
, NULL
, 0,
5899 &zdplane_info
.dg_t_update
);
5906 * Enqueue a context directly to zebra main.
5908 void dplane_provider_enqueue_to_zebra(struct zebra_dplane_ctx
*ctx
)
5910 struct dplane_ctx_list_head temp_list
;
5912 /* Zebra's api takes a list, so we need to use a temporary list */
5913 dplane_ctx_list_init(&temp_list
);
5915 dplane_ctx_list_add_tail(&temp_list
, ctx
);
5916 (zdplane_info
.dg_results_cb
)(&temp_list
);
5920 * Kernel dataplane provider
5923 static void kernel_dplane_log_detail(struct zebra_dplane_ctx
*ctx
)
5925 char buf
[PREFIX_STRLEN
];
5927 switch (dplane_ctx_get_op(ctx
)) {
5929 case DPLANE_OP_ROUTE_INSTALL
:
5930 case DPLANE_OP_ROUTE_UPDATE
:
5931 case DPLANE_OP_ROUTE_DELETE
:
5932 zlog_debug("%u:%pFX Dplane route update ctx %p op %s",
5933 dplane_ctx_get_vrf(ctx
), dplane_ctx_get_dest(ctx
),
5934 ctx
, dplane_op2str(dplane_ctx_get_op(ctx
)));
5937 case DPLANE_OP_NH_INSTALL
:
5938 case DPLANE_OP_NH_UPDATE
:
5939 case DPLANE_OP_NH_DELETE
:
5940 zlog_debug("ID (%u) Dplane nexthop update ctx %p op %s",
5941 dplane_ctx_get_nhe_id(ctx
), ctx
,
5942 dplane_op2str(dplane_ctx_get_op(ctx
)));
5945 case DPLANE_OP_LSP_INSTALL
:
5946 case DPLANE_OP_LSP_UPDATE
:
5947 case DPLANE_OP_LSP_DELETE
:
5950 case DPLANE_OP_PW_INSTALL
:
5951 case DPLANE_OP_PW_UNINSTALL
:
5952 zlog_debug("Dplane pw %s: op %s af %d loc: %u rem: %u",
5953 dplane_ctx_get_ifname(ctx
),
5954 dplane_op2str(ctx
->zd_op
), dplane_ctx_get_pw_af(ctx
),
5955 dplane_ctx_get_pw_local_label(ctx
),
5956 dplane_ctx_get_pw_remote_label(ctx
));
5959 case DPLANE_OP_ADDR_INSTALL
:
5960 case DPLANE_OP_ADDR_UNINSTALL
:
5961 zlog_debug("Dplane intf %s, idx %u, addr %pFX",
5962 dplane_op2str(dplane_ctx_get_op(ctx
)),
5963 dplane_ctx_get_ifindex(ctx
),
5964 dplane_ctx_get_intf_addr(ctx
));
5967 case DPLANE_OP_MAC_INSTALL
:
5968 case DPLANE_OP_MAC_DELETE
:
5969 prefix_mac2str(dplane_ctx_mac_get_addr(ctx
), buf
,
5972 zlog_debug("Dplane %s, mac %s, ifindex %u",
5973 dplane_op2str(dplane_ctx_get_op(ctx
)),
5974 buf
, dplane_ctx_get_ifindex(ctx
));
5977 case DPLANE_OP_NEIGH_INSTALL
:
5978 case DPLANE_OP_NEIGH_UPDATE
:
5979 case DPLANE_OP_NEIGH_DELETE
:
5980 case DPLANE_OP_VTEP_ADD
:
5981 case DPLANE_OP_VTEP_DELETE
:
5982 case DPLANE_OP_NEIGH_DISCOVER
:
5983 case DPLANE_OP_NEIGH_IP_INSTALL
:
5984 case DPLANE_OP_NEIGH_IP_DELETE
:
5985 ipaddr2str(dplane_ctx_neigh_get_ipaddr(ctx
), buf
,
5988 zlog_debug("Dplane %s, ip %s, ifindex %u",
5989 dplane_op2str(dplane_ctx_get_op(ctx
)),
5990 buf
, dplane_ctx_get_ifindex(ctx
));
5993 case DPLANE_OP_RULE_ADD
:
5994 case DPLANE_OP_RULE_DELETE
:
5995 case DPLANE_OP_RULE_UPDATE
:
5996 zlog_debug("Dplane rule update op %s, if %s(%u), ctx %p",
5997 dplane_op2str(dplane_ctx_get_op(ctx
)),
5998 dplane_ctx_get_ifname(ctx
),
5999 dplane_ctx_get_ifindex(ctx
), ctx
);
6002 case DPLANE_OP_SYS_ROUTE_ADD
:
6003 case DPLANE_OP_SYS_ROUTE_DELETE
:
6004 case DPLANE_OP_ROUTE_NOTIFY
:
6005 case DPLANE_OP_LSP_NOTIFY
:
6006 case DPLANE_OP_BR_PORT_UPDATE
:
6008 case DPLANE_OP_NONE
:
6011 case DPLANE_OP_IPTABLE_ADD
:
6012 case DPLANE_OP_IPTABLE_DELETE
: {
6013 struct zebra_pbr_iptable ipt
;
6015 dplane_ctx_get_pbr_iptable(ctx
, &ipt
);
6016 zlog_debug("Dplane iptable update op %s, unique(%u), ctx %p",
6017 dplane_op2str(dplane_ctx_get_op(ctx
)), ipt
.unique
,
6020 case DPLANE_OP_IPSET_ADD
:
6021 case DPLANE_OP_IPSET_DELETE
: {
6022 struct zebra_pbr_ipset ipset
;
6024 dplane_ctx_get_pbr_ipset(ctx
, &ipset
);
6025 zlog_debug("Dplane ipset update op %s, unique(%u), ctx %p",
6026 dplane_op2str(dplane_ctx_get_op(ctx
)), ipset
.unique
,
6029 case DPLANE_OP_IPSET_ENTRY_ADD
:
6030 case DPLANE_OP_IPSET_ENTRY_DELETE
: {
6031 struct zebra_pbr_ipset_entry ipent
;
6033 dplane_ctx_get_pbr_ipset_entry(ctx
, &ipent
);
6035 "Dplane ipset entry update op %s, unique(%u), ctx %p",
6036 dplane_op2str(dplane_ctx_get_op(ctx
)), ipent
.unique
,
6039 case DPLANE_OP_NEIGH_TABLE_UPDATE
:
6040 zlog_debug("Dplane neigh table op %s, ifp %s, family %s",
6041 dplane_op2str(dplane_ctx_get_op(ctx
)),
6042 dplane_ctx_get_ifname(ctx
),
6043 family2str(dplane_ctx_neightable_get_family(ctx
)));
6045 case DPLANE_OP_GRE_SET
:
6046 zlog_debug("Dplane gre set op %s, ifp %s, link %u",
6047 dplane_op2str(dplane_ctx_get_op(ctx
)),
6048 dplane_ctx_get_ifname(ctx
),
6049 ctx
->u
.gre
.link_ifindex
);
6052 case DPLANE_OP_INTF_ADDR_ADD
:
6053 case DPLANE_OP_INTF_ADDR_DEL
:
6054 zlog_debug("Dplane incoming op %s, intf %s, addr %pFX",
6055 dplane_op2str(dplane_ctx_get_op(ctx
)),
6056 dplane_ctx_get_ifname(ctx
),
6057 dplane_ctx_get_intf_addr(ctx
));
6060 case DPLANE_OP_INTF_NETCONFIG
:
6061 zlog_debug("%s: ifindex %d, mpls %d, mcast %d",
6062 dplane_op2str(dplane_ctx_get_op(ctx
)),
6063 dplane_ctx_get_ifindex(ctx
),
6064 dplane_ctx_get_netconf_mpls(ctx
),
6065 dplane_ctx_get_netconf_mcast(ctx
));
6068 case DPLANE_OP_INTF_INSTALL
:
6069 case DPLANE_OP_INTF_UPDATE
:
6070 case DPLANE_OP_INTF_DELETE
:
6071 zlog_debug("Dplane intf %s, idx %u, protodown %d",
6072 dplane_op2str(dplane_ctx_get_op(ctx
)),
6073 dplane_ctx_get_ifindex(ctx
),
6074 dplane_ctx_intf_is_protodown(ctx
));
6077 /* TODO: more detailed log */
6078 case DPLANE_OP_TC_QDISC_INSTALL
:
6079 case DPLANE_OP_TC_QDISC_UNINSTALL
:
6080 zlog_debug("Dplane tc qdisc ifidx %u",
6081 dplane_ctx_get_ifindex(ctx
));
6083 case DPLANE_OP_TC_CLASS_ADD
:
6084 case DPLANE_OP_TC_CLASS_DELETE
:
6085 case DPLANE_OP_TC_CLASS_UPDATE
:
6087 case DPLANE_OP_TC_FILTER_ADD
:
6088 case DPLANE_OP_TC_FILTER_DELETE
:
6089 case DPLANE_OP_TC_FILTER_UPDATE
:
6094 static void kernel_dplane_handle_result(struct zebra_dplane_ctx
*ctx
)
6096 enum zebra_dplane_result res
= dplane_ctx_get_status(ctx
);
6098 switch (dplane_ctx_get_op(ctx
)) {
6100 case DPLANE_OP_ROUTE_INSTALL
:
6101 case DPLANE_OP_ROUTE_UPDATE
:
6102 case DPLANE_OP_ROUTE_DELETE
:
6103 if (res
!= ZEBRA_DPLANE_REQUEST_SUCCESS
)
6104 atomic_fetch_add_explicit(&zdplane_info
.dg_route_errors
,
6105 1, memory_order_relaxed
);
6107 if ((dplane_ctx_get_op(ctx
) != DPLANE_OP_ROUTE_DELETE
)
6108 && (res
== ZEBRA_DPLANE_REQUEST_SUCCESS
)) {
6109 struct nexthop
*nexthop
;
6111 /* Update installed nexthops to signal which have been
6114 for (ALL_NEXTHOPS_PTR(dplane_ctx_get_ng(ctx
),
6116 if (CHECK_FLAG(nexthop
->flags
,
6117 NEXTHOP_FLAG_RECURSIVE
))
6120 if (CHECK_FLAG(nexthop
->flags
,
6121 NEXTHOP_FLAG_ACTIVE
)) {
6122 SET_FLAG(nexthop
->flags
,
6129 case DPLANE_OP_NH_INSTALL
:
6130 case DPLANE_OP_NH_UPDATE
:
6131 case DPLANE_OP_NH_DELETE
:
6132 if (res
!= ZEBRA_DPLANE_REQUEST_SUCCESS
)
6133 atomic_fetch_add_explicit(
6134 &zdplane_info
.dg_nexthop_errors
, 1,
6135 memory_order_relaxed
);
6138 case DPLANE_OP_LSP_INSTALL
:
6139 case DPLANE_OP_LSP_UPDATE
:
6140 case DPLANE_OP_LSP_DELETE
:
6141 if (res
!= ZEBRA_DPLANE_REQUEST_SUCCESS
)
6142 atomic_fetch_add_explicit(&zdplane_info
.dg_lsp_errors
,
6143 1, memory_order_relaxed
);
6146 case DPLANE_OP_PW_INSTALL
:
6147 case DPLANE_OP_PW_UNINSTALL
:
6148 if (res
!= ZEBRA_DPLANE_REQUEST_SUCCESS
)
6149 atomic_fetch_add_explicit(&zdplane_info
.dg_pw_errors
, 1,
6150 memory_order_relaxed
);
6153 case DPLANE_OP_ADDR_INSTALL
:
6154 case DPLANE_OP_ADDR_UNINSTALL
:
6155 if (res
!= ZEBRA_DPLANE_REQUEST_SUCCESS
)
6156 atomic_fetch_add_explicit(
6157 &zdplane_info
.dg_intf_addr_errors
, 1,
6158 memory_order_relaxed
);
6161 case DPLANE_OP_MAC_INSTALL
:
6162 case DPLANE_OP_MAC_DELETE
:
6163 if (res
!= ZEBRA_DPLANE_REQUEST_SUCCESS
)
6164 atomic_fetch_add_explicit(&zdplane_info
.dg_mac_errors
,
6165 1, memory_order_relaxed
);
6168 case DPLANE_OP_NEIGH_INSTALL
:
6169 case DPLANE_OP_NEIGH_UPDATE
:
6170 case DPLANE_OP_NEIGH_DELETE
:
6171 case DPLANE_OP_VTEP_ADD
:
6172 case DPLANE_OP_VTEP_DELETE
:
6173 case DPLANE_OP_NEIGH_DISCOVER
:
6174 case DPLANE_OP_NEIGH_IP_INSTALL
:
6175 case DPLANE_OP_NEIGH_IP_DELETE
:
6176 if (res
!= ZEBRA_DPLANE_REQUEST_SUCCESS
)
6177 atomic_fetch_add_explicit(&zdplane_info
.dg_neigh_errors
,
6178 1, memory_order_relaxed
);
6181 case DPLANE_OP_RULE_ADD
:
6182 case DPLANE_OP_RULE_DELETE
:
6183 case DPLANE_OP_RULE_UPDATE
:
6184 if (res
!= ZEBRA_DPLANE_REQUEST_SUCCESS
)
6185 atomic_fetch_add_explicit(&zdplane_info
.dg_rule_errors
,
6186 1, memory_order_relaxed
);
6189 case DPLANE_OP_IPTABLE_ADD
:
6190 case DPLANE_OP_IPTABLE_DELETE
:
6191 if (res
!= ZEBRA_DPLANE_REQUEST_SUCCESS
)
6192 atomic_fetch_add_explicit(
6193 &zdplane_info
.dg_iptable_errors
, 1,
6194 memory_order_relaxed
);
6197 case DPLANE_OP_IPSET_ADD
:
6198 case DPLANE_OP_IPSET_DELETE
:
6199 if (res
!= ZEBRA_DPLANE_REQUEST_SUCCESS
)
6200 atomic_fetch_add_explicit(&zdplane_info
.dg_ipset_errors
,
6201 1, memory_order_relaxed
);
6204 case DPLANE_OP_IPSET_ENTRY_ADD
:
6205 case DPLANE_OP_IPSET_ENTRY_DELETE
:
6206 if (res
!= ZEBRA_DPLANE_REQUEST_SUCCESS
)
6207 atomic_fetch_add_explicit(
6208 &zdplane_info
.dg_ipset_entry_errors
, 1,
6209 memory_order_relaxed
);
6212 case DPLANE_OP_NEIGH_TABLE_UPDATE
:
6213 if (res
!= ZEBRA_DPLANE_REQUEST_SUCCESS
)
6214 atomic_fetch_add_explicit(
6215 &zdplane_info
.dg_neightable_errors
, 1,
6216 memory_order_relaxed
);
6219 case DPLANE_OP_GRE_SET
:
6220 if (res
!= ZEBRA_DPLANE_REQUEST_SUCCESS
)
6221 atomic_fetch_add_explicit(
6222 &zdplane_info
.dg_gre_set_errors
, 1,
6223 memory_order_relaxed
);
6226 case DPLANE_OP_INTF_INSTALL
:
6227 case DPLANE_OP_INTF_UPDATE
:
6228 case DPLANE_OP_INTF_DELETE
:
6229 if (res
!= ZEBRA_DPLANE_REQUEST_SUCCESS
)
6230 atomic_fetch_add_explicit(&zdplane_info
.dg_intf_errors
,
6231 1, memory_order_relaxed
);
6234 case DPLANE_OP_TC_QDISC_INSTALL
:
6235 case DPLANE_OP_TC_QDISC_UNINSTALL
:
6236 case DPLANE_OP_TC_CLASS_ADD
:
6237 case DPLANE_OP_TC_CLASS_DELETE
:
6238 case DPLANE_OP_TC_CLASS_UPDATE
:
6239 case DPLANE_OP_TC_FILTER_ADD
:
6240 case DPLANE_OP_TC_FILTER_DELETE
:
6241 case DPLANE_OP_TC_FILTER_UPDATE
:
6242 if (res
!= ZEBRA_DPLANE_REQUEST_SUCCESS
)
6243 atomic_fetch_add_explicit(&zdplane_info
.dg_tcs_errors
,
6244 1, memory_order_relaxed
);
6247 /* Ignore 'notifications' - no-op */
6248 case DPLANE_OP_SYS_ROUTE_ADD
:
6249 case DPLANE_OP_SYS_ROUTE_DELETE
:
6250 case DPLANE_OP_ROUTE_NOTIFY
:
6251 case DPLANE_OP_LSP_NOTIFY
:
6252 case DPLANE_OP_BR_PORT_UPDATE
:
6255 /* TODO -- error counters for incoming events? */
6256 case DPLANE_OP_INTF_ADDR_ADD
:
6257 case DPLANE_OP_INTF_ADDR_DEL
:
6258 case DPLANE_OP_INTF_NETCONFIG
:
6261 case DPLANE_OP_NONE
:
6262 if (res
!= ZEBRA_DPLANE_REQUEST_SUCCESS
)
6263 atomic_fetch_add_explicit(&zdplane_info
.dg_other_errors
,
6264 1, memory_order_relaxed
);
6269 static void kernel_dplane_process_iptable(struct zebra_dplane_provider
*prov
,
6270 struct zebra_dplane_ctx
*ctx
)
6272 zebra_pbr_process_iptable(ctx
);
6273 dplane_provider_enqueue_out_ctx(prov
, ctx
);
6276 static void kernel_dplane_process_ipset(struct zebra_dplane_provider
*prov
,
6277 struct zebra_dplane_ctx
*ctx
)
6279 zebra_pbr_process_ipset(ctx
);
6280 dplane_provider_enqueue_out_ctx(prov
, ctx
);
6284 kernel_dplane_process_ipset_entry(struct zebra_dplane_provider
*prov
,
6285 struct zebra_dplane_ctx
*ctx
)
6287 zebra_pbr_process_ipset_entry(ctx
);
6288 dplane_provider_enqueue_out_ctx(prov
, ctx
);
6291 void dplane_rib_add_multipath(afi_t afi
, safi_t safi
, struct prefix
*p
,
6292 struct prefix_ipv6
*src_p
, struct route_entry
*re
,
6293 struct nexthop_group
*ng
, int startup
,
6294 struct zebra_dplane_ctx
*ctx
)
6297 rib_add_multipath(afi
, safi
, p
, src_p
, re
, ng
, startup
);
6299 dplane_ctx_route_init_basic(ctx
, dplane_ctx_get_op(ctx
), re
, p
,
6301 dplane_provider_enqueue_to_zebra(ctx
);
6306 * Kernel provider callback
6308 static int kernel_dplane_process_func(struct zebra_dplane_provider
*prov
)
6310 struct zebra_dplane_ctx
*ctx
;
6311 struct dplane_ctx_list_head work_list
;
6314 dplane_ctx_list_init(&work_list
);
6316 limit
= dplane_provider_get_work_limit(prov
);
6318 if (IS_ZEBRA_DEBUG_DPLANE_DETAIL
)
6319 zlog_debug("dplane provider '%s': processing",
6320 dplane_provider_get_name(prov
));
6322 for (counter
= 0; counter
< limit
; counter
++) {
6323 ctx
= dplane_provider_dequeue_in_ctx(prov
);
6326 if (IS_ZEBRA_DEBUG_DPLANE_DETAIL
)
6327 kernel_dplane_log_detail(ctx
);
6329 if ((dplane_ctx_get_op(ctx
) == DPLANE_OP_IPTABLE_ADD
6330 || dplane_ctx_get_op(ctx
) == DPLANE_OP_IPTABLE_DELETE
))
6331 kernel_dplane_process_iptable(prov
, ctx
);
6332 else if ((dplane_ctx_get_op(ctx
) == DPLANE_OP_IPSET_ADD
6333 || dplane_ctx_get_op(ctx
) == DPLANE_OP_IPSET_DELETE
))
6334 kernel_dplane_process_ipset(prov
, ctx
);
6335 else if ((dplane_ctx_get_op(ctx
) == DPLANE_OP_IPSET_ENTRY_ADD
6336 || dplane_ctx_get_op(ctx
)
6337 == DPLANE_OP_IPSET_ENTRY_DELETE
))
6338 kernel_dplane_process_ipset_entry(prov
, ctx
);
6340 dplane_ctx_list_add_tail(&work_list
, ctx
);
6343 kernel_update_multi(&work_list
);
6345 while ((ctx
= dplane_ctx_list_pop(&work_list
)) != NULL
) {
6346 kernel_dplane_handle_result(ctx
);
6348 dplane_provider_enqueue_out_ctx(prov
, ctx
);
6351 /* Ensure that we'll run the work loop again if there's still
6354 if (counter
>= limit
) {
6355 if (IS_ZEBRA_DEBUG_DPLANE_DETAIL
)
6356 zlog_debug("dplane provider '%s' reached max updates %d",
6357 dplane_provider_get_name(prov
), counter
);
6359 atomic_fetch_add_explicit(&zdplane_info
.dg_update_yields
,
6360 1, memory_order_relaxed
);
6362 dplane_provider_work_ready();
6368 #ifdef DPLANE_TEST_PROVIDER
6371 * Test dataplane provider plugin
6375 * Test provider process callback
6377 static int test_dplane_process_func(struct zebra_dplane_provider
*prov
)
6379 struct zebra_dplane_ctx
*ctx
;
6382 /* Just moving from 'in' queue to 'out' queue */
6384 if (IS_ZEBRA_DEBUG_DPLANE_DETAIL
)
6385 zlog_debug("dplane provider '%s': processing",
6386 dplane_provider_get_name(prov
));
6388 limit
= dplane_provider_get_work_limit(prov
);
6390 for (counter
= 0; counter
< limit
; counter
++) {
6391 ctx
= dplane_provider_dequeue_in_ctx(prov
);
6395 if (IS_ZEBRA_DEBUG_DPLANE_DETAIL
)
6396 zlog_debug("dplane provider '%s': op %s",
6397 dplane_provider_get_name(prov
),
6398 dplane_op2str(dplane_ctx_get_op(ctx
)));
6400 dplane_ctx_set_status(ctx
, ZEBRA_DPLANE_REQUEST_SUCCESS
);
6402 dplane_provider_enqueue_out_ctx(prov
, ctx
);
6405 if (IS_ZEBRA_DEBUG_DPLANE_DETAIL
)
6406 zlog_debug("dplane provider '%s': processed %d",
6407 dplane_provider_get_name(prov
), counter
);
6409 /* Ensure that we'll run the work loop again if there's still
6412 if (counter
>= limit
)
6413 dplane_provider_work_ready();
6419 * Test provider shutdown/fini callback
6421 static int test_dplane_shutdown_func(struct zebra_dplane_provider
*prov
,
6424 if (IS_ZEBRA_DEBUG_DPLANE
)
6425 zlog_debug("dplane provider '%s': %sshutdown",
6426 dplane_provider_get_name(prov
),
6427 early
? "early " : "");
6431 #endif /* DPLANE_TEST_PROVIDER */
6434 * Register default kernel provider
6436 static void dplane_provider_init(void)
6440 ret
= dplane_provider_register("Kernel",
6442 DPLANE_PROV_FLAGS_DEFAULT
, NULL
,
6443 kernel_dplane_process_func
,
6448 zlog_err("Unable to register kernel dplane provider: %d",
6451 #ifdef DPLANE_TEST_PROVIDER
6452 /* Optional test provider ... */
6453 ret
= dplane_provider_register("Test",
6454 DPLANE_PRIO_PRE_KERNEL
,
6455 DPLANE_PROV_FLAGS_DEFAULT
, NULL
,
6456 test_dplane_process_func
,
6457 test_dplane_shutdown_func
,
6458 NULL
/* data */, NULL
);
6461 zlog_err("Unable to register test dplane provider: %d",
6463 #endif /* DPLANE_TEST_PROVIDER */
6467 * Allow zebra code to walk the queue of pending contexts, evaluate each one
6468 * using a callback function. If the function returns 'true', the context
6469 * will be dequeued and freed without being processed.
6471 int dplane_clean_ctx_queue(bool (*context_cb
)(struct zebra_dplane_ctx
*ctx
,
6472 void *arg
), void *val
)
6474 struct zebra_dplane_ctx
*ctx
;
6475 struct dplane_ctx_list_head work_list
;
6477 dplane_ctx_list_init(&work_list
);
6479 if (context_cb
== NULL
)
6482 /* Walk the pending context queue under the dplane lock. */
6485 frr_each_safe (dplane_ctx_list
, &zdplane_info
.dg_update_list
, ctx
) {
6486 if (context_cb(ctx
, val
)) {
6487 dplane_ctx_list_del(&zdplane_info
.dg_update_list
, ctx
);
6488 dplane_ctx_list_add_tail(&work_list
, ctx
);
6494 /* Now free any contexts selected by the caller, without holding
6497 while ((ctx
= dplane_ctx_list_pop(&work_list
)) != NULL
)
6498 dplane_ctx_fini(&ctx
);
6503 /* Indicates zebra shutdown/exit is in progress. Some operations may be
6504 * simplified or skipped during shutdown processing.
6506 bool dplane_is_in_shutdown(void)
6508 return zdplane_info
.dg_is_shutdown
;
6512 * Enable collection of extra info about interfaces in route updates.
6514 void dplane_enable_intf_extra_info(void)
6516 dplane_collect_extra_intf_info
= true;
6520 * Early or pre-shutdown, de-init notification api. This runs pretty
6521 * early during zebra shutdown, as a signal to stop new work and prepare
6522 * for updates generated by shutdown/cleanup activity, as zebra tries to
6523 * remove everything it's responsible for.
6524 * NB: This runs in the main zebra pthread context.
6526 void zebra_dplane_pre_finish(void)
6528 struct zebra_dplane_provider
*prov
;
6530 if (IS_ZEBRA_DEBUG_DPLANE
)
6531 zlog_debug("Zebra dataplane pre-finish called");
6533 zdplane_info
.dg_is_shutdown
= true;
6535 /* Notify provider(s) of pending shutdown. */
6536 frr_each (dplane_prov_list
, &zdplane_info
.dg_providers
, prov
) {
6537 if (prov
->dp_fini
== NULL
)
6540 prov
->dp_fini(prov
, true /* early */);
6545 * Utility to determine whether work remains enqueued within the dplane;
6546 * used during system shutdown processing.
6548 static bool dplane_work_pending(void)
6551 struct zebra_dplane_ctx
*ctx
;
6552 struct zebra_dplane_provider
*prov
;
6554 /* TODO -- just checking incoming/pending work for now, must check
6559 ctx
= dplane_ctx_list_first(&zdplane_info
.dg_update_list
);
6560 prov
= dplane_prov_list_first(&zdplane_info
.dg_providers
);
6569 dplane_provider_lock(prov
);
6571 ctx
= dplane_ctx_list_first(&(prov
->dp_ctx_in_list
));
6573 ctx
= dplane_ctx_list_first(&(prov
->dp_ctx_out_list
));
6575 dplane_provider_unlock(prov
);
6580 prov
= dplane_prov_list_next(&zdplane_info
.dg_providers
, prov
);
6590 * Shutdown-time intermediate callback, used to determine when all pending
6591 * in-flight updates are done. If there's still work to do, reschedules itself.
6592 * If all work is done, schedules an event to the main zebra thread for
6593 * final zebra shutdown.
6594 * This runs in the dplane pthread context.
6596 static void dplane_check_shutdown_status(struct thread
*event
)
6598 struct dplane_zns_info
*zi
;
6600 if (IS_ZEBRA_DEBUG_DPLANE
)
6601 zlog_debug("Zebra dataplane shutdown status check called");
6603 /* Remove any zns info entries as we stop the dplane pthread. */
6604 frr_each_safe (zns_info_list
, &zdplane_info
.dg_zns_list
, zi
) {
6605 zns_info_list_del(&zdplane_info
.dg_zns_list
, zi
);
6607 if (zdplane_info
.dg_master
) {
6608 THREAD_OFF(zi
->t_read
);
6609 THREAD_OFF(zi
->t_request
);
6612 XFREE(MTYPE_DP_NS
, zi
);
6615 if (dplane_work_pending()) {
6616 /* Reschedule dplane check on a short timer */
6617 thread_add_timer_msec(zdplane_info
.dg_master
,
6618 dplane_check_shutdown_status
,
6620 &zdplane_info
.dg_t_shutdown_check
);
6622 /* TODO - give up and stop waiting after a short time? */
6625 /* We appear to be done - schedule a final callback event
6626 * for the zebra main pthread.
6628 thread_add_event(zrouter
.master
, zebra_finalize
, NULL
, 0, NULL
);
6633 * Shutdown, de-init api. This runs pretty late during shutdown,
6634 * after zebra has tried to free/remove/uninstall all routes during shutdown.
6635 * At this point, dplane work may still remain to be done, so we can't just
6636 * blindly terminate. If there's still work to do, we'll periodically check
6637 * and when done, we'll enqueue a task to the zebra main thread for final
6638 * termination processing.
6640 * NB: This runs in the main zebra thread context.
6642 void zebra_dplane_finish(void)
6644 if (IS_ZEBRA_DEBUG_DPLANE
)
6645 zlog_debug("Zebra dataplane fini called");
6647 thread_add_event(zdplane_info
.dg_master
,
6648 dplane_check_shutdown_status
, NULL
, 0,
6649 &zdplane_info
.dg_t_shutdown_check
);
6653 * Main dataplane pthread event loop. The thread takes new incoming work
6654 * and offers it to the first provider. It then iterates through the
6655 * providers, taking complete work from each one and offering it
6656 * to the next in order. At each step, a limited number of updates are
6657 * processed during a cycle in order to provide some fairness.
6659 * This loop through the providers is only run once, so that the dataplane
6660 * pthread can look for other pending work - such as i/o work on behalf of
6663 static void dplane_thread_loop(struct thread
*event
)
6665 struct dplane_ctx_list_head work_list
;
6666 struct dplane_ctx_list_head error_list
;
6667 struct zebra_dplane_provider
*prov
;
6668 struct zebra_dplane_ctx
*ctx
;
6669 int limit
, counter
, error_counter
;
6670 uint64_t curr
, high
;
6671 bool reschedule
= false;
6673 /* Capture work limit per cycle */
6674 limit
= zdplane_info
.dg_updates_per_cycle
;
6676 /* Init temporary lists used to move contexts among providers */
6677 dplane_ctx_list_init(&work_list
);
6678 dplane_ctx_list_init(&error_list
);
6682 /* Check for zebra shutdown */
6683 if (!zdplane_info
.dg_run
)
6686 /* Dequeue some incoming work from zebra (if any) onto the temporary
6691 /* Locate initial registered provider */
6692 prov
= dplane_prov_list_first(&zdplane_info
.dg_providers
);
6694 /* Move new work from incoming list to temp list */
6695 for (counter
= 0; counter
< limit
; counter
++) {
6696 ctx
= dplane_ctx_list_pop(&zdplane_info
.dg_update_list
);
6698 ctx
->zd_provider
= prov
->dp_id
;
6700 dplane_ctx_list_add_tail(&work_list
, ctx
);
6708 atomic_fetch_sub_explicit(&zdplane_info
.dg_routes_queued
, counter
,
6709 memory_order_relaxed
);
6711 if (IS_ZEBRA_DEBUG_DPLANE_DETAIL
)
6712 zlog_debug("dplane: incoming new work counter: %d", counter
);
6714 /* Iterate through the registered providers, offering new incoming
6715 * work. If the provider has outgoing work in its queue, take that
6716 * work for the next provider
6720 /* At each iteration, the temporary work list has 'counter'
6723 if (IS_ZEBRA_DEBUG_DPLANE_DETAIL
)
6724 zlog_debug("dplane enqueues %d new work to provider '%s'",
6725 counter
, dplane_provider_get_name(prov
));
6727 /* Capture current provider id in each context; check for
6730 frr_each_safe (dplane_ctx_list
, &work_list
, ctx
) {
6731 if (dplane_ctx_get_status(ctx
) ==
6732 ZEBRA_DPLANE_REQUEST_SUCCESS
) {
6733 ctx
->zd_provider
= prov
->dp_id
;
6736 * TODO -- improve error-handling: recirc
6737 * errors backwards so that providers can
6738 * 'undo' their work (if they want to)
6741 /* Move to error list; will be returned
6744 dplane_ctx_list_del(&work_list
, ctx
);
6745 dplane_ctx_list_add_tail(&error_list
, ctx
);
6750 /* Enqueue new work to the provider */
6751 dplane_provider_lock(prov
);
6753 while ((ctx
= dplane_ctx_list_pop(&work_list
)) != NULL
)
6754 dplane_ctx_list_add_tail(&(prov
->dp_ctx_in_list
), ctx
);
6756 atomic_fetch_add_explicit(&prov
->dp_in_counter
, counter
,
6757 memory_order_relaxed
);
6758 atomic_fetch_add_explicit(&prov
->dp_in_queued
, counter
,
6759 memory_order_relaxed
);
6760 curr
= atomic_load_explicit(&prov
->dp_in_queued
,
6761 memory_order_relaxed
);
6762 high
= atomic_load_explicit(&prov
->dp_in_max
,
6763 memory_order_relaxed
);
6765 atomic_store_explicit(&prov
->dp_in_max
, curr
,
6766 memory_order_relaxed
);
6768 dplane_provider_unlock(prov
);
6770 /* Reset the temp list (though the 'concat' may have done this
6771 * already), and the counter
6773 dplane_ctx_list_init(&work_list
);
6776 /* Call into the provider code. Note that this is
6777 * unconditional: we offer to do work even if we don't enqueue
6780 (*prov
->dp_fp
)(prov
);
6782 /* Check for zebra shutdown */
6783 if (!zdplane_info
.dg_run
)
6786 /* Dequeue completed work from the provider */
6787 dplane_provider_lock(prov
);
6789 while (counter
< limit
) {
6790 ctx
= dplane_ctx_list_pop(&(prov
->dp_ctx_out_list
));
6792 dplane_ctx_list_add_tail(&work_list
, ctx
);
6798 dplane_provider_unlock(prov
);
6800 if (counter
>= limit
)
6803 if (IS_ZEBRA_DEBUG_DPLANE_DETAIL
)
6804 zlog_debug("dplane dequeues %d completed work from provider %s",
6805 counter
, dplane_provider_get_name(prov
));
6807 /* Locate next provider */
6808 prov
= dplane_prov_list_next(&zdplane_info
.dg_providers
, prov
);
6812 * We hit the work limit while processing at least one provider's
6813 * output queue - ensure we come back and finish it.
6816 dplane_provider_work_ready();
6818 /* After all providers have been serviced, enqueue any completed
6819 * work and any errors back to zebra so it can process the results.
6821 if (IS_ZEBRA_DEBUG_DPLANE_DETAIL
)
6822 zlog_debug("dplane has %d completed, %d errors, for zebra main",
6823 counter
, error_counter
);
6826 * Hand lists through the api to zebra main,
6827 * to reduce the number of lock/unlock cycles
6830 /* Call through to zebra main */
6831 (zdplane_info
.dg_results_cb
)(&error_list
);
6833 dplane_ctx_list_init(&error_list
);
6835 /* Call through to zebra main */
6836 (zdplane_info
.dg_results_cb
)(&work_list
);
6838 dplane_ctx_list_init(&work_list
);
6842 * Final phase of shutdown, after all work enqueued to dplane has been
6843 * processed. This is called from the zebra main pthread context.
6845 void zebra_dplane_shutdown(void)
6847 struct zebra_dplane_provider
*dp
;
6849 if (IS_ZEBRA_DEBUG_DPLANE
)
6850 zlog_debug("Zebra dataplane shutdown called");
6852 /* Stop dplane thread, if it's running */
6854 zdplane_info
.dg_run
= false;
6856 if (zdplane_info
.dg_t_update
)
6857 thread_cancel_async(zdplane_info
.dg_t_update
->master
,
6858 &zdplane_info
.dg_t_update
, NULL
);
6860 frr_pthread_stop(zdplane_info
.dg_pthread
, NULL
);
6862 /* Destroy pthread */
6863 frr_pthread_destroy(zdplane_info
.dg_pthread
);
6864 zdplane_info
.dg_pthread
= NULL
;
6865 zdplane_info
.dg_master
= NULL
;
6867 /* Notify provider(s) of final shutdown.
6868 * Note that this call is in the main pthread, so providers must
6869 * be prepared for that.
6871 frr_each (dplane_prov_list
, &zdplane_info
.dg_providers
, dp
) {
6872 if (dp
->dp_fini
== NULL
)
6875 dp
->dp_fini(dp
, false);
6878 /* TODO -- Clean-up provider objects */
6880 /* TODO -- Clean queue(s), free memory */
6884 * Initialize the dataplane module during startup, internal/private version
6886 static void zebra_dplane_init_internal(void)
6888 memset(&zdplane_info
, 0, sizeof(zdplane_info
));
6890 pthread_mutex_init(&zdplane_info
.dg_mutex
, NULL
);
6892 dplane_prov_list_init(&zdplane_info
.dg_providers
);
6894 dplane_ctx_list_init(&zdplane_info
.dg_update_list
);
6895 zns_info_list_init(&zdplane_info
.dg_zns_list
);
6897 zdplane_info
.dg_updates_per_cycle
= DPLANE_DEFAULT_NEW_WORK
;
6899 zdplane_info
.dg_max_queued_updates
= DPLANE_DEFAULT_MAX_QUEUED
;
6901 /* Register default kernel 'provider' during init */
6902 dplane_provider_init();
6906 * Start the dataplane pthread. This step needs to be run later than the
6907 * 'init' step, in case zebra has fork-ed.
6909 void zebra_dplane_start(void)
6911 struct dplane_zns_info
*zi
;
6912 struct zebra_dplane_provider
*prov
;
6913 struct frr_pthread_attr pattr
= {
6914 .start
= frr_pthread_attr_default
.start
,
6915 .stop
= frr_pthread_attr_default
.stop
6918 /* Start dataplane pthread */
6920 zdplane_info
.dg_pthread
= frr_pthread_new(&pattr
, "Zebra dplane thread",
6923 zdplane_info
.dg_master
= zdplane_info
.dg_pthread
->master
;
6925 zdplane_info
.dg_run
= true;
6927 /* Enqueue an initial event for the dataplane pthread */
6928 thread_add_event(zdplane_info
.dg_master
, dplane_thread_loop
, NULL
, 0,
6929 &zdplane_info
.dg_t_update
);
6931 /* Enqueue requests and reads if necessary */
6932 frr_each (zns_info_list
, &zdplane_info
.dg_zns_list
, zi
) {
6933 #if defined(HAVE_NETLINK)
6934 thread_add_read(zdplane_info
.dg_master
, dplane_incoming_read
,
6935 zi
, zi
->info
.sock
, &zi
->t_read
);
6936 dplane_kernel_info_request(zi
);
6940 /* Call start callbacks for registered providers */
6943 prov
= dplane_prov_list_first(&zdplane_info
.dg_providers
);
6949 (prov
->dp_start
)(prov
);
6951 /* Locate next provider */
6952 prov
= dplane_prov_list_next(&zdplane_info
.dg_providers
, prov
);
6955 frr_pthread_run(zdplane_info
.dg_pthread
, NULL
);
6959 * Initialize the dataplane module at startup; called by zebra rib_init()
6961 void zebra_dplane_init(int (*results_fp
)(struct dplane_ctx_list_head
*))
6963 zebra_dplane_init_internal();
6964 zdplane_info
.dg_results_cb
= results_fp
;