+
+static inline void
+ofpbuf_adjust_layer_offset(uint16_t *offset, int increment)
+{
+ if (*offset != UINT16_MAX) {
+ *offset += increment;
+ }
+}
+
+/* Adjust the size of the l2_5 portion of the ofpbuf, updating the l2
+ * pointer and the layer offsets. The caller is responsible for
+ * modifying the contents. */
+void *
+ofpbuf_resize_l2_5(struct ofpbuf *b, int increment)
+{
+ if (increment >= 0) {
+ ofpbuf_push_uninit(b, increment);
+ } else {
+ ofpbuf_pull(b, -increment);
+ }
+
+ b->frame = ofpbuf_data(b);
+ /* Adjust layer offsets after l2_5. */
+ ofpbuf_adjust_layer_offset(&b->l3_ofs, increment);
+ ofpbuf_adjust_layer_offset(&b->l4_ofs, increment);
+
+ return b->frame;
+}
+
+/* Adjust the size of the l2 portion of the ofpbuf, updating the l2
+ * pointer and the layer offsets. The caller is responsible for
+ * modifying the contents. */
+void *
+ofpbuf_resize_l2(struct ofpbuf *b, int increment)
+{
+ ofpbuf_resize_l2_5(b, increment);
+ ofpbuf_adjust_layer_offset(&b->l2_5_ofs, increment);
+ return b->frame;
+}