From: Pravin B Shelar Date: Sun, 22 Feb 2015 11:21:09 +0000 (-0800) Subject: dp-packet: Remove ofpbuf dependency. X-Git-Tag: v2.4.0~542 X-Git-Url: http://git.cascardo.eti.br/?p=cascardo%2Fovs.git;a=commitdiff_plain;h=cf62fa4c7074121184a1f1d07980990113657612 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 Acked-by: Jarno Rajahalme Acked-by: Ben Pfaff --- 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 +#include +#include +#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 +#include +#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 #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 #include #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 #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 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 *); diff --git a/ofproto/bond.c b/ofproto/bond.c index 89979a042..7831fa41e 100644 --- a/ofproto/bond.c +++ b/ofproto/bond.c @@ -39,6 +39,7 @@ #include "odp-util.h" #include "ofpbuf.h" #include "packets.h" +#include "dp-packet.h" #include "poll-loop.h" #include "seq.h" #include "match.h" @@ -718,13 +719,13 @@ bond_should_send_learning_packets(struct bond *bond) * See bond_should_send_learning_packets() for description of usage. The * caller should send the composed packet on the port associated with * port_aux and takes ownership of the returned ofpbuf. */ -struct ofpbuf * +struct dp_packet * bond_compose_learning_packet(struct bond *bond, const uint8_t eth_src[ETH_ADDR_LEN], uint16_t vlan, void **port_aux) { struct bond_slave *slave; - struct ofpbuf *packet; + struct dp_packet *packet; struct flow flow; ovs_rwlock_rdlock(&rwlock); @@ -733,7 +734,7 @@ bond_compose_learning_packet(struct bond *bond, memcpy(flow.dl_src, eth_src, ETH_ADDR_LEN); slave = choose_output_slave(bond, &flow, NULL, vlan); - packet = ofpbuf_new(0); + packet = dp_packet_new(0); compose_rarp(packet, eth_src); if (vlan) { eth_push_vlan(packet, htons(ETH_TYPE_VLAN), htons(vlan)); diff --git a/ofproto/bond.h b/ofproto/bond.h index c7b630870..9082354b5 100644 --- a/ofproto/bond.h +++ b/ofproto/bond.h @@ -81,7 +81,7 @@ void bond_slave_set_may_enable(struct bond *, void *slave_, bool may_enable); /* Special MAC learning support for SLB bonding. */ bool bond_should_send_learning_packets(struct bond *); -struct ofpbuf *bond_compose_learning_packet(struct bond *, +struct dp_packet *bond_compose_learning_packet(struct bond *, const uint8_t eth_src[ETH_ADDR_LEN], uint16_t vlan, void **port_aux); bool bond_get_changed_active_slave(const char *name, uint8_t mac[ETH_ADDR_LEN], diff --git a/ofproto/connmgr.c b/ofproto/connmgr.c index 82143aaec..09771a6bd 100644 --- a/ofproto/connmgr.c +++ b/ofproto/connmgr.c @@ -1133,7 +1133,7 @@ ofconn_send_error(const struct ofconn *ofconn, /* Same as pktbuf_retrieve(), using the pktbuf owned by 'ofconn'. */ enum ofperr ofconn_pktbuf_retrieve(struct ofconn *ofconn, uint32_t id, - struct ofpbuf **bufferp, ofp_port_t *in_port) + struct dp_packet **bufferp, ofp_port_t *in_port) { return pktbuf_retrieve(ofconn->pktbuf, id, bufferp, in_port); } diff --git a/ofproto/connmgr.h b/ofproto/connmgr.h index dd1a027e3..193afa853 100644 --- a/ofproto/connmgr.h +++ b/ofproto/connmgr.h @@ -154,7 +154,7 @@ void ofconn_send_error(const struct ofconn *, const struct ofp_header *request, enum ofperr); enum ofperr ofconn_pktbuf_retrieve(struct ofconn *, uint32_t id, - struct ofpbuf **bufferp, ofp_port_t *in_port); + struct dp_packet **bufferp, ofp_port_t *in_port); struct hmap *ofconn_get_bundles(struct ofconn *ofconn); diff --git a/ofproto/fail-open.c b/ofproto/fail-open.c index 75c7d1c80..c60f6b9e9 100644 --- a/ofproto/fail-open.c +++ b/ofproto/fail-open.c @@ -23,12 +23,13 @@ #include "flow.h" #include "mac-learning.h" #include "odp-util.h" +#include "ofpbuf.h" #include "ofp-actions.h" #include "ofp-util.h" -#include "ofpbuf.h" #include "ofproto.h" #include "ofproto-provider.h" #include "pktbuf.h" +#include "dp-packet.h" #include "poll-loop.h" #include "rconn.h" #include "timeval.h" @@ -119,22 +120,22 @@ send_bogus_packet_ins(struct fail_open *fo) { struct ofproto_packet_in pin; uint8_t mac[ETH_ADDR_LEN]; - struct ofpbuf b; + struct dp_packet b; - ofpbuf_init(&b, 128); + dp_packet_init(&b, 128); eth_addr_nicira_random(mac); compose_rarp(&b, mac); memset(&pin, 0, sizeof pin); - pin.up.packet = ofpbuf_data(&b); - pin.up.packet_len = ofpbuf_size(&b); + pin.up.packet = dp_packet_data(&b); + pin.up.packet_len = dp_packet_size(&b); pin.up.reason = OFPR_NO_MATCH; pin.up.fmd.in_port = OFPP_LOCAL; - pin.send_len = ofpbuf_size(&b); + pin.send_len = dp_packet_size(&b); pin.miss_type = OFPROTO_PACKET_IN_NO_MISS; connmgr_send_packet_in(fo->connmgr, &pin); - ofpbuf_uninit(&b); + dp_packet_uninit(&b); } /* Enter fail-open mode if we should be in it. */ diff --git a/ofproto/ofproto-dpif-ipfix.c b/ofproto/ofproto-dpif-ipfix.c index 3ba6dce18..f73d8b456 100644 --- a/ofproto/ofproto-dpif-ipfix.c +++ b/ofproto/ofproto-dpif-ipfix.c @@ -26,6 +26,7 @@ #include "ofpbuf.h" #include "ofproto.h" #include "ofproto-dpif.h" +#include "dp-packet.h" #include "packets.h" #include "poll-loop.h" #include "sset.h" @@ -970,11 +971,11 @@ dpif_ipfix_unref(struct dpif_ipfix *di) OVS_EXCLUDED(mutex) static void ipfix_init_header(uint32_t export_time_sec, uint32_t seq_number, - uint32_t obs_domain_id, struct ofpbuf *msg) + uint32_t obs_domain_id, struct dp_packet *msg) { struct ipfix_header *hdr; - hdr = ofpbuf_put_zeros(msg, sizeof *hdr); + hdr = dp_packet_put_zeros(msg, sizeof *hdr); hdr->version = htons(IPFIX_VERSION); hdr->length = htons(sizeof *hdr); /* Updated in ipfix_send_msg. */ hdr->export_time = htonl(export_time_sec); @@ -983,16 +984,16 @@ ipfix_init_header(uint32_t export_time_sec, uint32_t seq_number, } static void -ipfix_send_msg(const struct collectors *collectors, struct ofpbuf *msg) +ipfix_send_msg(const struct collectors *collectors, struct dp_packet *msg) { struct ipfix_header *hdr; /* Adjust the length in the header. */ - hdr = ofpbuf_data(msg); - hdr->length = htons(ofpbuf_size(msg)); + hdr = dp_packet_data(msg); + hdr->length = htons(dp_packet_size(msg)); - collectors_send(collectors, ofpbuf_data(msg), ofpbuf_size(msg)); - ofpbuf_set_size(msg, 0); + collectors_send(collectors, dp_packet_data(msg), dp_packet_size(msg)); + dp_packet_set_size(msg, 0); } static uint16_t @@ -1011,7 +1012,7 @@ static void ipfix_define_template_entity(enum ipfix_entity_id id, enum ipfix_entity_size size, enum ipfix_entity_enterprise enterprise, - struct ofpbuf *msg) + struct dp_packet *msg) { struct ipfix_template_field_specifier *field; size_t field_size; @@ -1022,7 +1023,7 @@ ipfix_define_template_entity(enum ipfix_entity_id id, /* No enterprise number */ field_size = sizeof *field - sizeof(ovs_be32); } - field = ofpbuf_put_zeros(msg, field_size); + field = dp_packet_put_zeros(msg, field_size); field->element_id = htons(id); if (size) { field->field_length = htons(size); @@ -1039,7 +1040,7 @@ ipfix_define_template_entity(enum ipfix_entity_id id, static uint16_t ipfix_define_template_fields(enum ipfix_proto_l2 l2, enum ipfix_proto_l3 l3, enum ipfix_proto_l4 l4, enum ipfix_proto_tunnel tunnel, - struct ofpbuf *msg) + struct dp_packet *msg) { uint16_t count = 0; @@ -1134,34 +1135,34 @@ ipfix_define_template_fields(enum ipfix_proto_l2 l2, enum ipfix_proto_l3 l3, static void ipfix_init_template_msg(void *msg_stub, uint32_t export_time_sec, uint32_t seq_number, uint32_t obs_domain_id, - struct ofpbuf *msg, size_t *set_hdr_offset) + struct dp_packet *msg, size_t *set_hdr_offset) { struct ipfix_set_header *set_hdr; - ofpbuf_use_stub(msg, msg_stub, sizeof msg_stub); + dp_packet_use_stub(msg, msg_stub, sizeof msg_stub); ipfix_init_header(export_time_sec, seq_number, obs_domain_id, msg); - *set_hdr_offset = ofpbuf_size(msg); + *set_hdr_offset = dp_packet_size(msg); /* Add a Template Set. */ - set_hdr = ofpbuf_put_zeros(msg, sizeof *set_hdr); + set_hdr = dp_packet_put_zeros(msg, sizeof *set_hdr); set_hdr->set_id = htons(IPFIX_SET_ID_TEMPLATE); } static void ipfix_send_template_msg(const struct collectors *collectors, - struct ofpbuf *msg, size_t set_hdr_offset) + struct dp_packet *msg, size_t set_hdr_offset) { struct ipfix_set_header *set_hdr; /* Send template message. */ set_hdr = (struct ipfix_set_header*) - ((uint8_t*)ofpbuf_data(msg) + set_hdr_offset); - set_hdr->length = htons(ofpbuf_size(msg) - set_hdr_offset); + ((uint8_t*)dp_packet_data(msg) + set_hdr_offset); + set_hdr->length = htons(dp_packet_size(msg) - set_hdr_offset); ipfix_send_msg(collectors, msg); - ofpbuf_uninit(msg); + dp_packet_uninit(msg); } static void @@ -1169,7 +1170,7 @@ ipfix_send_template_msgs(struct dpif_ipfix_exporter *exporter, uint32_t export_time_sec, uint32_t obs_domain_id) { uint64_t msg_stub[DIV_ROUND_UP(MAX_MESSAGE_LEN, 8)]; - struct ofpbuf msg; + struct dp_packet msg; size_t set_hdr_offset, tmpl_hdr_offset; struct ipfix_template_record_header *tmpl_hdr; uint16_t field_count; @@ -1195,7 +1196,7 @@ ipfix_send_template_msgs(struct dpif_ipfix_exporter *exporter, * And then reinitialize the msg to construct a new * packet for the following templates. */ - if (ofpbuf_size(&msg) >= MAX_MESSAGE_LEN) { + if (dp_packet_size(&msg) >= MAX_MESSAGE_LEN) { /* Send template message. */ ipfix_send_template_msg(exporter->collectors, &msg, set_hdr_offset); @@ -1207,14 +1208,14 @@ ipfix_send_template_msgs(struct dpif_ipfix_exporter *exporter, &set_hdr_offset); } - tmpl_hdr_offset = ofpbuf_size(&msg); - tmpl_hdr = ofpbuf_put_zeros(&msg, sizeof *tmpl_hdr); + tmpl_hdr_offset = dp_packet_size(&msg); + tmpl_hdr = dp_packet_put_zeros(&msg, sizeof *tmpl_hdr); tmpl_hdr->template_id = htons( ipfix_get_template_id(l2, l3, l4, tunnel)); field_count = ipfix_define_template_fields(l2, l3, l4, tunnel, &msg); tmpl_hdr = (struct ipfix_template_record_header*) - ((uint8_t*)ofpbuf_data(&msg) + tmpl_hdr_offset); + ((uint8_t*)dp_packet_data(&msg) + tmpl_hdr_offset); tmpl_hdr->field_count = htons(field_count); } } @@ -1358,14 +1359,14 @@ ipfix_cache_update(struct dpif_ipfix_exporter *exporter, static void ipfix_cache_entry_init(struct ipfix_flow_cache_entry *entry, - const struct ofpbuf *packet, const struct flow *flow, + const struct dp_packet *packet, const struct flow *flow, uint64_t packet_delta_count, uint32_t obs_domain_id, uint32_t obs_point_id, odp_port_t output_odp_port, const struct dpif_ipfix_port *tunnel_port, const struct flow_tnl *tunnel_key) { struct ipfix_flow_key *flow_key; - struct ofpbuf msg; + struct dp_packet msg; enum ipfix_proto_l2 l2; enum ipfix_proto_l3 l3; enum ipfix_proto_l4 l4; @@ -1374,8 +1375,8 @@ ipfix_cache_entry_init(struct ipfix_flow_cache_entry *entry, uint16_t ethernet_total_length; flow_key = &entry->flow_key; - ofpbuf_use_stack(&msg, flow_key->flow_key_msg_part, - sizeof flow_key->flow_key_msg_part); + dp_packet_use_stub(&msg, flow_key->flow_key_msg_part, + sizeof flow_key->flow_key_msg_part); /* Choose the right template ID matching the protocols in the * sampled packet. */ @@ -1430,13 +1431,13 @@ ipfix_cache_entry_init(struct ipfix_flow_cache_entry *entry, ethernet_header_length = (l2 == IPFIX_PROTO_L2_VLAN) ? VLAN_ETH_HEADER_LEN : ETH_HEADER_LEN; - ethernet_total_length = ofpbuf_size(packet); + ethernet_total_length = dp_packet_size(packet); /* Common Ethernet entities. */ { struct ipfix_data_record_flow_key_common *data_common; - data_common = ofpbuf_put_zeros(&msg, sizeof *data_common); + data_common = dp_packet_put_zeros(&msg, sizeof *data_common); data_common->observation_point_id = htonl(obs_point_id); data_common->flow_direction = (output_odp_port == ODPP_NONE) ? INGRESS_FLOW : EGRESS_FLOW; @@ -1453,7 +1454,7 @@ ipfix_cache_entry_init(struct ipfix_flow_cache_entry *entry, uint16_t vlan_id = vlan_tci_to_vid(flow->vlan_tci); uint8_t priority = vlan_tci_to_pcp(flow->vlan_tci); - data_vlan = ofpbuf_put_zeros(&msg, sizeof *data_vlan); + data_vlan = dp_packet_put_zeros(&msg, sizeof *data_vlan); data_vlan->vlan_id = htons(vlan_id); data_vlan->dot1q_vlan_id = htons(vlan_id); data_vlan->dot1q_priority = priority; @@ -1462,7 +1463,7 @@ ipfix_cache_entry_init(struct ipfix_flow_cache_entry *entry, if (l3 != IPFIX_PROTO_L3_UNKNOWN) { struct ipfix_data_record_flow_key_ip *data_ip; - data_ip = ofpbuf_put_zeros(&msg, sizeof *data_ip); + data_ip = dp_packet_put_zeros(&msg, sizeof *data_ip); data_ip->ip_version = (l3 == IPFIX_PROTO_L3_IPV4) ? 4 : 6; data_ip->ip_ttl = flow->nw_ttl; data_ip->protocol_identifier = flow->nw_proto; @@ -1473,13 +1474,13 @@ ipfix_cache_entry_init(struct ipfix_flow_cache_entry *entry, if (l3 == IPFIX_PROTO_L3_IPV4) { struct ipfix_data_record_flow_key_ipv4 *data_ipv4; - data_ipv4 = ofpbuf_put_zeros(&msg, sizeof *data_ipv4); + data_ipv4 = dp_packet_put_zeros(&msg, sizeof *data_ipv4); data_ipv4->source_ipv4_address = flow->nw_src; data_ipv4->destination_ipv4_address = flow->nw_dst; } else { /* l3 == IPFIX_PROTO_L3_IPV6 */ struct ipfix_data_record_flow_key_ipv6 *data_ipv6; - data_ipv6 = ofpbuf_put_zeros(&msg, sizeof *data_ipv6); + data_ipv6 = dp_packet_put_zeros(&msg, sizeof *data_ipv6); memcpy(data_ipv6->source_ipv6_address, &flow->ipv6_src, sizeof flow->ipv6_src); memcpy(data_ipv6->destination_ipv6_address, &flow->ipv6_dst, @@ -1491,13 +1492,13 @@ ipfix_cache_entry_init(struct ipfix_flow_cache_entry *entry, if (l4 == IPFIX_PROTO_L4_TCP_UDP_SCTP) { struct ipfix_data_record_flow_key_transport *data_transport; - data_transport = ofpbuf_put_zeros(&msg, sizeof *data_transport); + data_transport = dp_packet_put_zeros(&msg, sizeof *data_transport); data_transport->source_transport_port = flow->tp_src; data_transport->destination_transport_port = flow->tp_dst; } else if (l4 == IPFIX_PROTO_L4_ICMP) { struct ipfix_data_record_flow_key_icmp *data_icmp; - data_icmp = ofpbuf_put_zeros(&msg, sizeof *data_icmp); + data_icmp = dp_packet_put_zeros(&msg, sizeof *data_icmp); data_icmp->icmp_type = ntohs(flow->tp_src) & 0xff; data_icmp->icmp_code = ntohs(flow->tp_dst) & 0xff; } @@ -1506,7 +1507,7 @@ ipfix_cache_entry_init(struct ipfix_flow_cache_entry *entry, struct ipfix_data_record_flow_key_tunnel *data_tunnel; const uint8_t *tun_id; - data_tunnel = ofpbuf_put_zeros(&msg, sizeof *data_tunnel + + data_tunnel = dp_packet_put_zeros(&msg, sizeof *data_tunnel + tunnel_port->tunnel_key_length); data_tunnel->tunnel_source_ipv4_address = tunnel_key->ip_src; data_tunnel->tunnel_destination_ipv4_address = tunnel_key->ip_dst; @@ -1532,7 +1533,7 @@ ipfix_cache_entry_init(struct ipfix_flow_cache_entry *entry, tunnel_port->tunnel_key_length); } - flow_key->flow_key_msg_part_size = ofpbuf_size(&msg); + flow_key->flow_key_msg_part_size = dp_packet_size(&msg); { struct timeval now; @@ -1578,20 +1579,20 @@ static void ipfix_put_data_set(uint32_t export_time_sec, struct ipfix_flow_cache_entry *entry, enum ipfix_flow_end_reason flow_end_reason, - struct ofpbuf *msg) + struct dp_packet *msg) { size_t set_hdr_offset; struct ipfix_set_header *set_hdr; - set_hdr_offset = ofpbuf_size(msg); + set_hdr_offset = dp_packet_size(msg); /* Put a Data Set. */ - set_hdr = ofpbuf_put_zeros(msg, sizeof *set_hdr); + set_hdr = dp_packet_put_zeros(msg, sizeof *set_hdr); set_hdr->set_id = htons(entry->flow_key.template_id); /* Copy the flow key part of the data record. */ - ofpbuf_put(msg, entry->flow_key.flow_key_msg_part, + dp_packet_put(msg, entry->flow_key.flow_key_msg_part, entry->flow_key.flow_key_msg_part_size); /* Put the non-key part of the data record. */ @@ -1609,7 +1610,7 @@ ipfix_put_data_set(uint32_t export_time_sec, flow_end_delta_usec = export_time_usec - entry->flow_end_timestamp_usec; - data_aggregated_common = ofpbuf_put_zeros( + data_aggregated_common = dp_packet_put_zeros( msg, sizeof *data_aggregated_common); data_aggregated_common->flow_start_delta_microseconds = htonl( flow_start_delta_usec); @@ -1625,7 +1626,7 @@ ipfix_put_data_set(uint32_t export_time_sec, if (entry->octet_delta_sum_of_squares) { /* IP packet. */ struct ipfix_data_record_aggregated_ip *data_aggregated_ip; - data_aggregated_ip = ofpbuf_put_zeros( + data_aggregated_ip = dp_packet_put_zeros( msg, sizeof *data_aggregated_ip); data_aggregated_ip->octet_delta_count = htonll( entry->octet_delta_count); @@ -1637,8 +1638,8 @@ ipfix_put_data_set(uint32_t export_time_sec, entry->maximum_ip_total_length); } - set_hdr = (struct ipfix_set_header*)((uint8_t*)ofpbuf_data(msg) + set_hdr_offset); - set_hdr->length = htons(ofpbuf_size(msg) - set_hdr_offset); + set_hdr = (struct ipfix_set_header*)((uint8_t*)dp_packet_data(msg) + set_hdr_offset); + set_hdr->length = htons(dp_packet_size(msg) - set_hdr_offset); } /* Send an IPFIX message with a single data record. */ @@ -1649,20 +1650,20 @@ ipfix_send_data_msg(struct dpif_ipfix_exporter *exporter, enum ipfix_flow_end_reason flow_end_reason) { uint64_t msg_stub[DIV_ROUND_UP(MAX_MESSAGE_LEN, 8)]; - struct ofpbuf msg; - ofpbuf_use_stub(&msg, msg_stub, sizeof msg_stub); + struct dp_packet msg; + dp_packet_use_stub(&msg, msg_stub, sizeof msg_stub); ipfix_init_header(export_time_sec, exporter->seq_number++, entry->flow_key.obs_domain_id, &msg); ipfix_put_data_set(export_time_sec, entry, flow_end_reason, &msg); ipfix_send_msg(exporter->collectors, &msg); - ofpbuf_uninit(&msg); + dp_packet_uninit(&msg); } static void dpif_ipfix_sample(struct dpif_ipfix_exporter *exporter, - const struct ofpbuf *packet, const struct flow *flow, + const struct dp_packet *packet, const struct flow *flow, uint64_t packet_delta_count, uint32_t obs_domain_id, uint32_t obs_point_id, odp_port_t output_odp_port, const struct dpif_ipfix_port *tunnel_port, @@ -1679,7 +1680,7 @@ dpif_ipfix_sample(struct dpif_ipfix_exporter *exporter, } void -dpif_ipfix_bridge_sample(struct dpif_ipfix *di, const struct ofpbuf *packet, +dpif_ipfix_bridge_sample(struct dpif_ipfix *di, const struct dp_packet *packet, const struct flow *flow, odp_port_t input_odp_port, odp_port_t output_odp_port, const struct flow_tnl *output_tunnel_key) @@ -1714,7 +1715,7 @@ dpif_ipfix_bridge_sample(struct dpif_ipfix *di, const struct ofpbuf *packet, } void -dpif_ipfix_flow_sample(struct dpif_ipfix *di, const struct ofpbuf *packet, +dpif_ipfix_flow_sample(struct dpif_ipfix *di, const struct dp_packet *packet, const struct flow *flow, uint32_t collector_set_id, uint16_t probability, uint32_t obs_domain_id, uint32_t obs_point_id) OVS_EXCLUDED(mutex) diff --git a/ofproto/ofproto-dpif-ipfix.h b/ofproto/ofproto-dpif-ipfix.h index e86fb9324..2bb0e43ff 100644 --- a/ofproto/ofproto-dpif-ipfix.h +++ b/ofproto/ofproto-dpif-ipfix.h @@ -23,7 +23,7 @@ #include "lib/odp-util.h" struct flow; -struct ofpbuf; +struct dp_packet; struct ofproto_ipfix_bridge_exporter_options; struct ofproto_ipfix_flow_exporter_options; struct flow_tnl; @@ -46,10 +46,10 @@ void dpif_ipfix_set_options( const struct ofproto_ipfix_bridge_exporter_options *, const struct ofproto_ipfix_flow_exporter_options *, size_t); -void dpif_ipfix_bridge_sample(struct dpif_ipfix *, const struct ofpbuf *, +void dpif_ipfix_bridge_sample(struct dpif_ipfix *, const struct dp_packet *, const struct flow *, odp_port_t, odp_port_t, const struct flow_tnl *); -void dpif_ipfix_flow_sample(struct dpif_ipfix *, const struct ofpbuf *, +void dpif_ipfix_flow_sample(struct dpif_ipfix *, const struct dp_packet *, const struct flow *, uint32_t, uint16_t, uint32_t, uint32_t); diff --git a/ofproto/ofproto-dpif-monitor.c b/ofproto/ofproto-dpif-monitor.c index 14de027b3..ed59f9e09 100644 --- a/ofproto/ofproto-dpif-monitor.c +++ b/ofproto/ofproto-dpif-monitor.c @@ -21,6 +21,7 @@ #include "bfd.h" #include "cfm.h" +#include "dp-packet.h" #include "guarded-list.h" #include "hash.h" #include "heap.h" @@ -80,9 +81,9 @@ static struct latch monitor_exit_latch; static struct ovs_mutex monitor_mutex = OVS_MUTEX_INITIALIZER; static void *monitor_main(void *); -static void monitor_check_send_soon(struct ofpbuf *); +static void monitor_check_send_soon(struct dp_packet *); static void monitor_run(void); -static void monitor_mport_run(struct mport *, struct ofpbuf *); +static void monitor_mport_run(struct mport *, struct dp_packet *); static void mport_register(const struct ofport_dpif *, struct bfd *, struct cfm *, uint8_t[ETH_ADDR_LEN]) @@ -194,9 +195,9 @@ monitor_run(void) { uint32_t stub[512 / 4]; long long int prio_now; - struct ofpbuf packet; + struct dp_packet packet; - ofpbuf_use_stub(&packet, stub, sizeof stub); + dp_packet_use_stub(&packet, stub, sizeof stub); ovs_mutex_lock(&monitor_mutex); /* The monitor_check_send_soon() needs to be run twice. The first @@ -227,13 +228,13 @@ monitor_run(void) poll_timer_wait_until(MIN(next_timeout, next_mport_wakeup)); } ovs_mutex_unlock(&monitor_mutex); - ofpbuf_uninit(&packet); + dp_packet_uninit(&packet); } /* Checks the 'send_soon' list for any mport that needs to send cfm/bfd * control packet immediately, and calls monitor_mport_run(). */ static void -monitor_check_send_soon(struct ofpbuf *packet) +monitor_check_send_soon(struct dp_packet *packet) OVS_REQUIRES(monitor_mutex) { while (!guarded_list_is_empty(&send_soon)) { @@ -255,18 +256,18 @@ monitor_check_send_soon(struct ofpbuf *packet) * on 'mport'. And changes the location of 'mport' in heap based on next * timeout. */ static void -monitor_mport_run(struct mport *mport, struct ofpbuf *packet) +monitor_mport_run(struct mport *mport, struct dp_packet *packet) OVS_REQUIRES(monitor_mutex) { long long int next_wake_time; if (mport->cfm && cfm_should_send_ccm(mport->cfm)) { - ofpbuf_clear(packet); + dp_packet_clear(packet); cfm_compose_ccm(mport->cfm, packet, mport->hw_addr); ofproto_dpif_send_packet(mport->ofport, packet); } if (mport->bfd && bfd_should_send_packet(mport->bfd)) { - ofpbuf_clear(packet); + dp_packet_clear(packet); bfd_put_packet(mport->bfd, packet, mport->hw_addr); ofproto_dpif_send_packet(mport->ofport, packet); } diff --git a/ofproto/ofproto-dpif-sflow.c b/ofproto/ofproto-dpif-sflow.c index 3113a5359..b146f5d78 100644 --- a/ofproto/ofproto-dpif-sflow.c +++ b/ofproto/ofproto-dpif-sflow.c @@ -753,7 +753,7 @@ dpif_sflow_odp_port_to_ifindex(const struct dpif_sflow *ds, } void -dpif_sflow_received(struct dpif_sflow *ds, const struct ofpbuf *packet, +dpif_sflow_received(struct dpif_sflow *ds, const struct dp_packet *packet, const struct flow *flow, odp_port_t odp_in_port, const union user_action_cookie *cookie) OVS_EXCLUDED(mutex) @@ -794,12 +794,12 @@ dpif_sflow_received(struct dpif_sflow *ds, const struct ofpbuf *packet, header->header_protocol = SFLHEADER_ETHERNET_ISO8023; /* The frame_length should include the Ethernet FCS (4 bytes), * but it has already been stripped, so we need to add 4 here. */ - header->frame_length = ofpbuf_size(packet) + 4; + header->frame_length = dp_packet_size(packet) + 4; /* Ethernet FCS stripped off. */ header->stripped = 4; - header->header_length = MIN(ofpbuf_size(packet), + header->header_length = MIN(dp_packet_size(packet), sampler->sFlowFsMaximumHeaderSize); - header->header_bytes = ofpbuf_data(packet); + header->header_bytes = dp_packet_data(packet); /* Add extended switch element. */ memset(&switchElem, 0, sizeof(switchElem)); diff --git a/ofproto/ofproto-dpif-sflow.h b/ofproto/ofproto-dpif-sflow.h index 130568aac..ff8b23158 100644 --- a/ofproto/ofproto-dpif-sflow.h +++ b/ofproto/ofproto-dpif-sflow.h @@ -46,7 +46,7 @@ void dpif_sflow_del_port(struct dpif_sflow *, odp_port_t odp_port); void dpif_sflow_run(struct dpif_sflow *); void dpif_sflow_wait(struct dpif_sflow *); -void dpif_sflow_received(struct dpif_sflow *, const struct ofpbuf *, +void dpif_sflow_received(struct dpif_sflow *, const struct dp_packet *, const struct flow *, odp_port_t odp_port, const union user_action_cookie *); diff --git a/ofproto/ofproto-dpif-upcall.c b/ofproto/ofproto-dpif-upcall.c index 748b0f1f8..2220c9bf4 100644 --- a/ofproto/ofproto-dpif-upcall.c +++ b/ofproto/ofproto-dpif-upcall.c @@ -159,7 +159,7 @@ struct upcall { const struct flow *flow; /* Parsed representation of the packet. */ const ovs_u128 *ufid; /* Unique identifier for 'flow'. */ int pmd_id; /* Datapath poll mode driver id. */ - const struct ofpbuf *packet; /* Packet associated with this upcall. */ + const struct dp_packet *packet; /* Packet associated with this upcall. */ ofp_port_t in_port; /* OpenFlow in port, or OFPP_NONE. */ enum dpif_upcall_type type; /* Datapath type of the upcall. */ @@ -288,7 +288,7 @@ static enum upcall_type classify_upcall(enum dpif_upcall_type type, const struct nlattr *userdata); static int upcall_receive(struct upcall *, const struct dpif_backer *, - const struct ofpbuf *packet, enum dpif_upcall_type, + const struct dp_packet *packet, enum dpif_upcall_type, const struct nlattr *userdata, const struct flow *, const ovs_u128 *ufid, const int pmd_id); static void upcall_uninit(struct upcall *); @@ -647,7 +647,6 @@ recv_upcalls(struct handler *handler) struct dpif_upcall *dupcall = &dupcalls[n_upcalls]; struct upcall *upcall = &upcalls[n_upcalls]; struct flow *flow = &flows[n_upcalls]; - struct pkt_metadata md; int error; ofpbuf_use_stub(recv_buf, recv_stubs[n_upcalls], @@ -690,8 +689,8 @@ recv_upcalls(struct handler *handler) upcall->vsp_adjusted = true; } - md = pkt_metadata_from_flow(flow); - flow_extract(&dupcall->packet, &md, flow); + pkt_metadata_from_flow(&dupcall->packet.md, flow); + flow_extract(&dupcall->packet, flow); error = process_upcall(udpif, upcall, NULL); if (error) { @@ -704,14 +703,14 @@ recv_upcalls(struct handler *handler) cleanup: upcall_uninit(upcall); free_dupcall: - ofpbuf_uninit(&dupcall->packet); + dp_packet_uninit(&dupcall->packet); ofpbuf_uninit(recv_buf); } if (n_upcalls) { handle_upcalls(handler->udpif, upcalls, n_upcalls); for (i = 0; i < n_upcalls; i++) { - ofpbuf_uninit(&dupcalls[i].packet); + dp_packet_uninit(&dupcalls[i].packet); ofpbuf_uninit(&recv_bufs[i]); upcall_uninit(&upcalls[i]); } @@ -892,7 +891,7 @@ compose_slow_path(struct udpif *udpif, struct xlate_out *xout, * since the 'upcall->put_actions' remains uninitialized. */ static int upcall_receive(struct upcall *upcall, const struct dpif_backer *backer, - const struct ofpbuf *packet, enum dpif_upcall_type type, + const struct dp_packet *packet, enum dpif_upcall_type type, const struct nlattr *userdata, const struct flow *flow, const ovs_u128 *ufid, const int pmd_id) { @@ -933,7 +932,7 @@ upcall_xlate(struct udpif *udpif, struct upcall *upcall, struct xlate_in xin; stats.n_packets = 1; - stats.n_bytes = ofpbuf_size(upcall->packet); + stats.n_bytes = dp_packet_size(upcall->packet); stats.used = time_msec(); stats.tcp_flags = ntohs(upcall->flow->tcp_flags); @@ -964,12 +963,12 @@ upcall_xlate(struct udpif *udpif, struct upcall *upcall, * * Copy packets before they are modified by execution. */ if (upcall->xout.fail_open) { - const struct ofpbuf *packet = upcall->packet; + const struct dp_packet *packet = upcall->packet; struct ofproto_packet_in *pin; pin = xmalloc(sizeof *pin); - pin->up.packet = xmemdup(ofpbuf_data(packet), ofpbuf_size(packet)); - pin->up.packet_len = ofpbuf_size(packet); + pin->up.packet = xmemdup(dp_packet_data(packet), dp_packet_size(packet)); + pin->up.packet_len = dp_packet_size(packet); pin->up.reason = OFPR_NO_MATCH; pin->up.table_id = 0; pin->up.cookie = OVS_BE64_MAX; @@ -1008,7 +1007,7 @@ upcall_uninit(struct upcall *upcall) } static int -upcall_cb(const struct ofpbuf *packet, const struct flow *flow, ovs_u128 *ufid, +upcall_cb(const struct dp_packet *packet, const struct flow *flow, ovs_u128 *ufid, int pmd_id, enum dpif_upcall_type type, const struct nlattr *userdata, struct ofpbuf *actions, struct flow_wildcards *wc, struct ofpbuf *put_actions, void *aux) @@ -1069,7 +1068,7 @@ process_upcall(struct udpif *udpif, struct upcall *upcall, struct ofpbuf *odp_actions) { const struct nlattr *userdata = upcall->userdata; - const struct ofpbuf *packet = upcall->packet; + const struct dp_packet *packet = upcall->packet; const struct flow *flow = upcall->flow; switch (classify_upcall(upcall->type, userdata)) { @@ -1162,7 +1161,7 @@ handle_upcalls(struct udpif *udpif, struct upcall *upcalls, n_ops = 0; for (i = 0; i < n_upcalls; i++) { struct upcall *upcall = &upcalls[i]; - const struct ofpbuf *packet = upcall->packet; + const struct dp_packet *packet = upcall->packet; struct ukey_op *op; if (upcall->vsp_adjusted) { @@ -1172,7 +1171,7 @@ handle_upcalls(struct udpif *udpif, struct upcall *upcalls, * VLAN. So, we must remove the VLAN header from the packet before * trying to execute the actions. */ if (ofpbuf_size(upcall->xout.odp_actions)) { - eth_pop_vlan(CONST_CAST(struct ofpbuf *, upcall->packet)); + eth_pop_vlan(CONST_CAST(struct dp_packet *, upcall->packet)); } /* Remove the flow vlan tags inserted by vlan splinter logic @@ -1209,9 +1208,9 @@ handle_upcalls(struct udpif *udpif, struct upcall *upcalls, op = &ops[n_ops++]; op->ukey = NULL; op->dop.type = DPIF_OP_EXECUTE; - op->dop.u.execute.packet = CONST_CAST(struct ofpbuf *, packet); + op->dop.u.execute.packet = CONST_CAST(struct dp_packet *, packet); odp_key_to_pkt_metadata(upcall->key, upcall->key_len, - &op->dop.u.execute.md); + &op->dop.u.execute.packet->md); op->dop.u.execute.actions = ofpbuf_data(upcall->xout.odp_actions); op->dop.u.execute.actions_len = ofpbuf_size(upcall->xout.odp_actions); op->dop.u.execute.needs_help = (upcall->xout.slow & SLOW_ACTION) != 0; diff --git a/ofproto/ofproto-dpif-xlate.c b/ofproto/ofproto-dpif-xlate.c index 2373820e9..419e86125 100644 --- a/ofproto/ofproto-dpif-xlate.c +++ b/ofproto/ofproto-dpif-xlate.c @@ -1186,11 +1186,11 @@ stp_should_process_flow(const struct flow *flow, struct flow_wildcards *wc) } static void -stp_process_packet(const struct xport *xport, const struct ofpbuf *packet) +stp_process_packet(const struct xport *xport, const struct dp_packet *packet) { struct stp_port *sp = xport_get_stp_port(xport); - struct ofpbuf payload = *packet; - struct eth_header *eth = ofpbuf_data(&payload); + struct dp_packet payload = *packet; + struct eth_header *eth = dp_packet_data(&payload); /* Sink packets on ports that have STP disabled when the bridge has * STP enabled. */ @@ -1199,12 +1199,12 @@ stp_process_packet(const struct xport *xport, const struct ofpbuf *packet) } /* Trim off padding on payload. */ - if (ofpbuf_size(&payload) > ntohs(eth->eth_type) + ETH_HEADER_LEN) { - ofpbuf_set_size(&payload, ntohs(eth->eth_type) + ETH_HEADER_LEN); + if (dp_packet_size(&payload) > ntohs(eth->eth_type) + ETH_HEADER_LEN) { + dp_packet_set_size(&payload, ntohs(eth->eth_type) + ETH_HEADER_LEN); } - if (ofpbuf_try_pull(&payload, ETH_HEADER_LEN + LLC_HEADER_LEN)) { - stp_received_bpdu(sp, ofpbuf_data(&payload), ofpbuf_size(&payload)); + if (dp_packet_try_pull(&payload, ETH_HEADER_LEN + LLC_HEADER_LEN)) { + stp_received_bpdu(sp, dp_packet_data(&payload), dp_packet_size(&payload)); } } @@ -1239,10 +1239,10 @@ xport_rstp_should_manage_bpdu(const struct xport *xport) } static void -rstp_process_packet(const struct xport *xport, const struct ofpbuf *packet) +rstp_process_packet(const struct xport *xport, const struct dp_packet *packet) { - struct ofpbuf payload = *packet; - struct eth_header *eth = ofpbuf_data(&payload); + struct dp_packet payload = *packet; + struct eth_header *eth = dp_packet_data(&payload); /* Sink packets on ports that have no RSTP. */ if (!xport->rstp_port) { @@ -1250,13 +1250,13 @@ rstp_process_packet(const struct xport *xport, const struct ofpbuf *packet) } /* Trim off padding on payload. */ - if (ofpbuf_size(&payload) > ntohs(eth->eth_type) + ETH_HEADER_LEN) { - ofpbuf_set_size(&payload, ntohs(eth->eth_type) + ETH_HEADER_LEN); + if (dp_packet_size(&payload) > ntohs(eth->eth_type) + ETH_HEADER_LEN) { + dp_packet_set_size(&payload, ntohs(eth->eth_type) + ETH_HEADER_LEN); } - if (ofpbuf_try_pull(&payload, ETH_HEADER_LEN + LLC_HEADER_LEN)) { - rstp_port_received_bpdu(xport->rstp_port, ofpbuf_data(&payload), - ofpbuf_size(&payload)); + if (dp_packet_try_pull(&payload, ETH_HEADER_LEN + LLC_HEADER_LEN)) { + rstp_port_received_bpdu(xport->rstp_port, dp_packet_data(&payload), + dp_packet_size(&payload)); } } @@ -2494,7 +2494,7 @@ fix_sflow_action(struct xlate_ctx *ctx) static enum slow_path_reason process_special(struct xlate_ctx *ctx, const struct flow *flow, - const struct xport *xport, const struct ofpbuf *packet) + const struct xport *xport, const struct dp_packet *packet) { struct flow_wildcards *wc = &ctx->xout->wc; const struct xbridge *xbridge = ctx->xbridge; @@ -2572,14 +2572,14 @@ tnl_route_lookup_flow(const struct flow *oflow, } static int -xlate_flood_packet(struct xbridge *xbridge, struct ofpbuf *packet) +xlate_flood_packet(struct xbridge *xbridge, struct dp_packet *packet) { struct ofpact_output output; struct flow flow; ofpact_init(&output.ofpact, OFPACT_OUTPUT, sizeof output); /* Use OFPP_NONE as the in_port to avoid special packet processing. */ - flow_extract(packet, NULL, &flow); + flow_extract(packet, &flow); flow.in_port.ofp_port = OFPP_NONE; output.port = OFPP_FLOOD; output.max_len = 0; @@ -2594,13 +2594,13 @@ tnl_send_arp_request(const struct xport *out_dev, const uint8_t eth_src[ETH_ADDR ovs_be32 ip_src, ovs_be32 ip_dst) { struct xbridge *xbridge = out_dev->xbridge; - struct ofpbuf packet; + struct dp_packet packet; - ofpbuf_init(&packet, 0); + dp_packet_init(&packet, 0); compose_arp(&packet, eth_src, ip_src, ip_dst); xlate_flood_packet(xbridge, &packet); - ofpbuf_uninit(&packet); + dp_packet_uninit(&packet); } static int @@ -3203,7 +3203,7 @@ execute_controller_action(struct xlate_ctx *ctx, int len, return; } - packet = dp_packet_clone_from_ofpbuf(ctx->xin->packet); + packet = dp_packet_clone(ctx->xin->packet); ctx->xout->slow |= commit_odp_actions(&ctx->xin->flow, &ctx->base_flow, ctx->xout->odp_actions, @@ -3215,8 +3215,8 @@ execute_controller_action(struct xlate_ctx *ctx, int len, ofpbuf_size(ctx->xout->odp_actions), NULL); pin = xmalloc(sizeof *pin); - pin->up.packet_len = ofpbuf_size(&packet->ofpbuf); - pin->up.packet = ofpbuf_steal_data(&packet->ofpbuf); + pin->up.packet_len = dp_packet_size(packet); + pin->up.packet = dp_packet_steal_data(packet); pin->up.reason = reason; pin->up.table_id = ctx->table_id; pin->up.cookie = (ctx->rule @@ -4162,7 +4162,7 @@ void xlate_in_init(struct xlate_in *xin, struct ofproto_dpif *ofproto, const struct flow *flow, ofp_port_t in_port, struct rule_dpif *rule, uint16_t tcp_flags, - const struct ofpbuf *packet) + const struct dp_packet *packet) { xin->ofproto = ofproto; xin->flow = *flow; @@ -4632,7 +4632,7 @@ xlate_actions(struct xlate_in *xin, struct xlate_out *xout) * May modify 'packet'. * Returns 0 if successful, otherwise a positive errno value. */ int -xlate_send_packet(const struct ofport_dpif *ofport, struct ofpbuf *packet) +xlate_send_packet(const struct ofport_dpif *ofport, struct dp_packet *packet) { struct xlate_cfg *xcfg = ovsrcu_get(struct xlate_cfg *, &xcfgp); struct xport *xport; @@ -4641,7 +4641,7 @@ xlate_send_packet(const struct ofport_dpif *ofport, struct ofpbuf *packet) ofpact_init(&output.ofpact, OFPACT_OUTPUT, sizeof output); /* Use OFPP_NONE as the in_port to avoid special packet processing. */ - flow_extract(packet, NULL, &flow); + flow_extract(packet, &flow); flow.in_port.ofp_port = OFPP_NONE; xport = xport_lookup(xcfg, ofport); diff --git a/ofproto/ofproto-dpif-xlate.h b/ofproto/ofproto-dpif-xlate.h index 9a0378241..5f3ad8154 100644 --- a/ofproto/ofproto-dpif-xlate.h +++ b/ofproto/ofproto-dpif-xlate.h @@ -15,6 +15,7 @@ #ifndef OFPROTO_DPIF_XLATE_H #define OFPROTO_DPIF_XLATE_H 1 +#include "dp-packet.h" #include "flow.h" #include "meta-flow.h" #include "odp-util.h" @@ -72,7 +73,7 @@ struct xlate_in { /* The packet corresponding to 'flow', or a null pointer if we are * revalidating without a packet to refer to. */ - const struct ofpbuf *packet; + const struct dp_packet *packet; /* Should OFPP_NORMAL update the MAC learning table? Should "learn" * actions update the flow table? @@ -185,12 +186,12 @@ int xlate_lookup(const struct dpif_backer *, const struct flow *, void xlate_actions(struct xlate_in *, struct xlate_out *); void xlate_in_init(struct xlate_in *, struct ofproto_dpif *, const struct flow *, ofp_port_t in_port, struct rule_dpif *, - uint16_t tcp_flags, const struct ofpbuf *packet); + uint16_t tcp_flags, const struct dp_packet *packet); void xlate_out_uninit(struct xlate_out *); void xlate_actions_for_side_effects(struct xlate_in *); void xlate_out_copy(struct xlate_out *dst, const struct xlate_out *src); -int xlate_send_packet(const struct ofport_dpif *, struct ofpbuf *); +int xlate_send_packet(const struct ofport_dpif *, struct dp_packet *); struct xlate_cache *xlate_cache_new(void); void xlate_push_stats(struct xlate_cache *, const struct dpif_flow_stats *); diff --git a/ofproto/ofproto-dpif.c b/ofproto/ofproto-dpif.c index 11e9d211a..867f450a1 100644 --- a/ofproto/ofproto-dpif.c +++ b/ofproto/ofproto-dpif.c @@ -395,7 +395,7 @@ ofproto_dpif_get_enable_ufid(struct dpif_backer *backer) static struct ofport_dpif *get_ofp_port(const struct ofproto_dpif *ofproto, ofp_port_t ofp_port); static void ofproto_trace(struct ofproto_dpif *, struct flow *, - const struct ofpbuf *packet, + const struct dp_packet *packet, const struct ofpact[], size_t ofpacts_len, struct ds *); @@ -1124,7 +1124,7 @@ check_variable_length_userdata(struct dpif_backer *backer) struct eth_header *eth; struct ofpbuf actions; struct dpif_execute execute; - struct ofpbuf packet; + struct dp_packet packet; size_t start; int error; @@ -1143,8 +1143,8 @@ check_variable_length_userdata(struct dpif_backer *backer) nl_msg_end_nested(&actions, start); /* Compose a dummy ethernet packet. */ - ofpbuf_init(&packet, ETH_HEADER_LEN); - eth = ofpbuf_put_zeros(&packet, ETH_HEADER_LEN); + dp_packet_init(&packet, ETH_HEADER_LEN); + eth = dp_packet_put_zeros(&packet, ETH_HEADER_LEN); eth->eth_type = htons(0x1234); /* Execute the actions. On older datapaths this fails with ERANGE, on @@ -1152,13 +1152,12 @@ check_variable_length_userdata(struct dpif_backer *backer) execute.actions = ofpbuf_data(&actions); execute.actions_len = ofpbuf_size(&actions); execute.packet = &packet; - execute.md = PKT_METADATA_INITIALIZER(0); execute.needs_help = false; execute.probe = true; error = dpif_execute(backer->dpif, &execute); - ofpbuf_uninit(&packet); + dp_packet_uninit(&packet); ofpbuf_uninit(&actions); switch (error) { @@ -1224,7 +1223,7 @@ check_masked_set_action(struct dpif_backer *backer) struct eth_header *eth; struct ofpbuf actions; struct dpif_execute execute; - struct ofpbuf packet; + struct dp_packet packet; int error; struct ovs_key_ethernet key, mask; @@ -1239,8 +1238,8 @@ check_masked_set_action(struct dpif_backer *backer) sizeof key); /* Compose a dummy ethernet packet. */ - ofpbuf_init(&packet, ETH_HEADER_LEN); - eth = ofpbuf_put_zeros(&packet, ETH_HEADER_LEN); + dp_packet_init(&packet, ETH_HEADER_LEN); + eth = dp_packet_put_zeros(&packet, ETH_HEADER_LEN); eth->eth_type = htons(0x1234); /* Execute the actions. On older datapaths this fails with EINVAL, on @@ -1248,13 +1247,12 @@ check_masked_set_action(struct dpif_backer *backer) execute.actions = ofpbuf_data(&actions); execute.actions_len = ofpbuf_size(&actions); execute.packet = &packet; - execute.md = PKT_METADATA_INITIALIZER(0); execute.needs_help = false; execute.probe = true; error = dpif_execute(backer->dpif, &execute); - ofpbuf_uninit(&packet); + dp_packet_uninit(&packet); ofpbuf_uninit(&actions); if (error) { @@ -2061,11 +2059,11 @@ get_bfd_status(struct ofport *ofport_, struct smap *smap) /* Called while rstp_mutex is held. */ static void -rstp_send_bpdu_cb(struct ofpbuf *pkt, void *ofport_, void *ofproto_) +rstp_send_bpdu_cb(struct dp_packet *pkt, void *ofport_, void *ofproto_) { struct ofproto_dpif *ofproto = ofproto_; struct ofport_dpif *ofport = ofport_; - struct eth_header *eth = ofpbuf_l2(pkt); + struct eth_header *eth = dp_packet_l2(pkt); netdev_get_etheraddr(ofport->up.netdev, eth->eth_src); if (eth_addr_is_zero(eth->eth_src)) { @@ -2075,11 +2073,11 @@ rstp_send_bpdu_cb(struct ofpbuf *pkt, void *ofport_, void *ofproto_) } else { ofproto_dpif_send_packet(ofport, pkt); } - ofpbuf_delete(pkt); + dp_packet_delete(pkt); } static void -send_bpdu_cb(struct ofpbuf *pkt, int port_num, void *ofproto_) +send_bpdu_cb(struct dp_packet *pkt, int port_num, void *ofproto_) { struct ofproto_dpif *ofproto = ofproto_; struct stp_port *sp = stp_get_port(ofproto->stp, port_num); @@ -2090,7 +2088,7 @@ send_bpdu_cb(struct ofpbuf *pkt, int port_num, void *ofproto_) VLOG_WARN_RL(&rl, "%s: cannot send BPDU on unknown port %d", ofproto->up.name, port_num); } else { - struct eth_header *eth = ofpbuf_l2(pkt); + struct eth_header *eth = dp_packet_l2(pkt); netdev_get_etheraddr(ofport->up.netdev, eth->eth_src); if (eth_addr_is_zero(eth->eth_src)) { @@ -2100,7 +2098,7 @@ send_bpdu_cb(struct ofpbuf *pkt, int port_num, void *ofproto_) ofproto_dpif_send_packet(ofport, pkt); } } - ofpbuf_delete(pkt); + dp_packet_delete(pkt); } /* Configure RSTP on 'ofproto_' using the settings defined in 's'. */ @@ -2931,16 +2929,16 @@ send_pdu_cb(void *port_, const void *pdu, size_t pdu_size) error = netdev_get_etheraddr(port->up.netdev, ea); if (!error) { - struct ofpbuf packet; + struct dp_packet packet; void *packet_pdu; - ofpbuf_init(&packet, 0); + dp_packet_init(&packet, 0); packet_pdu = eth_compose(&packet, eth_addr_lacp, ea, ETH_TYPE_LACP, pdu_size); memcpy(packet_pdu, pdu, pdu_size); ofproto_dpif_send_packet(port, &packet); - ofpbuf_uninit(&packet); + dp_packet_uninit(&packet); } else { VLOG_ERR_RL(&rl, "port %s: cannot obtain Ethernet address of iface " "%s (%s)", port->bundle->name, @@ -2952,7 +2950,7 @@ static void bundle_send_learning_packets(struct ofbundle *bundle) { struct ofproto_dpif *ofproto = bundle->ofproto; - struct ofpbuf *learning_packet; + struct dp_packet *learning_packet; int error, n_packets, n_errors; struct mac_entry *e; struct ovs_list packets; @@ -2967,7 +2965,7 @@ bundle_send_learning_packets(struct ofbundle *bundle) e->mac, e->vlan, &port_void); /* Temporarily use 'frame' as a private pointer (see below). */ - ovs_assert(learning_packet->frame == ofpbuf_data(learning_packet)); + ovs_assert(learning_packet->frame == dp_packet_data(learning_packet)); learning_packet->frame = port_void; list_push_back(&packets, &learning_packet->list_node); } @@ -2980,7 +2978,7 @@ bundle_send_learning_packets(struct ofbundle *bundle) void *port_void = learning_packet->frame; /* Restore 'frame'. */ - learning_packet->frame = ofpbuf_data(learning_packet); + learning_packet->frame = dp_packet_data(learning_packet); ret = ofproto_dpif_send_packet(port_void, learning_packet); if (ret) { error = ret; @@ -2988,7 +2986,7 @@ bundle_send_learning_packets(struct ofbundle *bundle) } n_packets++; } - ofpbuf_list_delete(&packets); + dp_packet_list_delete(&packets); if (n_errors) { static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(1, 5); @@ -3593,7 +3591,7 @@ ofproto_dpif_execute_actions(struct ofproto_dpif *ofproto, const struct flow *flow, struct rule_dpif *rule, const struct ofpact *ofpacts, size_t ofpacts_len, - struct ofpbuf *packet) + struct dp_packet *packet) { struct dpif_flow_stats stats; struct xlate_out xout; @@ -3620,8 +3618,8 @@ ofproto_dpif_execute_actions(struct ofproto_dpif *ofproto, execute.actions = ofpbuf_data(xout.odp_actions); execute.actions_len = ofpbuf_size(xout.odp_actions); + pkt_metadata_from_flow(&packet->md, flow); execute.packet = packet; - execute.md = pkt_metadata_from_flow(flow); execute.needs_help = (xout.slow & SLOW_ACTION) != 0; execute.probe = false; @@ -3630,7 +3628,7 @@ ofproto_dpif_execute_actions(struct ofproto_dpif *ofproto, if (in_port == OFPP_NONE) { in_port = OFPP_LOCAL; } - execute.md.in_port.odp_port = ofp_port_to_odp_port(ofproto, in_port); + execute.packet->md.in_port.odp_port = ofp_port_to_odp_port(ofproto, in_port); error = dpif_execute(ofproto->backer->dpif, &execute); @@ -3985,7 +3983,7 @@ rule_get_stats(struct rule *rule_, uint64_t *packets, uint64_t *bytes, static void rule_dpif_execute(struct rule_dpif *rule, const struct flow *flow, - struct ofpbuf *packet) + struct dp_packet *packet) { struct ofproto_dpif *ofproto = ofproto_dpif_cast(rule->up.ofproto); @@ -3994,10 +3992,10 @@ rule_dpif_execute(struct rule_dpif *rule, const struct flow *flow, static enum ofperr rule_execute(struct rule *rule, const struct flow *flow, - struct ofpbuf *packet) + struct dp_packet *packet) { rule_dpif_execute(rule_dpif_cast(rule), flow, packet); - ofpbuf_delete(packet); + dp_packet_delete(packet); return 0; } @@ -4176,7 +4174,7 @@ group_dpif_get_type(const struct group_dpif *group) * May modify 'packet'. * Returns 0 if successful, otherwise a positive errno value. */ int -ofproto_dpif_send_packet(const struct ofport_dpif *ofport, struct ofpbuf *packet) +ofproto_dpif_send_packet(const struct ofport_dpif *ofport, struct dp_packet *packet) { struct ofproto_dpif *ofproto = ofproto_dpif_cast(ofport->up.ofproto); int error; @@ -4185,7 +4183,7 @@ ofproto_dpif_send_packet(const struct ofport_dpif *ofport, struct ofpbuf *packet ovs_mutex_lock(&ofproto->stats_mutex); ofproto->stats.tx_packets++; - ofproto->stats.tx_bytes += ofpbuf_size(packet); + ofproto->stats.tx_bytes += dp_packet_size(packet); ovs_mutex_unlock(&ofproto->stats_mutex); return error; } @@ -4215,7 +4213,7 @@ set_frag_handling(struct ofproto *ofproto_, } static enum ofperr -packet_out(struct ofproto *ofproto_, struct ofpbuf *packet, +packet_out(struct ofproto *ofproto_, struct dp_packet *packet, const struct flow *flow, const struct ofpact *ofpacts, size_t ofpacts_len) { @@ -4571,13 +4569,13 @@ trace_report(struct xlate_in *xin, const char *s, int recurse) static char * OVS_WARN_UNUSED_RESULT parse_flow_and_packet(int argc, const char *argv[], struct ofproto_dpif **ofprotop, struct flow *flow, - struct ofpbuf **packetp) + struct dp_packet **packetp) { const struct dpif_backer *backer = NULL; const char *error = NULL; char *m_err = NULL; struct simap port_names = SIMAP_INITIALIZER(&port_names); - struct ofpbuf *packet; + struct dp_packet *packet; struct ofpbuf odp_key; struct ofpbuf odp_mask; @@ -4586,7 +4584,7 @@ parse_flow_and_packet(int argc, const char *argv[], /* Handle "-generate" or a hex string as the last argument. */ if (!strcmp(argv[argc - 1], "-generate")) { - packet = ofpbuf_new(0); + packet = dp_packet_new(0); argc--; } else { error = eth_from_hex(argv[argc - 1], &packet); @@ -4679,14 +4677,13 @@ parse_flow_and_packet(int argc, const char *argv[], /* Generate a packet, if requested. */ if (packet) { - if (!ofpbuf_size(packet)) { + if (!dp_packet_size(packet)) { flow_compose(packet, flow); } else { - struct pkt_metadata md = pkt_metadata_from_flow(flow); - /* Use the metadata from the flow and the packet argument * to reconstruct the flow. */ - flow_extract(packet, &md, flow); + pkt_metadata_from_flow(&packet->md, flow); + flow_extract(packet, flow); } } @@ -4695,7 +4692,7 @@ exit: m_err = xstrdup(error); } if (m_err) { - ofpbuf_delete(packet); + dp_packet_delete(packet); packet = NULL; } *packetp = packet; @@ -4710,7 +4707,7 @@ ofproto_unixctl_trace(struct unixctl_conn *conn, int argc, const char *argv[], void *aux OVS_UNUSED) { struct ofproto_dpif *ofproto; - struct ofpbuf *packet; + struct dp_packet *packet; char *error; struct flow flow; @@ -4722,7 +4719,7 @@ ofproto_unixctl_trace(struct unixctl_conn *conn, int argc, const char *argv[], ofproto_trace(ofproto, &flow, packet, NULL, 0, &result); unixctl_command_reply(conn, ds_cstr(&result)); ds_destroy(&result); - ofpbuf_delete(packet); + dp_packet_delete(packet); } else { unixctl_command_reply_error(conn, error); free(error); @@ -4737,7 +4734,7 @@ ofproto_unixctl_trace_actions(struct unixctl_conn *conn, int argc, struct ofproto_dpif *ofproto; bool enforce_consistency; struct ofpbuf ofpacts; - struct ofpbuf *packet; + struct dp_packet *packet; struct ds result; struct flow flow; uint16_t in_port; @@ -4814,7 +4811,7 @@ ofproto_unixctl_trace_actions(struct unixctl_conn *conn, int argc, exit: ds_destroy(&result); - ofpbuf_delete(packet); + dp_packet_delete(packet); ofpbuf_uninit(&ofpacts); } @@ -4829,7 +4826,7 @@ exit: * trace, otherwise the actions are determined by a flow table lookup. */ static void ofproto_trace(struct ofproto_dpif *ofproto, struct flow *flow, - const struct ofpbuf *packet, + const struct dp_packet *packet, const struct ofpact ofpacts[], size_t ofpacts_len, struct ds *ds) { @@ -5306,7 +5303,7 @@ vsp_vlandev_to_realdev(const struct ofproto_dpif *ofproto, * changes. */ bool vsp_adjust_flow(const struct ofproto_dpif *ofproto, struct flow *flow, - struct ofpbuf *packet) + struct dp_packet *packet) OVS_EXCLUDED(ofproto->vsp_mutex) { ofp_port_t realdev; diff --git a/ofproto/ofproto-dpif.h b/ofproto/ofproto-dpif.h index a8570b25b..e2359cd06 100644 --- a/ofproto/ofproto-dpif.h +++ b/ofproto/ofproto-dpif.h @@ -143,15 +143,15 @@ ofp_port_t vsp_realdev_to_vlandev(const struct ofproto_dpif *, ofp_port_t realdev_ofp_port, ovs_be16 vlan_tci); bool vsp_adjust_flow(const struct ofproto_dpif *, struct flow *, - struct ofpbuf *packet); + struct dp_packet *packet); int ofproto_dpif_execute_actions(struct ofproto_dpif *, const struct flow *, struct rule_dpif *, const struct ofpact *, - size_t ofpacts_len, struct ofpbuf *); + size_t ofpacts_len, struct dp_packet *); void ofproto_dpif_send_packet_in(struct ofproto_dpif *, struct ofproto_packet_in *); bool ofproto_dpif_wants_packet_in_on_miss(struct ofproto_dpif *); -int ofproto_dpif_send_packet(const struct ofport_dpif *, struct ofpbuf *); +int ofproto_dpif_send_packet(const struct ofport_dpif *, struct dp_packet *); void ofproto_dpif_flow_mod(struct ofproto_dpif *, struct ofputil_flow_mod *); struct rule_dpif *ofproto_dpif_refresh_rule(struct rule_dpif *); diff --git a/ofproto/ofproto-provider.h b/ofproto/ofproto-provider.h index a0d556a89..4e67a0961 100644 --- a/ofproto/ofproto-provider.h +++ b/ofproto/ofproto-provider.h @@ -1191,7 +1191,7 @@ struct ofproto_class { * * Returns 0 if successful, otherwise an OpenFlow error code. */ enum ofperr (*rule_execute)(struct rule *rule, const struct flow *flow, - struct ofpbuf *packet); + struct dp_packet *packet); /* If the datapath can properly implement changing 'rule''s actions to the * 'ofpacts_len' bytes in 'ofpacts', returns 0. Otherwise, returns an enum @@ -1292,7 +1292,7 @@ struct ofproto_class { * statistics should not be included in OpenFlow flow statistics. * * Returns 0 if successful, otherwise an OpenFlow error code. */ - enum ofperr (*packet_out)(struct ofproto *ofproto, struct ofpbuf *packet, + enum ofperr (*packet_out)(struct ofproto *ofproto, struct dp_packet *packet, const struct flow *flow, const struct ofpact *ofpacts, size_t ofpacts_len); diff --git a/ofproto/ofproto.c b/ofproto/ofproto.c index 460167044..b74653701 100644 --- a/ofproto/ofproto.c +++ b/ofproto/ofproto.c @@ -44,6 +44,7 @@ #include "openflow/nicira-ext.h" #include "openflow/openflow.h" #include "ovs-rcu.h" +#include "dp-packet.h" #include "packets.h" #include "pinsched.h" #include "pktbuf.h" @@ -170,7 +171,7 @@ struct rule_execute { struct ovs_list list_node; /* In struct ofproto's "rule_executes" list. */ struct rule *rule; /* Owns a reference to the rule. */ ofp_port_t in_port; - struct ofpbuf *packet; /* Owns the packet. */ + struct dp_packet *packet; /* Owns the packet. */ }; static void run_rule_executes(struct ofproto *) OVS_EXCLUDED(ofproto_mutex); @@ -2757,7 +2758,7 @@ run_rule_executes(struct ofproto *ofproto) LIST_FOR_EACH_SAFE (e, next, list_node, &executes) { struct flow flow; - flow_extract(e->packet, NULL, &flow); + flow_extract(e->packet, &flow); flow.in_port.ofp_port = e->in_port; ofproto->ofproto_class->rule_execute(e->rule, &flow, e->packet); @@ -2775,7 +2776,7 @@ destroy_rule_executes(struct ofproto *ofproto) guarded_list_pop_all(&ofproto->rule_executes, &executes); LIST_FOR_EACH_SAFE (e, next, list_node, &executes) { - ofpbuf_delete(e->packet); + dp_packet_delete(e->packet); rule_execute_destroy(e); } } @@ -3151,7 +3152,7 @@ handle_packet_out(struct ofconn *ofconn, const struct ofp_header *oh) { struct ofproto *p = ofconn_get_ofproto(ofconn); struct ofputil_packet_out po; - struct ofpbuf *payload; + struct dp_packet *payload; uint64_t ofpacts_stub[1024 / 8]; struct ofpbuf ofpacts; struct flow flow; @@ -3184,18 +3185,18 @@ handle_packet_out(struct ofconn *ofconn, const struct ofp_header *oh) } } else { /* Ensure that the L3 header is 32-bit aligned. */ - payload = ofpbuf_clone_data_with_headroom(po.packet, po.packet_len, 2); + payload = dp_packet_clone_data_with_headroom(po.packet, po.packet_len, 2); } /* Verify actions against packet, then send packet if successful. */ - flow_extract(payload, NULL, &flow); + flow_extract(payload, &flow); flow.in_port.ofp_port = po.in_port; error = ofproto_check_ofpacts(p, po.ofpacts, po.ofpacts_len); if (!error) { error = p->ofproto_class->packet_out(p, payload, &flow, po.ofpacts, po.ofpacts_len); } - ofpbuf_delete(payload); + dp_packet_delete(payload); exit_free_ofpacts: ofpbuf_uninit(&ofpacts); @@ -6488,7 +6489,7 @@ send_buffered_packet(struct ofconn *ofconn, uint32_t buffer_id, enum ofperr error = 0; if (ofconn && buffer_id != UINT32_MAX) { struct ofproto *ofproto = ofconn_get_ofproto(ofconn); - struct ofpbuf *packet; + struct dp_packet *packet; ofp_port_t in_port; error = ofconn_pktbuf_retrieve(ofconn, buffer_id, &packet, &in_port); @@ -6505,7 +6506,7 @@ send_buffered_packet(struct ofconn *ofconn, uint32_t buffer_id, if (!guarded_list_push_back(&ofproto->rule_executes, &re->list_node, 1024)) { ofproto_rule_unref(rule); - ofpbuf_delete(re->packet); + dp_packet_delete(re->packet); free(re); } } diff --git a/ofproto/pktbuf.c b/ofproto/pktbuf.c index aa6912ea0..def0c929d 100644 --- a/ofproto/pktbuf.c +++ b/ofproto/pktbuf.c @@ -20,7 +20,7 @@ #include #include "coverage.h" #include "ofp-util.h" -#include "ofpbuf.h" +#include "dp-packet.h" #include "timeval.h" #include "util.h" #include "openvswitch/vconn.h" @@ -48,7 +48,7 @@ COVERAGE_DEFINE(pktbuf_reuse_error); #define OVERWRITE_MSECS 5000 struct packet { - struct ofpbuf *buffer; + struct dp_packet *buffer; uint32_t cookie; long long int timeout; ofp_port_t in_port; @@ -79,7 +79,7 @@ pktbuf_destroy(struct pktbuf *pb) size_t i; for (i = 0; i < PKTBUF_CNT; i++) { - ofpbuf_delete(pb->packets[i].buffer); + dp_packet_delete(pb->packets[i].buffer); } free(pb); } @@ -112,7 +112,7 @@ pktbuf_save(struct pktbuf *pb, const void *buffer, size_t buffer_size, if (time_msec() < p->timeout) { return UINT32_MAX; } - ofpbuf_delete(p->buffer); + dp_packet_delete(p->buffer); } /* Don't use maximum cookie value since all-1-bits ID is special. */ @@ -121,7 +121,7 @@ pktbuf_save(struct pktbuf *pb, const void *buffer, size_t buffer_size, } /* Use 2 bytes of headroom to 32-bit align the L3 header. */ - p->buffer = ofpbuf_clone_data_with_headroom(buffer, buffer_size, 2); + p->buffer = dp_packet_clone_data_with_headroom(buffer, buffer_size, 2); p->timeout = time_msec() + OVERWRITE_MSECS; p->in_port = in_port; @@ -169,7 +169,7 @@ pktbuf_get_null(void) * * On failure, stores NULL in in '*bufferp' and UINT16_MAX in '*in_port'. */ enum ofperr -pktbuf_retrieve(struct pktbuf *pb, uint32_t id, struct ofpbuf **bufferp, +pktbuf_retrieve(struct pktbuf *pb, uint32_t id, struct dp_packet **bufferp, ofp_port_t *in_port) { static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(1, 20); @@ -190,7 +190,7 @@ pktbuf_retrieve(struct pktbuf *pb, uint32_t id, struct ofpbuf **bufferp, p = &pb->packets[id & PKTBUF_MASK]; if (p->cookie == id >> PKTBUF_BITS) { - struct ofpbuf *buffer = p->buffer; + struct dp_packet *buffer = p->buffer; if (buffer) { *bufferp = buffer; if (in_port) { @@ -228,7 +228,7 @@ pktbuf_discard(struct pktbuf *pb, uint32_t id) { struct packet *p = &pb->packets[id & PKTBUF_MASK]; if (p->cookie == id >> PKTBUF_BITS) { - ofpbuf_delete(p->buffer); + dp_packet_delete(p->buffer); p->buffer = NULL; } } diff --git a/ofproto/pktbuf.h b/ofproto/pktbuf.h index eb1b1fff3..a5cbcd64c 100644 --- a/ofproto/pktbuf.h +++ b/ofproto/pktbuf.h @@ -23,7 +23,7 @@ #include "ofp-errors.h" struct pktbuf; -struct ofpbuf; +struct dp_packet; int pktbuf_capacity(void); @@ -33,7 +33,7 @@ uint32_t pktbuf_save(struct pktbuf *, const void *buffer, size_t buffer_size, ofp_port_t in_port); uint32_t pktbuf_get_null(void); enum ofperr pktbuf_retrieve(struct pktbuf *, uint32_t id, - struct ofpbuf **bufferp, ofp_port_t *in_port); + struct dp_packet **bufferp, ofp_port_t *in_port); void pktbuf_discard(struct pktbuf *, uint32_t id); unsigned int pktbuf_count_packets(const struct pktbuf *); diff --git a/tests/ofproto-dpif.at b/tests/ofproto-dpif.at index cdbd7fae5..4932fcc79 100644 --- a/tests/ofproto-dpif.at +++ b/tests/ofproto-dpif.at @@ -1466,13 +1466,13 @@ NXT_PACKET_IN (xid=0x0): table_id=5 cookie=0x7 total_len=102 in_port=1 tun_id=0x sctp,in_port=0,dl_vlan=80,dl_vlan_pcp=0,dl_src=80:81:81:81:81:81,dl_dst=82:82:82:82:82:82,nw_src=83.83.83.83,nw_dst=84.84.84.84,nw_tos=0,nw_ecn=0,nw_ttl=0,tp_src=1112,tp_dst=2223 sctp_csum:d9d79157 dnl NXT_PACKET_IN (xid=0x0): table_id=6 cookie=0x8 total_len=102 in_port=1 tun_id=0x6 reg0=0x1 reg1=0x2 reg2=0x3 reg3=0x4 reg4=0x5 (via action) data_len=102 (unbuffered) -sctp,in_port=0,dl_vlan=80,dl_vlan_pcp=0,dl_src=80:81:81:81:81:81,dl_dst=82:82:82:82:82:82,nw_src=83.83.83.83,nw_dst=84.84.84.84,nw_tos=0,nw_ecn=0,nw_ttl=0,tp_src=85,tp_dst=2223 sctp_csum:7f12662e +sctp,in_port=0,dl_vlan=80,dl_vlan_pcp=0,dl_src=80:81:81:81:81:81,dl_dst=82:82:82:82:82:82,nw_src=83.83.83.83,nw_dst=84.84.84.84,nw_tos=0,nw_ecn=0,nw_ttl=0,tp_src=85,tp_dst=2223 sctp_csum:dd778f5f dnl NXT_PACKET_IN (xid=0x0): table_id=7 cookie=0x9 total_len=102 in_port=1 tun_id=0x6 reg0=0x1 reg1=0x2 reg2=0x3 reg3=0x4 reg4=0x5 (via action) data_len=102 (unbuffered) -sctp,in_port=0,dl_vlan=80,dl_vlan_pcp=0,dl_src=80:81:81:81:81:81,dl_dst=82:82:82:82:82:82,nw_src=83.83.83.83,nw_dst=84.84.84.84,nw_tos=0,nw_ecn=0,nw_ttl=0,tp_src=85,tp_dst=86 sctp_csum:a7e86f67 +sctp,in_port=0,dl_vlan=80,dl_vlan_pcp=0,dl_src=80:81:81:81:81:81,dl_dst=82:82:82:82:82:82,nw_src=83.83.83.83,nw_dst=84.84.84.84,nw_tos=0,nw_ecn=0,nw_ttl=0,tp_src=85,tp_dst=86 sctp_csum:62051f56 dnl NXT_PACKET_IN (xid=0x0): table_id=7 cookie=0x9 total_len=102 in_port=1 tun_id=0x6 reg0=0x1 reg1=0x2 reg2=0x3 reg3=0x4 reg4=0x5 (via action) data_len=102 (unbuffered) -sctp,in_port=0,dl_vlan=80,dl_vlan_pcp=0,dl_src=80:81:81:81:81:81,dl_dst=82:82:82:82:82:82,nw_src=83.83.83.83,nw_dst=84.84.84.84,nw_tos=0,nw_ecn=0,nw_ttl=0,tp_src=85,tp_dst=86 sctp_csum:a7e86f67 +sctp,in_port=0,dl_vlan=80,dl_vlan_pcp=0,dl_src=80:81:81:81:81:81,dl_dst=82:82:82:82:82:82,nw_src=83.83.83.83,nw_dst=84.84.84.84,nw_tos=0,nw_ecn=0,nw_ttl=0,tp_src=85,tp_dst=86 sctp_csum:62051f56 ]) AT_CHECK([ovs-ofctl dump-flows br0 | ofctl_strip | sort], [0], [dnl diff --git a/tests/test-flows.c b/tests/test-flows.c index 19e83151b..0e8b148bf 100644 --- a/tests/test-flows.c +++ b/tests/test-flows.c @@ -27,6 +27,7 @@ #include "ofp-util.h" #include "openflow/openflow.h" #include "ovstest.h" +#include "dp-packet.h" #include "pcap-file.h" #include "timeval.h" #include "util.h" @@ -57,7 +58,7 @@ test_flows_main(int argc OVS_UNUSED, char *argv[] OVS_UNUSED) } while (fread(&expected_match, sizeof expected_match, 1, flows)) { - struct ofpbuf *packet; + struct dp_packet *packet; struct ofp10_match extracted_match; struct match match; struct flow flow; @@ -70,7 +71,7 @@ test_flows_main(int argc OVS_UNUSED, char *argv[] OVS_UNUSED) ovs_fatal(retval, "error reading pcap file"); } - flow_extract(packet, NULL, &flow); + flow_extract(packet, &flow); flow.in_port.ofp_port = u16_to_ofp(1); match_wc_init(&match, &flow); @@ -82,8 +83,8 @@ test_flows_main(int argc OVS_UNUSED, char *argv[] OVS_UNUSED) errors++; printf("mismatch on packet #%d (1-based).\n", n); printf("Packet:\n"); - ofp_print_packet(stdout, ofpbuf_data(packet), ofpbuf_size(packet)); - ovs_hex_dump(stdout, ofpbuf_data(packet), ofpbuf_size(packet), 0, true); + ofp_print_packet(stdout, dp_packet_data(packet), dp_packet_size(packet)); + ovs_hex_dump(stdout, dp_packet_data(packet), dp_packet_size(packet), 0, true); match_print(&match); printf("Expected flow:\n%s\n", exp_s); printf("Actually extracted flow:\n%s\n", got_s); @@ -94,7 +95,7 @@ test_flows_main(int argc OVS_UNUSED, char *argv[] OVS_UNUSED) free(got_s); } - ofpbuf_delete(packet); + dp_packet_delete(packet); } printf("checked %d packets, %d errors\n", n, errors); exit(errors != 0); diff --git a/tests/test-rstp.c b/tests/test-rstp.c index 005423bf8..3eca15c0b 100644 --- a/tests/test-rstp.c +++ b/tests/test-rstp.c @@ -9,6 +9,7 @@ #include #include "ofpbuf.h" #include "ovstest.h" +#include "dp-packet.h" #include "packets.h" #include "openvswitch/vlog.h" @@ -74,7 +75,7 @@ new_test_case(void) /* This callback is called with rstp_mutex held. */ static void -send_bpdu(struct ofpbuf *pkt, void *port_, void *b_) +send_bpdu(struct dp_packet *pkt, void *port_, void *b_) OVS_REQUIRES(rstp_mutex) { struct bridge *b = b_; @@ -85,8 +86,8 @@ send_bpdu(struct ofpbuf *pkt, void *port_, void *b_) assert(port_no < b->n_ports); lan = b->ports[port_no]; if (lan) { - const void *data = ofpbuf_l3(pkt); - size_t size = (char *) ofpbuf_tail(pkt) - (char *) data; + const void *data = dp_packet_l3(pkt); + size_t size = (char *) dp_packet_tail(pkt) - (char *) data; int i; for (i = 0; i < lan->n_conns; i++) { @@ -103,7 +104,7 @@ send_bpdu(struct ofpbuf *pkt, void *port_, void *b_) } } } - ofpbuf_delete(pkt); + dp_packet_delete(pkt); } static struct bridge * diff --git a/tests/test-stp.c b/tests/test-stp.c index 6250c547d..ce3b689b8 100644 --- a/tests/test-stp.c +++ b/tests/test-stp.c @@ -23,6 +23,7 @@ #include #include #include +#include "dp-packet.h" #include "ofpbuf.h" #include "ovstest.h" #include "packets.h" @@ -85,7 +86,7 @@ new_test_case(void) } static void -send_bpdu(struct ofpbuf *pkt, int port_no, void *b_) +send_bpdu(struct dp_packet *pkt, int port_no, void *b_) { struct bridge *b = b_; struct lan *lan; @@ -93,8 +94,8 @@ send_bpdu(struct ofpbuf *pkt, int port_no, void *b_) assert(port_no < b->n_ports); lan = b->ports[port_no]; if (lan) { - const void *data = ofpbuf_l3(pkt); - size_t size = (char *) ofpbuf_tail(pkt) - (char *) data; + const void *data = dp_packet_l3(pkt); + size_t size = (char *) dp_packet_tail(pkt) - (char *) data; int i; for (i = 0; i < lan->n_conns; i++) { @@ -109,7 +110,7 @@ send_bpdu(struct ofpbuf *pkt, int port_no, void *b_) } } } - ofpbuf_delete(pkt); + dp_packet_delete(pkt); } static struct bridge * diff --git a/utilities/ovs-ofctl.c b/utilities/ovs-ofctl.c index b5ace5a91..9b78a42be 100644 --- a/utilities/ovs-ofctl.c +++ b/utilities/ovs-ofctl.c @@ -50,6 +50,7 @@ #include "ofproto/ofproto.h" #include "openflow/nicira-ext.h" #include "openflow/openflow.h" +#include "dp-packet.h" #include "packets.h" #include "pcap-file.h" #include "poll-loop.h" @@ -1695,7 +1696,8 @@ ofctl_packet_out(int argc, char *argv[]) protocol = open_vconn(argv[1], &vconn); for (i = 4; i < argc; i++) { - struct ofpbuf *packet, *opo; + struct dp_packet *packet; + struct ofpbuf *opo; const char *error_msg; error_msg = eth_from_hex(argv[i], &packet); @@ -1703,11 +1705,11 @@ ofctl_packet_out(int argc, char *argv[]) ovs_fatal(0, "%s", error_msg); } - po.packet = ofpbuf_data(packet); - po.packet_len = ofpbuf_size(packet); + po.packet = dp_packet_data(packet); + po.packet_len = dp_packet_size(packet); opo = ofputil_encode_packet_out(&po, protocol); transact_noreply(vconn, opo); - ofpbuf_delete(packet); + dp_packet_delete(packet); } vconn_close(vconn); ofpbuf_uninit(&ofpacts); @@ -1938,33 +1940,33 @@ ofctl_ofp_parse_pcap(int argc OVS_UNUSED, char *argv[]) reader = tcp_reader_open(); first = true; for (;;) { - struct ofpbuf *packet; + struct dp_packet *packet; long long int when; struct flow flow; - const struct pkt_metadata md = PKT_METADATA_INITIALIZER(ODPP_NONE); error = ovs_pcap_read(file, &packet, &when); if (error) { break; } - flow_extract(packet, &md, &flow); + packet->md = PKT_METADATA_INITIALIZER(ODPP_NONE); + flow_extract(packet, &flow); if (flow.dl_type == htons(ETH_TYPE_IP) && flow.nw_proto == IPPROTO_TCP && (is_openflow_port(flow.tp_src, argv + 2) || is_openflow_port(flow.tp_dst, argv + 2))) { - struct ofpbuf *payload = tcp_reader_run(reader, &flow, packet); + struct dp_packet *payload = tcp_reader_run(reader, &flow, packet); if (payload) { - while (ofpbuf_size(payload) >= sizeof(struct ofp_header)) { + while (dp_packet_size(payload) >= sizeof(struct ofp_header)) { const struct ofp_header *oh; - void *data = ofpbuf_data(payload); + void *data = dp_packet_data(payload); int length; /* Align OpenFlow on 8-byte boundary for safe access. */ - ofpbuf_shift(payload, -((intptr_t) data & 7)); + dp_packet_shift(payload, -((intptr_t) data & 7)); - oh = ofpbuf_data(payload); + oh = dp_packet_data(payload); length = ntohs(oh->length); - if (ofpbuf_size(payload) < length) { + if (dp_packet_size(payload) < length) { break; } @@ -1982,12 +1984,12 @@ ofctl_ofp_parse_pcap(int argc OVS_UNUSED, char *argv[]) printf(IP_FMT".%"PRIu16" > "IP_FMT".%"PRIu16":\n", IP_ARGS(flow.nw_src), ntohs(flow.tp_src), IP_ARGS(flow.nw_dst), ntohs(flow.tp_dst)); - ofp_print(stdout, ofpbuf_data(payload), length, verbosity + 1); - ofpbuf_pull(payload, length); + ofp_print(stdout, dp_packet_data(payload), length, verbosity + 1); + dp_packet_pull(payload, length); } } } - ofpbuf_delete(packet); + dp_packet_delete(packet); } tcp_reader_close(reader); } @@ -3243,9 +3245,8 @@ ofctl_parse_pcap(int argc OVS_UNUSED, char *argv[]) } for (;;) { - struct ofpbuf *packet; + struct dp_packet *packet; struct flow flow; - const struct pkt_metadata md = PKT_METADATA_INITIALIZER(ODPP_NONE); int error; error = ovs_pcap_read(pcap, &packet, NULL); @@ -3255,10 +3256,11 @@ ofctl_parse_pcap(int argc OVS_UNUSED, char *argv[]) ovs_fatal(error, "%s: read failed", argv[1]); } - flow_extract(packet, &md, &flow); + packet->md = PKT_METADATA_INITIALIZER(ODPP_NONE); + flow_extract(packet, &flow); flow_print(stdout, &flow); putchar('\n'); - ofpbuf_delete(packet); + dp_packet_delete(packet); } }