Example #1
0
/* Creates and returns a new ofpbuf whose data are copied from 'buffer'.   The
 * returned ofpbuf will additionally have 'headroom' bytes of headroom. */
struct ofpbuf *
ofpbuf_clone_with_headroom(const struct ofpbuf *buffer, size_t headroom)
{
    struct ofpbuf *new_buffer;
    uintptr_t data_delta;

    new_buffer = ofpbuf_clone_data_with_headroom(buffer->data, buffer->size,
                                                 headroom);
    data_delta = (char *) new_buffer->data - (char *) buffer->data;

    if (buffer->l2) {
        new_buffer->l2 = (char *) buffer->l2 + data_delta;
    }
    if (buffer->l3) {
        new_buffer->l3 = (char *) buffer->l3 + data_delta;
    }
    if (buffer->l4) {
        new_buffer->l4 = (char *) buffer->l4 + data_delta;
    }
    if (buffer->l7) {
        new_buffer->l7 = (char *) buffer->l7 + data_delta;
    }

    return new_buffer;
}
Example #2
0
/* Creates and returns a new ofpbuf whose data are copied from 'buffer'.   The
 * returned ofpbuf will additionally have 'headroom' bytes of headroom. */
struct ofpbuf *
ofpbuf_clone_with_headroom(const struct ofpbuf *buffer, size_t headroom)
{
    struct ofpbuf *new_buffer;

    new_buffer = ofpbuf_clone_data_with_headroom(buffer->data,
                                                 buffer->size,
                                                 headroom);
    if (buffer->header) {
        uintptr_t data_delta
            = (char *)new_buffer->data - (char *)buffer->data;

        new_buffer->header = (char *) buffer->header + data_delta;
    }
    new_buffer->msg = buffer->msg;

    return new_buffer;
}
Example #3
0
/* Creates and returns a new ofpbuf whose data are copied from 'buffer'.   The
 * returned ofpbuf will additionally have 'headroom' bytes of headroom. */
struct ofpbuf *
ofpbuf_clone_with_headroom(const struct ofpbuf *buffer, size_t headroom)
{
    struct ofpbuf *new_buffer;

    new_buffer = ofpbuf_clone_data_with_headroom(ofpbuf_data(buffer),
                                                 ofpbuf_size(buffer),
                                                 headroom);
    if (buffer->frame) {
        uintptr_t data_delta
            = (char *)ofpbuf_data(new_buffer) - (char *)ofpbuf_data(buffer);

        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_buffer->l4_ofs = buffer->l4_ofs;

    return new_buffer;
}
Example #4
0
/* Creates and returns a new ofpbuf that initially contains a copy of the
 * 'size' bytes of data starting at 'data' with no headroom or tailroom. */
struct ofpbuf *
ofpbuf_clone_data(const void *data, size_t size)
{
    return ofpbuf_clone_data_with_headroom(data, size, 0);
}