blob: 9ed56dff55474ea47af758e8aaff71bbc9b41d26 [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
20always_inline uword
21mpls_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
40static uword
41mpls_punt (vlib_main_t * vm,
42 vlib_node_runtime_t * node,
43 vlib_frame_t * frame)
44{
45 return (mpls_terminate(vm, node, frame, MPLS_ERROR_PUNT));
46}
47
48VLIB_REGISTER_NODE (mpls_punt_node) = {
49 .function = mpls_punt,
50 .name = "mpls-punt",
51 .vector_size = sizeof (u32),
52
53 .n_next_nodes = 1,
54 .next_nodes = {
55 [0] = "error-punt",
56 },
57};
58
59VLIB_NODE_FUNCTION_MULTIARCH (mpls_punt_node, mpls_punt)
60
61static uword
62mpls_drop (vlib_main_t * vm,
63 vlib_node_runtime_t * node,
64 vlib_frame_t * frame)
65{
66 return (mpls_terminate(vm, node, frame, MPLS_ERROR_DROP));
67}
68
69VLIB_REGISTER_NODE (mpls_drop_node) = {
70 .function = mpls_drop,
71 .name = "mpls-drop",
72 .vector_size = sizeof (u32),
73
74 .n_next_nodes = 1,
75 .next_nodes = {
76 [0] = "error-drop",
77 },
78};
79
80VLIB_NODE_FUNCTION_MULTIARCH (mpls_drop_node, mpls_drop)
81
82static uword
83mpls_not_enabled (vlib_main_t * vm,
84 vlib_node_runtime_t * node,
85 vlib_frame_t * frame)
86{
87 return (mpls_terminate(vm, node, frame, MPLS_ERROR_NOT_ENABLED));
88}
89
90VLIB_REGISTER_NODE (mpls_not_enabled_node) = {
91 .function = mpls_not_enabled,
92 .name = "mpls-not-enabled",
93 .vector_size = sizeof (u32),
94
95 .n_next_nodes = 1,
96 .next_nodes = {
97 [0] = "error-drop",
98 },
99};
100
101VLIB_NODE_FUNCTION_MULTIARCH (mpls_not_enabled_node, mpls_not_enabled)
102
Damjan Marion8b3191e2016-11-09 19:54:20 +0100103VNET_FEATURE_ARC_INIT (mpls_input, static) =
104{
105 .arc_name = "mpls-input",
106 .start_nodes = VNET_FEATURES ("mpls-input"),
Dave Baracha25def72018-11-26 11:04:45 -0500107 .last_in_arc = "mpls-lookup",
Damjan Marion8b3191e2016-11-09 19:54:20 +0100108 .arc_index_ptr = &mpls_main.input_feature_arc_index,
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100109};
110
Damjan Marion8b3191e2016-11-09 19:54:20 +0100111VNET_FEATURE_INIT (mpls_not_enabled, static) = {
112 .arc_name = "mpls-input",
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100113 .node_name = "mpls-not-enabled",
Neale Rannsb85e4392017-03-16 16:12:57 -0400114 .runs_before = VNET_FEATURES ("mpls-lookup"),
115};
116
117VNET_FEATURE_INIT (mpls_lookup, static) = {
118 .arc_name = "mpls-input",
119 .node_name = "mpls-lookup",
Damjan Marion8b3191e2016-11-09 19:54:20 +0100120 .runs_before = VNET_FEATURES (0), /* not before any other features */
121};
122
123VNET_FEATURE_ARC_INIT (mpls_output, static) =
124{
125 .arc_name = "mpls-output",
126 .start_nodes = VNET_FEATURES ("mpls-output", "mpls-midchain"),
Dave Baracha25def72018-11-26 11:04:45 -0500127 .last_in_arc = "interface-output",
Damjan Marion8b3191e2016-11-09 19:54:20 +0100128 .arc_index_ptr = &mpls_main.output_feature_arc_index,
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100129};
130
Neale Ranns5e575b12016-10-03 09:40:25 +0100131/* Built-in ip4 tx feature path definition */
Damjan Marion8b3191e2016-11-09 19:54:20 +0100132VNET_FEATURE_INIT (mpls_interface_output, static) = {
133 .arc_name = "mpls-output",
Neale Ranns5e575b12016-10-03 09:40:25 +0100134 .node_name = "interface-output",
135 .runs_before = 0, /* not before any other features */
Neale Ranns5e575b12016-10-03 09:40:25 +0100136};
137
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100138static clib_error_t *
139mpls_sw_interface_add_del (vnet_main_t * vnm,
140 u32 sw_if_index,
141 u32 is_add)
142{
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100143 mpls_main_t * mm = &mpls_main;
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100144
Damjan Marion8b3191e2016-11-09 19:54:20 +0100145 vec_validate_init_empty (mm->mpls_enabled_by_sw_if_index, sw_if_index, 0);
146 vec_validate_init_empty (mm->fib_index_by_sw_if_index, sw_if_index, 0);
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100147
Damjan Marion8b3191e2016-11-09 19:54:20 +0100148 vnet_feature_enable_disable ("mpls-input", "mpls-not-enabled", sw_if_index,
149 is_add, 0, 0);
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100150
151 return /* no error */ 0;
152}
153
154VNET_SW_INTERFACE_ADD_DEL_FUNCTION (mpls_sw_interface_add_del);
155
Neale Ranns5e575b12016-10-03 09:40:25 +0100156