]> git.puffer.fish Git - mirror/frr.git/commitdiff
lib: add simple generic version helpers
authorMark Stapp <mjs@cisco.com>
Fri, 5 Apr 2024 17:14:48 +0000 (13:14 -0400)
committerMark Stapp <mjs@cisco.com>
Tue, 9 Apr 2024 12:59:13 +0000 (08:59 -0400)
Add some simple helpers for generic major+minor+sub version
values.

Signed-off-by: Mark Stapp <mjs@cisco.com>
lib/libfrr.c
lib/libfrr.h

index c5c7e7837a79985db75e81634a6ebddecda6841d..03025328b73b0d2a302835b824cc3f81e4f0b92b 100644 (file)
@@ -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;
+}
index ee436d9f8f88cc5ae93c975456dd70beb52d3bfe..77d70448a9a10c5ed0c8d2c0311c6ab022af1149 100644 (file)
@@ -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