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:
7 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 #include <plugins/l3xc/l3xc.h>
17 #include <vnet/feature/feature.h>
19 typedef enum l3xc_next_t_
25 typedef struct l3xc_input_trace_t_
33 #define l3xc_error(n,s) L3XC_ERROR_##n,
34 #include "l3xc_error.def"
40 l3xc_input_inline (vlib_main_t * vm,
41 vlib_node_runtime_t * node,
42 vlib_frame_t * frame, fib_protocol_t fproto)
44 vlib_buffer_t *bufs[VLIB_FRAME_SIZE], **b;
45 u16 nexts[VLIB_FRAME_SIZE], *next;
48 from = vlib_frame_vector_args (frame);
49 n_left = frame->n_vectors;
53 vlib_get_buffers (vm, from, bufs, n_left);
57 const l3xc_t *l3xc0, *l3xc1, *l3xc2, *l3xc3;
58 u32 l3xci0, l3xci1, l3xci2, l3xci3;
61 /* Prefetch next iteration. */
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);
70 *(u32 *) vnet_feature_next_with_data (&next_u32, b[0],
73 *(u32 *) vnet_feature_next_with_data (&next_u32, b[1],
76 *(u32 *) vnet_feature_next_with_data (&next_u32, b[2],
79 *(u32 *) vnet_feature_next_with_data (&next_u32, b[3],
82 l3xc0 = l3xc_get (l3xci0);
83 l3xc1 = l3xc_get (l3xci1);
84 l3xc2 = l3xc_get (l3xci2);
85 l3xc3 = l3xc_get (l3xci3);
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;
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;
97 if (PREDICT_FALSE ((node->flags & VLIB_NODE_FLAG_TRACE)))
99 if (PREDICT_FALSE (b[0]->flags & VLIB_BUFFER_IS_TRACED))
101 l3xc_input_trace_t *tr;
103 tr = vlib_add_trace (vm, node, b[0], sizeof (*tr));
105 tr->lbi = vnet_buffer (b[0])->ip.adj_index[VLIB_TX];
107 if (PREDICT_FALSE (b[1]->flags & VLIB_BUFFER_IS_TRACED))
109 l3xc_input_trace_t *tr;
111 tr = vlib_add_trace (vm, node, b[1], sizeof (*tr));
113 tr->lbi = vnet_buffer (b[1])->ip.adj_index[VLIB_TX];
115 if (PREDICT_FALSE (b[2]->flags & VLIB_BUFFER_IS_TRACED))
117 l3xc_input_trace_t *tr;
119 tr = vlib_add_trace (vm, node, b[2], sizeof (*tr));
121 tr->lbi = vnet_buffer (b[2])->ip.adj_index[VLIB_TX];
123 if (PREDICT_FALSE (b[3]->flags & VLIB_BUFFER_IS_TRACED))
125 l3xc_input_trace_t *tr;
127 tr = vlib_add_trace (vm, node, b[3], sizeof (*tr));
129 tr->lbi = vnet_buffer (b[3])->ip.adj_index[VLIB_TX];
140 u32 l3xci0, next_u32;
144 *(u32 *) vnet_feature_next_with_data (&next_u32, b[0],
147 l3xc0 = l3xc_get (l3xci0);
149 next[0] = l3xc0->l3xc_dpo.dpoi_next_node;
151 vnet_buffer (b[0])->ip.adj_index[VLIB_TX] = l3xc0->l3xc_dpo.dpoi_index;
153 if (PREDICT_FALSE (b[0]->flags & VLIB_BUFFER_IS_TRACED))
155 l3xc_input_trace_t *tr;
157 tr = vlib_add_trace (vm, node, b[0], sizeof (*tr));
159 tr->lbi = vnet_buffer (b[0])->ip.adj_index[VLIB_TX];
167 vlib_buffer_enqueue_to_next (vm, node, from, nexts, frame->n_vectors);
168 return frame->n_vectors;
172 l3xc_input_ip4 (vlib_main_t * vm,
173 vlib_node_runtime_t * node, vlib_frame_t * frame)
175 return l3xc_input_inline (vm, node, frame, FIB_PROTOCOL_IP4);
179 l3xc_input_ip6 (vlib_main_t * vm,
180 vlib_node_runtime_t * node, vlib_frame_t * frame)
182 return l3xc_input_inline (vm, node, frame, FIB_PROTOCOL_IP6);
186 format_l3xc_input_trace (u8 * s, va_list * args)
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 *);
192 s = format (s, "l3xc-index:%d lb-index:%d", t->l3xci, t->lbi);
196 static char *l3xc_error_strings[] = {
197 #define l3xc_error(n,s) s,
198 #include "l3xc_error.def"
203 VLIB_REGISTER_NODE (l3xc_ip4_node) =
205 .function = l3xc_input_ip4,
206 .name = "l3xc-input-ip4",
207 .vector_size = sizeof (u32),
208 .format_trace = format_l3xc_input_trace,
209 .type = VLIB_NODE_TYPE_INTERNAL,
210 .n_errors = L3XC_N_ERROR,
211 .error_strings = l3xc_error_strings,
212 .n_next_nodes = L3XC_N_NEXT,
215 [L3XC_NEXT_DROP] = "error-drop",
219 VLIB_REGISTER_NODE (l3xc_ip6_node) =
221 .function = l3xc_input_ip6,
222 .name = "l3xc-input-ip6",
223 .vector_size = sizeof (u32),
224 .format_trace = format_l3xc_input_trace,
225 .type = VLIB_NODE_TYPE_INTERNAL,
227 .n_next_nodes = L3XC_N_NEXT,
231 [L3XC_NEXT_DROP] = "error-drop",
235 VNET_FEATURE_INIT (l3xc_ip4_feat, static) =
237 .arc_name = "ip4-unicast",
238 .node_name = "l3xc-input-ip4",
239 .runs_after = VNET_FEATURES ("acl-plugin-in-ip4-fa"),
242 VNET_FEATURE_INIT (l3xc_ip6_feat, static) =
244 .arc_name = "ip6-unicast",
245 .node_name = "l3xc-input-ip6",
246 .runs_after = VNET_FEATURES ("acl-plugin-in-ip6-fa"),
251 * fd.io coding-style-patch-verification: ON
254 * eval: (c-set-style "gnu")