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