FD.io VPP  v21.10.1-2-g0a485f517
Vector Packet Processing
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
mpls_features.c
Go to the documentation of this file.
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 static u8 *
21 format_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  s = format (s, "drop");
27  return s;
28 }
29 
30 static void
34 {
35  u32 *from, n_left;
36 
37  n_left = frame->n_vectors;
39 
40  while (n_left >= 1)
41  {
42  vlib_buffer_t *b0;
43  u32 bi0;
44 
45  bi0 = from[0];
46 
47  b0 = vlib_get_buffer (vm, bi0);
48 
49  if (b0->flags & VLIB_BUFFER_IS_TRACED)
50  {
51  vlib_add_trace (vm, node, b0, 0);
52  }
53  from += 1;
54  n_left -= 1;
55  }
56 }
57 
62  int error_code)
63 {
64  u32 * buffers = vlib_frame_vector_args (frame);
65  uword n_packets = frame->n_vectors;
66 
67  if (node->flags & VLIB_NODE_FLAG_TRACE)
69 
71  buffers,
72  /* stride */ 1,
73  n_packets,
74  /* next */ 0,
75  mpls_input_node.index,
76  error_code);
77 
78  return n_packets;
79 }
80 
84 {
85  return (mpls_terminate(vm, node, frame, MPLS_ERROR_PUNT));
86 }
87 
89  .name = "mpls-punt",
90  .vector_size = sizeof (u32),
91  .format_trace = format_mpls_drop_trace,
92 
93  .n_next_nodes = 1,
94  .next_nodes = {
95  [0] = "error-punt",
96  },
97 };
98 
102 {
103  return (mpls_terminate(vm, node, frame, MPLS_ERROR_DROP));
104 }
105 
107  .name = "mpls-drop",
108  .vector_size = sizeof (u32),
109  .format_trace = format_mpls_drop_trace,
110 
111  .n_next_nodes = 1,
112  .next_nodes = {
113  [0] = "error-drop",
114  },
115 };
116 
120 {
121  return (mpls_terminate(vm, node, frame, MPLS_ERROR_NOT_ENABLED));
122 }
123 
125  .name = "mpls-not-enabled",
126  .vector_size = sizeof (u32),
127  .format_trace = format_mpls_drop_trace,
128 
129  .n_next_nodes = 1,
130  .next_nodes = {
131  [0] = "error-drop",
132  },
133 };
134 
135 VNET_FEATURE_ARC_INIT (mpls_input, static) =
136 {
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,
141 };
142 
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"),
147 };
148 
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 */
153 };
154 
155 VNET_FEATURE_ARC_INIT (mpls_output, static) =
156 {
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,
161 };
162 
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 */
168 };
169 
170 static clib_error_t *
173  u32 is_add)
174 {
175  mpls_main_t * mm = &mpls_main;
176 
179 
180  vnet_feature_enable_disable ("mpls-input", "mpls-not-enabled", sw_if_index,
181  is_add, 0, 0);
182 
183  return /* no error */ 0;
184 }
185 
187 
188 
frame
vlib_main_t vlib_node_runtime_t vlib_frame_t * frame
Definition: nat44_ei.c:3048
VNET_SW_INTERFACE_ADD_DEL_FUNCTION
VNET_SW_INTERFACE_ADD_DEL_FUNCTION(mpls_sw_interface_add_del)
vlib_get_buffer
static vlib_buffer_t * vlib_get_buffer(vlib_main_t *vm, u32 buffer_index)
Translate buffer index into buffer pointer.
Definition: buffer_funcs.h:111
node
vlib_main_t vlib_node_runtime_t * node
Definition: nat44_ei.c:3047
mpls_main
mpls_main_t mpls_main
Definition: mpls.c:25
mpls_drop_node
vlib_node_registration_t mpls_drop_node
(constructor) VLIB_REGISTER_NODE (mpls_drop_node)
Definition: mpls_features.c:106
vm
vlib_main_t * vm
X-connect all packets from the HOST to the PHY.
Definition: nat44_ei.c:3047
mpls_input_node
vlib_node_registration_t mpls_input_node
(constructor) VLIB_REGISTER_NODE (mpls_input_node)
Definition: mpls_input.c:245
mpls_sw_interface_add_del
static clib_error_t * mpls_sw_interface_add_del(vnet_main_t *vnm, u32 sw_if_index, u32 is_add)
Definition: mpls_features.c:171
mpls.h
vlib_frame_t
Definition: node.h:372
mpls_punt_node
vlib_node_registration_t mpls_punt_node
(constructor) VLIB_REGISTER_NODE (mpls_punt_node)
Definition: mpls_features.c:88
mpls_main_t::mpls_enabled_by_sw_if_index
u8 * mpls_enabled_by_sw_if_index
Definition: mpls.h:60
mpls_main_t::input_feature_arc_index
u8 input_feature_arc_index
Definition: mpls.h:56
VLIB_NODE_FN
#define VLIB_NODE_FN(node)
Definition: node.h:202
CLIB_UNUSED
#define CLIB_UNUSED(x)
Definition: clib.h:90
VLIB_NODE_FLAG_TRACE
#define VLIB_NODE_FLAG_TRACE
Definition: node.h:291
vlib_frame_vector_args
static void * vlib_frame_vector_args(vlib_frame_t *f)
Get pointer to frame vector data.
Definition: node_funcs.h:301
VNET_FEATURE_INIT
VNET_FEATURE_INIT(mpls_not_enabled, static)
uword
u64 uword
Definition: types.h:112
vlib_error_drop_buffers
uword vlib_error_drop_buffers(vlib_main_t *vm, vlib_node_runtime_t *node, u32 *buffers, u32 next_buffer_stride, u32 n_buffers, u32 next_index, u32 drop_error_node, u32 drop_error_code)
Definition: error.c:45
mpls_terminate
static uword mpls_terminate(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame, int error_code)
Definition: mpls_features.c:59
vlib_node_registration_t
struct _vlib_node_registration vlib_node_registration_t
vnet_main_t
Definition: vnet.h:76
always_inline
#define always_inline
Definition: rdma_mlx5dv.h:23
format
description fragment has unexpected format
Definition: map.api:433
vec_validate_init_empty
#define vec_validate_init_empty(V, I, INIT)
Make sure vector is long enough for given index and initialize empty space (no header,...
Definition: vec.h:570
u32
unsigned int u32
Definition: types.h:88
format_mpls_drop_trace
static u8 * format_mpls_drop_trace(u8 *s, va_list *args)
Definition: mpls_features.c:21
n_left
u32 n_left
Definition: interface_output.c:1096
vnet_feature_enable_disable
int vnet_feature_enable_disable(const char *arc_name, const char *node_name, u32 sw_if_index, int enable_disable, void *feature_config, u32 n_feature_config_bytes)
Definition: pnat_test_stubs.h:50
vlib_main_t
Definition: main.h:102
vlib_node_t
Definition: node.h:247
vlib_add_trace
void * vlib_add_trace(vlib_main_t *vm, vlib_node_runtime_t *r, vlib_buffer_t *b, u32 n_data_bytes)
Definition: trace.c:628
VNET_FEATURES
#define VNET_FEATURES(...)
Definition: feature.h:470
u8
unsigned char u8
Definition: types.h:56
clib_error_t
Definition: clib_error.h:21
mpls_not_enabled_node
vlib_node_registration_t mpls_not_enabled_node
(constructor) VLIB_REGISTER_NODE (mpls_not_enabled_node)
Definition: mpls_features.c:124
mpls_main_t
Definition: mpls.h:41
mpls_main_t::fib_index_by_sw_if_index
u32 * fib_index_by_sw_if_index
Definition: mpls.h:44
vlib_node_runtime_t
Definition: node.h:454
from
from
Definition: nat44_ei_hairpinning.c:415
sw_if_index
vl_api_interface_index_t sw_if_index
Definition: wireguard.api:34
VNET_FEATURE_ARC_INIT
VNET_FEATURE_ARC_INIT(mpls_input, static)
mpls_drop_trace
static void mpls_drop_trace(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame)
Definition: mpls_features.c:31
vlib_buffer_t::flags
u32 flags
buffer flags: VLIB_BUFFER_FREE_LIST_INDEX_MASK: bits used to store free list index,...
Definition: buffer.h:133
mpls_main_t::output_feature_arc_index
u8 output_feature_arc_index
Definition: mpls.h:57
vlib_buffer_t
VLIB buffer representation.
Definition: buffer.h:111
VLIB_REGISTER_NODE
#define VLIB_REGISTER_NODE(x,...)
Definition: node.h:169