blob: 297240d45f72f47c2e5abfcf7b0d7fe72eede720 [file] [log] [blame]
Ed Warnickecb9cada2015-12-08 15:45:58 -07001/*
2 * Copyright (c) 2015 Cisco and/or its affiliates.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at:
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15/*
16 * buffer.h: VLIB buffers
17 *
18 * Copyright (c) 2008 Eliot Dresselhaus
19 *
20 * Permission is hereby granted, free of charge, to any person obtaining
21 * a copy of this software and associated documentation files (the
22 * "Software"), to deal in the Software without restriction, including
23 * without limitation the rights to use, copy, modify, merge, publish,
24 * distribute, sublicense, and/or sell copies of the Software, and to
25 * permit persons to whom the Software is furnished to do so, subject to
26 * the following conditions:
27 *
28 * The above copyright notice and this permission notice shall be
29 * included in all copies or substantial portions of the Software.
30 *
31 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
32 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
33 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
34 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
35 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
36 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
37 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
38 */
39
40#ifndef included_vlib_buffer_h
41#define included_vlib_buffer_h
42
43#include <vppinfra/types.h>
44#include <vppinfra/cache.h>
45#include <vppinfra/serialize.h>
46#include <vppinfra/vector.h>
Damjan Marion6b0f5892017-07-27 04:01:24 -040047#include <vppinfra/lock.h>
Ed Warnickecb9cada2015-12-08 15:45:58 -070048#include <vlib/error.h> /* for vlib_error_t */
Damjan Marion19010202016-03-24 17:17:47 +010049
Dave Barach9b8ffd92016-07-08 08:13:45 -040050#include <vlib/config.h> /* for __PRE_DATA_SIZE */
Damjan Marion19010202016-03-24 17:17:47 +010051#define VLIB_BUFFER_PRE_DATA_SIZE __PRE_DATA_SIZE
Ed Warnickecb9cada2015-12-08 15:45:58 -070052
Damjan Marion5de3fec2019-02-06 14:22:32 +010053#define VLIB_BUFFER_DEFAULT_DATA_SIZE (2048)
54
Damjan Marionbd0da972018-10-31 10:59:02 +010055/* Minimum buffer chain segment size. Does not apply to last buffer in chain.
56 Dataplane code can safely asume that specified amount of data is not split
57 into 2 chained buffers */
58#define VLIB_BUFFER_MIN_CHAIN_SEG_SIZE (128)
59
60/* Amount of head buffer data copied to each replica head buffer */
61#define VLIB_BUFFER_CLONE_HEAD_SIZE (256)
62
Ed Warnickecb9cada2015-12-08 15:45:58 -070063/** \file
64 vlib buffer structure definition and a few select
65 access methods. This structure and the buffer allocation
Dave Barach9b8ffd92016-07-08 08:13:45 -040066 mechanism should perhaps live in vnet, but it would take a lot
Ed Warnickecb9cada2015-12-08 15:45:58 -070067 of typing to make it so.
68*/
Dave Barach9b8ffd92016-07-08 08:13:45 -040069
Damjan Mariondac03522018-02-01 15:30:13 +010070/**
71 * Buffer Flags
72 */
73#define foreach_vlib_buffer_flag \
Damjan Marion36eb7c22019-01-18 20:45:30 +010074 _( 0, IS_TRACED, 0) \
BenoƮt Ganne43543172019-10-21 15:13:54 +020075 _( 1, NEXT_PRESENT, "next-present") \
Damjan Marion36eb7c22019-01-18 20:45:30 +010076 _( 2, TOTAL_LENGTH_VALID, 0) \
77 _( 3, EXT_HDR_VALID, "ext-hdr-valid")
Damjan Mariondac03522018-02-01 15:30:13 +010078
79/* NOTE: only buffer generic flags should be defined here, please consider
80 using user flags. i.e. src/vnet/buffer.h */
81
82enum
83{
84#define _(bit, name, v) VLIB_BUFFER_##name = (1 << (bit)),
85 foreach_vlib_buffer_flag
86#undef _
87};
88
89enum
90{
91#define _(bit, name, v) VLIB_BUFFER_LOG2_##name = (bit),
92 foreach_vlib_buffer_flag
93#undef _
94};
95
96 /* User defined buffer flags. */
97#define LOG2_VLIB_BUFFER_FLAG_USER(n) (32 - (n))
98#define VLIB_BUFFER_FLAG_USER(n) (1 << LOG2_VLIB_BUFFER_FLAG_USER(n))
Damjan Marion36eb7c22019-01-18 20:45:30 +010099#define VLIB_BUFFER_FLAGS_ALL (0x0f)
Damjan Mariondac03522018-02-01 15:30:13 +0100100
Damjan Marion9a8a12a2019-01-23 16:52:10 +0100101/** VLIB buffer representation. */
102typedef union
Dave Barach9b8ffd92016-07-08 08:13:45 -0400103{
Damjan Marion9a8a12a2019-01-23 16:52:10 +0100104 struct
105 {
106 CLIB_CACHE_LINE_ALIGN_MARK (cacheline0);
Damjan Marion072401e2017-07-13 18:53:27 +0200107
Damjan Marion9a8a12a2019-01-23 16:52:10 +0100108 /** signed offset in data[], pre_data[] that we are currently
109 * processing. If negative current header points into predata area. */
110 i16 current_data;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700111
Damjan Marion9a8a12a2019-01-23 16:52:10 +0100112 /** Nbytes between current data and the end of this buffer. */
113 u16 current_length;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700114
Damjan Marion9a8a12a2019-01-23 16:52:10 +0100115 /** buffer flags:
116 <br> VLIB_BUFFER_FREE_LIST_INDEX_MASK: bits used to store free list index,
117 <br> VLIB_BUFFER_IS_TRACED: trace this buffer.
118 <br> VLIB_BUFFER_NEXT_PRESENT: this is a multi-chunk buffer.
119 <br> VLIB_BUFFER_TOTAL_LENGTH_VALID: as it says
120 <br> VLIB_BUFFER_EXT_HDR_VALID: buffer contains valid external buffer manager header,
121 set to avoid adding it to a flow report
122 <br> VLIB_BUFFER_FLAG_USER(n): user-defined bit N
123 */
124 u32 flags;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700125
Damjan Marion9a8a12a2019-01-23 16:52:10 +0100126 /** Generic flow identifier */
127 u32 flow_id;
Damjan Marionc47ed032017-01-25 14:18:03 +0100128
Damjan Marion910d3692019-01-21 11:48:34 +0100129 /** Reference count for this buffer. */
130 volatile u8 ref_count;
Dave Barachb5adaea2016-06-17 14:09:56 -0400131
Damjan Marion9a8a12a2019-01-23 16:52:10 +0100132 /** index of buffer pool this buffer belongs. */
133 u8 buffer_pool_index;
Damjan Marione58041f2019-01-18 19:56:09 +0100134
Damjan Marion9a8a12a2019-01-23 16:52:10 +0100135 /** Error code for buffers to be enqueued to error handler. */
136 vlib_error_t error;
Damjan Marione58041f2019-01-18 19:56:09 +0100137
Damjan Marion9a8a12a2019-01-23 16:52:10 +0100138 /** Next buffer for this linked-list of buffers. Only valid if
139 * VLIB_BUFFER_NEXT_PRESENT flag is set. */
140 u32 next_buffer;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700141
Neale Ranns76b56492018-09-28 15:16:14 +0000142 /** The following fields can be in a union because once a packet enters
143 * the punt path, it is no longer on a feature arc */
144 union
145 {
146 /** Used by feature subgraph arcs to visit enabled feature nodes */
147 u32 current_config_index;
148 /* the reason the packet once punted */
149 u32 punt_reason;
150 };
Damjan Marion072401e2017-07-13 18:53:27 +0200151
Damjan Marion9a8a12a2019-01-23 16:52:10 +0100152 /** Opaque data used by sub-graphs for their own purposes. */
153 u32 opaque[10];
Ed Warnickecb9cada2015-12-08 15:45:58 -0700154
Damjan Marion9a8a12a2019-01-23 16:52:10 +0100155 /** part of buffer metadata which is initialized on alloc ends here. */
156 STRUCT_MARK (template_end);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700157
Damjan Marion6807b772020-11-13 10:46:32 +0100158 /** start of 2nd half (2nd cacheline on systems where cacheline size is 64) */
159 CLIB_ALIGN_MARK (second_half, 64);
Damjan Marion9a8a12a2019-01-23 16:52:10 +0100160
Dave Baracha638c182019-06-21 18:24:07 -0400161 /** Specifies trace buffer handle if VLIB_PACKET_IS_TRACED flag is
Damjan Marion9a8a12a2019-01-23 16:52:10 +0100162 * set. */
Dave Baracha638c182019-06-21 18:24:07 -0400163 u32 trace_handle;
Damjan Marion9a8a12a2019-01-23 16:52:10 +0100164
165 /** Only valid for first buffer in chain. Current length plus total length
166 * given here give total number of bytes in buffer chain. */
167 u32 total_length_not_including_first_buffer;
168
169 /**< More opaque data, see ../vnet/vnet/buffer.h */
170 u32 opaque2[14];
171
Damjan Marion6807b772020-11-13 10:46:32 +0100172 /** start of buffer headroom */
173 CLIB_ALIGN_MARK (headroom, 64);
Damjan Marion9a8a12a2019-01-23 16:52:10 +0100174
175 /** Space for inserting data before buffer start. Packet rewrite string
176 * will be rewritten backwards and may extend back before
177 * buffer->data[0]. Must come directly before packet data. */
178 u8 pre_data[VLIB_BUFFER_PRE_DATA_SIZE];
179
180 /** Packet data */
BenoƮt Ganne049d0b42020-04-24 11:48:04 +0200181 u8 data[];
Damjan Marion9a8a12a2019-01-23 16:52:10 +0100182 };
183#ifdef CLIB_HAVE_VEC128
184 u8x16 as_u8x16[4];
185#endif
186#ifdef CLIB_HAVE_VEC256
Damjan Marion22f23ae2019-01-24 15:36:57 +0100187 u8x32 as_u8x32[2];
Damjan Marion9a8a12a2019-01-23 16:52:10 +0100188#endif
189#ifdef CLIB_HAVE_VEC512
Damjan Marion22f23ae2019-01-24 15:36:57 +0100190 u8x64 as_u8x64[1];
Damjan Marion9a8a12a2019-01-23 16:52:10 +0100191#endif
192} vlib_buffer_t;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700193
Damjan Marion6807b772020-11-13 10:46:32 +0100194STATIC_ASSERT_SIZEOF (vlib_buffer_t, 128 + VLIB_BUFFER_PRE_DATA_SIZE);
195STATIC_ASSERT (VLIB_BUFFER_PRE_DATA_SIZE % CLIB_CACHE_LINE_BYTES == 0,
196 "VLIB_BUFFER_PRE_DATA_SIZE must be divisible by cache line size");
197
Damjan Marion19010202016-03-24 17:17:47 +0100198#define VLIB_BUFFER_HDR_SIZE (sizeof(vlib_buffer_t) - VLIB_BUFFER_PRE_DATA_SIZE)
199
Ed Warnickecb9cada2015-12-08 15:45:58 -0700200/** \brief Prefetch buffer metadata.
201 The first 64 bytes of buffer contains most header information
202
203 @param b - (vlib_buffer_t *) pointer to the buffer
204 @param type - LOAD, STORE. In most cases, STORE is the right answer
205*/
206
207#define vlib_prefetch_buffer_header(b,type) CLIB_PREFETCH (b, 64, type)
Damjan Mariond30bf012018-11-18 23:48:43 +0100208#define vlib_prefetch_buffer_data(b,type) \
209 CLIB_PREFETCH (vlib_buffer_get_current(b), CLIB_CACHE_LINE_BYTES, type)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700210
Ed Warnickecb9cada2015-12-08 15:45:58 -0700211always_inline void
212vlib_buffer_struct_is_sane (vlib_buffer_t * b)
213{
214 ASSERT (sizeof (b[0]) % 64 == 0);
215
216 /* Rewrite data must be before and contiguous with packet data. */
217 ASSERT (b->pre_data + VLIB_BUFFER_PRE_DATA_SIZE == b->data);
218}
219
Damjan Marion8f499362018-10-22 13:07:02 +0200220always_inline uword
221vlib_buffer_get_va (vlib_buffer_t * b)
222{
223 return pointer_to_uword (b->data);
224}
225
Ed Warnickecb9cada2015-12-08 15:45:58 -0700226/** \brief Get pointer to current data to process
227
228 @param b - (vlib_buffer_t *) pointer to the buffer
229 @return - (void *) (b->data + b->current_data)
Dave Barach9b8ffd92016-07-08 08:13:45 -0400230*/
Ed Warnickecb9cada2015-12-08 15:45:58 -0700231
232always_inline void *
233vlib_buffer_get_current (vlib_buffer_t * b)
234{
235 /* Check bounds. */
236 ASSERT ((signed) b->current_data >= (signed) -VLIB_BUFFER_PRE_DATA_SIZE);
237 return b->data + b->current_data;
238}
239
Damjan Marion8f499362018-10-22 13:07:02 +0200240always_inline uword
241vlib_buffer_get_current_va (vlib_buffer_t * b)
242{
243 return vlib_buffer_get_va (b) + b->current_data;
244}
245
Ed Warnickecb9cada2015-12-08 15:45:58 -0700246/** \brief Advance current data pointer by the supplied (signed!) amount
247
248 @param b - (vlib_buffer_t *) pointer to the buffer
249 @param l - (word) signed increment
Dave Barach9b8ffd92016-07-08 08:13:45 -0400250*/
Ed Warnickecb9cada2015-12-08 15:45:58 -0700251always_inline void
252vlib_buffer_advance (vlib_buffer_t * b, word l)
253{
254 ASSERT (b->current_length >= l);
255 b->current_data += l;
256 b->current_length -= l;
Damjan Marionbd0da972018-10-31 10:59:02 +0100257
258 ASSERT ((b->flags & VLIB_BUFFER_NEXT_PRESENT) == 0 ||
259 b->current_length >= VLIB_BUFFER_MIN_CHAIN_SEG_SIZE);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700260}
261
Filip Tehlar816f4372017-04-26 16:09:06 +0200262/** \brief Check if there is enough space in buffer to advance
263
264 @param b - (vlib_buffer_t *) pointer to the buffer
265 @param l - (word) size to check
266 @return - 0 if there is less space than 'l' in buffer
267*/
268always_inline u8
269vlib_buffer_has_space (vlib_buffer_t * b, word l)
270{
271 return b->current_length >= l;
272}
273
Ed Warnickecb9cada2015-12-08 15:45:58 -0700274/** \brief Reset current header & length to state they were in when
275 packet was received.
276
277 @param b - (vlib_buffer_t *) pointer to the buffer
278*/
279
280always_inline void
281vlib_buffer_reset (vlib_buffer_t * b)
282{
283 b->current_length += clib_max (b->current_data, 0);
284 b->current_data = 0;
285}
286
287/** \brief Get pointer to buffer's opaque data array
288
289 @param b - (vlib_buffer_t *) pointer to the buffer
290 @return - (void *) b->opaque
291*/
292always_inline void *
293vlib_get_buffer_opaque (vlib_buffer_t * b)
Dave Barach9b8ffd92016-07-08 08:13:45 -0400294{
295 return (void *) b->opaque;
296}
Ed Warnickecb9cada2015-12-08 15:45:58 -0700297
298/** \brief Get pointer to buffer's opaque2 data array
299
300 @param b - (vlib_buffer_t *) pointer to the buffer
301 @return - (void *) b->opaque2
302*/
303always_inline void *
304vlib_get_buffer_opaque2 (vlib_buffer_t * b)
Dave Barach9b8ffd92016-07-08 08:13:45 -0400305{
306 return (void *) b->opaque2;
307}
Ed Warnickecb9cada2015-12-08 15:45:58 -0700308
Dave Barach68b0fb02017-02-28 15:15:56 -0500309/** \brief Get pointer to the end of buffer's data
310 * @param b pointer to the buffer
311 * @return pointer to tail of packet's data
312 */
313always_inline u8 *
314vlib_buffer_get_tail (vlib_buffer_t * b)
315{
316 return b->data + b->current_data + b->current_length;
317}
318
319/** \brief Append uninitialized data to buffer
320 * @param b pointer to the buffer
321 * @param size number of uninitialized bytes
322 * @return pointer to beginning of uninitialized data
323 */
324always_inline void *
Eyal Barid3d42412018-11-05 13:29:25 +0200325vlib_buffer_put_uninit (vlib_buffer_t * b, u16 size)
Dave Barach68b0fb02017-02-28 15:15:56 -0500326{
327 void *p = vlib_buffer_get_tail (b);
328 /* XXX make sure there's enough space */
329 b->current_length += size;
330 return p;
331}
332
333/** \brief Prepend uninitialized data to buffer
334 * @param b pointer to the buffer
335 * @param size number of uninitialized bytes
336 * @return pointer to beginning of uninitialized data
337 */
338always_inline void *
339vlib_buffer_push_uninit (vlib_buffer_t * b, u8 size)
340{
341 ASSERT (b->current_data + VLIB_BUFFER_PRE_DATA_SIZE >= size);
342 b->current_data -= size;
343 b->current_length += size;
344
345 return vlib_buffer_get_current (b);
346}
347
348/** \brief Make head room, typically for packet headers
349 * @param b pointer to the buffer
350 * @param size number of head room bytes
351 * @return pointer to start of buffer (current data)
352 */
353always_inline void *
354vlib_buffer_make_headroom (vlib_buffer_t * b, u8 size)
355{
Dave Barach68b0fb02017-02-28 15:15:56 -0500356 b->current_data += size;
357 return vlib_buffer_get_current (b);
358}
359
Dave Baracha638c182019-06-21 18:24:07 -0400360/** \brief Construct a trace handle from thread and pool index
361 * @param thread Thread id
362 * @param pool_index Pool index
363 * @return trace handle
364 */
365always_inline u32
366vlib_buffer_make_trace_handle (u32 thread, u32 pool_index)
367{
368 u32 rv;
369 ASSERT (thread < 0xff);
370 ASSERT (pool_index < 0x00FFFFFF);
371 rv = (thread << 24) | (pool_index & 0x00FFFFFF);
372 return rv;
373}
374
375/** \brief Extract the thread id from a trace handle
376 * @param trace_handle the trace handle
377 * @return the thread id
378 */
379always_inline u32
380vlib_buffer_get_trace_thread (vlib_buffer_t * b)
381{
382 u32 trace_handle = b->trace_handle;
383
384 return trace_handle >> 24;
385}
386
387/** \brief Extract the trace (pool) index from a trace handle
388 * @param trace_handle the trace handle
389 * @return the trace index
390 */
391always_inline u32
392vlib_buffer_get_trace_index (vlib_buffer_t * b)
393{
394 u32 trace_handle = b->trace_handle;
395 return trace_handle & 0x00FFFFFF;
396}
397
Dave Barach68b0fb02017-02-28 15:15:56 -0500398/** \brief Retrieve bytes from buffer head
399 * @param b pointer to the buffer
400 * @param size number of bytes to pull
401 * @return pointer to start of buffer (current data)
402 */
403always_inline void *
404vlib_buffer_pull (vlib_buffer_t * b, u8 size)
405{
406 if (b->current_length + VLIB_BUFFER_PRE_DATA_SIZE < size)
407 return 0;
408
409 void *data = vlib_buffer_get_current (b);
410 vlib_buffer_advance (b, size);
411 return data;
412}
413
Ed Warnickecb9cada2015-12-08 15:45:58 -0700414/* Forward declaration. */
415struct vlib_main_t;
416
Damjan Marionb6e8b1a2019-03-12 18:14:15 +0100417#define VLIB_BUFFER_POOL_PER_THREAD_CACHE_SZ 512
418
Dave Barach9b8ffd92016-07-08 08:13:45 -0400419typedef struct
420{
Damjan Marion910d3692019-01-21 11:48:34 +0100421 CLIB_CACHE_LINE_ALIGN_MARK (cacheline0);
Damjan Marionb6e8b1a2019-03-12 18:14:15 +0100422 u32 cached_buffers[VLIB_BUFFER_POOL_PER_THREAD_CACHE_SZ];
423 u32 n_cached;
Damjan Marion910d3692019-01-21 11:48:34 +0100424} vlib_buffer_pool_thread_t;
Damjan Marionb6e8b1a2019-03-12 18:14:15 +0100425
Damjan Marion878c6092017-01-04 13:19:27 +0100426typedef struct
427{
Damjan Marion04a7f052017-07-10 15:06:17 +0200428 CLIB_CACHE_LINE_ALIGN_MARK (cacheline0);
Damjan Marion149ba772017-10-12 13:09:26 +0200429 uword start;
430 uword size;
Damjan Mariond1274cb2018-03-13 21:32:17 +0100431 uword log2_page_size;
Damjan Marion910d3692019-01-21 11:48:34 +0100432 u8 index;
433 u32 numa_node;
Damjan Marion68b4da62018-09-30 18:26:20 +0200434 u32 physmem_map_index;
Damjan Marion910d3692019-01-21 11:48:34 +0100435 u32 data_size;
436 u32 n_buffers;
Damjan Marionb6e8b1a2019-03-12 18:14:15 +0100437 u32 n_avail;
Damjan Mariond1274cb2018-03-13 21:32:17 +0100438 u32 *buffers;
Damjan Marion910d3692019-01-21 11:48:34 +0100439 u8 *name;
Damjan Mariond1274cb2018-03-13 21:32:17 +0100440 clib_spinlock_t lock;
Damjan Marion910d3692019-01-21 11:48:34 +0100441
442 /* per-thread data */
443 vlib_buffer_pool_thread_t *threads;
444
445 /* buffer metadata template */
446 vlib_buffer_t buffer_template;
Damjan Marion149ba772017-10-12 13:09:26 +0200447} vlib_buffer_pool_t;
448
Damjan Marionb592d1b2019-02-28 23:16:11 +0100449#define VLIB_BUFFER_MAX_NUMA_NODES 32
450
Damjan Marion149ba772017-10-12 13:09:26 +0200451typedef struct
452{
453 CLIB_CACHE_LINE_ALIGN_MARK (cacheline0);
Damjan Marion04a7f052017-07-10 15:06:17 +0200454 /* Virtual memory address and size of buffer memory, used for calculating
455 buffer index */
456 uword buffer_mem_start;
457 uword buffer_mem_size;
Damjan Marion149ba772017-10-12 13:09:26 +0200458 vlib_buffer_pool_t *buffer_pools;
Damjan Marion04a7f052017-07-10 15:06:17 +0200459
Ed Warnickecb9cada2015-12-08 15:45:58 -0700460 /* Hash table mapping buffer index into number
461 0 => allocated but free, 1 => allocated and not-free.
462 If buffer index is not in hash table then this buffer
463 has never been allocated. */
Dave Barach9b8ffd92016-07-08 08:13:45 -0400464 uword *buffer_known_hash;
Damjan Marion6b0f5892017-07-27 04:01:24 -0400465 clib_spinlock_t buffer_known_hash_lockp;
Damjan Marionb592d1b2019-02-28 23:16:11 +0100466 u8 default_buffer_pool_index_for_numa[VLIB_BUFFER_MAX_NUMA_NODES];
Ed Warnickecb9cada2015-12-08 15:45:58 -0700467
Damjan Marion910d3692019-01-21 11:48:34 +0100468 /* config */
469 u32 buffers_per_numa;
470 u16 ext_hdr_size;
Damjan Marion5de3fec2019-02-06 14:22:32 +0100471 u32 default_data_size;
Nathan Skrzypczak61559022020-11-23 16:25:21 +0100472 clib_mem_page_sz_t log2_page_size;
Damjan Marion910d3692019-01-21 11:48:34 +0100473
474 /* logging */
475 vlib_log_class_t log_default;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700476} vlib_buffer_main_t;
477
Damjan Marion49d66f12017-07-20 18:10:35 +0200478clib_error_t *vlib_buffer_main_init (struct vlib_main_t *vm);
Damjan Marion878c6092017-01-04 13:19:27 +0100479
Ed Warnickecb9cada2015-12-08 15:45:58 -0700480/*
481 */
482
483/** \brief Compile time buffer trajectory tracing option
Dave Barach9b8ffd92016-07-08 08:13:45 -0400484 Turn this on if you run into "bad monkey" contexts,
485 and you want to know exactly which nodes they've visited...
Ed Warnickecb9cada2015-12-08 15:45:58 -0700486 See vlib/main.c...
487*/
488#define VLIB_BUFFER_TRACE_TRAJECTORY 0
489
490#if VLIB_BUFFER_TRACE_TRAJECTORY > 0
Dave Barach7bee7732017-10-18 18:48:11 -0400491extern void (*vlib_buffer_trace_trajectory_cb) (vlib_buffer_t * b, u32 index);
492extern void (*vlib_buffer_trace_trajectory_init_cb) (vlib_buffer_t * b);
493extern void vlib_buffer_trace_trajectory_init (vlib_buffer_t * b);
494#define VLIB_BUFFER_TRACE_TRAJECTORY_INIT(b) \
495 vlib_buffer_trace_trajectory_init (b);
Dave Barach9b8ffd92016-07-08 08:13:45 -0400496#else
Ed Warnickecb9cada2015-12-08 15:45:58 -0700497#define VLIB_BUFFER_TRACE_TRAJECTORY_INIT(b)
498#endif /* VLIB_BUFFER_TRACE_TRAJECTORY */
499
Damjan Marion910d3692019-01-21 11:48:34 +0100500extern u16 __vlib_buffer_external_hdr_size;
501#define VLIB_BUFFER_SET_EXT_HDR_SIZE(x) \
502static void __clib_constructor \
503vnet_buffer_set_ext_hdr_size() \
504{ \
505 if (__vlib_buffer_external_hdr_size) \
506 clib_error ("buffer external header space already set"); \
507 __vlib_buffer_external_hdr_size = CLIB_CACHE_LINE_ROUND (x); \
508}
Dave Barach9b8ffd92016-07-08 08:13:45 -0400509
Damjan Marion910d3692019-01-21 11:48:34 +0100510#endif /* included_vlib_buffer_h */
Damjan Marion04a7f052017-07-10 15:06:17 +0200511
Dave Barach9b8ffd92016-07-08 08:13:45 -0400512/*
513 * fd.io coding-style-patch-verification: ON
514 *
515 * Local Variables:
516 * eval: (c-set-style "gnu")
517 * End:
518 */