#include "netdev-dpdk.h"
#include "util.h"
+static void
+ofpbuf_init__(struct ofpbuf *b, size_t allocated, enum ofpbuf_source source)
+{
+ b->allocated = allocated;
+ b->source = source;
+ b->frame = NULL;
+ b->l2_5_ofs = b->l3_ofs = b->l4_ofs = UINT16_MAX;
+ list_poison(&b->list_node);
+}
+
static void
ofpbuf_use__(struct ofpbuf *b, void *base, size_t allocated,
enum ofpbuf_source source)
ofpbuf_set_data(b, base);
ofpbuf_set_size(b, 0);
- b->allocated = allocated;
- b->source = source;
- b->l2 = NULL;
- b->l2_5_ofs = b->l3_ofs = b->l4_ofs = UINT16_MAX;
- list_poison(&b->list_node);
+ ofpbuf_init__(b, allocated, source);
}
/* Initializes 'b' as an empty ofpbuf that contains the 'allocated' bytes of
ofpbuf_set_size(b, size);
}
+/* Initializes 'b' as an empty ofpbuf that contains the 'allocated' bytes of
+ * memory starting at 'base'. DPDK allocated ofpbuf and *data is allocated
+ * from one continous memory region, so in memory data start right after
+ * ofpbuf. Therefore there is special method to free this type of
+ * buffer. ofpbuf base, data and size are initialized by dpdk rcv() so no
+ * need to initialize those fields. */
+void
+ofpbuf_init_dpdk(struct ofpbuf *b, size_t allocated)
+{
+ ofpbuf_init__(b, allocated, OFPBUF_DPDK);
+}
+
/* Initializes 'b' as an empty ofpbuf with an initial capacity of 'size'
* bytes. */
void
if (b->source == OFPBUF_MALLOC) {
free(ofpbuf_base(b));
}
- if (b->source == OFPBUF_DPDK) {
- free_dpdk_buf(b);
- }
+ ovs_assert(b->source != OFPBUF_DPDK);
}
}
new_buffer = ofpbuf_clone_data_with_headroom(ofpbuf_data(buffer),
ofpbuf_size(buffer),
headroom);
- if (buffer->l2) {
- uintptr_t data_delta = (char *)ofpbuf_data(new_buffer) - (char *)ofpbuf_data(buffer);
+ if (buffer->frame) {
+ uintptr_t data_delta
+ = (char *)ofpbuf_data(new_buffer) - (char *)ofpbuf_data(buffer);
- new_buffer->l2 = (char *) buffer->l2 + data_delta;
+ new_buffer->frame = (char *) buffer->frame + data_delta;
}
new_buffer->l2_5_ofs = buffer->l2_5_ofs;
new_buffer->l3_ofs = buffer->l3_ofs;
new_data = (char *) new_base + new_headroom;
if (ofpbuf_data(b) != new_data) {
- uintptr_t data_delta = (char *) new_data - (char *) ofpbuf_data(b);
+ if (b->frame) {
+ uintptr_t data_delta = (char *) new_data - (char *) ofpbuf_data(b);
- ofpbuf_set_data(b, new_data);
- if (b->l2) {
- b->l2 = (char *) b->l2 + data_delta;
+ b->frame = (char *) b->frame + data_delta;
}
+ ofpbuf_set_data(b, new_data);
}
}
ofpbuf_pull(b, -increment);
}
- b->l2 = ofpbuf_data(b);
+ 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->l2;
+ return b->frame;
}
/* Adjust the size of the l2 portion of the ofpbuf, updating the l2
{
ofpbuf_resize_l2_5(b, increment);
ofpbuf_adjust_layer_offset(&b->l2_5_ofs, increment);
- return b->l2;
+ return b->frame;
}