FD.io VPP  v20.05.1-6-gf53edbc3b
Vector Packet Processing
ip4_mfib.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  * @brief The IPv4 Multicast-FIB
17  *
18  * FIXME
19  *
20  * This IPv4 FIB is used by the protocol independent FIB. So directly using
21  * this APIs in client code is not encouraged. However, this IPv4 FIB can be
22  * used if all the client wants is an IPv4 prefix data-base
23  */
24 
25 #ifndef __IP4_MFIB_H__
26 #define __IP4_MFIB_H__
27 
28 #include <vlib/vlib.h>
29 #include <vnet/ip/ip.h>
30 
31 #include <vnet/mfib/mfib_table.h>
32 
34  const ip4_address_t *src,
35  const ip4_address_t *grp,
36  u32 len);
38  const ip4_address_t *grp,
39  const ip4_address_t *src,
40  u32 len);
42  const ip4_address_t *src,
43  const ip4_address_t *grp,
44  u32 len);
45 
47  const ip4_address_t *grp,
48  const ip4_address_t *src,
49  u32 len);
50 
52  const ip4_address_t *grp,
53  const ip4_address_t *src,
54  u32 len,
55  fib_node_index_t fib_entry_index);
56 extern void ip4_mfib_table_destroy(ip4_mfib_t *fib);
57 
58 /**
59  * @brief
60  * Add/remove the interface from the accepting list of the special MFIB entries
61  */
63  int is_enable);
64 
65 /**
66  * @brief Get the FIB at the given index
67  */
68 static inline ip4_mfib_t *
70 {
71  return (&(pool_elt_at_index(ip4_main.mfibs, index)->v4));
72 }
73 
74 /**
75  * @brief Get or create an IPv4 fib.
76  *
77  * Get or create an IPv4 fib with the provided table ID.
78  *
79  * @param table_id
80  * When set to \c ~0, an arbitrary and unused fib ID is picked
81  * and can be retrieved with \c ret->table_id.
82  * Otherwise, the fib ID to be used to retrieve or create the desired fib.
83  * @returns A pointer to the retrieved or created fib.
84  *
85  */
89 
90 static inline
92 {
93  ip4_main_t * im = &ip4_main;
94  uword * p;
95 
96  p = hash_get (im->mfib_index_by_table_id, table_id);
97  if (!p)
98  return ~0;
99 
100  return p[0];
101 }
102 
104 
105 /**
106  * @brief Walk the IP4 mfib table.
107  *
108  * @param mfib the table to walk
109  * @param fn The function to invoke on each entry visited
110  * @param ctx A context passed in the visit function
111  */
112 extern void ip4_mfib_table_walk(ip4_mfib_t *mfib,
114  void *ctx);
115 
116 /**
117  * @brief format (display) the memory usage for IP4 mfibs
118  */
119 extern u8 * format_ip4_mfib_table_memory(u8 * s, va_list * args);
120 
121 #endif
u8 * format_ip4_mfib_table_memory(u8 *s, va_list *args)
format (display) the memory usage for IP4 mfibs
Definition: ip4_mfib.c:392
vl_api_address_t src
Definition: gre.api:54
void ip4_mfib_interface_enable_disable(u32 sw_if_index, int is_enable)
Add/remove the interface from the accepting list of the special MFIB entries.
Definition: ip4_mfib.c:132
unsigned char u8
Definition: types.h:56
static ip4_mfib_t * ip4_mfib_get(u32 index)
Get the FIB at the given index.
Definition: ip4_mfib.h:69
enum mfib_source_t_ mfib_source_t
Possible [control plane] sources of MFIB entries.
vl_api_interface_index_t sw_if_index
Definition: gre.api:53
void ip4_mfib_table_entry_insert(ip4_mfib_t *fib, const ip4_address_t *grp, const ip4_address_t *src, u32 len, fib_node_index_t fib_entry_index)
Definition: ip4_mfib.c:311
u32 ip4_mfib_table_get_index_for_sw_if_index(u32 sw_if_index)
Definition: ip4_mfib.c:182
void ip4_mfib_table_walk(ip4_mfib_t *mfib, mfib_table_walk_fn_t fn, void *ctx)
Walk the IP4 mfib table.
Definition: ip4_mfib.c:369
unsigned int u32
Definition: types.h:88
struct mfib_table_t_ * mfibs
Vector of MFIBs.
Definition: ip4.h:117
#define hash_get(h, key)
Definition: hash.h:249
#define pool_elt_at_index(p, i)
Returns pointer to element at given index.
Definition: pool.h:534
long ctx[MAX_CONNS]
Definition: main.c:144
Definition: ip4.h:51
fib_node_index_t ip4_mfib_table_lookup_exact_match(const ip4_mfib_t *fib, const ip4_address_t *grp, const ip4_address_t *src, u32 len)
Definition: ip4_mfib.c:216
u8 len
Definition: ip_types.api:92
u32 fib_node_index_t
A typedef of a node index.
Definition: fib_types.h:30
fib_node_index_t ip4_mfib_table_lookup(const ip4_mfib_t *fib, const ip4_address_t *src, const ip4_address_t *grp, u32 len)
The IPv4 Multicast-FIB.
Definition: ip4_mfib.c:241
u32 ip4_mfib_table_find_or_create_and_lock(u32 table_id, mfib_source_t src)
Get or create an IPv4 fib.
Definition: ip4_mfib.c:168
u32 ip4_mfib_table_create_and_lock(mfib_source_t src)
IPv4 main type.
Definition: ip4.h:106
walk_rc_t(* mfib_table_walk_fn_t)(fib_node_index_t fei, void *ctx)
Call back function when walking entries in a FIB table.
Definition: mfib_table.h:554
void ip4_mfib_table_entry_remove(ip4_mfib_t *fib, const ip4_address_t *grp, const ip4_address_t *src, u32 len)
Definition: ip4_mfib.c:342
void ip4_mfib_table_destroy(ip4_mfib_t *fib)
Definition: ip4_mfib.c:102
u64 uword
Definition: types.h:112
ip4_main_t ip4_main
Global ip4 main structure.
Definition: ip4_forward.c:1144
uword * mfib_index_by_table_id
Hash table mapping table id to multicast fib index.
Definition: ip4.h:136
u32 table_id
Definition: fib_types.api:118
static u32 ip4_mfib_index_from_table_id(u32 table_id)
Definition: ip4_mfib.h:91
fib_node_index_t ip4_mfib_table_get_less_specific(const ip4_mfib_t *mfib, const ip4_address_t *src, const ip4_address_t *grp, u32 len)
Definition: ip4_mfib.c:279