+/* Reallocates 'b' so that it has exactly 'new_tailroom' bytes of tailroom. */
+static void
+ofpbuf_resize_tailroom__(struct ofpbuf *b, size_t new_tailroom)
+{
+ b->allocated = ofpbuf_headroom(b) + b->size + new_tailroom;
+ ofpbuf_rebase__(b, xrealloc(b->base, b->allocated));
+}
+
+/* Ensures that 'b' has room for at least 'size' bytes at its tail end,
+ * reallocating and copying its data if necessary. Its headroom, if any, is
+ * preserved. */
+void
+ofpbuf_prealloc_tailroom(struct ofpbuf *b, size_t size)
+{
+ if (size > ofpbuf_tailroom(b)) {
+ ofpbuf_resize_tailroom__(b, MAX(size, 64));
+ }
+}
+