summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorPravin B Shelar <pshelar@nicira.com>2015-02-22 03:21:09 -0800
committerPravin B Shelar <pshelar@nicira.com>2015-03-03 13:37:37 -0800
commitcf62fa4c7074121184a1f1d07980990113657612 (patch)
tree1d1b25bf0222b0b8e62d546f4d56ad366b84abed /lib
parente14deea0bd133796872d06f39a14d0393880f5bb (diff)
downloadopenvswitch-cf62fa4c7074121184a1f1d07980990113657612.tar.gz
dp-packet: Remove ofpbuf dependency.
Currently dp-packet make use of ofpbuf for managing packet buffers. That complicates ofpbuf, by making dp-packet independent of ofpbuf both libraries can be optimized for their own use case. This avoids mapping operation between ofpbuf and dp_packet in datapath upcalls. Signed-off-by: Pravin B Shelar <pshelar@nicira.com> Acked-by: Jarno Rajahalme <jrajahalme@nicira.com> Acked-by: Ben Pfaff <blp@nicira.com>
Diffstat (limited to 'lib')
-rw-r--r--lib/bfd.c23
-rw-r--r--lib/bfd.h6
-rw-r--r--lib/cfm.c12
-rw-r--r--lib/cfm.h6
-rw-r--r--lib/dp-packet.c500
-rw-r--r--lib/dp-packet.h441
-rw-r--r--lib/dpif-netdev.c44
-rw-r--r--lib/dpif-netdev.h8
-rw-r--r--lib/dpif-netlink.c20
-rw-r--r--lib/dpif.c31
-rw-r--r--lib/dpif.h11
-rw-r--r--lib/flow.c107
-rw-r--r--lib/flow.h32
-rw-r--r--lib/lacp.c8
-rw-r--r--lib/lacp.h2
-rw-r--r--lib/learning-switch.c11
-rw-r--r--lib/netdev-bsd.c31
-rw-r--r--lib/netdev-dpdk.c11
-rw-r--r--lib/netdev-dummy.c95
-rw-r--r--lib/netdev-linux.c35
-rw-r--r--lib/netdev-vport.c47
-rw-r--r--lib/netdev.c4
-rw-r--r--lib/odp-execute.c105
-rw-r--r--lib/ofp-print.c22
-rw-r--r--lib/packets.c158
-rw-r--r--lib/packets.h34
-rw-r--r--lib/pcap-file.c48
-rw-r--r--lib/pcap-file.h10
-rw-r--r--lib/rstp-common.h2
-rw-r--r--lib/rstp-state-machines.c15
-rw-r--r--lib/rstp.c3
-rw-r--r--lib/rstp.h4
-rw-r--r--lib/stp.c19
-rw-r--r--lib/stp.h4
34 files changed, 1356 insertions, 553 deletions
diff --git a/lib/bfd.c b/lib/bfd.c
index 3db1d5745..c463b66e1 100644
--- a/lib/bfd.c
+++ b/lib/bfd.c
@@ -24,6 +24,7 @@
#include "byte-order.h"
#include "connectivity.h"
#include "csum.h"
+#include "dp-packet.h"
#include "dpif.h"
#include "dynamic-string.h"
#include "flow.h"
@@ -585,7 +586,7 @@ bfd_should_send_packet(const struct bfd *bfd) OVS_EXCLUDED(mutex)
}
void
-bfd_put_packet(struct bfd *bfd, struct ofpbuf *p,
+bfd_put_packet(struct bfd *bfd, struct dp_packet *p,
uint8_t eth_src[ETH_ADDR_LEN]) OVS_EXCLUDED(mutex)
{
long long int min_tx, min_rx;
@@ -609,8 +610,8 @@ bfd_put_packet(struct bfd *bfd, struct ofpbuf *p,
* set. */
ovs_assert(!(bfd->flags & FLAG_POLL) || !(bfd->flags & FLAG_FINAL));
- ofpbuf_reserve(p, 2); /* Properly align after the ethernet header. */
- eth = ofpbuf_put_uninit(p, sizeof *eth);
+ dp_packet_reserve(p, 2); /* Properly align after the ethernet header. */
+ eth = dp_packet_put_uninit(p, sizeof *eth);
memcpy(eth->eth_src,
eth_addr_is_zero(bfd->local_eth_src) ? eth_src
: bfd->local_eth_src,
@@ -621,7 +622,7 @@ bfd_put_packet(struct bfd *bfd, struct ofpbuf *p,
ETH_ADDR_LEN);
eth->eth_type = htons(ETH_TYPE_IP);
- ip = ofpbuf_put_zeros(p, sizeof *ip);
+ ip = dp_packet_put_zeros(p, sizeof *ip);
ip->ip_ihl_ver = IP_IHL_VER(5, 4);
ip->ip_tot_len = htons(sizeof *ip + sizeof *udp + sizeof *msg);
ip->ip_ttl = MAXTTL;
@@ -631,12 +632,12 @@ bfd_put_packet(struct bfd *bfd, struct ofpbuf *p,
put_16aligned_be32(&ip->ip_dst, bfd->ip_dst);
ip->ip_csum = csum(ip, sizeof *ip);
- udp = ofpbuf_put_zeros(p, sizeof *udp);
+ udp = dp_packet_put_zeros(p, sizeof *udp);
udp->udp_src = htons(bfd->udp_src);
udp->udp_dst = htons(BFD_DEST_PORT);
udp->udp_len = htons(sizeof *udp + sizeof *msg);
- msg = ofpbuf_put_uninit(p, sizeof *msg);
+ msg = dp_packet_put_uninit(p, sizeof *msg);
msg->vers_diag = (BFD_VERSION << 5) | bfd->diag;
msg->flags = (bfd->state & STATE_MASK) | bfd->flags;
@@ -702,14 +703,14 @@ bfd_should_process_flow(const struct bfd *bfd_, const struct flow *flow,
void
bfd_process_packet(struct bfd *bfd, const struct flow *flow,
- const struct ofpbuf *p) OVS_EXCLUDED(mutex)
+ const struct dp_packet *p) OVS_EXCLUDED(mutex)
{
uint32_t rmt_min_rx, pkt_your_disc;
enum state rmt_state;
enum flags flags;
uint8_t version;
struct msg *msg;
- const uint8_t *l7 = ofpbuf_get_udp_payload(p);
+ const uint8_t *l7 = dp_packet_get_udp_payload(p);
if (!l7) {
return; /* No UDP payload. */
@@ -728,11 +729,11 @@ bfd_process_packet(struct bfd *bfd, const struct flow *flow,
goto out;
}
- msg = ofpbuf_at(p, l7 - (uint8_t *)ofpbuf_data(p), BFD_PACKET_LEN);
+ msg = dp_packet_at(p, l7 - (uint8_t *)dp_packet_data(p), BFD_PACKET_LEN);
if (!msg) {
VLOG_INFO_RL(&rl, "%s: Received too-short BFD control message (only "
"%"PRIdPTR" bytes long, at least %d required).",
- bfd->name, (uint8_t *) ofpbuf_tail(p) - l7,
+ bfd->name, (uint8_t *) dp_packet_tail(p) - l7,
BFD_PACKET_LEN);
goto out;
}
@@ -741,7 +742,7 @@ bfd_process_packet(struct bfd *bfd, const struct flow *flow,
* If the Length field is greater than the payload of the encapsulating
* protocol, the packet MUST be discarded.
*
- * Note that we make this check implicity. Above we use ofpbuf_at() to
+ * Note that we make this check implicitly. Above we use dp_packet_at() to
* ensure that there are at least BFD_PACKET_LEN bytes in the payload of
* the encapsulating protocol. Below we require msg->length to be exactly
* BFD_PACKET_LEN bytes. */
diff --git a/lib/bfd.h b/lib/bfd.h
index d803bf9ae..2f1924c1e 100644
--- a/lib/bfd.h
+++ b/lib/bfd.h
@@ -28,20 +28,20 @@ struct dpif_flow_stats;
struct flow;
struct flow_wildcards;
struct netdev;
-struct ofpbuf;
+struct dp_packet;
struct smap;
void bfd_wait(const struct bfd *);
void bfd_run(struct bfd *);
bool bfd_should_send_packet(const struct bfd *);
-void bfd_put_packet(struct bfd *bfd, struct ofpbuf *packet,
+void bfd_put_packet(struct bfd *bfd, struct dp_packet *packet,
uint8_t eth_src[ETH_ADDR_LEN]);
bool bfd_should_process_flow(const struct bfd *, const struct flow *,
struct flow_wildcards *);
void bfd_process_packet(struct bfd *, const struct flow *,
- const struct ofpbuf *);
+ const struct dp_packet *);
struct bfd *bfd_configure(struct bfd *, const char *name,
const struct smap *smap,
diff --git a/lib/cfm.c b/lib/cfm.c
index 23c1c6f31..3e7cfe66b 100644
--- a/lib/cfm.c
+++ b/lib/cfm.c
@@ -23,12 +23,12 @@
#include "byte-order.h"
#include "connectivity.h"
+#include "dp-packet.h"
#include "dynamic-string.h"
#include "flow.h"
#include "hash.h"
#include "hmap.h"
#include "netdev.h"
-#include "ofpbuf.h"
#include "packets.h"
#include "poll-loop.h"
#include "random.h"
@@ -563,7 +563,7 @@ cfm_should_send_ccm(struct cfm *cfm) OVS_EXCLUDED(mutex)
/* Composes a CCM message into 'packet'. Messages generated with this function
* should be sent whenever cfm_should_send_ccm() indicates. */
void
-cfm_compose_ccm(struct cfm *cfm, struct ofpbuf *packet,
+cfm_compose_ccm(struct cfm *cfm, struct dp_packet *packet,
uint8_t eth_src[ETH_ADDR_LEN]) OVS_EXCLUDED(mutex)
{
uint16_t ccm_vlan;
@@ -586,7 +586,7 @@ cfm_compose_ccm(struct cfm *cfm, struct ofpbuf *packet,
atomic_read_relaxed(&cfm->extended, &extended);
- ccm = ofpbuf_l3(packet);
+ ccm = dp_packet_l3(packet);
ccm->mdlevel_version = 0;
ccm->opcode = CCM_OPCODE;
ccm->tlv_offset = 70;
@@ -747,7 +747,7 @@ cfm_should_process_flow(const struct cfm *cfm_, const struct flow *flow,
* every packet whose flow returned true when passed to
* cfm_should_process_flow. */
void
-cfm_process_heartbeat(struct cfm *cfm, const struct ofpbuf *p)
+cfm_process_heartbeat(struct cfm *cfm, const struct dp_packet *p)
OVS_EXCLUDED(mutex)
{
struct ccm *ccm;
@@ -758,8 +758,8 @@ cfm_process_heartbeat(struct cfm *cfm, const struct ofpbuf *p)
atomic_read_relaxed(&cfm->extended, &extended);
- eth = ofpbuf_l2(p);
- ccm = ofpbuf_at(p, (uint8_t *)ofpbuf_l3(p) - (uint8_t *)ofpbuf_data(p),
+ eth = dp_packet_l2(p);
+ ccm = dp_packet_at(p, (uint8_t *)dp_packet_l3(p) - (uint8_t *)dp_packet_data(p),
CCM_ACCEPT_LEN);
if (!ccm) {
diff --git a/lib/cfm.h b/lib/cfm.h
index b3a2d45ff..a871ba875 100644
--- a/lib/cfm.h
+++ b/lib/cfm.h
@@ -23,7 +23,7 @@
#include "packets.h"
struct flow;
-struct ofpbuf;
+struct dp_packet;
struct netdev;
struct flow_wildcards;
@@ -93,13 +93,13 @@ struct cfm *cfm_ref(const struct cfm *);
void cfm_unref(struct cfm *);
void cfm_run(struct cfm *);
bool cfm_should_send_ccm(struct cfm *);
-void cfm_compose_ccm(struct cfm *, struct ofpbuf *packet, uint8_t eth_src[ETH_ADDR_LEN]);
+void cfm_compose_ccm(struct cfm *, struct dp_packet *packet, uint8_t eth_src[ETH_ADDR_LEN]);
void cfm_wait(struct cfm *);
bool cfm_configure(struct cfm *, const struct cfm_settings *);
void cfm_set_netdev(struct cfm *, const struct netdev *);
bool cfm_should_process_flow(const struct cfm *cfm, const struct flow *,
struct flow_wildcards *);
-void cfm_process_heartbeat(struct cfm *, const struct ofpbuf *packet);
+void cfm_process_heartbeat(struct cfm *, const struct dp_packet *packet);
bool cfm_check_status_change(struct cfm *);
int cfm_get_fault(const struct cfm *);
uint64_t cfm_get_flap_count(const struct cfm *);
diff --git a/lib/dp-packet.c b/lib/dp-packet.c
index d77f8e4c9..88b570886 100644
--- a/lib/dp-packet.c
+++ b/lib/dp-packet.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2014 Nicira, Inc.
+ * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013 Nicira, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -15,57 +15,499 @@
*/
#include <config.h>
+#include <stdlib.h>
+#include <string.h>
+#include "dynamic-string.h"
+#include "netdev-dpdk.h"
#include "dp-packet.h"
+#include "util.h"
-#include "ofpbuf.h"
+static void
+dp_packet_init__(struct dp_packet *b, size_t allocated, enum dp_packet_source source)
+{
+ b->allocated = allocated;
+ b->source = source;
+ b->frame = NULL;
+ b->l2_pad_size = 0;
+ b->l2_5_ofs = b->l3_ofs = b->l4_ofs = UINT16_MAX;
+ b->md = PKT_METADATA_INITIALIZER(0);
+ list_poison(&b->list_node);
+}
+
+static void
+dp_packet_use__(struct dp_packet *b, void *base, size_t allocated,
+ enum dp_packet_source source)
+{
+ dp_packet_set_base(b, base);
+ dp_packet_set_data(b, base);
+ dp_packet_set_size(b, 0);
+
+ dp_packet_init__(b, allocated, source);
+}
+
+/* Initializes 'b' as an empty dp_packet that contains the 'allocated' bytes of
+ * memory starting at 'base'. 'base' should be the first byte of a region
+ * obtained from malloc(). It will be freed (with free()) if 'b' is resized or
+ * freed. */
+void
+dp_packet_use(struct dp_packet *b, void *base, size_t allocated)
+{
+ dp_packet_use__(b, base, allocated, DPBUF_MALLOC);
+}
+
+/* Initializes 'b' as an empty dp_packet that contains the 'allocated' bytes of
+ * memory starting at 'base'. 'base' should point to a buffer on the stack.
+ * (Nothing actually relies on 'base' being allocated on the stack. It could
+ * be static or malloc()'d memory. But stack space is the most common use
+ * case.)
+ *
+ * 'base' should be appropriately aligned. Using an array of uint32_t or
+ * uint64_t for the buffer is a reasonable way to ensure appropriate alignment
+ * for 32- or 64-bit data.
+ *
+ * An dp_packet operation that requires reallocating data will copy the provided
+ * buffer into a malloc()'d buffer. Thus, it is wise to call dp_packet_uninit()
+ * on an dp_packet initialized by this function, so that if it expanded into the
+ * heap, that memory is freed. */
+void
+dp_packet_use_stub(struct dp_packet *b, void *base, size_t allocated)
+{
+ dp_packet_use__(b, base, allocated, DPBUF_STUB);
+}
+
+/* Initializes 'b' as an dp_packet whose data starts at 'data' and continues for
+ * 'size' bytes. This is appropriate for an dp_packet that will be used to
+ * inspect existing data, without moving it around or reallocating it, and
+ * generally without modifying it at all.
+ *
+ * An dp_packet operation that requires reallocating data will assert-fail if this
+ * function was used to initialize it. */
+void
+dp_packet_use_const(struct dp_packet *b, const void *data, size_t size)
+{
+ dp_packet_use__(b, CONST_CAST(void *, data), size, DPBUF_STACK);
+ dp_packet_set_size(b, size);
+}
+
+/* Initializes 'b' as an empty dp_packet that contains the 'allocated' bytes of
+ * memory starting at 'base'. DPDK allocated dp_packet and *data is allocated
+ * from one continous memory region, so in memory data start right after
+ * dp_packet. Therefore there is special method to free this type of
+ * buffer. dp_packet base, data and size are initialized by dpdk rcv() so no
+ * need to initialize those fields. */
+void
+dp_packet_init_dpdk(struct dp_packet *b, size_t allocated)
+{
+ dp_packet_init__(b, allocated, DPBUF_DPDK);
+}
+
+/* Initializes 'b' as an empty dp_packet with an initial capacity of 'size'
+ * bytes. */
+void
+dp_packet_init(struct dp_packet *b, size_t size)
+{
+ dp_packet_use(b, size ? xmalloc(size) : NULL, size);
+}
+
+/* Frees memory that 'b' points to. */
+void
+dp_packet_uninit(struct dp_packet *b)
+{
+ if (b) {
+ if (b->source == DPBUF_MALLOC) {
+ free(dp_packet_base(b));
+ } else if (b->source == DPBUF_DPDK) {
+#ifdef DPDK_NETDEV
+ /* If this dp_packet was allocated by DPDK it must have been
+ * created as a dp_packet */
+ free_dpdk_buf((struct dp_packet*) b);
+#endif
+ }
+ }
+}
+
+/* Creates and returns a new dp_packet with an initial capacity of 'size'
+ * bytes. */
+struct dp_packet *
+dp_packet_new(size_t size)
+{
+ struct dp_packet *b = xmalloc(sizeof *b);
+ dp_packet_init(b, size);
+ return b;
+}
+/* Creates and returns a new dp_packet with an initial capacity of 'size +
+ * headroom' bytes, reserving the first 'headroom' bytes as headroom. */
struct dp_packet *
dp_packet_new_with_headroom(size_t size, size_t headroom)
{
- struct dp_packet *p = xmalloc(sizeof *p);
- struct ofpbuf *b = &p->ofpbuf;
+ struct dp_packet *b = dp_packet_new(size + headroom);
+ dp_packet_reserve(b, headroom);
+ return b;
+}
+
+/* Creates and returns a new dp_packet that initially contains a copy of the
+ * 'dp_packet_size(buffer)' bytes of data starting at 'buffer->data' with no headroom or
+ * tailroom. */
+struct dp_packet *
+dp_packet_clone(const struct dp_packet *buffer)
+{
+ return dp_packet_clone_with_headroom(buffer, 0);
+}
- ofpbuf_init(b, size + headroom);
- ofpbuf_reserve(b, headroom);
- p->md = PKT_METADATA_INITIALIZER(0);
+/* Creates and returns a new dp_packet whose data are copied from 'buffer'. The
+ * returned dp_packet will additionally have 'headroom' bytes of headroom. */
+struct dp_packet *
+dp_packet_clone_with_headroom(const struct dp_packet *buffer, size_t headroom)
+{
+ struct dp_packet *new_buffer;
- return p;
+ new_buffer = dp_packet_clone_data_with_headroom(dp_packet_data(buffer),
+ dp_packet_size(buffer),
+ headroom);
+ if (buffer->frame) {
+ uintptr_t data_delta
+ = (char *)dp_packet_data(new_buffer) - (char *)dp_packet_data(buffer);
+
+ new_buffer->frame = (char *) buffer->frame + data_delta;
+ }
+ new_buffer->l2_pad_size = buffer->l2_pad_size;
+ new_buffer->l2_5_ofs = buffer->l2_5_ofs;
+ new_buffer->l3_ofs = buffer->l3_ofs;
+ new_buffer->l4_ofs = buffer->l4_ofs;
+ new_buffer->md = buffer->md;
+
+ return new_buffer;
+}
+
+/* Creates and returns a new dp_packet that initially contains a copy of the
+ * 'size' bytes of data starting at 'data' with no headroom or tailroom. */
+struct dp_packet *
+dp_packet_clone_data(const void *data, size_t size)
+{
+ return dp_packet_clone_data_with_headroom(data, size, 0);
}
+/* Creates and returns a new dp_packet that initially contains 'headroom' bytes of
+ * headroom followed by a copy of the 'size' bytes of data starting at
+ * 'data'. */
struct dp_packet *
-dp_packet_clone_from_ofpbuf(const struct ofpbuf *b)
+dp_packet_clone_data_with_headroom(const void *data, size_t size, size_t headroom)
{
- struct dp_packet *p = xmalloc(sizeof *p);
- size_t headroom = ofpbuf_headroom(b);
+ struct dp_packet *b = dp_packet_new_with_headroom(size, headroom);
+ dp_packet_put(b, data, size);
+ return b;
+}
- ofpbuf_init(&p->ofpbuf, ofpbuf_size(b) + headroom);
- p->md = PKT_METADATA_INITIALIZER(0);
- ofpbuf_reserve(&p->ofpbuf, headroom);
+static void
+dp_packet_copy__(struct dp_packet *b, uint8_t *new_base,
+ size_t new_headroom, size_t new_tailroom)
+{
+ const uint8_t *old_base = dp_packet_base(b);
+ size_t old_headroom = dp_packet_headroom(b);
+ size_t old_tailroom = dp_packet_tailroom(b);
+ size_t copy_headroom = MIN(old_headroom, new_headroom);
+ size_t copy_tailroom = MIN(old_tailroom, new_tailroom);
- ofpbuf_put(&p->ofpbuf, ofpbuf_data(b), ofpbuf_size(b));
+ memcpy(&new_base[new_headroom - copy_headroom],
+ &old_base[old_headroom - copy_headroom],
+ copy_headroom + dp_packet_size(b) + copy_tailroom);
+}
- if (b->frame) {
- uintptr_t data_delta
- = (char *)ofpbuf_data(&p->ofpbuf) - (char *)ofpbuf_data(b);
+/* Reallocates 'b' so that it has exactly 'new_headroom' and 'new_tailroom'
+ * bytes of headroom and tailroom, respectively. */
+static void
+dp_packet_resize__(struct dp_packet *b, size_t new_headroom, size_t new_tailroom)
+{
+ void *new_base, *new_data;
+ size_t new_allocated;
+
+ new_allocated = new_headroom + dp_packet_size(b) + new_tailroom;
+
+ switch (b->source) {
+ case DPBUF_DPDK:
+ OVS_NOT_REACHED();
+
+ case DPBUF_MALLOC:
+ if (new_headroom == dp_packet_headroom(b)) {
+ new_base = xrealloc(dp_packet_base(b), new_allocated);
+ } else {
+ new_base = xmalloc(new_allocated);
+ dp_packet_copy__(b, new_base, new_headroom, new_tailroom);
+ free(dp_packet_base(b));
+ }
+ break;
- p->ofpbuf.frame = (char *) b->frame + data_delta;
+ case DPBUF_STACK:
+ OVS_NOT_REACHED();
+
+ case DPBUF_STUB:
+ b->source = DPBUF_MALLOC;
+ new_base = xmalloc(new_allocated);
+ dp_packet_copy__(b, new_base, new_headroom, new_tailroom);
+ break;
+
+ default:
+ OVS_NOT_REACHED();
+ }
+
+ b->allocated = new_allocated;
+ dp_packet_set_base(b, new_base);
+
+ new_data = (char *) new_base + new_headroom;
+ if (dp_packet_data(b) != new_data) {
+ if (b->frame) {
+ uintptr_t data_delta = (char *) new_data - (char *) dp_packet_data(b);
+
+ b->frame = (char *) b->frame + data_delta;
+ }
+ dp_packet_set_data(b, new_data);
}
- p->ofpbuf.l2_5_ofs = b->l2_5_ofs;
- p->ofpbuf.l3_ofs = b->l3_ofs;
- p->ofpbuf.l4_ofs = b->l4_ofs;
+}
+/* Ensures that 'b' has room for at least 'size' bytes at its tail end,
+ * reallocating and copying its data if necessary. Its headroom, if any, is
+ * preserved. */
+void
+dp_packet_prealloc_tailroom(struct dp_packet *b, size_t size)
+{
+ if (size > dp_packet_tailroom(b)) {
+ dp_packet_resize__(b, dp_packet_headroom(b), MAX(size, 64));
+ }
+}
+
+/* Ensures that 'b' has room for at least 'size' bytes at its head,
+ * reallocating and copying its data if necessary. Its tailroom, if any, is
+ * preserved. */
+void
+dp_packet_prealloc_headroom(struct dp_packet *b, size_t size)
+{
+ if (size > dp_packet_headroom(b)) {
+ dp_packet_resize__(b, MAX(size, 64), dp_packet_tailroom(b));
+ }
+}
+
+/* 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
+dp_packet_shift(struct dp_packet *b, int delta)
+{
+ ovs_assert(delta > 0 ? delta <= dp_packet_tailroom(b)
+ : delta < 0 ? -delta <= dp_packet_headroom(b)
+ : true);
+
+ if (delta != 0) {
+ char *dst = (char *) dp_packet_data(b) + delta;
+ memmove(dst, dp_packet_data(b), dp_packet_size(b));
+ dp_packet_set_data(b, 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. */
+void *
+dp_packet_put_uninit(struct dp_packet *b, size_t size)
+{
+ void *p;
+ dp_packet_prealloc_tailroom(b, size);
+ p = dp_packet_tail(b);
+ dp_packet_set_size(b, dp_packet_size(b) + size);
return p;
}
-struct dp_packet *
-dp_packet_clone(struct dp_packet *p)
+/* Appends 'size' zeroed bytes to the tail end of 'b'. Data in 'b' is
+ * reallocated and copied if necessary. Returns a pointer to the first byte of
+ * the data's location in the dp_packet. */
+void *
+dp_packet_put_zeros(struct dp_packet *b, size_t size)
+{
+ void *dst = dp_packet_put_uninit(b, size);
+ memset(dst, 0, size);
+ return dst;
+}
+
+/* Appends the 'size' bytes of data in 'p' to the tail end of 'b'. Data in 'b'
+ * is reallocated and copied if necessary. Returns a pointer to the first
+ * byte of the data's location in the dp_packet. */
+void *
+dp_packet_put(struct dp_packet *b, const void *p, size_t size)
+{
+ void *dst = dp_packet_put_uninit(b, size);
+ memcpy(dst, p, size);
+ return dst;
+}
+
+/* Parses as many pairs of hex digits as possible (possibly separated by
+ * spaces) from the beginning of 's', appending bytes for their values to 'b'.
+ * Returns the first character of 's' that is not the first of a pair of hex
+ * digits. If 'n' is nonnull, stores the number of bytes added to 'b' in
+ * '*n'. */
+char *
+dp_packet_put_hex(struct dp_packet *b, const char *s, size_t *n)
+{
+ size_t initial_size = dp_packet_size(b);
+ for (;;) {
+ uint8_t byte;
+ bool ok;
+
+ s += strspn(s, " \t\r\n");
+ byte = hexits_value(s, 2, &ok);
+ if (!ok) {
+ if (n) {
+ *n = dp_packet_size(b) - initial_size;
+ }
+ return CONST_CAST(char *, s);
+ }
+
+ dp_packet_put(b, &byte, 1);
+ s += 2;
+ }
+}
+
+/* Reserves 'size' bytes of headroom so that they can be later allocated with
+ * dp_packet_push_uninit() without reallocating the dp_packet. */
+void
+dp_packet_reserve(struct dp_packet *b, size_t size)
{
- struct dp_packet *newp;
+ ovs_assert(!dp_packet_size(b));
+ dp_packet_prealloc_tailroom(b, size);
+ dp_packet_set_data(b, (char*)dp_packet_data(b) + size);
+}
- newp = dp_packet_clone_from_ofpbuf(&p->ofpbuf);
- memcpy(&newp->md, &p->md, sizeof p->md);
+/* Reserves 'headroom' bytes at the head and 'tailroom' at the end so that
+ * they can be later allocated with dp_packet_push_uninit() or
+ * dp_packet_put_uninit() without reallocating the dp_packet. */
+void
+dp_packet_reserve_with_tailroom(struct dp_packet *b, size_t headroom,
+ size_t tailroom)
+{
+ ovs_assert(!dp_packet_size(b));
+ dp_packet_prealloc_tailroom(b, headroom + tailroom);
+ dp_packet_set_data(b, (char*)dp_packet_data(b) + headroom);
+}
- dp_packet_set_dp_hash(newp, dp_packet_get_dp_hash(p));
+/* Prefixes 'size' bytes to the head end of 'b', reallocating and copying its
+ * data if necessary. Returns a pointer to the first byte of the data's
+ * location in the dp_packet. The new data is left uninitialized. */
+void *
+dp_packet_push_uninit(struct dp_packet *b, size_t size)
+{
+ dp_packet_prealloc_headroom(b, size);
+ dp_packet_set_data(b, (char*)dp_packet_data(b) - size);
+ dp_packet_set_size(b, dp_packet_size(b) + size);
+ return dp_packet_data(b);
+}
- return newp;
+/* Prefixes 'size' zeroed bytes to the head end of 'b', reallocating and
+ * copying its data if necessary. Returns a pointer to the first byte of the
+ * data's location in the dp_packet. */
+void *
+dp_packet_push_zeros(struct dp_packet *b, size_t size)
+{
+ void *dst = dp_packet_push_uninit(b, size);
+ memset(dst, 0, size);
+ return dst;
+}
+
+/* Copies the 'size' bytes starting at 'p' to the head end of 'b', reallocating
+ * and copying its data if necessary. Returns a pointer to the first byte of
+ * the data's location in the dp_packet. */
+void *
+dp_packet_push(struct dp_packet *b, const void *p, size_t size)
+{
+ void *dst = dp_packet_push_uninit(b, size);
+ memcpy(dst, p, size);
+ return dst;
+}
+
+/* Returns the data in 'b' as a block of malloc()'d memory and frees the buffer
+ * within 'b'. (If 'b' itself was dynamically allocated, e.g. with
+ * dp_packet_new(), then it should still be freed with, e.g., dp_packet_delete().) */
+void *
+dp_packet_steal_data(struct dp_packet *b)
+{
+ void *p;
+ ovs_assert(b->source != DPBUF_DPDK);
+
+ if (b->source == DPBUF_MALLOC && dp_packet_data(b) == dp_packet_base(b)) {
+ p = dp_packet_data(b);
+ } else {
+ p = xmemdup(dp_packet_data(b), dp_packet_size(b));
+ if (b->source == DPBUF_MALLOC) {
+ free(dp_packet_base(b));
+ }
+ }
+ dp_packet_set_base(b, NULL);
+ dp_packet_set_data(b, NULL);
+ return p;
+}
+
+/* Returns a string that describes some of 'b''s metadata plus a hex dump of up
+ * to 'maxbytes' from the start of the buffer. */
+char *
+dp_packet_to_string(const struct dp_packet *b, size_t maxbytes)
+{
+ struct ds s;
+
+ ds_init(&s);
+ ds_put_format(&s, "size=%"PRIu32", allocated=%"PRIu32", head=%"PRIuSIZE", tail=%"PRIuSIZE"\n",
+ dp_packet_size(b), b->allocated,
+ dp_packet_headroom(b), dp_packet_tailroom(b));
+ ds_put_hex_dump(&s, dp_packet_data(b), MIN(dp_packet_size(b), maxbytes), 0, false);
+ return ds_cstr(&s);
+}
+
+/* Removes each of the "struct dp_packet"s on 'list' from the list and frees
+ * them. */
+void
+dp_packet_list_delete(struct ovs_list *list)
+{
+ struct dp_packet *b, *next;
+
+ LIST_FOR_EACH_SAFE (b, next, list_node, list) {
+ list_remove(&b->list_node);
+ dp_packet_delete(b);
+ }
+}
+
+static inline void
+dp_packet_adjust_layer_offset(uint16_t *offset, int increment)
+{
+ if (*offset != UINT16_MAX) {
+ *offset += increment;
+ }
+}
+
+/* Adjust the size of the l2_5 portion of the dp_packet, updating the l2
+ * pointer and the layer offsets. The caller is responsible for
+ * modifying the contents. */
+void *
+dp_packet_resize_l2_5(struct dp_packet *b, int increment)
+{
+ if (increment >= 0) {
+ dp_packet_push_uninit(b, increment);
+ } else {
+ dp_packet_pull(b, -increment);
+ }
+
+ b->frame = dp_packet_data(b);
+ /* Adjust layer offsets after l2_5. */
+ dp_packet_adjust_layer_offset(&b->l3_ofs, increment);
+ dp_packet_adjust_layer_offset(&b->l4_ofs, increment);
+
+ return b->frame;
+}
+
+/* Adjust the size of the l2 portion of the dp_packet, updating the l2
+ * pointer and the layer offsets. The caller is responsible for
+ * modifying the contents. */
+void *
+dp_packet_resize_l2(struct dp_packet *b, int increment)
+{
+ dp_packet_resize_l2_5(b, increment);
+ dp_packet_adjust_layer_offset(&b->l2_5_ofs, increment);
+ return b->frame;
}
diff --git a/lib/dp-packet.h b/lib/dp-packet.h
index 74abdecfb..d754984ef 100644
--- a/lib/dp-packet.h
+++ b/lib/dp-packet.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2014 Nicira, Inc.
+ * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013 Nicira, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -14,43 +14,450 @@
* limitations under the License.
*/
-#ifndef PACKET_DPIF_H
-#define PACKET_DPIF_H 1
+#ifndef DPBUF_H
+#define DPBUF_H 1
-#include "ofpbuf.h"
+#include <stddef.h>
+#include <stdint.h>
+#include "list.h"
+#include "packets.h"
+#include "util.h"
+#include "netdev-dpdk.h"
#ifdef __cplusplus
extern "C" {
#endif
-/* A packet received from a netdev and passed to a dpif. */
+enum OVS_PACKED_ENUM dp_packet_source {
+ DPBUF_MALLOC, /* Obtained via malloc(). */
+ DPBUF_STACK, /* Un-movable stack space or static buffer. */
+ DPBUF_STUB, /* Starts on stack, may expand into heap. */
+ DPBUF_DPDK, /* buffer data is from DPDK allocated memory.
+ ref to build_dp_packet() in netdev-dpdk. */
+};
+/* Buffer for holding arbitrary data. An dp_packet is automatically reallocated
+ * as necessary if it grows too large for the available memory.
+ *
+ * 'frame' and offset conventions:
+ *
+ * Network frames (aka "packets"): 'frame' MUST be set to the start of the
+ * packet, layer offsets MAY be set as appropriate for the packet.
+ * Additionally, we assume in many places that the 'frame' and 'data' are
+ * the same for packets.
+ *
+ * OpenFlow messages: 'frame' points to the start of the OpenFlow
+ * header, while 'l3_ofs' is the length of the OpenFlow header.
+ * When parsing, the 'data' will move past these, as data is being
+ * pulled from the OpenFlow message.
+ *
+ * Actions: When encoding OVS action lists, the 'frame' is used
+ * as a pointer to the beginning of the current action (see ofpact_put()).
+ *
+ * rconn: Reuses 'frame' as a private pointer while queuing.
+ */
struct dp_packet {
- struct ofpbuf ofpbuf; /* Packet data. */
-#ifndef DPDK_NETDEV
+#ifdef DPDK_NETDEV
+ struct rte_mbuf mbuf; /* DPDK mbuf */
+#else
+ void *base_; /* First byte of allocated space. */
+ void *data_; /* First byte actually in use. */
+ uint32_t size_; /* Number of bytes in use. */
uint32_t dp_hash; /* Packet hash. */
#endif
+ uint32_t allocated; /* Number of bytes allocated. */
+
+ void *frame; /* Packet frame start, or NULL. */
+ enum dp_packet_source source; /* Source of memory allocated as 'base'. */
+ uint8_t l2_pad_size; /* Detected l2 padding size.
+ * Padding is non-pullable. */
+ uint16_t l2_5_ofs; /* MPLS label stack offset from 'frame', or
+ * UINT16_MAX */
+ uint16_t l3_ofs; /* Network-level header offset from 'frame',
+ or UINT16_MAX. */
+ uint16_t l4_ofs; /* Transport-level header offset from 'frame',
+ or UINT16_MAX. */
struct pkt_metadata md;
+ struct ovs_list list_node; /* Private list element for use by owner. */
};
-struct dp_packet *dp_packet_new_with_headroom(size_t size,
- size_t headroom);
+static inline void * dp_packet_data(const struct dp_packet *);
+static inline void dp_packet_set_data(struct dp_packet *, void *);
+static inline void * dp_packet_base(const struct dp_packet *);
+static inline void dp_packet_set_base(struct dp_packet *, void *);
+
+static inline uint32_t dp_packet_size(const struct dp_packet *);
+static inline void dp_packet_set_size(struct dp_packet *, uint32_t);
+
+void * dp_packet_resize_l2(struct dp_packet *, int increment);
+void * dp_packet_resize_l2_5(struct dp_packet *, int increment);
+static inline void * dp_packet_l2(const struct dp_packet *);
+static inline void dp_packet_set_frame(struct dp_packet *, void *);
+static inline uint8_t dp_packet_l2_pad_size(const struct dp_packet *);
+static inline void dp_packet_set_l2_pad_size(struct dp_packet *, uint8_t);
+static inline void * dp_packet_l2_5(const struct dp_packet *);
+static inline void dp_packet_set_l2_5(struct dp_packet *, void *);
+static inline void * dp_packet_l3(const struct dp_packet *);
+static inline void dp_packet_set_l3(struct dp_packet *, void *);
+static inline void * dp_packet_l4(const struct dp_packet *);
+static inline void dp_packet_set_l4(struct dp_packet *, void *);
+static inline size_t dp_packet_l4_size(const struct dp_packet *);
+static inline const void *dp_packet_get_tcp_payload(const struct dp_packet *);
+static inline const void *dp_packet_get_udp_payload(const struct dp_packet *);
+static inline const void *dp_packet_get_sctp_payload(const struct dp_packet *);
+static inline const void *dp_packet_get_icmp_payload(const struct dp_packet *);
+static inline const void *dp_packet_get_nd_payload(const struct dp_packet *);
+
+void dp_packet_use(struct dp_packet *, void *, size_t);
+void dp_packet_use_stub(struct dp_packet *, void *, size_t);
+void dp_packet_use_const(struct dp_packet *, const void *, size_t);
+
+void dp_packet_init_dpdk(struct dp_packet *b, size_t allocated);
+
+void dp_packet_init(struct dp_packet *, size_t);
+void dp_packet_uninit(struct dp_packet *);
+static inline void *dp_packet_get_uninit_pointer(struct dp_packet *);
+
+struct dp_packet *dp_packet_new(size_t);
+struct dp_packet *dp_packet_new_with_headroom(size_t, size_t headroom);
+struct dp_packet *dp_packet_clone(const struct dp_packet *);
+struct dp_packet *dp_packet_clone_with_headroom(const struct dp_packet *,
+ size_t headroom);
+struct dp_packet *dp_packet_clone_data(const void *, size_t);
+struct dp_packet *dp_packet_clone_data_with_headroom(const void *, size_t,
+ size_t headroom);
+static inline void dp_packet_delete(struct dp_packet *);
+
+static inline void *dp_packet_at(const struct dp_packet *, size_t offset,
+ size_t size);
+static inline void *dp_packet_at_assert(const struct dp_packet *, size_t offset,
+ size_t size);
+static inline void *dp_packet_tail(const struct dp_packet *);
+static inline void *dp_packet_end(const struct dp_packet *);
+
+void *dp_packet_put_uninit(struct dp_packet *, size_t);
+void *dp_packet_put_zeros(struct dp_packet *, size_t);
+void *dp_packet_put(struct dp_packet *, const void *, size_t);
+char *dp_packet_put_hex(struct dp_packet *, const char *s, size_t *n);
+void dp_packet_reserve(struct dp_packet *, size_t);
+void dp_packet_reserve_with_tailroom(struct dp_packet *b, size_t headroom,
+ size_t tailroom);
+void *dp_packet_push_uninit(struct dp_packet *b, size_t);
+void *dp_packet_push_zeros(struct dp_packet *, size_t);
+void *dp_packet_push(struct dp_packet *b, const void *, size_t);
+
+static inline size_t dp_packet_headroom(const struct dp_packet *);
+static inline size_t dp_packet_tailroom(const struct dp_packet *);
+void dp_packet_prealloc_headroom(struct dp_packet *, size_t);
+void dp_packet_prealloc_tailroom(struct dp_packet *, size_t);
+void dp_packet_shift(struct dp_packet *, int);
-struct dp_packet *dp_packet_clone_from_ofpbuf(const struct ofpbuf *b);
+static inline void dp_packet_clear(struct dp_packet *);
+static inline void *dp_packet_pull(struct dp_packet *, size_t);
+static inline void *dp_packet_try_pull(struct dp_packet *, size_t);
-struct dp_packet *dp_packet_clone(struct dp_packet *p);
+void *dp_packet_steal_data(struct dp_packet *);
-static inline void dp_packet_delete(struct dp_packet *p)
+char *dp_packet_to_string(const struct dp_packet *, size_t maxbytes);
+static inline struct dp_packet *dp_packet_from_list(const struct ovs_list *);
+void dp_packet_list_delete(struct ovs_list *);
+static inline bool dp_packet_equal(const struct dp_packet *, const struct dp_packet *);
+
+
+/* Returns a pointer that may be passed to free() to accomplish the same thing
+ * as dp_packet_uninit(b). The return value is a null pointer if dp_packet_uninit()
+ * would not free any memory. */
+static inline void *dp_packet_get_uninit_pointer(struct dp_packet *b)
+{
+ /* XXX: If 'source' is DPBUF_DPDK memory gets leaked! */
+ return b && b->source == DPBUF_MALLOC ? dp_packet_base(b) : NULL;
+}
+
+/* Frees memory that 'b' points to, as well as 'b' itself. */
+static inline void dp_packet_delete(struct dp_packet *b)
+{
+ if (b) {
+ if (b->source == DPBUF_DPDK) {
+ /* If this dp_packet was allocated by DPDK it must have been
+ * created as a dp_packet */
+ free_dpdk_buf((struct dp_packet*) b);
+ return;
+ }
+
+ dp_packet_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 *dp_packet_at(const struct dp_packet *b, size_t offset,
+ size_t size)
{
- struct ofpbuf *buf = &p->ofpbuf;
+ return offset + size <= dp_packet_size(b) ? (char *) dp_packet_data(b) + offset : NULL;
+}
- ofpbuf_delete(buf);
+/* Returns a pointer to byte 'offset' in 'b', which must contain at least
+ * 'offset + size' bytes of data. */
+static inline void *dp_packet_at_assert(const struct dp_packet *b, size_t offset,
+ size_t size)
+{
+ ovs_assert(offset + size <= dp_packet_size(b));
+ return ((char *) dp_packet_data(b)) + offset;
+}
+
+/* Returns a pointer to byte following the last byte of data in use in 'b'. */
+static inline void *dp_packet_tail(const struct dp_packet *b)
+{
+ return (char *) dp_packet_data(b) + dp_packet_size(b);
+}
+
+/* Returns a pointer to byte following the last byte allocated for use (but
+ * not necessarily in use) in 'b'. */
+static inline void *dp_packet_end(const struct dp_packet *b)
+{
+ return (char *) dp_packet_base(b) + b->allocated;
+}
+
+/* Returns the number of bytes of headroom in 'b', that is, the number of bytes
+ * of unused space in dp_packet 'b' before the data that is in use. (Most
+ * commonly, the data in a dp_packet is at its beginning, and thus the dp_packet's
+ * headroom is 0.) */
+static inline size_t dp_packet_headroom(const struct dp_packet *b)
+{
+ return (char*)dp_packet_data(b) - (char*)dp_packet_base(b);
+}
+
+/* Returns the number of bytes that may be appended to the tail end of dp_packet
+ * 'b' before the dp_packet must be reallocated. */
+static inline size_t dp_packet_tailroom(const struct dp_packet *b)
+{
+ return (char*)dp_packet_end(b) - (char*)dp_packet_tail(b);
+}
+
+/* Clears any data from 'b'. */
+static inline void dp_packet_clear(struct dp_packet *b)
+{
+ dp_packet_set_data(b, dp_packet_base(b));
+ dp_packet_set_size(b, 0);
+}
+
+/* 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 *dp_packet_pull(struct dp_packet *b, size_t size)
+{
+ void *data = dp_packet_data(b);
+ ovs_assert(dp_packet_size(b) - dp_packet_l2_pad_size(b) >= size);
+ dp_packet_set_data(b, (char*)dp_packet_data(b) + size);
+ dp_packet_set_size(b, dp_packet_size(b) - size);
+ 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 *dp_packet_try_pull(struct dp_packet *b, size_t size)
+{
+ return dp_packet_size(b) - dp_packet_l2_pad_size(b) >= size
+ ? dp_packet_pull(b, size) : NULL;
+}
+
+static inline struct dp_packet *dp_packet_from_list(const struct ovs_list *list)
+{
+ return CONTAINER_OF(list, struct dp_packet, list_node);
+}
+
+static inline bool dp_packet_equal(const struct dp_packet *a, const struct dp_packet *b)
+{
+ return dp_packet_size(a) == dp_packet_size(b) &&
+ memcmp(dp_packet_data(a), dp_packet_data(b), dp_packet_size(a)) == 0;
+}
+
+/* Get the start if the Ethernet frame. 'l3_ofs' marks the end of the l2
+ * headers, so return NULL if it is not set. */
+static inline void * dp_packet_l2(const struct dp_packet *b)
+{
+ return (b->l3_ofs != UINT16_MAX) ? b->frame : NULL;
+}
+
+/* Sets the packet frame start pointer and resets all layer offsets.
+ * l3 offset must be set before 'l2' can be retrieved. */
+static inline void dp_packet_set_frame(struct dp_packet *b, void *packet)
+{
+ b->frame = packet;
+ b->l2_pad_size = 0;
+ b->l2_5_ofs = UINT16_MAX;
+ b->l3_ofs = UINT16_MAX;
+ b->l4_ofs = UINT16_MAX;
+}
+
+static inline uint8_t dp_packet_l2_pad_size(const struct dp_packet *b)
+{
+ return b->l2_pad_size;
+}
+
+static inline void dp_packet_set_l2_pad_size(struct dp_packet *b, uint8_t pad_size)
+{
+ ovs_assert(pad_size <= dp_packet_size(b));
+ b->l2_pad_size = pad_size;
+}
+
+static inline void * dp_packet_l2_5(const struct dp_packet *b)
+{
+ return b->l2_5_ofs != UINT16_MAX ? (char *)b->frame + b->l2_5_ofs : NULL;
+}
+
+static inline void dp_packet_set_l2_5(struct dp_packet *b, void *l2_5)
+{
+ b->l2_5_ofs = l2_5 ? (char *)l2_5 - (char *)b->frame : UINT16_MAX;
+}
+
+static inline void * dp_packet_l3(const struct dp_packet *b)
+{
+ return b->l3_ofs != UINT16_MAX ? (char *)b->frame + b->l3_ofs : NULL;
+}
+
+static inline void dp_packet_set_l3(struct dp_packet *b, void *l3)
+{
+ b->l3_ofs = l3 ? (char *)l3 - (char *)b->frame : UINT16_MAX;
+}
+
+static inline void * dp_packet_l4(const struct dp_packet *b)
+{
+ return b->l4_ofs != UINT16_MAX ? (char *)b->frame + b->l4_ofs : NULL;
+}
+
+static inline void dp_packet_set_l4(struct dp_packet *b, void *l4)
+{
+ b->l4_ofs = l4 ? (char *)l4 - (char *)b->frame : UINT16_MAX;
+}
+
+static inline size_t dp_packet_l4_size(const struct dp_packet *b)
+{
+ return b->l4_ofs != UINT16_MAX
+ ? (const char *)dp_packet_tail(b) - (const char *)dp_packet_l4(b)
+ - dp_packet_l2_pad_size(b)
+ : 0;
+}
+
+static inline const void *dp_packet_get_tcp_payload(const struct dp_packet *b)
+{
+ size_t l4_size = dp_packet_l4_size(b);
+
+ if (OVS_LIKELY(l4_size >= TCP_HEADER_LEN)) {
+ struct tcp_header *tcp = dp_packet_l4(b);
+ 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 *dp_packet_get_udp_payload(const struct dp_packet *b)
+{
+ return OVS_LIKELY(dp_packet_l4_size(b) >= UDP_HEADER_LEN)
+ ? (const char *)dp_packet_l4(b) + UDP_HEADER_LEN : NULL;
+}
+
+static inline const void *dp_packet_get_sctp_payload(const struct dp_packet *b)
+{
+ return OVS_LIKELY(dp_packet_l4_size(b) >= SCTP_HEADER_LEN)
+ ? (const char *)dp_packet_l4(b) + SCTP_HEADER_LEN : NULL;
+}
+
+static inline const void *dp_packet_get_icmp_payload(const struct dp_packet *b)
+{
+ return OVS_LIKELY(dp_packet_l4_size(b) >= ICMP_HEADER_LEN)
+ ? (const char *)dp_packet_l4(b) + ICMP_HEADER_LEN : NULL;
+}
+
+static inline const void *dp_packet_get_nd_payload(const struct dp_packet *b)
+{
+ return OVS_LIKELY(dp_packet_l4_size(b) >= ND_MSG_LEN)
+ ? (const char *)dp_packet_l4(b) + ND_MSG_LEN : NULL;
+}
+
+#ifdef DPDK_NETDEV
+BUILD_ASSERT_DECL(offsetof(struct dp_packet, mbuf) == 0);
+
+static inline void * dp_packet_data(const struct dp_packet *b)
+{
+ return b->mbuf.pkt.data;
+}
+
+static inline void dp_packet_set_data(struct dp_packet *b, void *d)
+{
+ b->mbuf.pkt.data = d;
+}
+
+static inline void * dp_packet_base(const struct dp_packet *b)
+{
+ return b->mbuf.buf_addr;
+}
+
+static inline void dp_packet_set_base(struct dp_packet *b, void *d)
+{
+ b->mbuf.buf_addr = d;
+}
+
+static inline uint32_t dp_packet_size(const struct dp_packet *b)
+{
+ return b->mbuf.pkt.pkt_len;
+}
+
+static inline void dp_packet_set_size(struct dp_packet *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 * dp_packet_data(const struct dp_packet *b)
+{
+ return b->data_;
+}
+
+static inline void dp_packet_set_data(struct dp_packet *b, void *d)
+{
+ b->data_ = d;
+}
+
+static inline void * dp_packet_base(const struct dp_packet *b)
+{
+ return b->base_;
+}
+
+static inline void dp_packet_set_base(struct dp_packet *b, void *d)
+{
+ b->base_ = d;
+}
+
+static inline uint32_t dp_packet_size(const struct dp_packet *b)
+{
+ return b->size_;
+}
+
+static inline void dp_packet_set_size(struct dp_packet *b, uint32_t v)
+{
+ b->size_ = v;
+}
+#endif
+
+static inline void dp_packet_reset_packet(struct dp_packet *b, int off)
+{
+ dp_packet_set_size(b, dp_packet_size(b) - off);
+ dp_packet_set_data(b, (void *) ((unsigned char *) b->frame + off));
+ b->frame = NULL;
+ b->l2_5_ofs = b->l3_ofs = b->l4_ofs = UINT16_MAX;
}
static inline uint32_t dp_packet_get_dp_hash(struct dp_packet *p)
{
#ifdef DPDK_NETDEV
- return p->ofpbuf.mbuf.pkt.hash.rss;
+ return p->mbuf.pkt.hash.rss;
#else
return p->dp_hash;
#endif
@@ -60,7 +467,7 @@ static inline void dp_packet_set_dp_hash(struct dp_packet *p,
uint32_t hash)
{
#ifdef DPDK_NETDEV
- p->ofpbuf.mbuf.pkt.hash.rss = hash;
+ p->mbuf.pkt.hash.rss = hash;
#else
p->dp_hash = hash;
#endif
@@ -70,4 +477,4 @@ static inline void dp_packet_set_dp_hash(struct dp_packet *p,
}
#endif
-#endif /* dp-packet.h */
+#endif /* dp_packet.h */
diff --git a/lib/dpif-netdev.c b/lib/dpif-netdev.c
index 70ef97b82..531e5a36d 100644
--- a/lib/dpif-netdev.c
+++ b/lib/dpif-netdev.c
@@ -1323,16 +1323,16 @@ static void
netdev_flow_key_from_flow(struct netdev_flow_key *dst,
const struct flow *src)
{
- struct ofpbuf packet;
+ struct dp_packet packet;
uint64_t buf_stub[512 / 8];
- struct pkt_metadata md = pkt_metadata_from_flow(src);
miniflow_initialize(&dst->mf, dst->buf);
- ofpbuf_use_stub(&packet, buf_stub, sizeof buf_stub);
+ dp_packet_use_stub(&packet, buf_stub, sizeof buf_stub);
+ pkt_metadata_from_flow(&packet.md, src);
flow_compose(&packet, src);
- miniflow_extract(&packet, &md, &dst->mf);
- ofpbuf_uninit(&packet);
+ miniflow_extract(&packet, &dst->mf);
+ dp_packet_uninit(&packet);
dst->len = netdev_flow_key_size(count_1bits(dst->mf.map));
dst->hash = 0; /* Not computed yet. */
@@ -2046,17 +2046,13 @@ dpif_netdev_execute(struct dpif *dpif, struct dpif_execute *execute)
{
struct dp_netdev *dp = get_dp_netdev(dpif);
struct dp_netdev_pmd_thread *pmd;
- struct dp_packet packet, *pp;
+ struct dp_packet *pp;
- if (ofpbuf_size(execute->packet) < ETH_HEADER_LEN ||
- ofpbuf_size(execute->packet) > UINT16_MAX) {
+ if (dp_packet_size(execute->packet) < ETH_HEADER_LEN ||
+ dp_packet_size(execute->packet) > UINT16_MAX) {
return EINVAL;
}
- packet.ofpbuf = *execute->packet;
- packet.md = execute->md;
- pp = &packet;
-
/* Tries finding the 'pmd'. If NULL is returned, that means
* the current thread is a non-pmd thread and should use
* dp_netdev_get_pmd(dp, NON_PMD_CORE_ID). */
@@ -2072,6 +2068,7 @@ dpif_netdev_execute(struct dpif *dpif, struct dpif_execute *execute)
ovs_mutex_lock(&dp->port_mutex);
}
+ pp = execute->packet;
dp_netdev_execute_actions(pmd, &pp, 1, false, execute->actions,
execute->actions_len);
if (pmd->core_id == NON_PMD_CORE_ID) {
@@ -2080,11 +2077,6 @@ dpif_netdev_execute(struct dpif *dpif, struct dpif_execute *execute)
ovs_mutex_unlock(&dp->non_pmd_mutex);
}
- /* Even though may_steal is set to false, some actions could modify or
- * reallocate the ofpbuf memory. We need to pass those changes to the
- * caller */
- *execute->packet = packet.ofpbuf;
- execute->md = packet.md;
return 0;
}
@@ -2699,7 +2691,6 @@ dp_netdev_upcall(struct dp_netdev_pmd_thread *pmd, struct dp_packet *packet_,
struct ofpbuf *actions, struct ofpbuf *put_actions)
{
struct dp_netdev *dp = pmd->dp;
- struct ofpbuf *packet = &packet_->ofpbuf;
if (type == DPIF_UC_MISS) {
dp_netdev_count_packet(pmd, DP_STAT_MISS, 1);
@@ -2711,15 +2702,14 @@ dp_netdev_upcall(struct dp_netdev_pmd_thread *pmd, struct dp_packet *packet_,
if (OVS_UNLIKELY(!VLOG_DROP_DBG(&upcall_rl))) {
struct ds ds = DS_EMPTY_INITIALIZER;
- struct ofpbuf key;
char *packet_str;
+ struct ofpbuf key;
ofpbuf_init(&key, 0);
odp_flow_key_from_flow(&key, flow, &wc->masks, flow->in_port.odp_port,
true);
-
- packet_str = ofp_packet_to_string(ofpbuf_data(packet),
- ofpbuf_size(packet));
+ packet_str = ofp_packet_to_string(dp_packet_data(packet_),
+ dp_packet_size(packet_));
odp_flow_key_format(ofpbuf_data(&key), ofpbuf_size(&key), &ds);
@@ -2731,7 +2721,7 @@ dp_netdev_upcall(struct dp_netdev_pmd_thread *pmd, struct dp_packet *packet_,
ds_destroy(&ds);
}
- return dp->upcall_cb(packet, flow, ufid, pmd->core_id, type, userdata,
+ return dp->upcall_cb(packet_, flow, ufid, pmd->core_id, type, userdata,
actions, wc, put_actions, dp->upcall_aux);
}
@@ -2765,7 +2755,7 @@ packet_batch_update(struct packet_batch *batch, struct dp_packet *packet,
{
batch->tcp_flags |= miniflow_get_tcp_flags(mf);
batch->packets[batch->packet_count++] = packet;
- batch->byte_count += ofpbuf_size(&packet->ofpbuf);
+ batch->byte_count += dp_packet_size(packet);
}
static inline void
@@ -2862,12 +2852,12 @@ emc_processing(struct dp_netdev_pmd_thread *pmd, struct dp_packet **packets,
for (i = 0; i < cnt; i++) {
struct dp_netdev_flow *flow;
- if (OVS_UNLIKELY(ofpbuf_size(&packets[i]->ofpbuf) < ETH_HEADER_LEN)) {
+ if (OVS_UNLIKELY(dp_packet_size(packets[i]) < ETH_HEADER_LEN)) {
dp_packet_delete(packets[i]);
continue;
}
- miniflow_extract(&packets[i]->ofpbuf, &packets[i]->md, &key.mf);
+ miniflow_extract(packets[i], &key.mf);
key.len = 0; /* Not computed yet. */
key.hash = dpif_netdev_packet_get_dp_hash(packets[i], &key.mf);
@@ -3186,7 +3176,7 @@ dp_execute_cb(void *aux_, struct dp_packet **packets, int cnt,
ofpbuf_clear(&actions);
- flow_extract(&packets[i]->ofpbuf, &packets[i]->md, &flow);
+ flow_extract(packets[i], &flow);
dpif_flow_hash(dp->dpif, &flow, sizeof flow, &ufid);
error = dp_netdev_upcall(pmd, packets[i], &flow, NULL, &ufid,
DPIF_UC_ACTION, userdata,&actions,
diff --git a/lib/dpif-netdev.h b/lib/dpif-netdev.h
index 410fcfa15..5428b31a0 100644
--- a/lib/dpif-netdev.h
+++ b/lib/dpif-netdev.h
@@ -22,7 +22,7 @@
#include <stdint.h>
#include "dpif.h"
#include "openvswitch/types.h"
-#include "ofpbuf.h"
+#include "dp-packet.h"
#include "packets.h"
#ifdef __cplusplus
@@ -33,10 +33,10 @@ extern "C" {
* headers to be aligned on a 4-byte boundary. */
enum { DP_NETDEV_HEADROOM = 2 + VLAN_HEADER_LEN };
-static inline void dp_packet_pad(struct ofpbuf *b)
+static inline void dp_packet_pad(struct dp_packet *p)
{
- if (ofpbuf_size(b) < ETH_TOTAL_MIN) {
- ofpbuf_put_zeros(b, ETH_TOTAL_MIN - ofpbuf_size(b));
+ if (dp_packet_size(p) < ETH_TOTAL_MIN) {
+ dp_packet_put_zeros(p, ETH_TOTAL_MIN - dp_packet_size(p));
}
}
diff --git a/lib/dpif-netlink.c b/lib/dpif-netlink.c
index 337ebd6d0..15f83b910 100644
--- a/lib/dpif-netlink.c
+++ b/lib/dpif-netlink.c
@@ -1524,7 +1524,7 @@ dpif_netlink_encode_execute(int dp_ifindex, const struct dpif_execute *d_exec,
size_t key_ofs;
ofpbuf_prealloc_tailroom(buf, (64
- + ofpbuf_size(d_exec->packet)
+ + dp_packet_size(d_exec->packet)
+ ODP_KEY_METADATA_SIZE
+ d_exec->actions_len));
@@ -1535,11 +1535,11 @@ dpif_netlink_encode_execute(int dp_ifindex, const struct dpif_execute *d_exec,
k_exec->dp_ifindex = dp_ifindex;
nl_msg_put_unspec(buf, OVS_PACKET_ATTR_PACKET,
- ofpbuf_data(d_exec->packet),
- ofpbuf_size(d_exec->packet));
+ dp_packet_data(d_exec->packet),
+ dp_packet_size(d_exec->packet));
key_ofs = nl_msg_start_nested(buf, OVS_PACKET_ATTR_KEY);
- odp_key_from_pkt_metadata(buf, &d_exec->md);
+ odp_key_from_pkt_metadata(buf, &d_exec->packet->md);
nl_msg_end_nested(buf, key_ofs);
nl_msg_put_unspec(buf, OVS_PACKET_ATTR_ACTIONS,
@@ -1611,14 +1611,14 @@ dpif_netlink_operate__(struct dpif_netlink *dpif,
case DPIF_OP_EXECUTE:
/* Can't execute a packet that won't fit in a Netlink attribute. */
if (OVS_UNLIKELY(nl_attr_oversized(
- ofpbuf_size(op->u.execute.packet)))) {
+ dp_packet_size(op->u.execute.packet)))) {
/* Report an error immediately if this is the first operation.
* Otherwise the easiest thing to do is to postpone to the next
* call (when this will be the first operation). */
if (i == 0) {
VLOG_ERR_RL(&error_rl,
"dropping oversized %"PRIu32"-byte packet",
- ofpbuf_size(op->u.execute.packet));
+ dp_packet_size(op->u.execute.packet));
op->error = ENOBUFS;
return 1;
}
@@ -2002,14 +2002,14 @@ parse_odp_packet(const struct dpif_netlink *dpif, struct ofpbuf *buf,
upcall->out_tun_key = a[OVS_PACKET_ATTR_EGRESS_TUN_KEY];
/* Allow overwriting the netlink attribute header without reallocating. */
- ofpbuf_use_stub(&upcall->packet,
+ dp_packet_use_stub(&upcall->packet,
CONST_CAST(struct nlattr *,
nl_attr_get(a[OVS_PACKET_ATTR_PACKET])) - 1,
nl_attr_get_size(a[OVS_PACKET_ATTR_PACKET]) +
sizeof(struct nlattr));
- ofpbuf_set_data(&upcall->packet,
- (char *)ofpbuf_data(&upcall->packet) + sizeof(struct nlattr));
- ofpbuf_set_size(&upcall->packet, nl_attr_get_size(a[OVS_PACKET_ATTR_PACKET]));
+ dp_packet_set_data(&upcall->packet,
+ (char *)dp_packet_data(&upcall->packet) + sizeof(struct nlattr));
+ dp_packet_set_size(&upcall->packet, nl_attr_get_size(a[OVS_PACKET_ATTR_PACKET]));
*dp_ifindex = ovs_header->dp_ifindex;
diff --git a/lib/dpif.c b/lib/dpif.c
index 44cd54a5f..499def94b 100644
--- a/lib/dpif.c
+++ b/lib/dpif.c
@@ -805,11 +805,11 @@ dpif_port_poll_wait(const struct dpif *dpif)
* arguments must have been initialized through a call to flow_extract().
* 'used' is stored into stats->used. */
void
-dpif_flow_stats_extract(const struct flow *flow, const struct ofpbuf *packet,
+dpif_flow_stats_extract(const struct flow *flow, const struct dp_packet *packet,
long long int used, struct dpif_flow_stats *stats)
{
stats->tcp_flags = ntohs(flow->tcp_flags);
- stats->n_bytes = ofpbuf_size(packet);
+ stats->n_bytes = dp_packet_size(packet);
stats->n_packets = 1;
stats->used = used;
}
@@ -1080,8 +1080,7 @@ dpif_execute_helper_cb(void *aux_, struct dp_packet **packets, int cnt,
{
struct dpif_execute_helper_aux *aux = aux_;
int type = nl_attr_type(action);
- struct ofpbuf *packet = &packets[0]->ofpbuf;
- struct pkt_metadata *md = &packets[0]->md;
+ struct dp_packet *packet = *packets;
ovs_assert(cnt == 1);
@@ -1094,6 +1093,7 @@ dpif_execute_helper_cb(void *aux_, struct dp_packet **packets, int cnt,
struct dpif_execute execute;
struct ofpbuf execute_actions;
uint64_t stub[256 / 8];
+ struct pkt_metadata *md = &packet->md;
if (md->tunnel.ip_dst) {
/* The Linux kernel datapath throws away the tunnel information
@@ -1111,7 +1111,6 @@ dpif_execute_helper_cb(void *aux_, struct dp_packet **packets, int cnt,
}
execute.packet = packet;
- execute.md = *md;
execute.needs_help = false;
execute.probe = false;
aux->error = dpif_execute(aux->dpif, &execute);
@@ -1146,23 +1145,13 @@ static int
dpif_execute_with_help(struct dpif *dpif, struct dpif_execute *execute)
{
struct dpif_execute_helper_aux aux = {dpif, 0};
- struct dp_packet packet, *pp;
+ struct dp_packet *pp;
COVERAGE_INC(dpif_execute_with_help);
- packet.ofpbuf = *execute->packet;
- packet.md = execute->md;
- pp = &packet;
-
+ pp = execute->packet;
odp_execute_actions(&aux, &pp, 1, false, execute->actions,
execute->actions_len, dpif_execute_helper_cb);
-
- /* Even though may_steal is set to false, some actions could modify or
- * reallocate the ofpbuf memory. We need to pass those changes to the
- * caller */
- *execute->packet = packet.ofpbuf;
- execute->md = packet.md;
-
return aux.error;
}
@@ -1375,8 +1364,8 @@ dpif_print_packet(struct dpif *dpif, struct dpif_upcall *upcall)
struct ds flow;
char *packet;
- packet = ofp_packet_to_string(ofpbuf_data(&upcall->packet),
- ofpbuf_size(&upcall->packet));
+ packet = ofp_packet_to_string(dp_packet_data(&upcall->packet),
+ dp_packet_size(&upcall->packet));
ds_init(&flow);
odp_flow_key_format(upcall->key, upcall->key_len, &flow);
@@ -1671,8 +1660,8 @@ log_execute_message(struct dpif *dpif, const struct dpif_execute *execute,
struct ds ds = DS_EMPTY_INITIALIZER;
char *packet;
- packet = ofp_packet_to_string(ofpbuf_data(execute->packet),
- ofpbuf_size(execute->packet));
+ packet = ofp_packet_to_string(dp_packet_data(execute->packet),
+ dp_packet_size(execute->packet));
ds_put_format(&ds, "%s: %sexecute ",
dpif_name(dpif),
(subexecute ? "sub-"
diff --git a/lib/dpif.h b/lib/dpif.h
index 52d3f0201..06c652558 100644
--- a/lib/dpif.h
+++ b/lib/dpif.h
@@ -389,7 +389,7 @@
#include <stddef.h>
#include <stdint.h>
#include "netdev.h"
-#include "ofpbuf.h"
+#include "dp-packet.h"
#include "openflow/openflow.h"
#include "ovs-numa.h"
#include "packets.h"
@@ -505,7 +505,7 @@ struct dpif_flow_stats {
uint16_t tcp_flags;
};
-void dpif_flow_stats_extract(const struct flow *, const struct ofpbuf *packet,
+void dpif_flow_stats_extract(const struct flow *, const struct dp_packet *packet,
long long int used, struct dpif_flow_stats *);
void dpif_flow_stats_format(const struct dpif_flow_stats *, struct ds *);
@@ -699,8 +699,7 @@ struct dpif_execute {
bool probe; /* Suppress error messages. */
/* Input, but possibly modified as a side effect of execution. */
- struct ofpbuf *packet; /* Packet to execute. */
- struct pkt_metadata md; /* Packet metadata. */
+ struct dp_packet *packet; /* Packet to execute. */
};
/* Queries the dpif for a flow entry.
@@ -777,7 +776,7 @@ const char *dpif_upcall_type_to_string(enum dpif_upcall_type);
struct dpif_upcall {
/* All types. */
enum dpif_upcall_type type;
- struct ofpbuf packet; /* Packet data. */
+ struct dp_packet packet; /* Packet data. */
struct nlattr *key; /* Flow key. */
size_t key_len; /* Length of 'key' in bytes. */
ovs_u128 ufid; /* Unique flow identifier for 'key'. */
@@ -805,7 +804,7 @@ struct dpif_upcall {
*
* Returns 0 if successful, ENOSPC if the flow limit has been reached and no
* flow should be installed, or some otherwise a positive errno value. */
-typedef int upcall_callback(const struct ofpbuf *packet,
+typedef int upcall_callback(const struct dp_packet *packet,
const struct flow *flow,
ovs_u128 *ufid,
int pmd_id,
diff --git a/lib/flow.c b/lib/flow.c
index 81b36f927..965da4184 100644
--- a/lib/flow.c
+++ b/lib/flow.c
@@ -32,7 +32,7 @@
#include "hash.h"
#include "jhash.h"
#include "match.h"
-#include "ofpbuf.h"
+#include "dp-packet.h"
#include "openflow/openflow.h"
#include "packets.h"
#include "odp-util.h"
@@ -403,8 +403,7 @@ invalid:
* otherwise UINT16_MAX.
*/
void
-flow_extract(struct ofpbuf *packet, const struct pkt_metadata *md,
- struct flow *flow)
+flow_extract(struct dp_packet *packet, struct flow *flow)
{
struct {
struct miniflow mf;
@@ -414,18 +413,18 @@ flow_extract(struct ofpbuf *packet, const struct pkt_metadata *md,
COVERAGE_INC(flow_extract);
miniflow_initialize(&m.mf, m.buf);
- miniflow_extract(packet, md, &m.mf);
+ miniflow_extract(packet, &m.mf);
miniflow_expand(&m.mf, flow);
}
/* Caller is responsible for initializing 'dst' with enough storage for
* FLOW_U64S * 8 bytes. */
void
-miniflow_extract(struct ofpbuf *packet, const struct pkt_metadata *md,
- struct miniflow *dst)
+miniflow_extract(struct dp_packet *packet, struct miniflow *dst)
{
- void *data = ofpbuf_data(packet);
- size_t size = ofpbuf_size(packet);
+ const struct pkt_metadata *md = &packet->md;
+ void *data = dp_packet_data(packet);
+ size_t size = dp_packet_size(packet);
uint64_t *values = miniflow_values(dst);
struct mf_ctx mf = { 0, values, values + FLOW_U64S };
char *l2;
@@ -433,26 +432,24 @@ miniflow_extract(struct ofpbuf *packet, const struct pkt_metadata *md,
uint8_t nw_frag, nw_tos, nw_ttl, nw_proto;
/* Metadata. */
- if (md) {
- if (md->tunnel.ip_dst) {
- miniflow_push_words(mf, tunnel, &md->tunnel,
- sizeof md->tunnel / sizeof(uint64_t));
- }
- if (md->skb_priority || md->pkt_mark) {
- miniflow_push_uint32(mf, skb_priority, md->skb_priority);
- miniflow_push_uint32(mf, pkt_mark, md->pkt_mark);
- }
- miniflow_push_uint32(mf, dp_hash, md->dp_hash);
- miniflow_push_uint32(mf, in_port, odp_to_u32(md->in_port.odp_port));
- if (md->recirc_id) {
- miniflow_push_uint32(mf, recirc_id, md->recirc_id);
- miniflow_pad_to_64(mf, conj_id);
- }
+ if (md->tunnel.ip_dst) {
+ miniflow_push_words(mf, tunnel, &md->tunnel,
+ sizeof md->tunnel / sizeof(uint64_t));
+ }
+ if (md->skb_priority || md->pkt_mark) {
+ miniflow_push_uint32(mf, skb_priority, md->skb_priority);
+ miniflow_push_uint32(mf, pkt_mark, md->pkt_mark);
+ }
+ miniflow_push_uint32(mf, dp_hash, md->dp_hash);
+ miniflow_push_uint32(mf, in_port, odp_to_u32(md->in_port.odp_port));
+ if (md->recirc_id) {
+ miniflow_push_uint32(mf, recirc_id, md->recirc_id);
+ miniflow_pad_to_64(mf, conj_id);
}
/* Initialize packet's layer pointer and offsets. */
l2 = data;
- ofpbuf_set_frame(packet, data);
+ dp_packet_set_frame(packet, data);
/* Must have full Ethernet header to proceed. */
if (OVS_UNLIKELY(size < sizeof(struct eth_header))) {
@@ -508,7 +505,7 @@ miniflow_extract(struct ofpbuf *packet, const struct pkt_metadata *md,
if (OVS_UNLIKELY(size - tot_len > UINT8_MAX)) {
goto out;
}
- ofpbuf_set_l2_pad_size(packet, size - tot_len);
+ dp_packet_set_l2_pad_size(packet, size - tot_len);
size = tot_len; /* Never pull padding. */
/* Push both source and destination address at once. */
@@ -544,7 +541,7 @@ miniflow_extract(struct ofpbuf *packet, const struct pkt_metadata *md,
if (OVS_UNLIKELY(size - plen > UINT8_MAX)) {
goto out;
}
- ofpbuf_set_l2_pad_size(packet, size - plen);
+ dp_packet_set_l2_pad_size(packet, size - plen);
size = plen; /* Never pull padding. */
miniflow_push_words(mf, ipv6_src, &nh->ip6_src,
@@ -1707,7 +1704,7 @@ flow_set_mpls_lse(struct flow *flow, int idx, ovs_be32 lse)
}
static size_t
-flow_compose_l4(struct ofpbuf *b, const struct flow *flow)
+flow_compose_l4(struct dp_packet *p, const struct flow *flow)
{
size_t l4_len = 0;
@@ -1717,7 +1714,7 @@ flow_compose_l4(struct ofpbuf *b, const struct flow *flow)
struct tcp_header *tcp;
l4_len = sizeof *tcp;
- tcp = ofpbuf_put_zeros(b, l4_len);
+ tcp = dp_packet_put_zeros(p, l4_len);
tcp->tcp_src = flow->tp_src;
tcp->tcp_dst = flow->tp_dst;
tcp->tcp_ctl = TCP_CTL(ntohs(flow->tcp_flags), 5);
@@ -1725,21 +1722,21 @@ flow_compose_l4(struct ofpbuf *b, const struct flow *flow)
struct udp_header *udp;
l4_len = sizeof *udp;
- udp = ofpbuf_put_zeros(b, l4_len);
+ udp = dp_packet_put_zeros(p, l4_len);
udp->udp_src = flow->tp_src;
udp->udp_dst = flow->tp_dst;
} else if (flow->nw_proto == IPPROTO_SCTP) {
struct sctp_header *sctp;
l4_len = sizeof *sctp;
- sctp = ofpbuf_put_zeros(b, l4_len);
+ sctp = dp_packet_put_zeros(p, l4_len);
sctp->sctp_src = flow->tp_src;
sctp->sctp_dst = flow->tp_dst;
} else if (flow->nw_proto == IPPROTO_ICMP) {
struct icmp_header *icmp;
l4_len = sizeof *icmp;
- icmp = ofpbuf_put_zeros(b, l4_len);
+ icmp = dp_packet_put_zeros(p, l4_len);
icmp->icmp_type = ntohs(flow->tp_src);
icmp->icmp_code = ntohs(flow->tp_dst);
icmp->icmp_csum = csum(icmp, ICMP_HEADER_LEN);
@@ -1747,7 +1744,7 @@ flow_compose_l4(struct ofpbuf *b, const struct flow *flow)
struct igmp_header *igmp;
l4_len = sizeof *igmp;
- igmp = ofpbuf_put_zeros(b, l4_len);
+ igmp = dp_packet_put_zeros(p, l4_len);
igmp->igmp_type = ntohs(flow->tp_src);
igmp->igmp_code = ntohs(flow->tp_dst);
put_16aligned_be32(&igmp->group, flow->igmp_group_ip4);
@@ -1756,7 +1753,7 @@ flow_compose_l4(struct ofpbuf *b, const struct flow *flow)
struct icmp6_hdr *icmp;
l4_len = sizeof *icmp;
- icmp = ofpbuf_put_zeros(b, l4_len);
+ icmp = dp_packet_put_zeros(p, l4_len);
icmp->icmp6_type = ntohs(flow->tp_src);
icmp->icmp6_code = ntohs(flow->tp_dst);
@@ -1767,26 +1764,26 @@ flow_compose_l4(struct ofpbuf *b, const struct flow *flow)
struct nd_opt_hdr *nd_opt;
l4_len += sizeof *nd_target;
- nd_target = ofpbuf_put_zeros(b, sizeof *nd_target);
+ nd_target = dp_packet_put_zeros(p, sizeof *nd_target);
*nd_target = flow->nd_target;
if (!eth_addr_is_zero(flow->arp_sha)) {
l4_len += 8;
- nd_opt = ofpbuf_put_zeros(b, 8);
+ nd_opt = dp_packet_put_zeros(p, 8);
nd_opt->nd_opt_len = 1;
nd_opt->nd_opt_type = ND_OPT_SOURCE_LINKADDR;
memcpy(nd_opt + 1, flow->arp_sha, ETH_ADDR_LEN);
}
if (!eth_addr_is_zero(flow->arp_tha)) {
l4_len += 8;
- nd_opt = ofpbuf_put_zeros(b, 8);
+ nd_opt = dp_packet_put_zeros(p, 8);
nd_opt->nd_opt_len = 1;
nd_opt->nd_opt_type = ND_OPT_TARGET_LINKADDR;
memcpy(nd_opt + 1, flow->arp_tha, ETH_ADDR_LEN);
}
}
icmp->icmp6_cksum = (OVS_FORCE uint16_t)
- csum(icmp, (char *)ofpbuf_tail(b) - (char *)icmp);
+ csum(icmp, (char *)dp_packet_tail(p) - (char *)icmp);
}
}
return l4_len;
@@ -1799,26 +1796,26 @@ flow_compose_l4(struct ofpbuf *b, const struct flow *flow)
* valid. It hasn't got some checksums filled in, for one, and lots of fields
* are just zeroed.) */
void
-flow_compose(struct ofpbuf *b, const struct flow *flow)
+flow_compose(struct dp_packet *p, const struct flow *flow)
{
size_t l4_len;
/* eth_compose() sets l3 pointer and makes sure it is 32-bit aligned. */
- eth_compose(b, flow->dl_dst, flow->dl_src, ntohs(flow->dl_type), 0);
+ eth_compose(p, flow->dl_dst, flow->dl_src, ntohs(flow->dl_type), 0);
if (flow->dl_type == htons(FLOW_DL_TYPE_NONE)) {
- struct eth_header *eth = ofpbuf_l2(b);
- eth->eth_type = htons(ofpbuf_size(b));
+ struct eth_header *eth = dp_packet_l2(p);
+ eth->eth_type = htons(dp_packet_size(p));
return;
}
if (flow->vlan_tci & htons(VLAN_CFI)) {
- eth_push_vlan(b, htons(ETH_TYPE_VLAN), flow->vlan_tci);
+ eth_push_vlan(p, htons(ETH_TYPE_VLAN), flow->vlan_tci);
}
if (flow->dl_type == htons(ETH_TYPE_IP)) {
struct ip_header *ip;
- ip = ofpbuf_put_zeros(b, sizeof *ip);
+ ip = dp_packet_put_zeros(p, sizeof *ip);
ip->ip_ihl_ver = IP_IHL_VER(5, 4);
ip->ip_tos = flow->nw_tos;
ip->ip_ttl = flow->nw_ttl;
@@ -1833,17 +1830,17 @@ flow_compose(struct ofpbuf *b, const struct flow *flow)
}
}
- ofpbuf_set_l4(b, ofpbuf_tail(b));
+ dp_packet_set_l4(p, dp_packet_tail(p));
- l4_len = flow_compose_l4(b, flow);
+ l4_len = flow_compose_l4(p, flow);
- ip = ofpbuf_l3(b);
- ip->ip_tot_len = htons(b->l4_ofs - b->l3_ofs + l4_len);
+ ip = dp_packet_l3(p);
+ ip->ip_tot_len = htons(p->l4_ofs - p->l3_ofs + l4_len);
ip->ip_csum = csum(ip, sizeof *ip);
} else if (flow->dl_type == htons(ETH_TYPE_IPV6)) {
struct ovs_16aligned_ip6_hdr *nh;
- nh = ofpbuf_put_zeros(b, sizeof *nh);
+ nh = dp_packet_put_zeros(p, sizeof *nh);
put_16aligned_be32(&nh->ip6_flow, htonl(6 << 28) |
htonl(flow->nw_tos << 20) | flow->ipv6_label);
nh->ip6_hlim = flow->nw_ttl;
@@ -1852,18 +1849,18 @@ flow_compose(struct ofpbuf *b, const struct flow *flow)
memcpy(&nh->ip6_src, &flow->ipv6_src, sizeof(nh->ip6_src));
memcpy(&nh->ip6_dst, &flow->ipv6_dst, sizeof(nh->ip6_dst));
- ofpbuf_set_l4(b, ofpbuf_tail(b));
+ dp_packet_set_l4(p, dp_packet_tail(p));
- l4_len = flow_compose_l4(b, flow);
+ l4_len = flow_compose_l4(p, flow);
- nh = ofpbuf_l3(b);
+ nh = dp_packet_l3(p);
nh->ip6_plen = htons(l4_len);
} else if (flow->dl_type == htons(ETH_TYPE_ARP) ||
flow->dl_type == htons(ETH_TYPE_RARP)) {
struct arp_eth_header *arp;
- arp = ofpbuf_put_zeros(b, sizeof *arp);
- ofpbuf_set_l3(b, arp);
+ arp = dp_packet_put_zeros(p, sizeof *arp);
+ dp_packet_set_l3(p, arp);
arp->ar_hrd = htons(1);
arp->ar_pro = htons(ETH_TYPE_IP);
arp->ar_hln = ETH_ADDR_LEN;
@@ -1882,14 +1879,14 @@ flow_compose(struct ofpbuf *b, const struct flow *flow)
if (eth_type_mpls(flow->dl_type)) {
int n;
- b->l2_5_ofs = b->l3_ofs;
+ p->l2_5_ofs = p->l3_ofs;
for (n = 1; n < FLOW_MAX_MPLS_LABELS; n++) {
if (flow->mpls_lse[n - 1] & htonl(MPLS_BOS_MASK)) {
break;
}
}
while (n > 0) {
- push_mpls(b, flow->dl_type, flow->mpls_lse[--n]);
+ push_mpls(p, flow->dl_type, flow->mpls_lse[--n]);
}
}
}
diff --git a/lib/flow.h b/lib/flow.h
index f503097cd..dcb5bb030 100644
--- a/lib/flow.h
+++ b/lib/flow.h
@@ -32,7 +32,7 @@ struct dpif_flow_stats;
struct ds;
struct flow_wildcards;
struct minimask;
-struct ofpbuf;
+struct dp_packet;
struct pkt_metadata;
/* This sequence number should be incremented whenever anything involving flows
@@ -194,8 +194,7 @@ struct flow_metadata {
ofp_port_t in_port; /* OpenFlow port or zero. */
};
-void flow_extract(struct ofpbuf *, const struct pkt_metadata *md,
- struct flow *);
+void flow_extract(struct dp_packet *, struct flow *);
void flow_zero_wildcards(struct flow *, const struct flow_wildcards *);
void flow_unwildcard_tp_ports(const struct flow *, struct flow_wildcards *);
@@ -232,7 +231,7 @@ void flow_set_mpls_tc(struct flow *, int idx, uint8_t tc);
void flow_set_mpls_bos(struct flow *, int idx, uint8_t stack);
void flow_set_mpls_lse(struct flow *, int idx, ovs_be32 lse);
-void flow_compose(struct ofpbuf *, const struct flow *);
+void flow_compose(struct dp_packet *, const struct flow *);
static inline uint64_t
flow_get_xreg(const struct flow *flow, int idx)
@@ -451,8 +450,7 @@ struct pkt_metadata;
/* The 'dst->values' must be initialized with a buffer with space for
* FLOW_U64S. 'dst->map' is ignored on input and set on output to
* indicate which fields were extracted. */
-void miniflow_extract(struct ofpbuf *packet, const struct pkt_metadata *,
- struct miniflow *dst);
+void miniflow_extract(struct dp_packet *packet, struct miniflow *dst);
void miniflow_init(struct miniflow *, const struct flow *);
void miniflow_init_with_minimask(struct miniflow *, const struct flow *,
const struct minimask *);
@@ -746,19 +744,15 @@ flow_union_with_miniflow(struct flow *dst, const struct miniflow *src)
}
}
-static inline struct pkt_metadata
-pkt_metadata_from_flow(const struct flow *flow)
-{
- struct pkt_metadata md;
-
- md.recirc_id = flow->recirc_id;
- md.dp_hash = flow->dp_hash;
- md.tunnel = flow->tunnel;
- md.skb_priority = flow->skb_priority;
- md.pkt_mark = flow->pkt_mark;
- md.in_port = flow->in_port;
-
- return md;
+static inline void
+pkt_metadata_from_flow(struct pkt_metadata *md, const struct flow *flow)
+{
+ md->recirc_id = flow->recirc_id;
+ md->dp_hash = flow->dp_hash;
+ md->tunnel = flow->tunnel;
+ md->skb_priority = flow->skb_priority;
+ md->pkt_mark = flow->pkt_mark;
+ md->in_port = flow->in_port;
}
static inline bool is_ip_any(const struct flow *flow)
diff --git a/lib/lacp.c b/lib/lacp.c
index 6f526522e..6535e6dfe 100644
--- a/lib/lacp.c
+++ b/lib/lacp.c
@@ -22,7 +22,7 @@
#include "dynamic-string.h"
#include "hash.h"
#include "hmap.h"
-#include "ofpbuf.h"
+#include "dp-packet.h"
#include "packets.h"
#include "poll-loop.h"
#include "seq.h"
@@ -181,11 +181,11 @@ compose_lacp_pdu(const struct lacp_info *actor,
* supported by OVS. Otherwise, it returns a pointer to the lacp_pdu contained
* within 'b'. */
static const struct lacp_pdu *
-parse_lacp_packet(const struct ofpbuf *b)
+parse_lacp_packet(const struct dp_packet *p)
{
const struct lacp_pdu *pdu;
- pdu = ofpbuf_at(b, (uint8_t *)ofpbuf_l3(b) - (uint8_t *)ofpbuf_data(b),
+ pdu = dp_packet_at(p, (uint8_t *)dp_packet_l3(p) - (uint8_t *)dp_packet_data(p),
LACP_PDU_LEN);
if (pdu && pdu->subtype == 1
@@ -319,7 +319,7 @@ lacp_is_active(const struct lacp *lacp) OVS_EXCLUDED(mutex)
*/
void
lacp_process_packet(struct lacp *lacp, const void *slave_,
- const struct ofpbuf *packet)
+ const struct dp_packet *packet)
OVS_EXCLUDED(mutex)
{
static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(1, 5);
diff --git a/lib/lacp.h b/lib/lacp.h
index 4295f7b32..f56001b7f 100644
--- a/lib/lacp.h
+++ b/lib/lacp.h
@@ -47,7 +47,7 @@ void lacp_configure(struct lacp *, const struct lacp_settings *);
bool lacp_is_active(const struct lacp *);
void lacp_process_packet(struct lacp *, const void *slave,
- const struct ofpbuf *packet);
+ const struct dp_packet *packet);
enum lacp_status lacp_status(const struct lacp *);
struct lacp_slave_settings {
diff --git a/lib/learning-switch.c b/lib/learning-switch.c
index d03e52ed7..9ea70836e 100644
--- a/lib/learning-switch.c
+++ b/lib/learning-switch.c
@@ -25,6 +25,7 @@
#include "byte-order.h"
#include "classifier.h"
+#include "dp-packet.h"
#include "flow.h"
#include "hmap.h"
#include "mac-learning.h"
@@ -604,7 +605,7 @@ process_packet_in(struct lswitch *sw, const struct ofp_header *oh)
struct ofputil_packet_out po;
enum ofperr error;
- struct ofpbuf pkt;
+ struct dp_packet pkt;
struct flow flow;
error = ofputil_decode_packet_in(&pi, oh);
@@ -622,8 +623,8 @@ process_packet_in(struct lswitch *sw, const struct ofp_header *oh)
}
/* Extract flow data from 'opi' into 'flow'. */
- ofpbuf_use_const(&pkt, pi.packet, pi.packet_len);
- flow_extract(&pkt, NULL, &flow);
+ dp_packet_use_const(&pkt, pi.packet, pi.packet_len);
+ flow_extract(&pkt, &flow);
flow.in_port.ofp_port = pi.fmd.in_port;
flow.tunnel.tun_id = pi.fmd.tun_id;
@@ -648,8 +649,8 @@ process_packet_in(struct lswitch *sw, const struct ofp_header *oh)
/* Prepare packet_out in case we need one. */
po.buffer_id = pi.buffer_id;
if (po.buffer_id == UINT32_MAX) {
- po.packet = ofpbuf_data(&pkt);
- po.packet_len = ofpbuf_size(&pkt);
+ po.packet = dp_packet_data(&pkt);
+ po.packet_len = dp_packet_size(&pkt);
} else {
po.packet = NULL;
po.packet_len = 0;
diff --git a/lib/netdev-bsd.c b/lib/netdev-bsd.c
index 36a2642a4..7dfff131e 100644
--- a/lib/netdev-bsd.c
+++ b/lib/netdev-bsd.c
@@ -52,7 +52,7 @@
#include "dpif-netdev.h"
#include "dynamic-string.h"
#include "fatal-signal.h"
-#include "ofpbuf.h"
+#include "dp_packet.h"
#include "openflow/openflow.h"
#include "ovs-thread.h"
#include "packets.h"
@@ -569,20 +569,20 @@ proc_pkt(u_char *args_, const struct pcap_pkthdr *hdr, const u_char *packet)
* from rxq->pcap.
*/
static int
-netdev_rxq_bsd_recv_pcap(struct netdev_rxq_bsd *rxq, struct ofpbuf *buffer)
+netdev_rxq_bsd_recv_pcap(struct netdev_rxq_bsd *rxq, struct dp_packet *buffer)
{
struct pcap_arg arg;
int ret;
/* prepare the pcap argument to store the packet */
- arg.size = ofpbuf_tailroom(buffer);
- arg.data = ofpbuf_data(buffer);
+ arg.size = dp_packet_tailroom(buffer);
+ arg.data = dp_packet_data(buffer);
for (;;) {
ret = pcap_dispatch(rxq->pcap_handle, 1, proc_pkt, (u_char *) &arg);
if (ret > 0) {
- ofpbuf_set_size(buffer, ofpbuf_size(buffer) + arg.retval);
+ dp_packet_set_size(buffer, dp_packet_size(buffer) + arg.retval);
return 0;
}
if (ret == -1) {
@@ -601,14 +601,14 @@ netdev_rxq_bsd_recv_pcap(struct netdev_rxq_bsd *rxq, struct ofpbuf *buffer)
* 'rxq->fd' is initialized with the tap file descriptor.
*/
static int
-netdev_rxq_bsd_recv_tap(struct netdev_rxq_bsd *rxq, struct ofpbuf *buffer)
+netdev_rxq_bsd_recv_tap(struct netdev_rxq_bsd *rxq, struct dp_packet *buffer)
{
- size_t size = ofpbuf_tailroom(buffer);
+ size_t size = dp_packet_tailroom(buffer);
for (;;) {
- ssize_t retval = read(rxq->fd, ofpbuf_data(buffer), size);
+ ssize_t retval = read(rxq->fd, dp_packet_data(buffer), size);
if (retval >= 0) {
- ofpbuf_set_size(buffer, ofpbuf_size(buffer) + retval);
+ dp_packet_set_size(buffer, dp_packet_size(buffer) + retval);
return 0;
} else if (errno != EINTR) {
if (errno != EAGAIN) {
@@ -627,7 +627,6 @@ netdev_bsd_rxq_recv(struct netdev_rxq *rxq_, struct dp_packet **packets,
struct netdev_rxq_bsd *rxq = netdev_rxq_bsd_cast(rxq_);
struct netdev *netdev = rxq->up.netdev;
struct dp_packet *packet;
- struct ofpbuf *buffer;
ssize_t retval;
int mtu;
@@ -637,16 +636,14 @@ netdev_bsd_rxq_recv(struct netdev_rxq *rxq_, struct dp_packet **packets,
packet = dp_packet_new_with_headroom(VLAN_ETH_HEADER_LEN + mtu,
DP_NETDEV_HEADROOM);
- buffer = &packet->ofpbuf;
-
retval = (rxq->pcap_handle
- ? netdev_rxq_bsd_recv_pcap(rxq, buffer)
- : netdev_rxq_bsd_recv_tap(rxq, buffer));
+ ? netdev_rxq_bsd_recv_pcap(rxq, packet)
+ : netdev_rxq_bsd_recv_tap(rxq, packet));
if (retval) {
dp_packet_delete(packet);
} else {
- dp_packet_pad(buffer);
+ dp_packet_pad(packet);
dp_packet_set_dp_hash(packet, 0);
packets[0] = packet;
*c = 1;
@@ -703,8 +700,8 @@ netdev_bsd_send(struct netdev *netdev_, int qid OVS_UNUSED,
}
for (i = 0; i < cnt; i++) {
- const void *data = ofpbuf_data(&pkts[i]->ofpbuf);
- size_t size = ofpbuf_size(&pkts[i]->ofpbuf);
+ const void *data = dp_packet_data(pkts[i]);
+ size_t size = dp_packet_size(pkts[i]);
while (!error) {
ssize_t retval;
diff --git a/lib/netdev-dpdk.c b/lib/netdev-dpdk.c
index 34dd70689..2d560548e 100644
--- a/lib/netdev-dpdk.c
+++ b/lib/netdev-dpdk.c
@@ -36,7 +36,6 @@
#include "netdev-vport.h"
#include "odp-util.h"
#include "ofp-print.h"
-#include "ofpbuf.h"
#include "ovs-numa.h"
#include "ovs-thread.h"
#include "ovs-rcu.h"
@@ -284,7 +283,7 @@ ovs_rte_pktmbuf_init(struct rte_mempool *mp,
__rte_pktmbuf_init(mp, opaque_arg, _m, i);
- ofpbuf_init_dpdk((struct ofpbuf *) m, m->buf_len);
+ dp_packet_init_dpdk((struct dp_packet *) m, m->buf_len);
}
static struct dpdk_mp *
@@ -807,7 +806,7 @@ dpdk_do_tx_copy(struct netdev *netdev, int qid, struct dp_packet ** pkts,
}
for (i = 0; i < cnt; i++) {
- int size = ofpbuf_size(&pkts[i]->ofpbuf);
+ int size = dp_packet_size(pkts[i]);
if (OVS_UNLIKELY(size > dev->max_packet_len)) {
VLOG_WARN_RL(&rl, "Too big size %d max_packet_len %d",
@@ -825,7 +824,7 @@ dpdk_do_tx_copy(struct netdev *netdev, int qid, struct dp_packet ** pkts,
}
/* We have to do a copy for now */
- memcpy(mbufs[newcnt]->pkt.data, ofpbuf_data(&pkts[i]->ofpbuf), size);
+ memcpy(mbufs[newcnt]->pkt.data, dp_packet_data(pkts[i]), size);
rte_pktmbuf_data_len(mbufs[newcnt]) = size;
rte_pktmbuf_pkt_len(mbufs[newcnt]) = size;
@@ -854,7 +853,7 @@ netdev_dpdk_send__(struct netdev_dpdk *dev, int qid,
int i;
if (OVS_UNLIKELY(!may_steal ||
- pkts[0]->ofpbuf.source != OFPBUF_DPDK)) {
+ pkts[0]->source != DPBUF_DPDK)) {
struct netdev *netdev = &dev->up;
dpdk_do_tx_copy(netdev, qid, pkts, cnt);
@@ -869,7 +868,7 @@ netdev_dpdk_send__(struct netdev_dpdk *dev, int qid,
int dropped = 0;
for (i = 0; i < cnt; i++) {
- int size = ofpbuf_size(&pkts[i]->ofpbuf);
+ int size = dp_packet_size(pkts[i]);
if (OVS_UNLIKELY(size > dev->max_packet_len)) {
if (next_tx_idx != i) {
dpdk_queue_pkts(dev, qid,
diff --git a/lib/netdev-dummy.c b/lib/netdev-dummy.c
index 5abac3144..f1da891ca 100644
--- a/lib/netdev-dummy.c
+++ b/lib/netdev-dummy.c
@@ -48,7 +48,7 @@ struct reconnect;
struct dummy_packet_stream {
struct stream *stream;
- struct ofpbuf rxbuf;
+ struct dp_packet rxbuf;
struct ovs_list txq;
};
@@ -126,7 +126,7 @@ struct netdev_rxq_dummy {
static unixctl_cb_func netdev_dummy_set_admin_state;
static int netdev_dummy_construct(struct netdev *);
-static void netdev_dummy_queue_packet(struct netdev_dummy *, struct ofpbuf *);
+static void netdev_dummy_queue_packet(struct netdev_dummy *, struct dp_packet *);
static void dummy_packet_stream_close(struct dummy_packet_stream *);
@@ -155,7 +155,7 @@ dummy_packet_stream_init(struct dummy_packet_stream *s, struct stream *stream)
{
int rxbuf_size = stream ? 2048 : 0;
s->stream = stream;
- ofpbuf_init(&s->rxbuf, rxbuf_size);
+ dp_packet_init(&s->rxbuf, rxbuf_size);
list_init(&s->txq);
}
@@ -184,10 +184,10 @@ static void
dummy_packet_stream_send(struct dummy_packet_stream *s, const void *buffer, size_t size)
{
if (list_size(&s->txq) < NETDEV_DUMMY_MAX_QUEUE) {
- struct ofpbuf *b;
+ struct dp_packet *b;
- b = ofpbuf_clone_data_with_headroom(buffer, size, 2);
- put_unaligned_be16(ofpbuf_push_uninit(b, 2), htons(size));
+ b = dp_packet_clone_data_with_headroom(buffer, size, 2);
+ put_unaligned_be16(dp_packet_push_uninit(b, 2), htons(size));
list_push_back(&s->txq, &b->list_node);
}
}
@@ -201,17 +201,17 @@ dummy_packet_stream_run(struct netdev_dummy *dev, struct dummy_packet_stream *s)
stream_run(s->stream);
if (!list_is_empty(&s->txq)) {
- struct ofpbuf *txbuf;
+ struct dp_packet *txbuf;
int retval;
- txbuf = ofpbuf_from_list(list_front(&s->txq));
- retval = stream_send(s->stream, ofpbuf_data(txbuf), ofpbuf_size(txbuf));
+ txbuf = dp_packet_from_list(list_front(&s->txq));
+ retval = stream_send(s->stream, dp_packet_data(txbuf), dp_packet_size(txbuf));
if (retval > 0) {
- ofpbuf_pull(txbuf, retval);
- if (!ofpbuf_size(txbuf)) {
+ dp_packet_pull(txbuf, retval);
+ if (!dp_packet_size(txbuf)) {
list_remove(&txbuf->list_node);
- ofpbuf_delete(txbuf);
+ dp_packet_delete(txbuf);
}
} else if (retval != -EAGAIN) {
error = -retval;
@@ -219,37 +219,37 @@ dummy_packet_stream_run(struct netdev_dummy *dev, struct dummy_packet_stream *s)
}
if (!error) {
- if (ofpbuf_size(&s->rxbuf) < 2) {
- n = 2 - ofpbuf_size(&s->rxbuf);
+ if (dp_packet_size(&s->rxbuf) < 2) {
+ n = 2 - dp_packet_size(&s->rxbuf);
} else {
uint16_t frame_len;
- frame_len = ntohs(get_unaligned_be16(ofpbuf_data(&s->rxbuf)));
+ frame_len = ntohs(get_unaligned_be16(dp_packet_data(&s->rxbuf)));
if (frame_len < ETH_HEADER_LEN) {
error = EPROTO;
n = 0;
} else {
- n = (2 + frame_len) - ofpbuf_size(&s->rxbuf);
+ n = (2 + frame_len) - dp_packet_size(&s->rxbuf);
}
}
}
if (!error) {
int retval;
- ofpbuf_prealloc_tailroom(&s->rxbuf, n);
- retval = stream_recv(s->stream, ofpbuf_tail(&s->rxbuf), n);
+ dp_packet_prealloc_tailroom(&s->rxbuf, n);
+ retval = stream_recv(s->stream, dp_packet_tail(&s->rxbuf), n);
if (retval > 0) {
- ofpbuf_set_size(&s->rxbuf, ofpbuf_size(&s->rxbuf) + retval);
- if (retval == n && ofpbuf_size(&s->rxbuf) > 2) {
- ofpbuf_pull(&s->rxbuf, 2);
+ dp_packet_set_size(&s->rxbuf, dp_packet_size(&s->rxbuf) + retval);
+ if (retval == n && dp_packet_size(&s->rxbuf) > 2) {
+ dp_packet_pull(&s->rxbuf, 2);
netdev_dummy_queue_packet(dev,
- ofpbuf_clone(&s->rxbuf));
- ofpbuf_clear(&s->rxbuf);
+ dp_packet_clone(&s->rxbuf));
+ dp_packet_clear(&s->rxbuf);
}
} else if (retval != -EAGAIN) {
error = (retval < 0 ? -retval
- : ofpbuf_size(&s->rxbuf) ? EPROTO
+ : dp_packet_size(&s->rxbuf) ? EPROTO
: EOF);
}
}
@@ -261,8 +261,8 @@ static void
dummy_packet_stream_close(struct dummy_packet_stream *s)
{
stream_close(s->stream);
- ofpbuf_uninit(&s->rxbuf);
- ofpbuf_list_delete(&s->txq);
+ dp_packet_uninit(&s->rxbuf);
+ dp_packet_list_delete(&s->txq);
}
static void
@@ -794,7 +794,7 @@ netdev_dummy_rxq_destruct(struct netdev_rxq *rxq_)
ovs_mutex_lock(&netdev->mutex);
list_remove(&rx->node);
- ofpbuf_list_delete(&rx->recv_queue);
+ dp_packet_list_delete(&rx->recv_queue);
ovs_mutex_unlock(&netdev->mutex);
seq_destroy(rx->seq);
}
@@ -813,11 +813,11 @@ netdev_dummy_rxq_recv(struct netdev_rxq *rxq_, struct dp_packet **arr,
{
struct netdev_rxq_dummy *rx = netdev_rxq_dummy_cast(rxq_);
struct netdev_dummy *netdev = netdev_dummy_cast(rx->up.netdev);
- struct ofpbuf *packet;
+ struct dp_packet *packet;
ovs_mutex_lock(&netdev->mutex);
if (!list_is_empty(&rx->recv_queue)) {
- packet = ofpbuf_from_list(list_pop_front(&rx->recv_queue));
+ packet = dp_packet_from_list(list_pop_front(&rx->recv_queue));
rx->recv_queue_len--;
} else {
packet = NULL;
@@ -829,15 +829,13 @@ netdev_dummy_rxq_recv(struct netdev_rxq *rxq_, struct dp_packet **arr,
}
ovs_mutex_lock(&netdev->mutex);
netdev->stats.rx_packets++;
- netdev->stats.rx_bytes += ofpbuf_size(packet);
+ netdev->stats.rx_bytes += dp_packet_size(packet);
ovs_mutex_unlock(&netdev->mutex);
dp_packet_pad(packet);
+ dp_packet_set_dp_hash(packet, 0);
- /* This performs a (sometimes unnecessary) copy */
- arr[0] = dp_packet_clone_from_ofpbuf(packet);
- dp_packet_set_dp_hash(arr[0], 0);
- ofpbuf_delete(packet);
+ arr[0] = packet;
*c = 1;
return 0;
}
@@ -865,7 +863,7 @@ netdev_dummy_rxq_drain(struct netdev_rxq *rxq_)
struct netdev_dummy *netdev = netdev_dummy_cast(rx->up.netdev);
ovs_mutex_lock(&netdev->mutex);
- ofpbuf_list_delete(&rx->recv_queue);
+ dp_packet_list_delete(&rx->recv_queue);
rx->recv_queue_len = 0;
ovs_mutex_unlock(&netdev->mutex);
@@ -883,8 +881,8 @@ netdev_dummy_send(struct netdev *netdev, int qid OVS_UNUSED,
int i;
for (i = 0; i < cnt; i++) {
- const void *buffer = ofpbuf_data(&pkts[i]->ofpbuf);
- size_t size = ofpbuf_size(&pkts[i]->ofpbuf);
+ const void *buffer = dp_packet_data(pkts[i]);
+ size_t size = dp_packet_size(pkts[i]);
if (size < ETH_HEADER_LEN) {
error = EMSGSIZE;
@@ -913,9 +911,9 @@ netdev_dummy_send(struct netdev *netdev, int qid OVS_UNUSED,
dummy_packet_conn_send(&dev->conn, buffer, size);
if (dev->tx_pcap) {
- struct ofpbuf packet;
+ struct dp_packet packet;
- ofpbuf_use_const(&packet, buffer, size);
+ dp_packet_use_const(&packet, buffer, size);
ovs_pcap_write(dev->tx_pcap, &packet);
fflush(dev->tx_pcap);
}
@@ -1115,11 +1113,11 @@ static const struct netdev_class dummy_class = {
netdev_dummy_rxq_drain,
};
-static struct ofpbuf *
+static struct dp_packet *
eth_from_packet_or_flow(const char *s)
{
enum odp_key_fitness fitness;
- struct ofpbuf *packet;
+ struct dp_packet *packet;
struct ofpbuf odp_key;
struct flow flow;
int error;
@@ -1142,13 +1140,14 @@ eth_from_packet_or_flow(const char *s)
}
/* Convert odp_key to flow. */
- fitness = odp_flow_key_to_flow(ofpbuf_data(&odp_key), ofpbuf_size(&odp_key), &flow);
+ fitness = odp_flow_key_to_flow(ofpbuf_data(&odp_key),
+ ofpbuf_size(&odp_key), &flow);
if (fitness == ODP_FIT_ERROR) {
ofpbuf_uninit(&odp_key);
return NULL;
}
- packet = ofpbuf_new(0);
+ packet = dp_packet_new(0);
flow_compose(packet, &flow);
ofpbuf_uninit(&odp_key);
@@ -1156,7 +1155,7 @@ eth_from_packet_or_flow(const char *s)
}
static void
-netdev_dummy_queue_packet__(struct netdev_rxq_dummy *rx, struct ofpbuf *packet)
+netdev_dummy_queue_packet__(struct netdev_rxq_dummy *rx, struct dp_packet *packet)
{
list_push_back(&rx->recv_queue, &packet->list_node);
rx->recv_queue_len++;
@@ -1164,7 +1163,7 @@ netdev_dummy_queue_packet__(struct netdev_rxq_dummy *rx, struct ofpbuf *packet)
}
static void
-netdev_dummy_queue_packet(struct netdev_dummy *dummy, struct ofpbuf *packet)
+netdev_dummy_queue_packet(struct netdev_dummy *dummy, struct dp_packet *packet)
OVS_REQUIRES(dummy->mutex)
{
struct netdev_rxq_dummy *rx, *prev;
@@ -1177,7 +1176,7 @@ netdev_dummy_queue_packet(struct netdev_dummy *dummy, struct ofpbuf *packet)
LIST_FOR_EACH (rx, node, &dummy->rxes) {
if (rx->recv_queue_len < NETDEV_DUMMY_MAX_QUEUE) {
if (prev) {
- netdev_dummy_queue_packet__(prev, ofpbuf_clone(packet));
+ netdev_dummy_queue_packet__(prev, dp_packet_clone(packet));
}
prev = rx;
}
@@ -1185,7 +1184,7 @@ netdev_dummy_queue_packet(struct netdev_dummy *dummy, struct ofpbuf *packet)
if (prev) {
netdev_dummy_queue_packet__(prev, packet);
} else {
- ofpbuf_delete(packet);
+ dp_packet_delete(packet);
}
}
@@ -1205,7 +1204,7 @@ netdev_dummy_receive(struct unixctl_conn *conn,
dummy_dev = netdev_dummy_cast(netdev);
for (i = 2; i < argc; i++) {
- struct ofpbuf *packet;
+ struct dp_packet *packet;
packet = eth_from_packet_or_flow(argv[i]);
if (!packet) {
diff --git a/lib/netdev-linux.c b/lib/netdev-linux.c
index 2b7ceafbc..662ccc975 100644
--- a/lib/netdev-linux.c
+++ b/lib/netdev-linux.c
@@ -941,7 +941,7 @@ auxdata_has_vlan_tci(const struct tpacket_auxdata *aux)
}
static int
-netdev_linux_rxq_recv_sock(int fd, struct ofpbuf *buffer)
+netdev_linux_rxq_recv_sock(int fd, struct dp_packet *buffer)
{
size_t size;
ssize_t retval;
@@ -954,10 +954,10 @@ netdev_linux_rxq_recv_sock(int fd, struct ofpbuf *buffer)
struct msghdr msgh;
/* Reserve headroom for a single VLAN tag */
- ofpbuf_reserve(buffer, VLAN_HEADER_LEN);
- size = ofpbuf_tailroom(buffer);
+ dp_packet_reserve(buffer, VLAN_HEADER_LEN);
+ size = dp_packet_tailroom(buffer);
- iov.iov_base = ofpbuf_data(buffer);
+ iov.iov_base = dp_packet_data(buffer);
iov.iov_len = size;
msgh.msg_name = NULL;
msgh.msg_namelen = 0;
@@ -977,7 +977,7 @@ netdev_linux_rxq_recv_sock(int fd, struct ofpbuf *buffer)
return EMSGSIZE;
}
- ofpbuf_set_size(buffer, ofpbuf_size(buffer) + retval);
+ dp_packet_set_size(buffer, dp_packet_size(buffer) + retval);
for (cmsg = CMSG_FIRSTHDR(&msgh); cmsg; cmsg = CMSG_NXTHDR(&msgh, cmsg)) {
const struct tpacket_auxdata *aux;
@@ -1004,13 +1004,13 @@ netdev_linux_rxq_recv_sock(int fd, struct ofpbuf *buffer)
}
static int
-netdev_linux_rxq_recv_tap(int fd, struct ofpbuf *buffer)
+netdev_linux_rxq_recv_tap(int fd, struct dp_packet *buffer)
{
ssize_t retval;
- size_t size = ofpbuf_tailroom(buffer);
+ size_t size = dp_packet_tailroom(buffer);
do {
- retval = read(fd, ofpbuf_data(buffer), size);
+ retval = read(fd, dp_packet_data(buffer), size);
} while (retval < 0 && errno == EINTR);
if (retval < 0) {
@@ -1019,7 +1019,7 @@ netdev_linux_rxq_recv_tap(int fd, struct ofpbuf *buffer)
return EMSGSIZE;
}
- ofpbuf_set_size(buffer, ofpbuf_size(buffer) + retval);
+ dp_packet_set_size(buffer, dp_packet_size(buffer) + retval);
return 0;
}
@@ -1029,8 +1029,7 @@ netdev_linux_rxq_recv(struct netdev_rxq *rxq_, struct dp_packet **packets,
{
struct netdev_rxq_linux *rx = netdev_rxq_linux_cast(rxq_);
struct netdev *netdev = rx->up.netdev;
- struct dp_packet *packet;
- struct ofpbuf *buffer;
+ struct dp_packet *buffer;
ssize_t retval;
int mtu;
@@ -1038,10 +1037,8 @@ netdev_linux_rxq_recv(struct netdev_rxq *rxq_, struct dp_packet **packets,
mtu = ETH_PAYLOAD_MAX;
}
- packet = dp_packet_new_with_headroom(VLAN_ETH_HEADER_LEN + mtu,
+ buffer = dp_packet_new_with_headroom(VLAN_ETH_HEADER_LEN + mtu,
DP_NETDEV_HEADROOM);
- buffer = &packet->ofpbuf;
-
retval = (rx->is_tap
? netdev_linux_rxq_recv_tap(rx->fd, buffer)
: netdev_linux_rxq_recv_sock(rx->fd, buffer));
@@ -1051,11 +1048,11 @@ netdev_linux_rxq_recv(struct netdev_rxq *rxq_, struct dp_packet **packets,
VLOG_WARN_RL(&rl, "error receiving Ethernet packet on %s: %s",
ovs_strerror(errno), netdev_rxq_get_name(rxq_));
}
- dp_packet_delete(packet);
+ dp_packet_delete(buffer);
} else {
dp_packet_pad(buffer);
- dp_packet_set_dp_hash(packet, 0);
- packets[0] = packet;
+ dp_packet_set_dp_hash(buffer, 0);
+ packets[0] = buffer;
*c = 1;
}
@@ -1105,8 +1102,8 @@ netdev_linux_send(struct netdev *netdev_, int qid OVS_UNUSED,
/* 'i' is incremented only if there's no error */
for (i = 0; i < cnt;) {
- const void *data = ofpbuf_data(&pkts[i]->ofpbuf);
- size_t size = ofpbuf_size(&pkts[i]->ofpbuf);
+ const void *data = dp_packet_data(pkts[i]);
+ size_t size = dp_packet_size(pkts[i]);
ssize_t retval;
if (!is_tap_netdev(netdev_)) {
diff --git a/lib/netdev-vport.c b/lib/netdev-vport.c
index 34874a9cf..8e1b5424a 100644
--- a/lib/netdev-vport.c
+++ b/lib/netdev-vport.c
@@ -37,7 +37,7 @@
#include "list.h"
#include "netdev-provider.h"
#include "odp-netlink.h"
-#include "ofpbuf.h"
+#include "dp-packet.h"
#include "ovs-router.h"
#include "packets.h"
#include "poll-loop.h"
@@ -822,13 +822,13 @@ gre_hdr(struct ip_header *ip)
}
static void *
-ip_extract_tnl_md(struct ofpbuf *packet, struct flow_tnl *tnl)
+ip_extract_tnl_md(struct dp_packet *packet, struct flow_tnl *tnl)
{
struct ip_header *nh;
void *l4;
- nh = ofpbuf_l3(packet);
- l4 = ofpbuf_l4(packet);
+ nh = dp_packet_l3(packet);
+ l4 = dp_packet_l4(packet);
if (!nh || !l4) {
return NULL;
@@ -851,14 +851,14 @@ ip_extract_tnl_md(struct ofpbuf *packet, struct flow_tnl *tnl)
*
* Return pointer to the L4 header added to 'packet'. */
static void *
-push_ip_header(struct ofpbuf *packet,
+push_ip_header(struct dp_packet *packet,
const void *header, int size, int *ip_tot_size)
{
struct eth_header *eth;
struct ip_header *ip;
- eth = ofpbuf_push_uninit(packet, size);
- *ip_tot_size = ofpbuf_size(packet) - sizeof (struct eth_header);
+ eth = dp_packet_push_uninit(packet, size);
+ *ip_tot_size = dp_packet_size(packet) - sizeof (struct eth_header);
memcpy(eth, header, size);
ip = ip_hdr(eth);
@@ -889,7 +889,7 @@ gre_header_len(ovs_be16 flags)
}
static int
-parse_gre_header(struct ofpbuf *packet,
+parse_gre_header(struct dp_packet *packet,
struct flow_tnl *tnl)
{
const struct gre_base_hdr *greh;
@@ -906,7 +906,7 @@ parse_gre_header(struct ofpbuf *packet,
}
hlen = gre_header_len(greh->flags);
- if (hlen > ofpbuf_size(packet)) {
+ if (hlen > dp_packet_size(packet)) {
return -EINVAL;
}
@@ -914,9 +914,9 @@ parse_gre_header(struct ofpbuf *packet,
if (greh->flags & htons(GRE_CSUM)) {
ovs_be16 pkt_csum;
- pkt_csum = csum(greh, ofpbuf_size(packet) -
+ pkt_csum = csum(greh, dp_packet_size(packet) -
((const unsigned char *)greh -
- (const unsigned char *)ofpbuf_l2(packet)));
+ (const unsigned char *)dp_packet_l2(packet)));
if (pkt_csum) {
return -EINVAL;
}
@@ -944,16 +944,15 @@ reset_tnl_md(struct pkt_metadata *md)
}
static void
-gre_extract_md(struct dp_packet *dpif_pkt)
+gre_extract_md(struct dp_packet *packet)
{
- struct ofpbuf *packet = &dpif_pkt->ofpbuf;
- struct pkt_metadata *md = &dpif_pkt->md;
+ struct pkt_metadata *md = &packet->md;
struct flow_tnl *tnl = &md->tunnel;
int hlen = sizeof(struct eth_header) +
sizeof(struct ip_header) + 4;
memset(md, 0, sizeof *md);
- if (hlen > ofpbuf_size(packet)) {
+ if (hlen > dp_packet_size(packet)) {
return;
}
@@ -962,7 +961,7 @@ gre_extract_md(struct dp_packet *dpif_pkt)
reset_tnl_md(md);
}
- ofpbuf_reset_packet(packet, hlen);
+ dp_packet_reset_packet(packet, hlen);
}
static int
@@ -978,7 +977,7 @@ netdev_gre_pop_header(struct netdev *netdev_ OVS_UNUSED,
}
static void
-netdev_gre_push_header__(struct ofpbuf *packet,
+netdev_gre_push_header__(struct dp_packet *packet,
const void *header, int size)
{
struct gre_base_hdr *greh;
@@ -1002,8 +1001,7 @@ netdev_gre_push_header(const struct netdev *netdev OVS_UNUSED,
int i;
for (i = 0; i < cnt; i++) {
- netdev_gre_push_header__(&packets[i]->ofpbuf,
- data->header, data->header_len);
+ netdev_gre_push_header__(packets[i], data->header, data->header_len);
packets[i]->md = PKT_METADATA_INITIALIZER(u32_to_odp(data->out_port));
}
return 0;
@@ -1057,16 +1055,15 @@ netdev_gre_build_header(const struct netdev *netdev,
}
static void
-vxlan_extract_md(struct dp_packet *dpif_pkt)
+vxlan_extract_md(struct dp_packet *packet)
{
- struct ofpbuf *packet = &dpif_pkt->ofpbuf;
- struct pkt_metadata *md = &dpif_pkt->md;
+ struct pkt_metadata *md = &packet->md;
struct flow_tnl *tnl = &md->tunnel;
struct udp_header *udp;
struct vxlanhdr *vxh;
memset(md, 0, sizeof *md);
- if (VXLAN_HLEN > ofpbuf_size(packet)) {
+ if (VXLAN_HLEN > dp_packet_size(packet)) {
return;
}
@@ -1088,7 +1085,7 @@ vxlan_extract_md(struct dp_packet *dpif_pkt)
tnl->tp_dst = udp->udp_dst;
tnl->tun_id = htonll(ntohl(get_16aligned_be32(&vxh->vx_vni)) >> 8);
- ofpbuf_reset_packet(packet, VXLAN_HLEN);
+ dp_packet_reset_packet(packet, VXLAN_HLEN);
}
static int
@@ -1151,7 +1148,7 @@ netdev_vxlan_push_header__(struct dp_packet *packet,
struct udp_header *udp;
int ip_tot_size;
- udp = push_ip_header(&packet->ofpbuf, header, size, &ip_tot_size);
+ udp = push_ip_header(packet, header, size, &ip_tot_size);
/* set udp src port */
udp->udp_src = get_src_port(packet);
diff --git a/lib/netdev.c b/lib/netdev.c
index cfd979a0d..b76da139a 100644
--- a/lib/netdev.c
+++ b/lib/netdev.c
@@ -26,6 +26,7 @@
#include "coverage.h"
#include "dpif.h"
+#include "dp-packet.h"
#include "dynamic-string.h"
#include "fatal-signal.h"
#include "hash.h"
@@ -33,7 +34,6 @@
#include "netdev-dpdk.h"
#include "netdev-provider.h"
#include "netdev-vport.h"
-#include "ofpbuf.h"
#include "openflow/openflow.h"
#include "packets.h"
#include "poll-loop.h"
@@ -631,7 +631,7 @@ netdev_rxq_close(struct netdev_rxq *rx)
* Returns EAGAIN immediately if no packet is ready to be received.
*
* Returns EMSGSIZE, and discards the packet, if the received packet is longer
- * than 'ofpbuf_tailroom(buffer)'.
+ * than 'dp_packet_tailroom(buffer)'.
*
* It is advised that the tailroom of 'buffer' should be
* VLAN_HEADER_LEN bytes longer than the MTU to allow space for an
diff --git a/lib/odp-execute.c b/lib/odp-execute.c
index 079b0b49d..ccd29d7bc 100644
--- a/lib/odp-execute.c
+++ b/lib/odp-execute.c
@@ -27,7 +27,6 @@
#include "dp-packet.h"
#include "dpif.h"
#include "netlink.h"
-#include "ofpbuf.h"
#include "odp-netlink.h"
#include "odp-util.h"
#include "packets.h"
@@ -48,10 +47,10 @@ ether_addr_copy_masked(uint8_t *dst, const uint8_t *src,
}
static void
-odp_eth_set_addrs(struct ofpbuf *packet, const struct ovs_key_ethernet *key,
+odp_eth_set_addrs(struct dp_packet *packet, const struct ovs_key_ethernet *key,
const struct ovs_key_ethernet *mask)
{
- struct eth_header *eh = ofpbuf_l2(packet);
+ struct eth_header *eh = dp_packet_l2(packet);
if (eh) {
if (!mask) {
@@ -65,10 +64,10 @@ odp_eth_set_addrs(struct ofpbuf *packet, const struct ovs_key_ethernet *key,
}
static void
-odp_set_ipv4(struct ofpbuf *packet, const struct ovs_key_ipv4 *key,
+odp_set_ipv4(struct dp_packet *packet, const struct ovs_key_ipv4 *key,
const struct ovs_key_ipv4 *mask)
{
- struct ip_header *nh = ofpbuf_l3(packet);
+ struct ip_header *nh = dp_packet_l3(packet);
packet_set_ipv4(
packet,
@@ -90,10 +89,10 @@ mask_ipv6_addr(const ovs_16aligned_be32 *old, const ovs_be32 *addr,
}
static void
-odp_set_ipv6(struct ofpbuf *packet, const struct ovs_key_ipv6 *key,
+odp_set_ipv6(struct dp_packet *packet, const struct ovs_key_ipv6 *key,
const struct ovs_key_ipv6 *mask)
{
- struct ovs_16aligned_ip6_hdr *nh = ofpbuf_l3(packet);
+ struct ovs_16aligned_ip6_hdr *nh = dp_packet_l3(packet);
ovs_be32 sbuf[4], dbuf[4];
uint8_t old_tc = ntohl(get_16aligned_be32(&nh->ip6_flow)) >> 20;
ovs_be32 old_fl = get_16aligned_be32(&nh->ip6_flow) & htonl(0xfffff);
@@ -109,12 +108,12 @@ odp_set_ipv6(struct ofpbuf *packet, const struct ovs_key_ipv6 *key,
}
static void
-odp_set_tcp(struct ofpbuf *packet, const struct ovs_key_tcp *key,
+odp_set_tcp(struct dp_packet *packet, const struct ovs_key_tcp *key,
const struct ovs_key_tcp *mask)
{
- struct tcp_header *th = ofpbuf_l4(packet);
+ struct tcp_header *th = dp_packet_l4(packet);
- if (OVS_LIKELY(th && ofpbuf_get_tcp_payload(packet))) {
+ if (OVS_LIKELY(th && dp_packet_get_tcp_payload(packet))) {
packet_set_tcp_port(packet,
key->tcp_src | (th->tcp_src & ~mask->tcp_src),
key->tcp_dst | (th->tcp_dst & ~mask->tcp_dst));
@@ -122,12 +121,12 @@ odp_set_tcp(struct ofpbuf *packet, const struct ovs_key_tcp *key,
}
static void
-odp_set_udp(struct ofpbuf *packet, const struct ovs_key_udp *key,
+odp_set_udp(struct dp_packet *packet, const struct ovs_key_udp *key,
const struct ovs_key_udp *mask)
{
- struct udp_header *uh = ofpbuf_l4(packet);
+ struct udp_header *uh = dp_packet_l4(packet);
- if (OVS_LIKELY(uh && ofpbuf_get_udp_payload(packet))) {
+ if (OVS_LIKELY(uh && dp_packet_get_udp_payload(packet))) {
packet_set_udp_port(packet,
key->udp_src | (uh->udp_src & ~mask->udp_src),
key->udp_dst | (uh->udp_dst & ~mask->udp_dst));
@@ -135,12 +134,12 @@ odp_set_udp(struct ofpbuf *packet, const struct ovs_key_udp *key,
}
static void
-odp_set_sctp(struct ofpbuf *packet, const struct ovs_key_sctp *key,
+odp_set_sctp(struct dp_packet *packet, const struct ovs_key_sctp *key,
const struct ovs_key_sctp *mask)
{
- struct sctp_header *sh = ofpbuf_l4(packet);
+ struct sctp_header *sh = dp_packet_l4(packet);
- if (OVS_LIKELY(sh && ofpbuf_get_sctp_payload(packet))) {
+ if (OVS_LIKELY(sh && dp_packet_get_sctp_payload(packet))) {
packet_set_sctp_port(packet,
key->sctp_src | (sh->sctp_src & ~mask->sctp_src),
key->sctp_dst | (sh->sctp_dst & ~mask->sctp_dst));
@@ -157,10 +156,10 @@ odp_set_tunnel_action(const struct nlattr *a, struct flow_tnl *tun_key)
}
static void
-set_arp(struct ofpbuf *packet, const struct ovs_key_arp *key,
+set_arp(struct dp_packet *packet, const struct ovs_key_arp *key,
const struct ovs_key_arp *mask)
{
- struct arp_eth_header *arp = ofpbuf_l3(packet);
+ struct arp_eth_header *arp = dp_packet_l3(packet);
if (!mask) {
arp->ar_op = key->arp_op;
@@ -183,14 +182,14 @@ set_arp(struct ofpbuf *packet, const struct ovs_key_arp *key,
}
static void
-odp_set_nd(struct ofpbuf *packet, const struct ovs_key_nd *key,
+odp_set_nd(struct dp_packet *packet, const struct ovs_key_nd *key,
const struct ovs_key_nd *mask)
{
- const struct ovs_nd_msg *ns = ofpbuf_l4(packet);
- const struct ovs_nd_opt *nd_opt = ofpbuf_get_nd_payload(packet);
+ const struct ovs_nd_msg *ns = dp_packet_l4(packet);
+ const struct ovs_nd_opt *nd_opt = dp_packet_get_nd_payload(packet);
if (OVS_LIKELY(ns && nd_opt)) {
- int bytes_remain = ofpbuf_l4_size(packet) - sizeof(*ns);
+ int bytes_remain = dp_packet_l4_size(packet) - sizeof(*ns);
ovs_be32 tgt_buf[4];
uint8_t sll_buf[ETH_ADDR_LEN] = {0};
uint8_t tll_buf[ETH_ADDR_LEN] = {0};
@@ -246,67 +245,67 @@ odp_execute_set_action(struct dp_packet *packet, const struct nlattr *a)
break;
case OVS_KEY_ATTR_ETHERNET:
- odp_eth_set_addrs(&packet->ofpbuf, nl_attr_get(a), NULL);
+ odp_eth_set_addrs(packet, nl_attr_get(a), NULL);
break;
case OVS_KEY_ATTR_IPV4:
ipv4_key = nl_attr_get_unspec(a, sizeof(struct ovs_key_ipv4));
- packet_set_ipv4(&packet->ofpbuf, ipv4_key->ipv4_src,
+ packet_set_ipv4(packet, ipv4_key->ipv4_src,
ipv4_key->ipv4_dst, ipv4_key->ipv4_tos,
ipv4_key->ipv4_ttl);
break;
case OVS_KEY_ATTR_IPV6:
ipv6_key = nl_attr_get_unspec(a, sizeof(struct ovs_key_ipv6));
- packet_set_ipv6(&packet->ofpbuf, ipv6_key->ipv6_proto,
+ packet_set_ipv6(packet, ipv6_key->ipv6_proto,
ipv6_key->ipv6_src, ipv6_key->ipv6_dst,
ipv6_key->ipv6_tclass, ipv6_key->ipv6_label,
ipv6_key->ipv6_hlimit);
break;
case OVS_KEY_ATTR_TCP:
- if (OVS_LIKELY(ofpbuf_get_tcp_payload(&packet->ofpbuf))) {
+ if (OVS_LIKELY(dp_packet_get_tcp_payload(packet))) {
const struct ovs_key_tcp *tcp_key
= nl_attr_get_unspec(a, sizeof(struct ovs_key_tcp));
- packet_set_tcp_port(&packet->ofpbuf, tcp_key->tcp_src,
+ packet_set_tcp_port(packet, tcp_key->tcp_src,
tcp_key->tcp_dst);
}
break;
case OVS_KEY_ATTR_UDP:
- if (OVS_LIKELY(ofpbuf_get_udp_payload(&packet->ofpbuf))) {
+ if (OVS_LIKELY(dp_packet_get_udp_payload(packet))) {
const struct ovs_key_udp *udp_key
= nl_attr_get_unspec(a, sizeof(struct ovs_key_udp));
- packet_set_udp_port(&packet->ofpbuf, udp_key->udp_src,
+ packet_set_udp_port(packet, udp_key->udp_src,
udp_key->udp_dst);
}
break;
case OVS_KEY_ATTR_SCTP:
- if (OVS_LIKELY(ofpbuf_get_sctp_payload(&packet->ofpbuf))) {
+ if (OVS_LIKELY(dp_packet_get_sctp_payload(packet))) {
const struct ovs_key_sctp *sctp_key
= nl_attr_get_unspec(a, sizeof(struct ovs_key_sctp));
- packet_set_sctp_port(&packet->ofpbuf, sctp_key->sctp_src,
+ packet_set_sctp_port(packet, sctp_key->sctp_src,
sctp_key->sctp_dst);
}
break;
case OVS_KEY_ATTR_MPLS:
- set_mpls_lse(&packet->ofpbuf, nl_attr_get_be32(a));
+ set_mpls_lse(packet, nl_attr_get_be32(a));
break;
case OVS_KEY_ATTR_ARP:
- set_arp(&packet->ofpbuf, nl_attr_get(a), NULL);
+ set_arp(packet, nl_attr_get(a), NULL);
break;
case OVS_KEY_ATTR_ND:
- if (OVS_LIKELY(ofpbuf_get_nd_payload(&packet->ofpbuf))) {
+ if (OVS_LIKELY(dp_packet_get_nd_payload(packet))) {
const struct ovs_key_nd *nd_key
= nl_attr_get_unspec(a, sizeof(struct ovs_key_nd));
- packet_set_nd(&packet->ofpbuf, nd_key->nd_target,
+ packet_set_nd(packet, nd_key->nd_target,
nd_key->nd_sll, nd_key->nd_tll);
}
break;
@@ -356,37 +355,37 @@ odp_execute_masked_set_action(struct dp_packet *packet,
break;
case OVS_KEY_ATTR_ETHERNET:
- odp_eth_set_addrs(&packet->ofpbuf, nl_attr_get(a),
+ odp_eth_set_addrs(packet, nl_attr_get(a),
get_mask(a, struct ovs_key_ethernet));
break;
case OVS_KEY_ATTR_IPV4:
- odp_set_ipv4(&packet->ofpbuf, nl_attr_get(a),
+ odp_set_ipv4(packet, nl_attr_get(a),
get_mask(a, struct ovs_key_ipv4));
break;
case OVS_KEY_ATTR_IPV6:
- odp_set_ipv6(&packet->ofpbuf, nl_attr_get(a),
+ odp_set_ipv6(packet, nl_attr_get(a),
get_mask(a, struct ovs_key_ipv6));
break;
case OVS_KEY_ATTR_TCP:
- odp_set_tcp(&packet->ofpbuf, nl_attr_get(a),
+ odp_set_tcp(packet, nl_attr_get(a),
get_mask(a, struct ovs_key_tcp));
break;
case OVS_KEY_ATTR_UDP:
- odp_set_udp(&packet->ofpbuf, nl_attr_get(a),
+ odp_set_udp(packet, nl_attr_get(a),
get_mask(a, struct ovs_key_udp));
break;
case OVS_KEY_ATTR_SCTP:
- odp_set_sctp(&packet->ofpbuf, nl_attr_get(a),
+ odp_set_sctp(packet, nl_attr_get(a),
get_mask(a, struct ovs_key_sctp));
break;
case OVS_KEY_ATTR_MPLS:
- mh = ofpbuf_l2_5(&packet->ofpbuf);
+ mh = dp_packet_l2_5(packet);
if (mh) {
put_16aligned_be32(&mh->mpls_lse, nl_attr_get_be32(a)
| (get_16aligned_be32(&mh->mpls_lse)
@@ -395,12 +394,12 @@ odp_execute_masked_set_action(struct dp_packet *packet,
break;
case OVS_KEY_ATTR_ARP:
- set_arp(&packet->ofpbuf, nl_attr_get(a),
+ set_arp(packet, nl_attr_get(a),
get_mask(a, struct ovs_key_arp));
break;
case OVS_KEY_ATTR_ND:
- odp_set_nd(&packet->ofpbuf, nl_attr_get(a),
+ odp_set_nd(packet, nl_attr_get(a),
get_mask(a, struct ovs_key_nd));
break;
@@ -514,7 +513,7 @@ odp_execute_actions(void *dp, struct dp_packet **packets, int cnt, bool steal,
uint32_t hash;
for (i = 0; i < cnt; i++) {
- flow_extract(&packets[i]->ofpbuf, &packets[i]->md, &flow);
+ flow_extract(packets[i], &flow);
hash = flow_hash_5tuple(&flow, hash_act->hash_basis);
/* We also store the hash value with each packet */
@@ -531,18 +530,14 @@ odp_execute_actions(void *dp, struct dp_packet **packets, int cnt, bool steal,
const struct ovs_action_push_vlan *vlan = nl_attr_get(a);
for (i = 0; i < cnt; i++) {
- struct ofpbuf *buf = &packets[i]->ofpbuf;
-
- eth_push_vlan(buf, htons(ETH_TYPE_VLAN), vlan->vlan_tci);
+ eth_push_vlan(packets[i], htons(ETH_TYPE_VLAN), vlan->vlan_tci);
}
break;
}
case OVS_ACTION_ATTR_POP_VLAN:
for (i = 0; i < cnt; i++) {
- struct ofpbuf *buf = &packets[i]->ofpbuf;
-
- eth_pop_vlan(buf);
+ eth_pop_vlan(packets[i]);
}
break;
@@ -550,18 +545,14 @@ odp_execute_actions(void *dp, struct dp_packet **packets, int cnt, bool steal,
const struct ovs_action_push_mpls *mpls = nl_attr_get(a);
for (i = 0; i < cnt; i++) {
- struct ofpbuf *buf = &packets[i]->ofpbuf;
-
- push_mpls(buf, mpls->mpls_ethertype, mpls->mpls_lse);
+ push_mpls(packets[i], mpls->mpls_ethertype, mpls->mpls_lse);
}
break;
}
case OVS_ACTION_ATTR_POP_MPLS:
for (i = 0; i < cnt; i++) {
- struct ofpbuf *buf = &packets[i]->ofpbuf;
-
- pop_mpls(buf, nl_attr_get_be16(a));
+ pop_mpls(packets[i], nl_attr_get_be16(a));
}
break;
diff --git a/lib/ofp-print.c b/lib/ofp-print.c
index 8e947dad1..f3a8c1475 100644
--- a/lib/ofp-print.c
+++ b/lib/ofp-print.c
@@ -37,13 +37,14 @@
#include "netdev.h"
#include "nx-match.h"
#include "ofp-actions.h"
+#include "ofpbuf.h"
#include "ofp-errors.h"
#include "ofp-msgs.h"
#include "ofp-util.h"
-#include "ofpbuf.h"
#include "openflow/openflow.h"
#include "openflow/nicira-ext.h"
#include "packets.h"
+#include "dp-packet.h"
#include "type-props.h"
#include "unaligned.h"
#include "odp-util.h"
@@ -61,33 +62,32 @@ char *
ofp_packet_to_string(const void *data, size_t len)
{
struct ds ds = DS_EMPTY_INITIALIZER;
- const struct pkt_metadata md = PKT_METADATA_INITIALIZER(0);
- struct ofpbuf buf;
+ struct dp_packet buf;
struct flow flow;
size_t l4_size;
- ofpbuf_use_const(&buf, data, len);
- flow_extract(&buf, &md, &flow);
+ dp_packet_use_const(&buf, data, len);
+ flow_extract(&buf, &flow);
flow_format(&ds, &flow);
- l4_size = ofpbuf_l4_size(&buf);
+ l4_size = dp_packet_l4_size(&buf);
if (flow.nw_proto == IPPROTO_TCP && l4_size >= TCP_HEADER_LEN) {
- struct tcp_header *th = ofpbuf_l4(&buf);
+ struct tcp_header *th = dp_packet_l4(&buf);
ds_put_format(&ds, " tcp_csum:%"PRIx16, ntohs(th->tcp_csum));
} else if (flow.nw_proto == IPPROTO_UDP && l4_size >= UDP_HEADER_LEN) {
- struct udp_header *uh = ofpbuf_l4(&buf);
+ struct udp_header *uh = dp_packet_l4(&buf);
ds_put_format(&ds, " udp_csum:%"PRIx16, ntohs(uh->udp_csum));
} else if (flow.nw_proto == IPPROTO_SCTP && l4_size >= SCTP_HEADER_LEN) {
- struct sctp_header *sh = ofpbuf_l4(&buf);
+ struct sctp_header *sh = dp_packet_l4(&buf);
ds_put_format(&ds, " sctp_csum:%"PRIx32,
ntohl(get_16aligned_be32(&sh->sctp_csum)));
} else if (flow.nw_proto == IPPROTO_ICMP && l4_size >= ICMP_HEADER_LEN) {
- struct icmp_header *icmph = ofpbuf_l4(&buf);
+ struct icmp_header *icmph = dp_packet_l4(&buf);
ds_put_format(&ds, " icmp_csum:%"PRIx16,
ntohs(icmph->icmp_csum));
} else if (flow.nw_proto == IPPROTO_ICMPV6 && l4_size >= ICMP6_HEADER_LEN) {
- struct icmp6_header *icmp6h = ofpbuf_l4(&buf);
+ struct icmp6_header *icmp6h = dp_packet_l4(&buf);
ds_put_format(&ds, " icmp6_csum:%"PRIx16,
ntohs(icmp6h->icmp6_cksum));
}
diff --git a/lib/packets.c b/lib/packets.c
index 4d8aca98c..07cf2eb24 100644
--- a/lib/packets.c
+++ b/lib/packets.c
@@ -28,9 +28,9 @@
#include "flow.h"
#include "hmap.h"
#include "dynamic-string.h"
-#include "ofpbuf.h"
#include "ovs-thread.h"
#include "odp-util.h"
+#include "dp-packet.h"
#include "unaligned.h"
const struct in6_addr in6addr_exact = IN6ADDR_EXACT_INIT;
@@ -145,21 +145,21 @@ eth_addr_from_string(const char *s, uint8_t ea[ETH_ADDR_LEN])
* The returned packet has enough headroom to insert an 802.1Q VLAN header if
* desired. */
void
-compose_rarp(struct ofpbuf *b, const uint8_t eth_src[ETH_ADDR_LEN])
+compose_rarp(struct dp_packet *b, const uint8_t eth_src[ETH_ADDR_LEN])
{
struct eth_header *eth;
struct arp_eth_header *arp;
- ofpbuf_clear(b);
- ofpbuf_prealloc_tailroom(b, 2 + ETH_HEADER_LEN + VLAN_HEADER_LEN
+ dp_packet_clear(b);
+ dp_packet_prealloc_tailroom(b, 2 + ETH_HEADER_LEN + VLAN_HEADER_LEN
+ ARP_ETH_HEADER_LEN);
- ofpbuf_reserve(b, 2 + VLAN_HEADER_LEN);
- eth = ofpbuf_put_uninit(b, sizeof *eth);
+ dp_packet_reserve(b, 2 + VLAN_HEADER_LEN);
+ eth = dp_packet_put_uninit(b, sizeof *eth);
memcpy(eth->eth_dst, eth_addr_broadcast, ETH_ADDR_LEN);
memcpy(eth->eth_src, eth_src, ETH_ADDR_LEN);
eth->eth_type = htons(ETH_TYPE_RARP);
- arp = ofpbuf_put_uninit(b, sizeof *arp);
+ arp = dp_packet_put_uninit(b, sizeof *arp);
arp->ar_hrd = htons(ARP_HRD_ETHERNET);
arp->ar_pro = htons(ARP_PRO_IP);
arp->ar_hln = sizeof arp->ar_sha;
@@ -170,8 +170,8 @@ compose_rarp(struct ofpbuf *b, const uint8_t eth_src[ETH_ADDR_LEN])
memcpy(arp->ar_tha, eth_src, ETH_ADDR_LEN);
put_16aligned_be32(&arp->ar_tpa, htonl(0));
- ofpbuf_set_frame(b, eth);
- ofpbuf_set_l3(b, arp);
+ dp_packet_set_frame(b, eth);
+ dp_packet_set_l3(b, arp);
}
/* Insert VLAN header according to given TCI. Packet passed must be Ethernet
@@ -179,12 +179,12 @@ compose_rarp(struct ofpbuf *b, const uint8_t eth_src[ETH_ADDR_LEN])
*
* Also adjusts the layer offsets accordingly. */
void
-eth_push_vlan(struct ofpbuf *packet, ovs_be16 tpid, ovs_be16 tci)
+eth_push_vlan(struct dp_packet *packet, ovs_be16 tpid, ovs_be16 tci)
{
struct vlan_eth_header *veh;
/* Insert new 802.1Q header. */
- veh = ofpbuf_resize_l2(packet, VLAN_HEADER_LEN);
+ veh = dp_packet_resize_l2(packet, VLAN_HEADER_LEN);
memmove(veh, (char *)veh + VLAN_HEADER_LEN, 2 * ETH_ADDR_LEN);
veh->veth_type = tpid;
veh->veth_tci = tci & htons(~VLAN_CFI);
@@ -195,23 +195,23 @@ eth_push_vlan(struct ofpbuf *packet, ovs_be16 tpid, ovs_be16 tci)
* 'packet->l2_5' should initially point to 'packet''s outer-most MPLS header
* or may be NULL if there are no MPLS headers. */
void
-eth_pop_vlan(struct ofpbuf *packet)
+eth_pop_vlan(struct dp_packet *packet)
{
- struct vlan_eth_header *veh = ofpbuf_l2(packet);
+ struct vlan_eth_header *veh = dp_packet_l2(packet);
- if (veh && ofpbuf_size(packet) >= sizeof *veh
+ if (veh && dp_packet_size(packet) >= sizeof *veh
&& veh->veth_type == htons(ETH_TYPE_VLAN)) {
memmove((char *)veh + VLAN_HEADER_LEN, veh, 2 * ETH_ADDR_LEN);
- ofpbuf_resize_l2(packet, -VLAN_HEADER_LEN);
+ dp_packet_resize_l2(packet, -VLAN_HEADER_LEN);
}
}
/* Set ethertype of the packet. */
static void
-set_ethertype(struct ofpbuf *packet, ovs_be16 eth_type)
+set_ethertype(struct dp_packet *packet, ovs_be16 eth_type)
{
- struct eth_header *eh = ofpbuf_l2(packet);
+ struct eth_header *eh = dp_packet_l2(packet);
if (!eh) {
return;
@@ -219,17 +219,17 @@ set_ethertype(struct ofpbuf *packet, ovs_be16 eth_type)
if (eh->eth_type == htons(ETH_TYPE_VLAN)) {
ovs_be16 *p;
- char *l2_5 = ofpbuf_l2_5(packet);
+ char *l2_5 = dp_packet_l2_5(packet);
p = ALIGNED_CAST(ovs_be16 *,
- (l2_5 ? l2_5 : (char *)ofpbuf_l3(packet)) - 2);
+ (l2_5 ? l2_5 : (char *)dp_packet_l3(packet)) - 2);
*p = eth_type;
} else {
eh->eth_type = eth_type;
}
}
-static bool is_mpls(struct ofpbuf *packet)
+static bool is_mpls(struct dp_packet *packet)
{
return packet->l2_5_ofs != UINT16_MAX;
}
@@ -282,11 +282,11 @@ set_mpls_lse_values(uint8_t ttl, uint8_t tc, uint8_t bos, ovs_be32 label)
/* Set MPLS label stack entry to outermost MPLS header.*/
void
-set_mpls_lse(struct ofpbuf *packet, ovs_be32 mpls_lse)
+set_mpls_lse(struct dp_packet *packet, ovs_be32 mpls_lse)
{
/* Packet type should be MPLS to set label stack entry. */
if (is_mpls(packet)) {
- struct mpls_hdr *mh = ofpbuf_l2_5(packet);
+ struct mpls_hdr *mh = dp_packet_l2_5(packet);
/* Update mpls label stack entry. */
put_16aligned_be32(&mh->mpls_lse, mpls_lse);
@@ -297,7 +297,7 @@ set_mpls_lse(struct ofpbuf *packet, ovs_be32 mpls_lse)
* header. If 'packet' does not already have any MPLS labels, then its
* Ethertype is changed to 'ethtype' (which must be an MPLS Ethertype). */
void
-push_mpls(struct ofpbuf *packet, ovs_be16 ethtype, ovs_be32 lse)
+push_mpls(struct dp_packet *packet, ovs_be16 ethtype, ovs_be32 lse)
{
char * header;
size_t len;
@@ -315,7 +315,7 @@ push_mpls(struct ofpbuf *packet, ovs_be16 ethtype, ovs_be32 lse)
/* Push new MPLS shim header onto packet. */
len = packet->l2_5_ofs;
- header = ofpbuf_resize_l2_5(packet, MPLS_HLEN);
+ header = dp_packet_resize_l2_5(packet, MPLS_HLEN);
memmove(header, header + MPLS_HLEN, len);
memcpy(header + len, &lse, sizeof lse);
}
@@ -325,19 +325,19 @@ push_mpls(struct ofpbuf *packet, ovs_be16 ethtype, ovs_be32 lse)
* Ethertype to 'ethtype' (which ordinarily should not be an MPLS
* Ethertype). */
void
-pop_mpls(struct ofpbuf *packet, ovs_be16 ethtype)
+pop_mpls(struct dp_packet *packet, ovs_be16 ethtype)
{
if (is_mpls(packet)) {
- struct mpls_hdr *mh = ofpbuf_l2_5(packet);
+ struct mpls_hdr *mh = dp_packet_l2_5(packet);
size_t len = packet->l2_5_ofs;
set_ethertype(packet, ethtype);
if (get_16aligned_be32(&mh->mpls_lse) & htonl(MPLS_BOS_MASK)) {
- ofpbuf_set_l2_5(packet, NULL);
+ dp_packet_set_l2_5(packet, NULL);
}
/* Shift the l2 header forward. */
- memmove((char*)ofpbuf_data(packet) + MPLS_HLEN, ofpbuf_data(packet), len);
- ofpbuf_resize_l2_5(packet, -MPLS_HLEN);
+ memmove((char*)dp_packet_data(packet) + MPLS_HLEN, dp_packet_data(packet), len);
+ dp_packet_resize_l2_5(packet, -MPLS_HLEN);
}
}
@@ -347,21 +347,21 @@ pop_mpls(struct ofpbuf *packet, ovs_be16 ethtype)
*
* Aligns the L3 header of '*packetp' on a 32-bit boundary. */
const char *
-eth_from_hex(const char *hex, struct ofpbuf **packetp)
+eth_from_hex(const char *hex, struct dp_packet **packetp)
{
- struct ofpbuf *packet;
+ struct dp_packet *packet;
/* Use 2 bytes of headroom to 32-bit align the L3 header. */
- packet = *packetp = ofpbuf_new_with_headroom(strlen(hex) / 2, 2);
+ packet = *packetp = dp_packet_new_with_headroom(strlen(hex) / 2, 2);
- if (ofpbuf_put_hex(packet, hex, NULL)[0] != '\0') {
- ofpbuf_delete(packet);
+ if (dp_packet_put_hex(packet, hex, NULL)[0] != '\0') {
+ dp_packet_delete(packet);
*packetp = NULL;
return "Trailing garbage in packet data";
}
- if (ofpbuf_size(packet) < ETH_HEADER_LEN) {
- ofpbuf_delete(packet);
+ if (dp_packet_size(packet) < ETH_HEADER_LEN) {
+ dp_packet_delete(packet);
*packetp = NULL;
return "Packet data too short for Ethernet";
}
@@ -559,46 +559,46 @@ ipv6_is_cidr(const struct in6_addr *netmask)
* The returned packet has enough headroom to insert an 802.1Q VLAN header if
* desired. */
void *
-eth_compose(struct ofpbuf *b, const uint8_t eth_dst[ETH_ADDR_LEN],
+eth_compose(struct dp_packet *b, const uint8_t eth_dst[ETH_ADDR_LEN],
const uint8_t eth_src[ETH_ADDR_LEN], uint16_t eth_type,
size_t size)
{
void *data;
struct eth_header *eth;
- ofpbuf_clear(b);
+ dp_packet_clear(b);
/* The magic 2 here ensures that the L3 header (when it is added later)
* will be 32-bit aligned. */
- ofpbuf_prealloc_tailroom(b, 2 + ETH_HEADER_LEN + VLAN_HEADER_LEN + size);
- ofpbuf_reserve(b, 2 + VLAN_HEADER_LEN);
- eth = ofpbuf_put_uninit(b, ETH_HEADER_LEN);
- data = ofpbuf_put_uninit(b, size);
+ dp_packet_prealloc_tailroom(b, 2 + ETH_HEADER_LEN + VLAN_HEADER_LEN + size);
+ dp_packet_reserve(b, 2 + VLAN_HEADER_LEN);
+ eth = dp_packet_put_uninit(b, ETH_HEADER_LEN);
+ data = dp_packet_put_uninit(b, size);
memcpy(eth->eth_dst, eth_dst, ETH_ADDR_LEN);
memcpy(eth->eth_src, eth_src, ETH_ADDR_LEN);
eth->eth_type = htons(eth_type);
- ofpbuf_set_frame(b, eth);
- ofpbuf_set_l3(b, data);
+ dp_packet_set_frame(b, eth);
+ dp_packet_set_l3(b, data);
return data;
}
static void
-packet_set_ipv4_addr(struct ofpbuf *packet,
+packet_set_ipv4_addr(struct dp_packet *packet,
ovs_16aligned_be32 *addr, ovs_be32 new_addr)
{
- struct ip_header *nh = ofpbuf_l3(packet);
+ struct ip_header *nh = dp_packet_l3(packet);
ovs_be32 old_addr = get_16aligned_be32(addr);
- size_t l4_size = ofpbuf_l4_size(packet);
+ size_t l4_size = dp_packet_l4_size(packet);
if (nh->ip_proto == IPPROTO_TCP && l4_size >= TCP_HEADER_LEN) {
- struct tcp_header *th = ofpbuf_l4(packet);
+ struct tcp_header *th = dp_packet_l4(packet);
th->tcp_csum = recalc_csum32(th->tcp_csum, old_addr, new_addr);
} else if (nh->ip_proto == IPPROTO_UDP && l4_size >= UDP_HEADER_LEN ) {
- struct udp_header *uh = ofpbuf_l4(packet);
+ struct udp_header *uh = dp_packet_l4(packet);
if (uh->udp_csum) {
uh->udp_csum = recalc_csum32(uh->udp_csum, old_addr, new_addr);
@@ -616,13 +616,13 @@ packet_set_ipv4_addr(struct ofpbuf *packet,
*
* This function assumes that L3 and L4 offsets are set in the packet. */
static bool
-packet_rh_present(struct ofpbuf *packet)
+packet_rh_present(struct dp_packet *packet)
{
const struct ovs_16aligned_ip6_hdr *nh;
int nexthdr;
size_t len;
size_t remaining;
- uint8_t *data = ofpbuf_l3(packet);
+ uint8_t *data = dp_packet_l3(packet);
remaining = packet->l4_ofs - packet->l3_ofs;
@@ -697,17 +697,17 @@ packet_rh_present(struct ofpbuf *packet)
}
static void
-packet_update_csum128(struct ofpbuf *packet, uint8_t proto,
+packet_update_csum128(struct dp_packet *packet, uint8_t proto,
ovs_16aligned_be32 addr[4], const ovs_be32 new_addr[4])
{
- size_t l4_size = ofpbuf_l4_size(packet);
+ size_t l4_size = dp_packet_l4_size(packet);
if (proto == IPPROTO_TCP && l4_size >= TCP_HEADER_LEN) {
- struct tcp_header *th = ofpbuf_l4(packet);
+ struct tcp_header *th = dp_packet_l4(packet);
th->tcp_csum = recalc_csum128(th->tcp_csum, addr, new_addr);
} else if (proto == IPPROTO_UDP && l4_size >= UDP_HEADER_LEN) {
- struct udp_header *uh = ofpbuf_l4(packet);
+ struct udp_header *uh = dp_packet_l4(packet);
if (uh->udp_csum) {
uh->udp_csum = recalc_csum128(uh->udp_csum, addr, new_addr);
@@ -717,14 +717,14 @@ packet_update_csum128(struct ofpbuf *packet, uint8_t proto,
}
} else if (proto == IPPROTO_ICMPV6 &&
l4_size >= sizeof(struct icmp6_header)) {
- struct icmp6_header *icmp = ofpbuf_l4(packet);
+ struct icmp6_header *icmp = dp_packet_l4(packet);
icmp->icmp6_cksum = recalc_csum128(icmp->icmp6_cksum, addr, new_addr);
}
}
static void
-packet_set_ipv6_addr(struct ofpbuf *packet, uint8_t proto,
+packet_set_ipv6_addr(struct dp_packet *packet, uint8_t proto,
ovs_16aligned_be32 addr[4], const ovs_be32 new_addr[4],
bool recalculate_csum)
{
@@ -755,10 +755,10 @@ packet_set_ipv6_tc(ovs_16aligned_be32 *flow_label, uint8_t tc)
* 'packet' must contain a valid IPv4 packet with correctly populated l[347]
* markers. */
void
-packet_set_ipv4(struct ofpbuf *packet, ovs_be32 src, ovs_be32 dst,
+packet_set_ipv4(struct dp_packet *packet, ovs_be32 src, ovs_be32 dst,
uint8_t tos, uint8_t ttl)
{
- struct ip_header *nh = ofpbuf_l3(packet);
+ struct ip_header *nh = dp_packet_l3(packet);
if (get_16aligned_be32(&nh->ip_src) != src) {
packet_set_ipv4_addr(packet, &nh->ip_src, src);
@@ -790,11 +790,11 @@ packet_set_ipv4(struct ofpbuf *packet, ovs_be32 src, ovs_be32 dst,
* appropriate. 'packet' must contain a valid IPv6 packet with correctly
* populated l[34] offsets. */
void
-packet_set_ipv6(struct ofpbuf *packet, uint8_t proto, const ovs_be32 src[4],
+packet_set_ipv6(struct dp_packet *packet, uint8_t proto, const ovs_be32 src[4],
const ovs_be32 dst[4], uint8_t key_tc, ovs_be32 key_fl,
uint8_t key_hl)
{
- struct ovs_16aligned_ip6_hdr *nh = ofpbuf_l3(packet);
+ struct ovs_16aligned_ip6_hdr *nh = dp_packet_l3(packet);
if (memcmp(&nh->ip6_src, src, sizeof(ovs_be32[4]))) {
packet_set_ipv6_addr(packet, proto, nh->ip6_src.be32, src, true);
@@ -825,9 +825,9 @@ packet_set_port(ovs_be16 *port, ovs_be16 new_port, ovs_be16 *csum)
* the TCP header contained in 'packet'. 'packet' must be a valid TCP packet
* with its l4 offset properly populated. */
void
-packet_set_tcp_port(struct ofpbuf *packet, ovs_be16 src, ovs_be16 dst)
+packet_set_tcp_port(struct dp_packet *packet, ovs_be16 src, ovs_be16 dst)
{
- struct tcp_header *th = ofpbuf_l4(packet);
+ struct tcp_header *th = dp_packet_l4(packet);
packet_set_port(&th->tcp_src, src, &th->tcp_csum);
packet_set_port(&th->tcp_dst, dst, &th->tcp_csum);
@@ -837,9 +837,9 @@ packet_set_tcp_port(struct ofpbuf *packet, ovs_be16 src, ovs_be16 dst)
* the UDP header contained in 'packet'. 'packet' must be a valid UDP packet
* with its l4 offset properly populated. */
void
-packet_set_udp_port(struct ofpbuf *packet, ovs_be16 src, ovs_be16 dst)
+packet_set_udp_port(struct dp_packet *packet, ovs_be16 src, ovs_be16 dst)
{
- struct udp_header *uh = ofpbuf_l4(packet);
+ struct udp_header *uh = dp_packet_l4(packet);
if (uh->udp_csum) {
packet_set_port(&uh->udp_src, src, &uh->udp_csum);
@@ -858,11 +858,11 @@ packet_set_udp_port(struct ofpbuf *packet, ovs_be16 src, ovs_be16 dst)
* the SCTP header contained in 'packet'. 'packet' must be a valid SCTP packet
* with its l4 offset properly populated. */
void
-packet_set_sctp_port(struct ofpbuf *packet, ovs_be16 src, ovs_be16 dst)
+packet_set_sctp_port(struct dp_packet *packet, ovs_be16 src, ovs_be16 dst)
{
- struct sctp_header *sh = ofpbuf_l4(packet);
+ struct sctp_header *sh = dp_packet_l4(packet);
ovs_be32 old_csum, old_correct_csum, new_csum;
- uint16_t tp_len = ofpbuf_l4_size(packet);
+ uint16_t tp_len = dp_packet_l4_size(packet);
old_csum = get_16aligned_be32(&sh->sctp_csum);
put_16aligned_be32(&sh->sctp_csum, 0);
@@ -876,18 +876,18 @@ packet_set_sctp_port(struct ofpbuf *packet, ovs_be16 src, ovs_be16 dst)
}
void
-packet_set_nd(struct ofpbuf *packet, const ovs_be32 target[4],
+packet_set_nd(struct dp_packet *packet, const ovs_be32 target[4],
const uint8_t sll[ETH_ADDR_LEN],
const uint8_t tll[ETH_ADDR_LEN]) {
struct ovs_nd_msg *ns;
struct ovs_nd_opt *nd_opt;
- int bytes_remain = ofpbuf_l4_size(packet);
+ int bytes_remain = dp_packet_l4_size(packet);
if (OVS_UNLIKELY(bytes_remain < sizeof(*ns))) {
return;
}
- ns = ofpbuf_l4(packet);
+ ns = dp_packet_l4(packet);
nd_opt = &ns->options[0];
bytes_remain -= sizeof(*ns);
@@ -1013,22 +1013,22 @@ packet_format_tcp_flags(struct ds *s, uint16_t tcp_flags)
ARP_ETH_HEADER_LEN)
void
-compose_arp(struct ofpbuf *b, const uint8_t eth_src[ETH_ADDR_LEN],
+compose_arp(struct dp_packet *b, const uint8_t eth_src[ETH_ADDR_LEN],
ovs_be32 ip_src, ovs_be32 ip_dst)
{
struct eth_header *eth;
struct arp_eth_header *arp;
- ofpbuf_clear(b);
- ofpbuf_prealloc_tailroom(b, ARP_PACKET_SIZE);
- ofpbuf_reserve(b, 2 + VLAN_HEADER_LEN);
+ dp_packet_clear(b);
+ dp_packet_prealloc_tailroom(b, ARP_PACKET_SIZE);
+ dp_packet_reserve(b, 2 + VLAN_HEADER_LEN);
- eth = ofpbuf_put_uninit(b, sizeof *eth);
+ eth = dp_packet_put_uninit(b, sizeof *eth);
memcpy(eth->eth_dst, eth_addr_broadcast, ETH_ADDR_LEN);
memcpy(eth->eth_src, eth_src, ETH_ADDR_LEN);
eth->eth_type = htons(ETH_TYPE_ARP);
- arp = ofpbuf_put_uninit(b, sizeof *arp);
+ arp = dp_packet_put_uninit(b, sizeof *arp);
arp->ar_hrd = htons(ARP_HRD_ETHERNET);
arp->ar_pro = htons(ARP_PRO_IP);
arp->ar_hln = sizeof arp->ar_sha;
@@ -1040,6 +1040,6 @@ compose_arp(struct ofpbuf *b, const uint8_t eth_src[ETH_ADDR_LEN],
put_16aligned_be32(&arp->ar_spa, ip_src);
put_16aligned_be32(&arp->ar_tpa, ip_dst);
- ofpbuf_set_frame(b, eth);
- ofpbuf_set_l3(b, arp);
+ dp_packet_set_frame(b, eth);
+ dp_packet_set_l3(b, arp);
}
diff --git a/lib/packets.h b/lib/packets.h
index df95b2a72..e80de6bc6 100644
--- a/lib/packets.h
+++ b/lib/packets.h
@@ -28,7 +28,7 @@
#include "hash.h"
#include "util.h"
-struct ofpbuf;
+struct dp_packet;
struct ds;
/* Tunnel information used in flow key and metadata. */
@@ -187,21 +187,21 @@ static inline uint32_t hash_mac(const uint8_t ea[ETH_ADDR_LEN],
bool eth_addr_is_reserved(const uint8_t ea[ETH_ADDR_LEN]);
bool eth_addr_from_string(const char *, uint8_t ea[ETH_ADDR_LEN]);
-void compose_rarp(struct ofpbuf *, const uint8_t eth_src[ETH_ADDR_LEN]);
+void compose_rarp(struct dp_packet *, const uint8_t eth_src[ETH_ADDR_LEN]);
-void eth_push_vlan(struct ofpbuf *, ovs_be16 tpid, ovs_be16 tci);
-void eth_pop_vlan(struct ofpbuf *);
+void eth_push_vlan(struct dp_packet *, ovs_be16 tpid, ovs_be16 tci);
+void eth_pop_vlan(struct dp_packet *);
-const char *eth_from_hex(const char *hex, struct ofpbuf **packetp);
+const char *eth_from_hex(const char *hex, struct dp_packet **packetp);
void eth_format_masked(const uint8_t eth[ETH_ADDR_LEN],
const uint8_t mask[ETH_ADDR_LEN], struct ds *s);
void eth_addr_bitand(const uint8_t src[ETH_ADDR_LEN],
const uint8_t mask[ETH_ADDR_LEN],
uint8_t dst[ETH_ADDR_LEN]);
-void set_mpls_lse(struct ofpbuf *, ovs_be32 label);
-void push_mpls(struct ofpbuf *packet, ovs_be16 ethtype, ovs_be32 lse);
-void pop_mpls(struct ofpbuf *, ovs_be16 ethtype);
+void set_mpls_lse(struct dp_packet *, ovs_be32 label);
+void push_mpls(struct dp_packet *packet, ovs_be16 ethtype, ovs_be32 lse);
+void pop_mpls(struct dp_packet *, ovs_be16 ethtype);
void set_mpls_lse_ttl(ovs_be32 *lse, uint8_t ttl);
void set_mpls_lse_tc(ovs_be32 *lse, uint8_t tc);
@@ -766,26 +766,26 @@ struct in6_addr ipv6_create_mask(int mask);
int ipv6_count_cidr_bits(const struct in6_addr *netmask);
bool ipv6_is_cidr(const struct in6_addr *netmask);
-void *eth_compose(struct ofpbuf *, const uint8_t eth_dst[ETH_ADDR_LEN],
+void *eth_compose(struct dp_packet *, const uint8_t eth_dst[ETH_ADDR_LEN],
const uint8_t eth_src[ETH_ADDR_LEN], uint16_t eth_type,
size_t size);
-void *snap_compose(struct ofpbuf *, const uint8_t eth_dst[ETH_ADDR_LEN],
+void *snap_compose(struct dp_packet *, const uint8_t eth_dst[ETH_ADDR_LEN],
const uint8_t eth_src[ETH_ADDR_LEN],
unsigned int oui, uint16_t snap_type, size_t size);
-void packet_set_ipv4(struct ofpbuf *, ovs_be32 src, ovs_be32 dst, uint8_t tos,
+void packet_set_ipv4(struct dp_packet *, ovs_be32 src, ovs_be32 dst, uint8_t tos,
uint8_t ttl);
-void packet_set_ipv6(struct ofpbuf *, uint8_t proto, const ovs_be32 src[4],
+void packet_set_ipv6(struct dp_packet *, uint8_t proto, const ovs_be32 src[4],
const ovs_be32 dst[4], uint8_t tc,
ovs_be32 fl, uint8_t hlmit);
-void packet_set_tcp_port(struct ofpbuf *, ovs_be16 src, ovs_be16 dst);
-void packet_set_udp_port(struct ofpbuf *, ovs_be16 src, ovs_be16 dst);
-void packet_set_sctp_port(struct ofpbuf *, ovs_be16 src, ovs_be16 dst);
-void packet_set_nd(struct ofpbuf *, const ovs_be32 target[4],
+void packet_set_tcp_port(struct dp_packet *, ovs_be16 src, ovs_be16 dst);
+void packet_set_udp_port(struct dp_packet *, ovs_be16 src, ovs_be16 dst);
+void packet_set_sctp_port(struct dp_packet *, ovs_be16 src, ovs_be16 dst);
+void packet_set_nd(struct dp_packet *, const ovs_be32 target[4],
const uint8_t sll[6], const uint8_t tll[6]);
void packet_format_tcp_flags(struct ds *, uint16_t);
const char *packet_tcp_flag_to_string(uint32_t flag);
-void compose_arp(struct ofpbuf *b, const uint8_t eth_src[ETH_ADDR_LEN],
+void compose_arp(struct dp_packet *b, const uint8_t eth_src[ETH_ADDR_LEN],
ovs_be32 ip_src, ovs_be32 ip_dst);
#endif /* packets.h */
diff --git a/lib/pcap-file.c b/lib/pcap-file.c
index 58c60b1cc..553a7b6d7 100644
--- a/lib/pcap-file.c
+++ b/lib/pcap-file.c
@@ -23,9 +23,9 @@
#include <sys/stat.h>
#include "byte-order.h"
#include "compiler.h"
+#include "dp-packet.h"
#include "flow.h"
#include "hmap.h"
-#include "ofpbuf.h"
#include "packets.h"
#include "timeval.h"
#include "unaligned.h"
@@ -133,10 +133,10 @@ ovs_pcap_write_header(FILE *file)
}
int
-ovs_pcap_read(FILE *file, struct ofpbuf **bufp, long long int *when)
+ovs_pcap_read(FILE *file, struct dp_packet **bufp, long long int *when)
{
struct pcaprec_hdr prh;
- struct ofpbuf *buf;
+ struct dp_packet *buf;
void *data;
size_t len;
bool swap;
@@ -176,13 +176,13 @@ ovs_pcap_read(FILE *file, struct ofpbuf **bufp, long long int *when)
}
/* Read packet. */
- buf = ofpbuf_new(len);
- data = ofpbuf_put_uninit(buf, len);
+ buf = dp_packet_new(len);
+ data = dp_packet_put_uninit(buf, len);
if (fread(data, len, 1, file) != 1) {
int error = ferror(file) ? errno : EOF;
VLOG_WARN("failed to read pcap packet: %s",
ovs_retval_to_string(error));
- ofpbuf_delete(buf);
+ dp_packet_delete(buf);
return error;
}
*bufp = buf;
@@ -190,7 +190,7 @@ ovs_pcap_read(FILE *file, struct ofpbuf **bufp, long long int *when)
}
void
-ovs_pcap_write(FILE *file, struct ofpbuf *buf)
+ovs_pcap_write(FILE *file, struct dp_packet *buf)
{
struct pcaprec_hdr prh;
struct timeval tv;
@@ -198,10 +198,10 @@ ovs_pcap_write(FILE *file, struct ofpbuf *buf)
xgettimeofday(&tv);
prh.ts_sec = tv.tv_sec;
prh.ts_usec = tv.tv_usec;
- prh.incl_len = ofpbuf_size(buf);
- prh.orig_len = ofpbuf_size(buf);
+ prh.incl_len = dp_packet_size(buf);
+ prh.orig_len = dp_packet_size(buf);
ignore(fwrite(&prh, sizeof prh, 1, file));
- ignore(fwrite(ofpbuf_data(buf), ofpbuf_size(buf), 1, file));
+ ignore(fwrite(dp_packet_data(buf), dp_packet_size(buf), 1, file));
}
struct tcp_key {
@@ -213,7 +213,7 @@ struct tcp_stream {
struct hmap_node hmap_node;
struct tcp_key key;
uint32_t seq_no;
- struct ofpbuf payload;
+ struct dp_packet payload;
};
struct tcp_reader {
@@ -224,7 +224,7 @@ static void
tcp_stream_destroy(struct tcp_reader *r, struct tcp_stream *stream)
{
hmap_remove(&r->streams, &stream->hmap_node);
- ofpbuf_uninit(&stream->payload);
+ dp_packet_uninit(&stream->payload);
free(stream);
}
@@ -276,7 +276,7 @@ tcp_stream_new(struct tcp_reader *r, const struct tcp_key *key, uint32_t hash)
hmap_insert(&r->streams, &stream->hmap_node, hash);
memcpy(&stream->key, key, sizeof *key);
stream->seq_no = 0;
- ofpbuf_init(&stream->payload, 2048);
+ dp_packet_init(&stream->payload, 2048);
return stream;
}
@@ -284,35 +284,35 @@ tcp_stream_new(struct tcp_reader *r, const struct tcp_key *key, uint32_t hash)
* extracted the packet's headers into 'flow', using flow_extract().
*
* If 'packet' is a TCP packet, then the reader attempts to reconstruct the
- * data stream. If successful, it returns an ofpbuf that represents the data
- * stream so far. The caller may examine the data in the ofpbuf and pull off
+ * data stream. If successful, it returns an dp_packet that represents the data
+ * stream so far. The caller may examine the data in the dp_packet and pull off
* any data that it has fully processed. The remaining data that the caller
* does not pull off will be presented again in future calls if more data
* arrives in the stream.
*
* Returns null if 'packet' doesn't add new data to a TCP stream. */
-struct ofpbuf *
+struct dp_packet *
tcp_reader_run(struct tcp_reader *r, const struct flow *flow,
- const struct ofpbuf *packet)
+ const struct dp_packet *packet)
{
struct tcp_stream *stream;
struct tcp_header *tcp;
- struct ofpbuf *payload;
+ struct dp_packet *payload;
unsigned int l7_length;
struct tcp_key key;
uint32_t hash;
uint32_t seq;
uint8_t flags;
- const char *l7 = ofpbuf_get_tcp_payload(packet);
+ const char *l7 = dp_packet_get_tcp_payload(packet);
if (flow->dl_type != htons(ETH_TYPE_IP)
|| flow->nw_proto != IPPROTO_TCP
|| !l7) {
return NULL;
}
- tcp = ofpbuf_l4(packet);
+ tcp = dp_packet_l4(packet);
flags = TCP_FLAGS(tcp->tcp_ctl);
- l7_length = (char *) ofpbuf_tail(packet) - l7;
+ l7_length = (char *) dp_packet_tail(packet) - l7;
seq = ntohl(get_16aligned_be32(&tcp->tcp_seq));
/* Construct key. */
@@ -336,7 +336,7 @@ tcp_reader_run(struct tcp_reader *r, const struct flow *flow,
payload = &stream->payload;
if (flags & TCP_SYN || !stream->seq_no) {
- ofpbuf_clear(payload);
+ dp_packet_clear(payload);
stream->seq_no = seq + 1;
return NULL;
} else if (flags & (TCP_FIN | TCP_RST)) {
@@ -346,9 +346,9 @@ tcp_reader_run(struct tcp_reader *r, const struct flow *flow,
/* Shift all of the existing payload to the very beginning of the
* allocated space, so that we reuse allocated space instead of
* continually expanding it. */
- ofpbuf_shift(payload, (char *) ofpbuf_base(payload) - (char *) ofpbuf_data(payload));
+ dp_packet_shift(payload, (char *) dp_packet_base(payload) - (char *) dp_packet_data(payload));
- ofpbuf_put(payload, l7, l7_length);
+ dp_packet_put(payload, l7, l7_length);
stream->seq_no += l7_length;
return payload;
} else {
diff --git a/lib/pcap-file.h b/lib/pcap-file.h
index 5d79ccbea..ddc40022d 100644
--- a/lib/pcap-file.h
+++ b/lib/pcap-file.h
@@ -20,20 +20,20 @@
#include <stdio.h>
struct flow;
-struct ofpbuf;
+struct dp_packet;
/* PCAP file reading and writing. */
FILE *ovs_pcap_open(const char *file_name, const char *mode);
int ovs_pcap_read_header(FILE *);
void ovs_pcap_write_header(FILE *);
-int ovs_pcap_read(FILE *, struct ofpbuf **, long long int *when);
-void ovs_pcap_write(FILE *, struct ofpbuf *);
+int ovs_pcap_read(FILE *, struct dp_packet **, long long int *when);
+void ovs_pcap_write(FILE *, struct dp_packet *);
/* Extracting TCP stream data from an Ethernet packet capture. */
struct tcp_reader *tcp_reader_open(void);
void tcp_reader_close(struct tcp_reader *);
-struct ofpbuf *tcp_reader_run(struct tcp_reader *, const struct flow *,
- const struct ofpbuf *);
+struct dp_packet *tcp_reader_run(struct tcp_reader *, const struct flow *,
+ const struct dp_packet *);
#endif /* pcap-file.h */
diff --git a/lib/rstp-common.h b/lib/rstp-common.h
index 452417e66..5b257d016 100644
--- a/lib/rstp-common.h
+++ b/lib/rstp-common.h
@@ -866,7 +866,7 @@ struct rstp {
struct ovs_refcount ref_cnt;
/* Interface to client. */
- void (*send_bpdu)(struct ofpbuf *bpdu, void *port_aux, void *rstp_aux);
+ void (*send_bpdu)(struct dp_packet *bpdu, void *port_aux, void *rstp_aux);
void *aux;
bool root_changed;
diff --git a/lib/rstp-state-machines.c b/lib/rstp-state-machines.c
index 320201897..d254ca343 100644
--- a/lib/rstp-state-machines.c
+++ b/lib/rstp-state-machines.c
@@ -38,6 +38,7 @@
#include "byte-order.h"
#include "connectivity.h"
#include "ofpbuf.h"
+#include "dp-packet.h"
#include "packets.h"
#include "seq.h"
#include "unixctl.h"
@@ -689,19 +690,19 @@ rstp_send_bpdu(struct rstp_port *p, const void *bpdu, size_t bpdu_size)
{
struct eth_header *eth;
struct llc_header *llc;
- struct ofpbuf *pkt;
+ struct dp_packet *pkt;
/* Skeleton. */
- pkt = ofpbuf_new(ETH_HEADER_LEN + LLC_HEADER_LEN + bpdu_size);
- eth = ofpbuf_put_zeros(pkt, sizeof *eth);
- llc = ofpbuf_put_zeros(pkt, sizeof *llc);
- ofpbuf_set_frame(pkt, eth);
- ofpbuf_set_l3(pkt, ofpbuf_put(pkt, bpdu, bpdu_size));
+ pkt = dp_packet_new(ETH_HEADER_LEN + LLC_HEADER_LEN + bpdu_size);
+ eth = dp_packet_put_zeros(pkt, sizeof *eth);
+ llc = dp_packet_put_zeros(pkt, sizeof *llc);
+ dp_packet_set_frame(pkt, eth);
+ dp_packet_set_l3(pkt, dp_packet_put(pkt, bpdu, bpdu_size));
/* 802.2 header. */
memcpy(eth->eth_dst, eth_addr_stp, ETH_ADDR_LEN);
/* p->rstp->send_bpdu() must fill in source address. */
- eth->eth_type = htons(ofpbuf_size(pkt) - ETH_HEADER_LEN);
+ eth->eth_type = htons(dp_packet_size(pkt) - ETH_HEADER_LEN);
/* LLC header. */
llc->llc_dsap = STP_LLC_DSAP;
diff --git a/lib/rstp.c b/lib/rstp.c
index 3b314b4c5..a057c60f1 100644
--- a/lib/rstp.c
+++ b/lib/rstp.c
@@ -40,6 +40,7 @@
#include "connectivity.h"
#include "ofpbuf.h"
#include "ofproto/ofproto.h"
+#include "dp-packet.h"
#include "packets.h"
#include "seq.h"
#include "unixctl.h"
@@ -243,7 +244,7 @@ rstp_init(void)
/* Creates and returns a new RSTP instance that initially has no ports. */
struct rstp *
rstp_create(const char *name, rstp_identifier bridge_address,
- void (*send_bpdu)(struct ofpbuf *bpdu, void *port_aux,
+ void (*send_bpdu)(struct dp_packet *bpdu, void *port_aux,
void *rstp_aux),
void *aux)
OVS_EXCLUDED(rstp_mutex)
diff --git a/lib/rstp.h b/lib/rstp.h
index 8b5776191..824d9f8aa 100644
--- a/lib/rstp.h
+++ b/lib/rstp.h
@@ -43,7 +43,7 @@ extern struct ovs_mutex rstp_mutex;
#define RSTP_MAX_PORTS 4095
-struct ofpbuf;
+struct dp_packet;
/* Bridge priority defaults [Table 17-2] */
#define RSTP_MIN_PRIORITY 0
@@ -140,7 +140,7 @@ void rstp_init(void)
OVS_EXCLUDED(rstp_mutex);
struct rstp * rstp_create(const char *, rstp_identifier bridge_id,
- void (*send_bpdu)(struct ofpbuf *, void *port_aux,
+ void (*send_bpdu)(struct dp_packet *, void *port_aux,
void *rstp_aux),
void *aux)
OVS_EXCLUDED(rstp_mutex);
diff --git a/lib/stp.c b/lib/stp.c
index 1e88cba89..ec8b01a4e 100644
--- a/lib/stp.c
+++ b/lib/stp.c
@@ -29,6 +29,7 @@
#include "connectivity.h"
#include "ofpbuf.h"
#include "ovs-atomic.h"
+#include "dp-packet.h"
#include "packets.h"
#include "seq.h"
#include "unixctl.h"
@@ -144,7 +145,7 @@ struct stp {
/* Interface to client. */
bool fdb_needs_flush; /* MAC learning tables needs flushing. */
struct stp_port *first_changed_port;
- void (*send_bpdu)(struct ofpbuf *bpdu, int port_no, void *aux);
+ void (*send_bpdu)(struct dp_packet *bpdu, int port_no, void *aux);
void *aux;
struct ovs_refcount ref_cnt;
@@ -258,7 +259,7 @@ stp_init(void)
*/
struct stp *
stp_create(const char *name, stp_identifier bridge_id,
- void (*send_bpdu)(struct ofpbuf *bpdu, int port_no, void *aux),
+ void (*send_bpdu)(struct dp_packet *bpdu, int port_no, void *aux),
void *aux)
{
static struct ovsthread_once once = OVSTHREAD_ONCE_INITIALIZER;
@@ -1569,19 +1570,19 @@ stp_send_bpdu(struct stp_port *p, const void *bpdu, size_t bpdu_size)
{
struct eth_header *eth;
struct llc_header *llc;
- struct ofpbuf *pkt;
+ struct dp_packet *pkt;
/* Skeleton. */
- pkt = ofpbuf_new(ETH_HEADER_LEN + LLC_HEADER_LEN + bpdu_size);
- eth = ofpbuf_put_zeros(pkt, sizeof *eth);
- llc = ofpbuf_put_zeros(pkt, sizeof *llc);
- ofpbuf_set_frame(pkt, eth);
- ofpbuf_set_l3(pkt, ofpbuf_put(pkt, bpdu, bpdu_size));
+ pkt = dp_packet_new(ETH_HEADER_LEN + LLC_HEADER_LEN + bpdu_size);
+ eth = dp_packet_put_zeros(pkt, sizeof *eth);
+ llc = dp_packet_put_zeros(pkt, sizeof *llc);
+ dp_packet_set_frame(pkt, eth);
+ dp_packet_set_l3(pkt, dp_packet_put(pkt, bpdu, bpdu_size));
/* 802.2 header. */
memcpy(eth->eth_dst, eth_addr_stp, ETH_ADDR_LEN);
/* p->stp->send_bpdu() must fill in source address. */
- eth->eth_type = htons(ofpbuf_size(pkt) - ETH_HEADER_LEN);
+ eth->eth_type = htons(dp_packet_size(pkt) - ETH_HEADER_LEN);
/* LLC header. */
llc->llc_dsap = STP_LLC_DSAP;
diff --git a/lib/stp.h b/lib/stp.h
index 3d13bbaea..9f945ad21 100644
--- a/lib/stp.h
+++ b/lib/stp.h
@@ -25,7 +25,7 @@
#include "compiler.h"
#include "util.h"
-struct ofpbuf;
+struct dp_packet;
/* Bridge and port priorities that should be used by default. */
#define STP_DEFAULT_BRIDGE_PRIORITY 32768
@@ -52,7 +52,7 @@ typedef uint64_t stp_identifier;
#define STP_MAX_PORTS 255
void stp_init(void);
struct stp *stp_create(const char *name, stp_identifier bridge_id,
- void (*send_bpdu)(struct ofpbuf *bpdu, int port_no,
+ void (*send_bpdu)(struct dp_packet *bpdu, int port_no,
void *aux),
void *aux);
struct stp *stp_ref(const struct stp *);