FD.io VPP  v21.06-3-gbb25fbf28
Vector Packet Processing
ip_punt_drop.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015 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/ip/ip.h>
17 #include <vnet/ip/ip_punt_drop.h>
18 #include <vnet/fib/fib_path_list.h>
19 
21 
22 u8 *
23 format_ip_punt_redirect_trace (u8 * s, va_list * args)
24 {
25  CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
26  CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
28 
29  if (INDEX_INVALID == t->rrxi)
30  s = format (s, "ignore");
31  else
32  s = format (s, "via redirect:%d", t->rrxi);
33 
34  return s;
35 }
36 
37 static void
39 {
40  dpo_id_t dpo = DPO_INVALID;
41  vlib_node_t *pnode;
42 
44  ipr->payload_type,
46 
47  if (FIB_PROTOCOL_IP4 == ipr->fproto)
48  pnode =
49  vlib_get_node_by_name (vlib_get_main (), (u8 *) "ip4-punt-redirect");
50  else
51  pnode =
52  vlib_get_node_by_name (vlib_get_main (), (u8 *) "ip6-punt-redirect");
53 
54  dpo_stack_from_node (pnode->index, &ipr->dpo, &dpo);
55  dpo_reset (&dpo);
56 }
57 
58 index_t
59 ip_punt_redirect_find (fib_protocol_t fproto, u32 rx_sw_if_index)
60 {
61  index_t *rxs;
62 
64 
65  if (vec_len (rxs) <= rx_sw_if_index)
66  return (INDEX_INVALID);
67 
68  return rxs[rx_sw_if_index];
69 }
70 
71 void
73  u32 rx_sw_if_index,
75 {
77  index_t ipri;
78 
79  if (~0 == rx_sw_if_index)
80  rx_sw_if_index = 0;
81 
83  [fproto], rx_sw_if_index, INDEX_INVALID);
84 
86  ipri = ipr - ip_punt_redirect_cfg.pool;
87 
88  ip_punt_redirect_cfg.redirect_by_rx_sw_if_index[fproto][rx_sw_if_index] =
89  ipri;
90 
92  ipr->fproto = fproto;
93  ipr->payload_type = ct;
94 
96 
97  ipr->sibling = fib_path_list_child_add (ipr->pl,
99  ipri);
100 
102 }
103 
104 void
105 ip_punt_redirect_del (fib_protocol_t fproto, u32 rx_sw_if_index)
106 {
108  index_t *rxs;
109 
110  if (~0 == rx_sw_if_index)
111  rx_sw_if_index = 0;
112 
114 
115  if ((vec_len (rxs) <= rx_sw_if_index) ||
116  (INDEX_INVALID == rxs[rx_sw_if_index]))
117  return;
118 
119  ipr = ip_punt_redirect_get (rxs[rx_sw_if_index]);
120 
122  dpo_reset (&ipr->dpo);
124 
125  rxs[rx_sw_if_index] = INDEX_INVALID;
126 }
127 
128 u8 *
129 format_ip_punt_redirect (u8 * s, va_list * args)
130 {
131  fib_protocol_t fproto = va_arg (*args, int);
133  index_t *rxs;
134  u32 rx_sw_if_index;
135  vnet_main_t *vnm = vnet_get_main ();
136 
138 
139  vec_foreach_index (rx_sw_if_index, rxs)
140  {
141  if (INDEX_INVALID == rxs[rx_sw_if_index])
142  continue;
143 
144  rx = ip_punt_redirect_get (rxs[rx_sw_if_index]);
145 
146  s = format (s, " rx %U via:\n",
148  vnet_get_sw_interface (vnm, rx_sw_if_index));
149  s = format (s, " %U", format_fib_path_list, rx->pl, 2);
150  s = format (s, " forwarding\n", format_dpo_id, &rx->dpo, 0);
151  s = format (s, " %U\n", format_dpo_id, &rx->dpo, 0);
152  }
153 
154  return (s);
155 }
156 
157 void
160 {
162  u32 ii, rx_sw_if_index;
163  index_t *rxs;
164 
166 
167  vec_foreach_index (ii, rxs)
168  {
169  if (INDEX_INVALID == rxs[ii])
170  continue;
171 
172  rx = ip_punt_redirect_get (rxs[ii]);
173 
174  rx_sw_if_index = (ii == 0 ? ~0 : ii);
175  cb (rx_sw_if_index, rx, ctx);
176  }
177 }
178 
179 static fib_node_t *
181 {
183  return (&(ipr->node));
184 }
185 
186 static ip_punt_redirect_rx_t *
188 {
189  return ((ip_punt_redirect_rx_t *) (((char *) node) -
191  node)));
192 }
193 
194 static void
196 {
197  /*
198  * the lifetime of the entry is managed by the table.
199  */
200  ASSERT (0);
201 }
202 
203 /*
204  * A back walk has reached this BIER entry
205  */
209 {
210  /*
211  * re-populate the ECMP tables with new choices
212  */
214 
216 
217  /*
218  * no need to propagate further up the graph, since there's nothing there
219  */
221 }
222 
223 /*
224  * The BIER fmask's graph node virtual function table
225  */
228  .fnv_last_lock = ip_punt_redirect_last_lock_gone,
229  .fnv_back_walk = ip_punt_redirect_back_walk_notify,
230 };
231 
232 static clib_error_t *
234 {
237 
242 
243  return (NULL);
244 }
245 
247 
248 /*
249  * fd.io coding-style-patch-verification: ON
250  *
251  * Local Variables:
252  * eval: (c-set-style "gnu")
253  * End:
254  */
DPO_INVALID
#define DPO_INVALID
An initialiser for DPOs declared on the stack.
Definition: dpo.h:204
fib_node_back_walk_rc_t
enum fib_node_back_walk_rc_t_ fib_node_back_walk_rc_t
Return code from a back walk function.
ip_punt_redirect_stack
static void ip_punt_redirect_stack(ip_punt_redirect_rx_t *ipr)
Definition: ip_punt_drop.c:38
ip4_punt_policer_node
vlib_node_registration_t ip4_punt_policer_node
(constructor) VLIB_REGISTER_NODE (ip4_punt_policer_node)
Definition: ip4_punt_drop.c:93
ip_punt_drop_init
static clib_error_t * ip_punt_drop_init(vlib_main_t *vm)
Definition: ip_punt_drop.c:233
ip_punt_redirect_back_walk_notify
static fib_node_back_walk_rc_t ip_punt_redirect_back_walk_notify(fib_node_t *node, fib_node_back_walk_ctx_t *ctx)
Definition: ip_punt_drop.c:207
node
vlib_main_t vlib_node_runtime_t * node
Definition: nat44_ei.c:3047
fib_node_vft_t_
A FIB graph nodes virtual function table.
Definition: fib_node.h:288
ip6_punt_policer_node
vlib_node_registration_t ip6_punt_policer_node
(constructor) VLIB_REGISTER_NODE (ip6_punt_policer_node)
Definition: ip6_punt_drop.c:82
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
vnet_get_sw_interface
static vnet_sw_interface_t * vnet_get_sw_interface(vnet_main_t *vnm, u32 sw_if_index)
Definition: interface_funcs.h:58
ip_punt_redirect_del
void ip_punt_redirect_del(fib_protocol_t fproto, u32 rx_sw_if_index)
Definition: ip_punt_drop.c:105
ip_punt_drop.h
ip4_punt_redirect_trace_t_::rrxi
index_t rrxi
Definition: ip_punt_drop.h:263
ip_punt_redirect_t_::redirect_by_rx_sw_if_index
index_t * redirect_by_rx_sw_if_index[FIB_PROTOCOL_IP_MAX]
per-RX interface configuration.
Definition: ip_punt_drop.h:242
ip_punt_policer_t_::fq_index
u32 fq_index
Definition: ip_punt_drop.h:30
vlib_frame_queue_main_init
u32 vlib_frame_queue_main_init(u32 node_index, u32 frame_queue_nelts)
Definition: threads.c:1572
ip_punt_redirect_cfg
ip_punt_redirect_cfg_t ip_punt_redirect_cfg
Definition: ip_punt_drop.c:20
ip_punt_redirect_add
void ip_punt_redirect_add(fib_protocol_t fproto, u32 rx_sw_if_index, fib_forward_chain_type_t ct, fib_route_path_t *rpaths)
Add a punt redirect entry.
Definition: ip_punt_drop.c:72
STRUCT_OFFSET_OF
#define STRUCT_OFFSET_OF(t, f)
Definition: clib.h:73
ip_punt_redirect_rx_t_::node
fib_node_t node
Node linkage into the FIB graph.
Definition: ip_punt_drop.h:217
ip_punt_redirect_rx_t_::fproto
fib_protocol_t fproto
Definition: ip_punt_drop.h:219
vec_len
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
Definition: vec_bootstrap.h:142
vlib_node_t::index
u32 index
Definition: node.h:269
ip6_punt_policer_cfg
ip_punt_policer_t ip6_punt_policer_cfg
Definition: ip6_punt_drop.c:38
fib_forward_chain_type_t
enum fib_forward_chain_type_t_ fib_forward_chain_type_t
FIB output chain type.
CLIB_UNUSED
#define CLIB_UNUSED(x)
Definition: clib.h:90
ip_punt_redirect_last_lock_gone
static void ip_punt_redirect_last_lock_gone(fib_node_t *node)
Definition: ip_punt_drop.c:195
vnet_get_main
vnet_main_t * vnet_get_main(void)
Definition: pnat_test_stubs.h:56
format_fib_path_list
u8 * format_fib_path_list(u8 *s, va_list *args)
Definition: fib_path_list.c:125
index_t
u32 index_t
A Data-Path Object is an object that represents actions that are applied to packets are they are swit...
Definition: dpo.h:43
ip_punt_redirect_walk_cb_t
walk_rc_t(* ip_punt_redirect_walk_cb_t)(u32 rx_sw_if_index, const ip_punt_redirect_rx_t *redirect, void *arg)
Definition: ip_punt_drop.h:282
fib_node_index_t
u32 fib_node_index_t
A typedef of a node index.
Definition: fib_types.h:29
ip_punt_redirect_get_from_node
static ip_punt_redirect_rx_t * ip_punt_redirect_get_from_node(fib_node_t *node)
Definition: ip_punt_drop.c:187
vec_foreach_index
#define vec_foreach_index(var, v)
Iterate over vector indices.
Definition: vec_bootstrap.h:220
pool_get
#define pool_get(P, E)
Allocate an object E from a pool P (unspecified alignment).
Definition: pool.h:255
dpo_stack_from_node
void dpo_stack_from_node(u32 child_node_index, dpo_id_t *dpo, const dpo_id_t *parent)
Stack one DPO object on another, and thus establish a child parent relationship.
Definition: dpo.c:550
fib_protocol_t
enum fib_protocol_t_ fib_protocol_t
Protocol Type.
ip_punt_redirect_rx_t_
IP4 punt redirect per-rx interface configuration redirect punted traffic to another location.
Definition: ip_punt_drop.h:212
fib_path_list_child_add
u32 fib_path_list_child_add(fib_node_index_t path_list_index, fib_node_type_t child_type, fib_node_index_t child_index)
Definition: fib_path_list.c:1296
fib_path_list_contribute_forwarding
void fib_path_list_contribute_forwarding(fib_node_index_t path_list_index, fib_forward_chain_type_t fct, fib_path_list_fwd_flags_t flags, dpo_id_t *dpo)
Definition: fib_path_list.c:1211
FIB_PROTOCOL_IP4
@ FIB_PROTOCOL_IP4
Definition: fib_types.h:36
fib_node_register_type
void fib_node_register_type(fib_node_type_t type, const fib_node_vft_t *vft)
fib_node_register_type
Definition: fib_node.c:60
ip_punt_redirect_get_node
static fib_node_t * ip_punt_redirect_get_node(fib_node_index_t index)
Definition: ip_punt_drop.c:180
FIB_NODE_BACK_WALK_CONTINUE
@ FIB_NODE_BACK_WALK_CONTINUE
Definition: fib_node.h:259
ip_punt_redirect_walk
void ip_punt_redirect_walk(fib_protocol_t fproto, ip_punt_redirect_walk_cb_t cb, void *ctx)
Definition: ip_punt_drop.c:158
ip_punt_redirect_rx_t_::payload_type
fib_forward_chain_type_t payload_type
Definition: ip_punt_drop.h:220
format_dpo_id
u8 * format_dpo_id(u8 *s, va_list *args)
Format a DPO_id_t oject.
Definition: dpo.c:150
ip_punt_redirect_rx_t_::pl
fib_node_index_t pl
Definition: ip_punt_drop.h:221
ip_punt_redirect_find
index_t ip_punt_redirect_find(fib_protocol_t fproto, u32 rx_sw_if_index)
Definition: ip_punt_drop.c:59
vnet_main_t
Definition: vnet.h:76
ip_punt_redirect_rx_t_::dpo
dpo_id_t dpo
redirect forwarding
Definition: ip_punt_drop.h:227
index
u32 index
Definition: flow_types.api:221
format_ip_punt_redirect
u8 * format_ip_punt_redirect(u8 *s, va_list *args)
Definition: ip_punt_drop.c:129
vlib_get_node_by_name
vlib_node_t * vlib_get_node_by_name(vlib_main_t *vm, u8 *name)
Definition: node.c:45
fib_path_list.h
format_ip_punt_redirect_trace
u8 * format_ip_punt_redirect_trace(u8 *s, va_list *args)
Definition: ip_punt_drop.c:23
format
description fragment has unexpected format
Definition: map.api:433
ASSERT
#define ASSERT(truth)
Definition: error_bootstrap.h:69
vec_validate_init_empty
#define vec_validate_init_empty(V, I, INIT)
Make sure vector is long enough for given index and initialize empty space (no header,...
Definition: vec.h:570
FIB_NODE_TYPE_IP_PUNT_REDIRECT
@ FIB_NODE_TYPE_IP_PUNT_REDIRECT
Definition: fib_node.h:51
ip.h
u32
unsigned int u32
Definition: types.h:88
VLIB_INIT_FUNCTION
#define VLIB_INIT_FUNCTION(x)
Definition: init.h:172
ip4_punt_policer_cfg
ip_punt_policer_t ip4_punt_policer_cfg
Definition: ip4_punt_drop.c:49
fib_route_path_t_
A representation of a path as described by a route producer.
Definition: fib_types.h:500
ctx
long ctx[MAX_CONNS]
Definition: main.c:144
ip_punt_redirect_rx_t_::sibling
u32 sibling
Definition: ip_punt_drop.h:222
ip_punt_redirect_get
static_always_inline ip_punt_redirect_rx_t * ip_punt_redirect_get(index_t rrxi)
Definition: ip_punt_drop.h:289
fib_path_list_child_remove
void fib_path_list_child_remove(fib_node_index_t path_list_index, u32 si)
Definition: fib_path_list.c:1335
fib_node_t_
An node in the FIB graph.
Definition: fib_node.h:301
vlib_main_t
Definition: main.h:102
vlib_node_t
Definition: node.h:247
fib_node_init
void fib_node_init(fib_node_t *node, fib_node_type_t type)
Definition: fib_node.c:185
vlib_get_main
static vlib_main_t * vlib_get_main(void)
Definition: global_funcs.h:38
u8
unsigned char u8
Definition: types.h:56
clib_error_t
Definition: clib_error.h:21
ip_punt_redirect_vft
static const fib_node_vft_t ip_punt_redirect_vft
Definition: ip_punt_drop.c:226
vlib_init_function_t
clib_error_t *() vlib_init_function_t(struct vlib_main_t *vm)
Definition: init.h:51
FIB_PATH_LIST_FLAG_NO_URPF
@ FIB_PATH_LIST_FLAG_NO_URPF
Definition: fib_path_list.h:88
fib_node_back_walk_ctx_t_
Context passed between object during a back walk.
Definition: fib_node.h:214
fib_node_vft_t_::fnv_get
fib_node_get_t fnv_get
Definition: fib_node.h:289
dpo_id_t_
The identity of a DPO is a combination of its type and its instance number/index of objects of that t...
Definition: dpo.h:172
ip_punt_redirect_t_
IP punt redirect configuration.
Definition: ip_punt_drop.h:233
ip4_punt_redirect_trace_t_
IP Punt redirect trace.
Definition: ip_punt_drop.h:261
INDEX_INVALID
#define INDEX_INVALID
Invalid index - used when no index is known blazoned capitals INVALID speak volumes where ~0 does not...
Definition: dpo.h:49
fib_path_list_create
fib_node_index_t fib_path_list_create(fib_path_list_flags_t flags, const fib_route_path_t *rpaths)
Definition: fib_path_list.c:682
dpo_reset
void dpo_reset(dpo_id_t *dpo)
reset a DPO ID The DPO will be unlocked.
Definition: dpo.c:234
ip_punt_redirect_t_::pool
ip_punt_redirect_rx_t * pool
Definition: ip_punt_drop.h:235
FIB_PATH_LIST_FWD_FLAG_COLLAPSE
@ FIB_PATH_LIST_FWD_FLAG_COLLAPSE
Definition: fib_path_list.h:143
format_vnet_sw_interface_name
format_function_t format_vnet_sw_interface_name
Definition: interface_funcs.h:453