FD.io VPP  v21.01.1
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  */
72 extern ip6_fib_table_instance_t ip6_fib_table[IP6_FIB_NUM_TABLES];
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 
124  table = &ip6_fib_table[IP6_FIB_TABLE_FWDING];
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 {
216  return (pool_elt_at_index (ip6_main.v6_fibs, index));
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 
enum ip6_fib_table_instance_type_t_ ip6_fib_table_instance_type_t
Enumeration of the FIB table instance types.
enum fib_source_t_ fib_source_t
The different sources that can create a route.
The table that stores ALL routes learned by the DP.
Definition: ip6_fib.h:50
static u32 ip6_fib_table_fwding_lookup(u32 fib_index, const ip6_address_t *dst)
Definition: ip6_fib.h:115
ip6_fib_t * v6_fibs
Definition: ip6.h:118
vl_api_wireguard_peer_flags_t flags
Definition: wireguard.api:105
static ip6_fib_t * ip6_fib_get(fib_node_index_t index)
Definition: ip6_fib.h:213
int dpo_is_adj(const dpo_id_t *dpo)
Return TRUE is the DPO is any type of adjacency.
Definition: dpo.c:280
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
unsigned long u64
Definition: types.h:89
Definitions for all things IP (v4|v6) unicast and multicast lookup related.
enum fib_table_flags_t_ fib_table_flags_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:41
vl_api_address_t src
Definition: gre.api:54
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
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
u16 mask
Definition: flow_types.api:52
vhost_vring_addr_t addr
Definition: vhost_user.h:111
ip6_address_t src_address
Definition: ip6_packet.h:310
u8 * prefix_lengths_in_search_order
Definition: ip6_fib.h:65
unsigned char u8
Definition: types.h:56
clib_bihash_24_8_t ip6_hash
Definition: ip6_fib.h:61
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
Aggregate type for a prefix.
Definition: fib_types.h:202
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
const cJSON *const b
Definition: cJSON.h:255
A representation of a single IP6 table.
Definition: ip6_fib.h:58
unsigned int u32
Definition: types.h:88
The identity of a DPO is a combination of its type and its instance number/index of objects of that t...
Definition: dpo.h:170
#define hash_get(h, key)
Definition: hash.h:249
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
#define pool_elt_at_index(p, i)
Returns pointer to element at given index.
Definition: pool.h:546
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
void ip6_fib_table_destroy(u32 fib_index)
Definition: ip6_fib.c:127
static const dpo_id_t * load_balance_get_bucket_i(const load_balance_t *lb, u32 bucket)
Definition: load_balance.h:229
long ctx[MAX_CONNS]
Definition: main.c:144
static u32 ip6_fib_index_from_table_id(u32 table_id)
Definition: ip6_fib.h:220
#define always_inline
Definition: ipsec.h:28
ip6_main_t ip6_main
Definition: ip6_forward.c:2785
vl_api_address_t dst
Definition: gre.api:55
u8 len
Definition: ip_types.api:103
uword * fib_index_by_table_id
Definition: ip6.h:137
u32 ip6_fib_table_create_and_lock(fib_source_t src, fib_table_flags_t flags, u8 *desc)
Definition: ip6_fib.c:119
ip6_address_t fib_masks[129]
Definition: ip6.h:124
ip6_fib_table_instance_type_t_
Enumeration of the FIB table instance types.
Definition: ip6_fib.h:37
This table stores the routes that are used to forward traffic.
Definition: ip6_fib.h:43
sll srl srl sll sra u16x4 i
Definition: vector_sse42.h:317
Definition: ip6.h:61
u32 fib_node_index_t
A typedef of a node index.
Definition: fib_types.h:29
#define pool_is_free_index(P, I)
Use free bitmap to query whether given index is free.
Definition: pool.h:298
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
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
signed int i32
Definition: types.h:77
void ip6_fib_table_entry_remove(u32 fib_index, const ip6_address_t *addr, u32 len)
Definition: ip6_fib.c:283
u8 value
Definition: qos.api:54
#define IP6_FIB_NUM_TABLES
Definition: ip6_fib.h:53
#define ASSERT(truth)
static load_balance_t * load_balance_get(index_t lbi)
Definition: load_balance.h:220
i32 dst_address_length_refcounts[129]
Definition: ip6_fib.h:66
u32 ip6_fib_table_get_index_for_sw_if_index(u32 sw_if_index)
Definition: ip6_fib.c:353
index_t dpoi_index
the index of objects of that type
Definition: dpo.h:188
vl_api_address_t ip
Definition: l2.api:501
struct ip6_fib_table_instance_t_ ip6_fib_table_instance_t
A representation of a single IP6 table.
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
VLIB buffer representation.
Definition: buffer.h:102
u64 uword
Definition: types.h:112
u32 table_id
Definition: wireguard.api:102
u32 index
Definition: flow_types.api:221
uword * non_empty_dst_address_length_bitmap
Definition: ip6_fib.h:64
fib_node_index_t ip6_fib_table_lookup(u32 fib_index, const ip6_address_t *addr, u32 len)
Definition: ip6_fib.c:183
#define vnet_buffer(b)
Definition: buffer.h:417
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
u8 * format_ip6_fib_table_memory(u8 *s, va_list *args)
Definition: ip6_fib.c:600
struct fib_table_t_ * fibs
Definition: ip6.h:115
vl_api_interface_index_t sw_if_index
Definition: wireguard.api:34
Definition: defs.h:46