Skip to content

Commit

Permalink
Merge pull request FRRouting#15688 from mjstapp/dplane_api_version
Browse files Browse the repository at this point in the history
lib, zebra: Add a version scheme for the dataplane API
  • Loading branch information
Jafaral authored Apr 12, 2024
2 parents 5139ce8 + f8cab99 commit 692f916
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 0 deletions.
15 changes: 15 additions & 0 deletions doc/developer/zebra.rst
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,21 @@ Zebra Protocol Commands

The definitions of zebra protocol commands can be found at ``lib/zclient.h``.


Zebra Dataplane
===============

The zebra dataplane subsystem provides a framework for FIB
programming. Zebra uses the dataplane to program the local kernel as
it makes changes to objects such as IP routes, MPLS LSPs, and
interface IP addresses. The dataplane runs in its own pthread, in
order to off-load work from the main zebra pthread.

The zebra dataplane API is versioned; the version number must be
updated along with API changes. Plugins can test the current version
number and confirm that they are compatible with the current version.


Dataplane batching
==================

Expand Down
9 changes: 9 additions & 0 deletions lib/libfrr.c
Original file line number Diff line number Diff line change
Expand Up @@ -1450,3 +1450,12 @@ void _libfrr_version(void)
write(1, banner, sizeof(banner) - 1);
_exit(0);
}

/* Render simple version tuple to string */
const char *frr_vers2str(uint32_t version, char *buf, int buflen)
{
snprintf(buf, buflen, "%d.%d.%d", MAJOR_FRRVERSION(version),
MINOR_FRRVERSION(version), SUB_FRRVERSION(version));

return buf;
}
11 changes: 11 additions & 0 deletions lib/libfrr.h
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,17 @@ extern bool frr_is_after_fork;

extern bool debug_memstats_at_exit;

/*
* Version numbering: MAJOR (8) | MINOR (16) | SUB (8)
*/
#define MAKE_FRRVERSION(maj, min, sub) \
((((maj) & 0xff) << 24) | (((min) & 0xffff) << 8) | ((sub) & 0xff))
#define MAJOR_FRRVERSION(v) (((v) >> 24) & 0xff)
#define MINOR_FRRVERSION(v) (((v) >> 8) & 0xffff)
#define SUB_FRRVERSION(v) ((v) & 0xff)

const char *frr_vers2str(uint32_t version, char *buf, int buflen);

#ifdef __cplusplus
}
#endif
Expand Down
13 changes: 13 additions & 0 deletions zebra/zebra_dplane.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,13 @@ DEFINE_MTYPE_STATIC(ZEBRA, DP_NS, "DPlane NSes");
# define AOK 0
#endif

/*
* Dataplane API version. This must be updated when any incompatible changes
* are made. The minor version (at least) should be updated when new APIs
* are introduced.
*/
static uint32_t zdplane_version = MAKE_FRRVERSION(2, 0, 0);

/* Control for collection of extra interface info with route updates; a plugin
* can enable the extra info via a dplane api.
*/
Expand Down Expand Up @@ -664,6 +671,12 @@ neigh_update_internal(enum dplane_op_e op, const struct interface *ifp,
* Public APIs
*/

/* Access the dplane API version */
uint32_t zebra_dplane_get_version(void)
{
return zdplane_version;
}

/* Obtain thread_master for dataplane thread */
struct event_loop *dplane_get_thread_master(void)
{
Expand Down
7 changes: 7 additions & 0 deletions zebra/zebra_dplane.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@
extern "C" {
#endif

/* Retrieve the dataplane API version number; see libfrr.h to decode major,
* minor, sub version values.
* Plugins should pay attention to the major version number, at least, to
* be able to detect API changes that may not be backward-compatible.
*/
uint32_t zebra_dplane_get_version(void);

/* Key netlink info from zebra ns */
struct zebra_dplane_info {
ns_id_t ns_id;
Expand Down

0 comments on commit 692f916

Please sign in to comment.