FD.io VPP  v17.01.1-3-gc6833f8
Vector Packet Processing
node_in.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2016 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 #include <vlib/vlib.h>
16 #include <vnet/vnet.h>
17 #include <vnet/pg/pg.h>
18 #include <vppinfra/error.h>
19 #include <acl/acl.h>
20 #include "node_in.h"
21 
22 typedef struct
23 {
30 
31 /* packet trace format function */
32 static u8 *
33 format_acl_in_trace (u8 * s, va_list * args)
34 {
35  CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
36  CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
37  acl_in_trace_t *t = va_arg (*args, acl_in_trace_t *);
38 
39  s =
40  format (s,
41  "ACL_IN: sw_if_index %d, next index %d, match: inacl %d rule %d trace_bits %08x",
44  return s;
45 }
46 
48 
49 #define foreach_acl_in_error \
50 _(ACL_CHECK, "InACL check packets processed")
51 
52 typedef enum
53 {
54 #define _(sym,str) ACL_IN_ERROR_##sym,
56 #undef _
59 
60 static char *acl_in_error_strings[] = {
61 #define _(sym,string) string,
63 #undef _
64 };
65 
66 static uword
68  vlib_node_runtime_t * node, vlib_frame_t * frame)
69 {
70  u32 n_left_from, *from, *to_next;
71  acl_in_next_t next_index;
72  u32 pkts_acl_checked = 0;
73  u32 feature_bitmap0;
74  u32 trace_bitmap = 0;
75  u32 *input_feat_next_node_index =
77 
78  from = vlib_frame_vector_args (frame);
79  n_left_from = frame->n_vectors;
80  next_index = node->cached_next_index;
81 
82  while (n_left_from > 0)
83  {
84  u32 n_left_to_next;
85 
86  vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
87 
88  while (n_left_from > 0 && n_left_to_next > 0)
89  {
90  u32 bi0;
91  vlib_buffer_t *b0;
92  u32 next0 = ~0;
93  u32 sw_if_index0;
94  u32 next = ~0;
95  u32 match_acl_index = ~0;
96  u32 match_rule_index = ~0;
97 
98  /* speculatively enqueue b0 to the current next frame */
99  bi0 = from[0];
100  to_next[0] = bi0;
101  from += 1;
102  to_next += 1;
103  n_left_from -= 1;
104  n_left_to_next -= 1;
105 
106  b0 = vlib_get_buffer (vm, bi0);
107 
108 
109  sw_if_index0 = vnet_buffer (b0)->sw_if_index[VLIB_RX];
110  feature_bitmap0 = vnet_buffer (b0)->l2.feature_bitmap;
111 
112  input_acl_packet_match (sw_if_index0, b0, &next, &match_acl_index,
113  &match_rule_index, &trace_bitmap);
114  if (next != ~0)
115  {
116  next0 = next;
117  }
118  if (next0 == ~0)
119  {
120  next0 =
121  feat_bitmap_get_next_node_index (input_feat_next_node_index,
122  feature_bitmap0);
123  }
124 
126  && (b0->flags & VLIB_BUFFER_IS_TRACED)))
127  {
128  acl_in_trace_t *t = vlib_add_trace (vm, node, b0, sizeof (*t));
129  t->sw_if_index = sw_if_index0;
130  t->next_index = next0;
131  t->match_acl_index = match_acl_index;
132  t->match_rule_index = match_rule_index;
133  t->trace_bitmap = trace_bitmap;
134  }
135 
136  next0 = next0 < node->n_next_nodes ? next0 : 0;
137 
138  pkts_acl_checked += 1;
139 
140  /* verify speculative enqueue, maybe switch current next frame */
141  vlib_validate_buffer_enqueue_x1 (vm, node, next_index,
142  to_next, n_left_to_next,
143  bi0, next0);
144  }
145 
146  vlib_put_next_frame (vm, node, next_index, n_left_to_next);
147  }
148 
150  ACL_IN_ERROR_ACL_CHECK, pkts_acl_checked);
151  return frame->n_vectors;
152 }
153 
155 {
156  .function = acl_in_node_fn,.name = "acl-plugin-in",.vector_size =
157  sizeof (u32),.format_trace = format_acl_in_trace,.type =
158  VLIB_NODE_TYPE_INTERNAL,.n_errors =
159  ARRAY_LEN (acl_in_error_strings),.error_strings =
160  acl_in_error_strings,.n_next_nodes = ACL_IN_N_NEXT,
161  /* edit / add dispositions here */
162  .next_nodes =
163  {
164  [ACL_IN_ERROR_DROP] = "error-drop",
165  [ACL_IN_ETHERNET_INPUT] = "ethernet-input",
166  [ACL_IN_L2S_INPUT_IP4_ADD] = "aclp-l2s-input-ip4-add",
167  [ACL_IN_L2S_INPUT_IP6_ADD] = "aclp-l2s-input-ip6-add",}
168 ,};
void vlib_put_next_frame(vlib_main_t *vm, vlib_node_runtime_t *r, u32 next_index, u32 n_vectors_left)
Release pointer to next frame vector data.
Definition: main.c:459
u32 sw_if_index
Definition: node_in.c:25
#define CLIB_UNUSED(x)
Definition: clib.h:79
bad routing header type(not 4)") sr_error (NO_MORE_SEGMENTS
struct _vlib_node_registration vlib_node_registration_t
void input_acl_packet_match(u32 sw_if_index, vlib_buffer_t *b0, u32 *nextp, u32 *acl_match_p, u32 *rule_match_p, u32 *trace_bitmap)
Definition: acl.c:970
#define foreach_acl_in_error
Definition: node_in.c:49
u32 next_index
Definition: node_in.c:24
u32 acl_in_node_feat_next_node_index[32]
Definition: acl.h:126
acl_in_error_t
Definition: node_in.c:52
#define PREDICT_FALSE(x)
Definition: clib.h:97
static u32 feat_bitmap_get_next_node_index(u32 *next_nodes, u32 bitmap)
Return the graph node index for the feature corresponding to the first set bit in the bitmap...
Definition: feat_bitmap.h:79
#define vlib_validate_buffer_enqueue_x1(vm, node, next_index, to_next, n_left_to_next, bi0, next0)
Finish enqueueing one buffer forward in the graph.
Definition: buffer_node.h:216
#define vlib_get_next_frame(vm, node, next_index, vectors, n_vectors_left)
Get pointer to next frame vector data by (vlib_node_runtime_t, next_index).
Definition: node_funcs.h:350
static void vlib_node_increment_counter(vlib_main_t *vm, u32 node_index, u32 counter_index, u64 increment)
Definition: node_funcs.h:1113
u16 n_vectors
Definition: node.h:344
u32 match_rule_index
Definition: node_in.c:27
#define ARRAY_LEN(x)
Definition: clib.h:59
u16 cached_next_index
Definition: node.h:463
unsigned int u32
Definition: types.h:88
#define vnet_buffer(b)
Definition: buffer.h:361
#define VLIB_NODE_FLAG_TRACE
Definition: node.h:259
acl_main_t acl_main
Definition: acl.c:57
#define VLIB_BUFFER_IS_TRACED
Definition: buffer.h:95
u64 uword
Definition: types.h:112
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:55
vlib_node_registration_t acl_in_node
(constructor) VLIB_REGISTER_NODE (acl_in_node)
Definition: node_in.c:47
unsigned char u8
Definition: types.h:56
u32 match_acl_index
Definition: node_in.c:26
acl_in_next_t
Definition: node_in.h:4
static void * vlib_frame_vector_args(vlib_frame_t *f)
Get pointer to frame vector data.
Definition: node_funcs.h:253
static uword acl_in_node_fn(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame)
Definition: node_in.c:67
#define VLIB_REGISTER_NODE(x,...)
Definition: node.h:143
u8 * format(u8 *s, const char *fmt,...)
Definition: format.c:418
static char * acl_in_error_strings[]
Definition: node_in.c:60
u32 trace_bitmap
Definition: node_in.c:28
static u8 * format_acl_in_trace(u8 *s, va_list *args)
Definition: node_in.c:33
u32 flags
buffer flags: VLIB_BUFFER_IS_TRACED: trace this buffer.
Definition: buffer.h:85
static vlib_buffer_t * vlib_get_buffer(vlib_main_t *vm, u32 buffer_index)
Translate buffer index into buffer pointer.
Definition: buffer_funcs.h:57
Definition: defs.h:46