Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 1 | /* |
| 2 | * mpls_features.c: MPLS input and output features |
| 3 | * |
| 4 | * Copyright (c) 2016 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 <vnet/mpls/mpls.h> |
| 19 | |
| 20 | always_inline uword |
| 21 | mpls_terminate (vlib_main_t * vm, |
| 22 | vlib_node_runtime_t * node, |
| 23 | vlib_frame_t * frame, |
| 24 | int error_code) |
| 25 | { |
| 26 | u32 * buffers = vlib_frame_vector_args (frame); |
| 27 | uword n_packets = frame->n_vectors; |
| 28 | |
| 29 | vlib_error_drop_buffers (vm, node, |
| 30 | buffers, |
| 31 | /* stride */ 1, |
| 32 | n_packets, |
| 33 | /* next */ 0, |
| 34 | mpls_input_node.index, |
| 35 | error_code); |
| 36 | |
| 37 | return n_packets; |
| 38 | } |
| 39 | |
Filip Tehlar | 17fcd98 | 2019-03-05 04:32:11 -0800 | [diff] [blame] | 40 | VLIB_NODE_FN (mpls_punt_node) (vlib_main_t * vm, |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 41 | vlib_node_runtime_t * node, |
| 42 | vlib_frame_t * frame) |
| 43 | { |
| 44 | return (mpls_terminate(vm, node, frame, MPLS_ERROR_PUNT)); |
| 45 | } |
| 46 | |
| 47 | VLIB_REGISTER_NODE (mpls_punt_node) = { |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 48 | .name = "mpls-punt", |
| 49 | .vector_size = sizeof (u32), |
| 50 | |
| 51 | .n_next_nodes = 1, |
| 52 | .next_nodes = { |
| 53 | [0] = "error-punt", |
| 54 | }, |
| 55 | }; |
| 56 | |
Filip Tehlar | 17fcd98 | 2019-03-05 04:32:11 -0800 | [diff] [blame] | 57 | VLIB_NODE_FN (mpls_drop_node) (vlib_main_t * vm, |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 58 | vlib_node_runtime_t * node, |
| 59 | vlib_frame_t * frame) |
| 60 | { |
| 61 | return (mpls_terminate(vm, node, frame, MPLS_ERROR_DROP)); |
| 62 | } |
| 63 | |
| 64 | VLIB_REGISTER_NODE (mpls_drop_node) = { |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 65 | .name = "mpls-drop", |
| 66 | .vector_size = sizeof (u32), |
| 67 | |
| 68 | .n_next_nodes = 1, |
| 69 | .next_nodes = { |
| 70 | [0] = "error-drop", |
| 71 | }, |
| 72 | }; |
| 73 | |
Filip Tehlar | 17fcd98 | 2019-03-05 04:32:11 -0800 | [diff] [blame] | 74 | VLIB_NODE_FN (mpls_not_enabled_node) (vlib_main_t * vm, |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 75 | vlib_node_runtime_t * node, |
| 76 | vlib_frame_t * frame) |
| 77 | { |
| 78 | return (mpls_terminate(vm, node, frame, MPLS_ERROR_NOT_ENABLED)); |
| 79 | } |
| 80 | |
| 81 | VLIB_REGISTER_NODE (mpls_not_enabled_node) = { |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 82 | .name = "mpls-not-enabled", |
| 83 | .vector_size = sizeof (u32), |
| 84 | |
| 85 | .n_next_nodes = 1, |
| 86 | .next_nodes = { |
| 87 | [0] = "error-drop", |
| 88 | }, |
| 89 | }; |
| 90 | |
Damjan Marion | 8b3191e | 2016-11-09 19:54:20 +0100 | [diff] [blame] | 91 | VNET_FEATURE_ARC_INIT (mpls_input, static) = |
| 92 | { |
| 93 | .arc_name = "mpls-input", |
| 94 | .start_nodes = VNET_FEATURES ("mpls-input"), |
Dave Barach | a25def7 | 2018-11-26 11:04:45 -0500 | [diff] [blame] | 95 | .last_in_arc = "mpls-lookup", |
Damjan Marion | 8b3191e | 2016-11-09 19:54:20 +0100 | [diff] [blame] | 96 | .arc_index_ptr = &mpls_main.input_feature_arc_index, |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 97 | }; |
| 98 | |
Damjan Marion | 8b3191e | 2016-11-09 19:54:20 +0100 | [diff] [blame] | 99 | VNET_FEATURE_INIT (mpls_not_enabled, static) = { |
| 100 | .arc_name = "mpls-input", |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 101 | .node_name = "mpls-not-enabled", |
Neale Ranns | b85e439 | 2017-03-16 16:12:57 -0400 | [diff] [blame] | 102 | .runs_before = VNET_FEATURES ("mpls-lookup"), |
| 103 | }; |
| 104 | |
| 105 | VNET_FEATURE_INIT (mpls_lookup, static) = { |
| 106 | .arc_name = "mpls-input", |
| 107 | .node_name = "mpls-lookup", |
Damjan Marion | 8b3191e | 2016-11-09 19:54:20 +0100 | [diff] [blame] | 108 | .runs_before = VNET_FEATURES (0), /* not before any other features */ |
| 109 | }; |
| 110 | |
| 111 | VNET_FEATURE_ARC_INIT (mpls_output, static) = |
| 112 | { |
| 113 | .arc_name = "mpls-output", |
| 114 | .start_nodes = VNET_FEATURES ("mpls-output", "mpls-midchain"), |
Dave Barach | a25def7 | 2018-11-26 11:04:45 -0500 | [diff] [blame] | 115 | .last_in_arc = "interface-output", |
Damjan Marion | 8b3191e | 2016-11-09 19:54:20 +0100 | [diff] [blame] | 116 | .arc_index_ptr = &mpls_main.output_feature_arc_index, |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 117 | }; |
| 118 | |
Neale Ranns | 5e575b1 | 2016-10-03 09:40:25 +0100 | [diff] [blame] | 119 | /* Built-in ip4 tx feature path definition */ |
Damjan Marion | 8b3191e | 2016-11-09 19:54:20 +0100 | [diff] [blame] | 120 | VNET_FEATURE_INIT (mpls_interface_output, static) = { |
| 121 | .arc_name = "mpls-output", |
Neale Ranns | 5e575b1 | 2016-10-03 09:40:25 +0100 | [diff] [blame] | 122 | .node_name = "interface-output", |
| 123 | .runs_before = 0, /* not before any other features */ |
Neale Ranns | 5e575b1 | 2016-10-03 09:40:25 +0100 | [diff] [blame] | 124 | }; |
| 125 | |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 126 | static clib_error_t * |
| 127 | mpls_sw_interface_add_del (vnet_main_t * vnm, |
| 128 | u32 sw_if_index, |
| 129 | u32 is_add) |
| 130 | { |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 131 | mpls_main_t * mm = &mpls_main; |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 132 | |
Damjan Marion | 8b3191e | 2016-11-09 19:54:20 +0100 | [diff] [blame] | 133 | vec_validate_init_empty (mm->mpls_enabled_by_sw_if_index, sw_if_index, 0); |
| 134 | vec_validate_init_empty (mm->fib_index_by_sw_if_index, sw_if_index, 0); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 135 | |
Damjan Marion | 8b3191e | 2016-11-09 19:54:20 +0100 | [diff] [blame] | 136 | vnet_feature_enable_disable ("mpls-input", "mpls-not-enabled", sw_if_index, |
| 137 | is_add, 0, 0); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 138 | |
| 139 | return /* no error */ 0; |
| 140 | } |
| 141 | |
| 142 | VNET_SW_INTERFACE_ADD_DEL_FUNCTION (mpls_sw_interface_add_del); |
| 143 | |
Neale Ranns | 5e575b1 | 2016-10-03 09:40:25 +0100 | [diff] [blame] | 144 | |