2014-06-23 11:43:57 -07:00
|
|
|
|
/*
|
2015-02-22 03:21:09 -08:00
|
|
|
|
* Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013 Nicira, Inc.
|
2014-06-23 11:43:57 -07:00
|
|
|
|
*
|
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
|
* You may obtain a copy of the License at:
|
|
|
|
|
*
|
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
*
|
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
|
* limitations under the License.
|
|
|
|
|
*/
|
|
|
|
|
|
2015-02-22 03:21:09 -08:00
|
|
|
|
#ifndef DPBUF_H
|
|
|
|
|
#define DPBUF_H 1
|
2014-06-23 11:43:57 -07:00
|
|
|
|
|
2015-02-22 03:21:09 -08:00
|
|
|
|
#include <stddef.h>
|
|
|
|
|
#include <stdint.h>
|
2016-03-25 14:10:21 -07:00
|
|
|
|
#include "openvswitch/list.h"
|
2015-02-22 03:21:09 -08:00
|
|
|
|
#include "packets.h"
|
|
|
|
|
#include "util.h"
|
|
|
|
|
#include "netdev-dpdk.h"
|
2014-06-23 11:43:57 -07:00
|
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
|
extern "C" {
|
|
|
|
|
#endif
|
|
|
|
|
|
2015-02-22 03:21:09 -08:00
|
|
|
|
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.
|
2015-05-18 10:47:48 -07:00
|
|
|
|
* ref to build_dp_packet() in netdev-dpdk. */
|
2015-02-22 03:21:09 -08:00
|
|
|
|
};
|
2014-06-23 11:43:57 -07:00
|
|
|
|
|
2016-05-17 17:32:17 -07:00
|
|
|
|
#define DP_PACKET_CONTEXT_SIZE 64
|
|
|
|
|
|
2015-05-18 10:47:46 -07:00
|
|
|
|
/* Buffer for holding packet data. A dp_packet is automatically reallocated
|
2015-02-22 03:21:09 -08:00
|
|
|
|
* as necessary if it grows too large for the available memory.
|
|
|
|
|
*/
|
2015-02-25 12:01:53 -08:00
|
|
|
|
struct dp_packet {
|
2015-02-22 03:21:09 -08:00
|
|
|
|
#ifdef DPDK_NETDEV
|
|
|
|
|
struct rte_mbuf mbuf; /* DPDK mbuf */
|
|
|
|
|
#else
|
2015-02-17 13:20:04 -08:00
|
|
|
|
void *base_; /* First byte of allocated space. */
|
2015-05-18 10:47:47 -07:00
|
|
|
|
uint16_t allocated_; /* Number of bytes allocated. */
|
2015-02-17 13:20:04 -08:00
|
|
|
|
uint16_t data_ofs; /* First byte actually in use. */
|
|
|
|
|
uint32_t size_; /* Number of bytes in use. */
|
2015-04-15 19:11:48 +01:00
|
|
|
|
uint32_t rss_hash; /* Packet hash. */
|
2015-06-16 19:16:24 +01:00
|
|
|
|
bool rss_hash_valid; /* Is the 'rss_hash' valid? */
|
2014-08-29 16:06:42 -07:00
|
|
|
|
#endif
|
2015-02-22 03:21:09 -08:00
|
|
|
|
enum dp_packet_source source; /* Source of memory allocated as 'base'. */
|
2015-05-18 10:47:46 -07:00
|
|
|
|
uint8_t l2_pad_size; /* Detected l2 padding size.
|
|
|
|
|
* Padding is non-pullable. */
|
|
|
|
|
uint16_t l2_5_ofs; /* MPLS label stack offset, or UINT16_MAX */
|
|
|
|
|
uint16_t l3_ofs; /* Network-level header offset,
|
|
|
|
|
* or UINT16_MAX. */
|
|
|
|
|
uint16_t l4_ofs; /* Transport-level header offset,
|
|
|
|
|
or UINT16_MAX. */
|
ofp-actions: Add truncate action.
The patch adds a new action to support packet truncation. The new action
is formatted as 'output(port=n,max_len=m)', as output to port n, with
packet size being MIN(original_size, m).
One use case is to enable port mirroring to send smaller packets to the
destination port so that only useful packet information is mirrored/copied,
saving some performance overhead of copying entire packet payload. Example
use case is below as well as shown in the testcases:
- Output to port 1 with max_len 100 bytes.
- The output packet size on port 1 will be MIN(original_packet_size, 100).
# ovs-ofctl add-flow br0 'actions=output(port=1,max_len=100)'
- The scope of max_len is limited to output action itself. The following
packet size of output:1 and output:2 will be intact.
# ovs-ofctl add-flow br0 \
'actions=output(port=1,max_len=100),output:1,output:2'
- The Datapath actions shows:
# Datapath actions: trunc(100),1,1,2
Tested-at: https://travis-ci.org/williamtu/ovs-travis/builds/140037134
Signed-off-by: William Tu <u9012063@gmail.com>
Acked-by: Pravin B Shelar <pshelar@ovn.org>
2016-06-24 07:42:30 -07:00
|
|
|
|
uint32_t cutlen; /* length in bytes to cut from the end. */
|
2016-05-17 17:32:17 -07:00
|
|
|
|
union {
|
|
|
|
|
struct pkt_metadata md;
|
|
|
|
|
uint64_t data[DP_PACKET_CONTEXT_SIZE / 8];
|
|
|
|
|
};
|
2014-06-23 11:43:57 -07:00
|
|
|
|
};
|
|
|
|
|
|
2015-05-18 10:47:48 -07:00
|
|
|
|
static inline void *dp_packet_data(const struct dp_packet *);
|
2015-02-22 03:21:09 -08:00
|
|
|
|
static inline void dp_packet_set_data(struct dp_packet *, void *);
|
2015-05-18 10:47:48 -07:00
|
|
|
|
static inline void *dp_packet_base(const struct dp_packet *);
|
2015-02-22 03:21:09 -08:00
|
|
|
|
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);
|
|
|
|
|
|
2015-05-18 10:47:47 -07:00
|
|
|
|
static inline uint16_t dp_packet_get_allocated(const struct dp_packet *);
|
|
|
|
|
static inline void dp_packet_set_allocated(struct dp_packet *, uint16_t);
|
|
|
|
|
|
2015-05-18 10:47:48 -07:00
|
|
|
|
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 *);
|
2015-05-18 10:47:46 -07:00
|
|
|
|
static inline void dp_packet_reset_offsets(struct dp_packet *);
|
2015-02-22 03:21:09 -08:00
|
|
|
|
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);
|
2015-05-18 10:47:48 -07:00
|
|
|
|
static inline void *dp_packet_l2_5(const struct dp_packet *);
|
2015-02-22 03:21:09 -08:00
|
|
|
|
static inline void dp_packet_set_l2_5(struct dp_packet *, void *);
|
2015-05-18 10:47:48 -07:00
|
|
|
|
static inline void *dp_packet_l3(const struct dp_packet *);
|
2015-02-22 03:21:09 -08:00
|
|
|
|
static inline void dp_packet_set_l3(struct dp_packet *, void *);
|
2015-05-18 10:47:48 -07:00
|
|
|
|
static inline void *dp_packet_l4(const struct dp_packet *);
|
2015-02-22 03:21:09 -08:00
|
|
|
|
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);
|
|
|
|
|
|
2015-05-18 10:47:48 -07:00
|
|
|
|
void dp_packet_init_dpdk(struct dp_packet *, size_t allocated);
|
2015-02-22 03:21:09 -08:00
|
|
|
|
|
|
|
|
|
void dp_packet_init(struct dp_packet *, size_t);
|
|
|
|
|
void dp_packet_uninit(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 *,
|
2015-05-18 10:47:48 -07:00
|
|
|
|
size_t headroom);
|
2015-02-22 03:21:09 -08:00
|
|
|
|
struct dp_packet *dp_packet_clone_data(const void *, size_t);
|
|
|
|
|
struct dp_packet *dp_packet_clone_data_with_headroom(const void *, size_t,
|
2015-05-18 10:47:48 -07:00
|
|
|
|
size_t headroom);
|
2015-02-22 03:21:09 -08:00
|
|
|
|
static inline void dp_packet_delete(struct dp_packet *);
|
|
|
|
|
|
|
|
|
|
static inline void *dp_packet_at(const struct dp_packet *, size_t offset,
|
2015-05-18 10:47:48 -07:00
|
|
|
|
size_t size);
|
|
|
|
|
static inline void *dp_packet_at_assert(const struct dp_packet *,
|
|
|
|
|
size_t offset, size_t size);
|
2015-02-22 03:21:09 -08:00
|
|
|
|
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);
|
2015-05-18 10:47:48 -07:00
|
|
|
|
void dp_packet_reserve_with_tailroom(struct dp_packet *, size_t headroom,
|
|
|
|
|
size_t tailroom);
|
|
|
|
|
void *dp_packet_push_uninit(struct dp_packet *, size_t);
|
2015-02-22 03:21:09 -08:00
|
|
|
|
void *dp_packet_push_zeros(struct dp_packet *, size_t);
|
2015-05-18 10:47:48 -07:00
|
|
|
|
void *dp_packet_push(struct dp_packet *, const void *, size_t);
|
2015-02-22 03:21:09 -08:00
|
|
|
|
|
|
|
|
|
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);
|
2014-06-23 11:43:57 -07:00
|
|
|
|
|
2015-02-22 03:21:09 -08:00
|
|
|
|
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);
|
2014-06-23 11:43:57 -07:00
|
|
|
|
|
2015-02-22 03:21:09 -08:00
|
|
|
|
void *dp_packet_steal_data(struct dp_packet *);
|
2014-06-23 11:43:57 -07:00
|
|
|
|
|
2015-05-18 10:47:48 -07:00
|
|
|
|
static inline bool dp_packet_equal(const struct dp_packet *,
|
|
|
|
|
const struct dp_packet *);
|
2015-02-22 03:21:09 -08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Frees memory that 'b' points to, as well as 'b' itself. */
|
2015-05-18 10:47:48 -07:00
|
|
|
|
static inline void
|
|
|
|
|
dp_packet_delete(struct dp_packet *b)
|
2015-02-22 03:21:09 -08:00
|
|
|
|
{
|
|
|
|
|
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. */
|
2015-05-18 10:47:48 -07:00
|
|
|
|
static inline void *
|
|
|
|
|
dp_packet_at(const struct dp_packet *b, size_t offset, size_t size)
|
2014-06-23 11:43:57 -07:00
|
|
|
|
{
|
2015-05-18 10:47:48 -07:00
|
|
|
|
return offset + size <= dp_packet_size(b)
|
|
|
|
|
? (char *) dp_packet_data(b) + offset
|
|
|
|
|
: NULL;
|
2015-02-22 03:21:09 -08:00
|
|
|
|
}
|
2014-06-23 11:43:57 -07:00
|
|
|
|
|
2015-02-22 03:21:09 -08:00
|
|
|
|
/* Returns a pointer to byte 'offset' in 'b', which must contain at least
|
|
|
|
|
* 'offset + size' bytes of data. */
|
2015-05-18 10:47:48 -07:00
|
|
|
|
static inline void *
|
|
|
|
|
dp_packet_at_assert(const struct dp_packet *b, size_t offset, size_t size)
|
2015-02-22 03:21:09 -08:00
|
|
|
|
{
|
|
|
|
|
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'. */
|
2015-05-18 10:47:48 -07:00
|
|
|
|
static inline void *
|
|
|
|
|
dp_packet_tail(const struct dp_packet *b)
|
2015-02-22 03:21:09 -08:00
|
|
|
|
{
|
|
|
|
|
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'. */
|
2015-05-18 10:47:48 -07:00
|
|
|
|
static inline void *
|
|
|
|
|
dp_packet_end(const struct dp_packet *b)
|
2015-02-22 03:21:09 -08:00
|
|
|
|
{
|
2015-05-18 10:47:47 -07:00
|
|
|
|
return (char *) dp_packet_base(b) + dp_packet_get_allocated(b);
|
2015-02-22 03:21:09 -08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* 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
|
2015-05-18 10:47:48 -07:00
|
|
|
|
* 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)
|
2015-02-22 03:21:09 -08:00
|
|
|
|
{
|
2015-05-18 10:47:48 -07:00
|
|
|
|
return (char *) dp_packet_data(b) - (char *) dp_packet_base(b);
|
2015-02-22 03:21:09 -08:00
|
|
|
|
}
|
|
|
|
|
|
2015-05-18 10:47:48 -07:00
|
|
|
|
/* 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)
|
2015-02-22 03:21:09 -08:00
|
|
|
|
{
|
2015-05-18 10:47:48 -07:00
|
|
|
|
return (char *) dp_packet_end(b) - (char *) dp_packet_tail(b);
|
2015-02-22 03:21:09 -08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Clears any data from 'b'. */
|
2015-05-18 10:47:48 -07:00
|
|
|
|
static inline void
|
|
|
|
|
dp_packet_clear(struct dp_packet *b)
|
2015-02-22 03:21:09 -08:00
|
|
|
|
{
|
|
|
|
|
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. */
|
2015-05-18 10:47:48 -07:00
|
|
|
|
static inline void *
|
|
|
|
|
dp_packet_pull(struct dp_packet *b, size_t size)
|
2015-02-22 03:21:09 -08:00
|
|
|
|
{
|
|
|
|
|
void *data = dp_packet_data(b);
|
|
|
|
|
ovs_assert(dp_packet_size(b) - dp_packet_l2_pad_size(b) >= size);
|
2015-05-18 10:47:48 -07:00
|
|
|
|
dp_packet_set_data(b, (char *) dp_packet_data(b) + size);
|
2015-02-22 03:21:09 -08:00
|
|
|
|
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'. */
|
2015-05-18 10:47:48 -07:00
|
|
|
|
static inline void *
|
|
|
|
|
dp_packet_try_pull(struct dp_packet *b, size_t size)
|
2015-02-22 03:21:09 -08:00
|
|
|
|
{
|
|
|
|
|
return dp_packet_size(b) - dp_packet_l2_pad_size(b) >= size
|
|
|
|
|
? dp_packet_pull(b, size) : NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2015-05-18 10:47:48 -07:00
|
|
|
|
static inline bool
|
|
|
|
|
dp_packet_equal(const struct dp_packet *a, const struct dp_packet *b)
|
2015-02-22 03:21:09 -08:00
|
|
|
|
{
|
|
|
|
|
return dp_packet_size(a) == dp_packet_size(b) &&
|
2015-05-18 10:47:48 -07:00
|
|
|
|
!memcmp(dp_packet_data(a), dp_packet_data(b), dp_packet_size(a));
|
2015-02-22 03:21:09 -08:00
|
|
|
|
}
|
|
|
|
|
|
2015-05-18 10:47:46 -07:00
|
|
|
|
/* Get the start of the Ethernet frame. 'l3_ofs' marks the end of the l2
|
2015-02-22 03:21:09 -08:00
|
|
|
|
* headers, so return NULL if it is not set. */
|
2015-05-18 10:47:48 -07:00
|
|
|
|
static inline void *
|
|
|
|
|
dp_packet_l2(const struct dp_packet *b)
|
2015-02-22 03:21:09 -08:00
|
|
|
|
{
|
2015-05-18 10:47:46 -07:00
|
|
|
|
return (b->l3_ofs != UINT16_MAX) ? dp_packet_data(b) : NULL;
|
2015-02-22 03:21:09 -08:00
|
|
|
|
}
|
|
|
|
|
|
2015-05-18 10:47:46 -07:00
|
|
|
|
/* Resets all layer offsets. 'l3' offset must be set before 'l2' can be
|
|
|
|
|
* retrieved. */
|
2015-05-18 10:47:48 -07:00
|
|
|
|
static inline void
|
|
|
|
|
dp_packet_reset_offsets(struct dp_packet *b)
|
2015-02-22 03:21:09 -08:00
|
|
|
|
{
|
|
|
|
|
b->l2_pad_size = 0;
|
|
|
|
|
b->l2_5_ofs = UINT16_MAX;
|
|
|
|
|
b->l3_ofs = UINT16_MAX;
|
|
|
|
|
b->l4_ofs = UINT16_MAX;
|
|
|
|
|
}
|
|
|
|
|
|
2015-05-18 10:47:48 -07:00
|
|
|
|
static inline uint8_t
|
|
|
|
|
dp_packet_l2_pad_size(const struct dp_packet *b)
|
2015-02-22 03:21:09 -08:00
|
|
|
|
{
|
|
|
|
|
return b->l2_pad_size;
|
|
|
|
|
}
|
|
|
|
|
|
2015-05-18 10:47:48 -07:00
|
|
|
|
static inline void
|
|
|
|
|
dp_packet_set_l2_pad_size(struct dp_packet *b, uint8_t pad_size)
|
2015-02-22 03:21:09 -08:00
|
|
|
|
{
|
|
|
|
|
ovs_assert(pad_size <= dp_packet_size(b));
|
|
|
|
|
b->l2_pad_size = pad_size;
|
|
|
|
|
}
|
|
|
|
|
|
2015-05-18 10:47:48 -07:00
|
|
|
|
static inline void *
|
|
|
|
|
dp_packet_l2_5(const struct dp_packet *b)
|
2015-02-22 03:21:09 -08:00
|
|
|
|
{
|
2015-05-18 10:47:46 -07:00
|
|
|
|
return b->l2_5_ofs != UINT16_MAX
|
|
|
|
|
? (char *) dp_packet_data(b) + b->l2_5_ofs
|
|
|
|
|
: NULL;
|
2015-02-22 03:21:09 -08:00
|
|
|
|
}
|
|
|
|
|
|
2015-05-18 10:47:48 -07:00
|
|
|
|
static inline void
|
|
|
|
|
dp_packet_set_l2_5(struct dp_packet *b, void *l2_5)
|
2015-02-22 03:21:09 -08:00
|
|
|
|
{
|
2015-05-18 10:47:46 -07:00
|
|
|
|
b->l2_5_ofs = l2_5
|
|
|
|
|
? (char *) l2_5 - (char *) dp_packet_data(b)
|
|
|
|
|
: UINT16_MAX;
|
2015-02-22 03:21:09 -08:00
|
|
|
|
}
|
|
|
|
|
|
2015-05-18 10:47:48 -07:00
|
|
|
|
static inline void *
|
|
|
|
|
dp_packet_l3(const struct dp_packet *b)
|
2015-02-22 03:21:09 -08:00
|
|
|
|
{
|
2015-05-18 10:47:46 -07:00
|
|
|
|
return b->l3_ofs != UINT16_MAX
|
|
|
|
|
? (char *) dp_packet_data(b) + b->l3_ofs
|
|
|
|
|
: NULL;
|
2015-02-22 03:21:09 -08:00
|
|
|
|
}
|
|
|
|
|
|
2015-05-18 10:47:48 -07:00
|
|
|
|
static inline void
|
|
|
|
|
dp_packet_set_l3(struct dp_packet *b, void *l3)
|
2015-02-22 03:21:09 -08:00
|
|
|
|
{
|
2015-05-18 10:47:46 -07:00
|
|
|
|
b->l3_ofs = l3 ? (char *) l3 - (char *) dp_packet_data(b) : UINT16_MAX;
|
2015-02-22 03:21:09 -08:00
|
|
|
|
}
|
|
|
|
|
|
2015-05-18 10:47:48 -07:00
|
|
|
|
static inline void *
|
|
|
|
|
dp_packet_l4(const struct dp_packet *b)
|
2015-02-22 03:21:09 -08:00
|
|
|
|
{
|
2015-05-18 10:47:46 -07:00
|
|
|
|
return b->l4_ofs != UINT16_MAX
|
|
|
|
|
? (char *) dp_packet_data(b) + b->l4_ofs
|
|
|
|
|
: NULL;
|
2015-02-22 03:21:09 -08:00
|
|
|
|
}
|
|
|
|
|
|
2015-05-18 10:47:48 -07:00
|
|
|
|
static inline void
|
|
|
|
|
dp_packet_set_l4(struct dp_packet *b, void *l4)
|
2015-02-22 03:21:09 -08:00
|
|
|
|
{
|
2015-05-18 10:47:46 -07:00
|
|
|
|
b->l4_ofs = l4 ? (char *) l4 - (char *) dp_packet_data(b) : UINT16_MAX;
|
2015-02-22 03:21:09 -08:00
|
|
|
|
}
|
|
|
|
|
|
2015-05-18 10:47:48 -07:00
|
|
|
|
static inline size_t
|
|
|
|
|
dp_packet_l4_size(const struct dp_packet *b)
|
2015-02-22 03:21:09 -08:00
|
|
|
|
{
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2015-05-18 10:47:48 -07:00
|
|
|
|
static inline const void *
|
|
|
|
|
dp_packet_get_tcp_payload(const struct dp_packet *b)
|
2015-02-22 03:21:09 -08:00
|
|
|
|
{
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2015-05-18 10:47:48 -07:00
|
|
|
|
static inline const void *
|
|
|
|
|
dp_packet_get_udp_payload(const struct dp_packet *b)
|
2015-02-22 03:21:09 -08:00
|
|
|
|
{
|
|
|
|
|
return OVS_LIKELY(dp_packet_l4_size(b) >= UDP_HEADER_LEN)
|
|
|
|
|
? (const char *)dp_packet_l4(b) + UDP_HEADER_LEN : NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2015-05-18 10:47:48 -07:00
|
|
|
|
static inline const void *
|
|
|
|
|
dp_packet_get_sctp_payload(const struct dp_packet *b)
|
2015-02-22 03:21:09 -08:00
|
|
|
|
{
|
|
|
|
|
return OVS_LIKELY(dp_packet_l4_size(b) >= SCTP_HEADER_LEN)
|
|
|
|
|
? (const char *)dp_packet_l4(b) + SCTP_HEADER_LEN : NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2015-05-18 10:47:48 -07:00
|
|
|
|
static inline const void *
|
|
|
|
|
dp_packet_get_icmp_payload(const struct dp_packet *b)
|
2015-02-22 03:21:09 -08:00
|
|
|
|
{
|
|
|
|
|
return OVS_LIKELY(dp_packet_l4_size(b) >= ICMP_HEADER_LEN)
|
|
|
|
|
? (const char *)dp_packet_l4(b) + ICMP_HEADER_LEN : NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2015-05-18 10:47:48 -07:00
|
|
|
|
static inline const void *
|
|
|
|
|
dp_packet_get_nd_payload(const struct dp_packet *b)
|
2015-02-22 03:21:09 -08:00
|
|
|
|
{
|
|
|
|
|
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);
|
|
|
|
|
|
2015-05-18 10:47:48 -07:00
|
|
|
|
static inline void *
|
|
|
|
|
dp_packet_base(const struct dp_packet *b)
|
2015-02-22 03:21:09 -08:00
|
|
|
|
{
|
|
|
|
|
return b->mbuf.buf_addr;
|
|
|
|
|
}
|
|
|
|
|
|
2015-05-18 10:47:48 -07:00
|
|
|
|
static inline void
|
|
|
|
|
dp_packet_set_base(struct dp_packet *b, void *d)
|
2015-02-22 03:21:09 -08:00
|
|
|
|
{
|
|
|
|
|
b->mbuf.buf_addr = d;
|
|
|
|
|
}
|
|
|
|
|
|
2015-05-18 10:47:48 -07:00
|
|
|
|
static inline uint32_t
|
|
|
|
|
dp_packet_size(const struct dp_packet *b)
|
2015-02-22 03:21:09 -08:00
|
|
|
|
{
|
2015-02-17 13:20:04 -08:00
|
|
|
|
return b->mbuf.pkt_len;
|
2015-02-22 03:21:09 -08:00
|
|
|
|
}
|
|
|
|
|
|
2015-05-18 10:47:48 -07:00
|
|
|
|
static inline void
|
|
|
|
|
dp_packet_set_size(struct dp_packet *b, uint32_t v)
|
2015-02-22 03:21:09 -08:00
|
|
|
|
{
|
2015-02-17 13:20:04 -08:00
|
|
|
|
/* netdev-dpdk does not currently support segmentation; consequently, for
|
|
|
|
|
* all intents and purposes, 'data_len' (16 bit) and 'pkt_len' (32 bit) may
|
|
|
|
|
* be used interchangably.
|
|
|
|
|
*
|
|
|
|
|
* On the datapath, it is expected that the size of packets
|
|
|
|
|
* (and thus 'v') will always be <= UINT16_MAX; this means that there is no
|
|
|
|
|
* loss of accuracy in assigning 'v' to 'data_len'.
|
|
|
|
|
*/
|
|
|
|
|
b->mbuf.data_len = (uint16_t)v; /* Current seg length. */
|
|
|
|
|
b->mbuf.pkt_len = v; /* Total length of all segments linked to
|
|
|
|
|
* this segment. */
|
2015-02-22 03:21:09 -08:00
|
|
|
|
}
|
|
|
|
|
|
2015-05-18 10:47:48 -07:00
|
|
|
|
static inline uint16_t
|
|
|
|
|
__packet_data(const struct dp_packet *b)
|
2015-02-22 03:21:09 -08:00
|
|
|
|
{
|
2015-02-17 13:20:04 -08:00
|
|
|
|
return b->mbuf.data_off;
|
2015-02-22 03:21:09 -08:00
|
|
|
|
}
|
|
|
|
|
|
2015-05-18 10:47:48 -07:00
|
|
|
|
static inline void
|
|
|
|
|
__packet_set_data(struct dp_packet *b, uint16_t v)
|
2015-02-22 03:21:09 -08:00
|
|
|
|
{
|
2015-02-17 13:20:04 -08:00
|
|
|
|
b->mbuf.data_off = v;
|
2015-02-22 03:21:09 -08:00
|
|
|
|
}
|
|
|
|
|
|
2015-05-18 10:47:48 -07:00
|
|
|
|
static inline uint16_t
|
|
|
|
|
dp_packet_get_allocated(const struct dp_packet *b)
|
2015-05-18 10:47:47 -07:00
|
|
|
|
{
|
|
|
|
|
return b->mbuf.buf_len;
|
|
|
|
|
}
|
|
|
|
|
|
2015-05-18 10:47:48 -07:00
|
|
|
|
static inline void
|
|
|
|
|
dp_packet_set_allocated(struct dp_packet *b, uint16_t s)
|
2015-05-18 10:47:47 -07:00
|
|
|
|
{
|
|
|
|
|
b->mbuf.buf_len = s;
|
|
|
|
|
}
|
2015-02-17 13:20:04 -08:00
|
|
|
|
#else
|
2015-05-18 10:47:48 -07:00
|
|
|
|
static inline void *
|
|
|
|
|
dp_packet_base(const struct dp_packet *b)
|
2015-02-22 03:21:09 -08:00
|
|
|
|
{
|
|
|
|
|
return b->base_;
|
|
|
|
|
}
|
|
|
|
|
|
2015-05-18 10:47:48 -07:00
|
|
|
|
static inline void
|
|
|
|
|
dp_packet_set_base(struct dp_packet *b, void *d)
|
2015-02-22 03:21:09 -08:00
|
|
|
|
{
|
|
|
|
|
b->base_ = d;
|
|
|
|
|
}
|
|
|
|
|
|
2015-05-18 10:47:48 -07:00
|
|
|
|
static inline uint32_t
|
|
|
|
|
dp_packet_size(const struct dp_packet *b)
|
2015-02-22 03:21:09 -08:00
|
|
|
|
{
|
|
|
|
|
return b->size_;
|
|
|
|
|
}
|
|
|
|
|
|
2015-05-18 10:47:48 -07:00
|
|
|
|
static inline void
|
|
|
|
|
dp_packet_set_size(struct dp_packet *b, uint32_t v)
|
2015-02-22 03:21:09 -08:00
|
|
|
|
{
|
|
|
|
|
b->size_ = v;
|
|
|
|
|
}
|
2015-02-17 13:20:04 -08:00
|
|
|
|
|
2015-05-18 10:47:48 -07:00
|
|
|
|
static inline uint16_t
|
|
|
|
|
__packet_data(const struct dp_packet *b)
|
2015-02-17 13:20:04 -08:00
|
|
|
|
{
|
|
|
|
|
return b->data_ofs;
|
|
|
|
|
}
|
|
|
|
|
|
2015-05-18 10:47:48 -07:00
|
|
|
|
static inline void
|
|
|
|
|
__packet_set_data(struct dp_packet *b, uint16_t v)
|
2015-02-17 13:20:04 -08:00
|
|
|
|
{
|
|
|
|
|
b->data_ofs = v;
|
|
|
|
|
}
|
|
|
|
|
|
2015-05-18 10:47:48 -07:00
|
|
|
|
static inline uint16_t
|
|
|
|
|
dp_packet_get_allocated(const struct dp_packet *b)
|
2015-05-18 10:47:47 -07:00
|
|
|
|
{
|
|
|
|
|
return b->allocated_;
|
|
|
|
|
}
|
|
|
|
|
|
2015-05-18 10:47:48 -07:00
|
|
|
|
static inline void
|
|
|
|
|
dp_packet_set_allocated(struct dp_packet *b, uint16_t s)
|
2015-05-18 10:47:47 -07:00
|
|
|
|
{
|
|
|
|
|
b->allocated_ = s;
|
|
|
|
|
}
|
2015-02-22 03:21:09 -08:00
|
|
|
|
#endif
|
|
|
|
|
|
ofp-actions: Add truncate action.
The patch adds a new action to support packet truncation. The new action
is formatted as 'output(port=n,max_len=m)', as output to port n, with
packet size being MIN(original_size, m).
One use case is to enable port mirroring to send smaller packets to the
destination port so that only useful packet information is mirrored/copied,
saving some performance overhead of copying entire packet payload. Example
use case is below as well as shown in the testcases:
- Output to port 1 with max_len 100 bytes.
- The output packet size on port 1 will be MIN(original_packet_size, 100).
# ovs-ofctl add-flow br0 'actions=output(port=1,max_len=100)'
- The scope of max_len is limited to output action itself. The following
packet size of output:1 and output:2 will be intact.
# ovs-ofctl add-flow br0 \
'actions=output(port=1,max_len=100),output:1,output:2'
- The Datapath actions shows:
# Datapath actions: trunc(100),1,1,2
Tested-at: https://travis-ci.org/williamtu/ovs-travis/builds/140037134
Signed-off-by: William Tu <u9012063@gmail.com>
Acked-by: Pravin B Shelar <pshelar@ovn.org>
2016-06-24 07:42:30 -07:00
|
|
|
|
static inline void
|
|
|
|
|
dp_packet_reset_cutlen(struct dp_packet *b)
|
|
|
|
|
{
|
|
|
|
|
b->cutlen = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static inline uint32_t
|
|
|
|
|
dp_packet_set_cutlen(struct dp_packet *b, uint32_t max_len)
|
|
|
|
|
{
|
|
|
|
|
if (max_len < ETH_HEADER_LEN) {
|
|
|
|
|
max_len = ETH_HEADER_LEN;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (max_len >= dp_packet_size(b)) {
|
|
|
|
|
b->cutlen = 0;
|
|
|
|
|
} else {
|
|
|
|
|
b->cutlen = dp_packet_size(b) - max_len;
|
|
|
|
|
}
|
|
|
|
|
return b->cutlen;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static inline uint32_t
|
|
|
|
|
dp_packet_get_cutlen(struct dp_packet *b)
|
|
|
|
|
{
|
|
|
|
|
/* Always in valid range if user uses dp_packet_set_cutlen. */
|
|
|
|
|
return b->cutlen;
|
|
|
|
|
}
|
|
|
|
|
|
2015-05-18 10:47:48 -07:00
|
|
|
|
static inline void *
|
|
|
|
|
dp_packet_data(const struct dp_packet *b)
|
2015-02-17 13:20:04 -08:00
|
|
|
|
{
|
2015-05-18 10:47:48 -07:00
|
|
|
|
return __packet_data(b) != UINT16_MAX
|
|
|
|
|
? (char *) dp_packet_base(b) + __packet_data(b) : NULL;
|
2015-02-17 13:20:04 -08:00
|
|
|
|
}
|
|
|
|
|
|
2015-05-18 10:47:48 -07:00
|
|
|
|
static inline void
|
|
|
|
|
dp_packet_set_data(struct dp_packet *b, void *data)
|
2015-02-17 13:20:04 -08:00
|
|
|
|
{
|
|
|
|
|
if (data) {
|
2015-05-18 10:47:48 -07:00
|
|
|
|
__packet_set_data(b, (char *) data - (char *) dp_packet_base(b));
|
2015-02-17 13:20:04 -08:00
|
|
|
|
} else {
|
|
|
|
|
__packet_set_data(b, UINT16_MAX);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-05-18 10:47:48 -07:00
|
|
|
|
static inline void
|
|
|
|
|
dp_packet_reset_packet(struct dp_packet *b, int off)
|
2015-02-22 03:21:09 -08:00
|
|
|
|
{
|
|
|
|
|
dp_packet_set_size(b, dp_packet_size(b) - off);
|
2015-05-18 10:47:46 -07:00
|
|
|
|
dp_packet_set_data(b, ((unsigned char *) dp_packet_data(b) + off));
|
2016-05-17 17:32:23 -07:00
|
|
|
|
dp_packet_reset_offsets(b);
|
2014-06-23 11:43:57 -07:00
|
|
|
|
}
|
|
|
|
|
|
2015-06-16 19:16:24 +01:00
|
|
|
|
/* Returns the RSS hash of the packet 'p'. Note that the returned value is
|
|
|
|
|
* correct only if 'dp_packet_rss_valid(p)' returns true */
|
2015-05-18 10:47:48 -07:00
|
|
|
|
static inline uint32_t
|
|
|
|
|
dp_packet_get_rss_hash(struct dp_packet *p)
|
2014-08-29 16:06:42 -07:00
|
|
|
|
{
|
|
|
|
|
#ifdef DPDK_NETDEV
|
2015-02-17 13:20:04 -08:00
|
|
|
|
return p->mbuf.hash.rss;
|
2014-08-29 16:06:42 -07:00
|
|
|
|
#else
|
2015-04-15 19:11:48 +01:00
|
|
|
|
return p->rss_hash;
|
2014-08-29 16:06:42 -07:00
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
2015-05-18 10:47:48 -07:00
|
|
|
|
static inline void
|
|
|
|
|
dp_packet_set_rss_hash(struct dp_packet *p, uint32_t hash)
|
2014-08-29 16:06:42 -07:00
|
|
|
|
{
|
|
|
|
|
#ifdef DPDK_NETDEV
|
2015-02-17 13:20:04 -08:00
|
|
|
|
p->mbuf.hash.rss = hash;
|
2015-06-16 19:16:24 +01:00
|
|
|
|
p->mbuf.ol_flags |= PKT_RX_RSS_HASH;
|
2014-08-29 16:06:42 -07:00
|
|
|
|
#else
|
2015-04-15 19:11:48 +01:00
|
|
|
|
p->rss_hash = hash;
|
2015-06-16 19:16:24 +01:00
|
|
|
|
p->rss_hash_valid = true;
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static inline bool
|
|
|
|
|
dp_packet_rss_valid(struct dp_packet *p)
|
|
|
|
|
{
|
|
|
|
|
#ifdef DPDK_NETDEV
|
|
|
|
|
return p->mbuf.ol_flags & PKT_RX_RSS_HASH;
|
|
|
|
|
#else
|
|
|
|
|
return p->rss_hash_valid;
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static inline void
|
|
|
|
|
dp_packet_rss_invalidate(struct dp_packet *p)
|
|
|
|
|
{
|
|
|
|
|
#ifdef DPDK_NETDEV
|
|
|
|
|
p->mbuf.ol_flags &= ~PKT_RX_RSS_HASH;
|
|
|
|
|
#else
|
|
|
|
|
p->rss_hash_valid = false;
|
2014-08-29 16:06:42 -07:00
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
2016-05-17 17:32:33 -07:00
|
|
|
|
enum { NETDEV_MAX_BURST = 32 }; /* Maximum number packets in a batch. */
|
|
|
|
|
|
|
|
|
|
struct dp_packet_batch {
|
|
|
|
|
int count;
|
ofp-actions: Add truncate action.
The patch adds a new action to support packet truncation. The new action
is formatted as 'output(port=n,max_len=m)', as output to port n, with
packet size being MIN(original_size, m).
One use case is to enable port mirroring to send smaller packets to the
destination port so that only useful packet information is mirrored/copied,
saving some performance overhead of copying entire packet payload. Example
use case is below as well as shown in the testcases:
- Output to port 1 with max_len 100 bytes.
- The output packet size on port 1 will be MIN(original_packet_size, 100).
# ovs-ofctl add-flow br0 'actions=output(port=1,max_len=100)'
- The scope of max_len is limited to output action itself. The following
packet size of output:1 and output:2 will be intact.
# ovs-ofctl add-flow br0 \
'actions=output(port=1,max_len=100),output:1,output:2'
- The Datapath actions shows:
# Datapath actions: trunc(100),1,1,2
Tested-at: https://travis-ci.org/williamtu/ovs-travis/builds/140037134
Signed-off-by: William Tu <u9012063@gmail.com>
Acked-by: Pravin B Shelar <pshelar@ovn.org>
2016-06-24 07:42:30 -07:00
|
|
|
|
bool trunc; /* true if the batch needs truncate. */
|
2016-05-17 17:32:33 -07:00
|
|
|
|
struct dp_packet *packets[NETDEV_MAX_BURST];
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static inline void dp_packet_batch_init(struct dp_packet_batch *b)
|
|
|
|
|
{
|
|
|
|
|
b->count = 0;
|
ofp-actions: Add truncate action.
The patch adds a new action to support packet truncation. The new action
is formatted as 'output(port=n,max_len=m)', as output to port n, with
packet size being MIN(original_size, m).
One use case is to enable port mirroring to send smaller packets to the
destination port so that only useful packet information is mirrored/copied,
saving some performance overhead of copying entire packet payload. Example
use case is below as well as shown in the testcases:
- Output to port 1 with max_len 100 bytes.
- The output packet size on port 1 will be MIN(original_packet_size, 100).
# ovs-ofctl add-flow br0 'actions=output(port=1,max_len=100)'
- The scope of max_len is limited to output action itself. The following
packet size of output:1 and output:2 will be intact.
# ovs-ofctl add-flow br0 \
'actions=output(port=1,max_len=100),output:1,output:2'
- The Datapath actions shows:
# Datapath actions: trunc(100),1,1,2
Tested-at: https://travis-ci.org/williamtu/ovs-travis/builds/140037134
Signed-off-by: William Tu <u9012063@gmail.com>
Acked-by: Pravin B Shelar <pshelar@ovn.org>
2016-06-24 07:42:30 -07:00
|
|
|
|
b->trunc = false;
|
2016-05-17 17:32:33 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static inline void
|
|
|
|
|
dp_packet_batch_clone(struct dp_packet_batch *dst,
|
|
|
|
|
struct dp_packet_batch *src)
|
|
|
|
|
{
|
|
|
|
|
int i;
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < src->count; i++) {
|
|
|
|
|
dst->packets[i] = dp_packet_clone(src->packets[i]);
|
|
|
|
|
}
|
|
|
|
|
dst->count = src->count;
|
ofp-actions: Add truncate action.
The patch adds a new action to support packet truncation. The new action
is formatted as 'output(port=n,max_len=m)', as output to port n, with
packet size being MIN(original_size, m).
One use case is to enable port mirroring to send smaller packets to the
destination port so that only useful packet information is mirrored/copied,
saving some performance overhead of copying entire packet payload. Example
use case is below as well as shown in the testcases:
- Output to port 1 with max_len 100 bytes.
- The output packet size on port 1 will be MIN(original_packet_size, 100).
# ovs-ofctl add-flow br0 'actions=output(port=1,max_len=100)'
- The scope of max_len is limited to output action itself. The following
packet size of output:1 and output:2 will be intact.
# ovs-ofctl add-flow br0 \
'actions=output(port=1,max_len=100),output:1,output:2'
- The Datapath actions shows:
# Datapath actions: trunc(100),1,1,2
Tested-at: https://travis-ci.org/williamtu/ovs-travis/builds/140037134
Signed-off-by: William Tu <u9012063@gmail.com>
Acked-by: Pravin B Shelar <pshelar@ovn.org>
2016-06-24 07:42:30 -07:00
|
|
|
|
dst->trunc = src->trunc;
|
2016-05-17 17:32:33 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static inline void
|
|
|
|
|
packet_batch_init_packet(struct dp_packet_batch *b, struct dp_packet *p)
|
|
|
|
|
{
|
|
|
|
|
b->count = 1;
|
ofp-actions: Add truncate action.
The patch adds a new action to support packet truncation. The new action
is formatted as 'output(port=n,max_len=m)', as output to port n, with
packet size being MIN(original_size, m).
One use case is to enable port mirroring to send smaller packets to the
destination port so that only useful packet information is mirrored/copied,
saving some performance overhead of copying entire packet payload. Example
use case is below as well as shown in the testcases:
- Output to port 1 with max_len 100 bytes.
- The output packet size on port 1 will be MIN(original_packet_size, 100).
# ovs-ofctl add-flow br0 'actions=output(port=1,max_len=100)'
- The scope of max_len is limited to output action itself. The following
packet size of output:1 and output:2 will be intact.
# ovs-ofctl add-flow br0 \
'actions=output(port=1,max_len=100),output:1,output:2'
- The Datapath actions shows:
# Datapath actions: trunc(100),1,1,2
Tested-at: https://travis-ci.org/williamtu/ovs-travis/builds/140037134
Signed-off-by: William Tu <u9012063@gmail.com>
Acked-by: Pravin B Shelar <pshelar@ovn.org>
2016-06-24 07:42:30 -07:00
|
|
|
|
b->trunc = false;
|
2016-05-17 17:32:33 -07:00
|
|
|
|
b->packets[0] = p;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static inline void
|
|
|
|
|
dp_packet_delete_batch(struct dp_packet_batch *batch, bool may_steal)
|
|
|
|
|
{
|
|
|
|
|
if (may_steal) {
|
|
|
|
|
int i;
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < batch->count; i++) {
|
|
|
|
|
dp_packet_delete(batch->packets[i]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
ofp-actions: Add truncate action.
The patch adds a new action to support packet truncation. The new action
is formatted as 'output(port=n,max_len=m)', as output to port n, with
packet size being MIN(original_size, m).
One use case is to enable port mirroring to send smaller packets to the
destination port so that only useful packet information is mirrored/copied,
saving some performance overhead of copying entire packet payload. Example
use case is below as well as shown in the testcases:
- Output to port 1 with max_len 100 bytes.
- The output packet size on port 1 will be MIN(original_packet_size, 100).
# ovs-ofctl add-flow br0 'actions=output(port=1,max_len=100)'
- The scope of max_len is limited to output action itself. The following
packet size of output:1 and output:2 will be intact.
# ovs-ofctl add-flow br0 \
'actions=output(port=1,max_len=100),output:1,output:2'
- The Datapath actions shows:
# Datapath actions: trunc(100),1,1,2
Tested-at: https://travis-ci.org/williamtu/ovs-travis/builds/140037134
Signed-off-by: William Tu <u9012063@gmail.com>
Acked-by: Pravin B Shelar <pshelar@ovn.org>
2016-06-24 07:42:30 -07:00
|
|
|
|
static inline void
|
|
|
|
|
dp_packet_batch_apply_cutlen(struct dp_packet_batch *pktb)
|
|
|
|
|
{
|
|
|
|
|
int i;
|
|
|
|
|
|
|
|
|
|
if (!pktb->trunc)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < pktb->count; i++) {
|
|
|
|
|
uint32_t cutlen = dp_packet_get_cutlen(pktb->packets[i]);
|
|
|
|
|
|
|
|
|
|
dp_packet_set_size(pktb->packets[i],
|
|
|
|
|
dp_packet_size(pktb->packets[i]) - cutlen);
|
|
|
|
|
dp_packet_reset_cutlen(pktb->packets[i]);
|
|
|
|
|
}
|
|
|
|
|
pktb->trunc = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static inline void
|
|
|
|
|
dp_packet_batch_reset_cutlen(struct dp_packet_batch *pktb)
|
|
|
|
|
{
|
|
|
|
|
int i;
|
|
|
|
|
|
|
|
|
|
if (!pktb->trunc)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
pktb->trunc = false;
|
|
|
|
|
for (i = 0; i < pktb->count; i++) {
|
|
|
|
|
dp_packet_reset_cutlen(pktb->packets[i]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-06-23 11:43:57 -07:00
|
|
|
|
#ifdef __cplusplus
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
2015-03-04 14:10:11 +09:00
|
|
|
|
#endif /* dp-packet.h */
|