FD.io VPP  v21.06-3-gbb25fbf28
Vector Packet Processing
l3xc_node.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2019 Cisco and/or its affiliates.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at:
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include <plugins/l3xc/l3xc.h>
17 #include <vnet/feature/feature.h>
18 
19 typedef enum l3xc_next_t_
20 {
23 } l3xc_next_t;
24 
25 typedef struct l3xc_input_trace_t_
26 {
30 
31 typedef enum
32 {
33 #define l3xc_error(n,s) L3XC_ERROR_##n,
34 #include "l3xc_error.def"
35 #undef l3xc_error
37 } l3xc_error_t;
38 
43 {
46  u32 n_left, *from;
47 
49  n_left = frame->n_vectors;
50  b = bufs;
51  next = nexts;
52 
54 
55  while (n_left >= 8)
56  {
57  const l3xc_t *l3xc0, *l3xc1, *l3xc2, *l3xc3;
58  u32 l3xci0, l3xci1, l3xci2, l3xci3;
59  u32 next_u32;
60 
61  /* Prefetch next iteration. */
62  {
63  vlib_prefetch_buffer_header (b[4], LOAD);
64  vlib_prefetch_buffer_header (b[5], LOAD);
65  vlib_prefetch_buffer_header (b[6], LOAD);
66  vlib_prefetch_buffer_header (b[7], LOAD);
67  }
68 
69  l3xci0 =
70  *(u32 *) vnet_feature_next_with_data (&next_u32, b[0],
71  sizeof (l3xci0));
72  l3xci1 =
73  *(u32 *) vnet_feature_next_with_data (&next_u32, b[1],
74  sizeof (l3xci1));
75  l3xci2 =
76  *(u32 *) vnet_feature_next_with_data (&next_u32, b[2],
77  sizeof (l3xci2));
78  l3xci3 =
79  *(u32 *) vnet_feature_next_with_data (&next_u32, b[3],
80  sizeof (l3xci3));
81 
82  l3xc0 = l3xc_get (l3xci0);
83  l3xc1 = l3xc_get (l3xci1);
84  l3xc2 = l3xc_get (l3xci2);
85  l3xc3 = l3xc_get (l3xci3);
86 
87  next[0] = l3xc0->l3xc_dpo.dpoi_next_node;
88  next[1] = l3xc1->l3xc_dpo.dpoi_next_node;
89  next[2] = l3xc2->l3xc_dpo.dpoi_next_node;
90  next[3] = l3xc3->l3xc_dpo.dpoi_next_node;
91 
92  vnet_buffer (b[0])->ip.adj_index[VLIB_TX] = l3xc0->l3xc_dpo.dpoi_index;
93  vnet_buffer (b[1])->ip.adj_index[VLIB_TX] = l3xc1->l3xc_dpo.dpoi_index;
94  vnet_buffer (b[2])->ip.adj_index[VLIB_TX] = l3xc2->l3xc_dpo.dpoi_index;
95  vnet_buffer (b[3])->ip.adj_index[VLIB_TX] = l3xc3->l3xc_dpo.dpoi_index;
96 
97  if (PREDICT_FALSE ((node->flags & VLIB_NODE_FLAG_TRACE)))
98  {
99  if (PREDICT_FALSE (b[0]->flags & VLIB_BUFFER_IS_TRACED))
100  {
101  l3xc_input_trace_t *tr;
102 
103  tr = vlib_add_trace (vm, node, b[0], sizeof (*tr));
104  tr->l3xci = l3xci0;
105  tr->lbi = vnet_buffer (b[0])->ip.adj_index[VLIB_TX];
106  }
107  if (PREDICT_FALSE (b[1]->flags & VLIB_BUFFER_IS_TRACED))
108  {
109  l3xc_input_trace_t *tr;
110 
111  tr = vlib_add_trace (vm, node, b[1], sizeof (*tr));
112  tr->l3xci = l3xci1;
113  tr->lbi = vnet_buffer (b[1])->ip.adj_index[VLIB_TX];
114  }
115  if (PREDICT_FALSE (b[2]->flags & VLIB_BUFFER_IS_TRACED))
116  {
117  l3xc_input_trace_t *tr;
118 
119  tr = vlib_add_trace (vm, node, b[2], sizeof (*tr));
120  tr->l3xci = l3xci2;
121  tr->lbi = vnet_buffer (b[2])->ip.adj_index[VLIB_TX];
122  }
123  if (PREDICT_FALSE (b[3]->flags & VLIB_BUFFER_IS_TRACED))
124  {
125  l3xc_input_trace_t *tr;
126 
127  tr = vlib_add_trace (vm, node, b[3], sizeof (*tr));
128  tr->l3xci = l3xci3;
129  tr->lbi = vnet_buffer (b[3])->ip.adj_index[VLIB_TX];
130  }
131  }
132 
133  b += 4;
134  next += 4;
135  n_left -= 4;
136  }
137 
138  while (n_left > 0)
139  {
140  u32 l3xci0, next_u32;
141  const l3xc_t *l3xc0;
142 
143  l3xci0 =
144  *(u32 *) vnet_feature_next_with_data (&next_u32, b[0],
145  sizeof (l3xci0));
146 
147  l3xc0 = l3xc_get (l3xci0);
148 
149  next[0] = l3xc0->l3xc_dpo.dpoi_next_node;
150 
151  vnet_buffer (b[0])->ip.adj_index[VLIB_TX] = l3xc0->l3xc_dpo.dpoi_index;
152 
153  if (PREDICT_FALSE (b[0]->flags & VLIB_BUFFER_IS_TRACED))
154  {
155  l3xc_input_trace_t *tr;
156 
157  tr = vlib_add_trace (vm, node, b[0], sizeof (*tr));
158  tr->l3xci = l3xci0;
159  tr->lbi = vnet_buffer (b[0])->ip.adj_index[VLIB_TX];
160  }
161 
162  b += 1;
163  next += 1;
164  n_left -= 1;
165  }
166 
168  return frame->n_vectors;
169 }
170 
171 static uword
174 {
176 }
177 
178 static uword
181 {
183 }
184 
185 static u8 *
186 format_l3xc_input_trace (u8 * s, va_list * args)
187 {
188  CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
189  CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
190  l3xc_input_trace_t *t = va_arg (*args, l3xc_input_trace_t *);
191 
192  s = format (s, "l3xc-index:%d lb-index:%d", t->l3xci, t->lbi);
193  return s;
194 }
195 
196 static char *l3xc_error_strings[] = {
197 #define l3xc_error(n,s) s,
198 #include "l3xc_error.def"
199 #undef l3xc_error
200 };
201 
202 /* *INDENT-OFF* */
204 {
205  .function = l3xc_input_ip4,
206  .name = "l3xc-input-ip4",
207  .vector_size = sizeof (u32),
208  .format_trace = format_l3xc_input_trace,
210  .n_errors = L3XC_N_ERROR,
211  .error_strings = l3xc_error_strings,
212  .n_next_nodes = L3XC_N_NEXT,
213  .next_nodes =
214  {
215  [L3XC_NEXT_DROP] = "error-drop",
216  }
217 };
218 
220 {
221  .function = l3xc_input_ip6,
222  .name = "l3xc-input-ip6",
223  .vector_size = sizeof (u32),
224  .format_trace = format_l3xc_input_trace,
226  .n_errors = 0,
227  .n_next_nodes = L3XC_N_NEXT,
228 
229  .next_nodes =
230  {
231  [L3XC_NEXT_DROP] = "error-drop",
232  }
233 };
234 
235 VNET_FEATURE_INIT (l3xc_ip4_feat, static) =
236 {
237  .arc_name = "ip4-unicast",
238  .node_name = "l3xc-input-ip4",
239  .runs_after = VNET_FEATURES ("acl-plugin-in-ip4-fa"),
240 };
241 
242 VNET_FEATURE_INIT (l3xc_ip6_feat, static) =
243 {
244  .arc_name = "ip6-unicast",
245  .node_name = "l3xc-input-ip6",
246  .runs_after = VNET_FEATURES ("acl-plugin-in-ip6-fa"),
247 };
248 /* *INDENT-ON* */
249 
250 /*
251  * fd.io coding-style-patch-verification: ON
252  *
253  * Local Variables:
254  * eval: (c-set-style "gnu")
255  * End:
256  */
dpo_id_t_::dpoi_next_node
u16 dpoi_next_node
The next VLIB node to follow.
Definition: dpo.h:186
dpo_id_t_::dpoi_index
index_t dpoi_index
the index of objects of that type
Definition: dpo.h:190
l3xc.h
bufs
vlib_buffer_t * bufs[VLIB_FRAME_SIZE]
Definition: nat44_ei_out2in.c:717
vlib_prefetch_buffer_header
#define vlib_prefetch_buffer_header(b, type)
Prefetch buffer metadata.
Definition: buffer.h:231
frame
vlib_main_t vlib_node_runtime_t vlib_frame_t * frame
Definition: nat44_ei.c:3048
l3xc_input_ip6
static uword l3xc_input_ip6(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame)
Definition: l3xc_node.c:179
l3xc_error_t
l3xc_error_t
Definition: l3xc_node.c:31
vlib_get_buffers
vlib_get_buffers(vm, from, b, n_left_from)
next
u16 * next
Definition: nat44_ei_out2in.c:718
VLIB_NODE_TYPE_INTERNAL
@ VLIB_NODE_TYPE_INTERNAL
Definition: node.h:72
VLIB_FRAME_SIZE
#define VLIB_FRAME_SIZE
Definition: node.h:368
node
vlib_main_t vlib_node_runtime_t * node
Definition: nat44_ei.c:3047
u16
unsigned short u16
Definition: types.h:57
vm
vlib_main_t * vm
X-connect all packets from the HOST to the PHY.
Definition: nat44_ei.c:3047
l3xc_t_::l3xc_dpo
dpo_id_t l3xc_dpo
DPO for forwarding.
Definition: l3xc.h:61
vlib_buffer_enqueue_to_next
vlib_buffer_enqueue_to_next(vm, node, from,(u16 *) nexts, frame->n_vectors)
vnet_feature_next_with_data
static_always_inline void * vnet_feature_next_with_data(u32 *next0, vlib_buffer_t *b0, u32 n_data_bytes)
Definition: feature.h:309
vlib_frame_t
Definition: node.h:372
L3XC_N_NEXT
@ L3XC_N_NEXT
Definition: l3xc_node.c:22
format_l3xc_input_trace
static u8 * format_l3xc_input_trace(u8 *s, va_list *args)
Definition: l3xc_node.c:186
feature.h
l3xc_input_trace_t
struct l3xc_input_trace_t_ l3xc_input_trace_t
CLIB_UNUSED
#define CLIB_UNUSED(x)
Definition: clib.h:90
vnet_buffer
#define vnet_buffer(b)
Definition: buffer.h:437
l3xc_input_trace_t_
Definition: l3xc_node.c:25
VLIB_NODE_FLAG_TRACE
#define VLIB_NODE_FLAG_TRACE
Definition: node.h:291
PREDICT_FALSE
#define PREDICT_FALSE(x)
Definition: clib.h:124
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
index_t
u32 index_t
A Data-Path Object is an object that represents actions that are applied to packets are they are swit...
Definition: dpo.h:43
uword
u64 uword
Definition: types.h:112
l3xc_input_inline
static uword l3xc_input_inline(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame, fib_protocol_t fproto)
Definition: l3xc_node.c:40
VNET_FEATURE_INIT
VNET_FEATURE_INIT(l3xc_ip4_feat, static)
l3xc_get
static_always_inline l3xc_t * l3xc_get(u32 index)
Definition: l3xc.h:104
fib_protocol_t
enum fib_protocol_t_ fib_protocol_t
Protocol Type.
l3xc_input_trace_t_::l3xci
index_t l3xci
Definition: l3xc_node.c:27
FIB_PROTOCOL_IP4
@ FIB_PROTOCOL_IP4
Definition: fib_types.h:36
vlib_node_registration_t
struct _vlib_node_registration vlib_node_registration_t
L3XC_NEXT_DROP
@ L3XC_NEXT_DROP
Definition: l3xc_node.c:21
always_inline
#define always_inline
Definition: rdma_mlx5dv.h:23
format
description fragment has unexpected format
Definition: map.api:433
u32
unsigned int u32
Definition: types.h:88
FIB_PROTOCOL_IP6
@ FIB_PROTOCOL_IP6
Definition: fib_types.h:37
n_left
u32 n_left
Definition: interface_output.c:1078
l3xc_input_trace_t_::lbi
index_t lbi
Definition: l3xc_node.c:28
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
b
vlib_buffer_t ** b
Definition: nat44_ei_out2in.c:717
VNET_FEATURES
#define VNET_FEATURES(...)
Definition: feature.h:470
u8
unsigned char u8
Definition: types.h:56
l3xc_input_ip4
static uword l3xc_input_ip4(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame)
Definition: l3xc_node.c:172
l3xc_next_t_
l3xc_next_t_
Definition: l3xc_node.c:19
l3xc_next_t
enum l3xc_next_t_ l3xc_next_t
l3xc_t_
Definition: l3xc.h:33
l3xc_ip4_node
vlib_node_registration_t l3xc_ip4_node
(constructor) VLIB_REGISTER_NODE (l3xc_ip4_node)
Definition: l3xc_node.c:203
nexts
u16 nexts[VLIB_FRAME_SIZE]
Definition: nat44_ei_out2in.c:718
l3xc_error.def
L3XC_N_ERROR
@ L3XC_N_ERROR
Definition: l3xc_node.c:36
vlib_node_runtime_t
Definition: node.h:454
from
from
Definition: nat44_ei_hairpinning.c:415
l3xc_ip6_node
vlib_node_registration_t l3xc_ip6_node
(constructor) VLIB_REGISTER_NODE (l3xc_ip6_node)
Definition: l3xc_node.c:219
VLIB_TX
@ VLIB_TX
Definition: defs.h:47
l3xc_error_strings
static char * l3xc_error_strings[]
Definition: l3xc_node.c:196
type
vl_api_fib_path_type_t type
Definition: fib_types.api:123
vlib_buffer_t
VLIB buffer representation.
Definition: buffer.h:111
VLIB_REGISTER_NODE
#define VLIB_REGISTER_NODE(x,...)
Definition: node.h:169
flags
vl_api_wireguard_peer_flags_t flags
Definition: wireguard.api:105