summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDamjan Marion <damarion@cisco.com>2018-02-01 15:30:13 +0100
committerDave Barach <openvpp@barachs.net>2018-02-07 15:07:51 +0000
commitdac03527f64216e132953a1a1d47b414e6841c68 (patch)
treebfe382ab6927861aab72acdb6e3d13391b3c7761
parentf429a93d95c73bafdc7244799703abc051127ca8 (diff)
Refactor vlib_buffer flags
Change-Id: I853386aebfe488ebb10328435b81b6e3403c5dd0 Signed-off-by: Damjan Marion <damarion@cisco.com>
-rw-r--r--src/plugins/dpdk/buffer.c10
-rw-r--r--src/plugins/dpdk/device/dpdk.h3
-rwxr-xr-xsrc/plugins/dpdk/device/init.c9
-rw-r--r--src/plugins/flowprobe/node.c9
-rw-r--r--src/plugins/nat/nat_ipfix_logging.c2
-rw-r--r--src/vlib/buffer.c47
-rw-r--r--src/vlib/buffer.h67
-rw-r--r--src/vlib/buffer_funcs.h113
-rw-r--r--src/vnet/buffer.c2
-rw-r--r--src/vnet/buffer.h33
-rw-r--r--src/vnet/dns/dns.c2
-rw-r--r--src/vnet/dpo/dvr_dpo.c12
-rw-r--r--src/vnet/flow/flow_report.c2
-rw-r--r--src/vnet/pg/pg.h2
-rw-r--r--src/vnet/replication.h2
-rw-r--r--src/vnet/sctp/sctp_output.c2
-rw-r--r--src/vnet/tcp/tcp_output.c4
17 files changed, 152 insertions, 169 deletions
diff --git a/src/plugins/dpdk/buffer.c b/src/plugins/dpdk/buffer.c
index a73d3ff32b1..01ec1ac1f3c 100644
--- a/src/plugins/dpdk/buffer.c
+++ b/src/plugins/dpdk/buffer.c
@@ -159,11 +159,12 @@ del_free_list (vlib_main_t * vm, vlib_buffer_free_list_t * f)
/* Add buffer free list. */
static void
-dpdk_buffer_delete_free_list (vlib_main_t * vm, u32 free_list_index)
+dpdk_buffer_delete_free_list (vlib_main_t * vm,
+ vlib_buffer_free_list_index_t free_list_index)
{
vlib_buffer_main_t *bm = vm->buffer_main;
vlib_buffer_free_list_t *f;
- u32 merge_index;
+ vlib_buffer_free_list_index_t merge_index;
int i;
ASSERT (vlib_get_thread_index () == 0);
@@ -171,7 +172,8 @@ dpdk_buffer_delete_free_list (vlib_main_t * vm, u32 free_list_index)
f = vlib_buffer_get_free_list (vm, free_list_index);
merge_index = vlib_buffer_get_free_list_with_size (vm, f->n_data_bytes);
- if (merge_index != ~0 && merge_index != free_list_index)
+ if (merge_index != (vlib_buffer_free_list_index_t) ~ 0 &&
+ merge_index != free_list_index)
{
vlib_buffer_merge_free_lists (pool_elt_at_index
(bm->buffer_free_list_pool, merge_index),
@@ -321,7 +323,7 @@ recycle_or_free (vlib_main_t * vm, vlib_buffer_main_t * bm, u32 bi,
{
vlib_buffer_free_list_t *fl;
u32 thread_index = vlib_get_thread_index ();
- u32 fi;
+ vlib_buffer_free_list_index_t fi;
fl = vlib_buffer_get_buffer_free_list (vm, b, &fi);
/* The only current use of this callback: multicast recycle */
diff --git a/src/plugins/dpdk/device/dpdk.h b/src/plugins/dpdk/device/dpdk.h
index 770da6e3da6..3b067e66649 100644
--- a/src/plugins/dpdk/device/dpdk.h
+++ b/src/plugins/dpdk/device/dpdk.h
@@ -362,9 +362,6 @@ typedef struct
/* buffer flags template, configurable to enable/disable tcp / udp cksum */
u32 buffer_flags_template;
- /* vlib buffer free list, must be same size as an rte_mbuf */
- u32 vlib_buffer_free_list_index;
-
/* pcap tracing [only works if (CLIB_DEBUG > 0)] */
int tx_pcap_enable;
pcap_main_t pcap_main;
diff --git a/src/plugins/dpdk/device/init.c b/src/plugins/dpdk/device/init.c
index 1c630be29bf..5733be9223a 100755
--- a/src/plugins/dpdk/device/init.c
+++ b/src/plugins/dpdk/device/init.c
@@ -224,15 +224,6 @@ dpdk_lib_init (dpdk_main_t * dm)
if (CLIB_DEBUG > 0)
clib_warning ("DPDK drivers found %d ports...", nports);
- /*
- * All buffers are all allocated from the same rte_mempool.
- * Thus they all have the same number of data bytes.
- */
- dm->vlib_buffer_free_list_index =
- vlib_buffer_get_or_create_free_list (vm,
- VLIB_BUFFER_DEFAULT_FREE_LIST_BYTES,
- "dpdk rx");
-
if (dm->conf->enable_tcp_udp_checksum)
dm->buffer_flags_template &= ~(VNET_BUFFER_F_L4_CHECKSUM_CORRECT
| VNET_BUFFER_F_L4_CHECKSUM_COMPUTED);
diff --git a/src/plugins/flowprobe/node.c b/src/plugins/flowprobe/node.c
index 1c7786067ca..9ac74cfd617 100644
--- a/src/plugins/flowprobe/node.c
+++ b/src/plugins/flowprobe/node.c
@@ -657,7 +657,8 @@ flowprobe_get_buffer (vlib_main_t * vm, flowprobe_variant_t which)
b0->current_data = 0;
b0->current_length = flowprobe_get_headersize ();
- b0->flags |= (VLIB_BUFFER_TOTAL_LENGTH_VALID | VLIB_BUFFER_FLOW_REPORT);
+ b0->flags |=
+ (VLIB_BUFFER_TOTAL_LENGTH_VALID | VNET_BUFFER_F_FLOW_REPORT);
vnet_buffer (b0)->sw_if_index[VLIB_RX] = 0;
vnet_buffer (b0)->sw_if_index[VLIB_TX] = frm->fib_index;
fm->context[which].next_record_offset_per_worker[my_cpu_number] =
@@ -782,7 +783,7 @@ flowprobe_node_fn (vlib_main_t * vm,
ethernet_header_t *eh0 = vlib_buffer_get_current (b0);
u16 ethertype0 = clib_net_to_host_u16 (eh0->type);
- if (PREDICT_TRUE ((b0->flags & VLIB_BUFFER_FLOW_REPORT) == 0))
+ if (PREDICT_TRUE ((b0->flags & VNET_BUFFER_F_FLOW_REPORT) == 0))
add_to_flow_record_state (vm, node, fm, b0, timestamp, len0,
flowprobe_get_variant
(which, fm->context[which].flags,
@@ -792,7 +793,7 @@ flowprobe_node_fn (vlib_main_t * vm,
ethernet_header_t *eh1 = vlib_buffer_get_current (b1);
u16 ethertype1 = clib_net_to_host_u16 (eh1->type);
- if (PREDICT_TRUE ((b1->flags & VLIB_BUFFER_FLOW_REPORT) == 0))
+ if (PREDICT_TRUE ((b1->flags & VNET_BUFFER_F_FLOW_REPORT) == 0))
add_to_flow_record_state (vm, node, fm, b1, timestamp, len1,
flowprobe_get_variant
(which, fm->context[which].flags,
@@ -828,7 +829,7 @@ flowprobe_node_fn (vlib_main_t * vm,
ethernet_header_t *eh0 = vlib_buffer_get_current (b0);
u16 ethertype0 = clib_net_to_host_u16 (eh0->type);
- if (PREDICT_TRUE ((b0->flags & VLIB_BUFFER_FLOW_REPORT) == 0))
+ if (PREDICT_TRUE ((b0->flags & VNET_BUFFER_F_FLOW_REPORT) == 0))
{
flowprobe_trace_t *t = 0;
if (PREDICT_FALSE ((node->flags & VLIB_NODE_FLAG_TRACE)
diff --git a/src/plugins/nat/nat_ipfix_logging.c b/src/plugins/nat/nat_ipfix_logging.c
index ef1ab859d8d..70d8d6b1c62 100644
--- a/src/plugins/nat/nat_ipfix_logging.c
+++ b/src/plugins/nat/nat_ipfix_logging.c
@@ -519,7 +519,7 @@ snat_ipfix_header_create (flow_report_main_t * frm,
b0->current_data = 0;
b0->current_length = sizeof (*ip) + sizeof (*udp) + sizeof (*h) +
sizeof (*s);
- b0->flags |= (VLIB_BUFFER_TOTAL_LENGTH_VALID | VLIB_BUFFER_FLOW_REPORT);
+ b0->flags |= (VLIB_BUFFER_TOTAL_LENGTH_VALID | VNET_BUFFER_F_FLOW_REPORT);
vnet_buffer (b0)->sw_if_index[VLIB_RX] = 0;
vnet_buffer (b0)->sw_if_index[VLIB_TX] = frm->fib_index;
tp = vlib_buffer_get_current (b0);
diff --git a/src/vlib/buffer.c b/src/vlib/buffer.c
index 400488d0352..6b20a542ca1 100644
--- a/src/vlib/buffer.c
+++ b/src/vlib/buffer.c
@@ -71,10 +71,16 @@ format_vlib_buffer (u8 * s, va_list * args)
{
vlib_buffer_t *b = va_arg (*args, vlib_buffer_t *);
u32 indent = format_get_indent (s);
+ u8 *a = 0;
- s = format (s, "current data %d, length %d, free-list %d, clone-count %u",
- b->current_data, b->current_length,
- vlib_buffer_get_free_list_index (b), b->n_add_refs);
+#define _(bit, name, v) \
+ if (v && (b->flags & VLIB_BUFFER_##name)) \
+ a = format (a, "%s ", v);
+ foreach_vlib_buffer_flag
+#undef _
+ s = format (s, "current data %d, length %d, free-list %d, clone-count %u",
+ b->current_data, b->current_length,
+ vlib_buffer_get_free_list_index (b), b->n_add_refs);
if (b->flags & VLIB_BUFFER_TOTAL_LENGTH_VALID)
s = format (s, ", totlen-nifb %d",
@@ -83,6 +89,10 @@ format_vlib_buffer (u8 * s, va_list * args)
if (b->flags & VLIB_BUFFER_IS_TRACED)
s = format (s, ", trace 0x%x", b->trace_index);
+ if (a)
+ s = format (s, "\n%U%v", format_white_space, indent, a);
+ vec_free (a);
+
while (b->flags & VLIB_BUFFER_NEXT_PRESENT)
{
vlib_main_t *vm = vlib_get_main ();
@@ -349,7 +359,7 @@ vlib_buffer_merge_free_lists (vlib_buffer_free_list_t * dst,
}
/* Add buffer free list. */
-static u32
+static vlib_buffer_free_list_index_t
vlib_buffer_create_free_list_helper (vlib_main_t * vm,
u32 n_data_bytes,
u32 is_public, u32 is_default, u8 * name)
@@ -362,7 +372,7 @@ vlib_buffer_create_free_list_helper (vlib_main_t * vm,
if (!is_default && pool_elts (bm->buffer_free_list_pool) == 0)
{
- u32 default_free_free_list_index;
+ vlib_buffer_free_list_index_t default_free_free_list_index;
/* *INDENT-OFF* */
default_free_free_list_index =
@@ -417,7 +427,7 @@ vlib_buffer_create_free_list_helper (vlib_main_t * vm,
return f->index;
}
-u32
+vlib_buffer_free_list_index_t
vlib_buffer_create_free_list (vlib_main_t * vm, u32 n_data_bytes,
char *fmt, ...)
{
@@ -434,7 +444,7 @@ vlib_buffer_create_free_list (vlib_main_t * vm, u32 n_data_bytes,
name);
}
-u32
+vlib_buffer_free_list_index_t
vlib_buffer_get_or_create_free_list (vlib_main_t * vm, u32 n_data_bytes,
char *fmt, ...)
{
@@ -473,20 +483,22 @@ del_free_list (vlib_main_t * vm, vlib_buffer_free_list_t * f)
/* Add buffer free list. */
void
-vlib_buffer_delete_free_list_internal (vlib_main_t * vm, u32 free_list_index)
+vlib_buffer_delete_free_list_internal (vlib_main_t * vm,
+ vlib_buffer_free_list_index_t index)
{
vlib_buffer_main_t *bm = vm->buffer_main;
vlib_buffer_free_list_t *f;
- u32 merge_index;
+ vlib_buffer_free_list_index_t merge_index;
int i;
ASSERT (vlib_get_thread_index () == 0);
- f = vlib_buffer_get_free_list (vm, free_list_index);
+ f = vlib_buffer_get_free_list (vm, index);
ASSERT (vec_len (f->buffers) == f->n_alloc);
merge_index = vlib_buffer_get_free_list_with_size (vm, f->n_data_bytes);
- if (merge_index != ~0 && merge_index != free_list_index)
+ if (merge_index != (vlib_buffer_free_list_index_t) ~ 0
+ && merge_index != index)
{
vlib_buffer_merge_free_lists (pool_elt_at_index
(bm->buffer_free_list_pool, merge_index),
@@ -503,7 +515,7 @@ vlib_buffer_delete_free_list_internal (vlib_main_t * vm, u32 free_list_index)
for (i = 1; i < vec_len (vlib_mains); i++)
{
bm = vlib_mains[i]->buffer_main;
- f = vlib_buffer_get_free_list (vlib_mains[i], free_list_index);;
+ f = vlib_buffer_get_free_list (vlib_mains[i], index);;
memset (f, 0xab, sizeof (f[0]));
pool_put (bm->buffer_free_list_pool, f);
}
@@ -615,7 +627,7 @@ vlib_buffer_free_inline (vlib_main_t * vm,
{
vlib_buffer_main_t *bm = vm->buffer_main;
vlib_buffer_free_list_t *fl;
- u32 fi;
+ vlib_buffer_free_list_index_t fi;
int i;
u32 (*cb) (vlib_main_t * vm, u32 * buffers, u32 n_buffers,
u32 follow_buffer_next);
@@ -818,7 +830,7 @@ vlib_packet_template_get_packet_helper (vlib_main_t * vm,
/* Append given data to end of buffer, possibly allocating new buffers. */
u32
vlib_buffer_add_data (vlib_main_t * vm,
- u32 free_list_index,
+ vlib_buffer_free_list_index_t free_list_index,
u32 buffer_index, void *data, u32 n_data_bytes)
{
u32 n_buffer_bytes, n_left, n_left_this_buffer, bi;
@@ -875,10 +887,11 @@ out_of_buffers:
u16
vlib_buffer_chain_append_data_with_alloc (vlib_main_t * vm,
- u32 free_list_index,
+ vlib_buffer_free_list_index_t
+ free_list_index,
vlib_buffer_t * first,
- vlib_buffer_t ** last,
- void *data, u16 data_len)
+ vlib_buffer_t ** last, void *data,
+ u16 data_len)
{
vlib_buffer_t *l = *last;
u32 n_buffer_bytes =
diff --git a/src/vlib/buffer.h b/src/vlib/buffer.h
index c3c4def0991..a1c2db377ef 100644
--- a/src/vlib/buffer.h
+++ b/src/vlib/buffer.h
@@ -51,6 +51,8 @@
#define VLIB_BUFFER_DATA_SIZE (2048)
#define VLIB_BUFFER_PRE_DATA_SIZE __PRE_DATA_SIZE
+typedef u8 vlib_buffer_free_list_index_t;
+
/** \file
vlib buffer structure definition and a few select
access methods. This structure and the buffer allocation
@@ -58,6 +60,40 @@
of typing to make it so.
*/
+/**
+ * Buffer Flags
+ */
+#define foreach_vlib_buffer_flag \
+ _( 0, NON_DEFAULT_FREELIST, "non-default-fl") \
+ _( 1, IS_TRACED, 0) \
+ _( 2, NEXT_PRESENT, 0) \
+ _( 3, IS_RECYCLED, "is-recycled") \
+ _( 4, TOTAL_LENGTH_VALID, 0) \
+ _( 5, REPL_FAIL, "repl-fail") \
+ _( 6, RECYCLE, "recycle") \
+ _( 7, EXT_HDR_VALID, "ext-hdr-valid")
+
+/* NOTE: only buffer generic flags should be defined here, please consider
+ using user flags. i.e. src/vnet/buffer.h */
+
+enum
+{
+#define _(bit, name, v) VLIB_BUFFER_##name = (1 << (bit)),
+ foreach_vlib_buffer_flag
+#undef _
+};
+
+enum
+{
+#define _(bit, name, v) VLIB_BUFFER_LOG2_##name = (bit),
+ foreach_vlib_buffer_flag
+#undef _
+};
+
+ /* User defined buffer flags. */
+#define LOG2_VLIB_BUFFER_FLAG_USER(n) (32 - (n))
+#define VLIB_BUFFER_FLAG_USER(n) (1 << LOG2_VLIB_BUFFER_FLAG_USER(n))
+
/* VLIB buffer representation. */
typedef struct
{
@@ -79,30 +115,11 @@ typedef struct
<br> VLIB_BUFFER_TOTAL_LENGTH_VALID: as it says
<br> VLIB_BUFFER_REPL_FAIL: packet replication failure
<br> VLIB_BUFFER_RECYCLE: as it says
- <br> VLIB_BUFFER_FLOW_REPORT: buffer is a flow report,
<br> VLIB_BUFFER_EXT_HDR_VALID: buffer contains valid external buffer manager header,
set to avoid adding it to a flow report
<br> VLIB_BUFFER_FLAG_USER(n): user-defined bit N
*/
-/* any change to the following line requres update of
- * vlib_buffer_get_free_list_index(...) and
- * vlib_buffer_set_free_list_index(...) functions */
-#define VLIB_BUFFER_FREE_LIST_INDEX_MASK ((1 << 5) - 1)
-
-#define VLIB_BUFFER_IS_TRACED (1 << 5)
-#define VLIB_BUFFER_LOG2_NEXT_PRESENT (6)
-#define VLIB_BUFFER_NEXT_PRESENT (1 << VLIB_BUFFER_LOG2_NEXT_PRESENT)
-#define VLIB_BUFFER_IS_RECYCLED (1 << 7)
-#define VLIB_BUFFER_TOTAL_LENGTH_VALID (1 << 8)
-#define VLIB_BUFFER_REPL_FAIL (1 << 9)
-#define VLIB_BUFFER_RECYCLE (1 << 10)
-#define VLIB_BUFFER_FLOW_REPORT (1 << 11)
-#define VLIB_BUFFER_EXT_HDR_VALID (1 << 12)
-
- /* User defined buffer flags. */
-#define LOG2_VLIB_BUFFER_FLAG_USER(n) (32 - (n))
-#define VLIB_BUFFER_FLAG_USER(n) (1 << LOG2_VLIB_BUFFER_FLAG_USER(n))
STRUCT_MARK (template_end);
@@ -143,7 +160,10 @@ typedef struct
/**< Only valid for first buffer in chain. Current length plus
total length given here give total number of bytes in buffer chain.
*/
- u32 align_pad; /**< available */
+ vlib_buffer_free_list_index_t free_list_index; /** < only used if
+ VLIB_BUFFER_NON_DEFAULT_FREELIST
+ flag is set */
+ u8 align_pad[3]; /**< available */
u32 opaque2[12]; /**< More opaque data, see ../vnet/vnet/buffer.h */
/***** end of second cache line */
@@ -337,7 +357,7 @@ typedef struct vlib_buffer_free_list_t
vlib_buffer_t buffer_init_template;
/* Our index into vlib_main_t's buffer_free_list_pool. */
- u32 index;
+ vlib_buffer_free_list_index_t index;
/* Number of data bytes for buffers in this free list. */
u32 n_data_bytes;
@@ -400,7 +420,8 @@ typedef struct
min_n_buffers_each_physmem_alloc,
u8 * name);
void (*vlib_buffer_delete_free_list_cb) (struct vlib_main_t * vm,
- u32 free_list_index);
+ vlib_buffer_free_list_index_t
+ free_list_index);
} vlib_buffer_callbacks_t;
extern vlib_buffer_callbacks_t *vlib_buffer_callbacks;
@@ -479,7 +500,7 @@ typedef struct
u32 next_index;
/* Free list to use to allocate new buffers. */
- u32 free_list_index;
+ vlib_buffer_free_list_index_t free_list_index;
} tx;
struct
diff --git a/src/vlib/buffer_funcs.h b/src/vlib/buffer_funcs.h
index b73fb266d64..cda44d6aa20 100644
--- a/src/vlib/buffer_funcs.h
+++ b/src/vlib/buffer_funcs.h
@@ -254,22 +254,26 @@ vlib_buffer_round_size (u32 size)
return round_pow2 (size, sizeof (vlib_buffer_t));
}
-always_inline u32
+always_inline vlib_buffer_free_list_index_t
vlib_buffer_get_free_list_index (vlib_buffer_t * b)
{
- return b->flags & VLIB_BUFFER_FREE_LIST_INDEX_MASK;
+ if (PREDICT_FALSE (b->flags & VLIB_BUFFER_NON_DEFAULT_FREELIST))
+ return b->free_list_index;
+
+ return 0;
}
always_inline void
-vlib_buffer_set_free_list_index (vlib_buffer_t * b, u32 index)
+vlib_buffer_set_free_list_index (vlib_buffer_t * b,
+ vlib_buffer_free_list_index_t index)
{
- /* if there is an need for more free lists we should consider
- storig data in the 2nd cacheline */
- ASSERT (VLIB_BUFFER_FREE_LIST_INDEX_MASK & 1);
- ASSERT (index <= VLIB_BUFFER_FREE_LIST_INDEX_MASK);
-
- b->flags &= ~VLIB_BUFFER_FREE_LIST_INDEX_MASK;
- b->flags |= index & VLIB_BUFFER_FREE_LIST_INDEX_MASK;
+ if (PREDICT_FALSE (index))
+ {
+ b->flags |= VLIB_BUFFER_NON_DEFAULT_FREELIST;
+ b->free_list_index = index;
+ }
+ else
+ b->flags &= ~VLIB_BUFFER_NON_DEFAULT_FREELIST;
}
/** \brief Allocate buffers from specific freelist into supplied array
@@ -283,7 +287,8 @@ vlib_buffer_set_free_list_index (vlib_buffer_t * b, u32 index)
always_inline u32
vlib_buffer_alloc_from_free_list (vlib_main_t * vm,
u32 * buffers,
- u32 n_buffers, u32 free_list_index)
+ u32 n_buffers,
+ vlib_buffer_free_list_index_t index)
{
vlib_buffer_main_t *bm = vm->buffer_main;
vlib_buffer_free_list_t *fl;
@@ -292,7 +297,7 @@ vlib_buffer_alloc_from_free_list (vlib_main_t * vm,
ASSERT (bm->cb.vlib_buffer_fill_free_list_cb);
- fl = pool_elt_at_index (bm->buffer_free_list_pool, free_list_index);
+ fl = pool_elt_at_index (bm->buffer_free_list_pool, index);
len = vec_len (fl->buffers);
@@ -429,10 +434,12 @@ vlib_buffer_free_one (vlib_main_t * vm, u32 buffer_index)
}
/* Add/delete buffer free lists. */
-u32 vlib_buffer_create_free_list (vlib_main_t * vm, u32 n_data_bytes,
- char *fmt, ...);
+vlib_buffer_free_list_index_t vlib_buffer_create_free_list (vlib_main_t * vm,
+ u32 n_data_bytes,
+ char *fmt, ...);
always_inline void
-vlib_buffer_delete_free_list (vlib_main_t * vm, u32 free_list_index)
+vlib_buffer_delete_free_list (vlib_main_t * vm,
+ vlib_buffer_free_list_index_t free_list_index)
{
vlib_buffer_main_t *bm = vm->buffer_main;
@@ -442,8 +449,12 @@ vlib_buffer_delete_free_list (vlib_main_t * vm, u32 free_list_index)
}
/* Find already existing public free list with given size or create one. */
-u32 vlib_buffer_get_or_create_free_list (vlib_main_t * vm, u32 n_data_bytes,
- char *fmt, ...);
+vlib_buffer_free_list_index_t vlib_buffer_get_or_create_free_list (vlib_main_t
+ * vm,
+ u32
+ n_data_bytes,
+ char *fmt,
+ ...);
/* Merge two free lists */
void vlib_buffer_merge_free_lists (vlib_buffer_free_list_t * dst,
@@ -455,7 +466,7 @@ void vlib_buffer_free_list_fill_unaligned (vlib_main_t * vm,
free_list,
uword n_unaligned_buffers);
-always_inline u32
+always_inline vlib_buffer_free_list_index_t
vlib_buffer_get_free_list_with_size (vlib_main_t * vm, u32 size)
{
vlib_buffer_main_t *bm = vm->buffer_main;
@@ -467,17 +478,18 @@ vlib_buffer_get_free_list_with_size (vlib_main_t * vm, u32 size)
always_inline vlib_buffer_free_list_t *
vlib_buffer_get_buffer_free_list (vlib_main_t * vm, vlib_buffer_t * b,
- u32 * index)
+ vlib_buffer_free_list_index_t * index)
{
vlib_buffer_main_t *bm = vm->buffer_main;
- u32 i;
+ vlib_buffer_free_list_index_t i;
*index = i = vlib_buffer_get_free_list_index (b);
return pool_elt_at_index (bm->buffer_free_list_pool, i);
}
always_inline vlib_buffer_free_list_t *
-vlib_buffer_get_free_list (vlib_main_t * vm, u32 free_list_index)
+vlib_buffer_get_free_list (vlib_main_t * vm,
+ vlib_buffer_free_list_index_t free_list_index)
{
vlib_buffer_main_t *bm = vm->buffer_main;
vlib_buffer_free_list_t *f;
@@ -491,10 +503,10 @@ vlib_buffer_get_free_list (vlib_main_t * vm, u32 free_list_index)
}
always_inline u32
-vlib_buffer_free_list_buffer_size (vlib_main_t * vm, u32 free_list_index)
+vlib_buffer_free_list_buffer_size (vlib_main_t * vm,
+ vlib_buffer_free_list_index_t index)
{
- vlib_buffer_free_list_t *f =
- vlib_buffer_get_free_list (vm, free_list_index);
+ vlib_buffer_free_list_t *f = vlib_buffer_get_free_list (vm, index);
return f->n_data_bytes;
}
@@ -525,7 +537,7 @@ vlib_copy_buffers (u32 * dst, u32 * src, u32 n)
/* Append given data to end of buffer, possibly allocating new buffers. */
u32 vlib_buffer_add_data (vlib_main_t * vm,
- u32 free_list_index,
+ vlib_buffer_free_list_index_t free_list_index,
u32 buffer_index, void *data, u32 n_data_bytes);
/* duplicate all buffers in chain */
@@ -772,7 +784,7 @@ vlib_buffer_chain_increase_length (vlib_buffer_t * first,
* Returns the number of copied bytes. */
always_inline u16
vlib_buffer_chain_append_data (vlib_main_t * vm,
- u32 free_list_index,
+ vlib_buffer_free_list_index_t free_list_index,
vlib_buffer_t * first,
vlib_buffer_t * last, void *data, u16 data_len)
{
@@ -795,10 +807,11 @@ vlib_buffer_chain_append_data (vlib_main_t * vm,
* chained and points to the last buffer in the chain. */
u16
vlib_buffer_chain_append_data_with_alloc (vlib_main_t * vm,
- u32 free_list_index,
+ vlib_buffer_free_list_index_t
+ free_list_index,
vlib_buffer_t * first,
- vlib_buffer_t ** last,
- void *data, u16 data_len);
+ vlib_buffer_t ** last, void *data,
+ u16 data_len);
void vlib_buffer_chain_validate (vlib_main_t * vm, vlib_buffer_t * first);
format_function_t format_vlib_buffer, format_vlib_buffer_and_data,
@@ -814,7 +827,7 @@ typedef struct
u32 min_n_buffers_each_physmem_alloc;
/* Buffer free list for this template. */
- u32 free_list_index;
+ vlib_buffer_free_list_index_t free_list_index;
u32 *free_buffers;
} vlib_packet_template_t;
@@ -895,6 +908,7 @@ vlib_buffer_init_for_free_list (vlib_buffer_t * dst,
/* Not in the first 16 octets. */
dst->n_add_refs = src->n_add_refs;
+ vlib_buffer_set_free_list_index (dst, fl->index);
/* Make sure it really worked. */
#define _(f) ASSERT (dst->f == src->f);
@@ -936,43 +950,6 @@ vlib_buffer_add_to_free_list (vlib_main_t * vm,
}
}
-always_inline void
-vlib_buffer_init_two_for_free_list (vlib_buffer_t * dst0,
- vlib_buffer_t * dst1,
- vlib_buffer_free_list_t * fl)
-{
- vlib_buffer_t *src = &fl->buffer_init_template;
-
- /* Make sure buffer template is sane. */
- ASSERT (fl->index == vlib_buffer_get_free_list_index (src));
-
- clib_memcpy (STRUCT_MARK_PTR (dst0, template_start),
- STRUCT_MARK_PTR (src, template_start),
- STRUCT_OFFSET_OF (vlib_buffer_t, template_end) -
- STRUCT_OFFSET_OF (vlib_buffer_t, template_start));
-
- clib_memcpy (STRUCT_MARK_PTR (dst1, template_start),
- STRUCT_MARK_PTR (src, template_start),
- STRUCT_OFFSET_OF (vlib_buffer_t, template_end) -
- STRUCT_OFFSET_OF (vlib_buffer_t, template_start));
-
- /* Not in the first 16 octets. */
- dst0->n_add_refs = src->n_add_refs;
- dst1->n_add_refs = src->n_add_refs;
-
- /* Make sure it really worked. */
-#define _(f) ASSERT (dst0->f == src->f); ASSERT( dst1->f == src->f)
- _(current_data);
- _(current_length);
- _(flags);
-#undef _
-
- ASSERT (dst0->total_length_not_including_first_buffer == 0);
- ASSERT (dst1->total_length_not_including_first_buffer == 0);
- ASSERT (dst0->n_add_refs == 0);
- ASSERT (dst1->n_add_refs == 0);
-}
-
#if CLIB_DEBUG > 0
extern u32 *vlib_buffer_state_validation_lock;
extern uword *vlib_buffer_state_validation_hash;
@@ -1065,7 +1042,7 @@ vlib_buffer_chain_compress (vlib_main_t * vm,
return;
}
/* probe free list to find allocated buffer size to avoid overfill */
- u32 index;
+ vlib_buffer_free_list_index_t index;
vlib_buffer_free_list_t *free_list =
vlib_buffer_get_buffer_free_list (vm, first, &index);
diff --git a/src/vnet/buffer.c b/src/vnet/buffer.c
index 38bda8cb6f4..f12adf7eb64 100644
--- a/src/vnet/buffer.c
+++ b/src/vnet/buffer.c
@@ -27,7 +27,7 @@ format_vnet_buffer (u8 * s, va_list * args)
#define _(bit, name, v) \
if (v && (b->flags & VNET_BUFFER_F_##name)) \
a = format (a, "%s ", v);
- foreach_vnet_buffer_field
+ foreach_vnet_buffer_flag
#undef _
if (b->flags & VNET_BUFFER_F_L2_HDR_OFFSET_VALID)
a = format (a, "l2-hdr-offset %d ", vnet_buffer (b)->l2_hdr_offset);
diff --git a/src/vnet/buffer.h b/src/vnet/buffer.h
index 5d7273aa04f..807cd28f9e4 100644
--- a/src/vnet/buffer.h
+++ b/src/vnet/buffer.h
@@ -45,7 +45,7 @@
/**
* Flags that are set in the high order bits of ((vlib_buffer*)b)->flags
*/
-#define foreach_vnet_buffer_field \
+#define foreach_vnet_buffer_flag \
_( 1, L4_CHECKSUM_COMPUTED, "l4-cksum-computed") \
_( 2, L4_CHECKSUM_CORRECT, "l4-cksum-correct") \
_( 3, VLAN_2_DEEP, "vlan-2-deep") \
@@ -61,7 +61,9 @@
_(13, IS_NATED, "nated") \
_(14, L2_HDR_OFFSET_VALID, 0) \
_(15, L3_HDR_OFFSET_VALID, 0) \
- _(16, L4_HDR_OFFSET_VALID, 0)
+ _(16, L4_HDR_OFFSET_VALID, 0) \
+ _(17, FLOW_REPORT, "flow-report") \
+ _(18, IS_DVR, "dvr")
#define VNET_BUFFER_FLAGS_VLAN_BITS \
(VNET_BUFFER_F_VLAN_1_DEEP | VNET_BUFFER_F_VLAN_2_DEEP)
@@ -69,38 +71,17 @@
enum
{
#define _(bit, name, v) VNET_BUFFER_F_##name = (1 << LOG2_VLIB_BUFFER_FLAG_USER(bit)),
- foreach_vnet_buffer_field
+ foreach_vnet_buffer_flag
#undef _
};
enum
{
#define _(bit, name, v) VNET_BUFFER_F_LOG2_##name = LOG2_VLIB_BUFFER_FLAG_USER(bit),
- foreach_vnet_buffer_field
+ foreach_vnet_buffer_flag
#undef _
};
-/**
- * @brief Flags set in ((vnet_buffer(b)->flags
- */
-#define foreach_vnet_opaque_flag \
- _( 1, IS_DVR, "DVR-processed")
-
-enum
-{
-#define _(bit, name, v) VNET_OPAQUE_F_##name = (1 << bit),
- foreach_vnet_opaque_flag
-#undef _
-};
-
-enum
-{
-#define _(bit, name, v) VNET_OPAQUE_F_LOG2_##name = bit,
- foreach_vnet_opaque_flag
-#undef _
-};
-
-
#define foreach_buffer_opaque_union_subtype \
_(ip) \
_(swt) \
@@ -134,7 +115,7 @@ typedef struct
i16 l2_hdr_offset;
i16 l3_hdr_offset;
i16 l4_hdr_offset;
- u16 flags;
+ u16 dont_waste_me;
union
{
diff --git a/src/vnet/dns/dns.c b/src/vnet/dns/dns.c
index 24cd5969aa7..eff854933c4 100644
--- a/src/vnet/dns/dns.c
+++ b/src/vnet/dns/dns.c
@@ -2803,7 +2803,7 @@ vnet_send_dns4_reply (dns_main_t * dm, dns_pending_request_t * pr,
* In the resolution-required / deferred case, resetting a freshly-allocated
* buffer won't hurt. We hope.
*/
- b0->flags &= VLIB_BUFFER_FREE_LIST_INDEX_MASK;
+ b0->flags &= VLIB_BUFFER_NON_DEFAULT_FREELIST;
b0->flags |= (VNET_BUFFER_F_LOCALLY_ORIGINATED
| VLIB_BUFFER_TOTAL_LENGTH_VALID);
b0->current_data = 0;
diff --git a/src/vnet/dpo/dvr_dpo.c b/src/vnet/dpo/dvr_dpo.c
index 1aa16546c82..02b97ee2e9f 100644
--- a/src/vnet/dpo/dvr_dpo.c
+++ b/src/vnet/dpo/dvr_dpo.c
@@ -290,8 +290,8 @@ dvr_dpo_inline (vlib_main_t * vm,
(u8*)ethernet_buffer_get_header(b1));
vnet_buffer(b0)->l2.l2_len = len0;
vnet_buffer(b1)->l2.l2_len = len1;
- vnet_buffer(b0)->flags |= VNET_OPAQUE_F_IS_DVR;
- vnet_buffer(b1)->flags |= VNET_OPAQUE_F_IS_DVR;
+ b0->flags |= VNET_BUFFER_F_IS_DVR;
+ b1->flags |= VNET_BUFFER_F_IS_DVR;
vlib_buffer_advance(b0, -len0);
vlib_buffer_advance(b1, -len1);
@@ -350,7 +350,7 @@ dvr_dpo_inline (vlib_main_t * vm,
len0 = ((u8*)vlib_buffer_get_current(b0) -
(u8*)ethernet_buffer_get_header(b0));
vnet_buffer(b0)->l2.l2_len = len0;
- vnet_buffer(b0)->flags |= VNET_OPAQUE_F_IS_DVR;
+ b0->flags |= VNET_BUFFER_F_IS_DVR;
vlib_buffer_advance(b0, -len0);
/*
@@ -464,13 +464,13 @@ dvr_reinject_inline (vlib_main_t * vm,
b0 = vlib_get_buffer (vm, bi0);
b1 = vlib_get_buffer (vm, bi1);
- if (vnet_buffer(b0)->flags & VNET_OPAQUE_F_IS_DVR)
+ if (b0->flags & VNET_BUFFER_F_IS_DVR)
next0 = DVR_REINJECT_OUTPUT;
else
vnet_feature_next(vnet_buffer(b0)->sw_if_index[VLIB_TX],
&next0, b0);
- if (vnet_buffer(b1)->flags & VNET_OPAQUE_F_IS_DVR)
+ if (b1->flags & VNET_BUFFER_F_IS_DVR)
next1 = DVR_REINJECT_OUTPUT;
else
vnet_feature_next(vnet_buffer(b1)->sw_if_index[VLIB_TX],
@@ -511,7 +511,7 @@ dvr_reinject_inline (vlib_main_t * vm,
b0 = vlib_get_buffer (vm, bi0);
- if (vnet_buffer(b0)->flags & VNET_OPAQUE_F_IS_DVR)
+ if (b0->flags & VNET_BUFFER_F_IS_DVR)
next0 = DVR_REINJECT_OUTPUT;
else
vnet_feature_next(vnet_buffer(b0)->sw_if_index[VLIB_TX],
diff --git a/src/vnet/flow/flow_report.c b/src/vnet/flow/flow_report.c
index f912618ec75..4b890728a8a 100644
--- a/src/vnet/flow/flow_report.c
+++ b/src/vnet/flow/flow_report.c
@@ -126,7 +126,7 @@ send_template_packet (flow_report_main_t * frm,
clib_memcpy (b0->data, fr->rewrite, vec_len (fr->rewrite));
b0->current_data = 0;
b0->current_length = vec_len (fr->rewrite);
- b0->flags |= (VLIB_BUFFER_TOTAL_LENGTH_VALID | VLIB_BUFFER_FLOW_REPORT);
+ b0->flags |= (VLIB_BUFFER_TOTAL_LENGTH_VALID | VNET_BUFFER_F_FLOW_REPORT);
vnet_buffer (b0)->sw_if_index[VLIB_RX] = 0;
vnet_buffer (b0)->sw_if_index[VLIB_TX] = frm->fib_index;
diff --git a/src/vnet/pg/pg.h b/src/vnet/pg/pg.h
index 111df91ae99..20852ba18d1 100644
--- a/src/vnet/pg/pg.h
+++ b/src/vnet/pg/pg.h
@@ -90,7 +90,7 @@ typedef struct
u32 *buffer_fifo;
/* Buffer free list for this buffer index in stream. */
- u32 free_list_index;
+ vlib_buffer_free_list_index_t free_list_index;
} pg_buffer_index_t;
typedef struct pg_stream_t
diff --git a/src/vnet/replication.h b/src/vnet/replication.h
index 531a61c2fd1..6350aedfe7f 100644
--- a/src/vnet/replication.h
+++ b/src/vnet/replication.h
@@ -39,7 +39,7 @@ typedef struct
* data saved from the start of replication and restored
* at the end of replication
*/
- u32 saved_free_list_index; /* from vlib buffer */
+ vlib_buffer_free_list_index_t saved_free_list_index; /* from vlib buffer */
/* data saved from the original packet and restored for each replica */
u64 l2_header[3]; /* 24B (must be at least 22B for l2 packets) */
diff --git a/src/vnet/sctp/sctp_output.c b/src/vnet/sctp/sctp_output.c
index ef5d3b72968..dc78c0959ce 100644
--- a/src/vnet/sctp/sctp_output.c
+++ b/src/vnet/sctp/sctp_output.c
@@ -270,7 +270,7 @@ always_inline void *
sctp_init_buffer (vlib_main_t * vm, vlib_buffer_t * b)
{
ASSERT ((b->flags & VLIB_BUFFER_NEXT_PRESENT) == 0);
- b->flags &= VLIB_BUFFER_FREE_LIST_INDEX_MASK;
+ b->flags &= VLIB_BUFFER_NON_DEFAULT_FREELIST;
b->flags |= VNET_BUFFER_F_LOCALLY_ORIGINATED;
b->total_length_not_including_first_buffer = 0;
vnet_buffer (b)->sctp.flags = 0;
diff --git a/src/vnet/tcp/tcp_output.c b/src/vnet/tcp/tcp_output.c
index 78d64133c3a..ec8a251e6eb 100644
--- a/src/vnet/tcp/tcp_output.c
+++ b/src/vnet/tcp/tcp_output.c
@@ -503,7 +503,7 @@ always_inline void *
tcp_init_buffer (vlib_main_t * vm, vlib_buffer_t * b)
{
ASSERT ((b->flags & VLIB_BUFFER_NEXT_PRESENT) == 0);
- b->flags &= VLIB_BUFFER_FREE_LIST_INDEX_MASK;
+ b->flags &= VLIB_BUFFER_NON_DEFAULT_FREELIST;
b->flags |= VNET_BUFFER_F_LOCALLY_ORIGINATED;
b->total_length_not_including_first_buffer = 0;
vnet_buffer (b)->tcp.flags = 0;
@@ -1299,7 +1299,7 @@ tcp_prepare_retransmit_segment (tcp_connection_t * tc, u32 offset,
ASSERT (n_peeked == len_to_deq);
n_bytes += n_peeked;
chain_b->current_length = n_peeked;
- chain_b->flags &= VLIB_BUFFER_FREE_LIST_INDEX_MASK;
+ chain_b->flags &= VLIB_BUFFER_NON_DEFAULT_FREELIST;
chain_b->next_buffer = 0;
/* update previous buffer */