]> git.proxmox.com Git - mirror_ovs.git/blobdiff - lib/ofpbuf.c
tunnel: Bareudp Tunnel Support.
[mirror_ovs.git] / lib / ofpbuf.c
index cd83b57d098be7200921da2ff08e4c9051e8e541..4edb3c114ae6d9804bd172a8fd3e4b2c58dba7c8 100644 (file)
  */
 
 #include <config.h>
-#include "ofpbuf.h"
+#include "openvswitch/ofpbuf.h"
 #include <stdlib.h>
 #include <string.h>
 #include "openvswitch/dynamic-string.h"
-#include "netdev-dpdk.h"
 #include "util.h"
 
 static void
@@ -29,7 +28,7 @@ ofpbuf_init__(struct ofpbuf *b, size_t allocated, enum ofpbuf_source source)
     b->source = source;
     b->header = NULL;
     b->msg = NULL;
-    list_poison(&b->list_node);
+    ovs_list_poison(&b->list_node);
 }
 
 static void
@@ -375,7 +374,7 @@ void *
 ofpbuf_put_zeros(struct ofpbuf *b, size_t size)
 {
     void *dst = ofpbuf_put_uninit(b, size);
-    memset(dst, 0, size);
+    nullable_memset(dst, 0, size);
     return dst;
 }
 
@@ -461,6 +460,24 @@ ofpbuf_push(struct ofpbuf *b, const void *p, size_t size)
     return dst;
 }
 
+/* Inserts the 'n' bytes of 'data' into 'b' starting at the given 'offset',
+ * moving data forward as necessary to make room.
+ *
+ * 'data' must not point inside 'b'. */
+void
+ofpbuf_insert(struct ofpbuf *b, size_t offset, const void *data, size_t n)
+{
+    if (offset < b->size) {
+        ofpbuf_put_uninit(b, n); /* b->size gets increased. */
+        memmove((char *) b->data + offset + n, (char *) b->data + offset,
+                b->size - offset - n);
+        memcpy((char *) b->data + offset, data, n);
+    } else {
+        ovs_assert(offset == b->size);
+        ofpbuf_put(b, data, n);
+    }
+}
+
 /* Returns the data in 'b' as a block of malloc()'d memory and frees the buffer
  * within 'b'.  (If 'b' itself was dynamically allocated, e.g. with
  * ofpbuf_new(), then it should still be freed with, e.g., ofpbuf_delete().) */