summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRafael Zalamena <rzalamena@opensourcerouting.org>2020-05-11 16:41:23 +0200
committerRafael Zalamena <rzalamena@opensourcerouting.org>2020-11-24 11:54:07 +0100
commit91804f630cfe6ce783743c8bc9216132613e7975 (patch)
tree91f34124fcc722064cb9da4a9a477c03d0f13e4c
parentMerge pull request #7577 from donaldsharp/datacenter_stuff (diff)
downloadfrr-91804f630cfe6ce783743c8bc9216132613e7975.tar.xz
frr-91804f630cfe6ce783743c8bc9216132613e7975.zip
lib: add new stream function to reorganize buffer
The function was originally implemented for zebra data plane FPM plugin, but another code places could use it. Signed-off-by: Rafael Zalamena <rzalamena@opensourcerouting.org>
-rw-r--r--lib/stream.c16
-rw-r--r--lib/stream.h10
-rw-r--r--zebra/dplane_fpm_nl.c25
3 files changed, 26 insertions, 25 deletions
diff --git a/lib/stream.c b/lib/stream.c
index dc207c16a..e4e37b731 100644
--- a/lib/stream.c
+++ b/lib/stream.c
@@ -1372,3 +1372,19 @@ void stream_fifo_free(struct stream_fifo *fifo)
stream_fifo_deinit(fifo);
XFREE(MTYPE_STREAM_FIFO, fifo);
}
+
+void stream_pulldown(struct stream *s)
+{
+ size_t rlen = STREAM_READABLE(s);
+
+ /* No more data, so just move the pointers. */
+ if (rlen == 0) {
+ stream_reset(s);
+ return;
+ }
+
+ /* Move the available data to the beginning. */
+ memmove(s->data, &s->data[s->getp], rlen);
+ s->getp = 0;
+ s->endp = rlen;
+}
diff --git a/lib/stream.h b/lib/stream.h
index 4f75f121c..dedbf3798 100644
--- a/lib/stream.h
+++ b/lib/stream.h
@@ -262,6 +262,16 @@ extern int stream_empty(struct stream *); /* is the stream empty? */
/* debugging */
extern void stream_hexdump(const struct stream *s);
+/**
+ * Reorganize the buffer data so it can fit more. This function is normally
+ * called right after stream data is consumed so we can read more data
+ * (the functions that consume data start with `stream_get*()` and macros
+ * `STREAM_GET*()`).
+ *
+ * \param s stream pointer.
+ */
+extern void stream_pulldown(struct stream *s);
+
/* deprecated */
extern uint8_t *stream_pnt(struct stream *);
diff --git a/zebra/dplane_fpm_nl.c b/zebra/dplane_fpm_nl.c
index 5bf47580a..fd214cad2 100644
--- a/zebra/dplane_fpm_nl.c
+++ b/zebra/dplane_fpm_nl.c
@@ -184,31 +184,6 @@ static int fpm_rmac_send(struct thread *t);
static int fpm_rmac_reset(struct thread *t);
/*
- * Helper functions.
- */
-
-/**
- * Reorganizes the data on the buffer so it can fit more data.
- *
- * @param s stream pointer.
- */
-static void stream_pulldown(struct stream *s)
-{
- size_t rlen = STREAM_READABLE(s);
-
- /* No more data, so just move the pointers. */
- if (rlen == 0) {
- stream_reset(s);
- return;
- }
-
- /* Move the available data to the beginning. */
- memmove(s->data, &s->data[s->getp], rlen);
- s->getp = 0;
- s->endp = rlen;
-}
-
-/*
* CLI.
*/
#define FPM_STR "Forwarding Plane Manager configuration\n"