Damjan Marion | bd846cd | 2017-11-21 13:12:41 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2017 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 | #include <vlib/vlib.h> |
| 17 | #include <vnet/buffer.h> |
| 18 | |
Mohsin Kazmi | 6809538 | 2021-02-10 11:26:24 +0100 | [diff] [blame] | 19 | u8 * |
| 20 | format_vnet_buffer_offload (u8 *s, va_list *args) |
| 21 | { |
| 22 | vlib_buffer_t *b = va_arg (*args, vlib_buffer_t *); |
| 23 | |
| 24 | #define _(bit, name, ss, v) \ |
Mohsin Kazmi | a7e830e | 2021-04-23 15:16:50 +0200 | [diff] [blame] | 25 | if (v && (vnet_buffer (b)->oflags & VNET_BUFFER_OFFLOAD_F_##name)) \ |
Mohsin Kazmi | 6809538 | 2021-02-10 11:26:24 +0100 | [diff] [blame] | 26 | s = format (s, "%s ", ss); |
| 27 | foreach_vnet_buffer_offload_flag |
| 28 | #undef _ |
Mohsin Kazmi | 537e955 | 2021-06-17 14:33:03 +0200 | [diff] [blame] | 29 | |
| 30 | if (vnet_buffer (b)->oflags & VNET_BUFFER_OFFLOAD_F_TNL_MASK) |
| 31 | { |
| 32 | s = format (s, "outer-l3-hdr-offset %d ", |
| 33 | vnet_buffer2 (b)->outer_l3_hdr_offset); |
| 34 | s = format (s, "outer-l4-hdr-offset %d ", |
| 35 | vnet_buffer2 (b)->outer_l4_hdr_offset); |
| 36 | } |
Mohsin Kazmi | 6809538 | 2021-02-10 11:26:24 +0100 | [diff] [blame] | 37 | return s; |
| 38 | } |
Damjan Marion | bd846cd | 2017-11-21 13:12:41 +0100 | [diff] [blame] | 39 | |
Benoît Ganne | 03f2a01 | 2021-07-20 16:49:13 +0200 | [diff] [blame] | 40 | static u8 * |
| 41 | format_vnet_buffer_internal (u8 *s, vlib_buffer_t *b, int no_chain) |
Damjan Marion | bd846cd | 2017-11-21 13:12:41 +0100 | [diff] [blame] | 42 | { |
Damjan Marion | bd846cd | 2017-11-21 13:12:41 +0100 | [diff] [blame] | 43 | u32 indent = format_get_indent (s); |
| 44 | u8 *a = 0; |
| 45 | |
Dave Barach | 7fff3d2 | 2018-11-27 16:52:59 -0500 | [diff] [blame] | 46 | #define _(bit,name,ss,v) \ |
Damjan Marion | bd846cd | 2017-11-21 13:12:41 +0100 | [diff] [blame] | 47 | if (v && (b->flags & VNET_BUFFER_F_##name)) \ |
Dave Barach | 7fff3d2 | 2018-11-27 16:52:59 -0500 | [diff] [blame] | 48 | a = format (a, "%s ", ss); |
Damjan Marion | dac0352 | 2018-02-01 15:30:13 +0100 | [diff] [blame] | 49 | foreach_vnet_buffer_flag |
Damjan Marion | bd846cd | 2017-11-21 13:12:41 +0100 | [diff] [blame] | 50 | #undef _ |
Mohsin Kazmi | 6809538 | 2021-02-10 11:26:24 +0100 | [diff] [blame] | 51 | if (b->flags & VNET_BUFFER_F_OFFLOAD) a = |
| 52 | format (a, "%U ", format_vnet_buffer_offload, b); |
| 53 | |
| 54 | if (b->flags & VNET_BUFFER_F_L2_HDR_OFFSET_VALID) |
Damjan Marion | bd846cd | 2017-11-21 13:12:41 +0100 | [diff] [blame] | 55 | a = format (a, "l2-hdr-offset %d ", vnet_buffer (b)->l2_hdr_offset); |
| 56 | |
| 57 | if (b->flags & VNET_BUFFER_F_L3_HDR_OFFSET_VALID) |
Steven | 0b26bd7 | 2017-12-01 06:58:56 -0800 | [diff] [blame] | 58 | a = format (a, "l3-hdr-offset %d ", vnet_buffer (b)->l3_hdr_offset); |
Damjan Marion | bd846cd | 2017-11-21 13:12:41 +0100 | [diff] [blame] | 59 | |
| 60 | if (b->flags & VNET_BUFFER_F_L4_HDR_OFFSET_VALID) |
| 61 | a = format (a, "l4-hdr-offset %d ", vnet_buffer (b)->l4_hdr_offset); |
| 62 | |
Mohsin Kazmi | 6809538 | 2021-02-10 11:26:24 +0100 | [diff] [blame] | 63 | if (b->flags & VNET_BUFFER_F_GSO) |
Mohsin Kazmi | 537e955 | 2021-06-17 14:33:03 +0200 | [diff] [blame] | 64 | a = format (a, "gso l4-hdr-len %d gso-size %d", |
| 65 | vnet_buffer2 (b)->gso_l4_hdr_sz, vnet_buffer2 (b)->gso_size); |
Mohsin Kazmi | 6809538 | 2021-02-10 11:26:24 +0100 | [diff] [blame] | 66 | |
Neale Ranns | 039cbfe | 2018-02-27 03:45:38 -0800 | [diff] [blame] | 67 | if (b->flags & VNET_BUFFER_F_QOS_DATA_VALID) |
| 68 | a = format (a, "qos %d.%d ", |
| 69 | vnet_buffer2 (b)->qos.bits, vnet_buffer2 (b)->qos.source); |
| 70 | |
Neale Ranns | ce9e0b4 | 2018-08-01 12:53:17 -0700 | [diff] [blame] | 71 | if (b->flags & VNET_BUFFER_F_LOOP_COUNTER_VALID) |
| 72 | a = format (a, "loop-counter %d ", vnet_buffer2 (b)->loop_counter); |
| 73 | |
Benoît Ganne | 03f2a01 | 2021-07-20 16:49:13 +0200 | [diff] [blame] | 74 | s = format (s, "%U", |
| 75 | no_chain ? format_vlib_buffer_no_chain : format_vlib_buffer, b); |
Damjan Marion | bd846cd | 2017-11-21 13:12:41 +0100 | [diff] [blame] | 76 | if (a) |
| 77 | s = format (s, "\n%U%v", format_white_space, indent, a); |
| 78 | vec_free (a); |
| 79 | |
| 80 | return s; |
| 81 | } |
| 82 | |
Benoît Ganne | 03f2a01 | 2021-07-20 16:49:13 +0200 | [diff] [blame] | 83 | u8 * |
| 84 | format_vnet_buffer_no_chain (u8 *s, va_list *args) |
| 85 | { |
| 86 | vlib_buffer_t *b = va_arg (*args, vlib_buffer_t *); |
| 87 | return format_vnet_buffer_internal (s, b, 1 /* no_chain */); |
| 88 | } |
| 89 | |
| 90 | u8 * |
| 91 | format_vnet_buffer (u8 *s, va_list *args) |
| 92 | { |
| 93 | vlib_buffer_t *b = va_arg (*args, vlib_buffer_t *); |
| 94 | return format_vnet_buffer_internal (s, b, 0 /* no_chain */); |
| 95 | } |
Damjan Marion | bd846cd | 2017-11-21 13:12:41 +0100 | [diff] [blame] | 96 | |
| 97 | /* |
| 98 | * fd.io coding-style-patch-verification: ON |
| 99 | * |
| 100 | * Local Variables: |
| 101 | * eval: (c-set-style "gnu") |
| 102 | * End: |
| 103 | */ |