blob: 78da3746f17d30a930cd55f206076af943001f73 [file] [log] [blame]
Neale Ranns0bfe5d82016-08-25 15:29:12 +01001/*
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
26extern fib_node_index_t ip6_fib_table_lookup(u32 fib_index,
27 const ip6_address_t *addr,
28 u32 len);
29extern fib_node_index_t ip6_fib_table_lookup_exact_match(u32 fib_index,
30 const ip6_address_t *addr,
31 u32 len);
32
33extern void ip6_fib_table_entry_remove(u32 fib_index,
34 const ip6_address_t *addr,
35 u32 len);
36
37extern 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);
41extern void ip6_fib_table_destroy(u32 fib_index);
42
43extern 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
48extern 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
53u32 ip6_fib_table_fwding_lookup_with_if_index(ip6_main_t * im,
54 u32 sw_if_index,
55 const ip6_address_t * dst);
56u32 ip6_fib_table_fwding_lookup(ip6_main_t * im,
Neale Ranns32e1c012016-11-22 17:07:28 +000057 u32 fib_index,
Neale Ranns0bfe5d82016-08-25 15:29:12 +010058 const ip6_address_t * dst);
59
Neale Ranns0bfe5d82016-08-25 15:29:12 +010060/**
Neale Ranns32e1c012016-11-22 17:07:28 +000061 * @brief Walk all entries in a FIB table
62 * N.B: This is NOT safe to deletes. If you need to delete walk the whole
63 * table and store elements in a vector, then delete the elements
64 */
65extern void ip6_fib_table_walk(u32 fib_index,
66 fib_table_walk_fn_t fn,
67 void *ctx);
68
69/**
Neale Ranns0bfe5d82016-08-25 15:29:12 +010070 * @biref return the DPO that the LB stacks on.
71 */
72always_inline u32
73ip6_src_lookup_for_packet (ip6_main_t * im,
74 vlib_buffer_t * b,
75 ip6_header_t * i)
76{
77 if (vnet_buffer (b)->ip.adj_index[VLIB_RX] == ~0)
78 {
79 const dpo_id_t *dpo;
80 index_t lbi;
81
82 lbi = ip6_fib_table_fwding_lookup_with_if_index(
83 im,
84 vnet_buffer (b)->sw_if_index[VLIB_RX],
85 &i->src_address);
86
87 dpo = load_balance_get_bucket_i(load_balance_get(lbi), 0);
88
89 if (dpo_is_adj(dpo))
90 {
91 vnet_buffer (b)->ip.adj_index[VLIB_RX] = dpo->dpoi_index;
92 }
93 }
94 return vnet_buffer (b)->ip.adj_index[VLIB_RX];
95}
96
97/**
98 * \brief Get or create an IPv6 fib.
99 *
100 * Get or create an IPv4 fib with the provided table ID.
101 *
102 * \param im
103 * ip4_main pointer.
104 * \param table_id
105 * When set to \c ~0, an arbitrary and unused fib ID is picked
106 * and can be retrieved with \c ret->table_id.
107 * Otherwise, the fib ID to be used to retrieve or create the desired fib.
108 * \returns A pointer to the retrieved or created fib.
109 *
110 */
111extern u32 ip6_fib_table_find_or_create_and_lock(u32 table_id);
112extern u32 ip6_fib_table_create_and_lock(void);
113
114static inline ip6_fib_t *
115ip6_fib_get (fib_node_index_t index)
116{
117 ASSERT(!pool_is_free_index(ip6_main.fibs, index));
118 return (&pool_elt_at_index (ip6_main.fibs, index)->v6);
119}
120
121static inline
122u32 ip6_fib_index_from_table_id (u32 table_id)
123{
124 ip6_main_t * im = &ip6_main;
125 uword * p;
126
127 p = hash_get (im->fib_index_by_table_id, table_id);
128 if (!p)
129 return ~0;
130
131 return p[0];
132}
133
134extern u32 ip6_fib_table_get_index_for_sw_if_index(u32 sw_if_index);
135
136extern flow_hash_config_t ip6_fib_table_get_flow_hash_config(u32 fib_index);
137
138#endif
139