blob: a0f5a50c223cda38139890ad2715fc9faed7d456 [file] [log] [blame]
Neale Ranns810086d2017-11-05 16:26:46 -08001/*
Florin Corasc5df8c72019-04-08 07:42:30 -07002 * Copyright (c) 2017-2019 Cisco and/or its affiliates.
Neale Ranns810086d2017-11-05 16:26:46 -08003 * 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/udp/udp_encap.h>
17#include <vnet/fib/fib_entry.h>
Neale Ranns1f50bf82019-07-16 15:28:52 +000018#include <vnet/fib/fib_entry_track.h>
Neale Ranns810086d2017-11-05 16:26:46 -080019#include <vnet/fib/fib_table.h>
20#include <vnet/dpo/drop_dpo.h>
21
22/**
23 * Registered DPO types for the IP header encapsulated, v4 or v6.
24 */
25dpo_type_t udp_encap_dpo_types[FIB_PROTOCOL_MAX];
26
27/**
Neale Ranns810086d2017-11-05 16:26:46 -080028 * Pool of encaps
29 */
30udp_encap_t *udp_encap_pool;
31
Neale Ranns43b1f442018-03-20 01:47:35 -070032/**
33 * Stats for each UDP encap object
34 */
Neale Ranns9c0a3c42018-09-07 08:57:41 -070035vlib_combined_counter_main_t udp_encap_counters = {
36 /**
37 * The counter collection's name.
38 */
39 .name = "udp-encap",
40 /**
41 * Name in stat segment directory
42 */
43 .stat_segment_name = "/net/udp-encap",
44};
Neale Ranns810086d2017-11-05 16:26:46 -080045
46static void
47udp_encap_restack (udp_encap_t * ue)
48{
49 dpo_stack (udp_encap_dpo_types[ue->ue_ip_proto],
Mauro Sardara95396472022-03-22 17:53:46 +000050 fib_proto_to_dpo (ue->ue_ip_proto), &ue->ue_dpo,
Neale Ranns810086d2017-11-05 16:26:46 -080051 fib_entry_contribute_ip_forwarding (ue->ue_fib_entry_index));
52}
53
54index_t
Neale Ranns9c0a3c42018-09-07 08:57:41 -070055udp_encap_add_and_lock (fib_protocol_t proto,
Neale Ranns810086d2017-11-05 16:26:46 -080056 index_t fib_index,
57 const ip46_address_t * src_ip,
58 const ip46_address_t * dst_ip,
59 u16 src_port,
60 u16 dst_port, udp_encap_fixup_flags_t flags)
61{
62 udp_encap_t *ue;
Neale Ranns9c0a3c42018-09-07 08:57:41 -070063 u8 pfx_len = 0;
Neale Ranns810086d2017-11-05 16:26:46 -080064 index_t uei;
65
Arthur de Kerhor7aeb6472021-06-01 11:27:48 +020066 pool_get_aligned_zero (udp_encap_pool, ue, CLIB_CACHE_LINE_BYTES);
Neale Ranns9c0a3c42018-09-07 08:57:41 -070067 uei = ue - udp_encap_pool;
Neale Ranns810086d2017-11-05 16:26:46 -080068
Neale Ranns9c0a3c42018-09-07 08:57:41 -070069 vlib_validate_combined_counter (&(udp_encap_counters), uei);
70 vlib_zero_combined_counter (&(udp_encap_counters), uei);
71
72 fib_node_init (&ue->ue_fib_node, FIB_NODE_TYPE_UDP_ENCAP);
73 fib_node_lock (&ue->ue_fib_node);
74 ue->ue_fib_index = fib_index;
75 ue->ue_flags = flags;
76 ue->ue_ip_proto = proto;
77
78 switch (proto)
Neale Ranns810086d2017-11-05 16:26:46 -080079 {
Neale Ranns9c0a3c42018-09-07 08:57:41 -070080 case FIB_PROTOCOL_IP4:
81 pfx_len = 32;
82 ue->ue_hdrs.ip4.ue_ip4.ip_version_and_header_length = 0x45;
83 ue->ue_hdrs.ip4.ue_ip4.ttl = 254;
84 ue->ue_hdrs.ip4.ue_ip4.protocol = IP_PROTOCOL_UDP;
85 ue->ue_hdrs.ip4.ue_ip4.src_address.as_u32 = src_ip->ip4.as_u32;
86 ue->ue_hdrs.ip4.ue_ip4.dst_address.as_u32 = dst_ip->ip4.as_u32;
87 ue->ue_hdrs.ip4.ue_ip4.checksum =
88 ip4_header_checksum (&ue->ue_hdrs.ip4.ue_ip4);
89 ue->ue_hdrs.ip4.ue_udp.src_port = clib_host_to_net_u16 (src_port);
90 ue->ue_hdrs.ip4.ue_udp.dst_port = clib_host_to_net_u16 (dst_port);
Neale Ranns810086d2017-11-05 16:26:46 -080091
Neale Ranns9c0a3c42018-09-07 08:57:41 -070092 break;
93 case FIB_PROTOCOL_IP6:
94 pfx_len = 128;
95 ue->ue_hdrs.ip6.ue_ip6.ip_version_traffic_class_and_flow_label =
96 clib_host_to_net_u32 (6 << 28);
97 ue->ue_hdrs.ip6.ue_ip6.hop_limit = 255;
98 ue->ue_hdrs.ip6.ue_ip6.protocol = IP_PROTOCOL_UDP;
99 ue->ue_hdrs.ip6.ue_ip6.src_address.as_u64[0] = src_ip->ip6.as_u64[0];
100 ue->ue_hdrs.ip6.ue_ip6.src_address.as_u64[1] = src_ip->ip6.as_u64[1];
101 ue->ue_hdrs.ip6.ue_ip6.dst_address.as_u64[0] = dst_ip->ip6.as_u64[0];
102 ue->ue_hdrs.ip6.ue_ip6.dst_address.as_u64[1] = dst_ip->ip6.as_u64[1];
103 ue->ue_hdrs.ip6.ue_udp.src_port = clib_host_to_net_u16 (src_port);
104 ue->ue_hdrs.ip6.ue_udp.dst_port = clib_host_to_net_u16 (dst_port);
Neale Ranns810086d2017-11-05 16:26:46 -0800105
Neale Ranns9c0a3c42018-09-07 08:57:41 -0700106 break;
107 default:
108 ASSERT (0);
Neale Ranns810086d2017-11-05 16:26:46 -0800109 }
Neale Ranns9c0a3c42018-09-07 08:57:41 -0700110
111 /*
112 * track the destination address
113 */
114 fib_prefix_t dst_pfx = {
115 .fp_proto = proto,
116 .fp_len = pfx_len,
117 .fp_addr = *dst_ip,
118 };
119
Neale Ranns1f50bf82019-07-16 15:28:52 +0000120 ue->ue_fib_entry_index = fib_entry_track (fib_index,
121 &dst_pfx,
122 FIB_NODE_TYPE_UDP_ENCAP,
123 uei, &ue->ue_fib_sibling);
Neale Ranns9c0a3c42018-09-07 08:57:41 -0700124 udp_encap_restack (ue);
125
Neale Ranns810086d2017-11-05 16:26:46 -0800126 return (uei);
127}
128
129void
Neale Ranns9c0a3c42018-09-07 08:57:41 -0700130udp_encap_contribute_forwarding (index_t uei, dpo_proto_t proto,
131 dpo_id_t * dpo)
Neale Ranns810086d2017-11-05 16:26:46 -0800132{
Neale Ranns810086d2017-11-05 16:26:46 -0800133 if (INDEX_INVALID == uei)
134 {
135 dpo_copy (dpo, drop_dpo_get (proto));
136 }
137 else
138 {
139 udp_encap_t *ue;
140
141 ue = udp_encap_get (uei);
142
143 dpo_set (dpo, udp_encap_dpo_types[ue->ue_ip_proto], proto, uei);
144 }
145}
146
Neale Ranns810086d2017-11-05 16:26:46 -0800147void
Neale Ranns9c0a3c42018-09-07 08:57:41 -0700148udp_encap_lock (index_t uei)
Neale Ranns810086d2017-11-05 16:26:46 -0800149{
150 udp_encap_t *ue;
151
Neale Ranns9c0a3c42018-09-07 08:57:41 -0700152 ue = udp_encap_get (uei);
Neale Ranns810086d2017-11-05 16:26:46 -0800153
154 if (NULL != ue)
155 {
156 fib_node_lock (&ue->ue_fib_node);
157 }
158}
159
160void
Neale Ranns9c0a3c42018-09-07 08:57:41 -0700161udp_encap_unlock (index_t uei)
Neale Ranns810086d2017-11-05 16:26:46 -0800162{
163 udp_encap_t *ue;
164
165 if (INDEX_INVALID == uei)
166 {
167 return;
168 }
169
170 ue = udp_encap_get (uei);
171
172 if (NULL != ue)
173 {
174 fib_node_unlock (&ue->ue_fib_node);
175 }
176}
177
Neale Ranns810086d2017-11-05 16:26:46 -0800178static void
179udp_encap_dpo_lock (dpo_id_t * dpo)
180{
181 udp_encap_t *ue;
182
183 ue = udp_encap_get (dpo->dpoi_index);
184
185 fib_node_lock (&ue->ue_fib_node);
186}
187
188static void
189udp_encap_dpo_unlock (dpo_id_t * dpo)
190{
191 udp_encap_t *ue;
192
193 ue = udp_encap_get (dpo->dpoi_index);
194
195 fib_node_unlock (&ue->ue_fib_node);
196}
197
198static u8 *
199format_udp_encap_i (u8 * s, va_list * args)
200{
201 index_t uei = va_arg (*args, index_t);
202 u32 indent = va_arg (*args, u32);
203 u32 details = va_arg (*args, u32);
Neale Ranns43b1f442018-03-20 01:47:35 -0700204 vlib_counter_t to;
Neale Ranns810086d2017-11-05 16:26:46 -0800205 udp_encap_t *ue;
206
207 ue = udp_encap_get (uei);
208
209 // FIXME
Neale Ranns097fa662018-05-01 05:17:55 -0700210 s = format (s, "udp-encap:[%d]: ip-fib-index:%d ", uei, ue->ue_fib_index);
Neale Ranns810086d2017-11-05 16:26:46 -0800211 if (FIB_PROTOCOL_IP4 == ue->ue_ip_proto)
212 {
213 s = format (s, "ip:[src:%U, dst:%U] udp:[src:%d, dst:%d]",
214 format_ip4_address,
215 &ue->ue_hdrs.ip4.ue_ip4.src_address,
216 format_ip4_address,
217 &ue->ue_hdrs.ip4.ue_ip4.dst_address,
218 clib_net_to_host_u16 (ue->ue_hdrs.ip4.ue_udp.src_port),
219 clib_net_to_host_u16 (ue->ue_hdrs.ip4.ue_udp.dst_port));
220 }
221 else
222 {
223 s = format (s, "ip:[src:%U, dst:%U] udp:[src:%d dst:%d]",
224 format_ip6_address,
225 &ue->ue_hdrs.ip6.ue_ip6.src_address,
226 format_ip6_address,
227 &ue->ue_hdrs.ip6.ue_ip6.dst_address,
228 clib_net_to_host_u16 (ue->ue_hdrs.ip6.ue_udp.src_port),
229 clib_net_to_host_u16 (ue->ue_hdrs.ip6.ue_udp.dst_port));
230 }
Neale Ranns43b1f442018-03-20 01:47:35 -0700231 vlib_get_combined_counter (&(udp_encap_counters), uei, &to);
232 s = format (s, " to:[%Ld:%Ld]]", to.packets, to.bytes);
233
Neale Ranns810086d2017-11-05 16:26:46 -0800234 if (details)
235 {
236 s = format (s, " locks:%d", ue->ue_fib_node.fn_locks);
237 s = format (s, "\n%UStacked on:", format_white_space, indent + 1);
238 s = format (s, "\n%U%U",
239 format_white_space, indent + 2,
240 format_dpo_id, &ue->ue_dpo, indent + 3);
241 }
242 return (s);
243}
244
Neale Ranns43b1f442018-03-20 01:47:35 -0700245void
246udp_encap_get_stats (index_t uei, u64 * packets, u64 * bytes)
247{
248 vlib_counter_t to;
249
250 vlib_get_combined_counter (&(udp_encap_counters), uei, &to);
251
252 *packets = to.packets;
253 *bytes = to.bytes;
254}
255
Neale Ranns810086d2017-11-05 16:26:46 -0800256static u8 *
257format_udp_encap_dpo (u8 * s, va_list * args)
258{
259 index_t uei = va_arg (*args, index_t);
260 u32 indent = va_arg (*args, u32);
261
262 return (format (s, "%U", format_udp_encap_i, uei, indent, 1));
263}
264
265u8 *
266format_udp_encap (u8 * s, va_list * args)
267{
Neale Ranns9c0a3c42018-09-07 08:57:41 -0700268 index_t uei = va_arg (*args, u32);
Neale Ranns810086d2017-11-05 16:26:46 -0800269 u32 details = va_arg (*args, u32);
Neale Ranns810086d2017-11-05 16:26:46 -0800270
271 return (format (s, "%U", format_udp_encap_i, uei, 0, details));
272}
273
274static udp_encap_t *
275udp_encap_from_fib_node (fib_node_t * node)
276{
Neale Ranns810086d2017-11-05 16:26:46 -0800277 ASSERT (FIB_NODE_TYPE_UDP_ENCAP == node->fn_type);
Neale Ranns810086d2017-11-05 16:26:46 -0800278 return ((udp_encap_t *) (((char *) node) -
279 STRUCT_OFFSET_OF (udp_encap_t, ue_fib_node)));
280}
281
282/**
283 * Function definition to backwalk a FIB node
284 */
285static fib_node_back_walk_rc_t
286udp_encap_fib_back_walk (fib_node_t * node, fib_node_back_walk_ctx_t * ctx)
287{
288 udp_encap_restack (udp_encap_from_fib_node (node));
289
290 return (FIB_NODE_BACK_WALK_CONTINUE);
291}
292
293/**
294 * Function definition to get a FIB node from its index
295 */
296static fib_node_t *
297udp_encap_fib_node_get (fib_node_index_t index)
298{
299 udp_encap_t *ue;
300
301 ue = pool_elt_at_index (udp_encap_pool, index);
302
303 return (&ue->ue_fib_node);
304}
305
306/**
307 * Function definition to inform the FIB node that its last lock has gone.
308 */
309static void
310udp_encap_fib_last_lock_gone (fib_node_t * node)
311{
312 udp_encap_t *ue;
313
314 ue = udp_encap_from_fib_node (node);
315
316 /**
317 * reset the stacked DPO to unlock it
318 */
319 dpo_reset (&ue->ue_dpo);
Neale Ranns810086d2017-11-05 16:26:46 -0800320
Neale Ranns1f50bf82019-07-16 15:28:52 +0000321 fib_entry_untrack (ue->ue_fib_entry_index, ue->ue_fib_sibling);
Neale Ranns810086d2017-11-05 16:26:46 -0800322
323 pool_put (udp_encap_pool, ue);
324}
325
326const static char *const udp4_encap_ip4_nodes[] = {
Mauro Sardara95396472022-03-22 17:53:46 +0000327 "udp4o4-encap",
Neale Ranns810086d2017-11-05 16:26:46 -0800328 NULL,
329};
330
331const static char *const udp4_encap_ip6_nodes[] = {
Mauro Sardara95396472022-03-22 17:53:46 +0000332 "udp6o4-encap",
Neale Ranns810086d2017-11-05 16:26:46 -0800333 NULL,
334};
335
336const static char *const udp4_encap_mpls_nodes[] = {
337 "udp4-encap",
338 NULL,
339};
340
Neale Ranns91286372017-12-05 13:24:04 -0800341const static char *const udp4_encap_bier_nodes[] = {
342 "udp4-encap",
343 NULL,
344};
345
Neale Ranns810086d2017-11-05 16:26:46 -0800346const static char *const udp6_encap_ip4_nodes[] = {
Mauro Sardara95396472022-03-22 17:53:46 +0000347 "udp4o6-encap",
Neale Ranns810086d2017-11-05 16:26:46 -0800348 NULL,
349};
350
351const static char *const udp6_encap_ip6_nodes[] = {
Mauro Sardara95396472022-03-22 17:53:46 +0000352 "udp6o6-encap",
Neale Ranns810086d2017-11-05 16:26:46 -0800353 NULL,
354};
355
356const static char *const udp6_encap_mpls_nodes[] = {
357 "udp6-encap",
358 NULL,
359};
360
Neale Ranns91286372017-12-05 13:24:04 -0800361const static char *const udp6_encap_bier_nodes[] = {
362 "udp6-encap",
363 NULL,
364};
365
Neale Ranns810086d2017-11-05 16:26:46 -0800366const static char *const *const udp4_encap_nodes[DPO_PROTO_NUM] = {
367 [DPO_PROTO_IP4] = udp4_encap_ip4_nodes,
368 [DPO_PROTO_IP6] = udp4_encap_ip6_nodes,
369 [DPO_PROTO_MPLS] = udp4_encap_mpls_nodes,
Neale Ranns91286372017-12-05 13:24:04 -0800370 [DPO_PROTO_BIER] = udp4_encap_bier_nodes,
Neale Ranns810086d2017-11-05 16:26:46 -0800371};
372
373const static char *const *const udp6_encap_nodes[DPO_PROTO_NUM] = {
374 [DPO_PROTO_IP4] = udp6_encap_ip4_nodes,
375 [DPO_PROTO_IP6] = udp6_encap_ip6_nodes,
376 [DPO_PROTO_MPLS] = udp6_encap_mpls_nodes,
Neale Ranns91286372017-12-05 13:24:04 -0800377 [DPO_PROTO_BIER] = udp6_encap_bier_nodes,
Neale Ranns810086d2017-11-05 16:26:46 -0800378};
379
380/*
381 * Virtual function table registered by UDP encaps
382 * for participation in the FIB object graph.
383 */
384const static fib_node_vft_t udp_encap_fib_vft = {
385 .fnv_get = udp_encap_fib_node_get,
386 .fnv_last_lock = udp_encap_fib_last_lock_gone,
387 .fnv_back_walk = udp_encap_fib_back_walk,
388};
389
390const static dpo_vft_t udp_encap_dpo_vft = {
391 .dv_lock = udp_encap_dpo_lock,
392 .dv_unlock = udp_encap_dpo_unlock,
393 .dv_format = format_udp_encap_dpo,
Neale Ranns810086d2017-11-05 16:26:46 -0800394};
395
396clib_error_t *
397udp_encap_init (vlib_main_t * vm)
398{
Neale Ranns810086d2017-11-05 16:26:46 -0800399 fib_node_register_type (FIB_NODE_TYPE_UDP_ENCAP, &udp_encap_fib_vft);
400
401 udp_encap_dpo_types[FIB_PROTOCOL_IP4] =
402 dpo_register_new_type (&udp_encap_dpo_vft, udp4_encap_nodes);
403 udp_encap_dpo_types[FIB_PROTOCOL_IP6] =
404 dpo_register_new_type (&udp_encap_dpo_vft, udp6_encap_nodes);
405
406 return (NULL);
407}
408
409VLIB_INIT_FUNCTION (udp_encap_init);
410
411clib_error_t *
412udp_encap_cli (vlib_main_t * vm,
413 unformat_input_t * main_input, vlib_cli_command_t * cmd)
414{
415 unformat_input_t _line_input, *line_input = &_line_input;
416 clib_error_t *error = NULL;
417 ip46_address_t src_ip, dst_ip;
Neale Ranns9c0a3c42018-09-07 08:57:41 -0700418 u32 table_id, src_port, dst_port;
Neale Ranns810086d2017-11-05 16:26:46 -0800419 udp_encap_fixup_flags_t flags;
420 fib_protocol_t fproto;
Neale Ranns9c0a3c42018-09-07 08:57:41 -0700421 index_t uei;
Neale Ranns810086d2017-11-05 16:26:46 -0800422 u8 is_del;
423
424 is_del = 0;
425 table_id = 0;
426 flags = UDP_ENCAP_FIXUP_NONE;
427 fproto = FIB_PROTOCOL_MAX;
428 dst_port = 0;
Neale Ranns9c0a3c42018-09-07 08:57:41 -0700429 uei = ~0;
Neale Ranns810086d2017-11-05 16:26:46 -0800430
431 /* Get a line of input. */
432 if (!unformat_user (main_input, unformat_line_input, line_input))
433 return 0;
434
435 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
436 {
Neale Ranns9c0a3c42018-09-07 08:57:41 -0700437 if (unformat (line_input, "index %d", &uei))
Neale Ranns810086d2017-11-05 16:26:46 -0800438 ;
439 else if (unformat (line_input, "add"))
440 is_del = 0;
441 else if (unformat (line_input, "del"))
442 is_del = 1;
443 else if (unformat (line_input, "%U %U",
444 unformat_ip4_address,
445 &src_ip.ip4, unformat_ip4_address, &dst_ip.ip4))
446 fproto = FIB_PROTOCOL_IP4;
447 else if (unformat (line_input, "%U %U",
448 unformat_ip6_address,
449 &src_ip.ip6, unformat_ip6_address, &dst_ip.ip6))
450 fproto = FIB_PROTOCOL_IP6;
451 else if (unformat (line_input, "%d %d", &src_port, &dst_port))
452 ;
453 else if (unformat (line_input, "%d", &dst_port))
454 ;
455 else if (unformat (line_input, "table-id %d", &table_id))
456 ;
457 else if (unformat (line_input, "src-port-is-entropy"))
458 flags |= UDP_ENCAP_FIXUP_UDP_SRC_PORT_ENTROPY;
459 else
460 {
461 error = unformat_parse_error (line_input);
462 goto done;
463 }
464 }
465
Neale Ranns810086d2017-11-05 16:26:46 -0800466 if (!is_del && fproto != FIB_PROTOCOL_MAX)
467 {
468 u32 fib_index;
469 index_t uei;
470
471 fib_index = fib_table_find (fproto, table_id);
472
473 if (~0 == fib_index)
474 {
475 error = clib_error_return (0, "Nonexistent table id %d", table_id);
476 goto done;
477 }
478
Neale Ranns9c0a3c42018-09-07 08:57:41 -0700479 uei = udp_encap_add_and_lock (fproto, fib_index,
Neale Ranns810086d2017-11-05 16:26:46 -0800480 &src_ip, &dst_ip,
481 src_port, dst_port, flags);
482
Neale Ranns9c0a3c42018-09-07 08:57:41 -0700483 vlib_cli_output (vm, "udp-encap: %d\n", uei);
Neale Ranns810086d2017-11-05 16:26:46 -0800484 }
485 else if (is_del)
486 {
Neale Ranns9c0a3c42018-09-07 08:57:41 -0700487 if (INDEX_INVALID == uei)
488 {
489 error = clib_error_return (0, "specify udp-encap object index");
490 goto done;
491 }
492 udp_encap_unlock (uei);
Neale Ranns810086d2017-11-05 16:26:46 -0800493 }
494 else
495 {
Neale Ranns9c0a3c42018-09-07 08:57:41 -0700496 error = clib_error_return (0, "specify some IP addresses");
Neale Ranns810086d2017-11-05 16:26:46 -0800497 }
498
499done:
500 unformat_free (line_input);
501 return error;
502}
503
Neale Ranns43b1f442018-03-20 01:47:35 -0700504void
505udp_encap_walk (udp_encap_walk_cb_t cb, void *ctx)
506{
507 index_t uei;
508
509 /* *INDENT-OFF* */
Damjan Marionb2c31b62020-12-13 21:47:40 +0100510 pool_foreach_index (uei, udp_encap_pool)
511 {
Neale Ranns586479a2018-06-07 02:08:07 -0700512 if (WALK_STOP == cb(uei, ctx))
Neale Ranns43b1f442018-03-20 01:47:35 -0700513 break;
Damjan Marionb2c31b62020-12-13 21:47:40 +0100514 }
Neale Ranns43b1f442018-03-20 01:47:35 -0700515 /* *INDENT-ON* */
516}
517
Neale Ranns810086d2017-11-05 16:26:46 -0800518clib_error_t *
519udp_encap_show (vlib_main_t * vm,
520 unformat_input_t * input, vlib_cli_command_t * cmd)
521{
Neale Ranns9c0a3c42018-09-07 08:57:41 -0700522 index_t uei;
Neale Ranns810086d2017-11-05 16:26:46 -0800523
Neale Ranns9c0a3c42018-09-07 08:57:41 -0700524 uei = INDEX_INVALID;
Neale Ranns810086d2017-11-05 16:26:46 -0800525
526 /* Get a line of input. */
527 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
528 {
Neale Ranns9c0a3c42018-09-07 08:57:41 -0700529 if (unformat (input, "%d", &uei))
Neale Ranns810086d2017-11-05 16:26:46 -0800530 ;
Swarup Nayak529a4252017-12-21 11:35:33 +0530531 else
532 return clib_error_return (0, "unknown input `%U'",
533 format_unformat_error, input);
Neale Ranns810086d2017-11-05 16:26:46 -0800534 }
535
Neale Ranns9c0a3c42018-09-07 08:57:41 -0700536 if (INDEX_INVALID == uei)
Neale Ranns810086d2017-11-05 16:26:46 -0800537 {
Neale Ranns810086d2017-11-05 16:26:46 -0800538 /* *INDENT-OFF* */
Damjan Marionb2c31b62020-12-13 21:47:40 +0100539 pool_foreach_index (uei, udp_encap_pool)
540 {
Neale Ranns9c0a3c42018-09-07 08:57:41 -0700541 vlib_cli_output(vm, "%U", format_udp_encap, uei, 0);
Damjan Marionb2c31b62020-12-13 21:47:40 +0100542 }
Neale Ranns810086d2017-11-05 16:26:46 -0800543 /* *INDENT-ON* */
544 }
545 else
546 {
Neale Ranns9c0a3c42018-09-07 08:57:41 -0700547 vlib_cli_output (vm, "%U", format_udp_encap, uei, 1);
Neale Ranns810086d2017-11-05 16:26:46 -0800548 }
549
550 return NULL;
551}
552
553/* *INDENT-OFF* */
554VLIB_CLI_COMMAND (udp_encap_add_command, static) = {
555 .path = "udp encap",
556 .short_help = "udp encap [add|del] <id ID> <src-ip> <dst-ip> [<src-port>] <dst-port> [src-port-is-entropy] [table-id <table>]",
557 .function = udp_encap_cli,
558 .is_mp_safe = 1,
559};
560VLIB_CLI_COMMAND (udp_encap_show_command, static) = {
561 .path = "show udp encap",
562 .short_help = "show udp encap [ID]",
563 .function = udp_encap_show,
564 .is_mp_safe = 1,
565};
566/* *INDENT-ON* */
567
568/*
569 * fd.io coding-style-patch-verification: ON
570 *
571 * Local Variables:
572 * eval: (c-set-style "gnu")
573 * End:
574 */