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