diff options
author | Benoît Ganne <bganne@cisco.com> | 2023-06-05 10:02:29 +0200 |
---|---|---|
committer | Andrew Yourtchenko <ayourtch@gmail.com> | 2023-06-13 12:49:36 +0000 |
commit | f7687220e06f30105d4318679bec3d2ea04189c6 (patch) | |
tree | 7055ba1d336f5032e94c645648b940852d2de6ad /src/vnet/udp/udp_local.c | |
parent | 63e76fad7e369746f71305a3c9a88d035ec5cb58 (diff) |
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 d52f80f422439227e98d9d26bf43394c69f8a7fd)
Diffstat (limited to 'src/vnet/udp/udp_local.c')
-rw-r--r-- | src/vnet/udp/udp_local.c | 16 |
1 files changed, 6 insertions, 10 deletions
diff --git a/src/vnet/udp/udp_local.c b/src/vnet/udp/udp_local.c index 41938b8f1f7..88378ae04bc 100644 --- a/src/vnet/udp/udp_local.c +++ b/src/vnet/udp/udp_local.c @@ -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 |