Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 1 | /* |
| 2 | * mpls_output.c: MPLS Adj rewrite |
| 3 | * |
| 4 | * Copyright (c) 2012-2014 Cisco and/or its affiliates. |
| 5 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | * you may not use this file except in compliance with the License. |
| 7 | * You may obtain a copy of the License at: |
| 8 | * |
| 9 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | * |
| 11 | * Unless required by applicable law or agreed to in writing, software |
| 12 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | * See the License for the specific language governing permissions and |
| 15 | * limitations under the License. |
| 16 | */ |
| 17 | |
| 18 | #include <vlib/vlib.h> |
Neale Ranns | 1357f3b | 2016-10-16 12:01:42 -0700 | [diff] [blame] | 19 | #include <vnet/ip/ip.h> |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 20 | #include <vnet/mpls/mpls.h> |
Rajesh Goel | d6f1c9c | 2019-10-06 13:17:36 +0530 | [diff] [blame] | 21 | #include <vnet/ip/ip_frag.h> |
Neale Ranns | 4a58e49 | 2020-12-21 13:19:10 +0000 | [diff] [blame] | 22 | #include <vnet/adj/adj_dp.h> |
Neale Ranns | 41a85c0 | 2022-08-09 01:24:41 +0000 | [diff] [blame] | 23 | #include <vnet/mpls/mpls.api_enum.h> |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 24 | |
| 25 | typedef struct { |
| 26 | /* Adjacency taken. */ |
| 27 | u32 adj_index; |
| 28 | u32 flow_hash; |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 29 | } mpls_output_trace_t; |
| 30 | |
Rajesh Goel | d6f1c9c | 2019-10-06 13:17:36 +0530 | [diff] [blame] | 31 | typedef enum { |
| 32 | MPLS_OUTPUT_MODE, |
| 33 | MPLS_OUTPUT_MIDCHAIN_MODE |
| 34 | }mpls_output_mode_t; |
| 35 | |
Neale Ranns | 696e88d | 2017-03-16 07:34:55 -0400 | [diff] [blame] | 36 | #define foreach_mpls_output_next \ |
Rajesh Goel | d6f1c9c | 2019-10-06 13:17:36 +0530 | [diff] [blame] | 37 | _(DROP, "error-drop") \ |
Ole Troan | eb284a1 | 2019-10-09 13:33:19 +0200 | [diff] [blame] | 38 | _(FRAG, "mpls-frag") |
Neale Ranns | 696e88d | 2017-03-16 07:34:55 -0400 | [diff] [blame] | 39 | |
| 40 | typedef enum { |
| 41 | #define _(s,n) MPLS_OUTPUT_NEXT_##s, |
| 42 | foreach_mpls_output_next |
| 43 | #undef _ |
| 44 | MPLS_OUTPUT_N_NEXT, |
| 45 | } mpls_output_next_t; |
| 46 | |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 47 | static u8 * |
| 48 | format_mpls_output_trace (u8 * s, va_list * args) |
| 49 | { |
| 50 | CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *); |
| 51 | CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *); |
| 52 | mpls_output_trace_t * t = va_arg (*args, mpls_output_trace_t *); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 53 | |
| 54 | s = format (s, "adj-idx %d : %U flow hash: 0x%08x", |
| 55 | t->adj_index, |
Neale Ranns | b80c536 | 2016-10-08 13:03:40 +0100 | [diff] [blame] | 56 | format_ip_adjacency, t->adj_index, FORMAT_IP_ADJACENCY_NONE, |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 57 | t->flow_hash); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 58 | return s; |
| 59 | } |
| 60 | |
| 61 | static inline uword |
| 62 | mpls_output_inline (vlib_main_t * vm, |
| 63 | vlib_node_runtime_t * node, |
John Lo | aeb06f4 | 2016-10-15 17:45:35 -0400 | [diff] [blame] | 64 | vlib_frame_t * from_frame, |
Rajesh Goel | d6f1c9c | 2019-10-06 13:17:36 +0530 | [diff] [blame] | 65 | mpls_output_mode_t mode) |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 66 | { |
Damjan Marion | 586afd7 | 2017-04-05 19:18:20 +0200 | [diff] [blame] | 67 | u32 n_left_from, next_index, * from, * to_next, thread_index; |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 68 | vlib_node_runtime_t * error_node; |
Neale Ranns | 9ca18c6 | 2016-12-10 21:08:09 +0000 | [diff] [blame] | 69 | u32 n_left_to_next; |
Neale Ranns | b069a69 | 2017-03-15 12:34:25 -0400 | [diff] [blame] | 70 | mpls_main_t *mm; |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 71 | |
Damjan Marion | 586afd7 | 2017-04-05 19:18:20 +0200 | [diff] [blame] | 72 | thread_index = vlib_get_thread_index(); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 73 | error_node = vlib_node_get_runtime (vm, mpls_output_node.index); |
| 74 | from = vlib_frame_vector_args (from_frame); |
| 75 | n_left_from = from_frame->n_vectors; |
| 76 | next_index = node->cached_next_index; |
Neale Ranns | b069a69 | 2017-03-15 12:34:25 -0400 | [diff] [blame] | 77 | mm = &mpls_main; |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 78 | |
| 79 | while (n_left_from > 0) |
| 80 | { |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 81 | vlib_get_next_frame (vm, node, next_index, |
| 82 | to_next, n_left_to_next); |
| 83 | |
Neale Ranns | 9ca18c6 | 2016-12-10 21:08:09 +0000 | [diff] [blame] | 84 | while (n_left_from >= 4 && n_left_to_next >= 2) |
| 85 | { |
| 86 | ip_adjacency_t * adj0; |
| 87 | mpls_unicast_header_t *hdr0; |
| 88 | vlib_buffer_t * p0; |
Benoît Ganne | c257e07 | 2019-06-17 14:42:47 +0200 | [diff] [blame] | 89 | u32 pi0, adj_index0, next0, error0; |
| 90 | word rw_len0; |
Neale Ranns | 9ca18c6 | 2016-12-10 21:08:09 +0000 | [diff] [blame] | 91 | |
| 92 | ip_adjacency_t * adj1; |
| 93 | mpls_unicast_header_t *hdr1; |
| 94 | vlib_buffer_t * p1; |
Benoît Ganne | c257e07 | 2019-06-17 14:42:47 +0200 | [diff] [blame] | 95 | u32 pi1, adj_index1, next1, error1; |
| 96 | word rw_len1; |
Neale Ranns | 9ca18c6 | 2016-12-10 21:08:09 +0000 | [diff] [blame] | 97 | |
| 98 | /* Prefetch next iteration. */ |
| 99 | { |
| 100 | vlib_buffer_t * p2, * p3; |
| 101 | |
| 102 | p2 = vlib_get_buffer (vm, from[2]); |
| 103 | p3 = vlib_get_buffer (vm, from[3]); |
| 104 | |
| 105 | vlib_prefetch_buffer_header (p2, STORE); |
| 106 | vlib_prefetch_buffer_header (p3, STORE); |
| 107 | |
| 108 | CLIB_PREFETCH (p2->data, sizeof (hdr0[0]), STORE); |
| 109 | CLIB_PREFETCH (p3->data, sizeof (hdr1[0]), STORE); |
| 110 | } |
| 111 | |
| 112 | pi0 = to_next[0] = from[0]; |
| 113 | pi1 = to_next[1] = from[1]; |
| 114 | |
| 115 | from += 2; |
| 116 | n_left_from -= 2; |
| 117 | to_next += 2; |
| 118 | n_left_to_next -= 2; |
| 119 | |
| 120 | p0 = vlib_get_buffer (vm, pi0); |
| 121 | p1 = vlib_get_buffer (vm, pi1); |
| 122 | |
| 123 | adj_index0 = vnet_buffer (p0)->ip.adj_index[VLIB_TX]; |
| 124 | adj_index1 = vnet_buffer (p1)->ip.adj_index[VLIB_TX]; |
| 125 | |
Neale Ranns | 9ca18c6 | 2016-12-10 21:08:09 +0000 | [diff] [blame] | 126 | adj0 = adj_get(adj_index0); |
| 127 | adj1 = adj_get(adj_index1); |
| 128 | hdr0 = vlib_buffer_get_current (p0); |
| 129 | hdr1 = vlib_buffer_get_current (p1); |
| 130 | |
| 131 | /* Guess we are only writing on simple Ethernet header. */ |
| 132 | vnet_rewrite_two_headers (adj0[0], adj1[0], hdr0, hdr1, |
| 133 | sizeof (ethernet_header_t)); |
| 134 | |
| 135 | /* Update packet buffer attributes/set output interface. */ |
| 136 | rw_len0 = adj0[0].rewrite_header.data_bytes; |
| 137 | rw_len1 = adj1[0].rewrite_header.data_bytes; |
Neale Ranns | 039cbfe | 2018-02-27 03:45:38 -0800 | [diff] [blame] | 138 | vnet_buffer (p0)->mpls.save_rewrite_length = rw_len0; |
| 139 | vnet_buffer (p1)->mpls.save_rewrite_length = rw_len1; |
Neale Ranns | 9ca18c6 | 2016-12-10 21:08:09 +0000 | [diff] [blame] | 140 | |
Neale Ranns | 044183f | 2017-01-24 01:34:25 -0800 | [diff] [blame] | 141 | /* Bump the adj counters for packet and bytes */ |
| 142 | vlib_increment_combined_counter |
| 143 | (&adjacency_counters, |
Damjan Marion | 586afd7 | 2017-04-05 19:18:20 +0200 | [diff] [blame] | 144 | thread_index, |
Neale Ranns | 044183f | 2017-01-24 01:34:25 -0800 | [diff] [blame] | 145 | adj_index0, |
| 146 | 1, |
| 147 | vlib_buffer_length_in_chain (vm, p0) + rw_len0); |
| 148 | vlib_increment_combined_counter |
| 149 | (&adjacency_counters, |
Damjan Marion | 586afd7 | 2017-04-05 19:18:20 +0200 | [diff] [blame] | 150 | thread_index, |
Neale Ranns | 044183f | 2017-01-24 01:34:25 -0800 | [diff] [blame] | 151 | adj_index1, |
| 152 | 1, |
| 153 | vlib_buffer_length_in_chain (vm, p1) + rw_len1); |
Neale Ranns | 9ca18c6 | 2016-12-10 21:08:09 +0000 | [diff] [blame] | 154 | |
| 155 | /* Check MTU of outgoing interface. */ |
| 156 | if (PREDICT_TRUE(vlib_buffer_length_in_chain (vm, p0) <= |
| 157 | adj0[0].rewrite_header.max_l3_packet_bytes)) |
| 158 | { |
Zhiyong Yang | 734d430 | 2019-05-29 22:38:19 -0400 | [diff] [blame] | 159 | vlib_buffer_advance(p0, -rw_len0); |
Neale Ranns | 9ca18c6 | 2016-12-10 21:08:09 +0000 | [diff] [blame] | 160 | |
| 161 | vnet_buffer (p0)->sw_if_index[VLIB_TX] = |
| 162 | adj0[0].rewrite_header.sw_if_index; |
| 163 | next0 = adj0[0].rewrite_header.next_index; |
| 164 | error0 = IP4_ERROR_NONE; |
| 165 | |
Neale Ranns | b069a69 | 2017-03-15 12:34:25 -0400 | [diff] [blame] | 166 | if (PREDICT_FALSE(adj0[0].rewrite_header.flags & VNET_REWRITE_HAS_FEATURES)) |
| 167 | vnet_feature_arc_start (mm->output_feature_arc_index, |
| 168 | adj0[0].rewrite_header.sw_if_index, |
| 169 | &next0, p0); |
Neale Ranns | 9ca18c6 | 2016-12-10 21:08:09 +0000 | [diff] [blame] | 170 | } |
| 171 | else |
| 172 | { |
Rajesh Goel | d6f1c9c | 2019-10-06 13:17:36 +0530 | [diff] [blame] | 173 | error0 = IP4_ERROR_MTU_EXCEEDED; |
Ole Troan | eb284a1 | 2019-10-09 13:33:19 +0200 | [diff] [blame] | 174 | next0 = MPLS_OUTPUT_NEXT_FRAG; |
Rajesh Goel | d6f1c9c | 2019-10-06 13:17:36 +0530 | [diff] [blame] | 175 | vlib_node_increment_counter (vm, mpls_output_node.index, |
| 176 | MPLS_ERROR_PKTS_NEED_FRAG, |
| 177 | 1); |
Neale Ranns | 9ca18c6 | 2016-12-10 21:08:09 +0000 | [diff] [blame] | 178 | } |
| 179 | if (PREDICT_TRUE(vlib_buffer_length_in_chain (vm, p1) <= |
| 180 | adj1[0].rewrite_header.max_l3_packet_bytes)) |
| 181 | { |
Zhiyong Yang | 734d430 | 2019-05-29 22:38:19 -0400 | [diff] [blame] | 182 | vlib_buffer_advance(p1, -rw_len1); |
Neale Ranns | 9ca18c6 | 2016-12-10 21:08:09 +0000 | [diff] [blame] | 183 | |
| 184 | vnet_buffer (p1)->sw_if_index[VLIB_TX] = |
| 185 | adj1[0].rewrite_header.sw_if_index; |
| 186 | next1 = adj1[0].rewrite_header.next_index; |
| 187 | error1 = IP4_ERROR_NONE; |
| 188 | |
Neale Ranns | b069a69 | 2017-03-15 12:34:25 -0400 | [diff] [blame] | 189 | if (PREDICT_FALSE(adj1[0].rewrite_header.flags & VNET_REWRITE_HAS_FEATURES)) |
| 190 | vnet_feature_arc_start (mm->output_feature_arc_index, |
| 191 | adj1[0].rewrite_header.sw_if_index, |
| 192 | &next1, p1); |
Neale Ranns | 9ca18c6 | 2016-12-10 21:08:09 +0000 | [diff] [blame] | 193 | } |
| 194 | else |
| 195 | { |
Rajesh Goel | d6f1c9c | 2019-10-06 13:17:36 +0530 | [diff] [blame] | 196 | error1 = IP4_ERROR_MTU_EXCEEDED; |
Ole Troan | eb284a1 | 2019-10-09 13:33:19 +0200 | [diff] [blame] | 197 | next1 = MPLS_OUTPUT_NEXT_FRAG; |
Rajesh Goel | d6f1c9c | 2019-10-06 13:17:36 +0530 | [diff] [blame] | 198 | vlib_node_increment_counter (vm, mpls_output_node.index, |
| 199 | MPLS_ERROR_PKTS_NEED_FRAG, |
| 200 | 1); |
Neale Ranns | 9ca18c6 | 2016-12-10 21:08:09 +0000 | [diff] [blame] | 201 | } |
Rajesh Goel | d6f1c9c | 2019-10-06 13:17:36 +0530 | [diff] [blame] | 202 | if (mode == MPLS_OUTPUT_MIDCHAIN_MODE) |
Neale Ranns | b069a69 | 2017-03-15 12:34:25 -0400 | [diff] [blame] | 203 | { |
Neale Ranns | 4a58e49 | 2020-12-21 13:19:10 +0000 | [diff] [blame] | 204 | adj_midchain_fixup (vm, adj0, p0, VNET_LINK_MPLS); |
| 205 | adj_midchain_fixup (vm, adj1, p1, VNET_LINK_MPLS); |
| 206 | } |
Neale Ranns | 9ca18c6 | 2016-12-10 21:08:09 +0000 | [diff] [blame] | 207 | |
Neale Ranns | 4a58e49 | 2020-12-21 13:19:10 +0000 | [diff] [blame] | 208 | p0->error = error_node->errors[error0]; |
| 209 | p1->error = error_node->errors[error1]; |
Neale Ranns | 9ca18c6 | 2016-12-10 21:08:09 +0000 | [diff] [blame] | 210 | |
Neale Ranns | 4a58e49 | 2020-12-21 13:19:10 +0000 | [diff] [blame] | 211 | if (PREDICT_FALSE (p0->flags & VLIB_BUFFER_IS_TRACED)) |
| 212 | { |
| 213 | mpls_output_trace_t *tr = |
| 214 | vlib_add_trace (vm, node, p0, sizeof (*tr)); |
| 215 | tr->adj_index = vnet_buffer (p0)->ip.adj_index[VLIB_TX]; |
| 216 | tr->flow_hash = vnet_buffer (p0)->ip.flow_hash; |
| 217 | } |
| 218 | if (PREDICT_FALSE (p1->flags & VLIB_BUFFER_IS_TRACED)) |
| 219 | { |
| 220 | mpls_output_trace_t *tr = |
| 221 | vlib_add_trace (vm, node, p1, sizeof (*tr)); |
| 222 | tr->adj_index = vnet_buffer (p1)->ip.adj_index[VLIB_TX]; |
| 223 | tr->flow_hash = vnet_buffer (p1)->ip.flow_hash; |
| 224 | } |
Neale Ranns | 9ca18c6 | 2016-12-10 21:08:09 +0000 | [diff] [blame] | 225 | |
Neale Ranns | 4a58e49 | 2020-12-21 13:19:10 +0000 | [diff] [blame] | 226 | vlib_validate_buffer_enqueue_x2 (vm, node, next_index, to_next, |
| 227 | n_left_to_next, pi0, pi1, next0, |
| 228 | next1); |
| 229 | } |
Neale Ranns | 9ca18c6 | 2016-12-10 21:08:09 +0000 | [diff] [blame] | 230 | |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 231 | while (n_left_from > 0 && n_left_to_next > 0) |
| 232 | { |
| 233 | ip_adjacency_t * adj0; |
Rajesh Goel | d6f1c9c | 2019-10-06 13:17:36 +0530 | [diff] [blame] | 234 | mpls_unicast_header_t *hdr0; |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 235 | vlib_buffer_t * p0; |
Benoît Ganne | c257e07 | 2019-06-17 14:42:47 +0200 | [diff] [blame] | 236 | u32 pi0, adj_index0, next0, error0; |
| 237 | word rw_len0; |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 238 | |
| 239 | pi0 = to_next[0] = from[0]; |
| 240 | |
| 241 | p0 = vlib_get_buffer (vm, pi0); |
| 242 | |
| 243 | adj_index0 = vnet_buffer (p0)->ip.adj_index[VLIB_TX]; |
| 244 | |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 245 | adj0 = adj_get(adj_index0); |
Rajesh Goel | d6f1c9c | 2019-10-06 13:17:36 +0530 | [diff] [blame] | 246 | hdr0 = vlib_buffer_get_current (p0); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 247 | |
| 248 | /* Guess we are only writing on simple Ethernet header. */ |
Dave Barach | 9cbfb4c | 2020-04-08 10:19:29 -0400 | [diff] [blame] | 249 | vnet_rewrite_one_header (adj0[0], hdr0, |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 250 | sizeof (ethernet_header_t)); |
Dave Barach | 9cbfb4c | 2020-04-08 10:19:29 -0400 | [diff] [blame] | 251 | |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 252 | /* Update packet buffer attributes/set output interface. */ |
| 253 | rw_len0 = adj0[0].rewrite_header.data_bytes; |
Neale Ranns | 039cbfe | 2018-02-27 03:45:38 -0800 | [diff] [blame] | 254 | vnet_buffer (p0)->mpls.save_rewrite_length = rw_len0; |
| 255 | |
Neale Ranns | 044183f | 2017-01-24 01:34:25 -0800 | [diff] [blame] | 256 | vlib_increment_combined_counter |
| 257 | (&adjacency_counters, |
Damjan Marion | 586afd7 | 2017-04-05 19:18:20 +0200 | [diff] [blame] | 258 | thread_index, |
Neale Ranns | 044183f | 2017-01-24 01:34:25 -0800 | [diff] [blame] | 259 | adj_index0, |
| 260 | 1, |
| 261 | vlib_buffer_length_in_chain (vm, p0) + rw_len0); |
Zhiyong Yang | 734d430 | 2019-05-29 22:38:19 -0400 | [diff] [blame] | 262 | |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 263 | /* Check MTU of outgoing interface. */ |
Neale Ranns | 9ca18c6 | 2016-12-10 21:08:09 +0000 | [diff] [blame] | 264 | if (PREDICT_TRUE(vlib_buffer_length_in_chain (vm, p0) <= |
| 265 | adj0[0].rewrite_header.max_l3_packet_bytes)) |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 266 | { |
Zhiyong Yang | 734d430 | 2019-05-29 22:38:19 -0400 | [diff] [blame] | 267 | vlib_buffer_advance(p0, -rw_len0); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 268 | |
| 269 | vnet_buffer (p0)->sw_if_index[VLIB_TX] = |
| 270 | adj0[0].rewrite_header.sw_if_index; |
| 271 | next0 = adj0[0].rewrite_header.next_index; |
Neale Ranns | 9ca18c6 | 2016-12-10 21:08:09 +0000 | [diff] [blame] | 272 | error0 = IP4_ERROR_NONE; |
John Lo | aeb06f4 | 2016-10-15 17:45:35 -0400 | [diff] [blame] | 273 | |
Neale Ranns | b069a69 | 2017-03-15 12:34:25 -0400 | [diff] [blame] | 274 | if (PREDICT_FALSE(adj0[0].rewrite_header.flags & VNET_REWRITE_HAS_FEATURES)) |
| 275 | vnet_feature_arc_start (mm->output_feature_arc_index, |
| 276 | adj0[0].rewrite_header.sw_if_index, |
| 277 | &next0, p0); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 278 | } |
| 279 | else |
| 280 | { |
Rajesh Goel | d6f1c9c | 2019-10-06 13:17:36 +0530 | [diff] [blame] | 281 | error0 = IP4_ERROR_MTU_EXCEEDED; |
Ole Troan | eb284a1 | 2019-10-09 13:33:19 +0200 | [diff] [blame] | 282 | next0 = MPLS_OUTPUT_NEXT_FRAG; |
Rajesh Goel | d6f1c9c | 2019-10-06 13:17:36 +0530 | [diff] [blame] | 283 | vlib_node_increment_counter (vm, mpls_output_node.index, |
| 284 | MPLS_ERROR_PKTS_NEED_FRAG, |
| 285 | 1); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 286 | } |
Rajesh Goel | d6f1c9c | 2019-10-06 13:17:36 +0530 | [diff] [blame] | 287 | if (mode == MPLS_OUTPUT_MIDCHAIN_MODE) |
Neale Ranns | b069a69 | 2017-03-15 12:34:25 -0400 | [diff] [blame] | 288 | { |
Neale Ranns | 4a58e49 | 2020-12-21 13:19:10 +0000 | [diff] [blame] | 289 | adj_midchain_fixup (vm, adj0, p0, VNET_LINK_MPLS); |
| 290 | } |
Neale Ranns | b069a69 | 2017-03-15 12:34:25 -0400 | [diff] [blame] | 291 | |
Neale Ranns | 4a58e49 | 2020-12-21 13:19:10 +0000 | [diff] [blame] | 292 | p0->error = error_node->errors[error0]; |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 293 | |
| 294 | from += 1; |
| 295 | n_left_from -= 1; |
| 296 | to_next += 1; |
| 297 | n_left_to_next -= 1; |
Dave Barach | 9cbfb4c | 2020-04-08 10:19:29 -0400 | [diff] [blame] | 298 | |
| 299 | if (PREDICT_FALSE(p0->flags & VLIB_BUFFER_IS_TRACED)) |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 300 | { |
Dave Barach | 9cbfb4c | 2020-04-08 10:19:29 -0400 | [diff] [blame] | 301 | mpls_output_trace_t *tr = vlib_add_trace (vm, node, |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 302 | p0, sizeof (*tr)); |
| 303 | tr->adj_index = vnet_buffer(p0)->ip.adj_index[VLIB_TX]; |
| 304 | tr->flow_hash = vnet_buffer(p0)->ip.flow_hash; |
| 305 | } |
| 306 | |
| 307 | vlib_validate_buffer_enqueue_x1 (vm, node, next_index, |
| 308 | to_next, n_left_to_next, |
| 309 | pi0, next0); |
| 310 | } |
| 311 | |
| 312 | vlib_put_next_frame (vm, node, next_index, n_left_to_next); |
| 313 | } |
| 314 | vlib_node_increment_counter (vm, mpls_output_node.index, |
| 315 | MPLS_ERROR_PKTS_ENCAP, |
| 316 | from_frame->n_vectors); |
| 317 | |
| 318 | return from_frame->n_vectors; |
| 319 | } |
| 320 | |
Filip Tehlar | 17fcd98 | 2019-03-05 04:32:11 -0800 | [diff] [blame] | 321 | VLIB_NODE_FN (mpls_output_node) (vlib_main_t * vm, |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 322 | vlib_node_runtime_t * node, |
| 323 | vlib_frame_t * from_frame) |
| 324 | { |
Rajesh Goel | d6f1c9c | 2019-10-06 13:17:36 +0530 | [diff] [blame] | 325 | return (mpls_output_inline(vm, node, from_frame, MPLS_OUTPUT_MODE)); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 326 | } |
| 327 | |
| 328 | VLIB_REGISTER_NODE (mpls_output_node) = { |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 329 | .name = "mpls-output", |
| 330 | /* Takes a vector of packets. */ |
| 331 | .vector_size = sizeof (u32), |
| 332 | .n_errors = MPLS_N_ERROR, |
Neale Ranns | 41a85c0 | 2022-08-09 01:24:41 +0000 | [diff] [blame] | 333 | .error_counters = mpls_error_counters, |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 334 | |
| 335 | .n_next_nodes = MPLS_OUTPUT_N_NEXT, |
| 336 | .next_nodes = { |
Ole Troan | eb284a1 | 2019-10-09 13:33:19 +0200 | [diff] [blame] | 337 | [MPLS_OUTPUT_NEXT_DROP] = "mpls-drop", |
| 338 | [MPLS_OUTPUT_NEXT_FRAG] = "mpls-frag", |
| 339 | }, |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 340 | .format_trace = format_mpls_output_trace, |
| 341 | }; |
| 342 | |
Filip Tehlar | 17fcd98 | 2019-03-05 04:32:11 -0800 | [diff] [blame] | 343 | VLIB_NODE_FN (mpls_midchain_node) (vlib_main_t * vm, |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 344 | vlib_node_runtime_t * node, |
| 345 | vlib_frame_t * from_frame) |
| 346 | { |
Rajesh Goel | d6f1c9c | 2019-10-06 13:17:36 +0530 | [diff] [blame] | 347 | return (mpls_output_inline(vm, node, from_frame, MPLS_OUTPUT_MIDCHAIN_MODE)); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 348 | } |
| 349 | |
| 350 | VLIB_REGISTER_NODE (mpls_midchain_node) = { |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 351 | .name = "mpls-midchain", |
| 352 | .vector_size = sizeof (u32), |
| 353 | |
Ole Troan | eb284a1 | 2019-10-09 13:33:19 +0200 | [diff] [blame] | 354 | .n_errors = MPLS_N_ERROR, |
Neale Ranns | 41a85c0 | 2022-08-09 01:24:41 +0000 | [diff] [blame] | 355 | .error_counters = mpls_error_counters, |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 356 | |
| 357 | .sibling_of = "mpls-output", |
Ole Troan | eb284a1 | 2019-10-09 13:33:19 +0200 | [diff] [blame] | 358 | .format_trace = format_mpls_output_trace, |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 359 | }; |
| 360 | |
Ole Troan | eb284a1 | 2019-10-09 13:33:19 +0200 | [diff] [blame] | 361 | typedef struct mpls_frag_trace_t_ |
| 362 | { |
| 363 | u16 pkt_size; |
| 364 | u16 mtu; |
| 365 | } mpls_frag_trace_t; |
| 366 | |
| 367 | typedef enum |
| 368 | { |
Neale Ranns | ec5371e | 2022-03-04 11:45:41 +0000 | [diff] [blame] | 369 | MPLS_FRAG_NEXT_REWRITE, |
| 370 | MPLS_FRAG_NEXT_REWRITE_MIDCHAIN, |
| 371 | MPLS_FRAG_NEXT_ICMP4_ERROR, |
| 372 | MPLS_FRAG_NEXT_ICMP6_ERROR, |
| 373 | MPLS_FRAG_NEXT_DROP, |
| 374 | MPLS_FRAG_N_NEXT, |
Ole Troan | eb284a1 | 2019-10-09 13:33:19 +0200 | [diff] [blame] | 375 | } mpls_frag_next_t; |
| 376 | |
| 377 | static uword |
| 378 | mpls_frag (vlib_main_t * vm, |
| 379 | vlib_node_runtime_t * node, |
| 380 | vlib_frame_t * frame) |
| 381 | { |
| 382 | u32 n_left_from, next_index, * from, * to_next, n_left_to_next, *frags; |
Ole Troan | eb284a1 | 2019-10-09 13:33:19 +0200 | [diff] [blame] | 383 | |
Ole Troan | eb284a1 | 2019-10-09 13:33:19 +0200 | [diff] [blame] | 384 | from = vlib_frame_vector_args (frame); |
| 385 | n_left_from = frame->n_vectors; |
| 386 | next_index = node->cached_next_index; |
| 387 | frags = NULL; |
| 388 | |
| 389 | while (n_left_from > 0) |
| 390 | { |
| 391 | vlib_get_next_frame (vm, node, next_index, |
| 392 | to_next, n_left_to_next); |
| 393 | |
| 394 | while (n_left_from > 0 && n_left_to_next > 0) |
| 395 | { |
| 396 | ip_adjacency_t * adj0; |
| 397 | vlib_buffer_t * p0; |
| 398 | mpls_frag_next_t next0; |
| 399 | u32 pi0, adj_index0; |
| 400 | ip_frag_error_t error0 = IP_FRAG_ERROR_NONE; |
Neale Ranns | ec5371e | 2022-03-04 11:45:41 +0000 | [diff] [blame] | 401 | i16 encap_size, mtu; |
Neale Ranns | c396d23 | 2022-02-24 10:30:12 +0000 | [diff] [blame] | 402 | u8 is_ip4; |
Ole Troan | eb284a1 | 2019-10-09 13:33:19 +0200 | [diff] [blame] | 403 | |
Neale Ranns | c396d23 | 2022-02-24 10:30:12 +0000 | [diff] [blame] | 404 | pi0 = to_next[0] = from[0]; |
| 405 | p0 = vlib_get_buffer (vm, pi0); |
| 406 | from += 1; |
| 407 | n_left_from -= 1; |
| 408 | is_ip4 = vnet_buffer (p0)->mpls.pyld_proto == DPO_PROTO_IP4; |
Ole Troan | eb284a1 | 2019-10-09 13:33:19 +0200 | [diff] [blame] | 409 | |
Neale Ranns | c396d23 | 2022-02-24 10:30:12 +0000 | [diff] [blame] | 410 | adj_index0 = vnet_buffer (p0)->ip.adj_index[VLIB_TX]; |
| 411 | adj0 = adj_get (adj_index0); |
Neale Ranns | ec5371e | 2022-03-04 11:45:41 +0000 | [diff] [blame] | 412 | |
Neale Ranns | c396d23 | 2022-02-24 10:30:12 +0000 | [diff] [blame] | 413 | /* the size of the MPLS stack */ |
| 414 | encap_size = vnet_buffer (p0)->l3_hdr_offset - p0->current_data; |
| 415 | mtu = adj0->rewrite_header.max_l3_packet_bytes - encap_size; |
Ole Troan | eb284a1 | 2019-10-09 13:33:19 +0200 | [diff] [blame] | 416 | |
Neale Ranns | c396d23 | 2022-02-24 10:30:12 +0000 | [diff] [blame] | 417 | /* IP fragmentation */ |
| 418 | if (is_ip4) |
| 419 | error0 = ip4_frag_do_fragment (vm, pi0, mtu, encap_size, &frags); |
| 420 | else |
Neale Ranns | ec5371e | 2022-03-04 11:45:41 +0000 | [diff] [blame] | 421 | { |
| 422 | if (!(p0->flags & VNET_BUFFER_F_LOCALLY_ORIGINATED)) |
| 423 | { |
| 424 | /* only fragment locally generated IPv6 */ |
| 425 | error0 = IP_FRAG_ERROR_DONT_FRAGMENT_SET; |
| 426 | } |
| 427 | else |
| 428 | { |
| 429 | error0 = |
| 430 | ip6_frag_do_fragment (vm, pi0, mtu, encap_size, &frags); |
| 431 | } |
| 432 | } |
Dave Barach | 9cbfb4c | 2020-04-08 10:19:29 -0400 | [diff] [blame] | 433 | |
Neale Ranns | c396d23 | 2022-02-24 10:30:12 +0000 | [diff] [blame] | 434 | if (PREDICT_FALSE (p0->flags & VLIB_BUFFER_IS_TRACED)) |
| 435 | { |
| 436 | mpls_frag_trace_t *tr = |
| 437 | vlib_add_trace (vm, node, p0, sizeof (*tr)); |
| 438 | tr->mtu = mtu; |
| 439 | tr->pkt_size = vlib_buffer_length_in_chain (vm, p0); |
| 440 | } |
Ole Troan | eb284a1 | 2019-10-09 13:33:19 +0200 | [diff] [blame] | 441 | |
Neale Ranns | c396d23 | 2022-02-24 10:30:12 +0000 | [diff] [blame] | 442 | if (PREDICT_TRUE (error0 == IP_FRAG_ERROR_NONE)) |
| 443 | { |
| 444 | /* Free original buffer chain */ |
Neale Ranns | ec5371e | 2022-03-04 11:45:41 +0000 | [diff] [blame] | 445 | vlib_buffer_free_one (vm, pi0); |
Neale Ranns | c396d23 | 2022-02-24 10:30:12 +0000 | [diff] [blame] | 446 | next0 = (IP_LOOKUP_NEXT_MIDCHAIN == adj0->lookup_next_index ? |
| 447 | MPLS_FRAG_NEXT_REWRITE_MIDCHAIN : |
| 448 | MPLS_FRAG_NEXT_REWRITE); |
| 449 | } |
Neale Ranns | c396d23 | 2022-02-24 10:30:12 +0000 | [diff] [blame] | 450 | else |
| 451 | { |
Neale Ranns | ec5371e | 2022-03-04 11:45:41 +0000 | [diff] [blame] | 452 | vlib_error_count (vm, node->node_index, error0, 1); |
| 453 | |
| 454 | if (error0 == IP_FRAG_ERROR_DONT_FRAGMENT_SET) |
| 455 | { |
| 456 | vlib_buffer_advance (p0, encap_size); |
| 457 | if (is_ip4) |
| 458 | { |
| 459 | icmp4_error_set_vnet_buffer ( |
| 460 | p0, ICMP4_destination_unreachable, |
| 461 | ICMP4_destination_unreachable_fragmentation_needed_and_dont_fragment_set, |
Neale Ranns | fbc633f | 2022-03-18 13:05:09 +0000 | [diff] [blame] | 462 | mtu); |
Neale Ranns | ec5371e | 2022-03-04 11:45:41 +0000 | [diff] [blame] | 463 | next0 = MPLS_FRAG_NEXT_ICMP4_ERROR; |
| 464 | } |
| 465 | else |
| 466 | { |
Neale Ranns | fbc633f | 2022-03-18 13:05:09 +0000 | [diff] [blame] | 467 | icmp6_error_set_vnet_buffer (p0, ICMP6_packet_too_big, |
| 468 | 0, mtu); |
Neale Ranns | ec5371e | 2022-03-04 11:45:41 +0000 | [diff] [blame] | 469 | next0 = MPLS_FRAG_NEXT_ICMP6_ERROR; |
| 470 | } |
| 471 | } |
| 472 | else |
| 473 | { |
| 474 | next0 = MPLS_FRAG_NEXT_DROP; |
| 475 | } |
| 476 | |
| 477 | /* Get rid of the original buffer */ |
| 478 | vec_add1 (frags, pi0); |
Neale Ranns | c396d23 | 2022-02-24 10:30:12 +0000 | [diff] [blame] | 479 | } |
Ole Troan | eb284a1 | 2019-10-09 13:33:19 +0200 | [diff] [blame] | 480 | |
Neale Ranns | c396d23 | 2022-02-24 10:30:12 +0000 | [diff] [blame] | 481 | /* Send fragments that were added in the frame */ |
| 482 | u32 *frag_from, frag_left; |
Ole Troan | eb284a1 | 2019-10-09 13:33:19 +0200 | [diff] [blame] | 483 | |
Neale Ranns | c396d23 | 2022-02-24 10:30:12 +0000 | [diff] [blame] | 484 | frag_from = frags; |
| 485 | frag_left = vec_len (frags); |
Ole Troan | eb284a1 | 2019-10-09 13:33:19 +0200 | [diff] [blame] | 486 | |
Neale Ranns | c396d23 | 2022-02-24 10:30:12 +0000 | [diff] [blame] | 487 | while (frag_left > 0) |
| 488 | { |
| 489 | while (frag_left > 0 && n_left_to_next > 0) |
| 490 | { |
| 491 | u32 i; |
| 492 | i = to_next[0] = frag_from[0]; |
| 493 | frag_from += 1; |
| 494 | frag_left -= 1; |
| 495 | to_next += 1; |
| 496 | n_left_to_next -= 1; |
Ole Troan | eb284a1 | 2019-10-09 13:33:19 +0200 | [diff] [blame] | 497 | |
Neale Ranns | c396d23 | 2022-02-24 10:30:12 +0000 | [diff] [blame] | 498 | vlib_validate_buffer_enqueue_x1 ( |
| 499 | vm, node, next_index, to_next, n_left_to_next, i, next0); |
| 500 | } |
| 501 | vlib_put_next_frame (vm, node, next_index, n_left_to_next); |
| 502 | vlib_get_next_frame (vm, node, next_index, to_next, |
| 503 | n_left_to_next); |
| 504 | } |
| 505 | vec_reset_length (frags); |
Ole Troan | eb284a1 | 2019-10-09 13:33:19 +0200 | [diff] [blame] | 506 | } |
| 507 | vlib_put_next_frame (vm, node, next_index, n_left_to_next); |
| 508 | } |
| 509 | vec_free (frags); |
| 510 | |
| 511 | return frame->n_vectors; |
| 512 | } |
| 513 | |
| 514 | static u8 * |
| 515 | format_mpls_frag_trace (u8 * s, va_list * args) |
| 516 | { |
| 517 | CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *); |
| 518 | CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *); |
| 519 | mpls_frag_trace_t *t = va_arg (*args, mpls_frag_trace_t *); |
| 520 | |
| 521 | s = format (s, "mtu:%d pkt-size:%d", t->mtu, t->pkt_size); |
| 522 | return s; |
| 523 | } |
| 524 | |
| 525 | VLIB_REGISTER_NODE (mpls_frag_node) = { |
Neale Ranns | ec5371e | 2022-03-04 11:45:41 +0000 | [diff] [blame] | 526 | .function = mpls_frag, |
| 527 | .name = "mpls-frag", |
| 528 | .vector_size = sizeof (u32), |
| 529 | .format_trace = format_mpls_frag_trace, |
| 530 | .type = VLIB_NODE_TYPE_INTERNAL, |
Ole Troan | eb284a1 | 2019-10-09 13:33:19 +0200 | [diff] [blame] | 531 | |
Neale Ranns | ec5371e | 2022-03-04 11:45:41 +0000 | [diff] [blame] | 532 | .n_errors = IP_FRAG_N_ERROR, |
Neale Ranns | e22a704 | 2022-08-09 03:03:29 +0000 | [diff] [blame] | 533 | .error_counters = ip_frag_error_counters, |
Ole Troan | eb284a1 | 2019-10-09 13:33:19 +0200 | [diff] [blame] | 534 | |
Neale Ranns | ec5371e | 2022-03-04 11:45:41 +0000 | [diff] [blame] | 535 | .n_next_nodes = MPLS_FRAG_N_NEXT, |
| 536 | .next_nodes = { [MPLS_FRAG_NEXT_REWRITE] = "mpls-output", |
| 537 | [MPLS_FRAG_NEXT_REWRITE_MIDCHAIN] = "mpls-midchain", |
| 538 | [MPLS_FRAG_NEXT_ICMP4_ERROR] = "ip4-icmp-error", |
| 539 | [MPLS_FRAG_NEXT_ICMP6_ERROR] = "ip6-icmp-error", |
| 540 | [MPLS_FRAG_NEXT_DROP] = "mpls-drop" }, |
Ole Troan | eb284a1 | 2019-10-09 13:33:19 +0200 | [diff] [blame] | 541 | }; |
| 542 | |
| 543 | /* |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 544 | * @brief Next index values from the MPLS incomplete adj node |
| 545 | */ |
| 546 | #define foreach_mpls_adj_incomplete_next \ |
| 547 | _(DROP, "error-drop") \ |
| 548 | _(IP4, "ip4-arp") \ |
| 549 | _(IP6, "ip6-discover-neighbor") |
| 550 | |
| 551 | typedef enum { |
| 552 | #define _(s,n) MPLS_ADJ_INCOMPLETE_NEXT_##s, |
| 553 | foreach_mpls_adj_incomplete_next |
| 554 | #undef _ |
| 555 | MPLS_ADJ_INCOMPLETE_N_NEXT, |
| 556 | } mpls_adj_incomplete_next_t; |
| 557 | |
| 558 | /** |
| 559 | * @brief A struct to hold tracing information for the MPLS label imposition |
| 560 | * node. |
| 561 | */ |
| 562 | typedef struct mpls_adj_incomplete_trace_t_ |
| 563 | { |
| 564 | u32 next; |
| 565 | } mpls_adj_incomplete_trace_t; |
| 566 | |
| 567 | |
| 568 | /** |
| 569 | * @brief Graph node for incomplete MPLS adjacency. |
| 570 | * This node will push traffic to either the v4-arp or v6-nd node |
| 571 | * based on the next-hop proto of the adj. |
| 572 | * We pay a cost for this 'routing' node, but an incomplete adj is the |
| 573 | * exception case. |
| 574 | */ |
Filip Tehlar | 17fcd98 | 2019-03-05 04:32:11 -0800 | [diff] [blame] | 575 | VLIB_NODE_FN (mpls_adj_incomplete_node) (vlib_main_t * vm, |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 576 | vlib_node_runtime_t * node, |
| 577 | vlib_frame_t * from_frame) |
| 578 | { |
| 579 | u32 n_left_from, next_index, * from, * to_next; |
| 580 | |
| 581 | from = vlib_frame_vector_args (from_frame); |
| 582 | n_left_from = from_frame->n_vectors; |
| 583 | next_index = node->cached_next_index; |
| 584 | |
| 585 | while (n_left_from > 0) |
| 586 | { |
| 587 | u32 n_left_to_next; |
| 588 | |
| 589 | vlib_get_next_frame (vm, node, next_index, |
| 590 | to_next, n_left_to_next); |
| 591 | |
| 592 | while (n_left_from > 0 && n_left_to_next > 0) |
| 593 | { |
| 594 | u32 pi0, next0, adj_index0; |
| 595 | ip_adjacency_t * adj0; |
| 596 | vlib_buffer_t * p0; |
| 597 | |
| 598 | pi0 = to_next[0] = from[0]; |
| 599 | p0 = vlib_get_buffer (vm, pi0); |
| 600 | from += 1; |
| 601 | n_left_from -= 1; |
| 602 | to_next += 1; |
| 603 | n_left_to_next -= 1; |
| 604 | |
| 605 | adj_index0 = vnet_buffer (p0)->ip.adj_index[VLIB_TX]; |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 606 | |
| 607 | adj0 = adj_get(adj_index0); |
| 608 | |
| 609 | if (PREDICT_TRUE(FIB_PROTOCOL_IP4 == adj0->ia_nh_proto)) |
| 610 | { |
| 611 | next0 = MPLS_ADJ_INCOMPLETE_NEXT_IP4; |
| 612 | } |
| 613 | else |
| 614 | { |
| 615 | next0 = MPLS_ADJ_INCOMPLETE_NEXT_IP6; |
Dave Barach | 9cbfb4c | 2020-04-08 10:19:29 -0400 | [diff] [blame] | 616 | } |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 617 | |
Dave Barach | 9cbfb4c | 2020-04-08 10:19:29 -0400 | [diff] [blame] | 618 | if (PREDICT_FALSE(p0->flags & VLIB_BUFFER_IS_TRACED)) |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 619 | { |
| 620 | mpls_adj_incomplete_trace_t *tr = |
| 621 | vlib_add_trace (vm, node, p0, sizeof (*tr)); |
| 622 | tr->next = next0; |
| 623 | } |
| 624 | |
| 625 | vlib_validate_buffer_enqueue_x1 (vm, node, next_index, |
| 626 | to_next, n_left_to_next, |
| 627 | pi0, next0); |
| 628 | } |
| 629 | |
| 630 | vlib_put_next_frame (vm, node, next_index, n_left_to_next); |
| 631 | } |
| 632 | |
| 633 | return from_frame->n_vectors; |
| 634 | } |
| 635 | |
| 636 | static u8 * |
| 637 | format_mpls_adj_incomplete_trace (u8 * s, va_list * args) |
| 638 | { |
| 639 | CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *); |
| 640 | CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *); |
| 641 | mpls_adj_incomplete_trace_t * t; |
Christophe Fontaine | d3c008d | 2017-10-02 18:10:54 +0200 | [diff] [blame] | 642 | u32 indent; |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 643 | |
| 644 | t = va_arg (*args, mpls_adj_incomplete_trace_t *); |
| 645 | indent = format_get_indent (s); |
| 646 | |
| 647 | s = format (s, "%Unext:%d", |
| 648 | format_white_space, indent, |
| 649 | t->next); |
| 650 | return (s); |
| 651 | } |
| 652 | |
| 653 | VLIB_REGISTER_NODE (mpls_adj_incomplete_node) = { |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 654 | .name = "mpls-adj-incomplete", |
| 655 | .format_trace = format_mpls_adj_incomplete_trace, |
| 656 | /* Takes a vector of packets. */ |
| 657 | .vector_size = sizeof (u32), |
| 658 | .n_errors = MPLS_N_ERROR, |
Neale Ranns | 41a85c0 | 2022-08-09 01:24:41 +0000 | [diff] [blame] | 659 | .error_counters = mpls_error_counters, |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 660 | |
| 661 | .n_next_nodes = MPLS_ADJ_INCOMPLETE_N_NEXT, |
| 662 | .next_nodes = { |
| 663 | #define _(s,n) [MPLS_ADJ_INCOMPLETE_NEXT_##s] = n, |
| 664 | foreach_mpls_adj_incomplete_next |
| 665 | #undef _ |
| 666 | }, |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 667 | }; |