2 * mpls_features.c: MPLS input and output features
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:
9 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 #include <vnet/mpls/mpls.h>
21 format_mpls_drop_trace (u8 * s, va_list * args)
23 CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
24 CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
26 s = format (s, "drop");
31 mpls_drop_trace (vlib_main_t * vm,
32 vlib_node_runtime_t * node,
37 n_left = frame->n_vectors;
38 from = vlib_frame_vector_args (frame);
47 b0 = vlib_get_buffer (vm, bi0);
49 if (b0->flags & VLIB_BUFFER_IS_TRACED)
51 vlib_add_trace (vm, node, b0, 0);
59 mpls_terminate (vlib_main_t * vm,
60 vlib_node_runtime_t * node,
64 u32 * buffers = vlib_frame_vector_args (frame);
65 uword n_packets = frame->n_vectors;
67 if (node->flags & VLIB_NODE_FLAG_TRACE)
68 mpls_drop_trace (vm, node, frame);
70 vlib_error_drop_buffers (vm, node,
75 mpls_input_node.index,
81 VLIB_NODE_FN (mpls_punt_node) (vlib_main_t * vm,
82 vlib_node_runtime_t * node,
85 return (mpls_terminate(vm, node, frame, MPLS_ERROR_PUNT));
88 VLIB_REGISTER_NODE (mpls_punt_node) = {
90 .vector_size = sizeof (u32),
91 .format_trace = format_mpls_drop_trace,
99 VLIB_NODE_FN (mpls_drop_node) (vlib_main_t * vm,
100 vlib_node_runtime_t * node,
101 vlib_frame_t * frame)
103 return (mpls_terminate(vm, node, frame, MPLS_ERROR_DROP));
106 VLIB_REGISTER_NODE (mpls_drop_node) = {
108 .vector_size = sizeof (u32),
109 .format_trace = format_mpls_drop_trace,
117 VLIB_NODE_FN (mpls_not_enabled_node) (vlib_main_t * vm,
118 vlib_node_runtime_t * node,
119 vlib_frame_t * frame)
121 return (mpls_terminate(vm, node, frame, MPLS_ERROR_NOT_ENABLED));
124 VLIB_REGISTER_NODE (mpls_not_enabled_node) = {
125 .name = "mpls-not-enabled",
126 .vector_size = sizeof (u32),
127 .format_trace = format_mpls_drop_trace,
135 VNET_FEATURE_ARC_INIT (mpls_input, static) =
137 .arc_name = "mpls-input",
138 .start_nodes = VNET_FEATURES ("mpls-input"),
139 .last_in_arc = "mpls-lookup",
140 .arc_index_ptr = &mpls_main.input_feature_arc_index,
143 VNET_FEATURE_INIT (mpls_not_enabled, static) = {
144 .arc_name = "mpls-input",
145 .node_name = "mpls-not-enabled",
146 .runs_before = VNET_FEATURES ("mpls-lookup"),
149 VNET_FEATURE_INIT (mpls_lookup, static) = {
150 .arc_name = "mpls-input",
151 .node_name = "mpls-lookup",
152 .runs_before = VNET_FEATURES (0), /* not before any other features */
155 VNET_FEATURE_ARC_INIT (mpls_output, static) =
157 .arc_name = "mpls-output",
158 .start_nodes = VNET_FEATURES ("mpls-output", "mpls-midchain"),
159 .last_in_arc = "interface-output",
160 .arc_index_ptr = &mpls_main.output_feature_arc_index,
163 /* Built-in ip4 tx feature path definition */
164 VNET_FEATURE_INIT (mpls_interface_output, static) = {
165 .arc_name = "mpls-output",
166 .node_name = "interface-output",
167 .runs_before = 0, /* not before any other features */
170 static clib_error_t *
171 mpls_sw_interface_add_del (vnet_main_t * vnm,
175 mpls_main_t * mm = &mpls_main;
177 vec_validate_init_empty (mm->mpls_enabled_by_sw_if_index, sw_if_index, 0);
178 vec_validate_init_empty (mm->fib_index_by_sw_if_index, sw_if_index, 0);
180 vnet_feature_enable_disable ("mpls-input", "mpls-not-enabled", sw_if_index,
183 return /* no error */ 0;
186 VNET_SW_INTERFACE_ADD_DEL_FUNCTION (mpls_sw_interface_add_del);