blob: 0964f3ab1331bcf40c5c6e50141de7c2d505e0cc [file] [log] [blame]
Neale Rannsd6953332021-08-10 07:39:18 +00001/*
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 FIB
17 *
18 * FIBs are composed of two prefix data-bases (akak tables). The non-forwarding
19 * table contains all the routes that the control plane has programmed, the
20 * forwarding table contains the sub-set of those routes that can be used to
21 * forward packets.
22 * In the IPv4 FIB the non-forwarding table is an array of hash tables indexed
23 * by mask length, the forwarding table is an mtrie
24 *
25 * This IPv4 FIB is used by the protocol independent FIB. So directly using
26 * this APIs in client code is not encouraged. However, this IPv4 FIB can be
27 * used if all the client wants is an IPv4 prefix data-base
28 */
29
30#ifndef __IP4_FIB_8_H__
31#define __IP4_FIB_8_H__
32
33#include <vnet/fib/ip4_fib_hash.h>
34#include <vnet/ip/ip4_mtrie.h>
35
36typedef struct ip4_fib_8_t_
37{
38 /** Required for pool_get_aligned */
39 CLIB_CACHE_LINE_ALIGN_MARK(cacheline0);
40
41 /**
42 * Mtrie for fast lookups. Hash is used to maintain overlapping prefixes.
43 * First member so it's in the first cacheline.
44 */
45 ip4_mtrie_8_t mtrie;
46
47 /**
48 * The hash table DB
49 */
50 ip4_fib_hash_t hash;
51} ip4_fib_8_t;
52
53extern ip4_fib_8_t *ip4_fib_8s;
54
55extern fib_node_index_t ip4_fib_8_table_lookup(const ip4_fib_8_t *fib,
56 const ip4_address_t *addr,
57 u32 len);
58extern fib_node_index_t ip4_fib_8_table_lookup_exact_match(const ip4_fib_8_t *fib,
59 const ip4_address_t *addr,
60 u32 len);
61
62extern void ip4_fib_8_table_entry_remove(ip4_fib_8_t *fib,
63 const ip4_address_t *addr,
64 u32 len);
65
66extern void ip4_fib_8_table_entry_insert(ip4_fib_8_t *fib,
67 const ip4_address_t *addr,
68 u32 len,
69 fib_node_index_t fib_entry_index);
70extern void ip4_fib_8_table_free(ip4_fib_8_t *fib);
71extern void ip4_fib_8_table_init(ip4_fib_8_t *fib);
72
73extern void ip4_fib_8_table_fwding_dpo_update(ip4_fib_8_t *fib,
74 const ip4_address_t *addr,
75 u32 len,
76 const dpo_id_t *dpo);
77
78extern void ip4_fib_8_table_fwding_dpo_remove(ip4_fib_8_t *fib,
79 const ip4_address_t *addr,
80 u32 len,
81 const dpo_id_t *dpo,
82 fib_node_index_t cover_index);
83extern u32 ip4_fib_8_table_lookup_lb (ip4_fib_8_t *fib,
84 const ip4_address_t * dst);
85
86/**
87 * @brief Walk all entries in a FIB table
88 * N.B: This is NOT safe to deletes. If you need to delete walk the whole
89 * table and store elements in a vector, then delete the elements
90 */
91extern void ip4_fib_8_table_walk(ip4_fib_8_t *fib,
92 fib_table_walk_fn_t fn,
93 void *ctx);
94
95/**
96 * @brief Walk all entries in a sub-tree of the FIB table
97 * N.B: This is NOT safe to deletes. If you need to delete walk the whole
98 * table and store elements in a vector, then delete the elements
99 */
100extern void ip4_fib_8_table_sub_tree_walk(ip4_fib_8_t *fib,
101 const fib_prefix_t *root,
102 fib_table_walk_fn_t fn,
103 void *ctx);
104
105#endif
106