summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMark Stapp <mjs@cisco.com>2024-04-05 13:14:48 -0400
committerMark Stapp <mjs@cisco.com>2024-04-09 08:59:13 -0400
commitf090079390dd8e1aaea288ec1b69f8e8bb22de1a (patch)
treedc93d8e4cbdef00e40c5b391b0a5d7080ccabd88
parent8cfa3b57e905ea2d5536c0c44b70a44cb11f4bb2 (diff)
lib: add simple generic version helpers
Add some simple helpers for generic major+minor+sub version values. Signed-off-by: Mark Stapp <mjs@cisco.com>
-rw-r--r--lib/libfrr.c9
-rw-r--r--lib/libfrr.h11
2 files changed, 20 insertions, 0 deletions
diff --git a/lib/libfrr.c b/lib/libfrr.c
index c5c7e7837a..03025328b7 100644
--- a/lib/libfrr.c
+++ b/lib/libfrr.c
@@ -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;
+}
diff --git a/lib/libfrr.h b/lib/libfrr.h
index ee436d9f8f..77d70448a9 100644
--- a/lib/libfrr.h
+++ b/lib/libfrr.h
@@ -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