blob: c826827628852a832b1ed099d6273eb9ae49f165 [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>
18#include <vnet/fib/fib_table.h>
19#include <vnet/dpo/drop_dpo.h>
20
21/**
22 * Registered DPO types for the IP header encapsulated, v4 or v6.
23 */
24dpo_type_t udp_encap_dpo_types[FIB_PROTOCOL_MAX];
25
26/**
Neale Ranns810086d2017-11-05 16:26:46 -080027 * Pool of encaps
28 */
29udp_encap_t *udp_encap_pool;
30
Neale Ranns43b1f442018-03-20 01:47:35 -070031/**
32 * Stats for each UDP encap object
33 */
Neale Ranns9c0a3c42018-09-07 08:57:41 -070034vlib_combined_counter_main_t udp_encap_counters = {
35 /**
36 * The counter collection's name.
37 */
38 .name = "udp-encap",
39 /**
40 * Name in stat segment directory
41 */
42 .stat_segment_name = "/net/udp-encap",
43};
Neale Ranns810086d2017-11-05 16:26:46 -080044
45static void
46udp_encap_restack (udp_encap_t * ue)
47{
48 dpo_stack (udp_encap_dpo_types[ue->ue_ip_proto],
49 fib_proto_to_dpo (ue->ue_ip_proto),
50 &ue->ue_dpo,
51 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
Neale Ranns9c0a3c42018-09-07 08:57:41 -070066 pool_get_aligned (udp_encap_pool, ue, CLIB_CACHE_LINE_BYTES);
67 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
120 ue->ue_fib_entry_index =
121 fib_table_entry_special_add (fib_index,
122 &dst_pfx,
123 FIB_SOURCE_RR, FIB_ENTRY_FLAG_NONE);
124 ue->ue_fib_sibling =
125 fib_entry_child_add (ue->ue_fib_entry_index,
126 FIB_NODE_TYPE_UDP_ENCAP, uei);
127
128 udp_encap_restack (ue);
129
Neale Ranns810086d2017-11-05 16:26:46 -0800130 return (uei);
131}
132
133void
Neale Ranns9c0a3c42018-09-07 08:57:41 -0700134udp_encap_contribute_forwarding (index_t uei, dpo_proto_t proto,
135 dpo_id_t * dpo)
Neale Ranns810086d2017-11-05 16:26:46 -0800136{
Neale Ranns810086d2017-11-05 16:26:46 -0800137 if (INDEX_INVALID == uei)
138 {
139 dpo_copy (dpo, drop_dpo_get (proto));
140 }
141 else
142 {
143 udp_encap_t *ue;
144
145 ue = udp_encap_get (uei);
146
147 dpo_set (dpo, udp_encap_dpo_types[ue->ue_ip_proto], proto, uei);
148 }
149}
150
Neale Ranns810086d2017-11-05 16:26:46 -0800151void
Neale Ranns9c0a3c42018-09-07 08:57:41 -0700152udp_encap_lock (index_t uei)
Neale Ranns810086d2017-11-05 16:26:46 -0800153{
154 udp_encap_t *ue;
155
Neale Ranns9c0a3c42018-09-07 08:57:41 -0700156 ue = udp_encap_get (uei);
Neale Ranns810086d2017-11-05 16:26:46 -0800157
158 if (NULL != ue)
159 {
160 fib_node_lock (&ue->ue_fib_node);
161 }
162}
163
164void
Neale Ranns9c0a3c42018-09-07 08:57:41 -0700165udp_encap_unlock (index_t uei)
Neale Ranns810086d2017-11-05 16:26:46 -0800166{
167 udp_encap_t *ue;
168
169 if (INDEX_INVALID == uei)
170 {
171 return;
172 }
173
174 ue = udp_encap_get (uei);
175
176 if (NULL != ue)
177 {
178 fib_node_unlock (&ue->ue_fib_node);
179 }
180}
181
Neale Ranns810086d2017-11-05 16:26:46 -0800182static void
183udp_encap_dpo_lock (dpo_id_t * dpo)
184{
185 udp_encap_t *ue;
186
187 ue = udp_encap_get (dpo->dpoi_index);
188
189 fib_node_lock (&ue->ue_fib_node);
190}
191
192static void
193udp_encap_dpo_unlock (dpo_id_t * dpo)
194{
195 udp_encap_t *ue;
196
197 ue = udp_encap_get (dpo->dpoi_index);
198
199 fib_node_unlock (&ue->ue_fib_node);
200}
201
202static u8 *
203format_udp_encap_i (u8 * s, va_list * args)
204{
205 index_t uei = va_arg (*args, index_t);
206 u32 indent = va_arg (*args, u32);
207 u32 details = va_arg (*args, u32);
Neale Ranns43b1f442018-03-20 01:47:35 -0700208 vlib_counter_t to;
Neale Ranns810086d2017-11-05 16:26:46 -0800209 udp_encap_t *ue;
210
211 ue = udp_encap_get (uei);
212
213 // FIXME
Neale Ranns9c0a3c42018-09-07 08:57:41 -0700214 s = format (s, "udp-ecap:[%d]: ip-fib-index:%d ", uei, ue->ue_fib_index);
Neale Ranns810086d2017-11-05 16:26:46 -0800215 if (FIB_PROTOCOL_IP4 == ue->ue_ip_proto)
216 {
217 s = format (s, "ip:[src:%U, dst:%U] udp:[src:%d, dst:%d]",
218 format_ip4_address,
219 &ue->ue_hdrs.ip4.ue_ip4.src_address,
220 format_ip4_address,
221 &ue->ue_hdrs.ip4.ue_ip4.dst_address,
222 clib_net_to_host_u16 (ue->ue_hdrs.ip4.ue_udp.src_port),
223 clib_net_to_host_u16 (ue->ue_hdrs.ip4.ue_udp.dst_port));
224 }
225 else
226 {
227 s = format (s, "ip:[src:%U, dst:%U] udp:[src:%d dst:%d]",
228 format_ip6_address,
229 &ue->ue_hdrs.ip6.ue_ip6.src_address,
230 format_ip6_address,
231 &ue->ue_hdrs.ip6.ue_ip6.dst_address,
232 clib_net_to_host_u16 (ue->ue_hdrs.ip6.ue_udp.src_port),
233 clib_net_to_host_u16 (ue->ue_hdrs.ip6.ue_udp.dst_port));
234 }
Neale Ranns43b1f442018-03-20 01:47:35 -0700235 vlib_get_combined_counter (&(udp_encap_counters), uei, &to);
236 s = format (s, " to:[%Ld:%Ld]]", to.packets, to.bytes);
237
Neale Ranns810086d2017-11-05 16:26:46 -0800238 if (details)
239 {
240 s = format (s, " locks:%d", ue->ue_fib_node.fn_locks);
241 s = format (s, "\n%UStacked on:", format_white_space, indent + 1);
242 s = format (s, "\n%U%U",
243 format_white_space, indent + 2,
244 format_dpo_id, &ue->ue_dpo, indent + 3);
245 }
246 return (s);
247}
248
Neale Ranns43b1f442018-03-20 01:47:35 -0700249void
250udp_encap_get_stats (index_t uei, u64 * packets, u64 * bytes)
251{
252 vlib_counter_t to;
253
254 vlib_get_combined_counter (&(udp_encap_counters), uei, &to);
255
256 *packets = to.packets;
257 *bytes = to.bytes;
258}
259
Neale Ranns810086d2017-11-05 16:26:46 -0800260static u8 *
261format_udp_encap_dpo (u8 * s, va_list * args)
262{
263 index_t uei = va_arg (*args, index_t);
264 u32 indent = va_arg (*args, u32);
265
266 return (format (s, "%U", format_udp_encap_i, uei, indent, 1));
267}
268
269u8 *
270format_udp_encap (u8 * s, va_list * args)
271{
Neale Ranns9c0a3c42018-09-07 08:57:41 -0700272 index_t uei = va_arg (*args, u32);
Neale Ranns810086d2017-11-05 16:26:46 -0800273 u32 details = va_arg (*args, u32);
Neale Ranns810086d2017-11-05 16:26:46 -0800274
275 return (format (s, "%U", format_udp_encap_i, uei, 0, details));
276}
277
278static udp_encap_t *
279udp_encap_from_fib_node (fib_node_t * node)
280{
Neale Ranns810086d2017-11-05 16:26:46 -0800281 ASSERT (FIB_NODE_TYPE_UDP_ENCAP == node->fn_type);
Neale Ranns810086d2017-11-05 16:26:46 -0800282 return ((udp_encap_t *) (((char *) node) -
283 STRUCT_OFFSET_OF (udp_encap_t, ue_fib_node)));
284}
285
286/**
287 * Function definition to backwalk a FIB node
288 */
289static fib_node_back_walk_rc_t
290udp_encap_fib_back_walk (fib_node_t * node, fib_node_back_walk_ctx_t * ctx)
291{
292 udp_encap_restack (udp_encap_from_fib_node (node));
293
294 return (FIB_NODE_BACK_WALK_CONTINUE);
295}
296
297/**
298 * Function definition to get a FIB node from its index
299 */
300static fib_node_t *
301udp_encap_fib_node_get (fib_node_index_t index)
302{
303 udp_encap_t *ue;
304
305 ue = pool_elt_at_index (udp_encap_pool, index);
306
307 return (&ue->ue_fib_node);
308}
309
310/**
311 * Function definition to inform the FIB node that its last lock has gone.
312 */
313static void
314udp_encap_fib_last_lock_gone (fib_node_t * node)
315{
316 udp_encap_t *ue;
317
318 ue = udp_encap_from_fib_node (node);
319
320 /**
321 * reset the stacked DPO to unlock it
322 */
323 dpo_reset (&ue->ue_dpo);
Neale Ranns810086d2017-11-05 16:26:46 -0800324
325 fib_entry_child_remove (ue->ue_fib_entry_index, ue->ue_fib_sibling);
326 fib_table_entry_delete_index (ue->ue_fib_entry_index, FIB_SOURCE_RR);
327
328
329 pool_put (udp_encap_pool, ue);
330}
331
332const static char *const udp4_encap_ip4_nodes[] = {
333 "udp4-encap",
334 NULL,
335};
336
337const static char *const udp4_encap_ip6_nodes[] = {
338 "udp4-encap",
339 NULL,
340};
341
342const static char *const udp4_encap_mpls_nodes[] = {
343 "udp4-encap",
344 NULL,
345};
346
Neale Ranns91286372017-12-05 13:24:04 -0800347const static char *const udp4_encap_bier_nodes[] = {
348 "udp4-encap",
349 NULL,
350};
351
Neale Ranns810086d2017-11-05 16:26:46 -0800352const static char *const udp6_encap_ip4_nodes[] = {
353 "udp6-encap",
354 NULL,
355};
356
357const static char *const udp6_encap_ip6_nodes[] = {
358 "udp6-encap",
359 NULL,
360};
361
362const static char *const udp6_encap_mpls_nodes[] = {
363 "udp6-encap",
364 NULL,
365};
366
Neale Ranns91286372017-12-05 13:24:04 -0800367const static char *const udp6_encap_bier_nodes[] = {
368 "udp6-encap",
369 NULL,
370};
371
Neale Ranns810086d2017-11-05 16:26:46 -0800372const static char *const *const udp4_encap_nodes[DPO_PROTO_NUM] = {
373 [DPO_PROTO_IP4] = udp4_encap_ip4_nodes,
374 [DPO_PROTO_IP6] = udp4_encap_ip6_nodes,
375 [DPO_PROTO_MPLS] = udp4_encap_mpls_nodes,
Neale Ranns91286372017-12-05 13:24:04 -0800376 [DPO_PROTO_BIER] = udp4_encap_bier_nodes,
Neale Ranns810086d2017-11-05 16:26:46 -0800377};
378
379const static char *const *const udp6_encap_nodes[DPO_PROTO_NUM] = {
380 [DPO_PROTO_IP4] = udp6_encap_ip4_nodes,
381 [DPO_PROTO_IP6] = udp6_encap_ip6_nodes,
382 [DPO_PROTO_MPLS] = udp6_encap_mpls_nodes,
Neale Ranns91286372017-12-05 13:24:04 -0800383 [DPO_PROTO_BIER] = udp6_encap_bier_nodes,
Neale Ranns810086d2017-11-05 16:26:46 -0800384};
385
386/*
387 * Virtual function table registered by UDP encaps
388 * for participation in the FIB object graph.
389 */
390const static fib_node_vft_t udp_encap_fib_vft = {
391 .fnv_get = udp_encap_fib_node_get,
392 .fnv_last_lock = udp_encap_fib_last_lock_gone,
393 .fnv_back_walk = udp_encap_fib_back_walk,
394};
395
396const static dpo_vft_t udp_encap_dpo_vft = {
397 .dv_lock = udp_encap_dpo_lock,
398 .dv_unlock = udp_encap_dpo_unlock,
399 .dv_format = format_udp_encap_dpo,
Neale Ranns810086d2017-11-05 16:26:46 -0800400};
401
402clib_error_t *
403udp_encap_init (vlib_main_t * vm)
404{
Neale Ranns810086d2017-11-05 16:26:46 -0800405 fib_node_register_type (FIB_NODE_TYPE_UDP_ENCAP, &udp_encap_fib_vft);
406
407 udp_encap_dpo_types[FIB_PROTOCOL_IP4] =
408 dpo_register_new_type (&udp_encap_dpo_vft, udp4_encap_nodes);
409 udp_encap_dpo_types[FIB_PROTOCOL_IP6] =
410 dpo_register_new_type (&udp_encap_dpo_vft, udp6_encap_nodes);
411
412 return (NULL);
413}
414
415VLIB_INIT_FUNCTION (udp_encap_init);
416
417clib_error_t *
418udp_encap_cli (vlib_main_t * vm,
419 unformat_input_t * main_input, vlib_cli_command_t * cmd)
420{
421 unformat_input_t _line_input, *line_input = &_line_input;
422 clib_error_t *error = NULL;
423 ip46_address_t src_ip, dst_ip;
Neale Ranns9c0a3c42018-09-07 08:57:41 -0700424 u32 table_id, src_port, dst_port;
Neale Ranns810086d2017-11-05 16:26:46 -0800425 udp_encap_fixup_flags_t flags;
426 fib_protocol_t fproto;
Neale Ranns9c0a3c42018-09-07 08:57:41 -0700427 index_t uei;
Neale Ranns810086d2017-11-05 16:26:46 -0800428 u8 is_del;
429
430 is_del = 0;
431 table_id = 0;
432 flags = UDP_ENCAP_FIXUP_NONE;
433 fproto = FIB_PROTOCOL_MAX;
434 dst_port = 0;
Neale Ranns9c0a3c42018-09-07 08:57:41 -0700435 uei = ~0;
Neale Ranns810086d2017-11-05 16:26:46 -0800436
437 /* Get a line of input. */
438 if (!unformat_user (main_input, unformat_line_input, line_input))
439 return 0;
440
441 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
442 {
Neale Ranns9c0a3c42018-09-07 08:57:41 -0700443 if (unformat (line_input, "index %d", &uei))
Neale Ranns810086d2017-11-05 16:26:46 -0800444 ;
445 else if (unformat (line_input, "add"))
446 is_del = 0;
447 else if (unformat (line_input, "del"))
448 is_del = 1;
449 else if (unformat (line_input, "%U %U",
450 unformat_ip4_address,
451 &src_ip.ip4, unformat_ip4_address, &dst_ip.ip4))
452 fproto = FIB_PROTOCOL_IP4;
453 else if (unformat (line_input, "%U %U",
454 unformat_ip6_address,
455 &src_ip.ip6, unformat_ip6_address, &dst_ip.ip6))
456 fproto = FIB_PROTOCOL_IP6;
457 else if (unformat (line_input, "%d %d", &src_port, &dst_port))
458 ;
459 else if (unformat (line_input, "%d", &dst_port))
460 ;
461 else if (unformat (line_input, "table-id %d", &table_id))
462 ;
463 else if (unformat (line_input, "src-port-is-entropy"))
464 flags |= UDP_ENCAP_FIXUP_UDP_SRC_PORT_ENTROPY;
465 else
466 {
467 error = unformat_parse_error (line_input);
468 goto done;
469 }
470 }
471
Neale Ranns810086d2017-11-05 16:26:46 -0800472 if (!is_del && fproto != FIB_PROTOCOL_MAX)
473 {
474 u32 fib_index;
475 index_t uei;
476
477 fib_index = fib_table_find (fproto, table_id);
478
479 if (~0 == fib_index)
480 {
481 error = clib_error_return (0, "Nonexistent table id %d", table_id);
482 goto done;
483 }
484
Neale Ranns9c0a3c42018-09-07 08:57:41 -0700485 uei = udp_encap_add_and_lock (fproto, fib_index,
Neale Ranns810086d2017-11-05 16:26:46 -0800486 &src_ip, &dst_ip,
487 src_port, dst_port, flags);
488
Neale Ranns9c0a3c42018-09-07 08:57:41 -0700489 vlib_cli_output (vm, "udp-encap: %d\n", uei);
Neale Ranns810086d2017-11-05 16:26:46 -0800490 }
491 else if (is_del)
492 {
Neale Ranns9c0a3c42018-09-07 08:57:41 -0700493 if (INDEX_INVALID == uei)
494 {
495 error = clib_error_return (0, "specify udp-encap object index");
496 goto done;
497 }
498 udp_encap_unlock (uei);
Neale Ranns810086d2017-11-05 16:26:46 -0800499 }
500 else
501 {
Neale Ranns9c0a3c42018-09-07 08:57:41 -0700502 error = clib_error_return (0, "specify some IP addresses");
Neale Ranns810086d2017-11-05 16:26:46 -0800503 }
504
505done:
506 unformat_free (line_input);
507 return error;
508}
509
Neale Ranns43b1f442018-03-20 01:47:35 -0700510void
511udp_encap_walk (udp_encap_walk_cb_t cb, void *ctx)
512{
513 index_t uei;
514
515 /* *INDENT-OFF* */
516 pool_foreach_index(uei, udp_encap_pool,
517 ({
Neale Ranns586479a2018-06-07 02:08:07 -0700518 if (WALK_STOP == cb(uei, ctx))
Neale Ranns43b1f442018-03-20 01:47:35 -0700519 break;
520 }));
521 /* *INDENT-ON* */
522}
523
Neale Ranns810086d2017-11-05 16:26:46 -0800524clib_error_t *
525udp_encap_show (vlib_main_t * vm,
526 unformat_input_t * input, vlib_cli_command_t * cmd)
527{
Neale Ranns9c0a3c42018-09-07 08:57:41 -0700528 index_t uei;
Neale Ranns810086d2017-11-05 16:26:46 -0800529
Neale Ranns9c0a3c42018-09-07 08:57:41 -0700530 uei = INDEX_INVALID;
Neale Ranns810086d2017-11-05 16:26:46 -0800531
532 /* Get a line of input. */
533 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
534 {
Neale Ranns9c0a3c42018-09-07 08:57:41 -0700535 if (unformat (input, "%d", &uei))
Neale Ranns810086d2017-11-05 16:26:46 -0800536 ;
Swarup Nayak529a4252017-12-21 11:35:33 +0530537 else
538 return clib_error_return (0, "unknown input `%U'",
539 format_unformat_error, input);
Neale Ranns810086d2017-11-05 16:26:46 -0800540 }
541
Neale Ranns9c0a3c42018-09-07 08:57:41 -0700542 if (INDEX_INVALID == uei)
Neale Ranns810086d2017-11-05 16:26:46 -0800543 {
Neale Ranns810086d2017-11-05 16:26:46 -0800544 /* *INDENT-OFF* */
Neale Ranns9c0a3c42018-09-07 08:57:41 -0700545 pool_foreach_index(uei, udp_encap_pool,
Neale Ranns810086d2017-11-05 16:26:46 -0800546 ({
Neale Ranns9c0a3c42018-09-07 08:57:41 -0700547 vlib_cli_output(vm, "%U", format_udp_encap, uei, 0);
Neale Ranns810086d2017-11-05 16:26:46 -0800548 }));
549 /* *INDENT-ON* */
550 }
551 else
552 {
Neale Ranns9c0a3c42018-09-07 08:57:41 -0700553 vlib_cli_output (vm, "%U", format_udp_encap, uei, 1);
Neale Ranns810086d2017-11-05 16:26:46 -0800554 }
555
556 return NULL;
557}
558
559/* *INDENT-OFF* */
560VLIB_CLI_COMMAND (udp_encap_add_command, static) = {
561 .path = "udp encap",
562 .short_help = "udp encap [add|del] <id ID> <src-ip> <dst-ip> [<src-port>] <dst-port> [src-port-is-entropy] [table-id <table>]",
563 .function = udp_encap_cli,
564 .is_mp_safe = 1,
565};
566VLIB_CLI_COMMAND (udp_encap_show_command, static) = {
567 .path = "show udp encap",
568 .short_help = "show udp encap [ID]",
569 .function = udp_encap_show,
570 .is_mp_safe = 1,
571};
572/* *INDENT-ON* */
573
574/*
575 * fd.io coding-style-patch-verification: ON
576 *
577 * Local Variables:
578 * eval: (c-set-style "gnu")
579 * End:
580 */