/* Buffer for holding arbitrary data. An ofpbuf is automatically reallocated
* as necessary if it grows too large for the available memory. */
struct ofpbuf {
+#ifdef DPDK_NETDEV
+ struct rte_mbuf mbuf; /* DPDK mbuf */
+#else
void *base; /* First byte of allocated space. */
- uint32_t allocated; /* Number of bytes allocated. */
- uint32_t size; /* Number of bytes in use. */
void *data; /* First byte actually in use. */
+ uint32_t size; /* Number of bytes in use. */
+#endif
+ uint32_t allocated; /* Number of bytes allocated. */
void *l2; /* Link-level header. */
uint16_t l2_5_ofs; /* MPLS label stack offset from l2, or
UINT16_MAX. */
enum ofpbuf_source source; /* Source of memory allocated as 'base'. */
struct list list_node; /* Private list element for use by owner. */
-#ifdef DPDK_NETDEV
- void *private_p; /* private pointer for use by dpdk */
-#endif
};
static inline void * ofpbuf_data(const struct ofpbuf *);
void ofpbuf_use_stub(struct ofpbuf *, void *, size_t);
void ofpbuf_use_const(struct ofpbuf *, const void *, size_t);
+void ofpbuf_init_dpdk(struct ofpbuf *b, size_t allocated);
+
void ofpbuf_init(struct ofpbuf *, size_t);
void ofpbuf_uninit(struct ofpbuf *);
static inline void *ofpbuf_get_uninit_pointer(struct ofpbuf *);
static inline void ofpbuf_delete(struct ofpbuf *b)
{
if (b) {
+ if (b->source == OFPBUF_DPDK) {
+ free_dpdk_buf(b);
+ return;
+ }
+
ofpbuf_uninit(b);
free(b);
}
? (const char *)ofpbuf_get_l4(b) + ICMP_HEADER_LEN : NULL;
}
+#ifdef DPDK_NETDEV
+static inline void * ofpbuf_data(const struct ofpbuf *b)
+{
+ return b->mbuf.pkt.data;
+}
+
+static inline void ofpbuf_set_data(struct ofpbuf *b, void *d)
+{
+ b->mbuf.pkt.data = d;
+}
+
+static inline void * ofpbuf_base(const struct ofpbuf *b)
+{
+ return b->mbuf.buf_addr;
+}
+
+static inline void ofpbuf_set_base(struct ofpbuf *b, void *d)
+{
+ b->mbuf.buf_addr = d;
+}
+
+static inline uint32_t ofpbuf_size(const struct ofpbuf *b)
+{
+ return b->mbuf.pkt.pkt_len;
+}
+
+static inline void ofpbuf_set_size(struct ofpbuf *b, uint32_t v)
+{
+ b->mbuf.pkt.data_len = v; /* Current seg length. */
+ b->mbuf.pkt.pkt_len = v; /* Total length of all segments linked to
+ * this segment. */
+}
+
+#else
static inline void * ofpbuf_data(const struct ofpbuf *b)
{
return b->data;
{
b->size = v;
}
+#endif
#ifdef __cplusplus
}