X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=lib%2Fofpbuf.c;h=3de8ca5e234f535afd8bb3582c0b31d835d22b90;hb=8a9562d21a40c765a8ae6775a070cb279cb2147a;hp=82940eb750be0560b576b9c03917c7dce4aee586;hpb=428b2eddc9c47d8306252f0fc5218839d2ff017c;p=sliver-openvswitch.git diff --git a/lib/ofpbuf.c b/lib/ofpbuf.c index 82940eb75..3de8ca5e2 100644 --- a/lib/ofpbuf.c +++ b/lib/ofpbuf.c @@ -19,6 +19,7 @@ #include #include #include "dynamic-string.h" +#include "netdev-dpdk.h" #include "util.h" static void @@ -110,8 +111,13 @@ ofpbuf_init(struct ofpbuf *b, size_t size) void ofpbuf_uninit(struct ofpbuf *b) { - if (b && b->source == OFPBUF_MALLOC) { - free(b->base); + if (b) { + if (b->source == OFPBUF_MALLOC) { + free(b->base); + } + if (b->source == OFPBUF_DPDK) { + free_dpdk_buf(b); + } } } @@ -265,6 +271,9 @@ ofpbuf_resize__(struct ofpbuf *b, size_t new_headroom, size_t new_tailroom) new_allocated = new_headroom + b->size + new_tailroom; switch (b->source) { + case OFPBUF_DPDK: + OVS_NOT_REACHED(); + case OFPBUF_MALLOC: if (new_headroom == ofpbuf_headroom(b)) { new_base = xrealloc(b->base, new_allocated); @@ -343,6 +352,8 @@ ofpbuf_prealloc_headroom(struct ofpbuf *b, size_t size) void ofpbuf_trim(struct ofpbuf *b) { + ovs_assert(b->source != OFPBUF_DPDK); + if (b->source == OFPBUF_MALLOC && (ofpbuf_headroom(b) || ofpbuf_tailroom(b))) { ofpbuf_resize__(b, 0, 0); @@ -359,6 +370,24 @@ ofpbuf_padto(struct ofpbuf *b, size_t length) } } +/* Shifts all of the data within the allocated space in 'b' by 'delta' bytes. + * For example, a 'delta' of 1 would cause each byte of data to move one byte + * forward (from address 'p' to 'p+1'), and a 'delta' of -1 would cause each + * byte to move one byte backward (from 'p' to 'p-1'). */ +void +ofpbuf_shift(struct ofpbuf *b, int delta) +{ + ovs_assert(delta > 0 ? delta <= ofpbuf_tailroom(b) + : delta < 0 ? -delta <= ofpbuf_headroom(b) + : true); + + if (delta != 0) { + char *dst = (char *) b->data + delta; + memmove(dst, b->data, b->size); + b->data = dst; + } +} + /* Appends 'size' bytes of data to the tail end of 'b', reallocating and * copying its data if necessary. Returns a pointer to the first byte of the * new data, which is left uninitialized. */ @@ -544,6 +573,8 @@ void * ofpbuf_steal_data(struct ofpbuf *b) { void *p; + ovs_assert(b->source != OFPBUF_DPDK); + if (b->source == OFPBUF_MALLOC && b->data == b->base) { p = b->data; } else {