FD.io VPP  v21.10.1-2-g0a485f517
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  {
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);
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 
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 
adj_midchain.h
adj_delegate_t_::ad_index
index_t ad_index
The index passed by the provider to identify its delegate instance.
Definition: adj_delegate.h:66
FIB_NODE_TYPE_ADJ
@ FIB_NODE_TYPE_ADJ
Definition: fib_node.h:37
adj_delegate_vft_t_
An ADJ delegate virtual function table.
Definition: adj_delegate.h:94
fib_entry_get_prefix
const fib_prefix_t * fib_entry_get_prefix(fib_node_index_t fib_entry_index)
Definition: fib_entry.c:1728
adj_delegate_t_
Adj delegate.
Definition: adj_delegate.h:50
adj_get_sw_if_index
u32 adj_get_sw_if_index(adj_index_t ai)
Return the sw interface index of the adjacency.
Definition: adj.c:543
pool_elt_at_index
#define pool_elt_at_index(p, i)
Returns pointer to element at given index.
Definition: pool.h:549
adj_midchain_delegate_t_::amd_sibling
u32 amd_sibling
The sibling entry on the FIB entry.
Definition: adj_midchain_delegate.c:34
fib_entry_untrack
void fib_entry_untrack(fib_node_index_t fei, u32 sibling)
Stop tracking a FIB entry.
Definition: fib_entry_track.c:79
FIB_NODE_INDEX_INVALID
#define FIB_NODE_INDEX_INVALID
Definition: fib_types.h:30
fib_table.h
pool_put
#define pool_put(P, E)
Free an object E in pool P.
Definition: pool.h:305
vm
vlib_main_t * vm
X-connect all packets from the HOST to the PHY.
Definition: nat44_ei.c:3047
adj_midchain_delegate_t_::amd_fei
fib_node_index_t amd_fei
the Fib Entry we are stacked on
Definition: adj_midchain_delegate.c:29
adj_midchain_delegate_restack
void adj_midchain_delegate_restack(adj_index_t ai)
restack a midchain delegate
Definition: adj_midchain_delegate.c:76
adj_nbr_midchain_stack_on_fib_entry
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:335
error
Definition: cJSON.c:88
adj_midchain_delegate_t
struct adj_midchain_delegate_t_ adj_midchain_delegate_t
Midchain stacker delegate.
adj_midchain_from_const_base
static const adj_midchain_delegate_t * adj_midchain_from_const_base(const adj_delegate_t *ad)
Definition: adj_midchain_delegate.c:43
fib_entry_track
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.
Definition: fib_entry_track.c:49
adj_delegate_add
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
vnet_get_main
vnet_main_t * vnet_get_main(void)
Definition: pnat_test_stubs.h:56
adj_midchain_delegate_unstack
void adj_midchain_delegate_unstack(adj_index_t ai)
unstack a midchain delegate (this stacks it on a drop)
Definition: adj_midchain_delegate.c:135
fib_node_index_t
u32 fib_node_index_t
A typedef of a node index.
Definition: fib_types.h:29
adj_delegate.h
pool_get
#define pool_get(P, E)
Allocate an object E from a pool P (unspecified alignment).
Definition: pool.h:255
adj_delegate_register_type
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_MIDCHAIN
@ ADJ_DELEGATE_MIDCHAIN
Stacking of a midchain's nexthop.
Definition: adj_delegate.h:42
ip_adjacency_t_
IP unicast adjacency.
Definition: adj.h:235
adj_midchain_delegate_stack
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
Definition: adj_midchain_delegate.c:101
adj_midchain_delegate_adj_deleted
static void adj_midchain_delegate_adj_deleted(adj_delegate_t *ad)
Definition: adj_midchain_delegate.c:141
vnet_sw_interface_is_admin_up
static uword vnet_sw_interface_is_admin_up(vnet_main_t *vnm, u32 sw_if_index)
Definition: interface_funcs.h:265
fib_entry_track.h
adj_midchain_delegate_restack_i
static void adj_midchain_delegate_restack_i(adj_index_t ai, adj_midchain_delegate_t *amd)
Definition: adj_midchain_delegate.c:53
adj_delegate_get
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
fib_forw_chain_type_from_fib_proto
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
format
description fragment has unexpected format
Definition: map.api:433
u32
unsigned int u32
Definition: types.h:88
VLIB_INIT_FUNCTION
#define VLIB_INIT_FUNCTION(x)
Definition: init.h:172
adj_midchain_delegate_module_init
static clib_error_t * adj_midchain_delegate_module_init(vlib_main_t *vm)
Definition: adj_midchain_delegate.c:171
fib_prefix_t_::fp_proto
fib_protocol_t fp_proto
protocol type
Definition: fib_types.h:211
adj_nbr_midchain_unstack
void adj_nbr_midchain_unstack(adj_index_t adj_index)
adj_nbr_midchain_unstack
Definition: adj_midchain.c:303
adj_midchain_delegate_t_
Midchain stacker delegate.
Definition: adj_midchain_delegate.c:24
adj_index_t
u32 adj_index_t
An index for adjacencies.
Definition: adj_types.h:30
vlib_main_t
Definition: main.h:102
u8
unsigned char u8
Definition: types.h:56
clib_error_t
Definition: clib_error.h:21
adj_delegate_vft
const static adj_delegate_vft_t adj_delegate_vft
Definition: adj_midchain_delegate.c:165
vlib_init_function_t
clib_error_t *() vlib_init_function_t(struct vlib_main_t *vm)
Definition: init.h:51
adj_midchain_delegate_fmt
static u8 * adj_midchain_delegate_fmt(const adj_delegate_t *aed, u8 *s)
Print a delegate that represents MIDCHAIN tracking.
Definition: adj_midchain_delegate.c:156
amd_pool
static adj_midchain_delegate_t * amd_pool
Pool of delegates.
Definition: adj_midchain_delegate.c:40
adj_get
static ip_adjacency_t * adj_get(adj_index_t adj_index)
Get a pointer to an adjacency object from its index.
Definition: adj.h:470
adj_delegate_vft_t_::adv_format
adj_delegate_format_t adv_format
Definition: adj_delegate.h:95
fib_prefix_t_
Aggregate type for a prefix.
Definition: fib_types.h:202