1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Sample plugin for the FRR zebra dataplane.
5 * Copyright (c) 2019 Volta Networks, Inc.
9 * Should be possible to build this plugin using this sort of command:
11 * gcc -I ~/work/frr/ -I ~/work/frr/lib -I ~/work/frr/zebra \
12 * -g -O0 -o sample_plugin.so -shared -fPIC sample_plugin.c
14 * where 'frr' is a configured and built frr sandbox.
16 * Run zebra with '-M /path/to/sample_plugin.so' to load the module.
19 #include "config.h" /* Include this explicitly */
20 #include "lib/zebra.h"
21 #include "lib/libfrr.h"
22 #include "zebra/zebra_dplane.h"
23 #include "zebra/debug.h"
25 static const char *plugin_name
= "SAMPLE";
27 static struct zebra_dplane_provider
*prov_p
;
30 * Startup/init callback, called from the dataplane.
32 static int sample_start(struct zebra_dplane_provider
*prov
)
34 /* Nothing special to do - we don't allocate anything. */
40 * Shutdown/cleanup callback, called from the dataplane pthread.
42 static int sample_fini(struct zebra_dplane_provider
*prov
, bool early
)
44 /* Nothing special to do. */
49 * Callback from the dataplane to process incoming work; this runs in the
52 static int sample_process(struct zebra_dplane_provider
*prov
)
55 struct zebra_dplane_ctx
*ctx
;
57 limit
= dplane_provider_get_work_limit(prov_p
);
59 /* Respect the configured limit on the amount of work to do in
62 for (counter
= 0; counter
< limit
; counter
++) {
63 ctx
= dplane_provider_dequeue_in_ctx(prov_p
);
67 /* Just set 'success' status and return to the dataplane */
68 dplane_ctx_set_status(ctx
, ZEBRA_DPLANE_REQUEST_SUCCESS
);
69 dplane_provider_enqueue_out_ctx(prov_p
, ctx
);
76 * Init entry point called during zebra startup. This is registered during
79 static int init_sample_plugin(struct event_loop
*tm
)
83 /* Note that we don't use or store the thread_master 'tm'. We
84 * don't use the zebra main pthread: our plugin code will run in
85 * the zebra dataplane pthread context.
88 /* Register the plugin with the dataplane infrastructure. We
89 * register to be called before the kernel, and we register
90 * our init, process work, and shutdown callbacks.
92 ret
= dplane_provider_register(plugin_name
, DPLANE_PRIO_PRE_KERNEL
,
93 DPLANE_PROV_FLAGS_DEFAULT
,
100 if (IS_ZEBRA_DEBUG_DPLANE
)
101 zlog_debug("sample plugin register => %d", ret
);
107 * Base FRR loadable module info: basic info including module entry-point.
109 static int module_init(void)
111 hook_register(frr_late_init
, init_sample_plugin
);
116 .name
= "dplane_sample",
118 .description
= "Dataplane Sample Plugin",