summaryrefslogtreecommitdiff
path: root/proto/bmp/buffer.h
diff options
context:
space:
mode:
authorPawel Maslanka <pmaslank@akamai.com>2021-03-29 22:45:21 +0200
committerOndrej Zajicek <santiago@crfreenet.org>2023-04-16 20:05:15 +0200
commita848dad40aa618e5e24417e4ef46b62c860de679 (patch)
treef14426246ec7f6ef89b0c12460f4979f6b2a047e /proto/bmp/buffer.h
parent9e44ace3928a19560058dc713fcbff3a8bad3b3c (diff)
BMP protocol support
Initial implementation of a basic subset of the BMP (BGP Monitoring Protocol, RFC 7854) from Akamai team. Submitted for further review and improvement.
Diffstat (limited to 'proto/bmp/buffer.h')
-rw-r--r--proto/bmp/buffer.h78
1 files changed, 78 insertions, 0 deletions
diff --git a/proto/bmp/buffer.h b/proto/bmp/buffer.h
new file mode 100644
index 00000000..07eb4e9c
--- /dev/null
+++ b/proto/bmp/buffer.h
@@ -0,0 +1,78 @@
+/*
+ * BIRD -- The BGP Monitoring Protocol (BMP)
+ *
+ * (c) 2020 Akamai Technologies, Inc. (Pawel Maslanka, pmaslank@akamai.com)
+ *
+ * Can be freely distributed and used under the terms of the GNU GPL.
+ */
+
+#ifndef _BIRD_BMP_BUFFER_H_
+#define _BIRD_BMP_BUFFER_H_
+
+#include "proto/bmp/bmp.h"
+#include "proto/bmp/utils.h"
+
+#include <stdlib.h>
+
+#include "lib/resource.h"
+
+buffer
+bmp_buffer_alloc(pool *ppool, const size_t n);
+
+void
+bmp_buffer_free(buffer *buf);
+
+static inline void
+bmp_buffer_flush(buffer *buf)
+{
+ buf->pos = buf->start;
+}
+
+static inline size_t
+bmp_buffer_size(const buffer *buf)
+{
+ return buf->end - buf->start;
+}
+
+static inline size_t
+bmp_buffer_avail(const buffer *buf)
+{
+ return buf->end - buf->pos;
+}
+
+static inline size_t
+bmp_buffer_pos(const buffer *buf)
+{
+ return buf->pos - buf->start;
+}
+
+static inline byte *
+bmp_buffer_data(const buffer *buf)
+{
+ return buf->start;
+}
+
+void
+bmp_buffer_need(buffer *buf, const size_t n);
+
+// Idea for following macros has been taken from |proto/mrt/mrt.c|
+#define BMP_DEFINE_PUT_FUNC(S, T) \
+ static inline void \
+ bmp_put_##S(buffer *b, const T x) \
+ { \
+ bmp_buffer_need(b, sizeof(T)); \
+ put_##S(b->pos, x); \
+ b->pos += sizeof(T); \
+ }
+
+BMP_DEFINE_PUT_FUNC(u8, u8)
+BMP_DEFINE_PUT_FUNC(u16, u16)
+BMP_DEFINE_PUT_FUNC(u32, u32)
+BMP_DEFINE_PUT_FUNC(u64, u64)
+BMP_DEFINE_PUT_FUNC(ip4, ip4_addr)
+BMP_DEFINE_PUT_FUNC(ip6, ip6_addr)
+
+void
+bmp_put_data(buffer *buf, const void *src, const size_t n);
+
+#endif /* _BIRD_BMP_BUFFER_H_ */ \ No newline at end of file