FD.io VPP  v19.04.4-rc0-5-ge88582fac
Vector Packet Processing
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  return s;
27 }
28 
29 static void
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 
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 
66  if (node->flags & VLIB_NODE_FLAG_TRACE)
67  mpls_drop_trace (vm, node, frame);
68 
69  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 
81  vlib_node_runtime_t * node,
82  vlib_frame_t * frame)
83 {
84  return (mpls_terminate(vm, node, frame, MPLS_ERROR_PUNT));
85 }
86 
88  .name = "mpls-punt",
89  .vector_size = sizeof (u32),
90  .format_trace = format_mpls_drop_trace,
91 
92  .n_next_nodes = 1,
93  .next_nodes = {
94  [0] = "error-punt",
95  },
96 };
97 
99  vlib_node_runtime_t * node,
100  vlib_frame_t * frame)
101 {
102  return (mpls_terminate(vm, node, frame, MPLS_ERROR_DROP));
103 }
104 
106  .name = "mpls-drop",
107  .vector_size = sizeof (u32),
108  .format_trace = format_mpls_drop_trace,
109 
110  .n_next_nodes = 1,
111  .next_nodes = {
112  [0] = "error-drop",
113  },
114 };
115 
117  vlib_node_runtime_t * node,
118  vlib_frame_t * frame)
119 {
120  return (mpls_terminate(vm, node, frame, MPLS_ERROR_NOT_ENABLED));
121 }
122 
124  .name = "mpls-not-enabled",
125  .vector_size = sizeof (u32),
126  .format_trace = format_mpls_drop_trace,
127 
128  .n_next_nodes = 1,
129  .next_nodes = {
130  [0] = "error-drop",
131  },
132 };
133 
134 VNET_FEATURE_ARC_INIT (mpls_input, static) =
135 {
136  .arc_name = "mpls-input",
137  .start_nodes = VNET_FEATURES ("mpls-input"),
138  .last_in_arc = "mpls-lookup",
139  .arc_index_ptr = &mpls_main.input_feature_arc_index,
140 };
141 
142 VNET_FEATURE_INIT (mpls_not_enabled, static) = {
143  .arc_name = "mpls-input",
144  .node_name = "mpls-not-enabled",
145  .runs_before = VNET_FEATURES ("mpls-lookup"),
146 };
147 
148 VNET_FEATURE_INIT (mpls_lookup, static) = {
149  .arc_name = "mpls-input",
150  .node_name = "mpls-lookup",
151  .runs_before = VNET_FEATURES (0), /* not before any other features */
152 };
153 
154 VNET_FEATURE_ARC_INIT (mpls_output, static) =
155 {
156  .arc_name = "mpls-output",
157  .start_nodes = VNET_FEATURES ("mpls-output", "mpls-midchain"),
158  .last_in_arc = "interface-output",
159  .arc_index_ptr = &mpls_main.output_feature_arc_index,
160 };
161 
162 /* Built-in ip4 tx feature path definition */
163 VNET_FEATURE_INIT (mpls_interface_output, static) = {
164  .arc_name = "mpls-output",
165  .node_name = "interface-output",
166  .runs_before = 0, /* not before any other features */
167 };
168 
169 static clib_error_t *
172  u32 is_add)
173 {
174  mpls_main_t * mm = &mpls_main;
175 
178 
179  vnet_feature_enable_disable ("mpls-input", "mpls-not-enabled", sw_if_index,
180  is_add, 0, 0);
181 
182  return /* no error */ 0;
183 }
184 
186 
187 
u32 sw_if_index
Definition: ipsec_gre.api:37
u32 flags
buffer flags: VLIB_BUFFER_FREE_LIST_INDEX_MASK: bits used to store free list index, VLIB_BUFFER_IS_TRACED: trace this buffer.
Definition: buffer.h:124
vlib_node_registration_t mpls_drop_node
(constructor) VLIB_REGISTER_NODE (mpls_drop_node)
#define CLIB_UNUSED(x)
Definition: clib.h:82
vlib_node_registration_t mpls_not_enabled_node
(constructor) VLIB_REGISTER_NODE (mpls_not_enabled_node)
u8 input_feature_arc_index
Definition: mpls.h:56
u32 * fib_index_by_sw_if_index
Definition: mpls.h:44
VNET_FEATURE_INIT(mpls_not_enabled, static)
VNET_SW_INTERFACE_ADD_DEL_FUNCTION(mpls_sw_interface_add_del)
#define VLIB_NODE_FN(node)
Definition: node.h:201
static void mpls_drop_trace(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame)
Definition: mpls_features.c:30
unsigned char u8
Definition: types.h:56
u8 * mpls_enabled_by_sw_if_index
Definition: mpls.h:60
static uword mpls_terminate(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame, int error_code)
Definition: mpls_features.c:58
#define always_inline
Definition: clib.h:98
static u8 * format_mpls_drop_trace(u8 *s, va_list *args)
Definition: mpls_features.c:21
unsigned int u32
Definition: types.h:88
vlib_node_registration_t mpls_punt_node
(constructor) VLIB_REGISTER_NODE (mpls_punt_node)
Definition: mpls_features.c:87
u8 output_feature_arc_index
Definition: mpls.h:57
static clib_error_t * mpls_sw_interface_add_del(vnet_main_t *vnm, u32 sw_if_index, u32 is_add)
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:44
vlib_node_registration_t mpls_input_node
(constructor) VLIB_REGISTER_NODE (mpls_input_node)
Definition: mpls_input.c:245
VNET_FEATURE_ARC_INIT(mpls_input, static)
#define VLIB_REGISTER_NODE(x,...)
Definition: node.h:169
u16 n_vectors
Definition: node.h:395
mpls_main_t mpls_main
Definition: mpls.c:25
vlib_main_t * vm
Definition: buffer.c:312
u8 is_add
Definition: ipsec_gre.api:36
#define VNET_FEATURES(...)
Definition: feature.h:435
static void * vlib_add_trace(vlib_main_t *vm, vlib_node_runtime_t *r, vlib_buffer_t *b, u32 n_data_bytes)
Definition: trace_funcs.h:57
VLIB buffer representation.
Definition: buffer.h:102
u64 uword
Definition: types.h:112
static void * vlib_frame_vector_args(vlib_frame_t *f)
Get pointer to frame vector data.
Definition: node_funcs.h:244
u16 flags
Copy of main node flags.
Definition: node.h:507
#define VLIB_NODE_FLAG_TRACE
Definition: node.h:301
#define vec_validate_init_empty(V, I, INIT)
Make sure vector is long enough for given index and initialize empty space (no header, unspecified alignment)
Definition: vec.h:486
static vlib_buffer_t * vlib_get_buffer(vlib_main_t *vm, u32 buffer_index)
Translate buffer index into buffer pointer.
Definition: buffer_funcs.h:85
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: feature.c:274