diff options
author | Neale Ranns <neale@graphiant.com> | 2021-10-25 09:47:09 +0000 |
---|---|---|
committer | Neale Ranns <neale@graphiant.com> | 2021-11-18 14:06:02 +0000 |
commit | b28652ed7ab016177593b059390f2e99e6af2961 (patch) | |
tree | 99f1bc49227d37e467cb74216de8e9324436b416 /src/vnet/ip/ip_types.c | |
parent | fc8d0c510372823ac029b6330e876fab9400dbae (diff) |
ip: comparing IP prefixes should not modify them
Type: improvement
make the ip_prefix_cmp take const paramenters.
plus some other miscellaneous functions.
Signed-off-by: Neale Ranns <neale@graphiant.com>
Change-Id: Ib69bacfb09483a8a8f8b89900c92d3d55c354ac6
Diffstat (limited to 'src/vnet/ip/ip_types.c')
-rw-r--r-- | src/vnet/ip/ip_types.c | 20 |
1 files changed, 14 insertions, 6 deletions
diff --git a/src/vnet/ip/ip_types.c b/src/vnet/ip/ip_types.c index 3e5ecebf142..323cf4d456c 100644 --- a/src/vnet/ip/ip_types.c +++ b/src/vnet/ip/ip_types.c @@ -288,6 +288,13 @@ ip_address_to_fib_prefix (const ip_address_t * addr, fib_prefix_t * prefix) } void +ip_address_to_prefix (const ip_address_t *addr, ip_prefix_t *prefix) +{ + prefix->len = (addr->version == AF_IP4 ? 32 : 128); + clib_memcpy (&prefix->addr, addr, sizeof (prefix->addr)); +} + +void ip_address_increment (ip_address_t * ip) { ip46_address_increment ((ip_addr_version (ip) == AF_IP4 ? @@ -380,23 +387,24 @@ ip_prefix_copy (void *dst, void *src) } int -ip_prefix_cmp (ip_prefix_t * p1, ip_prefix_t * p2) +ip_prefix_cmp (const ip_prefix_t *ipp1, const ip_prefix_t *ipp2) { + ip_prefix_t p1 = *ipp1, p2 = *ipp2; int cmp = 0; - ip_prefix_normalize (p1); - ip_prefix_normalize (p2); + ip_prefix_normalize (&p1); + ip_prefix_normalize (&p2); - cmp = ip_address_cmp (&ip_prefix_addr (p1), &ip_prefix_addr (p2)); + cmp = ip_address_cmp (&ip_prefix_addr (&p1), &ip_prefix_addr (&p2)); if (cmp == 0) { - if (ip_prefix_len (p1) < ip_prefix_len (p2)) + if (ip_prefix_len (&p1) < ip_prefix_len (&p2)) { cmp = 1; } else { - if (ip_prefix_len (p1) > ip_prefix_len (p2)) + if (ip_prefix_len (&p1) > ip_prefix_len (&p2)) cmp = 2; } } |