aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorBenoît Ganne <bganne@cisco.com>2022-04-26 18:44:19 +0200
committerBeno�t Ganne <bganne@cisco.com>2022-06-01 08:15:07 +0000
commitdd2f12ba6ab952d9d66f4d9ba89ffde6309b1ff2 (patch)
tree54ac79bb3b4a3abe33f3eff7323e77da8648aa0f /src
parentd1ca70c7e11dac7b9fff802ca5f1d9051c984c34 (diff)
ip: unformat_ip_address should no modify its argument on failure
When failing to match an ip address, we should not reset the ip address that could have been initialized by a previous match. Type: fix Change-Id: I026766391eb3eb8230f75f66bf4b681e774741d9 Signed-off-by: Benoît Ganne <bganne@cisco.com>
Diffstat (limited to 'src')
-rw-r--r--src/vat/ip_types.c17
-rw-r--r--src/vnet/ip/ip_types.c17
2 files changed, 18 insertions, 16 deletions
diff --git a/src/vat/ip_types.c b/src/vat/ip_types.c
index f4dcc96febe..cdfcbc07de3 100644
--- a/src/vat/ip_types.c
+++ b/src/vat/ip_types.c
@@ -42,14 +42,15 @@ unformat_ip_address (unformat_input_t * input, va_list * args)
{
ip_address_t *a = va_arg (*args, ip_address_t *);
- clib_memset (a, 0, sizeof (*a));
- if (unformat (input, "%U", unformat_ip4_address, &ip_addr_v4 (a)))
- ip_addr_version (a) = AF_IP4;
- else if (unformat_user (input, unformat_ip6_address, &ip_addr_v6 (a)))
- ip_addr_version (a) = AF_IP6;
- else
- return 0;
- return 1;
+ if (unformat_user (input, unformat_ip46_address, &ip_addr_46 (a),
+ IP46_TYPE_ANY))
+ {
+ ip_addr_version (a) =
+ ip46_address_is_ip4 (&ip_addr_46 (a)) ? AF_IP4 : AF_IP6;
+ return 1;
+ }
+
+ return 0;
}
u8 *
diff --git a/src/vnet/ip/ip_types.c b/src/vnet/ip/ip_types.c
index 323cf4d456c..88b3f7b9820 100644
--- a/src/vnet/ip/ip_types.c
+++ b/src/vnet/ip/ip_types.c
@@ -42,14 +42,15 @@ unformat_ip_address (unformat_input_t * input, va_list * args)
{
ip_address_t *a = va_arg (*args, ip_address_t *);
- clib_memset (a, 0, sizeof (*a));
- if (unformat (input, "%U", unformat_ip4_address, &ip_addr_v4 (a)))
- ip_addr_version (a) = AF_IP4;
- else if (unformat_user (input, unformat_ip6_address, &ip_addr_v6 (a)))
- ip_addr_version (a) = AF_IP6;
- else
- return 0;
- return 1;
+ if (unformat_user (input, unformat_ip46_address, &ip_addr_46 (a),
+ IP46_TYPE_ANY))
+ {
+ ip_addr_version (a) =
+ ip46_address_is_ip4 (&ip_addr_46 (a)) ? AF_IP4 : AF_IP6;
+ return 1;
+ }
+
+ return 0;
}
u8 *