]> git.proxmox.com Git - mirror_frr.git/blobdiff - zebra/zebra_dplane.h
isisd: implement the 'if-state-change' notification
[mirror_frr.git] / zebra / zebra_dplane.h
index fcc70e99bf63c9018b3dafe8023171589388eb1c..b6b2e64600ff83bf79d250cf3b27f0d46b42df09 100644 (file)
@@ -29,7 +29,6 @@
 #include "zebra/rib.h"
 #include "zebra/zserv.h"
 
-
 /* Key netlink info from zebra ns */
 struct zebra_dplane_info {
        ns_id_t ns_id;
@@ -94,7 +93,7 @@ enum zebra_dplane_result {
 /*
  * Enqueue a route install or update for the dataplane.
  */
-typedef enum {
+enum dplane_op_e {
        DPLANE_OP_NONE = 0,
 
        /* Route update */
@@ -102,75 +101,100 @@ typedef enum {
        DPLANE_OP_ROUTE_UPDATE,
        DPLANE_OP_ROUTE_DELETE,
 
-} dplane_op_e;
+};
 
 /*
- * Opaque context block used to exchange info between the main zebra
+ * The dataplane context struct is used to exchange info between the main zebra
  * context and the dataplane module(s). If these are two independent pthreads,
  * they cannot share existing global data structures safely.
  */
-typedef struct zebra_dplane_ctx_s * dplane_ctx_h;
 
 /* Define a tailq list type for context blocks. The list is exposed/public,
  * but the internal linkage in the context struct is private, so there
  * are accessor apis that support enqueue and dequeue.
  */
-TAILQ_HEAD(dplane_ctx_q_s, zebra_dplane_ctx_s);
-
-/*
- * Allocate an opaque context block, currently for a route update.
- */
-dplane_ctx_h dplane_ctx_alloc(void);
+TAILQ_HEAD(dplane_ctx_q, zebra_dplane_ctx);
 
 /* Return a dataplane results context block after use; the caller's pointer will
  * be cleared.
  */
-void dplane_ctx_fini(dplane_ctx_h *pctx);
+void dplane_ctx_fini(struct zebra_dplane_ctx **pctx);
 
-/* Enqueue a context block to caller's tailq. This just exists so that the
+/* Enqueue a context block to caller's tailq. This exists so that the
  * context struct can remain opaque.
  */
-void dplane_ctx_enqueue_tail(struct dplane_ctx_q_s *q, dplane_ctx_h ctx);
+void dplane_ctx_enqueue_tail(struct dplane_ctx_q *q,
+                            const struct zebra_dplane_ctx *ctx);
+
+/* Append a list of context blocks to another list - again, just keeping
+ * the context struct opaque.
+ */
+void dplane_ctx_list_append(struct dplane_ctx_q *to_list,
+                           struct dplane_ctx_q *from_list);
 
 /* Dequeue a context block from the head of caller's tailq */
-void dplane_ctx_dequeue(struct dplane_ctx_q_s *q, dplane_ctx_h *ctxp);
+struct zebra_dplane_ctx *dplane_ctx_dequeue(struct dplane_ctx_q *q);
 
 /*
  * Accessors for information from the context object
  */
-enum zebra_dplane_result dplane_ctx_get_status(const dplane_ctx_h ctx);
+enum zebra_dplane_result dplane_ctx_get_status(
+       const struct zebra_dplane_ctx *ctx);
+void dplane_ctx_set_status(struct zebra_dplane_ctx *ctx,
+                          enum zebra_dplane_result status);
+const char *dplane_res2str(enum zebra_dplane_result res);
 
-dplane_op_e dplane_ctx_get_op(const dplane_ctx_h ctx);
-const char *dplane_op2str(dplane_op_e op);
+enum dplane_op_e dplane_ctx_get_op(const struct zebra_dplane_ctx *ctx);
+const char *dplane_op2str(enum dplane_op_e op);
 
-const struct prefix *dplane_ctx_get_dest(const dplane_ctx_h ctx);
+const struct prefix *dplane_ctx_get_dest(const struct zebra_dplane_ctx *ctx);
 
-/* Source prefix is a little special - use convention like prefix-len of zero
- * and all-zeroes address means "no src prefix"? or ... return NULL in that case?
- */
-const struct prefix *dplane_ctx_get_src(const dplane_ctx_h ctx);
+/* Retrieve last/current provider id */
+uint32_t dplane_ctx_get_provider(const struct zebra_dplane_ctx *ctx);
 
-bool dplane_ctx_is_update(const dplane_ctx_h ctx);
-uint32_t dplane_ctx_get_seq(const dplane_ctx_h ctx);
-uint32_t dplane_ctx_get_old_seq(const dplane_ctx_h ctx);
-vrf_id_t dplane_ctx_get_vrf(const dplane_ctx_h ctx);
-int dplane_ctx_get_type(const dplane_ctx_h ctx);
-int dplane_ctx_get_old_type(const dplane_ctx_h ctx);
-afi_t dplane_ctx_get_afi(const dplane_ctx_h ctx);
-safi_t dplane_ctx_get_safi(const dplane_ctx_h ctx);
-uint32_t dplane_ctx_get_table(const dplane_ctx_h ctx);
-route_tag_t dplane_ctx_get_tag(const dplane_ctx_h ctx);
-route_tag_t dplane_ctx_get_old_tag(const dplane_ctx_h ctx);
-uint16_t dplane_ctx_get_instance(const dplane_ctx_h ctx);
-uint16_t dplane_ctx_get_old_instance(const dplane_ctx_h ctx);
-uint32_t dplane_ctx_get_metric(const dplane_ctx_h ctx);
-uint32_t dplane_ctx_get_mtu(const dplane_ctx_h ctx);
-uint32_t dplane_ctx_get_nh_mtu(const dplane_ctx_h ctx);
-uint8_t dplane_ctx_get_distance(const dplane_ctx_h ctx);
-uint8_t dplane_ctx_get_old_distance(const dplane_ctx_h ctx);
+/* Providers running before the kernel can control whether a kernel
+ * update should be done.
+ */
+void dplane_ctx_set_skip_kernel(struct zebra_dplane_ctx *ctx);
+bool dplane_ctx_is_skip_kernel(const struct zebra_dplane_ctx *ctx);
 
-const struct nexthop_group *dplane_ctx_get_ng(const dplane_ctx_h ctx);
-const struct zebra_dplane_info *dplane_ctx_get_ns(const dplane_ctx_h ctx);
+/* Source prefix is a little special - use convention to return NULL
+ * to mean "no src prefix"
+ */
+const struct prefix *dplane_ctx_get_src(const struct zebra_dplane_ctx *ctx);
+
+bool dplane_ctx_is_update(const struct zebra_dplane_ctx *ctx);
+uint32_t dplane_ctx_get_seq(const struct zebra_dplane_ctx *ctx);
+uint32_t dplane_ctx_get_old_seq(const struct zebra_dplane_ctx *ctx);
+vrf_id_t dplane_ctx_get_vrf(const struct zebra_dplane_ctx *ctx);
+int dplane_ctx_get_type(const struct zebra_dplane_ctx *ctx);
+int dplane_ctx_get_old_type(const struct zebra_dplane_ctx *ctx);
+afi_t dplane_ctx_get_afi(const struct zebra_dplane_ctx *ctx);
+safi_t dplane_ctx_get_safi(const struct zebra_dplane_ctx *ctx);
+uint32_t dplane_ctx_get_table(const struct zebra_dplane_ctx *ctx);
+route_tag_t dplane_ctx_get_tag(const struct zebra_dplane_ctx *ctx);
+route_tag_t dplane_ctx_get_old_tag(const struct zebra_dplane_ctx *ctx);
+uint16_t dplane_ctx_get_instance(const struct zebra_dplane_ctx *ctx);
+uint16_t dplane_ctx_get_old_instance(const struct zebra_dplane_ctx *ctx);
+uint32_t dplane_ctx_get_metric(const struct zebra_dplane_ctx *ctx);
+uint32_t dplane_ctx_get_old_metric(const struct zebra_dplane_ctx *ctx);
+uint32_t dplane_ctx_get_mtu(const struct zebra_dplane_ctx *ctx);
+uint32_t dplane_ctx_get_nh_mtu(const struct zebra_dplane_ctx *ctx);
+uint8_t dplane_ctx_get_distance(const struct zebra_dplane_ctx *ctx);
+uint8_t dplane_ctx_get_old_distance(const struct zebra_dplane_ctx *ctx);
+
+const struct nexthop_group *dplane_ctx_get_ng(
+       const struct zebra_dplane_ctx *ctx);
+const struct nexthop_group *dplane_ctx_get_old_ng(
+       const struct zebra_dplane_ctx *ctx);
+
+const struct zebra_dplane_info *dplane_ctx_get_ns(
+       const struct zebra_dplane_ctx *ctx);
+
+/* Indicates zebra shutdown/exit is in progress. Some operations may be
+ * simplified or skipped during shutdown processing.
+ */
+bool dplane_is_in_shutdown(void);
 
 /*
  * Enqueue route change operations for the dataplane.
@@ -185,9 +209,31 @@ enum zebra_dplane_result dplane_route_update(struct route_node *rn,
 enum zebra_dplane_result dplane_route_delete(struct route_node *rn,
                                             struct route_entry *re);
 
-/* Opaque handle to a dataplane provider plugin */
-typedef struct zebra_dplane_provider_s *dplane_provider_h;
+/* Retrieve the limit on the number of pending, unprocessed updates. */
+uint32_t dplane_get_in_queue_limit(void);
+
+/* Configure limit on the number of pending, queued updates. If 'unset', reset
+ * to default value.
+ */
+void dplane_set_in_queue_limit(uint32_t limit, bool set);
+
+/* Retrieve the current queue depth of incoming, unprocessed updates */
+uint32_t dplane_get_in_queue_len(void);
+
+/*
+ * Vty/cli apis
+ */
+int dplane_show_helper(struct vty *vty, bool detailed);
+int dplane_show_provs_helper(struct vty *vty, bool detailed);
+
+
+/*
+ * Dataplane providers: modules that process or consume dataplane events.
+ */
+
+struct zebra_dplane_provider;
 
+/* Support string name for a dataplane provider */
 #define DPLANE_PROVIDER_NAMELEN 64
 
 /* Priority or ordering values for providers. The idea is that there may be
@@ -195,38 +241,114 @@ typedef struct zebra_dplane_provider_s *dplane_provider_h;
  * followed by the kernel, followed by some post-processing step (such as
  * the fpm output stream.)
  */
-typedef enum {
+enum dplane_provider_prio {
        DPLANE_PRIO_NONE = 0,
        DPLANE_PRIO_PREPROCESS,
        DPLANE_PRIO_PRE_KERNEL,
        DPLANE_PRIO_KERNEL,
        DPLANE_PRIO_POSTPROCESS,
        DPLANE_PRIO_LAST
-}  dplane_provider_prio_e;
+};
+
+/* Provider's entry-point for incoming work, called in the context of the
+ * dataplane pthread. The dataplane pthread enqueues any new work to the
+ * provider's 'inbound' queue, then calls the callback. The dataplane
+ * then checks the provider's outbound queue.
+ */
+typedef int (*dplane_provider_process_fp)(struct zebra_dplane_provider *prov);
+
+/* Provider's entry-point for shutdown and cleanup. Called with 'early'
+ * during shutdown, to indicate that the dataplane subsystem is allowing
+ * work to move through the providers and finish. When called without 'early',
+ * the provider should release all resources (if it has any allocated).
+ */
+typedef int (*dplane_provider_fini_fp)(struct zebra_dplane_provider *prov,
+                                      bool early);
+
+/* Flags values used during provider registration. */
+#define DPLANE_PROV_FLAGS_DEFAULT  0x0
 
-/* Provider's entry-point to process a context block */
-typedef int (*dplane_provider_process_fp)(dplane_ctx_h ctx);
+/* Provider will be spawning its own worker thread */
+#define DPLANE_PROV_FLAG_THREADED  0x1
 
-/* Provider registration */
+
+/* Provider registration: ordering or priority value, callbacks, and optional
+ * opaque data value.
+ */
 int dplane_provider_register(const char *name,
-                            dplane_provider_prio_e prio,
-                            dplane_provider_process_fp fp);
+                            enum dplane_provider_prio prio,
+                            int flags,
+                            dplane_provider_process_fp fp,
+                            dplane_provider_fini_fp fini_fp,
+                            void *data);
+
+/* Accessors for provider attributes */
+const char *dplane_provider_get_name(const struct zebra_dplane_provider *prov);
+uint32_t dplane_provider_get_id(const struct zebra_dplane_provider *prov);
+void *dplane_provider_get_data(const struct zebra_dplane_provider *prov);
+bool dplane_provider_is_threaded(const struct zebra_dplane_provider *prov);
+
+/* Lock/unlock a provider's mutex - iff the provider was registered with
+ * the THREADED flag.
+ */
+void dplane_provider_lock(struct zebra_dplane_provider *prov);
+void dplane_provider_unlock(struct zebra_dplane_provider *prov);
 
-/*
- * Results are returned to zebra core via a callback
+/* Obtain thread_master for dataplane thread */
+struct thread_master *dplane_get_thread_master(void);
+
+/* Providers should (generally) limit number of updates per work cycle */
+int dplane_provider_get_work_limit(const struct zebra_dplane_provider *prov);
+
+/* Provider api to signal that work/events are available
+ * for the dataplane pthread.
  */
-typedef int (*dplane_results_fp)(const dplane_ctx_h ctx);
+int dplane_provider_work_ready(void);
+
+/* Dequeue, maintain associated counter and locking */
+struct zebra_dplane_ctx *dplane_provider_dequeue_in_ctx(
+       struct zebra_dplane_provider *prov);
+
+/* Dequeue work to a list, maintain counter and locking, return count */
+int dplane_provider_dequeue_in_list(struct zebra_dplane_provider *prov,
+                                   struct dplane_ctx_q *listp);
+
+/* Enqueue, maintain associated counter and locking */
+void dplane_provider_enqueue_out_ctx(struct zebra_dplane_provider *prov,
+                                    struct zebra_dplane_ctx *ctx);
 
 /*
  * Zebra registers a results callback with the dataplane. The callback is
- * called in the dataplane thread context, so the expectation is that the
- * context is queued (or that processing is very limited).
+ * called in the dataplane pthread context, so the expectation is that the
+ * context is queued for the zebra main pthread or that processing
+ * is very limited.
  */
+typedef int (*dplane_results_fp)(struct zebra_dplane_ctx *ctx);
+
 int dplane_results_register(dplane_results_fp fp);
 
 /*
- * Initialize the dataplane modules at zebra startup.
+ * Initialize the dataplane modules at zebra startup. This is currently called
+ * by the rib module.
  */
 void zebra_dplane_init(void);
 
+/*
+ * Start the dataplane pthread. This step needs to be run later than the
+ * 'init' step, in case zebra has fork-ed.
+ */
+void zebra_dplane_start(void);
+
+/* Finalize/cleanup apis, one called early as shutdown is starting,
+ * one called late at the end of zebra shutdown, and then one called
+ * from the zebra main pthread to stop the dplane pthread and
+ * free all resources.
+ *
+ * Zebra expects to try to clean up all vrfs and all routes during
+ * shutdown, so the dplane must be available until very late.
+ */
+void zebra_dplane_pre_finish(void);
+void zebra_dplane_finish(void);
+void zebra_dplane_shutdown(void);
+
 #endif /* _ZEBRA_DPLANE_H */