FD.io VPP  v21.01
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>
20 
21 /**
22  * Midchain stacker delegate
23  */
25 {
26  /**
27  * the Fib Entry we are stacked on
28  */
30 
31  /**
32  * The sibling entry on the FIB entry
33  */
36 
37 /**
38  * Pool of delegates
39  */
41 
42 static inline const adj_midchain_delegate_t*
44 {
45  if (NULL != ad)
46  {
47  return (pool_elt_at_index(amd_pool, ad->ad_index));
48  }
49  return (NULL);
50 }
51 
52 static void
55 {
57  adj_get_sw_if_index(ai)) &&
59  {
60  const fib_prefix_t *pfx;
61 
62  pfx = fib_entry_get_prefix(amd->amd_fei);
63 
65  ai,
66  amd->amd_fei,
68  }
69  else
70  {
72  }
73 }
74 
75 void
77 {
79  ip_adjacency_t *adj;
80  adj_delegate_t *ad;
81 
82  /*
83  * if there's a delegate already use that
84  */
85  adj = adj_get(ai);
87 
88  if (NULL != ad)
89  {
90  amd = pool_elt_at_index(amd_pool, ad->ad_index);
91 
93  }
94  /*
95  * else
96  * nothing to stack
97  */
98 }
99 
100 void
102  u32 fib_index,
103  const fib_prefix_t *pfx)
104 {
106  ip_adjacency_t *adj;
107  adj_delegate_t *ad;
108 
109  /*
110  * if there's a delegate already use that
111  */
112  adj = adj_get(ai);
114 
115  if (NULL != ad)
116  {
117  amd = pool_elt_at_index(amd_pool, ad->ad_index);
118  }
119  else
120  {
121  pool_get(amd_pool, amd);
123  adj_delegate_add(adj, ADJ_DELEGATE_MIDCHAIN, amd - amd_pool);
124 
125  amd->amd_fei = fib_entry_track(fib_index,
126  pfx,
128  ai,
129  &amd->amd_sibling);
130  }
132 }
133 
134 void
136 {
138 }
139 
140 static void
142 {
144 
145  amd = pool_elt_at_index(amd_pool, ad->ad_index);
146 
148 
149  pool_put(amd_pool, amd);
150 }
151 
152 /**
153  * Print a delegate that represents MIDCHAIN tracking
154  */
155 static u8 *
157 {
159 
160  s = format(s, "MIDCHAIN:[fib-entry:%d]", amd->amd_fei);
161 
162  return (s);
163 }
164 
165 const static adj_delegate_vft_t adj_delegate_vft = {
167  .adv_adj_deleted = adj_midchain_delegate_adj_deleted,
168 };
169 
170 static clib_error_t *
172 {
173  clib_error_t * error = NULL;
174 
176 
177  return (error);
178 }
179 
181 
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:211
fib_node_index_t fib_entry_track(u32 fib_index, const fib_prefix_t *prefix, fib_node_type_t child_type, index_t child_index, u32 *sibling)
Trackers are used on FIB entries by objects that which to track the changing state of the entry...
vnet_main_t * vnet_get_main(void)
Definition: misc.c:46
struct adj_midchain_delegate_t_ adj_midchain_delegate_t
Midchain stacker delegate.
IP unicast adjacency.
Definition: adj.h:235
void adj_midchain_delegate_restack(adj_index_t ai)
restack a midchain delegate
vlib_main_t * vm
Definition: in2out_ed.c:1578
const fib_prefix_t * fib_entry_get_prefix(fib_node_index_t fib_entry_index)
Definition: fib_entry.c:1712
#define pool_get(P, E)
Allocate an object E from a pool P (unspecified alignment).
Definition: pool.h:251
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:467
Stacking of a midchain&#39;s nexthop.
Definition: adj_delegate.h:42
#define VLIB_INIT_FUNCTION(x)
Definition: init.h:173
description fragment has unexpected format
Definition: map.api:433
Aggregate type for a prefix.
Definition: fib_types.h:202
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:562
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: cJSON.c:84
#define pool_elt_at_index(p, i)
Returns pointer to element at given index.
Definition: pool.h:546
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:519
#define pool_put(P, E)
Free an object E in pool P.
Definition: pool.h:301
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
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:29
u32 adj_index_t
An index for adjacencies.
Definition: adj_types.h:30
void fib_entry_untrack(fib_node_index_t fei, u32 sibling)
Stop tracking a FIB entry.
void adj_delegate_register_type(adj_delegate_type_t type, const adj_delegate_vft_t *vft)
adj_delegate_register_type
Definition: adj_delegate.c:199
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:95
void adj_nbr_midchain_unstack(adj_index_t adj_index)
adj_nbr_midchain_unstack
Definition: adj_midchain.c:530
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:30
An ADJ delegate virtual function table.
Definition: adj_delegate.h:94
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:449