FD.io VPP  v21.06-3-gbb25fbf28
Vector Packet Processing
ip6_forward.h
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 /*
16  * ip/ip6_forward.h: IP v6 forwarding
17  *
18  * Copyright (c) 2008 Eliot Dresselhaus
19  *
20  * Permission is hereby granted, free of charge, to any person obtaining
21  * a copy of this software and associated documentation files (the
22  * "Software"), to deal in the Software without restriction, including
23  * without limitation the rights to use, copy, modify, merge, publish,
24  * distribute, sublicense, and/or sell copies of the Software, and to
25  * permit persons to whom the Software is furnished to do so, subject to
26  * the following conditions:
27  *
28  * The above copyright notice and this permission notice shall be
29  * included in all copies or substantial portions of the Software.
30  *
31  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
32  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
33  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
34  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
35  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
36  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
37  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
38  */
39 
40 #ifndef __included_ip6_forward_h__
41 #define __included_ip6_forward_h__
42 
43 #include <vnet/fib/ip6_fib.h>
45 #include <vnet/ip/ip6_inlines.h>
46 
47 /**
48  * @file
49  * @brief IPv6 Forwarding.
50  *
51  * This file contains the source code for IPv6 forwarding.
52  */
53 
54 
58 {
61  u32 n_left_from, n_left_to_next, *from, *to_next;
64 
66  n_left_from = frame->n_vectors;
67  next = node->cached_next_index;
68 
69  while (n_left_from > 0)
70  {
71  vlib_get_next_frame (vm, node, next, to_next, n_left_to_next);
72 
73  while (n_left_from >= 4 && n_left_to_next >= 2)
74  {
75  vlib_buffer_t *p0, *p1;
76  u32 pi0, pi1, lbi0, lbi1, wrong_next;
77  ip_lookup_next_t next0, next1;
78  ip6_header_t *ip0, *ip1;
79  ip6_address_t *dst_addr0, *dst_addr1;
80  u32 flow_hash_config0, flow_hash_config1;
81  const dpo_id_t *dpo0, *dpo1;
82  const load_balance_t *lb0, *lb1;
83 
84  /* Prefetch next iteration. */
85  {
86  vlib_buffer_t *p2, *p3;
87 
88  p2 = vlib_get_buffer (vm, from[2]);
89  p3 = vlib_get_buffer (vm, from[3]);
90 
91  vlib_prefetch_buffer_header (p2, LOAD);
92  vlib_prefetch_buffer_header (p3, LOAD);
93  CLIB_PREFETCH (p2->data, sizeof (ip0[0]), LOAD);
94  CLIB_PREFETCH (p3->data, sizeof (ip0[0]), LOAD);
95  }
96 
97  pi0 = to_next[0] = from[0];
98  pi1 = to_next[1] = from[1];
99 
100  p0 = vlib_get_buffer (vm, pi0);
101  p1 = vlib_get_buffer (vm, pi1);
102 
103  ip0 = vlib_buffer_get_current (p0);
104  ip1 = vlib_buffer_get_current (p1);
105 
106  dst_addr0 = &ip0->dst_address;
107  dst_addr1 = &ip1->dst_address;
108 
109  ip_lookup_set_buffer_fib_index (im->fib_index_by_sw_if_index, p0);
110  ip_lookup_set_buffer_fib_index (im->fib_index_by_sw_if_index, p1);
111 
112  lbi0 = ip6_fib_table_fwding_lookup (vnet_buffer (p0)->ip.fib_index,
113  dst_addr0);
114  lbi1 = ip6_fib_table_fwding_lookup (vnet_buffer (p1)->ip.fib_index,
115  dst_addr1);
116 
117  lb0 = load_balance_get (lbi0);
118  lb1 = load_balance_get (lbi1);
119  ASSERT (lb0->lb_n_buckets > 0);
120  ASSERT (lb1->lb_n_buckets > 0);
121  ASSERT (is_pow2 (lb0->lb_n_buckets));
122  ASSERT (is_pow2 (lb1->lb_n_buckets));
123 
124  vnet_buffer (p0)->ip.flow_hash = vnet_buffer (p1)->ip.flow_hash = 0;
125 
126  if (PREDICT_FALSE (lb0->lb_n_buckets > 1))
127  {
128  flow_hash_config0 = lb0->lb_hash_config;
129  vnet_buffer (p0)->ip.flow_hash =
130  ip6_compute_flow_hash (ip0, flow_hash_config0);
131  dpo0 =
133  (vnet_buffer (p0)->ip.flow_hash &
134  (lb0->lb_n_buckets_minus_1)));
135  }
136  else
137  {
138  dpo0 = load_balance_get_bucket_i (lb0, 0);
139  }
140  if (PREDICT_FALSE (lb1->lb_n_buckets > 1))
141  {
142  flow_hash_config1 = lb1->lb_hash_config;
143  vnet_buffer (p1)->ip.flow_hash =
144  ip6_compute_flow_hash (ip1, flow_hash_config1);
145  dpo1 =
147  (vnet_buffer (p1)->ip.flow_hash &
148  (lb1->lb_n_buckets_minus_1)));
149  }
150  else
151  {
152  dpo1 = load_balance_get_bucket_i (lb1, 0);
153  }
154  next0 = dpo0->dpoi_next_node;
155  next1 = dpo1->dpoi_next_node;
156 
157  /* Only process the HBH Option Header if explicitly configured to do so */
158  if (PREDICT_FALSE
159  (ip0->protocol == IP_PROTOCOL_IP6_HOP_BY_HOP_OPTIONS))
160  {
161  next0 = (dpo_is_adj (dpo0) && im->hbh_enabled) ?
163  }
164  if (PREDICT_FALSE
165  (ip1->protocol == IP_PROTOCOL_IP6_HOP_BY_HOP_OPTIONS))
166  {
167  next1 = (dpo_is_adj (dpo1) && im->hbh_enabled) ?
169  }
170  vnet_buffer (p0)->ip.adj_index[VLIB_TX] = dpo0->dpoi_index;
171  vnet_buffer (p1)->ip.adj_index[VLIB_TX] = dpo1->dpoi_index;
172 
174  (cm, thread_index, lbi0, 1, vlib_buffer_length_in_chain (vm, p0));
176  (cm, thread_index, lbi1, 1, vlib_buffer_length_in_chain (vm, p1));
177 
178  from += 2;
179  to_next += 2;
180  n_left_to_next -= 2;
181  n_left_from -= 2;
182 
183  wrong_next = (next0 != next) + 2 * (next1 != next);
184  if (PREDICT_FALSE (wrong_next != 0))
185  {
186  switch (wrong_next)
187  {
188  case 1:
189  /* A B A */
190  to_next[-2] = pi1;
191  to_next -= 1;
192  n_left_to_next += 1;
193  vlib_set_next_frame_buffer (vm, node, next0, pi0);
194  break;
195 
196  case 2:
197  /* A A B */
198  to_next -= 1;
199  n_left_to_next += 1;
200  vlib_set_next_frame_buffer (vm, node, next1, pi1);
201  break;
202 
203  case 3:
204  /* A B C */
205  to_next -= 2;
206  n_left_to_next += 2;
207  vlib_set_next_frame_buffer (vm, node, next0, pi0);
208  vlib_set_next_frame_buffer (vm, node, next1, pi1);
209  if (next0 == next1)
210  {
211  /* A B B */
212  vlib_put_next_frame (vm, node, next, n_left_to_next);
213  next = next1;
214  vlib_get_next_frame (vm, node, next, to_next,
215  n_left_to_next);
216  }
217  }
218  }
219  }
220 
221  while (n_left_from > 0 && n_left_to_next > 0)
222  {
223  vlib_buffer_t *p0;
224  ip6_header_t *ip0;
225  u32 pi0, lbi0;
226  ip_lookup_next_t next0;
227  load_balance_t *lb0;
228  ip6_address_t *dst_addr0;
229  u32 flow_hash_config0;
230  const dpo_id_t *dpo0;
231 
232  pi0 = from[0];
233  to_next[0] = pi0;
234 
235  p0 = vlib_get_buffer (vm, pi0);
236  ip0 = vlib_buffer_get_current (p0);
237  dst_addr0 = &ip0->dst_address;
238  ip_lookup_set_buffer_fib_index (im->fib_index_by_sw_if_index, p0);
239  lbi0 = ip6_fib_table_fwding_lookup (vnet_buffer (p0)->ip.fib_index,
240  dst_addr0);
241 
242  lb0 = load_balance_get (lbi0);
243  flow_hash_config0 = lb0->lb_hash_config;
244 
245  vnet_buffer (p0)->ip.flow_hash = 0;
246  ASSERT (lb0->lb_n_buckets > 0);
247  ASSERT (is_pow2 (lb0->lb_n_buckets));
248 
249  if (PREDICT_FALSE (lb0->lb_n_buckets > 1))
250  {
251  flow_hash_config0 = lb0->lb_hash_config;
252  vnet_buffer (p0)->ip.flow_hash =
253  ip6_compute_flow_hash (ip0, flow_hash_config0);
254  dpo0 =
256  (vnet_buffer (p0)->ip.flow_hash &
257  (lb0->lb_n_buckets_minus_1)));
258  }
259  else
260  {
261  dpo0 = load_balance_get_bucket_i (lb0, 0);
262  }
263 
264  dpo0 = load_balance_get_bucket_i (lb0,
265  (vnet_buffer (p0)->ip.flow_hash &
266  lb0->lb_n_buckets_minus_1));
267  next0 = dpo0->dpoi_next_node;
268 
269  /* Only process the HBH Option Header if explicitly configured to do so */
270  if (PREDICT_FALSE
271  (ip0->protocol == IP_PROTOCOL_IP6_HOP_BY_HOP_OPTIONS))
272  {
273  next0 = (dpo_is_adj (dpo0) && im->hbh_enabled) ?
275  }
276  vnet_buffer (p0)->ip.adj_index[VLIB_TX] = dpo0->dpoi_index;
277 
279  (cm, thread_index, lbi0, 1, vlib_buffer_length_in_chain (vm, p0));
280 
281  from += 1;
282  to_next += 1;
283  n_left_to_next -= 1;
284  n_left_from -= 1;
285 
286  if (PREDICT_FALSE (next0 != next))
287  {
288  n_left_to_next += 1;
289  vlib_put_next_frame (vm, node, next, n_left_to_next);
290  next = next0;
291  vlib_get_next_frame (vm, node, next, to_next, n_left_to_next);
292  to_next[0] = pi0;
293  to_next += 1;
294  n_left_to_next -= 1;
295  }
296  }
297 
298  vlib_put_next_frame (vm, node, next, n_left_to_next);
299  }
300 
301  if (node->flags & VLIB_NODE_FLAG_TRACE)
303 
304  return frame->n_vectors;
305 }
306 
307 #endif /*__included_ip6_forward_h__ */
308 
309 /*
310  * fd.io coding-style-patch-verification: ON
311  *
312  * Local Variables:
313  * eval: (c-set-style "gnu")
314  * End:
315  */
dpo_id_t_::dpoi_next_node
u16 dpoi_next_node
The next VLIB node to follow.
Definition: dpo.h:186
im
vnet_interface_main_t * im
Definition: interface_output.c:395
load_balance_t_::lb_n_buckets
u16 lb_n_buckets
number of buckets in the load-balance.
Definition: load_balance.h:116
dpo_id_t_::dpoi_index
index_t dpoi_index
the index of objects of that type
Definition: dpo.h:190
thread_index
u32 thread_index
Definition: nat44_ei_hairpinning.c:492
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
load_balance_map.h
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
ip6_header_t::protocol
u8 protocol
Definition: ip6_packet.h:304
next
u16 * next
Definition: nat44_ei_out2in.c:718
node
vlib_main_t vlib_node_runtime_t * node
Definition: nat44_ei.c:3047
load_balance_t_::lb_hash_config
flow_hash_config_t lb_hash_config
the hash config to use when selecting a bucket.
Definition: load_balance.h:161
vm
vlib_main_t * vm
X-connect all packets from the HOST to the PHY.
Definition: nat44_ei.c:3047
IP6_LOOKUP_NEXT_HOP_BY_HOP
@ IP6_LOOKUP_NEXT_HOP_BY_HOP
Definition: adj.h:102
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
CLIB_PREFETCH
#define CLIB_PREFETCH(addr, size, type)
Definition: cache.h:80
load_balance_main
load_balance_main_t load_balance_main
The one instance of load-balance main.
Definition: load_balance.c:59
load_balance_get_fwd_bucket
static const dpo_id_t * load_balance_get_fwd_bucket(const load_balance_t *lb, u16 bucket)
Definition: load_balance_map.h:94
ip6_compute_flow_hash
static u32 ip6_compute_flow_hash(const ip6_header_t *ip, flow_hash_config_t flow_hash_config)
Definition: ip6_inlines.h:49
vnet_buffer
#define vnet_buffer(b)
Definition: buffer.h:437
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
uword
u64 uword
Definition: types.h:112
vlib_main_t::thread_index
u32 thread_index
Definition: main.h:213
load_balance_get_bucket_i
static const dpo_id_t * load_balance_get_bucket_i(const load_balance_t *lb, u32 bucket)
Definition: load_balance.h:229
ip6_header_t::dst_address
ip6_address_t dst_address
Definition: ip6_packet.h:310
cm
vnet_feature_config_main_t * cm
Definition: nat44_ei_hairpinning.c:591
ip6_inlines.h
ip6_fib_table_fwding_lookup
static u32 ip6_fib_table_fwding_lookup(u32 fib_index, const ip6_address_t *dst)
Definition: ip6_fib.h:115
ip6_main
ip6_main_t ip6_main
Definition: ip6_forward.c:2787
ip_lookup_next_t
ip_lookup_next_t
An adjacency is a representation of an attached L3 peer.
Definition: adj.h:50
always_inline
#define always_inline
Definition: rdma_mlx5dv.h:23
load_balance_main_t_::lbm_to_counters
vlib_combined_counter_main_t lbm_to_counters
Definition: load_balance.h:46
ASSERT
#define ASSERT(truth)
Definition: error_bootstrap.h:69
vlib_combined_counter_main_t
A collection of combined counters.
Definition: counter.h:203
vlib_put_next_frame
vlib_put_next_frame(vm, node, next_index, 0)
vlib_set_next_frame_buffer
static void vlib_set_next_frame_buffer(vlib_main_t *vm, vlib_node_runtime_t *node, u32 next_index, u32 buffer_index)
Definition: node_funcs.h:428
u32
unsigned int u32
Definition: types.h:88
load_balance_get
static load_balance_t * load_balance_get(index_t lbi)
Definition: load_balance.h:220
ip6_header_t
Definition: ip6_packet.h:294
ip6_main_t
Definition: ip6.h:110
ip6_fib.h
ip_lookup_set_buffer_fib_index
static void ip_lookup_set_buffer_fib_index(u32 *fib_index_by_sw_if_index, vlib_buffer_t *b)
Definition: lookup.h:168
vlib_main_t
Definition: main.h:102
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
ip
vl_api_address_t ip
Definition: l2.api:558
dpo_is_adj
int dpo_is_adj(const dpo_id_t *dpo)
Return TRUE is the DPO is any type of adjacency.
Definition: dpo.c:282
vlib_buffer_t::data
u8 data[]
Packet data.
Definition: buffer.h:204
dpo_id_t_
The identity of a DPO is a combination of its type and its instance number/index of objects of that t...
Definition: dpo.h:172
load_balance_t_::lb_n_buckets_minus_1
u16 lb_n_buckets_minus_1
number of buckets in the load-balance - 1.
Definition: load_balance.h:121
load_balance_t_
The FIB DPO provieds;.
Definition: load_balance.h:106
vlib_node_runtime_t
Definition: node.h:454
from
from
Definition: nat44_ei_hairpinning.c:415
is_pow2
static uword is_pow2(uword x)
Definition: clib.h:267
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
ip6_lookup_inline
static uword ip6_lookup_inline(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame)
Definition: ip6_forward.h:56
VLIB_TX
@ VLIB_TX
Definition: defs.h:47
ip6_forward_next_trace
void ip6_forward_next_trace(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame, vlib_rx_or_tx_t which_adj_index)
Definition: ip6_forward.c:1006
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
VLIB buffer representation.
Definition: buffer.h:111