FD.io VPP  v21.06-3-gbb25fbf28
Vector Packet Processing
adj_nsh.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2017 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 <vnet/vnet.h>
17 #include <vnet/adj/adj_nsh.h>
18 #include <vnet/ip/ip.h>
19 
20 #ifndef CLIB_MARCH_VARIANT
22 #endif /* CLIB_MARCH_VARIANT */
23 
24 /**
25  * @brief Trace data for a NSH Midchain
26  */
27 typedef struct adj_nsh_trace_t_ {
28  /** Adjacency index taken. */
31 
32 static u8 *
33 format_adj_nsh_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  adj_nsh_trace_t * t = va_arg (*args, adj_nsh_trace_t *);
38 
39  s = format (s, "adj-idx %d : %U",
40  t->adj_index,
42  return s;
43 }
44 
46 {
49 
54  int is_midchain)
55 {
57  u32 n_left_from, n_left_to_next, * to_next, next_index;
59 
60  n_left_from = frame->n_vectors;
61  next_index = node->cached_next_index;
62 
63  while (n_left_from > 0)
64  {
65  vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
66 
67  while (n_left_from > 0 && n_left_to_next > 0)
68  {
69  ip_adjacency_t * adj0;
70  vlib_buffer_t * p0;
71  char *h0;
72  u32 pi0, rw_len0, adj_index0, next0 = 0;
73  u32 tx_sw_if_index0;
74 
75  pi0 = to_next[0] = from[0];
76  from += 1;
77  n_left_from -= 1;
78  to_next += 1;
79  n_left_to_next -= 1;
80 
81  p0 = vlib_get_buffer (vm, pi0);
82  h0 = vlib_buffer_get_current (p0);
83 
84  adj_index0 = vnet_buffer (p0)->ip.adj_index[VLIB_TX];
85 
86  /* We should never rewrite a pkt using the MISS adjacency */
87  ASSERT(adj_index0);
88 
89  adj0 = adj_get (adj_index0);
90 
91  /* Guess we are only writing on simple IP4 header. */
92  vnet_rewrite_one_header(adj0[0], h0, sizeof(ip4_header_t));
93 
94  /* Update packet buffer attributes/set output interface. */
95  rw_len0 = adj0[0].rewrite_header.data_bytes;
96  vnet_buffer(p0)->ip.save_rewrite_length = rw_len0;
97 
100  adj_index0,
101  /* packet increment */ 0,
102  /* byte increment */ rw_len0);
103 
104  /* Check MTU of outgoing interface. */
106  adj0[0].rewrite_header.max_l3_packet_bytes)))
107  {
108  /* Don't adjust the buffer for ttl issue; icmp-error node wants
109  * to see the IP header */
110  p0->current_data -= rw_len0;
111  p0->current_length += rw_len0;
112  tx_sw_if_index0 = adj0[0].rewrite_header.sw_if_index;
113 
114  if (is_midchain)
115  {
116  adj0->sub_type.midchain.fixup_func(
117  vm, adj0, p0,
118  adj0->sub_type.midchain.fixup_data);
119  }
120 
121  vnet_buffer (p0)->sw_if_index[VLIB_TX] = tx_sw_if_index0;
122 
123  /*
124  * Follow the feature ARC. this will result eventually in
125  * the midchain-tx node
126  */
127  vnet_feature_arc_start (nsh_main_placeholder.output_feature_arc_index,
128  tx_sw_if_index0, &next0, p0);
129  }
130  else
131  {
132  /* can't fragment NSH */
134  }
135 
136  if (PREDICT_FALSE(p0->flags & VLIB_BUFFER_IS_TRACED))
137  {
139  p0, sizeof (*tr));
140  tr->adj_index = vnet_buffer(p0)->ip.adj_index[VLIB_TX];
141  }
142 
144  to_next, n_left_to_next,
145  pi0, next0);
146  }
147 
148  vlib_put_next_frame (vm, node, next_index, n_left_to_next);
149  }
150 
151  return frame->n_vectors;
152 }
153 
157 {
158  return adj_nsh_rewrite_inline (vm, node, frame, 0);
159 }
160 
164 {
165  return adj_nsh_rewrite_inline (vm, node, frame, 1);
166 }
167 
169  .name = "adj-nsh-rewrite",
170  .vector_size = sizeof (u32),
171 
172  .format_trace = format_adj_nsh_trace,
173 
174  .n_next_nodes = 1,
175  .next_nodes = {
176  [ADJ_NSH_REWRITE_NEXT_DROP] = "error-drop",
177  },
178 };
179 
181  .name = "adj-nsh-midchain",
182  .vector_size = sizeof (u32),
183 
184  .format_trace = format_adj_nsh_trace,
185 
186  .n_next_nodes = 1,
187  .next_nodes = {
188  [ADJ_NSH_REWRITE_NEXT_DROP] = "error-drop",
189  },
190 };
191 
192 /* Built-in ip4 tx feature path definition */
193 /* *INDENT-OFF* */
194 VNET_FEATURE_ARC_INIT (nsh_output, static) =
195 {
196  .arc_name = "nsh-output",
197  .start_nodes = VNET_FEATURES ("adj-nsh-midchain"),
198  .arc_index_ptr = &nsh_main_placeholder.output_feature_arc_index,
199 };
200 
201 VNET_FEATURE_INIT (nsh_tx_drop, static) =
202 {
203  .arc_name = "nsh-output",
204  .node_name = "error-drop",
205  .runs_before = 0, /* not before any other features */
206 };
207 /* *INDENT-ON* */
nsh_main_placeholder_t
struct _nsh_main_placeholder nsh_main_placeholder_t
adj_nsh_rewrite_next_t_
adj_nsh_rewrite_next_t_
Definition: adj_nsh.c:45
thread_index
u32 thread_index
Definition: nat44_ei_hairpinning.c:492
frame
vlib_main_t vlib_node_runtime_t vlib_frame_t * frame
Definition: nat44_ei.c:3048
next_index
nat44_ei_hairpin_src_next_t next_index
Definition: nat44_ei_hairpinning.c:412
adj_nsh_midchain_node
vlib_node_registration_t adj_nsh_midchain_node
(constructor) VLIB_REGISTER_NODE (adj_nsh_midchain_node)
Definition: adj_nsh.c:180
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
adj_nsh_trace_t_::adj_index
u32 adj_index
Adjacency index taken.
Definition: adj_nsh.c:29
format_ip_adjacency
format_function_t format_ip_adjacency
Definition: format.h:58
node
vlib_main_t vlib_node_runtime_t * node
Definition: nat44_ei.c:3047
FORMAT_IP_ADJACENCY_NONE
@ FORMAT_IP_ADJACENCY_NONE
Definition: format.h:53
vm
vlib_main_t * vm
X-connect all packets from the HOST to the PHY.
Definition: nat44_ei.c:3047
vlib_frame_t
Definition: node.h:372
vlib_buffer_length_in_chain
static uword vlib_buffer_length_in_chain(vlib_main_t *vm, vlib_buffer_t *b)
Get length in bytes of the buffer chain.
Definition: buffer_funcs.h:433
ip4_header_t
Definition: ip4_packet.h:87
nsh_main_placeholder
nsh_main_placeholder_t nsh_main_placeholder
Definition: adj_nsh.c:21
adj_nsh_trace_t
struct adj_nsh_trace_t_ adj_nsh_trace_t
Trace data for a NSH Midchain.
vlib_buffer_t::current_data
i16 current_data
signed offset in data[], pre_data[] that we are currently processing.
Definition: buffer.h:119
adj_nsh_rewrite_node
vlib_node_registration_t adj_nsh_rewrite_node
(constructor) VLIB_REGISTER_NODE (adj_nsh_rewrite_node)
Definition: adj_nsh.c:168
VLIB_NODE_FN
#define VLIB_NODE_FN(node)
Definition: node.h:202
CLIB_UNUSED
#define CLIB_UNUSED(x)
Definition: clib.h:90
vnet_buffer
#define vnet_buffer(b)
Definition: buffer.h:437
PREDICT_FALSE
#define PREDICT_FALSE(x)
Definition: clib.h:124
vlib_get_thread_index
static_always_inline uword vlib_get_thread_index(void)
Definition: threads.h:208
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
adj_gpe_rewrite_next_t
enum adj_nsh_rewrite_next_t_ adj_gpe_rewrite_next_t
format_adj_nsh_trace
static u8 * format_adj_nsh_trace(u8 *s, va_list *args)
Definition: adj_nsh.c:33
uword
u64 uword
Definition: types.h:112
adj_nsh.h
ADJ_NSH_REWRITE_NEXT_DROP
@ ADJ_NSH_REWRITE_NEXT_DROP
Definition: adj_nsh.c:47
ip_adjacency_t_
IP unicast adjacency.
Definition: adj.h:235
vlib_node_registration_t
struct _vlib_node_registration vlib_node_registration_t
vlib_buffer_t::current_length
u16 current_length
Nbytes between current data and the end of this buffer.
Definition: buffer.h:122
adj_nsh_trace_t_
Trace data for a NSH Midchain.
Definition: adj_nsh.c:27
VNET_FEATURE_INIT
VNET_FEATURE_INIT(nsh_tx_drop, static)
VNET_FEATURE_ARC_INIT
VNET_FEATURE_ARC_INIT(nsh_output, static)
ip_adjacency_t_::sub_type
union ip_adjacency_t_::@144 sub_type
vlib_validate_buffer_enqueue_x1
#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:224
always_inline
#define always_inline
Definition: rdma_mlx5dv.h:23
format
description fragment has unexpected format
Definition: map.api:433
ASSERT
#define ASSERT(truth)
Definition: error_bootstrap.h:69
adjacency_counters
vlib_combined_counter_main_t adjacency_counters
Adjacency packet counters.
Definition: adj.c:26
vlib_put_next_frame
vlib_put_next_frame(vm, node, next_index, 0)
ip.h
u32
unsigned int u32
Definition: types.h:88
adj_nsh_rewrite_inline
static uword adj_nsh_rewrite_inline(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame, int is_midchain)
Definition: adj_nsh.c:51
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
vlib_buffer_get_current
static void * vlib_buffer_get_current(vlib_buffer_t *b)
Get pointer to current data to process.
Definition: buffer.h:257
vnet_rewrite_one_header
#define vnet_rewrite_one_header(rw0, p0, most_likely_size)
Definition: rewrite.h:218
vnet_feature_arc_start
static_always_inline void vnet_feature_arc_start(u8 arc, u32 sw_if_index, u32 *next0, vlib_buffer_t *b0)
Definition: feature.h:302
vnet.h
vlib_node_runtime_t
Definition: node.h:454
from
from
Definition: nat44_ei_hairpinning.c:415
PREDICT_TRUE
#define PREDICT_TRUE(x)
Definition: clib.h:125
vlib_get_next_frame
#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:395
VLIB_TX
@ VLIB_TX
Definition: defs.h:47
adj_get
static ip_adjacency_t * adj_get(adj_index_t adj_index)
Get a pointer to an adjacency object from its index.
Definition: adj.h:470
n_left_from
n_left_from
Definition: nat44_ei_hairpinning.c:416
vlib_increment_combined_counter
vlib_increment_combined_counter(ccm, ti, sw_if_index, n_buffers, n_bytes)
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
vlib_buffer_t
VLIB buffer representation.
Definition: buffer.h:111
VLIB_REGISTER_NODE
#define VLIB_REGISTER_NODE(x,...)
Definition: node.h:169
ip_adjacency_t_::midchain
struct ip_adjacency_t_::@144::@146 midchain
IP_LOOKUP_NEXT_MIDCHAIN.