2009-07-08 13:19:16 -07:00
|
|
|
|
/*
|
2013-02-27 17:02:53 -08:00
|
|
|
|
* Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013 Nicira, Inc.
|
2009-07-08 13:19:16 -07:00
|
|
|
|
*
|
2009-06-15 15:11:30 -07:00
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
|
* You may obtain a copy of the License at:
|
2009-07-08 13:19:16 -07:00
|
|
|
|
*
|
2009-06-15 15:11:30 -07:00
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
*
|
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
|
* limitations under the License.
|
2009-07-08 13:19:16 -07:00
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#ifndef OFPBUF_H
|
|
|
|
|
#define OFPBUF_H 1
|
|
|
|
|
|
|
|
|
|
#include <stddef.h>
|
2010-12-23 14:23:41 -08:00
|
|
|
|
#include <stdint.h>
|
2010-12-06 10:03:31 -08:00
|
|
|
|
#include "list.h"
|
2014-03-25 15:26:23 -07:00
|
|
|
|
#include "packets.h"
|
2010-12-23 14:23:41 -08:00
|
|
|
|
#include "util.h"
|
2014-03-31 12:44:06 -07:00
|
|
|
|
#include "netdev-dpdk.h"
|
2009-07-08 13:19:16 -07:00
|
|
|
|
|
2010-02-01 09:46:31 -08:00
|
|
|
|
#ifdef __cplusplus
|
|
|
|
|
extern "C" {
|
|
|
|
|
#endif
|
|
|
|
|
|
lib/ofpbuf: Compact
This patch shrinks the struct ofpbuf from 104 to 48 bytes on 64-bit
systems, or from 52 to 36 bytes on 32-bit systems (counting in the
'l7' removal from an earlier patch). This may help contribute to
cache efficiency, and will speed up initializing, copying and
manipulating ofpbufs. This is potentially important for the DPDK
datapath, but the rest of the code base may also see a little benefit.
Changes are:
- Remove 'l7' pointer (previous patch).
- Use offsets instead of layer pointers for l2_5, l3, and l4 using
'l2' as basis. Usually 'data' is the same as 'l2', but this is not
always the case (e.g., when parsing or constructing a packet), so it
can not be easily used as the offset basis. Also, packet parsing is
faster if we do not need to maintain the offsets each time we pull
data from the ofpbuf.
- Use uint32_t for 'allocated' and 'size', as 2^32 is enough even for
largest possible messages/packets.
- Use packed enum for 'source'.
- Rearrange to avoid unnecessary padding.
- Remove 'private_p', which was used only in two cases, both of which
had the invariant ('l2' == 'data'), so we can temporarily use 'l2'
as a private pointer.
Signed-off-by: Jarno Rajahalme <jrajahalme@nicira.com>
Signed-off-by: Ben Pfaff <blp@nicira.com>
2014-03-24 09:17:01 -07:00
|
|
|
|
enum OVS_PACKED_ENUM ofpbuf_source {
|
2010-12-23 14:23:41 -08:00
|
|
|
|
OFPBUF_MALLOC, /* Obtained via malloc(). */
|
2012-04-17 21:55:27 -07:00
|
|
|
|
OFPBUF_STACK, /* Un-movable stack space or static buffer. */
|
2014-03-20 11:00:14 -07:00
|
|
|
|
OFPBUF_STUB, /* Starts on stack, may expand into heap. */
|
2014-03-24 19:23:08 -07:00
|
|
|
|
OFPBUF_DPDK, /* buffer data is from DPDK allocated memory.
|
|
|
|
|
ref to build_ofpbuf() in netdev-dpdk. */
|
2010-12-23 14:23:41 -08:00
|
|
|
|
};
|
|
|
|
|
|
2009-07-08 13:19:16 -07:00
|
|
|
|
/* Buffer for holding arbitrary data. An ofpbuf is automatically reallocated
|
|
|
|
|
* as necessary if it grows too large for the available memory. */
|
|
|
|
|
struct ofpbuf {
|
2010-12-23 14:23:41 -08:00
|
|
|
|
void *base; /* First byte of allocated space. */
|
lib/ofpbuf: Compact
This patch shrinks the struct ofpbuf from 104 to 48 bytes on 64-bit
systems, or from 52 to 36 bytes on 32-bit systems (counting in the
'l7' removal from an earlier patch). This may help contribute to
cache efficiency, and will speed up initializing, copying and
manipulating ofpbufs. This is potentially important for the DPDK
datapath, but the rest of the code base may also see a little benefit.
Changes are:
- Remove 'l7' pointer (previous patch).
- Use offsets instead of layer pointers for l2_5, l3, and l4 using
'l2' as basis. Usually 'data' is the same as 'l2', but this is not
always the case (e.g., when parsing or constructing a packet), so it
can not be easily used as the offset basis. Also, packet parsing is
faster if we do not need to maintain the offsets each time we pull
data from the ofpbuf.
- Use uint32_t for 'allocated' and 'size', as 2^32 is enough even for
largest possible messages/packets.
- Use packed enum for 'source'.
- Rearrange to avoid unnecessary padding.
- Remove 'private_p', which was used only in two cases, both of which
had the invariant ('l2' == 'data'), so we can temporarily use 'l2'
as a private pointer.
Signed-off-by: Jarno Rajahalme <jrajahalme@nicira.com>
Signed-off-by: Ben Pfaff <blp@nicira.com>
2014-03-24 09:17:01 -07:00
|
|
|
|
uint32_t allocated; /* Number of bytes allocated. */
|
|
|
|
|
uint32_t size; /* Number of bytes in use. */
|
2009-07-08 13:19:16 -07:00
|
|
|
|
void *data; /* First byte actually in use. */
|
|
|
|
|
|
|
|
|
|
void *l2; /* Link-level header. */
|
lib/ofpbuf: Compact
This patch shrinks the struct ofpbuf from 104 to 48 bytes on 64-bit
systems, or from 52 to 36 bytes on 32-bit systems (counting in the
'l7' removal from an earlier patch). This may help contribute to
cache efficiency, and will speed up initializing, copying and
manipulating ofpbufs. This is potentially important for the DPDK
datapath, but the rest of the code base may also see a little benefit.
Changes are:
- Remove 'l7' pointer (previous patch).
- Use offsets instead of layer pointers for l2_5, l3, and l4 using
'l2' as basis. Usually 'data' is the same as 'l2', but this is not
always the case (e.g., when parsing or constructing a packet), so it
can not be easily used as the offset basis. Also, packet parsing is
faster if we do not need to maintain the offsets each time we pull
data from the ofpbuf.
- Use uint32_t for 'allocated' and 'size', as 2^32 is enough even for
largest possible messages/packets.
- Use packed enum for 'source'.
- Rearrange to avoid unnecessary padding.
- Remove 'private_p', which was used only in two cases, both of which
had the invariant ('l2' == 'data'), so we can temporarily use 'l2'
as a private pointer.
Signed-off-by: Jarno Rajahalme <jrajahalme@nicira.com>
Signed-off-by: Ben Pfaff <blp@nicira.com>
2014-03-24 09:17:01 -07:00
|
|
|
|
uint16_t l2_5_ofs; /* MPLS label stack offset from l2, or
|
|
|
|
|
* UINT16_MAX */
|
|
|
|
|
uint16_t l3_ofs; /* Network-level header offset from l2, or
|
|
|
|
|
* UINT16_MAX. */
|
|
|
|
|
uint16_t l4_ofs; /* Transport-level header offset from l2, or
|
|
|
|
|
UINT16_MAX. */
|
|
|
|
|
enum ofpbuf_source source; /* Source of memory allocated as 'base'. */
|
2010-12-06 10:03:31 -08:00
|
|
|
|
struct list list_node; /* Private list element for use by owner. */
|
2014-03-31 12:44:06 -07:00
|
|
|
|
#ifdef DPDK_NETDEV
|
|
|
|
|
void *private_p; /* private pointer for use by dpdk */
|
|
|
|
|
#endif
|
2009-07-08 13:19:16 -07:00
|
|
|
|
};
|
|
|
|
|
|
2014-03-30 01:31:50 -07:00
|
|
|
|
static inline void * ofpbuf_data(const struct ofpbuf *);
|
|
|
|
|
static inline void ofpbuf_set_data(struct ofpbuf *, void *);
|
|
|
|
|
static inline void * ofpbuf_base(const struct ofpbuf *);
|
|
|
|
|
static inline void ofpbuf_set_base(struct ofpbuf *, void *);
|
|
|
|
|
|
|
|
|
|
static inline uint32_t ofpbuf_size(const struct ofpbuf *);
|
|
|
|
|
static inline void ofpbuf_set_size(struct ofpbuf *, uint32_t);
|
|
|
|
|
|
lib/ofpbuf: Compact
This patch shrinks the struct ofpbuf from 104 to 48 bytes on 64-bit
systems, or from 52 to 36 bytes on 32-bit systems (counting in the
'l7' removal from an earlier patch). This may help contribute to
cache efficiency, and will speed up initializing, copying and
manipulating ofpbufs. This is potentially important for the DPDK
datapath, but the rest of the code base may also see a little benefit.
Changes are:
- Remove 'l7' pointer (previous patch).
- Use offsets instead of layer pointers for l2_5, l3, and l4 using
'l2' as basis. Usually 'data' is the same as 'l2', but this is not
always the case (e.g., when parsing or constructing a packet), so it
can not be easily used as the offset basis. Also, packet parsing is
faster if we do not need to maintain the offsets each time we pull
data from the ofpbuf.
- Use uint32_t for 'allocated' and 'size', as 2^32 is enough even for
largest possible messages/packets.
- Use packed enum for 'source'.
- Rearrange to avoid unnecessary padding.
- Remove 'private_p', which was used only in two cases, both of which
had the invariant ('l2' == 'data'), so we can temporarily use 'l2'
as a private pointer.
Signed-off-by: Jarno Rajahalme <jrajahalme@nicira.com>
Signed-off-by: Ben Pfaff <blp@nicira.com>
2014-03-24 09:17:01 -07:00
|
|
|
|
void * ofpbuf_resize_l2(struct ofpbuf *, int increment);
|
|
|
|
|
void * ofpbuf_resize_l2_5(struct ofpbuf *, int increment);
|
|
|
|
|
static inline void * ofpbuf_get_l2_5(const struct ofpbuf *);
|
|
|
|
|
static inline void ofpbuf_set_l2_5(struct ofpbuf *, void *);
|
|
|
|
|
static inline void * ofpbuf_get_l3(const struct ofpbuf *);
|
|
|
|
|
static inline void ofpbuf_set_l3(struct ofpbuf *, void *);
|
|
|
|
|
static inline void * ofpbuf_get_l4(const struct ofpbuf *);
|
|
|
|
|
static inline void ofpbuf_set_l4(struct ofpbuf *, void *);
|
|
|
|
|
static inline size_t ofpbuf_get_l4_size(const struct ofpbuf *);
|
|
|
|
|
static inline const void *ofpbuf_get_tcp_payload(const struct ofpbuf *);
|
|
|
|
|
static inline const void *ofpbuf_get_udp_payload(const struct ofpbuf *);
|
|
|
|
|
static inline const void *ofpbuf_get_sctp_payload(const struct ofpbuf *);
|
|
|
|
|
static inline const void *ofpbuf_get_icmp_payload(const struct ofpbuf *);
|
|
|
|
|
|
2009-07-08 13:19:16 -07:00
|
|
|
|
void ofpbuf_use(struct ofpbuf *, void *, size_t);
|
2010-12-23 14:23:41 -08:00
|
|
|
|
void ofpbuf_use_stack(struct ofpbuf *, void *, size_t);
|
2012-04-17 21:55:27 -07:00
|
|
|
|
void ofpbuf_use_stub(struct ofpbuf *, void *, size_t);
|
2010-12-02 14:53:12 -08:00
|
|
|
|
void ofpbuf_use_const(struct ofpbuf *, const void *, size_t);
|
2009-07-08 13:19:16 -07:00
|
|
|
|
|
2014-03-31 13:22:39 -07:00
|
|
|
|
void ofpbuf_init_dpdk(struct ofpbuf *b, size_t allocated);
|
|
|
|
|
|
2009-07-08 13:19:16 -07:00
|
|
|
|
void ofpbuf_init(struct ofpbuf *, size_t);
|
|
|
|
|
void ofpbuf_uninit(struct ofpbuf *);
|
2014-03-25 15:26:23 -07:00
|
|
|
|
static inline void *ofpbuf_get_uninit_pointer(struct ofpbuf *);
|
2009-07-08 13:19:16 -07:00
|
|
|
|
void ofpbuf_reinit(struct ofpbuf *, size_t);
|
|
|
|
|
|
|
|
|
|
struct ofpbuf *ofpbuf_new(size_t);
|
2010-09-01 12:55:38 -07:00
|
|
|
|
struct ofpbuf *ofpbuf_new_with_headroom(size_t, size_t headroom);
|
2009-07-08 13:19:16 -07:00
|
|
|
|
struct ofpbuf *ofpbuf_clone(const struct ofpbuf *);
|
2010-09-01 12:55:38 -07:00
|
|
|
|
struct ofpbuf *ofpbuf_clone_with_headroom(const struct ofpbuf *,
|
|
|
|
|
size_t headroom);
|
2009-07-08 13:19:16 -07:00
|
|
|
|
struct ofpbuf *ofpbuf_clone_data(const void *, size_t);
|
2010-12-27 14:36:16 -08:00
|
|
|
|
struct ofpbuf *ofpbuf_clone_data_with_headroom(const void *, size_t,
|
|
|
|
|
size_t headroom);
|
2014-03-25 15:26:23 -07:00
|
|
|
|
static inline void ofpbuf_delete(struct ofpbuf *);
|
2009-07-08 13:19:16 -07:00
|
|
|
|
|
2014-03-25 15:26:23 -07:00
|
|
|
|
static inline void *ofpbuf_at(const struct ofpbuf *, size_t offset,
|
|
|
|
|
size_t size);
|
|
|
|
|
static inline void *ofpbuf_at_assert(const struct ofpbuf *, size_t offset,
|
|
|
|
|
size_t size);
|
|
|
|
|
static inline void *ofpbuf_tail(const struct ofpbuf *);
|
|
|
|
|
static inline void *ofpbuf_end(const struct ofpbuf *);
|
2009-07-08 13:19:16 -07:00
|
|
|
|
|
|
|
|
|
void *ofpbuf_put_uninit(struct ofpbuf *, size_t);
|
|
|
|
|
void *ofpbuf_put_zeros(struct ofpbuf *, size_t);
|
|
|
|
|
void *ofpbuf_put(struct ofpbuf *, const void *, size_t);
|
2010-12-08 13:09:59 -08:00
|
|
|
|
char *ofpbuf_put_hex(struct ofpbuf *, const char *s, size_t *n);
|
2009-07-08 13:19:16 -07:00
|
|
|
|
void ofpbuf_reserve(struct ofpbuf *, size_t);
|
2013-12-16 08:14:52 -08:00
|
|
|
|
void ofpbuf_reserve_with_tailroom(struct ofpbuf *b, size_t headroom,
|
|
|
|
|
size_t tailroom);
|
2009-07-08 13:19:16 -07:00
|
|
|
|
void *ofpbuf_push_uninit(struct ofpbuf *b, size_t);
|
2010-04-09 12:36:16 -07:00
|
|
|
|
void *ofpbuf_push_zeros(struct ofpbuf *, size_t);
|
2009-07-08 13:19:16 -07:00
|
|
|
|
void *ofpbuf_push(struct ofpbuf *b, const void *, size_t);
|
|
|
|
|
|
2014-03-25 15:26:23 -07:00
|
|
|
|
static inline size_t ofpbuf_headroom(const struct ofpbuf *);
|
|
|
|
|
static inline size_t ofpbuf_tailroom(const struct ofpbuf *);
|
2009-07-08 13:19:16 -07:00
|
|
|
|
void ofpbuf_prealloc_headroom(struct ofpbuf *, size_t);
|
|
|
|
|
void ofpbuf_prealloc_tailroom(struct ofpbuf *, size_t);
|
|
|
|
|
void ofpbuf_trim(struct ofpbuf *);
|
2011-05-31 16:49:06 -07:00
|
|
|
|
void ofpbuf_padto(struct ofpbuf *, size_t);
|
2013-11-22 11:42:42 -08:00
|
|
|
|
void ofpbuf_shift(struct ofpbuf *, int);
|
2009-07-08 13:19:16 -07:00
|
|
|
|
|
2014-03-25 15:26:23 -07:00
|
|
|
|
static inline void ofpbuf_clear(struct ofpbuf *);
|
|
|
|
|
static inline void *ofpbuf_pull(struct ofpbuf *, size_t);
|
|
|
|
|
static inline void *ofpbuf_try_pull(struct ofpbuf *, size_t);
|
2009-07-08 13:19:16 -07:00
|
|
|
|
|
2011-03-11 11:52:49 -08:00
|
|
|
|
void *ofpbuf_steal_data(struct ofpbuf *);
|
|
|
|
|
|
2010-02-11 13:56:45 -08:00
|
|
|
|
char *ofpbuf_to_string(const struct ofpbuf *, size_t maxbytes);
|
2014-03-25 15:26:23 -07:00
|
|
|
|
static inline struct ofpbuf *ofpbuf_from_list(const struct list *);
|
|
|
|
|
void ofpbuf_list_delete(struct list *);
|
|
|
|
|
static inline bool ofpbuf_equal(const struct ofpbuf *, const struct ofpbuf *);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Returns a pointer that may be passed to free() to accomplish the same thing
|
|
|
|
|
* as ofpbuf_uninit(b). The return value is a null pointer if ofpbuf_uninit()
|
|
|
|
|
* would not free any memory. */
|
|
|
|
|
static inline void *ofpbuf_get_uninit_pointer(struct ofpbuf *b)
|
|
|
|
|
{
|
|
|
|
|
/* XXX: If 'source' is OFPBUF_DPDK memory gets leaked! */
|
2014-03-30 01:31:50 -07:00
|
|
|
|
return b && b->source == OFPBUF_MALLOC ? ofpbuf_base(b) : NULL;
|
2014-03-25 15:26:23 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Frees memory that 'b' points to, as well as 'b' itself. */
|
|
|
|
|
static inline void ofpbuf_delete(struct ofpbuf *b)
|
|
|
|
|
{
|
|
|
|
|
if (b) {
|
|
|
|
|
ofpbuf_uninit(b);
|
|
|
|
|
free(b);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* If 'b' contains at least 'offset + size' bytes of data, returns a pointer to
|
|
|
|
|
* byte 'offset'. Otherwise, returns a null pointer. */
|
|
|
|
|
static inline void *ofpbuf_at(const struct ofpbuf *b, size_t offset,
|
|
|
|
|
size_t size)
|
|
|
|
|
{
|
2014-03-30 01:31:50 -07:00
|
|
|
|
return offset + size <= ofpbuf_size(b) ? (char *) ofpbuf_data(b) + offset : NULL;
|
2014-03-25 15:26:23 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Returns a pointer to byte 'offset' in 'b', which must contain at least
|
|
|
|
|
* 'offset + size' bytes of data. */
|
|
|
|
|
static inline void *ofpbuf_at_assert(const struct ofpbuf *b, size_t offset,
|
|
|
|
|
size_t size)
|
|
|
|
|
{
|
2014-03-30 01:31:50 -07:00
|
|
|
|
ovs_assert(offset + size <= ofpbuf_size(b));
|
|
|
|
|
return ((char *) ofpbuf_data(b)) + offset;
|
2014-03-25 15:26:23 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Returns the byte following the last byte of data in use in 'b'. */
|
|
|
|
|
static inline void *ofpbuf_tail(const struct ofpbuf *b)
|
|
|
|
|
{
|
2014-03-30 01:31:50 -07:00
|
|
|
|
return (char *) ofpbuf_data(b) + ofpbuf_size(b);
|
2014-03-25 15:26:23 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Returns the byte following the last byte allocated for use (but not
|
|
|
|
|
* necessarily in use) by 'b'. */
|
|
|
|
|
static inline void *ofpbuf_end(const struct ofpbuf *b)
|
|
|
|
|
{
|
2014-03-30 01:31:50 -07:00
|
|
|
|
return (char *) ofpbuf_base(b) + b->allocated;
|
2014-03-25 15:26:23 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Returns the number of bytes of headroom in 'b', that is, the number of bytes
|
|
|
|
|
* of unused space in ofpbuf 'b' before the data that is in use. (Most
|
|
|
|
|
* commonly, the data in a ofpbuf is at its beginning, and thus the ofpbuf's
|
|
|
|
|
* headroom is 0.) */
|
|
|
|
|
static inline size_t ofpbuf_headroom(const struct ofpbuf *b)
|
|
|
|
|
{
|
2014-03-30 01:31:50 -07:00
|
|
|
|
return (char*)ofpbuf_data(b) - (char*)ofpbuf_base(b);
|
2014-03-25 15:26:23 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Returns the number of bytes that may be appended to the tail end of ofpbuf
|
|
|
|
|
* 'b' before the ofpbuf must be reallocated. */
|
|
|
|
|
static inline size_t ofpbuf_tailroom(const struct ofpbuf *b)
|
|
|
|
|
{
|
|
|
|
|
return (char*)ofpbuf_end(b) - (char*)ofpbuf_tail(b);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Clears any data from 'b'. */
|
|
|
|
|
static inline void ofpbuf_clear(struct ofpbuf *b)
|
|
|
|
|
{
|
2014-03-30 01:31:50 -07:00
|
|
|
|
ofpbuf_set_data(b, ofpbuf_base(b));
|
|
|
|
|
ofpbuf_set_size(b, 0);
|
2014-03-25 15:26:23 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Removes 'size' bytes from the head end of 'b', which must contain at least
|
|
|
|
|
* 'size' bytes of data. Returns the first byte of data removed. */
|
|
|
|
|
static inline void *ofpbuf_pull(struct ofpbuf *b, size_t size)
|
|
|
|
|
{
|
2014-03-30 01:31:50 -07:00
|
|
|
|
void *data = ofpbuf_data(b);
|
|
|
|
|
ovs_assert(ofpbuf_size(b) >= size);
|
|
|
|
|
ofpbuf_set_data(b, (char*)ofpbuf_data(b) + size);
|
|
|
|
|
ofpbuf_set_size(b, ofpbuf_size(b) - size);
|
2014-03-25 15:26:23 -07:00
|
|
|
|
return data;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* If 'b' has at least 'size' bytes of data, removes that many bytes from the
|
|
|
|
|
* head end of 'b' and returns the first byte removed. Otherwise, returns a
|
|
|
|
|
* null pointer without modifying 'b'. */
|
|
|
|
|
static inline void *ofpbuf_try_pull(struct ofpbuf *b, size_t size)
|
|
|
|
|
{
|
2014-03-30 01:31:50 -07:00
|
|
|
|
return ofpbuf_size(b) >= size ? ofpbuf_pull(b, size) : NULL;
|
2014-03-25 15:26:23 -07:00
|
|
|
|
}
|
2010-02-11 13:56:45 -08:00
|
|
|
|
|
2010-12-06 10:03:31 -08:00
|
|
|
|
static inline struct ofpbuf *ofpbuf_from_list(const struct list *list)
|
|
|
|
|
{
|
|
|
|
|
return CONTAINER_OF(list, struct ofpbuf, list_node);
|
|
|
|
|
}
|
|
|
|
|
|
2014-03-25 15:26:23 -07:00
|
|
|
|
static inline bool ofpbuf_equal(const struct ofpbuf *a, const struct ofpbuf *b)
|
2013-03-19 14:46:12 -07:00
|
|
|
|
{
|
2014-03-30 01:31:50 -07:00
|
|
|
|
return ofpbuf_size(a) == ofpbuf_size(b) &&
|
|
|
|
|
memcmp(ofpbuf_data(a), ofpbuf_data(b), ofpbuf_size(a)) == 0;
|
2013-03-19 14:46:12 -07:00
|
|
|
|
}
|
|
|
|
|
|
lib/ofpbuf: Compact
This patch shrinks the struct ofpbuf from 104 to 48 bytes on 64-bit
systems, or from 52 to 36 bytes on 32-bit systems (counting in the
'l7' removal from an earlier patch). This may help contribute to
cache efficiency, and will speed up initializing, copying and
manipulating ofpbufs. This is potentially important for the DPDK
datapath, but the rest of the code base may also see a little benefit.
Changes are:
- Remove 'l7' pointer (previous patch).
- Use offsets instead of layer pointers for l2_5, l3, and l4 using
'l2' as basis. Usually 'data' is the same as 'l2', but this is not
always the case (e.g., when parsing or constructing a packet), so it
can not be easily used as the offset basis. Also, packet parsing is
faster if we do not need to maintain the offsets each time we pull
data from the ofpbuf.
- Use uint32_t for 'allocated' and 'size', as 2^32 is enough even for
largest possible messages/packets.
- Use packed enum for 'source'.
- Rearrange to avoid unnecessary padding.
- Remove 'private_p', which was used only in two cases, both of which
had the invariant ('l2' == 'data'), so we can temporarily use 'l2'
as a private pointer.
Signed-off-by: Jarno Rajahalme <jrajahalme@nicira.com>
Signed-off-by: Ben Pfaff <blp@nicira.com>
2014-03-24 09:17:01 -07:00
|
|
|
|
static inline void * ofpbuf_get_l2_5(const struct ofpbuf *b)
|
|
|
|
|
{
|
|
|
|
|
return b->l2_5_ofs != UINT16_MAX ? (char *)b->l2 + b->l2_5_ofs : NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static inline void ofpbuf_set_l2_5(struct ofpbuf *b, void *l2_5)
|
|
|
|
|
{
|
|
|
|
|
b->l2_5_ofs = l2_5 ? (char *)l2_5 - (char *)b->l2 : UINT16_MAX;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static inline void * ofpbuf_get_l3(const struct ofpbuf *b)
|
|
|
|
|
{
|
|
|
|
|
return b->l3_ofs != UINT16_MAX ? (char *)b->l2 + b->l3_ofs : NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static inline void ofpbuf_set_l3(struct ofpbuf *b, void *l3)
|
|
|
|
|
{
|
|
|
|
|
b->l3_ofs = l3 ? (char *)l3 - (char *)b->l2 : UINT16_MAX;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static inline void * ofpbuf_get_l4(const struct ofpbuf *b)
|
|
|
|
|
{
|
|
|
|
|
return b->l4_ofs != UINT16_MAX ? (char *)b->l2 + b->l4_ofs : NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static inline void ofpbuf_set_l4(struct ofpbuf *b, void *l4)
|
|
|
|
|
{
|
|
|
|
|
b->l4_ofs = l4 ? (char *)l4 - (char *)b->l2 : UINT16_MAX;
|
|
|
|
|
}
|
|
|
|
|
|
2014-03-25 15:26:23 -07:00
|
|
|
|
static inline size_t ofpbuf_get_l4_size(const struct ofpbuf *b)
|
|
|
|
|
{
|
lib/ofpbuf: Compact
This patch shrinks the struct ofpbuf from 104 to 48 bytes on 64-bit
systems, or from 52 to 36 bytes on 32-bit systems (counting in the
'l7' removal from an earlier patch). This may help contribute to
cache efficiency, and will speed up initializing, copying and
manipulating ofpbufs. This is potentially important for the DPDK
datapath, but the rest of the code base may also see a little benefit.
Changes are:
- Remove 'l7' pointer (previous patch).
- Use offsets instead of layer pointers for l2_5, l3, and l4 using
'l2' as basis. Usually 'data' is the same as 'l2', but this is not
always the case (e.g., when parsing or constructing a packet), so it
can not be easily used as the offset basis. Also, packet parsing is
faster if we do not need to maintain the offsets each time we pull
data from the ofpbuf.
- Use uint32_t for 'allocated' and 'size', as 2^32 is enough even for
largest possible messages/packets.
- Use packed enum for 'source'.
- Rearrange to avoid unnecessary padding.
- Remove 'private_p', which was used only in two cases, both of which
had the invariant ('l2' == 'data'), so we can temporarily use 'l2'
as a private pointer.
Signed-off-by: Jarno Rajahalme <jrajahalme@nicira.com>
Signed-off-by: Ben Pfaff <blp@nicira.com>
2014-03-24 09:17:01 -07:00
|
|
|
|
return b->l4_ofs != UINT16_MAX
|
|
|
|
|
? (const char *)ofpbuf_tail(b) - (const char *)ofpbuf_get_l4(b) : 0;
|
2014-03-25 15:26:23 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static inline const void *ofpbuf_get_tcp_payload(const struct ofpbuf *b)
|
|
|
|
|
{
|
|
|
|
|
size_t l4_size = ofpbuf_get_l4_size(b);
|
|
|
|
|
|
|
|
|
|
if (OVS_LIKELY(l4_size >= TCP_HEADER_LEN)) {
|
lib/ofpbuf: Compact
This patch shrinks the struct ofpbuf from 104 to 48 bytes on 64-bit
systems, or from 52 to 36 bytes on 32-bit systems (counting in the
'l7' removal from an earlier patch). This may help contribute to
cache efficiency, and will speed up initializing, copying and
manipulating ofpbufs. This is potentially important for the DPDK
datapath, but the rest of the code base may also see a little benefit.
Changes are:
- Remove 'l7' pointer (previous patch).
- Use offsets instead of layer pointers for l2_5, l3, and l4 using
'l2' as basis. Usually 'data' is the same as 'l2', but this is not
always the case (e.g., when parsing or constructing a packet), so it
can not be easily used as the offset basis. Also, packet parsing is
faster if we do not need to maintain the offsets each time we pull
data from the ofpbuf.
- Use uint32_t for 'allocated' and 'size', as 2^32 is enough even for
largest possible messages/packets.
- Use packed enum for 'source'.
- Rearrange to avoid unnecessary padding.
- Remove 'private_p', which was used only in two cases, both of which
had the invariant ('l2' == 'data'), so we can temporarily use 'l2'
as a private pointer.
Signed-off-by: Jarno Rajahalme <jrajahalme@nicira.com>
Signed-off-by: Ben Pfaff <blp@nicira.com>
2014-03-24 09:17:01 -07:00
|
|
|
|
struct tcp_header *tcp = ofpbuf_get_l4(b);
|
2014-03-25 15:26:23 -07:00
|
|
|
|
int tcp_len = TCP_OFFSET(tcp->tcp_ctl) * 4;
|
|
|
|
|
|
|
|
|
|
if (OVS_LIKELY(tcp_len >= TCP_HEADER_LEN && tcp_len <= l4_size)) {
|
|
|
|
|
return (const char *)tcp + tcp_len;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static inline const void *ofpbuf_get_udp_payload(const struct ofpbuf *b)
|
|
|
|
|
{
|
|
|
|
|
return OVS_LIKELY(ofpbuf_get_l4_size(b) >= UDP_HEADER_LEN)
|
lib/ofpbuf: Compact
This patch shrinks the struct ofpbuf from 104 to 48 bytes on 64-bit
systems, or from 52 to 36 bytes on 32-bit systems (counting in the
'l7' removal from an earlier patch). This may help contribute to
cache efficiency, and will speed up initializing, copying and
manipulating ofpbufs. This is potentially important for the DPDK
datapath, but the rest of the code base may also see a little benefit.
Changes are:
- Remove 'l7' pointer (previous patch).
- Use offsets instead of layer pointers for l2_5, l3, and l4 using
'l2' as basis. Usually 'data' is the same as 'l2', but this is not
always the case (e.g., when parsing or constructing a packet), so it
can not be easily used as the offset basis. Also, packet parsing is
faster if we do not need to maintain the offsets each time we pull
data from the ofpbuf.
- Use uint32_t for 'allocated' and 'size', as 2^32 is enough even for
largest possible messages/packets.
- Use packed enum for 'source'.
- Rearrange to avoid unnecessary padding.
- Remove 'private_p', which was used only in two cases, both of which
had the invariant ('l2' == 'data'), so we can temporarily use 'l2'
as a private pointer.
Signed-off-by: Jarno Rajahalme <jrajahalme@nicira.com>
Signed-off-by: Ben Pfaff <blp@nicira.com>
2014-03-24 09:17:01 -07:00
|
|
|
|
? (const char *)ofpbuf_get_l4(b) + UDP_HEADER_LEN : NULL;
|
2014-03-25 15:26:23 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static inline const void *ofpbuf_get_sctp_payload(const struct ofpbuf *b)
|
|
|
|
|
{
|
|
|
|
|
return OVS_LIKELY(ofpbuf_get_l4_size(b) >= SCTP_HEADER_LEN)
|
lib/ofpbuf: Compact
This patch shrinks the struct ofpbuf from 104 to 48 bytes on 64-bit
systems, or from 52 to 36 bytes on 32-bit systems (counting in the
'l7' removal from an earlier patch). This may help contribute to
cache efficiency, and will speed up initializing, copying and
manipulating ofpbufs. This is potentially important for the DPDK
datapath, but the rest of the code base may also see a little benefit.
Changes are:
- Remove 'l7' pointer (previous patch).
- Use offsets instead of layer pointers for l2_5, l3, and l4 using
'l2' as basis. Usually 'data' is the same as 'l2', but this is not
always the case (e.g., when parsing or constructing a packet), so it
can not be easily used as the offset basis. Also, packet parsing is
faster if we do not need to maintain the offsets each time we pull
data from the ofpbuf.
- Use uint32_t for 'allocated' and 'size', as 2^32 is enough even for
largest possible messages/packets.
- Use packed enum for 'source'.
- Rearrange to avoid unnecessary padding.
- Remove 'private_p', which was used only in two cases, both of which
had the invariant ('l2' == 'data'), so we can temporarily use 'l2'
as a private pointer.
Signed-off-by: Jarno Rajahalme <jrajahalme@nicira.com>
Signed-off-by: Ben Pfaff <blp@nicira.com>
2014-03-24 09:17:01 -07:00
|
|
|
|
? (const char *)ofpbuf_get_l4(b) + SCTP_HEADER_LEN : NULL;
|
2014-03-25 15:26:23 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static inline const void *ofpbuf_get_icmp_payload(const struct ofpbuf *b)
|
|
|
|
|
{
|
|
|
|
|
return OVS_LIKELY(ofpbuf_get_l4_size(b) >= ICMP_HEADER_LEN)
|
lib/ofpbuf: Compact
This patch shrinks the struct ofpbuf from 104 to 48 bytes on 64-bit
systems, or from 52 to 36 bytes on 32-bit systems (counting in the
'l7' removal from an earlier patch). This may help contribute to
cache efficiency, and will speed up initializing, copying and
manipulating ofpbufs. This is potentially important for the DPDK
datapath, but the rest of the code base may also see a little benefit.
Changes are:
- Remove 'l7' pointer (previous patch).
- Use offsets instead of layer pointers for l2_5, l3, and l4 using
'l2' as basis. Usually 'data' is the same as 'l2', but this is not
always the case (e.g., when parsing or constructing a packet), so it
can not be easily used as the offset basis. Also, packet parsing is
faster if we do not need to maintain the offsets each time we pull
data from the ofpbuf.
- Use uint32_t for 'allocated' and 'size', as 2^32 is enough even for
largest possible messages/packets.
- Use packed enum for 'source'.
- Rearrange to avoid unnecessary padding.
- Remove 'private_p', which was used only in two cases, both of which
had the invariant ('l2' == 'data'), so we can temporarily use 'l2'
as a private pointer.
Signed-off-by: Jarno Rajahalme <jrajahalme@nicira.com>
Signed-off-by: Ben Pfaff <blp@nicira.com>
2014-03-24 09:17:01 -07:00
|
|
|
|
? (const char *)ofpbuf_get_l4(b) + ICMP_HEADER_LEN : NULL;
|
2014-03-25 15:26:23 -07:00
|
|
|
|
}
|
2014-03-25 15:26:23 -07:00
|
|
|
|
|
2014-03-30 01:31:50 -07:00
|
|
|
|
static inline void * ofpbuf_data(const struct ofpbuf *b)
|
|
|
|
|
{
|
|
|
|
|
return b->data;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static inline void ofpbuf_set_data(struct ofpbuf *b, void *d)
|
|
|
|
|
{
|
|
|
|
|
b->data = d;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static inline void * ofpbuf_base(const struct ofpbuf *b)
|
|
|
|
|
{
|
|
|
|
|
return b->base;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static inline void ofpbuf_set_base(struct ofpbuf *b, void *d)
|
|
|
|
|
{
|
|
|
|
|
b->base = d;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static inline uint32_t ofpbuf_size(const struct ofpbuf *b)
|
|
|
|
|
{
|
|
|
|
|
return b->size;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static inline void ofpbuf_set_size(struct ofpbuf *b, uint32_t v)
|
|
|
|
|
{
|
|
|
|
|
b->size = v;
|
|
|
|
|
}
|
|
|
|
|
|
2010-02-01 09:46:31 -08:00
|
|
|
|
#ifdef __cplusplus
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
2009-07-08 13:19:16 -07:00
|
|
|
|
#endif /* ofpbuf.h */
|