FD.io VPP  v19.04.2-12-g66b1689
Vector Packet Processing
adj_midchain_delegate.c
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 #include <vnet/adj/adj_delegate.h>
17 #include <vnet/adj/adj_midchain.h>
18 #include <vnet/fib/fib_table.h>
19 
20 /**
21  * Midchain stacker delegate
22  */
24 {
25  /**
26  * the Fib Entry we are stacked on
27  */
29 
30  /**
31  * The sibling entry on the FIB entry
32  */
35 
36 /**
37  * Pool of delegates
38  */
40 
41 static inline const adj_midchain_delegate_t*
43 {
44  if (NULL != ad)
45  {
46  return (pool_elt_at_index(amd_pool, ad->ad_index));
47  }
48  return (NULL);
49 }
50 
51 static void
54 {
56  adj_get_sw_if_index(ai)) &&
58  {
59  const fib_prefix_t *pfx;
60 
61  pfx = fib_entry_get_prefix(amd->amd_fei);
62 
64  ai,
65  amd->amd_fei,
67  }
68  else
69  {
71  }
72 }
73 
74 void
76 {
78  ip_adjacency_t *adj;
79  adj_delegate_t *ad;
80 
81  /*
82  * if there's a delegate already use that
83  */
84  adj = adj_get(ai);
86 
87  if (NULL != ad)
88  {
89  amd = pool_elt_at_index(amd_pool, ad->ad_index);
90 
92  }
93  /*
94  * else
95  * nothing to stack
96  */
97 }
98 
99 void
101  u32 fib_index,
102  const fib_prefix_t *pfx)
103 {
105  ip_adjacency_t *adj;
106  adj_delegate_t *ad;
107 
108  /*
109  * if there's a delegate already use that
110  */
111  adj = adj_get(ai);
113 
114  if (NULL != ad)
115  {
116  amd = pool_elt_at_index(amd_pool, ad->ad_index);
117  }
118  else
119  {
120  pool_get(amd_pool, amd);
122  adj_delegate_add(adj, ADJ_DELEGATE_MIDCHAIN, amd - amd_pool);
123 
124  amd->amd_fei = fib_table_entry_special_add(fib_index,
125  pfx,
130  ai);
131  }
133 }
134 
135 void
137 {
139 }
140 
141 static void
143 {
145 
146  amd = pool_elt_at_index(amd_pool, ad->ad_index);
147 
150 
151  pool_put(amd_pool, amd);
152 }
153 
154 /**
155  * Print a delegate that represents MIDCHAIN tracking
156  */
157 static u8 *
159 {
161 
162  s = format(s, "MIDCHAIN:[fib-entry:%d]", amd->amd_fei);
163 
164  return (s);
165 }
166 
167 const static adj_delegate_vft_t adj_delegate_vft = {
169  .adv_adj_deleted = adj_midchain_delegate_adj_deleted,
170 };
171 
172 static clib_error_t *
174 {
175  clib_error_t * error = NULL;
176 
178 
179  return (error);
180 }
181 
183 
static const adj_midchain_delegate_t * adj_midchain_from_const_base(const adj_delegate_t *ad)
fib_protocol_t fp_proto
protocol type
Definition: fib_types.h:212
Recursive resolution source.
Definition: fib_entry.h:125
vnet_main_t * vnet_get_main(void)
Definition: misc.c:47
u32 fib_entry_child_add(fib_node_index_t fib_entry_index, fib_node_type_t child_type, fib_node_index_t child_index)
Definition: fib_entry.c:565
struct adj_midchain_delegate_t_ adj_midchain_delegate_t
Midchain stacker delegate.
#define NULL
Definition: clib.h:58
IP unicast adjacency.
Definition: adj.h:221
void adj_midchain_delegate_restack(adj_index_t ai)
restack a midchain delegate
void fib_entry_child_remove(fib_node_index_t fib_entry_index, u32 sibling_index)
Definition: fib_entry.c:576
const fib_prefix_t * fib_entry_get_prefix(fib_node_index_t fib_entry_index)
Definition: fib_entry.c:1688
u8 * format(u8 *s, const char *fmt,...)
Definition: format.c:424
#define pool_get(P, E)
Allocate an object E from a pool P (unspecified alignment).
Definition: pool.h:236
unsigned char u8
Definition: types.h:56
static ip_adjacency_t * adj_get(adj_index_t adj_index)
Get a pointer to an adjacency object from its index.
Definition: adj.h:433
Stacking of a midchain&#39;s nexthop.
Definition: adj_delegate.h:42
#define VLIB_INIT_FUNCTION(x)
Definition: init.h:163
Aggregrate type for a prefix.
Definition: fib_types.h:203
void adj_nbr_midchain_stack_on_fib_entry(adj_index_t ai, fib_node_index_t fei, fib_forward_chain_type_t fct)
[re]stack a midchain.
Definition: adj_midchain.c:570
Adj delegate.
Definition: adj_delegate.h:50
unsigned int u32
Definition: types.h:88
static u8 * adj_midchain_delegate_fmt(const adj_delegate_t *aed, u8 *s)
Print a delegate that represents MIDCHAIN tracking.
Definition: fib_entry.h:275
#define pool_elt_at_index(p, i)
Returns pointer to element at given index.
Definition: pool.h:514
int adj_delegate_add(ip_adjacency_t *adj, adj_delegate_type_t adt, index_t adi)
Add a delegate to an adjacency.
Definition: adj_delegate.c:107
u32 amd_sibling
The sibling entry on the FIB entry.
u32 adj_get_sw_if_index(adj_index_t ai)
Return the sw interface index of the adjacency.
Definition: adj.c:481
#define pool_put(P, E)
Free an object E in pool P.
Definition: pool.h:286
static void adj_midchain_delegate_restack_i(adj_index_t ai, adj_midchain_delegate_t *amd)
fib_node_index_t amd_fei
the Fib Entry we are stacked on
fib_node_index_t fib_table_entry_special_add(u32 fib_index, const fib_prefix_t *prefix, fib_source_t source, fib_entry_flag_t flags)
Add a &#39;special&#39; entry to the FIB.
Definition: fib_table.c:388
vlib_main_t * vm
Definition: buffer.c:312
void fib_table_entry_delete_index(fib_node_index_t fib_entry_index, fib_source_t source)
Delete a FIB entry.
Definition: fib_table.c:877
index_t ad_index
The index passed by the provider to identify its delegate instance.
Definition: adj_delegate.h:66
static clib_error_t * adj_midchain_delegate_module_init(vlib_main_t *vm)
static void adj_midchain_delegate_adj_deleted(adj_delegate_t *ad)
u32 fib_node_index_t
A typedef of a node index.
Definition: fib_types.h:30
u32 adj_index_t
An index for adjacencies.
Definition: adj_types.h:30
void adj_delegate_register_type(adj_delegate_type_t type, const adj_delegate_vft_t *vft)
adj_delegate_register_type
Definition: adj_delegate.c:171
adj_delegate_t * adj_delegate_get(const ip_adjacency_t *adj, adj_delegate_type_t type)
Get a delegate from an adjacency.
Definition: adj_delegate.c:58
Midchain stacker delegate.
adj_delegate_format_t adv_format
Definition: adj_delegate.h:84
void adj_nbr_midchain_unstack(adj_index_t adj_index)
adj_nbr_midchain_unstack
Definition: adj_midchain.c:538
static uword vnet_sw_interface_is_admin_up(vnet_main_t *vnm, u32 sw_if_index)
#define FIB_NODE_INDEX_INVALID
Definition: fib_types.h:31
An ADJ delegate virtual function table.
Definition: adj_delegate.h:83
void adj_midchain_delegate_unstack(adj_index_t ai)
unstack a midchain delegate (this stacks it on a drop)
void adj_midchain_delegate_stack(adj_index_t ai, u32 fib_index, const fib_prefix_t *pfx)
create/attach a midchain delegate and stack it on the prefix passed
static adj_midchain_delegate_t * amd_pool
Pool of delegates.
fib_forward_chain_type_t fib_forw_chain_type_from_fib_proto(fib_protocol_t proto)
Convert from a fib-protocol to a chain type.
Definition: fib_types.c:343