]> git.puffer.fish Git - matthieu/frr.git/commitdiff
lib: add new stream function to reorganize buffer
authorRafael Zalamena <rzalamena@opensourcerouting.org>
Mon, 11 May 2020 14:41:23 +0000 (11:41 -0300)
committerRafael Zalamena <rzalamena@opensourcerouting.org>
Tue, 24 Nov 2020 10:54:07 +0000 (07:54 -0300)
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>
lib/stream.c
lib/stream.h
zebra/dplane_fpm_nl.c

index dc207c16a4114dc2480e4a6d476adb1625228e2c..e4e37b731572d3057efc8028385b7927617d3ccf 100644 (file)
@@ -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;
+}
index 4f75f121ca25a6ad3034f51fdd800686933e256e..dedbf37984ca9023251665b87ad1f06600c03c44 100644 (file)
@@ -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 *);
 
index 5bf47580a852c60bb16963b6e02a5e1d36369215..fd214cad2eb986780a14049ee1abeef2ed205757 100644 (file)
@@ -183,31 +183,6 @@ static int fpm_rib_reset(struct thread *t);
 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.
  */