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:
7 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 * @brief The IPv4 Multicast-FIB
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
25 #ifndef __IP6_MFIB_H__
26 #define __IP6_MFIB_H__
28 #include <vppinfra/bihash_40_8.h>
29 #include <vppinfra/bihash_template.h>
31 #include <vlib/vlib.h>
32 #include <vnet/ip/ip.h>
34 #include <vnet/mfib/mfib_table.h>
37 * Default size of the ip6 fib hash table
39 #define IP6_MFIB_DEFAULT_HASH_NUM_BUCKETS (64 * 1024)
40 #define IP6_MFIB_DEFAULT_HASH_MEMORY_SIZE (32<<20)
44 * A representation of a single IP6 mfib table
46 typedef struct ip6_mfib_table_instance_t_
49 clib_bihash_40_8_t ip6_mhash;
51 /* bitmap / refcounts / vector of mask widths to search */
52 uword *non_empty_dst_address_length_bitmap;
53 u16 *prefix_lengths_in_search_order;
54 i32 dst_address_length_refcounts[257];
55 } ip6_mfib_table_instance_t;
58 * the single MFIB table
60 extern ip6_mfib_table_instance_t ip6_mfib_table;
62 extern fib_node_index_t ip6_mfib_table_lookup(const ip6_mfib_t *fib,
63 const ip6_address_t *src,
64 const ip6_address_t *grp,
66 extern fib_node_index_t ip6_mfib_table_fwd_lookup(const ip6_mfib_t *fib,
67 const ip6_address_t *src,
68 const ip6_address_t *grp);
69 extern fib_node_index_t ip6_mfib_table_lookup_exact_match(const ip6_mfib_t *fib,
70 const ip6_address_t *grp,
71 const ip6_address_t *src,
73 extern fib_node_index_t ip6_mfib_table_get_less_specific (const ip6_mfib_t *mfib,
74 const ip6_address_t *src,
75 const ip6_address_t *grp,
78 extern void ip6_mfib_table_entry_remove(ip6_mfib_t *fib,
79 const ip6_address_t *grp,
80 const ip6_address_t *src,
83 extern void ip6_mfib_table_entry_insert(ip6_mfib_t *fib,
84 const ip6_address_t *grp,
85 const ip6_address_t *src,
87 fib_node_index_t fib_entry_index);
88 extern void ip6_mfib_table_destroy(ip6_mfib_t *fib);
92 * Add/remove the interface from the accepting list of the special MFIB entries
94 extern void ip6_mfib_interface_enable_disable(u32 sw_if_index,
98 * @brief Get the FIB at the given index
100 static inline ip6_mfib_t *
101 ip6_mfib_get (u32 index)
103 return (&(pool_elt_at_index(ip6_main.mfibs, index)->v6));
107 * @brief Get or create an IPv4 fib.
109 * Get or create an IPv4 fib with the provided table ID.
112 * When set to \c ~0, an arbitrary and unused fib ID is picked
113 * and can be retrieved with \c ret->table_id.
114 * Otherwise, the fib ID to be used to retrieve or create the desired fib.
115 * @returns A pointer to the retrieved or created fib.
118 extern u32 ip6_mfib_table_find_or_create_and_lock(u32 table_id,
120 extern u32 ip6_mfib_table_create_and_lock(mfib_source_t src);
124 u32 ip6_mfib_index_from_table_id (u32 table_id)
126 ip6_main_t * im = &ip6_main;
129 p = hash_get (im->mfib_index_by_table_id, table_id);
136 extern u32 ip6_mfib_table_get_index_for_sw_if_index(u32 sw_if_index);
139 * @brief Data-plane lookup function
141 extern fib_node_index_t ip6_mfib_table_lookup2(const ip6_mfib_t *mfib,
142 const ip6_address_t *src,
143 const ip6_address_t *grp);
146 * @brief Walk the IP6 mfib table.
148 * @param mfib the table to walk
149 * @param fn The function to invoke on each entry visited
150 * @param ctx A context passed in the visit function
152 extern void ip6_mfib_table_walk (ip6_mfib_t *mfib,
153 mfib_table_walk_fn_t fn,
157 * @brief format (display) ipv6 MFIB mempry usage
159 extern u8 *format_ip6_mfib_table_memory(u8 * s, va_list * args);