summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorAndreas Schultz <andreas.schultz@travelping.com>2020-05-12 14:41:16 +0200
committerFlorin Coras <florin.coras@gmail.com>2020-06-01 15:41:08 +0000
commit3b519b38b0df186f424d2ff2f5e8015408d67c53 (patch)
tree3d7bef0fddadfe9de95b16d09776439a0a150790 /src
parent63c672c440d92cc570c587254afb4167617ec0b7 (diff)
ip: fix IPv6 mask to prefix length conversion
make sure we don't pass a 0 (zero) to log2. Type: fix Signed-off-by: Andreas Schultz <andreas.schultz@travelping.com> Change-Id: Ib3386ad4686835d3836f48294cee4058e897847a
Diffstat (limited to 'src')
-rw-r--r--src/vat/ip_types.c15
-rw-r--r--src/vnet/ip/ip_types.c15
2 files changed, 10 insertions, 20 deletions
diff --git a/src/vat/ip_types.c b/src/vat/ip_types.c
index cd08c5417ad..5041c129245 100644
--- a/src/vat/ip_types.c
+++ b/src/vat/ip_types.c
@@ -511,16 +511,11 @@ ip6_prefix_max_address_host_order (ip6_address_t * ip, u8 plen,
u32
ip6_mask_to_preflen (ip6_address_t * mask)
{
- u8 first1, first0;
- if (mask->as_u64[0] == 0 && mask->as_u64[1] == 0)
- return 0;
- first1 = log2_first_set (clib_net_to_host_u64 (mask->as_u64[1]));
- first0 = log2_first_set (clib_net_to_host_u64 (mask->as_u64[0]));
-
- if (first1 != 0)
- return 128 - first1;
- else
- return 64 - first0;
+ if (mask->as_u64[1] != 0)
+ return 128 - log2_first_set (clib_net_to_host_u64 (mask->as_u64[1]));
+ if (mask->as_u64[0] != 0)
+ return 64 - log2_first_set (clib_net_to_host_u64 (mask->as_u64[0]));
+ return 0;
}
/*
diff --git a/src/vnet/ip/ip_types.c b/src/vnet/ip/ip_types.c
index cd08c5417ad..5041c129245 100644
--- a/src/vnet/ip/ip_types.c
+++ b/src/vnet/ip/ip_types.c
@@ -511,16 +511,11 @@ ip6_prefix_max_address_host_order (ip6_address_t * ip, u8 plen,
u32
ip6_mask_to_preflen (ip6_address_t * mask)
{
- u8 first1, first0;
- if (mask->as_u64[0] == 0 && mask->as_u64[1] == 0)
- return 0;
- first1 = log2_first_set (clib_net_to_host_u64 (mask->as_u64[1]));
- first0 = log2_first_set (clib_net_to_host_u64 (mask->as_u64[0]));
-
- if (first1 != 0)
- return 128 - first1;
- else
- return 64 - first0;
+ if (mask->as_u64[1] != 0)
+ return 128 - log2_first_set (clib_net_to_host_u64 (mask->as_u64[1]));
+ if (mask->as_u64[0] != 0)
+ return 64 - log2_first_set (clib_net_to_host_u64 (mask->as_u64[0]));
+ return 0;
}
/*