FD.io VPP  v17.07.01-10-g3be13f0
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 
21 
22 /**
23  * @brief Trace data for a NSH Midchain
24  */
25 typedef struct adj_nsh_trace_t_ {
26  /** Adjacency index taken. */
29 
30 static u8 *
31 format_adj_nsh_trace (u8 * s, va_list * args)
32 {
33  CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
34  CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
35  adj_nsh_trace_t * t = va_arg (*args, adj_nsh_trace_t *);
36 
37  s = format (s, "adj-idx %d : %U",
38  t->adj_index,
40  return s;
41 }
42 
44 {
47 
50  vlib_node_runtime_t * node,
51  vlib_frame_t * frame,
52  int is_midchain)
53 {
54  u32 * from = vlib_frame_vector_args (frame);
55  u32 n_left_from, n_left_to_next, * to_next, next_index;
56  u32 thread_index = vlib_get_thread_index();
57 
58  n_left_from = frame->n_vectors;
59  next_index = node->cached_next_index;
60 
61  while (n_left_from > 0)
62  {
63  vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
64 
65  while (n_left_from > 0 && n_left_to_next > 0)
66  {
67  ip_adjacency_t * adj0;
68  vlib_buffer_t * p0;
69  char *h0;
70  u32 pi0, rw_len0, adj_index0, next0 = 0;
71  u32 tx_sw_if_index0;
72 
73  pi0 = to_next[0] = from[0];
74  from += 1;
75  n_left_from -= 1;
76  to_next += 1;
77  n_left_to_next -= 1;
78 
79  p0 = vlib_get_buffer (vm, pi0);
80  h0 = vlib_buffer_get_current (p0);
81 
82  adj_index0 = vnet_buffer (p0)->ip.adj_index[VLIB_TX];
83 
84  /* We should never rewrite a pkt using the MISS adjacency */
85  ASSERT(adj_index0);
86 
87  adj0 = adj_get (adj_index0);
88 
89  /* Guess we are only writing on simple IP4 header. */
90  vnet_rewrite_one_header(adj0[0], h0, sizeof(ip4_header_t));
91 
92  /* Update packet buffer attributes/set output interface. */
93  rw_len0 = adj0[0].rewrite_header.data_bytes;
94  vnet_buffer(p0)->ip.save_rewrite_length = rw_len0;
95 
97  thread_index,
98  adj_index0,
99  /* packet increment */ 0,
100  /* byte increment */ rw_len0);
101 
102  /* Check MTU of outgoing interface. */
104  adj0[0].rewrite_header.max_l3_packet_bytes)))
105  {
106  /* Don't adjust the buffer for ttl issue; icmp-error node wants
107  * to see the IP headerr */
108  p0->current_data -= rw_len0;
109  p0->current_length += rw_len0;
110  tx_sw_if_index0 = adj0[0].rewrite_header.sw_if_index;
111 
112  if (is_midchain)
113  {
114  adj0->sub_type.midchain.fixup_func(vm, adj0, p0);
115  }
116 
117  vnet_buffer (p0)->sw_if_index[VLIB_TX] = tx_sw_if_index0;
118 
119  /*
120  * Follow the feature ARC. this will result eventually in
121  * the midchain-tx node
122  */
123  vnet_feature_arc_start (nsh_main_dummy.output_feature_arc_index,
124  tx_sw_if_index0, &next0, p0);
125  }
126  else
127  {
128  /* can't fragment NSH */
130  }
131 
133  {
134  adj_nsh_trace_t *tr = vlib_add_trace (vm, node,
135  p0, sizeof (*tr));
136  tr->adj_index = vnet_buffer(p0)->ip.adj_index[VLIB_TX];
137  }
138 
139  vlib_validate_buffer_enqueue_x1 (vm, node, next_index,
140  to_next, n_left_to_next,
141  pi0, next0);
142  }
143 
144  vlib_put_next_frame (vm, node, next_index, n_left_to_next);
145  }
146 
147  return frame->n_vectors;
148 }
149 
150 static uword
152  vlib_node_runtime_t * node,
153  vlib_frame_t * frame)
154 {
155  return adj_nsh_rewrite_inline (vm, node, frame, 0);
156 }
157 
158 static uword
160  vlib_node_runtime_t * node,
161  vlib_frame_t * frame)
162 {
163  return adj_nsh_rewrite_inline (vm, node, frame, 1);
164 }
165 
167  .function = adj_nsh_rewrite,
168  .name = "adj-nsh-rewrite",
169  .vector_size = sizeof (u32),
170 
171  .format_trace = format_adj_nsh_trace,
172 
173  .n_next_nodes = 1,
174  .next_nodes = {
175  [ADJ_NSH_REWRITE_NEXT_DROP] = "error-drop",
176  },
177 };
178 
180 
182  .function = adj_nsh_midchain,
183  .name = "adj-nsh-midchain",
184  .vector_size = sizeof (u32),
185 
186  .format_trace = format_adj_nsh_trace,
187 
188  .n_next_nodes = 1,
189  .next_nodes = {
190  [ADJ_NSH_REWRITE_NEXT_DROP] = "error-drop",
191  },
192 };
193 
195 
196 /* Built-in ip4 tx feature path definition */
197 /* *INDENT-OFF* */
198 VNET_FEATURE_ARC_INIT (nsh_output, static) =
199 {
200  .arc_name = "nsh-output",
201  .start_nodes = VNET_FEATURES ("adj-nsh-midchain"),
202  .arc_index_ptr = &nsh_main_dummy.output_feature_arc_index,
203 };
204 
205 VNET_FEATURE_INIT (nsh_tx_drop, static) =
206 {
207  .arc_name = "nsh-output",
208  .node_name = "error-drop",
209  .runs_before = 0, /* not before any other features */
210 };
211 /* *INDENT-ON* */
#define vnet_rewrite_one_header(rw0, p0, most_likely_size)
Definition: rewrite.h:281
Trace data for a NSH Midchain.
Definition: adj_nsh.c:25
#define CLIB_UNUSED(x)
Definition: clib.h:79
static void vlib_increment_combined_counter(vlib_combined_counter_main_t *cm, u32 thread_index, u32 index, u64 n_packets, u64 n_bytes)
Increment a combined counter.
Definition: counter.h:211
#define PREDICT_TRUE(x)
Definition: clib.h:98
IP unicast adjacency.
Definition: adj.h:174
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
vlib_node_registration_t adj_nsh_rewrite_node
(constructor) VLIB_REGISTER_NODE (adj_nsh_rewrite_node)
Definition: adj_nsh.c:166
u8 * format(u8 *s, const char *fmt,...)
Definition: format.c:419
union ip_adjacency_t_::@37 sub_type
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:100
static ip_adjacency_t * adj_get(adj_index_t adj_index)
Get a pointer to an adjacency object from its index.
Definition: adj.h:365
i16 current_data
signed offset in data[], pre_data[] that we are currently processing.
Definition: buffer.h:67
static u8 * format_adj_nsh_trace(u8 *s, va_list *args)
Definition: adj_nsh.c:31
vlib_node_registration_t adj_nsh_midchain_node
(constructor) VLIB_REGISTER_NODE (adj_nsh_midchain_node)
Definition: adj_nsh.c:181
format_function_t format_ip_adjacency
Definition: format.h:58
#define always_inline
Definition: clib.h:84
static uword adj_nsh_midchain(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame)
Definition: adj_nsh.c:159
u16 current_length
Nbytes between current data and the end of this buffer.
Definition: buffer.h:71
static void * vlib_buffer_get_current(vlib_buffer_t *b)
Get pointer to current data to process.
Definition: buffer.h:188
#define PREDICT_FALSE(x)
Definition: clib.h:97
struct ip_adjacency_t_::@37::@39 midchain
IP_LOOKUP_NEXT_MIDCHAIN.
#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:366
vlib_combined_counter_main_t adjacency_counters
Adjacency packet counters.
Definition: adj.c:25
u16 n_vectors
Definition: node.h:345
static_always_inline uword vlib_get_thread_index(void)
Definition: threads.h:185
static uword adj_nsh_rewrite(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame)
Definition: adj_nsh.c:151
#define VLIB_BUFFER_IS_TRACED
Definition: buffer.h:85
u32 adj_index
Adjacency index taken.
Definition: adj_nsh.c:27
u16 cached_next_index
Next frame index that vector arguments were last enqueued to last time this node ran.
Definition: node.h:460
#define ASSERT(truth)
unsigned int u32
Definition: types.h:88
struct _nsh_main_dummy nsh_main_dummy_t
struct adj_nsh_trace_t_ adj_nsh_trace_t
Trace data for a NSH Midchain.
VNET_FEATURE_INIT(nsh_tx_drop, static)
#define VNET_FEATURES(...)
Definition: feature.h:368
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
Definition: defs.h:47
unsigned char u8
Definition: types.h:56
adj_nsh_rewrite_next_t_
Definition: adj_nsh.c:43
nsh_main_dummy_t nsh_main_dummy
Definition: adj_nsh.c:20
VNET_FEATURE_ARC_INIT(nsh_output, static)
static void * vlib_frame_vector_args(vlib_frame_t *f)
Get pointer to frame vector data.
Definition: node_funcs.h:269
#define vnet_buffer(b)
Definition: buffer.h:304
#define VLIB_NODE_FUNCTION_MULTIARCH(node, fn)
Definition: node.h:159
#define VLIB_REGISTER_NODE(x,...)
Definition: node.h:144
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:49
enum adj_nsh_rewrite_next_t_ adj_gpe_rewrite_next_t
u32 flags
buffer flags: VLIB_BUFFER_IS_TRACED: trace this buffer.
Definition: buffer.h:74
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
static_always_inline void vnet_feature_arc_start(u8 arc, u32 sw_if_index, u32 *next0, vlib_buffer_t *b0)
Definition: feature.h:201