132e1c010SNeale Ranns/*
232e1c010SNeale Ranns * Copyright (c) 2016 Cisco and/or its affiliates.
332e1c010SNeale Ranns * Licensed under the Apache License, Version 2.0 (the "License");
432e1c010SNeale Ranns * you may not use this file except in compliance with the License.
532e1c010SNeale Ranns * You may obtain a copy of the License at:
632e1c010SNeale Ranns *
732e1c010SNeale Ranns *     http://www.apache.org/licenses/LICENSE-2.0
832e1c010SNeale Ranns *
932e1c010SNeale Ranns * Unless required by applicable law or agreed to in writing, software
1032e1c010SNeale Ranns * distributed under the License is distributed on an "AS IS" BASIS,
1132e1c010SNeale Ranns * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1232e1c010SNeale Ranns * See the License for the specific language governing permissions and
1332e1c010SNeale Ranns * limitations under the License.
1432e1c010SNeale Ranns */
1532e1c010SNeale Ranns/**
1632e1c010SNeale Ranns * @brief The IPv4 Multicast-FIB
1732e1c010SNeale Ranns *
1832e1c010SNeale Ranns * FIXME
1932e1c010SNeale Ranns *
2032e1c010SNeale Ranns * This IPv4 FIB is used by the protocol independent FIB. So directly using
2132e1c010SNeale Ranns * this APIs in client code is not encouraged. However, this IPv4 FIB can be
2232e1c010SNeale Ranns * used if all the client wants is an IPv4 prefix data-base
2332e1c010SNeale Ranns */
2432e1c010SNeale Ranns
2532e1c010SNeale Ranns#ifndef __IP4_MFIB_H__
2632e1c010SNeale Ranns#define __IP4_MFIB_H__
2732e1c010SNeale Ranns
2832e1c010SNeale Ranns#include <vlib/vlib.h>
2932e1c010SNeale Ranns#include <vnet/ip/ip.h>
3032e1c010SNeale Ranns
3132e1c010SNeale Ranns#include <vnet/mfib/mfib_table.h>
3232e1c010SNeale Ranns
3332e1c010SNeale Rannsextern fib_node_index_t ip4_mfib_table_lookup(const ip4_mfib_t *fib,
3432e1c010SNeale Ranns                                              const ip4_address_t *src,
3532e1c010SNeale Ranns                                              const ip4_address_t *grp,
3632e1c010SNeale Ranns                                              u32 len);
3732e1c010SNeale Rannsextern fib_node_index_t ip4_mfib_table_lookup_exact_match(const ip4_mfib_t *fib,
3832e1c010SNeale Ranns                                                          const ip4_address_t *grp,
3932e1c010SNeale Ranns                                                          const ip4_address_t *src,
4032e1c010SNeale Ranns                                                          u32 len);
419e829a85SNeale Rannsextern fib_node_index_t ip4_mfib_table_get_less_specific (const ip4_mfib_t *mfib,
429e829a85SNeale Ranns                                                          const ip4_address_t *src,
439e829a85SNeale Ranns                                                          const ip4_address_t *grp,
449e829a85SNeale Ranns                                                          u32 len);
4532e1c010SNeale Ranns
4632e1c010SNeale Rannsextern void ip4_mfib_table_entry_remove(ip4_mfib_t *fib,
4732e1c010SNeale Ranns                                        const ip4_address_t *grp,
4832e1c010SNeale Ranns                                        const ip4_address_t *src,
4932e1c010SNeale Ranns                                        u32 len);
5032e1c010SNeale Ranns
5132e1c010SNeale Rannsextern void ip4_mfib_table_entry_insert(ip4_mfib_t *fib,
5232e1c010SNeale Ranns                                        const ip4_address_t *grp,
5332e1c010SNeale Ranns                                        const ip4_address_t *src,
5432e1c010SNeale Ranns                                        u32 len,
5532e1c010SNeale Ranns                                        fib_node_index_t fib_entry_index);
5632e1c010SNeale Rannsextern void ip4_mfib_table_destroy(ip4_mfib_t *fib);
5732e1c010SNeale Ranns
5803c254ecSNeale Ranns/**
5903c254ecSNeale Ranns * @brief
6003c254ecSNeale Ranns *  Add/remove the interface from the accepting list of the special MFIB entries
6103c254ecSNeale Ranns */
6203c254ecSNeale Rannsextern void ip4_mfib_interface_enable_disable(u32 sw_if_index,
6303c254ecSNeale Ranns                                              int is_enable);
6403c254ecSNeale Ranns
6532e1c010SNeale Ranns/**
6632e1c010SNeale Ranns * @brief Get the FIB at the given index
6732e1c010SNeale Ranns */
6832e1c010SNeale Rannsstatic inline ip4_mfib_t *
6932e1c010SNeale Rannsip4_mfib_get (u32 index)
7032e1c010SNeale Ranns{
7132e1c010SNeale Ranns    return (&(pool_elt_at_index(ip4_main.mfibs, index)->v4));
7232e1c010SNeale Ranns}
7332e1c010SNeale Ranns
7432e1c010SNeale Ranns/**
7532e1c010SNeale Ranns * @brief Get or create an IPv4 fib.
7632e1c010SNeale Ranns *
7732e1c010SNeale Ranns * Get or create an IPv4 fib with the provided table ID.
7832e1c010SNeale Ranns *
7932e1c010SNeale Ranns * @param table_id
8032e1c010SNeale Ranns *      When set to \c ~0, an arbitrary and unused fib ID is picked
8132e1c010SNeale Ranns *      and can be retrieved with \c ret->table_id.
8232e1c010SNeale Ranns *      Otherwise, the fib ID to be used to retrieve or create the desired fib.
8332e1c010SNeale Ranns * @returns A pointer to the retrieved or created fib.
8432e1c010SNeale Ranns *
8532e1c010SNeale Ranns */
861500254bSNeale Rannsextern u32 ip4_mfib_table_find_or_create_and_lock(u32 table_id,
871500254bSNeale Ranns                                                  mfib_source_t src);
881500254bSNeale Rannsextern u32 ip4_mfib_table_create_and_lock(mfib_source_t src);
8932e1c010SNeale Ranns
9032e1c010SNeale Rannsstatic inline
9132e1c010SNeale Rannsu32 ip4_mfib_index_from_table_id (u32 table_id)
9232e1c010SNeale Ranns{
9332e1c010SNeale Ranns  ip4_main_t * im = &ip4_main;
9432e1c010SNeale Ranns  uword * p;
9532e1c010SNeale Ranns
9632e1c010SNeale Ranns  p = hash_get (im->mfib_index_by_table_id, table_id);
9732e1c010SNeale Ranns  if (!p)
9832e1c010SNeale Ranns    return ~0;
9932e1c010SNeale Ranns
10032e1c010SNeale Ranns  return p[0];
10132e1c010SNeale Ranns}
10232e1c010SNeale Ranns
10332e1c010SNeale Rannsextern u32 ip4_mfib_table_get_index_for_sw_if_index(u32 sw_if_index);
10432e1c010SNeale Ranns
1055a8123bdSNeale Ranns/**
1065a8123bdSNeale Ranns * @brief Walk the IP4 mfib table.
1075a8123bdSNeale Ranns *
1085a8123bdSNeale Ranns * @param mfib the table to walk
1095a8123bdSNeale Ranns * @param fn The function to invoke on each entry visited
1105a8123bdSNeale Ranns * @param ctx A context passed in the visit function
1115a8123bdSNeale Ranns */
112c87aafadSNeale Rannsextern void ip4_mfib_table_walk(ip4_mfib_t *mfib,
113c87aafadSNeale Ranns                                mfib_table_walk_fn_t fn,
114c87aafadSNeale Ranns                                void *ctx);
115c87aafadSNeale Ranns
116c87aafadSNeale Ranns/**
117c87aafadSNeale Ranns * @brief format (display) the memory usage for IP4 mfibs
118c87aafadSNeale Ranns */
119c87aafadSNeale Rannsextern u8 * format_ip4_mfib_table_memory(u8 * s, va_list * args);
12032e1c010SNeale Ranns
12132e1c010SNeale Ranns#endif