blob: f59753723abef104f05d6d5299229ade2db041ea [file] [log] [blame]
Neale Ranns0bfe5d82016-08-25 15:29:12 +01001/*
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
Neale Ranns9b309b62019-03-06 08:07:34 -080020static u8 *
21format_mpls_drop_trace (u8 * s, va_list * args)
22{
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 *);
25
26 return s;
27}
28
29static void
30mpls_drop_trace (vlib_main_t * vm,
31 vlib_node_runtime_t * node,
32 vlib_frame_t * frame)
33{
34 u32 *from, n_left;
35
36 n_left = frame->n_vectors;
37 from = vlib_frame_vector_args (frame);
38
39 while (n_left >= 1)
40 {
41 vlib_buffer_t *b0;
42 u32 bi0;
43
44 bi0 = from[0];
45
46 b0 = vlib_get_buffer (vm, bi0);
47
48 if (b0->flags & VLIB_BUFFER_IS_TRACED)
49 {
50 vlib_add_trace (vm, node, b0, 0);
51 }
52 from += 1;
53 n_left -= 1;
54 }
55}
56
Neale Ranns0bfe5d82016-08-25 15:29:12 +010057always_inline uword
58mpls_terminate (vlib_main_t * vm,
59 vlib_node_runtime_t * node,
60 vlib_frame_t * frame,
61 int error_code)
62{
63 u32 * buffers = vlib_frame_vector_args (frame);
64 uword n_packets = frame->n_vectors;
65
Neale Ranns9b309b62019-03-06 08:07:34 -080066 if (node->flags & VLIB_NODE_FLAG_TRACE)
67 mpls_drop_trace (vm, node, frame);
68
Neale Ranns0bfe5d82016-08-25 15:29:12 +010069 vlib_error_drop_buffers (vm, node,
70 buffers,
71 /* stride */ 1,
72 n_packets,
73 /* next */ 0,
74 mpls_input_node.index,
75 error_code);
76
77 return n_packets;
78}
79
Filip Tehlar17fcd982019-03-05 04:32:11 -080080VLIB_NODE_FN (mpls_punt_node) (vlib_main_t * vm,
Neale Ranns0bfe5d82016-08-25 15:29:12 +010081 vlib_node_runtime_t * node,
82 vlib_frame_t * frame)
83{
84 return (mpls_terminate(vm, node, frame, MPLS_ERROR_PUNT));
85}
86
87VLIB_REGISTER_NODE (mpls_punt_node) = {
Neale Ranns0bfe5d82016-08-25 15:29:12 +010088 .name = "mpls-punt",
89 .vector_size = sizeof (u32),
Neale Ranns9b309b62019-03-06 08:07:34 -080090 .format_trace = format_mpls_drop_trace,
Neale Ranns0bfe5d82016-08-25 15:29:12 +010091
92 .n_next_nodes = 1,
93 .next_nodes = {
94 [0] = "error-punt",
95 },
96};
97
Filip Tehlar17fcd982019-03-05 04:32:11 -080098VLIB_NODE_FN (mpls_drop_node) (vlib_main_t * vm,
Neale Ranns0bfe5d82016-08-25 15:29:12 +010099 vlib_node_runtime_t * node,
100 vlib_frame_t * frame)
101{
102 return (mpls_terminate(vm, node, frame, MPLS_ERROR_DROP));
103}
104
105VLIB_REGISTER_NODE (mpls_drop_node) = {
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100106 .name = "mpls-drop",
107 .vector_size = sizeof (u32),
Neale Ranns9b309b62019-03-06 08:07:34 -0800108 .format_trace = format_mpls_drop_trace,
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100109
110 .n_next_nodes = 1,
111 .next_nodes = {
112 [0] = "error-drop",
113 },
114};
115
Filip Tehlar17fcd982019-03-05 04:32:11 -0800116VLIB_NODE_FN (mpls_not_enabled_node) (vlib_main_t * vm,
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100117 vlib_node_runtime_t * node,
118 vlib_frame_t * frame)
119{
120 return (mpls_terminate(vm, node, frame, MPLS_ERROR_NOT_ENABLED));
121}
122
123VLIB_REGISTER_NODE (mpls_not_enabled_node) = {
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100124 .name = "mpls-not-enabled",
125 .vector_size = sizeof (u32),
Neale Ranns9b309b62019-03-06 08:07:34 -0800126 .format_trace = format_mpls_drop_trace,
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100127
128 .n_next_nodes = 1,
129 .next_nodes = {
130 [0] = "error-drop",
131 },
132};
133
Damjan Marion8b3191e2016-11-09 19:54:20 +0100134VNET_FEATURE_ARC_INIT (mpls_input, static) =
135{
136 .arc_name = "mpls-input",
137 .start_nodes = VNET_FEATURES ("mpls-input"),
Dave Baracha25def72018-11-26 11:04:45 -0500138 .last_in_arc = "mpls-lookup",
Damjan Marion8b3191e2016-11-09 19:54:20 +0100139 .arc_index_ptr = &mpls_main.input_feature_arc_index,
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100140};
141
Damjan Marion8b3191e2016-11-09 19:54:20 +0100142VNET_FEATURE_INIT (mpls_not_enabled, static) = {
143 .arc_name = "mpls-input",
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100144 .node_name = "mpls-not-enabled",
Neale Rannsb85e4392017-03-16 16:12:57 -0400145 .runs_before = VNET_FEATURES ("mpls-lookup"),
146};
147
148VNET_FEATURE_INIT (mpls_lookup, static) = {
149 .arc_name = "mpls-input",
150 .node_name = "mpls-lookup",
Damjan Marion8b3191e2016-11-09 19:54:20 +0100151 .runs_before = VNET_FEATURES (0), /* not before any other features */
152};
153
154VNET_FEATURE_ARC_INIT (mpls_output, static) =
155{
156 .arc_name = "mpls-output",
157 .start_nodes = VNET_FEATURES ("mpls-output", "mpls-midchain"),
Dave Baracha25def72018-11-26 11:04:45 -0500158 .last_in_arc = "interface-output",
Damjan Marion8b3191e2016-11-09 19:54:20 +0100159 .arc_index_ptr = &mpls_main.output_feature_arc_index,
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100160};
161
Neale Ranns5e575b12016-10-03 09:40:25 +0100162/* Built-in ip4 tx feature path definition */
Damjan Marion8b3191e2016-11-09 19:54:20 +0100163VNET_FEATURE_INIT (mpls_interface_output, static) = {
164 .arc_name = "mpls-output",
Neale Ranns5e575b12016-10-03 09:40:25 +0100165 .node_name = "interface-output",
166 .runs_before = 0, /* not before any other features */
Neale Ranns5e575b12016-10-03 09:40:25 +0100167};
168
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100169static clib_error_t *
170mpls_sw_interface_add_del (vnet_main_t * vnm,
171 u32 sw_if_index,
172 u32 is_add)
173{
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100174 mpls_main_t * mm = &mpls_main;
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100175
Damjan Marion8b3191e2016-11-09 19:54:20 +0100176 vec_validate_init_empty (mm->mpls_enabled_by_sw_if_index, sw_if_index, 0);
177 vec_validate_init_empty (mm->fib_index_by_sw_if_index, sw_if_index, 0);
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100178
Damjan Marion8b3191e2016-11-09 19:54:20 +0100179 vnet_feature_enable_disable ("mpls-input", "mpls-not-enabled", sw_if_index,
180 is_add, 0, 0);
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100181
182 return /* no error */ 0;
183}
184
185VNET_SW_INTERFACE_ADD_DEL_FUNCTION (mpls_sw_interface_add_del);
186
Neale Ranns5e575b12016-10-03 09:40:25 +0100187