Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2016 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 | |
Neale Ranns | 4c7c8e5 | 2017-10-21 09:37:55 -0700 | [diff] [blame] | 16 | #include <vnet/ip/ip4_input.h> |
| 17 | #include <vnet/ip/ip6_input.h> |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 18 | #include <vnet/dpo/mpls_disposition.h> |
| 19 | #include <vnet/mpls/mpls.h> |
| 20 | |
Filip Tehlar | eb9a27f | 2019-03-07 01:42:11 -0800 | [diff] [blame^] | 21 | #ifndef CLIB_MARCH_VARIANT |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 22 | /* |
| 23 | * pool of all MPLS Label DPOs |
| 24 | */ |
| 25 | mpls_disp_dpo_t *mpls_disp_dpo_pool; |
| 26 | |
| 27 | static mpls_disp_dpo_t * |
| 28 | mpls_disp_dpo_alloc (void) |
| 29 | { |
| 30 | mpls_disp_dpo_t *mdd; |
| 31 | |
| 32 | pool_get_aligned(mpls_disp_dpo_pool, mdd, CLIB_CACHE_LINE_BYTES); |
Dave Barach | b7b9299 | 2018-10-17 10:38:51 -0400 | [diff] [blame] | 33 | clib_memset(mdd, 0, sizeof(*mdd)); |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 34 | |
| 35 | dpo_reset(&mdd->mdd_dpo); |
| 36 | |
| 37 | return (mdd); |
| 38 | } |
| 39 | |
| 40 | static index_t |
| 41 | mpls_disp_dpo_get_index (mpls_disp_dpo_t *mdd) |
| 42 | { |
| 43 | return (mdd - mpls_disp_dpo_pool); |
| 44 | } |
| 45 | |
Neale Ranns | 31ed744 | 2018-02-23 05:29:09 -0800 | [diff] [blame] | 46 | void |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 47 | mpls_disp_dpo_create (dpo_proto_t payload_proto, |
| 48 | fib_rpf_id_t rpf_id, |
Neale Ranns | 31ed744 | 2018-02-23 05:29:09 -0800 | [diff] [blame] | 49 | fib_mpls_lsp_mode_t mode, |
| 50 | const dpo_id_t *parent, |
| 51 | dpo_id_t *dpo) |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 52 | { |
| 53 | mpls_disp_dpo_t *mdd; |
Neale Ranns | 31ed744 | 2018-02-23 05:29:09 -0800 | [diff] [blame] | 54 | dpo_type_t dtype; |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 55 | |
| 56 | mdd = mpls_disp_dpo_alloc(); |
| 57 | |
| 58 | mdd->mdd_payload_proto = payload_proto; |
| 59 | mdd->mdd_rpf_id = rpf_id; |
Neale Ranns | 31ed744 | 2018-02-23 05:29:09 -0800 | [diff] [blame] | 60 | mdd->mdd_mode = mode; |
| 61 | dtype = (FIB_MPLS_LSP_MODE_PIPE == mode ? |
| 62 | DPO_MPLS_DISPOSITION_PIPE : |
| 63 | DPO_MPLS_DISPOSITION_UNIFORM); |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 64 | |
Neale Ranns | 31ed744 | 2018-02-23 05:29:09 -0800 | [diff] [blame] | 65 | /* |
| 66 | * stack this disposition object on the parent given |
| 67 | */ |
| 68 | dpo_stack(dtype, |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 69 | mdd->mdd_payload_proto, |
| 70 | &mdd->mdd_dpo, |
Neale Ranns | 31ed744 | 2018-02-23 05:29:09 -0800 | [diff] [blame] | 71 | parent); |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 72 | |
Neale Ranns | 31ed744 | 2018-02-23 05:29:09 -0800 | [diff] [blame] | 73 | /* |
| 74 | * set up the return DPO to refer to this object |
| 75 | */ |
| 76 | dpo_set(dpo, |
| 77 | dtype, |
| 78 | payload_proto, |
| 79 | mpls_disp_dpo_get_index(mdd)); |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 80 | } |
| 81 | |
| 82 | u8* |
| 83 | format_mpls_disp_dpo (u8 *s, va_list *args) |
| 84 | { |
Neale Ranns | 31ed744 | 2018-02-23 05:29:09 -0800 | [diff] [blame] | 85 | index_t index = va_arg(*args, index_t); |
| 86 | u32 indent = va_arg(*args, u32); |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 87 | mpls_disp_dpo_t *mdd; |
| 88 | |
| 89 | mdd = mpls_disp_dpo_get(index); |
| 90 | |
Neale Ranns | 31ed744 | 2018-02-23 05:29:09 -0800 | [diff] [blame] | 91 | s = format(s, "mpls-disposition:[%d]:[%U, %U]", |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 92 | index, |
Neale Ranns | 31ed744 | 2018-02-23 05:29:09 -0800 | [diff] [blame] | 93 | format_dpo_proto, mdd->mdd_payload_proto, |
| 94 | format_fib_mpls_lsp_mode, mdd->mdd_mode); |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 95 | |
| 96 | s = format(s, "\n%U", format_white_space, indent); |
| 97 | s = format(s, "%U", format_dpo_id, &mdd->mdd_dpo, indent+2); |
| 98 | |
| 99 | return (s); |
| 100 | } |
| 101 | |
| 102 | static void |
| 103 | mpls_disp_dpo_lock (dpo_id_t *dpo) |
| 104 | { |
| 105 | mpls_disp_dpo_t *mdd; |
| 106 | |
| 107 | mdd = mpls_disp_dpo_get(dpo->dpoi_index); |
| 108 | |
| 109 | mdd->mdd_locks++; |
| 110 | } |
| 111 | |
| 112 | static void |
| 113 | mpls_disp_dpo_unlock (dpo_id_t *dpo) |
| 114 | { |
| 115 | mpls_disp_dpo_t *mdd; |
| 116 | |
| 117 | mdd = mpls_disp_dpo_get(dpo->dpoi_index); |
| 118 | |
| 119 | mdd->mdd_locks--; |
| 120 | |
| 121 | if (0 == mdd->mdd_locks) |
| 122 | { |
| 123 | dpo_reset(&mdd->mdd_dpo); |
| 124 | pool_put(mpls_disp_dpo_pool, mdd); |
| 125 | } |
| 126 | } |
Filip Tehlar | eb9a27f | 2019-03-07 01:42:11 -0800 | [diff] [blame^] | 127 | #endif /* CLIB_MARCH_VARIANT */ |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 128 | |
| 129 | /** |
| 130 | * @brief A struct to hold tracing information for the MPLS label disposition |
| 131 | * node. |
| 132 | */ |
| 133 | typedef struct mpls_label_disposition_trace_t_ |
| 134 | { |
| 135 | index_t mdd; |
| 136 | } mpls_label_disposition_trace_t; |
| 137 | |
Neale Ranns | 31ed744 | 2018-02-23 05:29:09 -0800 | [diff] [blame] | 138 | extern vlib_node_registration_t ip4_mpls_label_disposition_pipe_node; |
| 139 | extern vlib_node_registration_t ip6_mpls_label_disposition_pipe_node; |
| 140 | extern vlib_node_registration_t ip4_mpls_label_disposition_uniform_node; |
| 141 | extern vlib_node_registration_t ip6_mpls_label_disposition_uniform_node; |
Neale Ranns | 4c7c8e5 | 2017-10-21 09:37:55 -0700 | [diff] [blame] | 142 | |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 143 | always_inline uword |
| 144 | mpls_label_disposition_inline (vlib_main_t * vm, |
Neale Ranns | 31ed744 | 2018-02-23 05:29:09 -0800 | [diff] [blame] | 145 | vlib_node_runtime_t * node, |
| 146 | vlib_frame_t * from_frame, |
| 147 | u8 payload_is_ip4, |
| 148 | u8 payload_is_ip6, |
| 149 | fib_mpls_lsp_mode_t mode) |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 150 | { |
| 151 | u32 n_left_from, next_index, * from, * to_next; |
Neale Ranns | 4c7c8e5 | 2017-10-21 09:37:55 -0700 | [diff] [blame] | 152 | vlib_node_runtime_t *error_node; |
| 153 | |
| 154 | if (payload_is_ip4) |
Neale Ranns | 31ed744 | 2018-02-23 05:29:09 -0800 | [diff] [blame] | 155 | { |
| 156 | if (FIB_MPLS_LSP_MODE_PIPE == mode) |
| 157 | error_node = |
| 158 | vlib_node_get_runtime(vm, ip4_mpls_label_disposition_pipe_node.index); |
| 159 | else |
| 160 | error_node = |
| 161 | vlib_node_get_runtime(vm, ip4_mpls_label_disposition_uniform_node.index); |
| 162 | } |
Neale Ranns | 4c7c8e5 | 2017-10-21 09:37:55 -0700 | [diff] [blame] | 163 | else |
Neale Ranns | 31ed744 | 2018-02-23 05:29:09 -0800 | [diff] [blame] | 164 | { |
| 165 | if (FIB_MPLS_LSP_MODE_PIPE == mode) |
| 166 | error_node = |
Neale Ranns | 19bd190 | 2018-03-19 02:32:57 -0700 | [diff] [blame] | 167 | vlib_node_get_runtime(vm, ip6_mpls_label_disposition_pipe_node.index); |
Neale Ranns | 31ed744 | 2018-02-23 05:29:09 -0800 | [diff] [blame] | 168 | else |
| 169 | error_node = |
| 170 | vlib_node_get_runtime(vm, ip6_mpls_label_disposition_uniform_node.index); |
| 171 | } |
| 172 | from = vlib_frame_vector_args(from_frame); |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 173 | n_left_from = from_frame->n_vectors; |
| 174 | |
| 175 | next_index = node->cached_next_index; |
| 176 | |
| 177 | while (n_left_from > 0) |
| 178 | { |
| 179 | u32 n_left_to_next; |
| 180 | |
| 181 | vlib_get_next_frame(vm, node, next_index, to_next, n_left_to_next); |
| 182 | |
| 183 | while (n_left_from >= 4 && n_left_to_next >= 2) |
| 184 | { |
| 185 | mpls_disp_dpo_t *mdd0, *mdd1; |
| 186 | u32 bi0, mddi0, bi1, mddi1; |
| 187 | vlib_buffer_t * b0, *b1; |
| 188 | u32 next0, next1; |
| 189 | |
| 190 | bi0 = to_next[0] = from[0]; |
| 191 | bi1 = to_next[1] = from[1]; |
| 192 | |
| 193 | /* Prefetch next iteration. */ |
| 194 | { |
| 195 | vlib_buffer_t * p2, * p3; |
| 196 | |
Neale Ranns | 31ed744 | 2018-02-23 05:29:09 -0800 | [diff] [blame] | 197 | p2 = vlib_get_buffer(vm, from[2]); |
| 198 | p3 = vlib_get_buffer(vm, from[3]); |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 199 | |
Neale Ranns | 31ed744 | 2018-02-23 05:29:09 -0800 | [diff] [blame] | 200 | vlib_prefetch_buffer_header(p2, STORE); |
| 201 | vlib_prefetch_buffer_header(p3, STORE); |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 202 | |
Neale Ranns | 31ed744 | 2018-02-23 05:29:09 -0800 | [diff] [blame] | 203 | CLIB_PREFETCH(p2->data, sizeof(ip6_header_t), STORE); |
| 204 | CLIB_PREFETCH(p3->data, sizeof(ip6_header_t), STORE); |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 205 | } |
| 206 | |
| 207 | from += 2; |
| 208 | to_next += 2; |
| 209 | n_left_from -= 2; |
| 210 | n_left_to_next -= 2; |
| 211 | |
Neale Ranns | 31ed744 | 2018-02-23 05:29:09 -0800 | [diff] [blame] | 212 | b0 = vlib_get_buffer(vm, bi0); |
| 213 | b1 = vlib_get_buffer(vm, bi1); |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 214 | |
| 215 | /* dst lookup was done by ip4 lookup */ |
| 216 | mddi0 = vnet_buffer(b0)->ip.adj_index[VLIB_TX]; |
| 217 | mddi1 = vnet_buffer(b1)->ip.adj_index[VLIB_TX]; |
| 218 | mdd0 = mpls_disp_dpo_get(mddi0); |
| 219 | mdd1 = mpls_disp_dpo_get(mddi1); |
| 220 | |
Neale Ranns | 4c7c8e5 | 2017-10-21 09:37:55 -0700 | [diff] [blame] | 221 | next0 = mdd0->mdd_dpo.dpoi_next_node; |
| 222 | next1 = mdd1->mdd_dpo.dpoi_next_node; |
| 223 | |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 224 | if (payload_is_ip4) |
| 225 | { |
Neale Ranns | 4c7c8e5 | 2017-10-21 09:37:55 -0700 | [diff] [blame] | 226 | ip4_header_t *ip0, *ip1; |
| 227 | |
Neale Ranns | 31ed744 | 2018-02-23 05:29:09 -0800 | [diff] [blame] | 228 | ip0 = vlib_buffer_get_current(b0); |
| 229 | ip1 = vlib_buffer_get_current(b1); |
Neale Ranns | 4c7c8e5 | 2017-10-21 09:37:55 -0700 | [diff] [blame] | 230 | |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 231 | /* |
Neale Ranns | 4c7c8e5 | 2017-10-21 09:37:55 -0700 | [diff] [blame] | 232 | * IPv4 input checks on the exposed IP header |
| 233 | * including checksum |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 234 | */ |
Neale Ranns | 31ed744 | 2018-02-23 05:29:09 -0800 | [diff] [blame] | 235 | ip4_input_check_x2(vm, error_node, |
| 236 | b0, b1, ip0, ip1, |
| 237 | &next0, &next1, 1); |
| 238 | |
| 239 | if (FIB_MPLS_LSP_MODE_UNIFORM == mode) |
| 240 | { |
| 241 | /* |
| 242 | * Copy the TTL from the MPLS packet into the |
| 243 | * exposed IP. recalc the chksum |
| 244 | */ |
| 245 | ip0->ttl = vnet_buffer(b0)->mpls.ttl; |
| 246 | ip1->ttl = vnet_buffer(b1)->mpls.ttl; |
| 247 | ip0->tos = mpls_exp_to_ip_dscp(vnet_buffer(b0)->mpls.exp); |
| 248 | ip1->tos = mpls_exp_to_ip_dscp(vnet_buffer(b1)->mpls.exp); |
| 249 | |
| 250 | ip0->checksum = ip4_header_checksum(ip0); |
| 251 | ip1->checksum = ip4_header_checksum(ip1); |
| 252 | } |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 253 | } |
| 254 | else if (payload_is_ip6) |
| 255 | { |
Neale Ranns | 4c7c8e5 | 2017-10-21 09:37:55 -0700 | [diff] [blame] | 256 | ip6_header_t *ip0, *ip1; |
| 257 | |
Neale Ranns | 31ed744 | 2018-02-23 05:29:09 -0800 | [diff] [blame] | 258 | ip0 = vlib_buffer_get_current(b0); |
| 259 | ip1 = vlib_buffer_get_current(b1); |
Neale Ranns | 4c7c8e5 | 2017-10-21 09:37:55 -0700 | [diff] [blame] | 260 | |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 261 | /* |
Neale Ranns | 4c7c8e5 | 2017-10-21 09:37:55 -0700 | [diff] [blame] | 262 | * IPv6 input checks on the exposed IP header |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 263 | */ |
Neale Ranns | 31ed744 | 2018-02-23 05:29:09 -0800 | [diff] [blame] | 264 | ip6_input_check_x2(vm, error_node, |
| 265 | b0, b1, ip0, ip1, |
| 266 | &next0, &next1); |
| 267 | |
| 268 | if (FIB_MPLS_LSP_MODE_UNIFORM == mode) |
| 269 | { |
| 270 | /* |
| 271 | * Copy the TTL from the MPLS packet into the |
| 272 | * exposed IP |
| 273 | */ |
| 274 | ip0->hop_limit = vnet_buffer(b0)->mpls.ttl; |
| 275 | ip1->hop_limit = vnet_buffer(b1)->mpls.ttl; |
| 276 | |
| 277 | ip6_set_traffic_class_network_order( |
| 278 | ip0, |
| 279 | mpls_exp_to_ip_dscp(vnet_buffer(b0)->mpls.exp)); |
| 280 | ip6_set_traffic_class_network_order( |
| 281 | ip1, |
| 282 | mpls_exp_to_ip_dscp(vnet_buffer(b1)->mpls.exp)); |
| 283 | } |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 284 | } |
Neale Ranns | 4c7c8e5 | 2017-10-21 09:37:55 -0700 | [diff] [blame] | 285 | |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 286 | vnet_buffer(b0)->ip.adj_index[VLIB_TX] = mdd0->mdd_dpo.dpoi_index; |
| 287 | vnet_buffer(b1)->ip.adj_index[VLIB_TX] = mdd1->mdd_dpo.dpoi_index; |
| 288 | vnet_buffer(b0)->ip.rpf_id = mdd0->mdd_rpf_id; |
| 289 | vnet_buffer(b1)->ip.rpf_id = mdd1->mdd_rpf_id; |
| 290 | |
| 291 | if (PREDICT_FALSE(b0->flags & VLIB_BUFFER_IS_TRACED)) |
| 292 | { |
| 293 | mpls_label_disposition_trace_t *tr = |
Neale Ranns | 31ed744 | 2018-02-23 05:29:09 -0800 | [diff] [blame] | 294 | vlib_add_trace(vm, node, b0, sizeof(*tr)); |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 295 | |
| 296 | tr->mdd = mddi0; |
| 297 | } |
| 298 | if (PREDICT_FALSE(b1->flags & VLIB_BUFFER_IS_TRACED)) |
| 299 | { |
| 300 | mpls_label_disposition_trace_t *tr = |
Neale Ranns | 31ed744 | 2018-02-23 05:29:09 -0800 | [diff] [blame] | 301 | vlib_add_trace(vm, node, b1, sizeof(*tr)); |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 302 | tr->mdd = mddi1; |
| 303 | } |
| 304 | |
| 305 | vlib_validate_buffer_enqueue_x2(vm, node, next_index, to_next, |
| 306 | n_left_to_next, |
| 307 | bi0, bi1, next0, next1); |
| 308 | } |
| 309 | |
| 310 | while (n_left_from > 0 && n_left_to_next > 0) |
| 311 | { |
| 312 | mpls_disp_dpo_t *mdd0; |
| 313 | vlib_buffer_t * b0; |
| 314 | u32 bi0, mddi0; |
| 315 | u32 next0; |
| 316 | |
| 317 | bi0 = from[0]; |
| 318 | to_next[0] = bi0; |
| 319 | from += 1; |
| 320 | to_next += 1; |
| 321 | n_left_from -= 1; |
| 322 | n_left_to_next -= 1; |
| 323 | |
Neale Ranns | 31ed744 | 2018-02-23 05:29:09 -0800 | [diff] [blame] | 324 | b0 = vlib_get_buffer(vm, bi0); |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 325 | |
| 326 | /* dst lookup was done by ip4 lookup */ |
| 327 | mddi0 = vnet_buffer(b0)->ip.adj_index[VLIB_TX]; |
| 328 | mdd0 = mpls_disp_dpo_get(mddi0); |
Neale Ranns | 4c7c8e5 | 2017-10-21 09:37:55 -0700 | [diff] [blame] | 329 | next0 = mdd0->mdd_dpo.dpoi_next_node; |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 330 | |
| 331 | if (payload_is_ip4) |
| 332 | { |
Neale Ranns | 4c7c8e5 | 2017-10-21 09:37:55 -0700 | [diff] [blame] | 333 | ip4_header_t *ip0; |
| 334 | |
Neale Ranns | 31ed744 | 2018-02-23 05:29:09 -0800 | [diff] [blame] | 335 | ip0 = vlib_buffer_get_current(b0); |
Neale Ranns | 4c7c8e5 | 2017-10-21 09:37:55 -0700 | [diff] [blame] | 336 | |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 337 | /* |
Neale Ranns | 4c7c8e5 | 2017-10-21 09:37:55 -0700 | [diff] [blame] | 338 | * IPv4 input checks on the exposed IP header |
| 339 | * including checksum |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 340 | */ |
Neale Ranns | 31ed744 | 2018-02-23 05:29:09 -0800 | [diff] [blame] | 341 | ip4_input_check_x1(vm, error_node, b0, ip0, &next0, 1); |
| 342 | |
| 343 | if (FIB_MPLS_LSP_MODE_UNIFORM == mode) |
| 344 | { |
| 345 | /* |
| 346 | * Copy the TTL from the MPLS packet into the |
| 347 | * exposed IP. recalc the chksum |
| 348 | */ |
| 349 | ip0->ttl = vnet_buffer(b0)->mpls.ttl; |
| 350 | ip0->tos = mpls_exp_to_ip_dscp(vnet_buffer(b0)->mpls.exp); |
| 351 | ip0->checksum = ip4_header_checksum(ip0); |
| 352 | } |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 353 | } |
| 354 | else if (payload_is_ip6) |
| 355 | { |
Neale Ranns | 4c7c8e5 | 2017-10-21 09:37:55 -0700 | [diff] [blame] | 356 | ip6_header_t *ip0; |
| 357 | |
Neale Ranns | 31ed744 | 2018-02-23 05:29:09 -0800 | [diff] [blame] | 358 | ip0 = vlib_buffer_get_current(b0); |
Neale Ranns | 4c7c8e5 | 2017-10-21 09:37:55 -0700 | [diff] [blame] | 359 | |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 360 | /* |
Neale Ranns | 4c7c8e5 | 2017-10-21 09:37:55 -0700 | [diff] [blame] | 361 | * IPv6 input checks on the exposed IP header |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 362 | */ |
Neale Ranns | 31ed744 | 2018-02-23 05:29:09 -0800 | [diff] [blame] | 363 | ip6_input_check_x1(vm, error_node, b0, ip0, &next0); |
| 364 | |
| 365 | if (FIB_MPLS_LSP_MODE_UNIFORM == mode) |
| 366 | { |
| 367 | /* |
| 368 | * Copy the TTL from the MPLS packet into the |
| 369 | * exposed IP |
| 370 | */ |
| 371 | ip0->hop_limit = vnet_buffer(b0)->mpls.ttl; |
| 372 | |
| 373 | ip6_set_traffic_class_network_order( |
| 374 | ip0, |
| 375 | mpls_exp_to_ip_dscp(vnet_buffer(b0)->mpls.exp)); |
| 376 | } |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 377 | } |
| 378 | |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 379 | vnet_buffer(b0)->ip.adj_index[VLIB_TX] = mdd0->mdd_dpo.dpoi_index; |
| 380 | vnet_buffer(b0)->ip.rpf_id = mdd0->mdd_rpf_id; |
| 381 | |
| 382 | if (PREDICT_FALSE(b0->flags & VLIB_BUFFER_IS_TRACED)) |
| 383 | { |
| 384 | mpls_label_disposition_trace_t *tr = |
Neale Ranns | 31ed744 | 2018-02-23 05:29:09 -0800 | [diff] [blame] | 385 | vlib_add_trace(vm, node, b0, sizeof(*tr)); |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 386 | tr->mdd = mddi0; |
| 387 | } |
| 388 | |
| 389 | vlib_validate_buffer_enqueue_x1(vm, node, next_index, to_next, |
| 390 | n_left_to_next, bi0, next0); |
| 391 | } |
Neale Ranns | 31ed744 | 2018-02-23 05:29:09 -0800 | [diff] [blame] | 392 | vlib_put_next_frame(vm, node, next_index, n_left_to_next); |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 393 | } |
| 394 | return from_frame->n_vectors; |
| 395 | } |
| 396 | |
| 397 | static u8 * |
| 398 | format_mpls_label_disposition_trace (u8 * s, va_list * args) |
| 399 | { |
Neale Ranns | 31ed744 | 2018-02-23 05:29:09 -0800 | [diff] [blame] | 400 | CLIB_UNUSED(vlib_main_t * vm) = va_arg(*args, vlib_main_t *); |
| 401 | CLIB_UNUSED(vlib_node_t * node) = va_arg(*args, vlib_node_t *); |
| 402 | CLIB_UNUSED(mpls_label_disposition_trace_t * t); |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 403 | |
Neale Ranns | 31ed744 | 2018-02-23 05:29:09 -0800 | [diff] [blame] | 404 | t = va_arg(*args, mpls_label_disposition_trace_t *); |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 405 | |
| 406 | s = format(s, "disp:%d", t->mdd); |
| 407 | return (s); |
| 408 | } |
| 409 | |
Filip Tehlar | eb9a27f | 2019-03-07 01:42:11 -0800 | [diff] [blame^] | 410 | VLIB_NODE_FN (ip4_mpls_label_disposition_pipe_node) (vlib_main_t * vm, |
Neale Ranns | 31ed744 | 2018-02-23 05:29:09 -0800 | [diff] [blame] | 411 | vlib_node_runtime_t * node, |
| 412 | vlib_frame_t * frame) |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 413 | { |
Neale Ranns | 31ed744 | 2018-02-23 05:29:09 -0800 | [diff] [blame] | 414 | return (mpls_label_disposition_inline(vm, node, frame, 1, 0, |
| 415 | FIB_MPLS_LSP_MODE_PIPE)); |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 416 | } |
| 417 | |
Neale Ranns | 31ed744 | 2018-02-23 05:29:09 -0800 | [diff] [blame] | 418 | VLIB_REGISTER_NODE(ip4_mpls_label_disposition_pipe_node) = { |
Neale Ranns | 31ed744 | 2018-02-23 05:29:09 -0800 | [diff] [blame] | 419 | .name = "ip4-mpls-label-disposition-pipe", |
| 420 | .vector_size = sizeof(u32), |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 421 | |
| 422 | .format_trace = format_mpls_label_disposition_trace, |
Neale Ranns | 4c7c8e5 | 2017-10-21 09:37:55 -0700 | [diff] [blame] | 423 | .sibling_of = "ip4-input", |
| 424 | .n_errors = IP4_N_ERROR, |
| 425 | .error_strings = ip4_error_strings, |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 426 | }; |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 427 | |
Filip Tehlar | eb9a27f | 2019-03-07 01:42:11 -0800 | [diff] [blame^] | 428 | VLIB_NODE_FN (ip6_mpls_label_disposition_pipe_node) (vlib_main_t * vm, |
Neale Ranns | 31ed744 | 2018-02-23 05:29:09 -0800 | [diff] [blame] | 429 | vlib_node_runtime_t * node, |
| 430 | vlib_frame_t * frame) |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 431 | { |
Neale Ranns | 31ed744 | 2018-02-23 05:29:09 -0800 | [diff] [blame] | 432 | return (mpls_label_disposition_inline(vm, node, frame, 0, 1, |
| 433 | FIB_MPLS_LSP_MODE_PIPE)); |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 434 | } |
| 435 | |
Neale Ranns | 31ed744 | 2018-02-23 05:29:09 -0800 | [diff] [blame] | 436 | VLIB_REGISTER_NODE(ip6_mpls_label_disposition_pipe_node) = { |
Neale Ranns | 31ed744 | 2018-02-23 05:29:09 -0800 | [diff] [blame] | 437 | .name = "ip6-mpls-label-disposition-pipe", |
| 438 | .vector_size = sizeof(u32), |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 439 | |
| 440 | .format_trace = format_mpls_label_disposition_trace, |
Neale Ranns | 4c7c8e5 | 2017-10-21 09:37:55 -0700 | [diff] [blame] | 441 | .sibling_of = "ip6-input", |
| 442 | .n_errors = IP6_N_ERROR, |
| 443 | .error_strings = ip6_error_strings, |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 444 | }; |
Neale Ranns | 31ed744 | 2018-02-23 05:29:09 -0800 | [diff] [blame] | 445 | |
Filip Tehlar | eb9a27f | 2019-03-07 01:42:11 -0800 | [diff] [blame^] | 446 | VLIB_NODE_FN (ip4_mpls_label_disposition_uniform_node) (vlib_main_t * vm, |
Neale Ranns | 31ed744 | 2018-02-23 05:29:09 -0800 | [diff] [blame] | 447 | vlib_node_runtime_t * node, |
| 448 | vlib_frame_t * frame) |
| 449 | { |
| 450 | return (mpls_label_disposition_inline(vm, node, frame, 1, 0, |
| 451 | FIB_MPLS_LSP_MODE_UNIFORM)); |
| 452 | } |
| 453 | |
| 454 | VLIB_REGISTER_NODE(ip4_mpls_label_disposition_uniform_node) = { |
Neale Ranns | 31ed744 | 2018-02-23 05:29:09 -0800 | [diff] [blame] | 455 | .name = "ip4-mpls-label-disposition-uniform", |
| 456 | .vector_size = sizeof(u32), |
| 457 | |
| 458 | .format_trace = format_mpls_label_disposition_trace, |
| 459 | .sibling_of = "ip4-input", |
| 460 | .n_errors = IP4_N_ERROR, |
| 461 | .error_strings = ip4_error_strings, |
| 462 | }; |
Neale Ranns | 31ed744 | 2018-02-23 05:29:09 -0800 | [diff] [blame] | 463 | |
Filip Tehlar | eb9a27f | 2019-03-07 01:42:11 -0800 | [diff] [blame^] | 464 | VLIB_NODE_FN (ip6_mpls_label_disposition_uniform_node) (vlib_main_t * vm, |
Neale Ranns | 31ed744 | 2018-02-23 05:29:09 -0800 | [diff] [blame] | 465 | vlib_node_runtime_t * node, |
| 466 | vlib_frame_t * frame) |
| 467 | { |
| 468 | return (mpls_label_disposition_inline(vm, node, frame, 0, 1, |
| 469 | FIB_MPLS_LSP_MODE_UNIFORM)); |
| 470 | } |
| 471 | |
| 472 | VLIB_REGISTER_NODE(ip6_mpls_label_disposition_uniform_node) = { |
Neale Ranns | 31ed744 | 2018-02-23 05:29:09 -0800 | [diff] [blame] | 473 | .name = "ip6-mpls-label-disposition-uniform", |
| 474 | .vector_size = sizeof(u32), |
| 475 | |
| 476 | .format_trace = format_mpls_label_disposition_trace, |
| 477 | .sibling_of = "ip6-input", |
| 478 | .n_errors = IP6_N_ERROR, |
| 479 | .error_strings = ip6_error_strings, |
| 480 | }; |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 481 | |
Filip Tehlar | eb9a27f | 2019-03-07 01:42:11 -0800 | [diff] [blame^] | 482 | #ifndef CLIB_MARCH_VARIANT |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 483 | static void |
| 484 | mpls_disp_dpo_mem_show (void) |
| 485 | { |
| 486 | fib_show_memory_usage("MPLS label", |
| 487 | pool_elts(mpls_disp_dpo_pool), |
| 488 | pool_len(mpls_disp_dpo_pool), |
| 489 | sizeof(mpls_disp_dpo_t)); |
| 490 | } |
| 491 | |
| 492 | const static dpo_vft_t mdd_vft = { |
| 493 | .dv_lock = mpls_disp_dpo_lock, |
| 494 | .dv_unlock = mpls_disp_dpo_unlock, |
| 495 | .dv_format = format_mpls_disp_dpo, |
| 496 | .dv_mem_show = mpls_disp_dpo_mem_show, |
| 497 | }; |
| 498 | |
Neale Ranns | 31ed744 | 2018-02-23 05:29:09 -0800 | [diff] [blame] | 499 | const static char* const mpls_label_disp_pipe_ip4_nodes[] = |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 500 | { |
Neale Ranns | 31ed744 | 2018-02-23 05:29:09 -0800 | [diff] [blame] | 501 | "ip4-mpls-label-disposition-pipe", |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 502 | NULL, |
| 503 | }; |
Neale Ranns | 31ed744 | 2018-02-23 05:29:09 -0800 | [diff] [blame] | 504 | const static char* const mpls_label_disp_pipe_ip6_nodes[] = |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 505 | { |
Neale Ranns | 31ed744 | 2018-02-23 05:29:09 -0800 | [diff] [blame] | 506 | "ip6-mpls-label-disposition-pipe", |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 507 | NULL, |
| 508 | }; |
Neale Ranns | 31ed744 | 2018-02-23 05:29:09 -0800 | [diff] [blame] | 509 | const static char* const * const mpls_label_disp_pipe_nodes[DPO_PROTO_NUM] = |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 510 | { |
Neale Ranns | 31ed744 | 2018-02-23 05:29:09 -0800 | [diff] [blame] | 511 | [DPO_PROTO_IP4] = mpls_label_disp_pipe_ip4_nodes, |
| 512 | [DPO_PROTO_IP6] = mpls_label_disp_pipe_ip6_nodes, |
| 513 | }; |
| 514 | |
| 515 | const static char* const mpls_label_disp_uniform_ip4_nodes[] = |
| 516 | { |
| 517 | "ip4-mpls-label-disposition-uniform", |
| 518 | NULL, |
| 519 | }; |
| 520 | const static char* const mpls_label_disp_uniform_ip6_nodes[] = |
| 521 | { |
| 522 | "ip6-mpls-label-disposition-uniform", |
| 523 | NULL, |
| 524 | }; |
| 525 | const static char* const * const mpls_label_disp_uniform_nodes[DPO_PROTO_NUM] = |
| 526 | { |
| 527 | [DPO_PROTO_IP4] = mpls_label_disp_uniform_ip4_nodes, |
| 528 | [DPO_PROTO_IP6] = mpls_label_disp_uniform_ip6_nodes, |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 529 | }; |
| 530 | |
| 531 | |
| 532 | void |
Neale Ranns | 31ed744 | 2018-02-23 05:29:09 -0800 | [diff] [blame] | 533 | mpls_disp_dpo_module_init(void) |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 534 | { |
Neale Ranns | 31ed744 | 2018-02-23 05:29:09 -0800 | [diff] [blame] | 535 | dpo_register(DPO_MPLS_DISPOSITION_PIPE, &mdd_vft, |
| 536 | mpls_label_disp_pipe_nodes); |
| 537 | dpo_register(DPO_MPLS_DISPOSITION_UNIFORM, &mdd_vft, |
| 538 | mpls_label_disp_uniform_nodes); |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 539 | } |
Filip Tehlar | eb9a27f | 2019-03-07 01:42:11 -0800 | [diff] [blame^] | 540 | #endif /* CLIB_MARCH_VARIANT */ |