udp: improve port validity check

- do not allocate port sparse vector when only checking if a port is
   already in use
 - do not display port that have been unregistered by default

Type: improvement

Change-Id: I6cc94e35806dd8d415cd5d1c1c51e6b066ac26a1
Signed-off-by: Benoît Ganne <bganne@cisco.com>
(cherry picked from commit d52f80f422)
This commit is contained in:
Benoît Ganne
2023-06-05 10:02:29 +02:00
committed by Andrew Yourtchenko
parent 63e76fad7e
commit f7687220e0
2 changed files with 14 additions and 13 deletions

View File

@ -211,16 +211,21 @@ static void
table_format_udp_port_ (vlib_main_t *vm, udp_main_t *um, table_t *t, int *c,
int port, int bind, int is_ip4)
{
const udp_dst_port_info_t *pi = udp_get_dst_port_info (um, port, is_ip4);
const udp_dst_port_info_t *pi;
if (bind && !udp_is_valid_dst_port (port, is_ip4))
return;
pi = udp_get_dst_port_info (um, port, is_ip4);
if (!pi)
return;
if (bind && ~0 == pi->node_index)
return;
table_format_cell (t, *c, 0, "%d", pi->dst_port);
table_format_cell (t, *c, 1, is_ip4 ? "ip4" : "ip6");
table_format_cell (t, *c, 2, ~0 == pi->node_index ? "none" : "%U",
format_vlib_node_name, vm, pi->node_index);
table_format_cell (t, *c, 3, "%s", pi->name);
(*c)++;
}

View File

@ -523,16 +523,12 @@ u8
udp_is_valid_dst_port (udp_dst_port_t dst_port, u8 is_ip4)
{
udp_main_t *um = &udp_main;
u16 *n;
if (is_ip4)
n = sparse_vec_validate (um->next_by_dst_port4,
clib_host_to_net_u16 (dst_port));
else
n = sparse_vec_validate (um->next_by_dst_port6,
clib_host_to_net_u16 (dst_port));
return (n[0] != SPARSE_VEC_INVALID_INDEX && n[0] != UDP_NO_NODE_SET);
u16 *next_by_dst_port =
is_ip4 ? um->next_by_dst_port4 : um->next_by_dst_port6;
uword index =
sparse_vec_index (next_by_dst_port, clib_host_to_net_u16 (dst_port));
return (index != SPARSE_VEC_INVALID_INDEX &&
vec_elt (next_by_dst_port, index) != UDP_NO_NODE_SET);
}
void