FD.io VPP  v19.01.3-6-g70449b9b9
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 
27  const ip6_address_t *addr,
28  u32 len);
30  const ip6_address_t *addr,
31  u32 len);
32 
33 extern void ip6_fib_table_entry_remove(u32 fib_index,
34  const ip6_address_t *addr,
35  u32 len);
36 
37 extern void ip6_fib_table_entry_insert(u32 fib_index,
38  const ip6_address_t *addr,
39  u32 len,
40  fib_node_index_t fib_entry_index);
41 extern void ip6_fib_table_destroy(u32 fib_index);
42 
43 extern void ip6_fib_table_fwding_dpo_update(u32 fib_index,
44  const ip6_address_t *addr,
45  u32 len,
46  const dpo_id_t *dpo);
47 
48 extern void ip6_fib_table_fwding_dpo_remove(u32 fib_index,
49  const ip6_address_t *addr,
50  u32 len,
51  const dpo_id_t *dpo);
52 
55  const ip6_address_t * dst);
56 
57 /**
58  * @brief Walk all entries in a FIB table
59  * N.B: This is NOT safe to deletes. If you need to delete walk the whole
60  * table and store elements in a vector, then delete the elements
61  */
62 extern void ip6_fib_table_walk(u32 fib_index,
64  void *ctx);
65 
68  u32 fib_index,
69  const ip6_address_t * dst)
70 {
72  clib_bihash_kv_24_8_t kv, value;
73  int i, len;
74  int rv;
75  u64 fib;
76 
79 
80  kv.key[0] = dst->as_u64[0];
81  kv.key[1] = dst->as_u64[1];
82  fib = ((u64)((fib_index))<<32);
83 
84  for (i = 0; i < len; i++)
85  {
86  int dst_address_length = table->prefix_lengths_in_search_order[i];
87  ip6_address_t * mask = &ip6_main.fib_masks[dst_address_length];
88 
89  ASSERT(dst_address_length >= 0 && dst_address_length <= 128);
90  //As lengths are decreasing, masks are increasingly specific.
91  kv.key[0] &= mask->as_u64[0];
92  kv.key[1] &= mask->as_u64[1];
93  kv.key[2] = fib | dst_address_length;
94 
95  rv = clib_bihash_search_inline_2_24_8(&table->ip6_hash, &kv, &value);
96  if (rv == 0)
97  return value.value;
98  }
99 
100  /* default route is always present */
101  ASSERT(0);
102  return 0;
103 }
104 
105 /**
106  * @brief Walk all entries in a sub-tree of the 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_sub_tree_walk(u32 fib_index,
111  const fib_prefix_t *root,
113  void *ctx);
114 
115 /**
116  * @brief return the DPO that the LB stacks on.
117  */
120  vlib_buffer_t * b,
121  ip6_header_t * i)
122 {
123  if (vnet_buffer (b)->ip.adj_index[VLIB_RX] == ~0)
124  {
125  const dpo_id_t *dpo;
126  index_t lbi;
127 
129  im,
131  &i->src_address);
132 
134 
135  if (dpo_is_adj(dpo))
136  {
137  vnet_buffer (b)->ip.adj_index[VLIB_RX] = dpo->dpoi_index;
138  }
139  }
140  return vnet_buffer (b)->ip.adj_index[VLIB_RX];
141 }
142 
143 /**
144  * \brief Get or create an IPv6 fib.
145  *
146  * Get or create an IPv4 fib with the provided table ID.
147  *
148  * \param im
149  * ip4_main pointer.
150  * \param table_id
151  * When set to \c ~0, an arbitrary and unused fib ID is picked
152  * and can be retrieved with \c ret->table_id.
153  * Otherwise, the fib ID to be used to retrieve or create the desired fib.
154  * \returns A pointer to the retrieved or created fib.
155  *
156  */
158  fib_source_t src);
161  u8* desc);
162 
163 extern u8 *format_ip6_fib_table_memory(u8 * s, va_list * args);
164 
165 static inline ip6_fib_t *
167 {
169  return (pool_elt_at_index (ip6_main.v6_fibs, index));
170 }
171 
172 static inline
174 {
175  ip6_main_t * im = &ip6_main;
176  uword * p;
177 
178  p = hash_get (im->fib_index_by_table_id, table_id);
179  if (!p)
180  return ~0;
181 
182  return p[0];
183 }
184 
186 
187 #endif
188 
u32 flags
Definition: vhost_user.h:115
vl_api_address_t src
Definition: vxlan_gbp.api:32
ip6_fib_t * v6_fibs
Definition: ip6.h:184
static ip6_fib_t * ip6_fib_get(fib_node_index_t index)
Definition: ip6_fib.h:166
int dpo_is_adj(const dpo_id_t *dpo)
Return TRUE is the DPO is any type of adjacency.
Definition: dpo.c:277
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:96
u64 as_u64[2]
Definition: ip6_packet.h:51
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
int i
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:317
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:340
static u32 ip6_fib_table_fwding_lookup(ip6_main_t *im, u32 fib_index, const ip6_address_t *dst)
Definition: ip6_fib.h:67
vhost_vring_addr_t addr
Definition: vhost_user.h:121
ip6_address_t src_address
Definition: ip6_packet.h:378
u8 * prefix_lengths_in_search_order
Definition: ip6.h:148
unsigned char u8
Definition: types.h:56
clib_bihash_24_8_t ip6_hash
Definition: ip6.h:144
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:500
u32 sw_if_index
Definition: vxlan_gbp.api:37
#define always_inline
Definition: clib.h:98
Aggregrate type for a prefix.
Definition: fib_types.h:203
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:119
A represenation of a single IP6 table.
Definition: ip6.h:141
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:168
#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:288
#define pool_elt_at_index(p, i)
Returns pointer to element at given index.
Definition: pool.h:511
fib_node_index_t ip6_fib_table_lookup_exact_match(u32 fib_index, const ip6_address_t *addr, u32 len)
Definition: ip6_fib.c:218
void ip6_fib_table_destroy(u32 fib_index)
Definition: ip6_fib.c:121
enum fib_source_t_ fib_source_t
The different sources that can create a route.
static const dpo_id_t * load_balance_get_bucket_i(const load_balance_t *lb, u32 bucket)
Definition: load_balance.h:228
long ctx[MAX_CONNS]
Definition: main.c:144
static u32 ip6_fib_index_from_table_id(u32 table_id)
Definition: ip6_fib.h:173
u8 len
Definition: ip_types.api:49
uword * fib_index_by_table_id
Definition: ip6.h:203
u32 ip6_fib_table_create_and_lock(fib_source_t src, fib_table_flags_t flags, u8 *desc)
Definition: ip6_fib.c:113
ip6_address_t fib_masks[129]
Definition: ip6.h:190
vl_api_address_t dst
Definition: vxlan_gbp.api:33
Definition: ip6.h:68
This table stores the routes that are used to forward traffic.
Definition: ip6.h:126
u32 fib_node_index_t
A typedef of a node index.
Definition: fib_types.h:30
#define pool_is_free_index(P, I)
Use free bitmap to query whether given index is free.
Definition: pool.h:283
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:882
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:477
void ip6_fib_table_entry_remove(u32 fib_index, const ip6_address_t *addr, u32 len)
Definition: ip6_fib.c:257
#define ASSERT(truth)
ip6_main_t ip6_main
Definition: ip6_forward.c:2624
static load_balance_t * load_balance_get(index_t lbi)
Definition: load_balance.h:219
ip6_fib_table_instance_t ip6_table[IP6_FIB_NUM_TABLES]
The two FIB tables; fwding and non-fwding.
Definition: ip6.h:171
u32 ip6_fib_table_get_index_for_sw_if_index(u32 sw_if_index)
Definition: ip6_fib.c:326
index_t dpoi_index
the index of objects of that type
Definition: dpo.h:184
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
u64 uword
Definition: types.h:112
fib_node_index_t ip6_fib_table_lookup(u32 fib_index, const ip6_address_t *addr, u32 len)
Definition: ip6_fib.c:172
#define vnet_buffer(b)
Definition: buffer.h:368
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:370
u8 * format_ip6_fib_table_memory(u8 *s, va_list *args)
Definition: ip6_fib.c:572
struct fib_table_t_ * fibs
Definition: ip6.h:181
Definition: defs.h:46