FD.io VPP  v21.06-3-gbb25fbf28
Vector Packet Processing
ip6_fib.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 #ifndef __IP6_FIB_H__
17 #define __IP6_FIB_H__
18 
19 #include <vlib/vlib.h>
20 #include <vnet/ip/format.h>
21 #include <vnet/fib/fib_entry.h>
22 #include <vnet/fib/fib_table.h>
23 #include <vnet/ip/lookup.h>
24 #include <vnet/dpo/load_balance.h>
25 #include <vppinfra/bihash_24_8.h>
27 
28 /*
29  * Default size of the ip6 fib hash table
30  */
31 #define IP6_FIB_DEFAULT_HASH_NUM_BUCKETS (64 * 1024)
32 #define IP6_FIB_DEFAULT_HASH_MEMORY_SIZE (32<<20)
33 
34 /**
35  * Enumeration of the FIB table instance types
36  */
38 {
39  /**
40  * This table stores the routes that are used to forward traffic.
41  * The key is the prefix, the result the adjacency to forward on.
42  */
44  /**
45  * The table that stores ALL routes learned by the DP.
46  * Some of these routes may not be ready to install in forwarding
47  * at a given time.
48  * The key in this table is the prefix, the result is the fib_entry_t
49  */
52 
53 #define IP6_FIB_NUM_TABLES (IP6_FIB_TABLE_NON_FWDING+1)
54 
55 /**
56  * A representation of a single IP6 table
57  */
59 {
60  /* The hash table */
61  clib_bihash_24_8_t ip6_hash;
62 
63  /* bitmap / refcounts / vector of mask widths to search */
68 
69 /**
70  * The two FIB tables; fwding and non-fwding
71  */
73 
75  const ip6_address_t *addr,
76  u32 len);
78  const ip6_address_t *addr,
79  u32 len);
80 
81 extern void ip6_fib_table_entry_remove(u32 fib_index,
82  const ip6_address_t *addr,
83  u32 len);
84 
85 extern void ip6_fib_table_entry_insert(u32 fib_index,
86  const ip6_address_t *addr,
87  u32 len,
88  fib_node_index_t fib_entry_index);
89 extern void ip6_fib_table_destroy(u32 fib_index);
90 
91 extern void ip6_fib_table_fwding_dpo_update(u32 fib_index,
92  const ip6_address_t *addr,
93  u32 len,
94  const dpo_id_t *dpo);
95 
96 extern void ip6_fib_table_fwding_dpo_remove(u32 fib_index,
97  const ip6_address_t *addr,
98  u32 len,
99  const dpo_id_t *dpo);
100 
103  const ip6_address_t * dst);
104 
105 /**
106  * @brief Walk all entries in a FIB table
107  * N.B: This is NOT safe to deletes. If you need to delete walk the whole
108  * table and store elements in a vector, then delete the elements
109  */
110 extern void ip6_fib_table_walk(u32 fib_index,
112  void *ctx);
113 
116  const ip6_address_t * dst)
117 {
120  int i, len;
121  int rv;
122  u64 fib;
123 
126 
127  kv.key[0] = dst->as_u64[0];
128  kv.key[1] = dst->as_u64[1];
129  fib = ((u64)((fib_index))<<32);
130 
131  for (i = 0; i < len; i++)
132  {
133  int dst_address_length = table->prefix_lengths_in_search_order[i];
134  ip6_address_t * mask = &ip6_main.fib_masks[dst_address_length];
135 
136  ASSERT(dst_address_length >= 0 && dst_address_length <= 128);
137  //As lengths are decreasing, masks are increasingly specific.
138  kv.key[0] &= mask->as_u64[0];
139  kv.key[1] &= mask->as_u64[1];
140  kv.key[2] = fib | dst_address_length;
141 
142  rv = clib_bihash_search_inline_2_24_8(&table->ip6_hash, &kv, &value);
143  if (rv == 0)
144  return value.value;
145  }
146 
147  /* default route is always present */
148  ASSERT(0);
149  return 0;
150 }
151 
152 /**
153  * @brief Walk all entries in a sub-tree of the FIB table
154  * N.B: This is NOT safe to deletes. If you need to delete walk the whole
155  * table and store elements in a vector, then delete the elements
156  */
157 extern void ip6_fib_table_sub_tree_walk(u32 fib_index,
158  const fib_prefix_t *root,
160  void *ctx);
161 
162 /**
163  * @brief return the DPO that the LB stacks on.
164  */
167  vlib_buffer_t * b,
168  ip6_header_t * i)
169 {
170  if (vnet_buffer (b)->ip.adj_index[VLIB_RX] == ~0)
171  {
172  const dpo_id_t *dpo;
173  index_t lbi;
174 
176  im,
178  &i->src_address);
179 
181 
182  if (dpo_is_adj(dpo))
183  {
184  vnet_buffer (b)->ip.adj_index[VLIB_RX] = dpo->dpoi_index;
185  }
186  }
187  return vnet_buffer (b)->ip.adj_index[VLIB_RX];
188 }
189 
190 /**
191  * \brief Get or create an IPv6 fib.
192  *
193  * Get or create an IPv4 fib with the provided table ID.
194  *
195  * \param im
196  * ip4_main pointer.
197  * \param table_id
198  * When set to \c ~0, an arbitrary and unused fib ID is picked
199  * and can be retrieved with \c ret->table_id.
200  * Otherwise, the fib ID to be used to retrieve or create the desired fib.
201  * \returns A pointer to the retrieved or created fib.
202  *
203  */
205  fib_source_t src);
208  u8* desc);
209 
210 extern u8 *format_ip6_fib_table_memory(u8 * s, va_list * args);
211 
212 static inline ip6_fib_t *
214 {
217 }
218 
219 static inline
221 {
222  ip6_main_t * im = &ip6_main;
223  uword * p;
224 
225  p = hash_get (im->fib_index_by_table_id, table_id);
226  if (!p)
227  return ~0;
228 
229  return p[0];
230 }
231 
233 
234 #endif
235 
load_balance.h
vlib.h
ip6_fib_table_entry_insert
void ip6_fib_table_entry_insert(u32 fib_index, const ip6_address_t *addr, u32 len, fib_node_index_t fib_entry_index)
Definition: ip6_fib.c:314
bihash_24_8.h
im
vnet_interface_main_t * im
Definition: interface_output.c:395
fib_entry.h
ip6_fib_table_lookup
fib_node_index_t ip6_fib_table_lookup(u32 fib_index, const ip6_address_t *addr, u32 len)
Definition: ip6_fib.c:183
dpo_id_t_::dpoi_index
index_t dpoi_index
the index of objects of that type
Definition: dpo.h:190
ip6_fib_table_instance_type_t_
ip6_fib_table_instance_type_t_
Enumeration of the FIB table instance types.
Definition: ip6_fib.h:37
ip6_fib_table_fwding_dpo_update
void ip6_fib_table_fwding_dpo_update(u32 fib_index, const ip6_address_t *addr, u32 len, const dpo_id_t *dpo)
Definition: ip6_fib.c:367
format_ip6_fib_table_memory
u8 * format_ip6_fib_table_memory(u8 *s, va_list *args)
Definition: ip6_fib.c:600
ip6_fib_table
ip6_fib_table_instance_t ip6_fib_table[IP6_FIB_NUM_TABLES]
The two FIB tables; fwding and non-fwding.
Definition: ip6_fib.c:23
pool_elt_at_index
#define pool_elt_at_index(p, i)
Returns pointer to element at given index.
Definition: pool.h:553
bihash_template.h
IP6_FIB_TABLE_NON_FWDING
@ IP6_FIB_TABLE_NON_FWDING
The table that stores ALL routes learned by the DP.
Definition: ip6_fib.h:50
clib_bihash_kv_24_8_t
Definition: bihash_24_8.h:40
fib_table.h
ip6_fib_table_sub_tree_walk
void ip6_fib_table_sub_tree_walk(u32 fib_index, const fib_prefix_t *root, fib_table_walk_fn_t fn, void *ctx)
Walk all entries in a sub-tree of the FIB table N.B: This is NOT safe to deletes.
Definition: ip6_fib.c:528
VLIB_RX
@ VLIB_RX
Definition: defs.h:46
ip6_fib_table_walk
void ip6_fib_table_walk(u32 fib_index, fib_table_walk_fn_t fn, void *ctx)
Walk all entries in a FIB table N.B: This is NOT safe to deletes.
Definition: ip6_fib.c:505
addr
vhost_vring_addr_t addr
Definition: vhost_user.h:130
ip6_fib_index_from_table_id
static u32 ip6_fib_index_from_table_id(u32 table_id)
Definition: ip6_fib.h:220
fib_table_flags_t
enum fib_table_flags_t_ fib_table_flags_t
ip6_fib_get
static ip6_fib_t * ip6_fib_get(fib_node_index_t index)
Definition: ip6_fib.h:213
IP6_FIB_NUM_TABLES
#define IP6_FIB_NUM_TABLES
Definition: ip6_fib.h:53
i32
signed int i32
Definition: types.h:77
pool_is_free_index
#define pool_is_free_index(P, I)
Use free bitmap to query whether given index is free.
Definition: pool.h:302
ip6_fib_table_instance_t_::non_empty_dst_address_length_bitmap
uword * non_empty_dst_address_length_bitmap
Definition: ip6_fib.h:64
ip6_fib_table_entry_remove
void ip6_fib_table_entry_remove(u32 fib_index, const ip6_address_t *addr, u32 len)
Definition: ip6_fib.c:283
vec_len
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
Definition: vec_bootstrap.h:142
len
u8 len
Definition: ip_types.api:103
ip6_fib_table_instance_t_::dst_address_length_refcounts
i32 dst_address_length_refcounts[129]
Definition: ip6_fib.h:66
vnet_buffer
#define vnet_buffer(b)
Definition: buffer.h:437
format.h
ip6_main_t::v6_fibs
ip6_fib_t * v6_fibs
Definition: ip6.h:118
index_t
u32 index_t
A Data-Path Object is an object that represents actions that are applied to packets are they are swit...
Definition: dpo.h:43
ip6_fib_table_fwding_dpo_remove
void ip6_fib_table_fwding_dpo_remove(u32 fib_index, const ip6_address_t *addr, u32 len, const dpo_id_t *dpo)
Definition: ip6_fib.c:398
ip6_fib_table_instance_t
struct ip6_fib_table_instance_t_ ip6_fib_table_instance_t
A representation of a single IP6 table.
fib_node_index_t
u32 fib_node_index_t
A typedef of a node index.
Definition: fib_types.h:29
uword
u64 uword
Definition: types.h:112
hash_get
#define hash_get(h, key)
Definition: hash.h:249
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
i
sll srl srl sll sra u16x4 i
Definition: vector_sse42.h:261
mask
vl_api_pnat_mask_t mask
Definition: pnat.api:45
ip6_src_lookup_for_packet
static u32 ip6_src_lookup_for_packet(ip6_main_t *im, vlib_buffer_t *b, ip6_header_t *i)
return the DPO that the LB stacks on.
Definition: ip6_fib.h:166
ip6_main_t::fibs
struct fib_table_t_ * fibs
Definition: ip6.h:115
ip6_fib_t
Definition: ip6.h:61
src
vl_api_address_t src
Definition: gre.api:54
ip6_fib_table_lookup_exact_match
fib_node_index_t ip6_fib_table_lookup_exact_match(u32 fib_index, const ip6_address_t *addr, u32 len)
Definition: ip6_fib.c:229
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
fib_table_walk_fn_t
fib_table_walk_rc_t(* fib_table_walk_fn_t)(fib_node_index_t fei, void *ctx)
Call back function when walking entries in a FIB table.
Definition: fib_table.h:930
ip6_fib_table_destroy
void ip6_fib_table_destroy(u32 fib_index)
Definition: ip6_fib.c:127
ip6_main
ip6_main_t ip6_main
Definition: ip6_forward.c:2787
index
u32 index
Definition: flow_types.api:221
always_inline
#define always_inline
Definition: rdma_mlx5dv.h:23
ip6_fib_table_find_or_create_and_lock
u32 ip6_fib_table_find_or_create_and_lock(u32 table_id, fib_source_t src)
Get or create an IPv6 fib.
Definition: ip6_fib.c:102
u64
unsigned long u64
Definition: types.h:89
ASSERT
#define ASSERT(truth)
Definition: error_bootstrap.h:69
ip6_fib_table_instance_type_t
enum ip6_fib_table_instance_type_t_ ip6_fib_table_instance_type_t
Enumeration of the FIB table instance types.
u32
unsigned int u32
Definition: types.h:88
ip6_fib_table_fwding_lookup_with_if_index
u32 ip6_fib_table_fwding_lookup_with_if_index(ip6_main_t *im, u32 sw_if_index, const ip6_address_t *dst)
Definition: ip6_fib.c:344
ip6_main_t::fib_masks
ip6_address_t fib_masks[129]
Definition: ip6.h:124
table_id
u32 table_id
Definition: wireguard.api:102
dst
vl_api_ip4_address_t dst
Definition: pnat.api:41
ctx
long ctx[MAX_CONNS]
Definition: main.c:144
clib_bihash_kv_24_8_t::key
u64 key[3]
Definition: bihash_24_8.h:42
load_balance_get
static load_balance_t * load_balance_get(index_t lbi)
Definition: load_balance.h:220
value
u8 value
Definition: qos.api:54
ip6_header_t
Definition: ip6_packet.h:294
ip6_main_t
Definition: ip6.h:110
IP6_FIB_TABLE_FWDING
@ IP6_FIB_TABLE_FWDING
This table stores the routes that are used to forward traffic.
Definition: ip6_fib.h:43
b
vlib_buffer_t ** b
Definition: nat44_ei_out2in.c:717
u8
unsigned char u8
Definition: types.h:56
ip
vl_api_address_t ip
Definition: l2.api:558
lookup.h
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
fib_source_t
enum fib_source_t_ fib_source_t
The different sources that can create a route.
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
ip6_fib_table_instance_t_
A representation of a single IP6 table.
Definition: ip6_fib.h:58
rv
int __clib_unused rv
Definition: application.c:491
ip6_fib_table_create_and_lock
u32 ip6_fib_table_create_and_lock(fib_source_t src, fib_table_flags_t flags, u8 *desc)
Definition: ip6_fib.c:119
sw_if_index
vl_api_interface_index_t sw_if_index
Definition: wireguard.api:34
ip6_fib_table_instance_t_::prefix_lengths_in_search_order
u8 * prefix_lengths_in_search_order
Definition: ip6_fib.h:65
ip6_fib_table_get_index_for_sw_if_index
u32 ip6_fib_table_get_index_for_sw_if_index(u32 sw_if_index)
Definition: ip6_fib.c:353
fib_prefix_t_
Aggregate type for a prefix.
Definition: fib_types.h:202
ip6_fib_table_instance_t_::ip6_hash
clib_bihash_24_8_t ip6_hash
Definition: ip6_fib.h:61
vlib_buffer_t
VLIB buffer representation.
Definition: buffer.h:111
flags
vl_api_wireguard_peer_flags_t flags
Definition: wireguard.api:105