Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1 | /* |
| 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_funcs.h: VLIB buffer related functions/inlines |
| 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_funcs_h |
| 41 | #define included_vlib_buffer_funcs_h |
| 42 | |
| 43 | #include <vppinfra/hash.h> |
Dave Barach | c3a0655 | 2018-10-01 09:25:32 -0400 | [diff] [blame] | 44 | #include <vppinfra/fifo.h> |
Klement Sekera | f883f6a | 2019-02-13 11:01:32 +0100 | [diff] [blame^] | 45 | #include <vlib/buffer.h> |
| 46 | #include <vlib/physmem_funcs.h> |
| 47 | #include <vlib/main.h> |
| 48 | #include <vlib/node.h> |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 49 | |
| 50 | /** \file |
| 51 | vlib buffer access methods. |
| 52 | */ |
| 53 | |
Damjan Marion | 24dcbe4 | 2019-01-31 12:29:39 +0100 | [diff] [blame] | 54 | always_inline void |
| 55 | vlib_buffer_validate (vlib_main_t * vm, vlib_buffer_t * b) |
| 56 | { |
| 57 | vlib_buffer_main_t *bm = vm->buffer_main; |
| 58 | vlib_buffer_pool_t *bp; |
| 59 | |
| 60 | /* reference count in allocated buffer always must be 1 or higher */ |
| 61 | ASSERT (b->ref_count > 0); |
| 62 | |
Damjan Marion | 24dcbe4 | 2019-01-31 12:29:39 +0100 | [diff] [blame] | 63 | /* verify that buffer pool index is valid */ |
| 64 | bp = vec_elt_at_index (bm->buffer_pools, b->buffer_pool_index); |
| 65 | ASSERT (pointer_to_uword (b) >= bp->start); |
| 66 | ASSERT (pointer_to_uword (b) < bp->start + bp->size - |
Damjan Marion | 5de3fec | 2019-02-06 14:22:32 +0100 | [diff] [blame] | 67 | (bp->data_size + sizeof (vlib_buffer_t))); |
Damjan Marion | 24dcbe4 | 2019-01-31 12:29:39 +0100 | [diff] [blame] | 68 | } |
| 69 | |
| 70 | always_inline void * |
| 71 | vlib_buffer_ptr_from_index (uword buffer_mem_start, u32 buffer_index, |
| 72 | uword offset) |
| 73 | { |
| 74 | offset += ((uword) buffer_index) << CLIB_LOG2_CACHE_LINE_BYTES; |
| 75 | return uword_to_pointer (buffer_mem_start + offset, vlib_buffer_t *); |
| 76 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 77 | |
| 78 | /** \brief Translate buffer index into buffer pointer |
| 79 | |
| 80 | @param vm - (vlib_main_t *) vlib main data structure pointer |
| 81 | @param buffer_index - (u32) buffer index |
| 82 | @return - (vlib_buffer_t *) buffer pointer |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 83 | */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 84 | always_inline vlib_buffer_t * |
| 85 | vlib_get_buffer (vlib_main_t * vm, u32 buffer_index) |
| 86 | { |
Damjan Marion | d50e347 | 2019-01-20 00:03:56 +0100 | [diff] [blame] | 87 | vlib_buffer_main_t *bm = vm->buffer_main; |
Damjan Marion | 24dcbe4 | 2019-01-31 12:29:39 +0100 | [diff] [blame] | 88 | vlib_buffer_t *b; |
Damjan Marion | 04a7f05 | 2017-07-10 15:06:17 +0200 | [diff] [blame] | 89 | |
Damjan Marion | 24dcbe4 | 2019-01-31 12:29:39 +0100 | [diff] [blame] | 90 | b = vlib_buffer_ptr_from_index (bm->buffer_mem_start, buffer_index, 0); |
| 91 | vlib_buffer_validate (vm, b); |
| 92 | return b; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 93 | } |
| 94 | |
Damjan Marion | 5de3fec | 2019-02-06 14:22:32 +0100 | [diff] [blame] | 95 | static_always_inline u32 |
Damjan Marion | 8934a04 | 2019-02-09 23:29:26 +0100 | [diff] [blame] | 96 | vlib_buffer_get_default_data_size (vlib_main_t * vm) |
Damjan Marion | 5de3fec | 2019-02-06 14:22:32 +0100 | [diff] [blame] | 97 | { |
| 98 | return vm->buffer_main->default_data_size; |
| 99 | } |
| 100 | |
Damjan Marion | e58041f | 2019-01-18 19:56:09 +0100 | [diff] [blame] | 101 | static_always_inline void |
Damjan Marion | 64d557c | 2019-01-18 20:03:41 +0100 | [diff] [blame] | 102 | vlib_buffer_copy_indices (u32 * dst, u32 * src, u32 n_indices) |
| 103 | { |
| 104 | clib_memcpy_fast (dst, src, n_indices * sizeof (u32)); |
| 105 | } |
| 106 | |
Damjan Marion | 9a8a12a | 2019-01-23 16:52:10 +0100 | [diff] [blame] | 107 | STATIC_ASSERT_OFFSET_OF (vlib_buffer_t, template_end, 64); |
Damjan Marion | 64d557c | 2019-01-18 20:03:41 +0100 | [diff] [blame] | 108 | static_always_inline void |
Damjan Marion | e58041f | 2019-01-18 19:56:09 +0100 | [diff] [blame] | 109 | vlib_buffer_copy_template (vlib_buffer_t * b, vlib_buffer_t * bt) |
| 110 | { |
Damjan Marion | 22f23ae | 2019-01-24 15:36:57 +0100 | [diff] [blame] | 111 | #if defined CLIB_HAVE_VEC512 |
| 112 | b->as_u8x64[0] = bt->as_u8x64[0]; |
| 113 | #elif defined (CLIB_HAVE_VEC256) |
Damjan Marion | 9a8a12a | 2019-01-23 16:52:10 +0100 | [diff] [blame] | 114 | b->as_u8x32[0] = bt->as_u8x32[0]; |
| 115 | b->as_u8x32[1] = bt->as_u8x32[1]; |
| 116 | #elif defined (CLIB_HAVE_VEC128) |
| 117 | b->as_u8x16[0] = bt->as_u8x16[0]; |
| 118 | b->as_u8x16[1] = bt->as_u8x16[1]; |
| 119 | b->as_u8x16[2] = bt->as_u8x16[2]; |
| 120 | b->as_u8x16[3] = bt->as_u8x16[3]; |
| 121 | #else |
| 122 | clib_memcpy_fast (b, bt, 64); |
| 123 | #endif |
Damjan Marion | e58041f | 2019-01-18 19:56:09 +0100 | [diff] [blame] | 124 | } |
| 125 | |
Damjan Marion | 910d369 | 2019-01-21 11:48:34 +0100 | [diff] [blame] | 126 | always_inline u8 |
| 127 | vlib_buffer_pool_get_default_for_numa (vlib_main_t * vm, u32 numa_node) |
| 128 | { |
| 129 | ASSERT (numa_node < vm->buffer_main->n_numa_nodes); |
| 130 | return numa_node; |
| 131 | } |
| 132 | |
Damjan Marion | afe56de | 2018-05-17 12:44:00 +0200 | [diff] [blame] | 133 | /** \brief Translate array of buffer indices into buffer pointers with offset |
| 134 | |
| 135 | @param vm - (vlib_main_t *) vlib main data structure pointer |
| 136 | @param bi - (u32 *) array of buffer indices |
| 137 | @param b - (void **) array to store buffer pointers |
| 138 | @param count - (uword) number of elements |
| 139 | @param offset - (i32) offset applied to each pointer |
| 140 | */ |
| 141 | static_always_inline void |
| 142 | vlib_get_buffers_with_offset (vlib_main_t * vm, u32 * bi, void **b, int count, |
| 143 | i32 offset) |
| 144 | { |
Damjan Marion | d50e347 | 2019-01-20 00:03:56 +0100 | [diff] [blame] | 145 | uword buffer_mem_start = vm->buffer_main->buffer_mem_start; |
Damjan Marion | afe56de | 2018-05-17 12:44:00 +0200 | [diff] [blame] | 146 | #ifdef CLIB_HAVE_VEC256 |
Damjan Marion | d50e347 | 2019-01-20 00:03:56 +0100 | [diff] [blame] | 147 | u64x4 off = u64x4_splat (buffer_mem_start + offset); |
Damjan Marion | afe56de | 2018-05-17 12:44:00 +0200 | [diff] [blame] | 148 | /* if count is not const, compiler will not unroll while loop |
| 149 | se we maintain two-in-parallel variant */ |
| 150 | while (count >= 8) |
| 151 | { |
| 152 | u64x4 b0 = u32x4_extend_to_u64x4 (u32x4_load_unaligned (bi)); |
| 153 | u64x4 b1 = u32x4_extend_to_u64x4 (u32x4_load_unaligned (bi + 4)); |
| 154 | /* shift and add to get vlib_buffer_t pointer */ |
| 155 | u64x4_store_unaligned ((b0 << CLIB_LOG2_CACHE_LINE_BYTES) + off, b); |
| 156 | u64x4_store_unaligned ((b1 << CLIB_LOG2_CACHE_LINE_BYTES) + off, b + 4); |
| 157 | b += 8; |
| 158 | bi += 8; |
| 159 | count -= 8; |
| 160 | } |
| 161 | #endif |
| 162 | while (count >= 4) |
| 163 | { |
| 164 | #ifdef CLIB_HAVE_VEC256 |
| 165 | u64x4 b0 = u32x4_extend_to_u64x4 (u32x4_load_unaligned (bi)); |
| 166 | /* shift and add to get vlib_buffer_t pointer */ |
| 167 | u64x4_store_unaligned ((b0 << CLIB_LOG2_CACHE_LINE_BYTES) + off, b); |
Sirshak Das | 759226e | 2018-08-22 08:46:52 +0800 | [diff] [blame] | 168 | #elif defined (CLIB_HAVE_VEC128) |
Damjan Marion | d50e347 | 2019-01-20 00:03:56 +0100 | [diff] [blame] | 169 | u64x2 off = u64x2_splat (buffer_mem_start + offset); |
Damjan Marion | 5df580e | 2018-07-27 01:47:57 +0200 | [diff] [blame] | 170 | u32x4 bi4 = u32x4_load_unaligned (bi); |
| 171 | u64x2 b0 = u32x4_extend_to_u64x2 ((u32x4) bi4); |
Sirshak Das | 759226e | 2018-08-22 08:46:52 +0800 | [diff] [blame] | 172 | #if defined (__aarch64__) |
| 173 | u64x2 b1 = u32x4_extend_to_u64x2_high ((u32x4) bi4); |
| 174 | #else |
Damjan Marion | 5df580e | 2018-07-27 01:47:57 +0200 | [diff] [blame] | 175 | bi4 = u32x4_shuffle (bi4, 2, 3, 0, 1); |
| 176 | u64x2 b1 = u32x4_extend_to_u64x2 ((u32x4) bi4); |
Sirshak Das | 759226e | 2018-08-22 08:46:52 +0800 | [diff] [blame] | 177 | #endif |
Damjan Marion | 5df580e | 2018-07-27 01:47:57 +0200 | [diff] [blame] | 178 | u64x2_store_unaligned ((b0 << CLIB_LOG2_CACHE_LINE_BYTES) + off, b); |
| 179 | u64x2_store_unaligned ((b1 << CLIB_LOG2_CACHE_LINE_BYTES) + off, b + 2); |
Damjan Marion | afe56de | 2018-05-17 12:44:00 +0200 | [diff] [blame] | 180 | #else |
Damjan Marion | 24dcbe4 | 2019-01-31 12:29:39 +0100 | [diff] [blame] | 181 | b[0] = vlib_buffer_ptr_from_index (buffer_mem_start, bi[0], offset); |
| 182 | b[1] = vlib_buffer_ptr_from_index (buffer_mem_start, bi[1], offset); |
| 183 | b[2] = vlib_buffer_ptr_from_index (buffer_mem_start, bi[2], offset); |
| 184 | b[3] = vlib_buffer_ptr_from_index (buffer_mem_start, bi[3], offset); |
Damjan Marion | afe56de | 2018-05-17 12:44:00 +0200 | [diff] [blame] | 185 | #endif |
| 186 | b += 4; |
| 187 | bi += 4; |
| 188 | count -= 4; |
| 189 | } |
| 190 | while (count) |
| 191 | { |
Damjan Marion | 24dcbe4 | 2019-01-31 12:29:39 +0100 | [diff] [blame] | 192 | b[0] = vlib_buffer_ptr_from_index (buffer_mem_start, bi[0], offset); |
Damjan Marion | afe56de | 2018-05-17 12:44:00 +0200 | [diff] [blame] | 193 | b += 1; |
| 194 | bi += 1; |
| 195 | count -= 1; |
| 196 | } |
| 197 | } |
| 198 | |
| 199 | /** \brief Translate array of buffer indices into buffer pointers |
| 200 | |
| 201 | @param vm - (vlib_main_t *) vlib main data structure pointer |
| 202 | @param bi - (u32 *) array of buffer indices |
| 203 | @param b - (vlib_buffer_t **) array to store buffer pointers |
| 204 | @param count - (uword) number of elements |
| 205 | */ |
| 206 | |
| 207 | static_always_inline void |
| 208 | vlib_get_buffers (vlib_main_t * vm, u32 * bi, vlib_buffer_t ** b, int count) |
| 209 | { |
| 210 | vlib_get_buffers_with_offset (vm, bi, (void **) b, count, 0); |
| 211 | } |
| 212 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 213 | /** \brief Translate buffer pointer into buffer index |
| 214 | |
| 215 | @param vm - (vlib_main_t *) vlib main data structure pointer |
Chris Luke | d4024f5 | 2016-09-06 09:32:36 -0400 | [diff] [blame] | 216 | @param p - (void *) buffer pointer |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 217 | @return - (u32) buffer index |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 218 | */ |
Damjan Marion | 04a7f05 | 2017-07-10 15:06:17 +0200 | [diff] [blame] | 219 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 220 | always_inline u32 |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 221 | vlib_get_buffer_index (vlib_main_t * vm, void *p) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 222 | { |
Damjan Marion | d50e347 | 2019-01-20 00:03:56 +0100 | [diff] [blame] | 223 | vlib_buffer_main_t *bm = vm->buffer_main; |
Damjan Marion | 04a7f05 | 2017-07-10 15:06:17 +0200 | [diff] [blame] | 224 | uword offset = pointer_to_uword (p) - bm->buffer_mem_start; |
| 225 | ASSERT (pointer_to_uword (p) >= bm->buffer_mem_start); |
| 226 | ASSERT (offset < bm->buffer_mem_size); |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 227 | ASSERT ((offset % (1 << CLIB_LOG2_CACHE_LINE_BYTES)) == 0); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 228 | return offset >> CLIB_LOG2_CACHE_LINE_BYTES; |
| 229 | } |
| 230 | |
Damjan Marion | afe56de | 2018-05-17 12:44:00 +0200 | [diff] [blame] | 231 | /** \brief Translate array of buffer pointers into buffer indices with offset |
| 232 | |
| 233 | @param vm - (vlib_main_t *) vlib main data structure pointer |
| 234 | @param b - (void **) array of buffer pointers |
| 235 | @param bi - (u32 *) array to store buffer indices |
| 236 | @param count - (uword) number of elements |
| 237 | @param offset - (i32) offset applied to each pointer |
| 238 | */ |
| 239 | static_always_inline void |
| 240 | vlib_get_buffer_indices_with_offset (vlib_main_t * vm, void **b, u32 * bi, |
| 241 | uword count, i32 offset) |
| 242 | { |
| 243 | #ifdef CLIB_HAVE_VEC256 |
| 244 | u32x8 mask = { 0, 2, 4, 6, 1, 3, 5, 7 }; |
Damjan Marion | d50e347 | 2019-01-20 00:03:56 +0100 | [diff] [blame] | 245 | u64x4 off4 = u64x4_splat (vm->buffer_main->buffer_mem_start - offset); |
Damjan Marion | afe56de | 2018-05-17 12:44:00 +0200 | [diff] [blame] | 246 | |
| 247 | while (count >= 8) |
| 248 | { |
| 249 | /* load 4 pointers into 256-bit register */ |
| 250 | u64x4 v0 = u64x4_load_unaligned (b); |
| 251 | u64x4 v1 = u64x4_load_unaligned (b + 4); |
| 252 | u32x8 v2, v3; |
| 253 | |
| 254 | v0 -= off4; |
| 255 | v1 -= off4; |
| 256 | |
| 257 | v0 >>= CLIB_LOG2_CACHE_LINE_BYTES; |
| 258 | v1 >>= CLIB_LOG2_CACHE_LINE_BYTES; |
| 259 | |
| 260 | /* permute 256-bit register so lower u32s of each buffer index are |
| 261 | * placed into lower 128-bits */ |
| 262 | v2 = u32x8_permute ((u32x8) v0, mask); |
| 263 | v3 = u32x8_permute ((u32x8) v1, mask); |
| 264 | |
| 265 | /* extract lower 128-bits and save them to the array of buffer indices */ |
| 266 | u32x4_store_unaligned (u32x8_extract_lo (v2), bi); |
| 267 | u32x4_store_unaligned (u32x8_extract_lo (v3), bi + 4); |
| 268 | bi += 8; |
| 269 | b += 8; |
| 270 | count -= 8; |
| 271 | } |
| 272 | #endif |
| 273 | while (count >= 4) |
| 274 | { |
| 275 | /* equivalent non-nector implementation */ |
| 276 | bi[0] = vlib_get_buffer_index (vm, ((u8 *) b[0]) + offset); |
| 277 | bi[1] = vlib_get_buffer_index (vm, ((u8 *) b[1]) + offset); |
| 278 | bi[2] = vlib_get_buffer_index (vm, ((u8 *) b[2]) + offset); |
| 279 | bi[3] = vlib_get_buffer_index (vm, ((u8 *) b[3]) + offset); |
| 280 | bi += 4; |
| 281 | b += 4; |
| 282 | count -= 4; |
| 283 | } |
| 284 | while (count) |
| 285 | { |
Zhiyong Yang | 462072a | 2018-05-30 22:12:57 -0400 | [diff] [blame] | 286 | bi[0] = vlib_get_buffer_index (vm, ((u8 *) b[0]) + offset); |
Damjan Marion | afe56de | 2018-05-17 12:44:00 +0200 | [diff] [blame] | 287 | bi += 1; |
| 288 | b += 1; |
| 289 | count -= 1; |
| 290 | } |
| 291 | } |
| 292 | |
| 293 | /** \brief Translate array of buffer pointers into buffer indices |
| 294 | |
| 295 | @param vm - (vlib_main_t *) vlib main data structure pointer |
| 296 | @param b - (vlib_buffer_t **) array of buffer pointers |
| 297 | @param bi - (u32 *) array to store buffer indices |
| 298 | @param count - (uword) number of elements |
| 299 | */ |
| 300 | static_always_inline void |
| 301 | vlib_get_buffer_indices (vlib_main_t * vm, vlib_buffer_t ** b, u32 * bi, |
| 302 | uword count) |
| 303 | { |
| 304 | vlib_get_buffer_indices_with_offset (vm, (void **) b, bi, count, 0); |
| 305 | } |
| 306 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 307 | /** \brief Get next buffer in buffer linklist, or zero for end of list. |
| 308 | |
| 309 | @param vm - (vlib_main_t *) vlib main data structure pointer |
| 310 | @param b - (void *) buffer pointer |
| 311 | @return - (vlib_buffer_t *) next buffer, or NULL |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 312 | */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 313 | always_inline vlib_buffer_t * |
| 314 | vlib_get_next_buffer (vlib_main_t * vm, vlib_buffer_t * b) |
| 315 | { |
| 316 | return (b->flags & VLIB_BUFFER_NEXT_PRESENT |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 317 | ? vlib_get_buffer (vm, b->next_buffer) : 0); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 318 | } |
| 319 | |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 320 | uword vlib_buffer_length_in_chain_slow_path (vlib_main_t * vm, |
| 321 | vlib_buffer_t * b_first); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 322 | |
| 323 | /** \brief Get length in bytes of the buffer chain |
| 324 | |
| 325 | @param vm - (vlib_main_t *) vlib main data structure pointer |
| 326 | @param b - (void *) buffer pointer |
| 327 | @return - (uword) length of buffer chain |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 328 | */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 329 | always_inline uword |
| 330 | vlib_buffer_length_in_chain (vlib_main_t * vm, vlib_buffer_t * b) |
| 331 | { |
Damjan Marion | 072401e | 2017-07-13 18:53:27 +0200 | [diff] [blame] | 332 | uword len = b->current_length; |
| 333 | |
| 334 | if (PREDICT_TRUE ((b->flags & VLIB_BUFFER_NEXT_PRESENT) == 0)) |
| 335 | return len; |
| 336 | |
| 337 | if (PREDICT_TRUE (b->flags & VLIB_BUFFER_TOTAL_LENGTH_VALID)) |
| 338 | return len + b->total_length_not_including_first_buffer; |
| 339 | |
| 340 | return vlib_buffer_length_in_chain_slow_path (vm, b); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 341 | } |
| 342 | |
| 343 | /** \brief Get length in bytes of the buffer index buffer chain |
| 344 | |
| 345 | @param vm - (vlib_main_t *) vlib main data structure pointer |
| 346 | @param bi - (u32) buffer index |
| 347 | @return - (uword) length of buffer chain |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 348 | */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 349 | always_inline uword |
| 350 | vlib_buffer_index_length_in_chain (vlib_main_t * vm, u32 bi) |
| 351 | { |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 352 | vlib_buffer_t *b = vlib_get_buffer (vm, bi); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 353 | return vlib_buffer_length_in_chain (vm, b); |
| 354 | } |
| 355 | |
| 356 | /** \brief Copy buffer contents to memory |
| 357 | |
| 358 | @param vm - (vlib_main_t *) vlib main data structure pointer |
Chris Luke | d4024f5 | 2016-09-06 09:32:36 -0400 | [diff] [blame] | 359 | @param buffer_index - (u32) buffer index |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 360 | @param contents - (u8 *) memory, <strong>must be large enough</strong> |
| 361 | @return - (uword) length of buffer chain |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 362 | */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 363 | always_inline uword |
| 364 | vlib_buffer_contents (vlib_main_t * vm, u32 buffer_index, u8 * contents) |
| 365 | { |
| 366 | uword content_len = 0; |
| 367 | uword l; |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 368 | vlib_buffer_t *b; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 369 | |
| 370 | while (1) |
| 371 | { |
| 372 | b = vlib_get_buffer (vm, buffer_index); |
| 373 | l = b->current_length; |
Dave Barach | 178cf49 | 2018-11-13 16:34:13 -0500 | [diff] [blame] | 374 | clib_memcpy_fast (contents + content_len, b->data + b->current_data, l); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 375 | content_len += l; |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 376 | if (!(b->flags & VLIB_BUFFER_NEXT_PRESENT)) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 377 | break; |
| 378 | buffer_index = b->next_buffer; |
| 379 | } |
| 380 | |
| 381 | return content_len; |
| 382 | } |
| 383 | |
Damjan Marion | 8f49936 | 2018-10-22 13:07:02 +0200 | [diff] [blame] | 384 | always_inline uword |
| 385 | vlib_buffer_get_pa (vlib_main_t * vm, vlib_buffer_t * b) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 386 | { |
Damjan Marion | 68b4da6 | 2018-09-30 18:26:20 +0200 | [diff] [blame] | 387 | return vlib_physmem_get_pa (vm, b->data); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 388 | } |
| 389 | |
Damjan Marion | 8f49936 | 2018-10-22 13:07:02 +0200 | [diff] [blame] | 390 | always_inline uword |
| 391 | vlib_buffer_get_current_pa (vlib_main_t * vm, vlib_buffer_t * b) |
| 392 | { |
| 393 | return vlib_buffer_get_pa (vm, b) + b->current_data; |
| 394 | } |
| 395 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 396 | /** \brief Prefetch buffer metadata by buffer index |
| 397 | The first 64 bytes of buffer contains most header information |
| 398 | |
| 399 | @param vm - (vlib_main_t *) vlib main data structure pointer |
| 400 | @param bi - (u32) buffer index |
| 401 | @param type - LOAD, STORE. In most cases, STORE is the right answer |
| 402 | */ |
| 403 | /* Prefetch buffer header given index. */ |
| 404 | #define vlib_prefetch_buffer_with_index(vm,bi,type) \ |
| 405 | do { \ |
| 406 | vlib_buffer_t * _b = vlib_get_buffer (vm, bi); \ |
| 407 | vlib_prefetch_buffer_header (_b, type); \ |
| 408 | } while (0) |
| 409 | |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 410 | typedef enum |
| 411 | { |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 412 | /* Index is unknown. */ |
| 413 | VLIB_BUFFER_UNKNOWN, |
| 414 | |
| 415 | /* Index is known and free/allocated. */ |
| 416 | VLIB_BUFFER_KNOWN_FREE, |
| 417 | VLIB_BUFFER_KNOWN_ALLOCATED, |
| 418 | } vlib_buffer_known_state_t; |
| 419 | |
Damjan Marion | c8a26c6 | 2017-11-24 20:15:23 +0100 | [diff] [blame] | 420 | void vlib_buffer_validate_alloc_free (vlib_main_t * vm, u32 * buffers, |
| 421 | uword n_buffers, |
| 422 | vlib_buffer_known_state_t |
| 423 | expected_state); |
| 424 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 425 | always_inline vlib_buffer_known_state_t |
Damjan Marion | d50e347 | 2019-01-20 00:03:56 +0100 | [diff] [blame] | 426 | vlib_buffer_is_known (vlib_main_t * vm, u32 buffer_index) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 427 | { |
Damjan Marion | d50e347 | 2019-01-20 00:03:56 +0100 | [diff] [blame] | 428 | vlib_buffer_main_t *bm = vm->buffer_main; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 429 | |
Damjan Marion | 6b0f589 | 2017-07-27 04:01:24 -0400 | [diff] [blame] | 430 | clib_spinlock_lock (&bm->buffer_known_hash_lockp); |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 431 | uword *p = hash_get (bm->buffer_known_hash, buffer_index); |
Damjan Marion | 6b0f589 | 2017-07-27 04:01:24 -0400 | [diff] [blame] | 432 | clib_spinlock_unlock (&bm->buffer_known_hash_lockp); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 433 | return p ? p[0] : VLIB_BUFFER_UNKNOWN; |
| 434 | } |
| 435 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 436 | /* Validates sanity of a single buffer. |
| 437 | Returns format'ed vector with error message if any. */ |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 438 | u8 *vlib_validate_buffer (vlib_main_t * vm, u32 buffer_index, |
| 439 | uword follow_chain); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 440 | |
Damjan Marion | 910d369 | 2019-01-21 11:48:34 +0100 | [diff] [blame] | 441 | static_always_inline vlib_buffer_pool_t * |
| 442 | vlib_get_buffer_pool (vlib_main_t * vm, u8 buffer_pool_index) |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 443 | { |
Damjan Marion | 910d369 | 2019-01-21 11:48:34 +0100 | [diff] [blame] | 444 | vlib_buffer_main_t *bm = vm->buffer_main; |
| 445 | return vec_elt_at_index (bm->buffer_pools, buffer_pool_index); |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 446 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 447 | |
Damjan Marion | 910d369 | 2019-01-21 11:48:34 +0100 | [diff] [blame] | 448 | static_always_inline uword |
| 449 | vlib_buffer_pool_get (vlib_main_t * vm, u8 buffer_pool_index, u32 * buffers, |
| 450 | u32 n_buffers) |
| 451 | { |
| 452 | vlib_buffer_pool_t *bp = vlib_get_buffer_pool (vm, buffer_pool_index); |
| 453 | u32 len; |
| 454 | |
| 455 | ASSERT (bp->buffers); |
| 456 | |
| 457 | clib_spinlock_lock (&bp->lock); |
| 458 | len = vec_len (bp->buffers); |
| 459 | if (PREDICT_TRUE (n_buffers < len)) |
| 460 | { |
| 461 | len -= n_buffers; |
| 462 | vlib_buffer_copy_indices (buffers, bp->buffers + len, n_buffers); |
| 463 | _vec_len (bp->buffers) = len; |
| 464 | clib_spinlock_unlock (&bp->lock); |
| 465 | return n_buffers; |
| 466 | } |
| 467 | else |
| 468 | { |
| 469 | vlib_buffer_copy_indices (buffers, bp->buffers, len); |
| 470 | _vec_len (bp->buffers) = 0; |
| 471 | clib_spinlock_unlock (&bp->lock); |
| 472 | return len; |
| 473 | } |
| 474 | } |
| 475 | |
| 476 | |
| 477 | /** \brief Allocate buffers from specific pool into supplied array |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 478 | |
| 479 | @param vm - (vlib_main_t *) vlib main data structure pointer |
| 480 | @param buffers - (u32 * ) buffer index array |
| 481 | @param n_buffers - (u32) number of buffers requested |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 482 | @return - (u32) number of buffers actually allocated, may be |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 483 | less than the number requested or zero |
| 484 | */ |
Damjan Marion | 910d369 | 2019-01-21 11:48:34 +0100 | [diff] [blame] | 485 | |
Damjan Marion | 878c609 | 2017-01-04 13:19:27 +0100 | [diff] [blame] | 486 | always_inline u32 |
Damjan Marion | 910d369 | 2019-01-21 11:48:34 +0100 | [diff] [blame] | 487 | vlib_buffer_alloc_from_pool (vlib_main_t * vm, u32 * buffers, u32 n_buffers, |
| 488 | u8 buffer_pool_index) |
Damjan Marion | 878c609 | 2017-01-04 13:19:27 +0100 | [diff] [blame] | 489 | { |
Damjan Marion | d50e347 | 2019-01-20 00:03:56 +0100 | [diff] [blame] | 490 | vlib_buffer_main_t *bm = vm->buffer_main; |
Damjan Marion | 910d369 | 2019-01-21 11:48:34 +0100 | [diff] [blame] | 491 | vlib_buffer_pool_t *bp; |
| 492 | vlib_buffer_pool_thread_t *bpt; |
| 493 | u32 *src, *dst, len, n_left; |
Damjan Marion | 878c609 | 2017-01-04 13:19:27 +0100 | [diff] [blame] | 494 | |
Damjan Marion | 910d369 | 2019-01-21 11:48:34 +0100 | [diff] [blame] | 495 | bp = vec_elt_at_index (bm->buffer_pools, buffer_pool_index); |
| 496 | bpt = vec_elt_at_index (bp->threads, vm->thread_index); |
Damjan Marion | 878c609 | 2017-01-04 13:19:27 +0100 | [diff] [blame] | 497 | |
Damjan Marion | 910d369 | 2019-01-21 11:48:34 +0100 | [diff] [blame] | 498 | dst = buffers; |
| 499 | n_left = n_buffers; |
| 500 | len = vec_len (bpt->cached_buffers); |
Damjan Marion | c8a26c6 | 2017-11-24 20:15:23 +0100 | [diff] [blame] | 501 | |
Damjan Marion | 910d369 | 2019-01-21 11:48:34 +0100 | [diff] [blame] | 502 | /* per-thread cache contains enough buffers */ |
| 503 | if (len >= n_buffers) |
Damjan Marion | c8a26c6 | 2017-11-24 20:15:23 +0100 | [diff] [blame] | 504 | { |
Damjan Marion | 910d369 | 2019-01-21 11:48:34 +0100 | [diff] [blame] | 505 | src = bpt->cached_buffers + len - n_buffers; |
| 506 | vlib_buffer_copy_indices (dst, src, n_buffers); |
| 507 | _vec_len (bpt->cached_buffers) -= n_buffers; |
Damjan Marion | c8a26c6 | 2017-11-24 20:15:23 +0100 | [diff] [blame] | 508 | |
Damjan Marion | 910d369 | 2019-01-21 11:48:34 +0100 | [diff] [blame] | 509 | if (CLIB_DEBUG > 0) |
| 510 | vlib_buffer_validate_alloc_free (vm, buffers, n_buffers, |
| 511 | VLIB_BUFFER_KNOWN_FREE); |
Damjan Marion | c8a26c6 | 2017-11-24 20:15:23 +0100 | [diff] [blame] | 512 | return n_buffers; |
| 513 | } |
| 514 | |
Damjan Marion | 910d369 | 2019-01-21 11:48:34 +0100 | [diff] [blame] | 515 | /* take everything available in the cache */ |
| 516 | if (len) |
| 517 | { |
| 518 | vlib_buffer_copy_indices (dst, bpt->cached_buffers, len); |
| 519 | _vec_len (bpt->cached_buffers) = 0; |
| 520 | dst += len; |
| 521 | n_left -= len; |
| 522 | } |
| 523 | |
| 524 | len = round_pow2 (n_left, 32); |
| 525 | vec_validate_aligned (bpt->cached_buffers, len - 1, CLIB_CACHE_LINE_BYTES); |
| 526 | len = vlib_buffer_pool_get (vm, buffer_pool_index, bpt->cached_buffers, |
| 527 | len); |
| 528 | _vec_len (bpt->cached_buffers) = len; |
| 529 | |
| 530 | if (len) |
| 531 | { |
| 532 | u32 n_copy = clib_min (len, n_left); |
| 533 | src = bpt->cached_buffers + len - n_copy; |
| 534 | vlib_buffer_copy_indices (dst, src, n_copy); |
| 535 | _vec_len (bpt->cached_buffers) -= n_copy; |
| 536 | n_left -= n_copy; |
| 537 | } |
| 538 | |
| 539 | n_buffers -= n_left; |
Damjan Marion | c8a26c6 | 2017-11-24 20:15:23 +0100 | [diff] [blame] | 540 | |
| 541 | /* Verify that buffers are known free. */ |
Damjan Marion | 910d369 | 2019-01-21 11:48:34 +0100 | [diff] [blame] | 542 | if (CLIB_DEBUG > 0) |
| 543 | vlib_buffer_validate_alloc_free (vm, buffers, n_buffers, |
| 544 | VLIB_BUFFER_KNOWN_FREE); |
Damjan Marion | c8a26c6 | 2017-11-24 20:15:23 +0100 | [diff] [blame] | 545 | |
| 546 | return n_buffers; |
| 547 | } |
| 548 | |
Damjan Marion | 910d369 | 2019-01-21 11:48:34 +0100 | [diff] [blame] | 549 | /** \brief Allocate buffers from specific numa node into supplied array |
| 550 | |
| 551 | @param vm - (vlib_main_t *) vlib main data structure pointer |
| 552 | @param buffers - (u32 * ) buffer index array |
| 553 | @param n_buffers - (u32) number of buffers requested |
| 554 | @param numa_node - (u32) numa node |
| 555 | @return - (u32) number of buffers actually allocated, may be |
| 556 | less than the number requested or zero |
| 557 | */ |
| 558 | always_inline u32 |
| 559 | vlib_buffer_alloc_on_numa (vlib_main_t * vm, u32 * buffers, u32 n_buffers, |
| 560 | u32 numa_node) |
| 561 | { |
| 562 | u8 index = vlib_buffer_pool_get_default_for_numa (vm, numa_node); |
| 563 | return vlib_buffer_alloc_from_pool (vm, buffers, n_buffers, index); |
| 564 | } |
| 565 | |
Damjan Marion | c8a26c6 | 2017-11-24 20:15:23 +0100 | [diff] [blame] | 566 | /** \brief Allocate buffers into supplied array |
| 567 | |
| 568 | @param vm - (vlib_main_t *) vlib main data structure pointer |
| 569 | @param buffers - (u32 * ) buffer index array |
| 570 | @param n_buffers - (u32) number of buffers requested |
| 571 | @return - (u32) number of buffers actually allocated, may be |
| 572 | less than the number requested or zero |
| 573 | */ |
Damjan Marion | 910d369 | 2019-01-21 11:48:34 +0100 | [diff] [blame] | 574 | |
Damjan Marion | c8a26c6 | 2017-11-24 20:15:23 +0100 | [diff] [blame] | 575 | always_inline u32 |
| 576 | vlib_buffer_alloc (vlib_main_t * vm, u32 * buffers, u32 n_buffers) |
| 577 | { |
Damjan Marion | 910d369 | 2019-01-21 11:48:34 +0100 | [diff] [blame] | 578 | return vlib_buffer_alloc_on_numa (vm, buffers, n_buffers, vm->numa_node); |
Damjan Marion | 878c609 | 2017-01-04 13:19:27 +0100 | [diff] [blame] | 579 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 580 | |
Damjan Marion | c58408c | 2018-01-18 14:54:04 +0100 | [diff] [blame] | 581 | /** \brief Allocate buffers into ring |
| 582 | |
| 583 | @param vm - (vlib_main_t *) vlib main data structure pointer |
| 584 | @param buffers - (u32 * ) buffer index ring |
| 585 | @param start - (u32) first slot in the ring |
| 586 | @param ring_size - (u32) ring size |
| 587 | @param n_buffers - (u32) number of buffers requested |
| 588 | @return - (u32) number of buffers actually allocated, may be |
| 589 | less than the number requested or zero |
| 590 | */ |
| 591 | always_inline u32 |
| 592 | vlib_buffer_alloc_to_ring (vlib_main_t * vm, u32 * ring, u32 start, |
| 593 | u32 ring_size, u32 n_buffers) |
| 594 | { |
| 595 | u32 n_alloc; |
| 596 | |
| 597 | ASSERT (n_buffers <= ring_size); |
| 598 | |
| 599 | if (PREDICT_TRUE (start + n_buffers <= ring_size)) |
| 600 | return vlib_buffer_alloc (vm, ring + start, n_buffers); |
| 601 | |
| 602 | n_alloc = vlib_buffer_alloc (vm, ring + start, ring_size - start); |
| 603 | |
| 604 | if (PREDICT_TRUE (n_alloc == ring_size - start)) |
| 605 | n_alloc += vlib_buffer_alloc (vm, ring, n_buffers - n_alloc); |
| 606 | |
| 607 | return n_alloc; |
| 608 | } |
| 609 | |
Damjan Marion | 910d369 | 2019-01-21 11:48:34 +0100 | [diff] [blame] | 610 | /** \brief Allocate buffers into ring from specific buffer pool |
| 611 | |
| 612 | @param vm - (vlib_main_t *) vlib main data structure pointer |
| 613 | @param buffers - (u32 * ) buffer index ring |
| 614 | @param start - (u32) first slot in the ring |
| 615 | @param ring_size - (u32) ring size |
| 616 | @param n_buffers - (u32) number of buffers requested |
| 617 | @return - (u32) number of buffers actually allocated, may be |
| 618 | less than the number requested or zero |
| 619 | */ |
| 620 | always_inline u32 |
| 621 | vlib_buffer_alloc_to_ring_from_pool (vlib_main_t * vm, u32 * ring, u32 start, |
| 622 | u32 ring_size, u32 n_buffers, |
| 623 | u8 buffer_pool_index) |
| 624 | { |
| 625 | u32 n_alloc; |
| 626 | |
| 627 | ASSERT (n_buffers <= ring_size); |
| 628 | |
| 629 | if (PREDICT_TRUE (start + n_buffers <= ring_size)) |
| 630 | return vlib_buffer_alloc_from_pool (vm, ring + start, n_buffers, |
| 631 | buffer_pool_index); |
| 632 | |
| 633 | n_alloc = vlib_buffer_alloc_from_pool (vm, ring + start, ring_size - start, |
| 634 | buffer_pool_index); |
| 635 | |
| 636 | if (PREDICT_TRUE (n_alloc == ring_size - start)) |
| 637 | n_alloc += vlib_buffer_alloc_from_pool (vm, ring, n_buffers - n_alloc, |
| 638 | buffer_pool_index); |
| 639 | |
| 640 | return n_alloc; |
| 641 | } |
| 642 | |
Damjan Marion | f646d74 | 2019-01-31 18:50:04 +0100 | [diff] [blame] | 643 | static_always_inline void |
Damjan Marion | 910d369 | 2019-01-21 11:48:34 +0100 | [diff] [blame] | 644 | vlib_buffer_pool_put (vlib_main_t * vm, u8 buffer_pool_index, |
| 645 | u32 * buffers, u32 n_buffers) |
| 646 | { |
| 647 | vlib_buffer_pool_t *bp = vlib_get_buffer_pool (vm, buffer_pool_index); |
| 648 | vlib_buffer_pool_thread_t *bpt = |
| 649 | vec_elt_at_index (bp->threads, vm->thread_index); |
| 650 | |
Damjan Marion | f646d74 | 2019-01-31 18:50:04 +0100 | [diff] [blame] | 651 | if (CLIB_DEBUG > 0) |
| 652 | vlib_buffer_validate_alloc_free (vm, buffers, n_buffers, |
| 653 | VLIB_BUFFER_KNOWN_ALLOCATED); |
| 654 | |
Damjan Marion | 910d369 | 2019-01-21 11:48:34 +0100 | [diff] [blame] | 655 | vec_add_aligned (bpt->cached_buffers, buffers, n_buffers, |
| 656 | CLIB_CACHE_LINE_BYTES); |
| 657 | |
| 658 | if (vec_len (bpt->cached_buffers) > 4 * VLIB_FRAME_SIZE) |
| 659 | { |
| 660 | clib_spinlock_lock (&bp->lock); |
| 661 | /* keep last stored buffers, as they are more likely hot in the cache */ |
| 662 | vec_add_aligned (bp->buffers, bpt->cached_buffers, VLIB_FRAME_SIZE, |
| 663 | CLIB_CACHE_LINE_BYTES); |
| 664 | vec_delete (bpt->cached_buffers, VLIB_FRAME_SIZE, 0); |
| 665 | bpt->n_alloc -= VLIB_FRAME_SIZE; |
| 666 | clib_spinlock_unlock (&bp->lock); |
| 667 | } |
| 668 | } |
| 669 | |
| 670 | static_always_inline void |
| 671 | vlib_buffer_free_inline (vlib_main_t * vm, u32 * buffers, u32 n_buffers, |
| 672 | int maybe_next) |
| 673 | { |
| 674 | const int queue_size = 128; |
| 675 | vlib_buffer_pool_t *bp = 0; |
| 676 | u8 buffer_pool_index = ~0; |
| 677 | u32 n_queue = 0, queue[queue_size + 4]; |
| 678 | vlib_buffer_t bt = { }; |
| 679 | #if defined(CLIB_HAVE_VEC128) && !__aarch64__ |
| 680 | vlib_buffer_t bpi_mask = {.buffer_pool_index = ~0 }; |
| 681 | vlib_buffer_t bpi_vec = {.buffer_pool_index = ~0 }; |
| 682 | vlib_buffer_t flags_refs_mask = { |
| 683 | .flags = VLIB_BUFFER_NEXT_PRESENT, |
| 684 | .ref_count = ~0 |
| 685 | }; |
| 686 | #endif |
| 687 | |
| 688 | while (n_buffers) |
| 689 | { |
| 690 | vlib_buffer_t *b[8]; |
| 691 | u32 bi, sum = 0, flags, next; |
| 692 | |
| 693 | if (n_buffers < 12) |
| 694 | goto one_by_one; |
| 695 | |
| 696 | vlib_get_buffers (vm, buffers, b, 4); |
| 697 | vlib_get_buffers (vm, buffers + 8, b + 4, 4); |
| 698 | |
| 699 | vlib_prefetch_buffer_header (b[4], LOAD); |
| 700 | vlib_prefetch_buffer_header (b[5], LOAD); |
| 701 | vlib_prefetch_buffer_header (b[6], LOAD); |
| 702 | vlib_prefetch_buffer_header (b[7], LOAD); |
| 703 | |
| 704 | #if defined(CLIB_HAVE_VEC128) && !__aarch64__ |
| 705 | u8x16 p0, p1, p2, p3, r; |
| 706 | p0 = u8x16_load_unaligned (b[0]); |
| 707 | p1 = u8x16_load_unaligned (b[1]); |
| 708 | p2 = u8x16_load_unaligned (b[2]); |
| 709 | p3 = u8x16_load_unaligned (b[3]); |
| 710 | |
| 711 | r = p0 ^ bpi_vec.as_u8x16[0]; |
| 712 | r |= p1 ^ bpi_vec.as_u8x16[0]; |
| 713 | r |= p2 ^ bpi_vec.as_u8x16[0]; |
| 714 | r |= p3 ^ bpi_vec.as_u8x16[0]; |
| 715 | r &= bpi_mask.as_u8x16[0]; |
| 716 | r |= (p0 | p1 | p2 | p3) & flags_refs_mask.as_u8x16[0]; |
| 717 | |
| 718 | sum = !u8x16_is_all_zero (r); |
| 719 | #else |
| 720 | sum |= b[0]->flags; |
| 721 | sum |= b[1]->flags; |
| 722 | sum |= b[2]->flags; |
| 723 | sum |= b[3]->flags; |
| 724 | sum &= VLIB_BUFFER_NEXT_PRESENT; |
| 725 | sum += b[0]->ref_count - 1; |
| 726 | sum += b[1]->ref_count - 1; |
| 727 | sum += b[2]->ref_count - 1; |
| 728 | sum += b[3]->ref_count - 1; |
| 729 | sum |= b[0]->buffer_pool_index ^ buffer_pool_index; |
| 730 | sum |= b[1]->buffer_pool_index ^ buffer_pool_index; |
| 731 | sum |= b[2]->buffer_pool_index ^ buffer_pool_index; |
| 732 | sum |= b[3]->buffer_pool_index ^ buffer_pool_index; |
| 733 | #endif |
| 734 | |
| 735 | if (sum) |
| 736 | goto one_by_one; |
| 737 | |
| 738 | vlib_buffer_copy_indices (queue + n_queue, buffers, 4); |
| 739 | vlib_buffer_copy_template (b[0], &bt); |
| 740 | vlib_buffer_copy_template (b[1], &bt); |
| 741 | vlib_buffer_copy_template (b[2], &bt); |
| 742 | vlib_buffer_copy_template (b[3], &bt); |
| 743 | n_queue += 4; |
| 744 | |
Damjan Marion | 24dcbe4 | 2019-01-31 12:29:39 +0100 | [diff] [blame] | 745 | vlib_buffer_validate (vm, b[0]); |
| 746 | vlib_buffer_validate (vm, b[1]); |
| 747 | vlib_buffer_validate (vm, b[2]); |
| 748 | vlib_buffer_validate (vm, b[3]); |
| 749 | |
Damjan Marion | 910d369 | 2019-01-21 11:48:34 +0100 | [diff] [blame] | 750 | VLIB_BUFFER_TRACE_TRAJECTORY_INIT (b[0]); |
| 751 | VLIB_BUFFER_TRACE_TRAJECTORY_INIT (b[1]); |
| 752 | VLIB_BUFFER_TRACE_TRAJECTORY_INIT (b[2]); |
| 753 | VLIB_BUFFER_TRACE_TRAJECTORY_INIT (b[3]); |
| 754 | |
| 755 | if (n_queue >= queue_size) |
| 756 | { |
| 757 | vlib_buffer_pool_put (vm, buffer_pool_index, queue, n_queue); |
| 758 | n_queue = 0; |
| 759 | } |
| 760 | buffers += 4; |
| 761 | n_buffers -= 4; |
| 762 | continue; |
| 763 | |
| 764 | one_by_one: |
| 765 | bi = buffers[0]; |
| 766 | |
| 767 | next_in_chain: |
| 768 | b[0] = vlib_get_buffer (vm, bi); |
| 769 | flags = b[0]->flags; |
| 770 | next = b[0]->next_buffer; |
| 771 | |
| 772 | if (PREDICT_FALSE (buffer_pool_index != b[0]->buffer_pool_index)) |
| 773 | { |
Damjan Marion | 910d369 | 2019-01-21 11:48:34 +0100 | [diff] [blame] | 774 | |
| 775 | if (n_queue) |
| 776 | { |
| 777 | vlib_buffer_pool_put (vm, buffer_pool_index, queue, n_queue); |
| 778 | n_queue = 0; |
| 779 | } |
Lollita Liu | 8f6c1dd | 2019-02-14 05:02:44 -0500 | [diff] [blame] | 780 | |
| 781 | buffer_pool_index = b[0]->buffer_pool_index; |
| 782 | #if defined(CLIB_HAVE_VEC128) && !__aarch64__ |
| 783 | bpi_vec.buffer_pool_index = buffer_pool_index; |
| 784 | #endif |
| 785 | bp = vlib_get_buffer_pool (vm, buffer_pool_index); |
| 786 | vlib_buffer_copy_template (&bt, &bp->buffer_template); |
Damjan Marion | 910d369 | 2019-01-21 11:48:34 +0100 | [diff] [blame] | 787 | } |
| 788 | |
Damjan Marion | 24dcbe4 | 2019-01-31 12:29:39 +0100 | [diff] [blame] | 789 | vlib_buffer_validate (vm, b[0]); |
Damjan Marion | 910d369 | 2019-01-21 11:48:34 +0100 | [diff] [blame] | 790 | |
| 791 | VLIB_BUFFER_TRACE_TRAJECTORY_INIT (b[0]); |
| 792 | |
| 793 | if (clib_atomic_sub_fetch (&b[0]->ref_count, 1) == 0) |
| 794 | { |
Damjan Marion | 910d369 | 2019-01-21 11:48:34 +0100 | [diff] [blame] | 795 | vlib_buffer_copy_template (b[0], &bt); |
| 796 | queue[n_queue++] = bi; |
| 797 | } |
| 798 | |
| 799 | if (n_queue == queue_size) |
| 800 | { |
| 801 | vlib_buffer_pool_put (vm, buffer_pool_index, queue, queue_size); |
| 802 | n_queue = 0; |
| 803 | } |
| 804 | |
| 805 | if (flags & VLIB_BUFFER_NEXT_PRESENT) |
| 806 | { |
| 807 | bi = next; |
| 808 | goto next_in_chain; |
| 809 | } |
| 810 | |
| 811 | buffers++; |
| 812 | n_buffers--; |
| 813 | } |
| 814 | |
| 815 | if (n_queue) |
| 816 | vlib_buffer_pool_put (vm, buffer_pool_index, queue, n_queue); |
| 817 | } |
| 818 | |
| 819 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 820 | /** \brief Free buffers |
| 821 | Frees the entire buffer chain for each buffer |
| 822 | |
| 823 | @param vm - (vlib_main_t *) vlib main data structure pointer |
| 824 | @param buffers - (u32 * ) buffer index array |
| 825 | @param n_buffers - (u32) number of buffers to free |
| 826 | |
| 827 | */ |
Damjan Marion | 878c609 | 2017-01-04 13:19:27 +0100 | [diff] [blame] | 828 | always_inline void |
| 829 | vlib_buffer_free (vlib_main_t * vm, |
| 830 | /* pointer to first buffer */ |
| 831 | u32 * buffers, |
| 832 | /* number of buffers to free */ |
| 833 | u32 n_buffers) |
| 834 | { |
Damjan Marion | 910d369 | 2019-01-21 11:48:34 +0100 | [diff] [blame] | 835 | vlib_buffer_free_inline (vm, buffers, n_buffers, /* maybe next */ 1); |
Damjan Marion | 878c609 | 2017-01-04 13:19:27 +0100 | [diff] [blame] | 836 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 837 | |
| 838 | /** \brief Free buffers, does not free the buffer chain for each buffer |
| 839 | |
| 840 | @param vm - (vlib_main_t *) vlib main data structure pointer |
| 841 | @param buffers - (u32 * ) buffer index array |
| 842 | @param n_buffers - (u32) number of buffers to free |
| 843 | |
| 844 | */ |
Damjan Marion | 878c609 | 2017-01-04 13:19:27 +0100 | [diff] [blame] | 845 | always_inline void |
| 846 | vlib_buffer_free_no_next (vlib_main_t * vm, |
| 847 | /* pointer to first buffer */ |
| 848 | u32 * buffers, |
| 849 | /* number of buffers to free */ |
| 850 | u32 n_buffers) |
| 851 | { |
Damjan Marion | 910d369 | 2019-01-21 11:48:34 +0100 | [diff] [blame] | 852 | vlib_buffer_free_inline (vm, buffers, n_buffers, /* maybe next */ 0); |
Damjan Marion | 878c609 | 2017-01-04 13:19:27 +0100 | [diff] [blame] | 853 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 854 | |
| 855 | /** \brief Free one buffer |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 856 | Shorthand to free a single buffer chain. |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 857 | |
| 858 | @param vm - (vlib_main_t *) vlib main data structure pointer |
| 859 | @param buffer_index - (u32) buffer index to free |
| 860 | */ |
| 861 | always_inline void |
| 862 | vlib_buffer_free_one (vlib_main_t * vm, u32 buffer_index) |
| 863 | { |
Damjan Marion | 910d369 | 2019-01-21 11:48:34 +0100 | [diff] [blame] | 864 | vlib_buffer_free_inline (vm, &buffer_index, 1, /* maybe next */ 1); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 865 | } |
| 866 | |
Damjan Marion | a373149 | 2018-02-25 22:50:39 +0100 | [diff] [blame] | 867 | /** \brief Free buffers from ring |
| 868 | |
| 869 | @param vm - (vlib_main_t *) vlib main data structure pointer |
| 870 | @param buffers - (u32 * ) buffer index ring |
| 871 | @param start - (u32) first slot in the ring |
| 872 | @param ring_size - (u32) ring size |
| 873 | @param n_buffers - (u32) number of buffers |
| 874 | */ |
| 875 | always_inline void |
| 876 | vlib_buffer_free_from_ring (vlib_main_t * vm, u32 * ring, u32 start, |
| 877 | u32 ring_size, u32 n_buffers) |
| 878 | { |
| 879 | ASSERT (n_buffers <= ring_size); |
| 880 | |
| 881 | if (PREDICT_TRUE (start + n_buffers <= ring_size)) |
| 882 | { |
| 883 | vlib_buffer_free (vm, ring + start, n_buffers); |
| 884 | } |
| 885 | else |
| 886 | { |
| 887 | vlib_buffer_free (vm, ring + start, ring_size - start); |
| 888 | vlib_buffer_free (vm, ring, n_buffers - (ring_size - start)); |
| 889 | } |
| 890 | } |
| 891 | |
Damjan Marion | cef1db9 | 2018-03-28 18:27:38 +0200 | [diff] [blame] | 892 | /** \brief Free buffers from ring without freeing tail buffers |
| 893 | |
| 894 | @param vm - (vlib_main_t *) vlib main data structure pointer |
| 895 | @param buffers - (u32 * ) buffer index ring |
| 896 | @param start - (u32) first slot in the ring |
| 897 | @param ring_size - (u32) ring size |
| 898 | @param n_buffers - (u32) number of buffers |
| 899 | */ |
| 900 | always_inline void |
| 901 | vlib_buffer_free_from_ring_no_next (vlib_main_t * vm, u32 * ring, u32 start, |
| 902 | u32 ring_size, u32 n_buffers) |
| 903 | { |
| 904 | ASSERT (n_buffers <= ring_size); |
| 905 | |
| 906 | if (PREDICT_TRUE (start + n_buffers <= ring_size)) |
| 907 | { |
Damjan Marion | 4a97393 | 2018-06-09 19:29:16 +0200 | [diff] [blame] | 908 | vlib_buffer_free_no_next (vm, ring + start, n_buffers); |
Damjan Marion | cef1db9 | 2018-03-28 18:27:38 +0200 | [diff] [blame] | 909 | } |
| 910 | else |
| 911 | { |
| 912 | vlib_buffer_free_no_next (vm, ring + start, ring_size - start); |
| 913 | vlib_buffer_free_no_next (vm, ring, n_buffers - (ring_size - start)); |
| 914 | } |
| 915 | } |
Damjan Marion | a373149 | 2018-02-25 22:50:39 +0100 | [diff] [blame] | 916 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 917 | /* Append given data to end of buffer, possibly allocating new buffers. */ |
Damjan Marion | ab9b7ec | 2019-01-18 20:24:44 +0100 | [diff] [blame] | 918 | int vlib_buffer_add_data (vlib_main_t * vm, u32 * buffer_index, void *data, |
| 919 | u32 n_data_bytes); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 920 | |
Damjan Marion | 05ab8cb | 2016-11-03 20:16:04 +0100 | [diff] [blame] | 921 | /* duplicate all buffers in chain */ |
| 922 | always_inline vlib_buffer_t * |
| 923 | vlib_buffer_copy (vlib_main_t * vm, vlib_buffer_t * b) |
| 924 | { |
| 925 | vlib_buffer_t *s, *d, *fd; |
| 926 | uword n_alloc, n_buffers = 1; |
Damjan Marion | 6765549 | 2016-11-15 12:50:28 +0100 | [diff] [blame] | 927 | u32 flag_mask = VLIB_BUFFER_NEXT_PRESENT | VLIB_BUFFER_TOTAL_LENGTH_VALID; |
Damjan Marion | 05ab8cb | 2016-11-03 20:16:04 +0100 | [diff] [blame] | 928 | int i; |
| 929 | |
| 930 | s = b; |
| 931 | while (s->flags & VLIB_BUFFER_NEXT_PRESENT) |
| 932 | { |
| 933 | n_buffers++; |
| 934 | s = vlib_get_buffer (vm, s->next_buffer); |
| 935 | } |
Neale Ranns | 9d676af | 2017-03-15 01:28:31 -0700 | [diff] [blame] | 936 | u32 new_buffers[n_buffers]; |
Damjan Marion | 05ab8cb | 2016-11-03 20:16:04 +0100 | [diff] [blame] | 937 | |
Damjan Marion | 05ab8cb | 2016-11-03 20:16:04 +0100 | [diff] [blame] | 938 | n_alloc = vlib_buffer_alloc (vm, new_buffers, n_buffers); |
Dave Barach | 26cd8c1 | 2017-02-23 17:11:26 -0500 | [diff] [blame] | 939 | |
| 940 | /* No guarantee that we'll get all the buffers we asked for */ |
| 941 | if (PREDICT_FALSE (n_alloc < n_buffers)) |
| 942 | { |
| 943 | if (n_alloc > 0) |
| 944 | vlib_buffer_free (vm, new_buffers, n_alloc); |
Dave Barach | 26cd8c1 | 2017-02-23 17:11:26 -0500 | [diff] [blame] | 945 | return 0; |
| 946 | } |
Damjan Marion | 05ab8cb | 2016-11-03 20:16:04 +0100 | [diff] [blame] | 947 | |
| 948 | /* 1st segment */ |
| 949 | s = b; |
| 950 | fd = d = vlib_get_buffer (vm, new_buffers[0]); |
Damjan Marion | 05ab8cb | 2016-11-03 20:16:04 +0100 | [diff] [blame] | 951 | d->current_data = s->current_data; |
| 952 | d->current_length = s->current_length; |
Damjan Marion | 6765549 | 2016-11-15 12:50:28 +0100 | [diff] [blame] | 953 | d->flags = s->flags & flag_mask; |
Damjan Marion | 05ab8cb | 2016-11-03 20:16:04 +0100 | [diff] [blame] | 954 | d->total_length_not_including_first_buffer = |
| 955 | s->total_length_not_including_first_buffer; |
Dave Barach | 178cf49 | 2018-11-13 16:34:13 -0500 | [diff] [blame] | 956 | clib_memcpy_fast (d->opaque, s->opaque, sizeof (s->opaque)); |
| 957 | clib_memcpy_fast (d->opaque2, s->opaque2, sizeof (s->opaque2)); |
| 958 | clib_memcpy_fast (vlib_buffer_get_current (d), |
| 959 | vlib_buffer_get_current (s), s->current_length); |
Damjan Marion | 05ab8cb | 2016-11-03 20:16:04 +0100 | [diff] [blame] | 960 | |
| 961 | /* next segments */ |
| 962 | for (i = 1; i < n_buffers; i++) |
| 963 | { |
| 964 | /* previous */ |
| 965 | d->next_buffer = new_buffers[i]; |
| 966 | /* current */ |
| 967 | s = vlib_get_buffer (vm, s->next_buffer); |
| 968 | d = vlib_get_buffer (vm, new_buffers[i]); |
| 969 | d->current_data = s->current_data; |
| 970 | d->current_length = s->current_length; |
Dave Barach | 178cf49 | 2018-11-13 16:34:13 -0500 | [diff] [blame] | 971 | clib_memcpy_fast (vlib_buffer_get_current (d), |
| 972 | vlib_buffer_get_current (s), s->current_length); |
Damjan Marion | 6765549 | 2016-11-15 12:50:28 +0100 | [diff] [blame] | 973 | d->flags = s->flags & flag_mask; |
Damjan Marion | 05ab8cb | 2016-11-03 20:16:04 +0100 | [diff] [blame] | 974 | } |
| 975 | |
| 976 | return fd; |
| 977 | } |
| 978 | |
Neale Ranns | 8f36e4a | 2018-01-11 09:02:01 -0800 | [diff] [blame] | 979 | /** \brief Create a maximum of 256 clones of buffer and store them |
| 980 | in the supplied array |
Damjan Marion | c47ed03 | 2017-01-25 14:18:03 +0100 | [diff] [blame] | 981 | |
| 982 | @param vm - (vlib_main_t *) vlib main data structure pointer |
| 983 | @param src_buffer - (u32) source buffer index |
| 984 | @param buffers - (u32 * ) buffer index array |
Neale Ranns | 8f36e4a | 2018-01-11 09:02:01 -0800 | [diff] [blame] | 985 | @param n_buffers - (u16) number of buffer clones requested (<=256) |
Damjan Marion | c47ed03 | 2017-01-25 14:18:03 +0100 | [diff] [blame] | 986 | @param head_end_offset - (u16) offset relative to current position |
| 987 | where packet head ends |
Neale Ranns | 8f36e4a | 2018-01-11 09:02:01 -0800 | [diff] [blame] | 988 | @return - (u16) number of buffers actually cloned, may be |
Damjan Marion | c47ed03 | 2017-01-25 14:18:03 +0100 | [diff] [blame] | 989 | less than the number requested or zero |
| 990 | */ |
Neale Ranns | 8f36e4a | 2018-01-11 09:02:01 -0800 | [diff] [blame] | 991 | always_inline u16 |
| 992 | vlib_buffer_clone_256 (vlib_main_t * vm, u32 src_buffer, u32 * buffers, |
| 993 | u16 n_buffers, u16 head_end_offset) |
Damjan Marion | c47ed03 | 2017-01-25 14:18:03 +0100 | [diff] [blame] | 994 | { |
Neale Ranns | 8f36e4a | 2018-01-11 09:02:01 -0800 | [diff] [blame] | 995 | u16 i; |
Damjan Marion | c47ed03 | 2017-01-25 14:18:03 +0100 | [diff] [blame] | 996 | vlib_buffer_t *s = vlib_get_buffer (vm, src_buffer); |
| 997 | |
Damjan Marion | 910d369 | 2019-01-21 11:48:34 +0100 | [diff] [blame] | 998 | ASSERT (s->ref_count == 1); |
Damjan Marion | c47ed03 | 2017-01-25 14:18:03 +0100 | [diff] [blame] | 999 | ASSERT (n_buffers); |
Neale Ranns | 8f36e4a | 2018-01-11 09:02:01 -0800 | [diff] [blame] | 1000 | ASSERT (n_buffers <= 256); |
Damjan Marion | c47ed03 | 2017-01-25 14:18:03 +0100 | [diff] [blame] | 1001 | |
| 1002 | if (s->current_length <= head_end_offset + CLIB_CACHE_LINE_BYTES * 2) |
| 1003 | { |
| 1004 | buffers[0] = src_buffer; |
| 1005 | for (i = 1; i < n_buffers; i++) |
| 1006 | { |
| 1007 | vlib_buffer_t *d; |
| 1008 | d = vlib_buffer_copy (vm, s); |
| 1009 | if (d == 0) |
| 1010 | return i; |
| 1011 | buffers[i] = vlib_get_buffer_index (vm, d); |
| 1012 | |
| 1013 | } |
| 1014 | return n_buffers; |
| 1015 | } |
| 1016 | |
Neale Ranns | 8f36e4a | 2018-01-11 09:02:01 -0800 | [diff] [blame] | 1017 | if (PREDICT_FALSE (n_buffers == 1)) |
Damjan Marion | c47ed03 | 2017-01-25 14:18:03 +0100 | [diff] [blame] | 1018 | { |
| 1019 | buffers[0] = src_buffer; |
| 1020 | return 1; |
| 1021 | } |
| 1022 | |
Damjan Marion | 910d369 | 2019-01-21 11:48:34 +0100 | [diff] [blame] | 1023 | n_buffers = vlib_buffer_alloc_from_pool (vm, buffers, n_buffers, |
| 1024 | s->buffer_pool_index); |
Neale Ranns | 8f36e4a | 2018-01-11 09:02:01 -0800 | [diff] [blame] | 1025 | |
Damjan Marion | c47ed03 | 2017-01-25 14:18:03 +0100 | [diff] [blame] | 1026 | for (i = 0; i < n_buffers; i++) |
| 1027 | { |
| 1028 | vlib_buffer_t *d = vlib_get_buffer (vm, buffers[i]); |
| 1029 | d->current_data = s->current_data; |
| 1030 | d->current_length = head_end_offset; |
Damjan Marion | 910d369 | 2019-01-21 11:48:34 +0100 | [diff] [blame] | 1031 | ASSERT (d->buffer_pool_index == s->buffer_pool_index); |
| 1032 | |
Yoann Desmouceaux | 1977a34 | 2018-05-29 13:38:44 +0200 | [diff] [blame] | 1033 | d->total_length_not_including_first_buffer = s->current_length - |
Damjan Marion | c47ed03 | 2017-01-25 14:18:03 +0100 | [diff] [blame] | 1034 | head_end_offset; |
Yoann Desmouceaux | 1977a34 | 2018-05-29 13:38:44 +0200 | [diff] [blame] | 1035 | if (PREDICT_FALSE (s->flags & VLIB_BUFFER_NEXT_PRESENT)) |
| 1036 | { |
| 1037 | d->total_length_not_including_first_buffer += |
| 1038 | s->total_length_not_including_first_buffer; |
| 1039 | } |
Damjan Marion | c47ed03 | 2017-01-25 14:18:03 +0100 | [diff] [blame] | 1040 | d->flags = s->flags | VLIB_BUFFER_NEXT_PRESENT; |
| 1041 | d->flags &= ~VLIB_BUFFER_EXT_HDR_VALID; |
Dave Barach | 178cf49 | 2018-11-13 16:34:13 -0500 | [diff] [blame] | 1042 | clib_memcpy_fast (d->opaque, s->opaque, sizeof (s->opaque)); |
| 1043 | clib_memcpy_fast (d->opaque2, s->opaque2, sizeof (s->opaque2)); |
| 1044 | clib_memcpy_fast (vlib_buffer_get_current (d), |
| 1045 | vlib_buffer_get_current (s), head_end_offset); |
Damjan Marion | c47ed03 | 2017-01-25 14:18:03 +0100 | [diff] [blame] | 1046 | d->next_buffer = src_buffer; |
| 1047 | } |
| 1048 | vlib_buffer_advance (s, head_end_offset); |
Damjan Marion | 910d369 | 2019-01-21 11:48:34 +0100 | [diff] [blame] | 1049 | s->ref_count = n_buffers; |
Damjan Marion | c47ed03 | 2017-01-25 14:18:03 +0100 | [diff] [blame] | 1050 | while (s->flags & VLIB_BUFFER_NEXT_PRESENT) |
| 1051 | { |
| 1052 | s = vlib_get_buffer (vm, s->next_buffer); |
Damjan Marion | 910d369 | 2019-01-21 11:48:34 +0100 | [diff] [blame] | 1053 | s->ref_count = n_buffers; |
Damjan Marion | c47ed03 | 2017-01-25 14:18:03 +0100 | [diff] [blame] | 1054 | } |
| 1055 | |
| 1056 | return n_buffers; |
| 1057 | } |
| 1058 | |
Neale Ranns | 8f36e4a | 2018-01-11 09:02:01 -0800 | [diff] [blame] | 1059 | /** \brief Create multiple clones of buffer and store them |
| 1060 | in the supplied array |
| 1061 | |
| 1062 | @param vm - (vlib_main_t *) vlib main data structure pointer |
| 1063 | @param src_buffer - (u32) source buffer index |
| 1064 | @param buffers - (u32 * ) buffer index array |
| 1065 | @param n_buffers - (u16) number of buffer clones requested (<=256) |
| 1066 | @param head_end_offset - (u16) offset relative to current position |
| 1067 | where packet head ends |
| 1068 | @return - (u16) number of buffers actually cloned, may be |
| 1069 | less than the number requested or zero |
| 1070 | */ |
| 1071 | always_inline u16 |
| 1072 | vlib_buffer_clone (vlib_main_t * vm, u32 src_buffer, u32 * buffers, |
| 1073 | u16 n_buffers, u16 head_end_offset) |
| 1074 | { |
| 1075 | vlib_buffer_t *s = vlib_get_buffer (vm, src_buffer); |
| 1076 | u16 n_cloned = 0; |
| 1077 | |
| 1078 | while (n_buffers > 256) |
| 1079 | { |
| 1080 | vlib_buffer_t *copy; |
| 1081 | copy = vlib_buffer_copy (vm, s); |
| 1082 | n_cloned += vlib_buffer_clone_256 (vm, |
| 1083 | vlib_get_buffer_index (vm, copy), |
| 1084 | (buffers + n_cloned), |
| 1085 | 256, head_end_offset); |
| 1086 | n_buffers -= 256; |
| 1087 | } |
| 1088 | n_cloned += vlib_buffer_clone_256 (vm, src_buffer, |
| 1089 | buffers + n_cloned, |
| 1090 | n_buffers, head_end_offset); |
| 1091 | |
| 1092 | return n_cloned; |
| 1093 | } |
| 1094 | |
Damjan Marion | c47ed03 | 2017-01-25 14:18:03 +0100 | [diff] [blame] | 1095 | /** \brief Attach cloned tail to the buffer |
| 1096 | |
| 1097 | @param vm - (vlib_main_t *) vlib main data structure pointer |
| 1098 | @param head - (vlib_buffer_t *) head buffer |
| 1099 | @param tail - (Vlib buffer_t *) tail buffer to clone and attach to head |
| 1100 | */ |
| 1101 | |
| 1102 | always_inline void |
| 1103 | vlib_buffer_attach_clone (vlib_main_t * vm, vlib_buffer_t * head, |
| 1104 | vlib_buffer_t * tail) |
| 1105 | { |
| 1106 | ASSERT ((head->flags & VLIB_BUFFER_NEXT_PRESENT) == 0); |
Damjan Marion | 910d369 | 2019-01-21 11:48:34 +0100 | [diff] [blame] | 1107 | ASSERT (head->buffer_pool_index == tail->buffer_pool_index); |
Damjan Marion | c47ed03 | 2017-01-25 14:18:03 +0100 | [diff] [blame] | 1108 | |
| 1109 | head->flags |= VLIB_BUFFER_NEXT_PRESENT; |
| 1110 | head->flags &= ~VLIB_BUFFER_TOTAL_LENGTH_VALID; |
| 1111 | head->flags &= ~VLIB_BUFFER_EXT_HDR_VALID; |
| 1112 | head->flags |= (tail->flags & VLIB_BUFFER_TOTAL_LENGTH_VALID); |
| 1113 | head->next_buffer = vlib_get_buffer_index (vm, tail); |
| 1114 | head->total_length_not_including_first_buffer = tail->current_length + |
| 1115 | tail->total_length_not_including_first_buffer; |
| 1116 | |
| 1117 | next_segment: |
Damjan Marion | 910d369 | 2019-01-21 11:48:34 +0100 | [diff] [blame] | 1118 | clib_atomic_add_fetch (&tail->ref_count, 1); |
Damjan Marion | c47ed03 | 2017-01-25 14:18:03 +0100 | [diff] [blame] | 1119 | |
| 1120 | if (tail->flags & VLIB_BUFFER_NEXT_PRESENT) |
| 1121 | { |
| 1122 | tail = vlib_get_buffer (vm, tail->next_buffer); |
| 1123 | goto next_segment; |
| 1124 | } |
| 1125 | } |
| 1126 | |
Pierre Pfister | 328e99b | 2016-02-12 13:18:42 +0000 | [diff] [blame] | 1127 | /* Initializes the buffer as an empty packet with no chained buffers. */ |
| 1128 | always_inline void |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 1129 | vlib_buffer_chain_init (vlib_buffer_t * first) |
Pierre Pfister | 328e99b | 2016-02-12 13:18:42 +0000 | [diff] [blame] | 1130 | { |
| 1131 | first->total_length_not_including_first_buffer = 0; |
| 1132 | first->current_length = 0; |
| 1133 | first->flags &= ~VLIB_BUFFER_NEXT_PRESENT; |
| 1134 | first->flags |= VLIB_BUFFER_TOTAL_LENGTH_VALID; |
Pierre Pfister | 328e99b | 2016-02-12 13:18:42 +0000 | [diff] [blame] | 1135 | } |
| 1136 | |
| 1137 | /* The provided next_bi buffer index is appended to the end of the packet. */ |
| 1138 | always_inline vlib_buffer_t * |
Eyal Bari | b688fb1 | 2018-11-12 16:13:49 +0200 | [diff] [blame] | 1139 | vlib_buffer_chain_buffer (vlib_main_t * vm, vlib_buffer_t * last, u32 next_bi) |
Pierre Pfister | 328e99b | 2016-02-12 13:18:42 +0000 | [diff] [blame] | 1140 | { |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 1141 | vlib_buffer_t *next_buffer = vlib_get_buffer (vm, next_bi); |
Pierre Pfister | 328e99b | 2016-02-12 13:18:42 +0000 | [diff] [blame] | 1142 | last->next_buffer = next_bi; |
| 1143 | last->flags |= VLIB_BUFFER_NEXT_PRESENT; |
| 1144 | next_buffer->current_length = 0; |
| 1145 | next_buffer->flags &= ~VLIB_BUFFER_NEXT_PRESENT; |
Pierre Pfister | 328e99b | 2016-02-12 13:18:42 +0000 | [diff] [blame] | 1146 | return next_buffer; |
| 1147 | } |
| 1148 | |
| 1149 | /* Increases or decreases the packet length. |
| 1150 | * It does not allocate or deallocate new buffers. |
| 1151 | * Therefore, the added length must be compatible |
| 1152 | * with the last buffer. */ |
| 1153 | always_inline void |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 1154 | vlib_buffer_chain_increase_length (vlib_buffer_t * first, |
| 1155 | vlib_buffer_t * last, i32 len) |
Pierre Pfister | 328e99b | 2016-02-12 13:18:42 +0000 | [diff] [blame] | 1156 | { |
| 1157 | last->current_length += len; |
| 1158 | if (first != last) |
| 1159 | first->total_length_not_including_first_buffer += len; |
Pierre Pfister | 328e99b | 2016-02-12 13:18:42 +0000 | [diff] [blame] | 1160 | } |
| 1161 | |
| 1162 | /* Copy data to the end of the packet and increases its length. |
| 1163 | * It does not allocate new buffers. |
| 1164 | * Returns the number of copied bytes. */ |
| 1165 | always_inline u16 |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 1166 | vlib_buffer_chain_append_data (vlib_main_t * vm, |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 1167 | vlib_buffer_t * first, |
| 1168 | vlib_buffer_t * last, void *data, u16 data_len) |
Pierre Pfister | 328e99b | 2016-02-12 13:18:42 +0000 | [diff] [blame] | 1169 | { |
Damjan Marion | 8934a04 | 2019-02-09 23:29:26 +0100 | [diff] [blame] | 1170 | u32 n_buffer_bytes = vlib_buffer_get_default_data_size (vm); |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 1171 | ASSERT (n_buffer_bytes >= last->current_length + last->current_data); |
| 1172 | u16 len = clib_min (data_len, |
| 1173 | n_buffer_bytes - last->current_length - |
| 1174 | last->current_data); |
Dave Barach | 178cf49 | 2018-11-13 16:34:13 -0500 | [diff] [blame] | 1175 | clib_memcpy_fast (vlib_buffer_get_current (last) + last->current_length, |
| 1176 | data, len); |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 1177 | vlib_buffer_chain_increase_length (first, last, len); |
Pierre Pfister | 328e99b | 2016-02-12 13:18:42 +0000 | [diff] [blame] | 1178 | return len; |
| 1179 | } |
| 1180 | |
| 1181 | /* Copy data to the end of the packet and increases its length. |
| 1182 | * Allocates additional buffers from the free list if necessary. |
| 1183 | * Returns the number of copied bytes. |
| 1184 | * 'last' value is modified whenever new buffers are allocated and |
| 1185 | * chained and points to the last buffer in the chain. */ |
| 1186 | u16 |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 1187 | vlib_buffer_chain_append_data_with_alloc (vlib_main_t * vm, |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 1188 | vlib_buffer_t * first, |
Damjan Marion | dac0352 | 2018-02-01 15:30:13 +0100 | [diff] [blame] | 1189 | vlib_buffer_t ** last, void *data, |
| 1190 | u16 data_len); |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 1191 | void vlib_buffer_chain_validate (vlib_main_t * vm, vlib_buffer_t * first); |
Pierre Pfister | 328e99b | 2016-02-12 13:18:42 +0000 | [diff] [blame] | 1192 | |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 1193 | format_function_t format_vlib_buffer, format_vlib_buffer_and_data, |
| 1194 | format_vlib_buffer_contents; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1195 | |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 1196 | typedef struct |
| 1197 | { |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1198 | /* Vector of packet data. */ |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 1199 | u8 *packet_data; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1200 | |
Damjan Marion | d1274cb | 2018-03-13 21:32:17 +0100 | [diff] [blame] | 1201 | /* Number of buffers to allocate in each call to allocator. */ |
| 1202 | u32 min_n_buffers_each_alloc; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1203 | |
Damjan Marion | 671e60e | 2018-12-30 18:09:59 +0100 | [diff] [blame] | 1204 | u8 *name; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1205 | } vlib_packet_template_t; |
| 1206 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1207 | void vlib_packet_template_init (vlib_main_t * vm, |
| 1208 | vlib_packet_template_t * t, |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 1209 | void *packet_data, |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1210 | uword n_packet_data_bytes, |
Damjan Marion | d1274cb | 2018-03-13 21:32:17 +0100 | [diff] [blame] | 1211 | uword min_n_buffers_each_alloc, |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 1212 | char *fmt, ...); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1213 | |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 1214 | void *vlib_packet_template_get_packet (vlib_main_t * vm, |
| 1215 | vlib_packet_template_t * t, |
| 1216 | u32 * bi_result); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1217 | |
| 1218 | always_inline void |
| 1219 | vlib_packet_template_free (vlib_main_t * vm, vlib_packet_template_t * t) |
| 1220 | { |
| 1221 | vec_free (t->packet_data); |
| 1222 | } |
| 1223 | |
Klement Sekera | f883f6a | 2019-02-13 11:01:32 +0100 | [diff] [blame^] | 1224 | always_inline u32 |
| 1225 | vlib_buffer_space_left_at_end (vlib_main_t * vm, vlib_buffer_t * b) |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 1226 | { |
Klement Sekera | f883f6a | 2019-02-13 11:01:32 +0100 | [diff] [blame^] | 1227 | return b->data + vlib_buffer_get_default_data_size (vm) - |
| 1228 | ((u8 *) vlib_buffer_get_current (b) + b->current_length); |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 1229 | } |
| 1230 | |
Klement Sekera | f883f6a | 2019-02-13 11:01:32 +0100 | [diff] [blame^] | 1231 | always_inline u32 |
| 1232 | vlib_buffer_chain_linearize (vlib_main_t * vm, vlib_buffer_t * b) |
Eyal Bari | d3d4241 | 2018-11-05 13:29:25 +0200 | [diff] [blame] | 1233 | { |
Klement Sekera | f883f6a | 2019-02-13 11:01:32 +0100 | [diff] [blame^] | 1234 | vlib_buffer_t *db = b, *sb, *first = b; |
| 1235 | int is_cloned = 0; |
| 1236 | u32 bytes_left = 0, data_size; |
| 1237 | u16 src_left, dst_left, n_buffers = 1; |
| 1238 | u8 *dp, *sp; |
| 1239 | u32 to_free = 0; |
Eyal Bari | d3d4241 | 2018-11-05 13:29:25 +0200 | [diff] [blame] | 1240 | |
Klement Sekera | f883f6a | 2019-02-13 11:01:32 +0100 | [diff] [blame^] | 1241 | if (PREDICT_TRUE ((b->flags & VLIB_BUFFER_NEXT_PRESENT) == 0)) |
| 1242 | return 1; |
Eyal Bari | d3d4241 | 2018-11-05 13:29:25 +0200 | [diff] [blame] | 1243 | |
Klement Sekera | f883f6a | 2019-02-13 11:01:32 +0100 | [diff] [blame^] | 1244 | data_size = vlib_buffer_get_default_data_size (vm); |
| 1245 | |
| 1246 | dst_left = vlib_buffer_space_left_at_end (vm, b); |
| 1247 | |
| 1248 | while (b->flags & VLIB_BUFFER_NEXT_PRESENT) |
Eyal Bari | d3d4241 | 2018-11-05 13:29:25 +0200 | [diff] [blame] | 1249 | { |
Klement Sekera | f883f6a | 2019-02-13 11:01:32 +0100 | [diff] [blame^] | 1250 | b = vlib_get_buffer (vm, b->next_buffer); |
| 1251 | if (b->ref_count > 1) |
| 1252 | is_cloned = 1; |
| 1253 | bytes_left += b->current_length; |
| 1254 | n_buffers++; |
Eyal Bari | d3d4241 | 2018-11-05 13:29:25 +0200 | [diff] [blame] | 1255 | } |
| 1256 | |
Klement Sekera | f883f6a | 2019-02-13 11:01:32 +0100 | [diff] [blame^] | 1257 | /* if buffer is cloned, create completely new chain - unless everything fits |
| 1258 | * into one buffer */ |
| 1259 | if (is_cloned && bytes_left >= dst_left) |
Eyal Bari | d3d4241 | 2018-11-05 13:29:25 +0200 | [diff] [blame] | 1260 | { |
Klement Sekera | f883f6a | 2019-02-13 11:01:32 +0100 | [diff] [blame^] | 1261 | u32 len = 0; |
| 1262 | u32 space_needed = bytes_left - dst_left; |
| 1263 | u32 tail; |
| 1264 | |
| 1265 | if (vlib_buffer_alloc (vm, &tail, 1) == 0) |
| 1266 | return 0; |
| 1267 | |
| 1268 | ++n_buffers; |
| 1269 | len += data_size; |
| 1270 | b = vlib_get_buffer (vm, tail); |
| 1271 | |
| 1272 | while (len < space_needed) |
Eyal Bari | d3d4241 | 2018-11-05 13:29:25 +0200 | [diff] [blame] | 1273 | { |
Klement Sekera | f883f6a | 2019-02-13 11:01:32 +0100 | [diff] [blame^] | 1274 | u32 bi; |
| 1275 | if (vlib_buffer_alloc (vm, &bi, 1) == 0) |
| 1276 | { |
| 1277 | vlib_buffer_free_one (vm, tail); |
| 1278 | return 0; |
| 1279 | } |
| 1280 | b->flags = VLIB_BUFFER_NEXT_PRESENT; |
| 1281 | b->next_buffer = bi; |
| 1282 | b = vlib_get_buffer (vm, bi); |
| 1283 | len += data_size; |
| 1284 | n_buffers++; |
| 1285 | } |
| 1286 | sb = vlib_get_buffer (vm, first->next_buffer); |
| 1287 | to_free = first->next_buffer; |
| 1288 | first->next_buffer = tail; |
| 1289 | } |
| 1290 | else |
| 1291 | sb = vlib_get_buffer (vm, first->next_buffer); |
| 1292 | |
| 1293 | src_left = sb->current_length; |
| 1294 | sp = vlib_buffer_get_current (sb); |
| 1295 | dp = vlib_buffer_get_tail (db); |
| 1296 | |
| 1297 | while (bytes_left) |
| 1298 | { |
| 1299 | u16 bytes_to_copy; |
| 1300 | |
| 1301 | if (dst_left == 0) |
| 1302 | { |
| 1303 | if (db != first) |
| 1304 | db->current_data = 0; |
| 1305 | db->current_length = dp - (u8 *) vlib_buffer_get_current (db); |
| 1306 | ASSERT (db->flags & VLIB_BUFFER_NEXT_PRESENT); |
| 1307 | db = vlib_get_buffer (vm, db->next_buffer); |
| 1308 | dst_left = data_size; |
| 1309 | dp = db->data; |
| 1310 | } |
| 1311 | |
| 1312 | while (src_left == 0) |
| 1313 | { |
| 1314 | ASSERT (sb->flags & VLIB_BUFFER_NEXT_PRESENT); |
| 1315 | sb = vlib_get_buffer (vm, sb->next_buffer); |
| 1316 | src_left = sb->current_length; |
| 1317 | sp = vlib_buffer_get_current (sb); |
| 1318 | } |
| 1319 | |
| 1320 | bytes_to_copy = clib_min (dst_left, src_left); |
| 1321 | |
| 1322 | if (dp != sp) |
| 1323 | { |
| 1324 | if (sb == db) |
| 1325 | bytes_to_copy = clib_min (bytes_to_copy, sp - dp); |
| 1326 | |
| 1327 | clib_memcpy_fast (dp, sp, bytes_to_copy); |
| 1328 | } |
| 1329 | |
| 1330 | src_left -= bytes_to_copy; |
| 1331 | dst_left -= bytes_to_copy; |
| 1332 | dp += bytes_to_copy; |
| 1333 | sp += bytes_to_copy; |
| 1334 | bytes_left -= bytes_to_copy; |
| 1335 | } |
| 1336 | if (db != first) |
| 1337 | db->current_data = 0; |
| 1338 | db->current_length = dp - (u8 *) vlib_buffer_get_current (db); |
| 1339 | |
| 1340 | if (is_cloned && to_free) |
| 1341 | vlib_buffer_free_one (vm, to_free); |
| 1342 | else |
| 1343 | { |
| 1344 | if (db->flags & VLIB_BUFFER_NEXT_PRESENT) |
| 1345 | vlib_buffer_free_one (vm, db->next_buffer); |
| 1346 | db->flags &= ~VLIB_BUFFER_NEXT_PRESENT; |
| 1347 | b = first; |
| 1348 | n_buffers = 1; |
| 1349 | while (b->flags & VLIB_BUFFER_NEXT_PRESENT) |
| 1350 | { |
| 1351 | b = vlib_get_buffer (vm, b->next_buffer); |
| 1352 | ++n_buffers; |
Eyal Bari | d3d4241 | 2018-11-05 13:29:25 +0200 | [diff] [blame] | 1353 | } |
| 1354 | } |
Klement Sekera | f883f6a | 2019-02-13 11:01:32 +0100 | [diff] [blame^] | 1355 | |
| 1356 | first->flags &= ~VLIB_BUFFER_TOTAL_LENGTH_VALID; |
| 1357 | |
| 1358 | return n_buffers; |
Eyal Bari | d3d4241 | 2018-11-05 13:29:25 +0200 | [diff] [blame] | 1359 | } |
| 1360 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1361 | #endif /* included_vlib_buffer_funcs_h */ |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 1362 | |
| 1363 | /* |
| 1364 | * fd.io coding-style-patch-verification: ON |
| 1365 | * |
| 1366 | * Local Variables: |
| 1367 | * eval: (c-set-style "gnu") |
| 1368 | * End: |
| 1369 | */ |