From 1d8897caf5cec5f044f870f949a15fa57de54d71 Mon Sep 17 00:00:00 2001 From: Ajay Lele Date: Mon, 6 Jan 2020 10:49:50 -0800 Subject: [PATCH] Parse IPv4-mapped IPv6 address as an IPv6 address Inet6Address.getByAddress(byte[]) does not explicitly exist, and is really InetAddress.getByAddress(byte[]). That method ends up returning an Inet4Address for IPv4-mapped IPv6 addresses. This in turn causes addressStringV6() to do the wrong thing and format the address as an Ipv4. This is not caught by validation, as we are skipping it by default -- and ends up causing problems way later when such an address meets an enforcement point -- such as DOM->Binding translation. Fix this by using Inet6Address.getByAddress(String. byte[], NetworkInterface), which is guaranteed to result in an Inet6Address. Also add proper defences to addressStringV6(InetAddress), so that any attempt to mis-use it is caught. JIRA: BGPCEP-891 Signed-off-by: Ajay Lele Change-Id: Ife4cc9e57bd49b45f2beb73462a865ad84483d8f Signed-off-by: Robert Varga --- .../model/ietf/util/AbstractIetfInetUtil.java | 18 +++++++++--------- .../ietf/util/AbstractIetfInetUtilTest.java | 5 +++++ 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/model/ietf/ietf-type-util/src/main/java/org/opendaylight/mdsal/model/ietf/util/AbstractIetfInetUtil.java b/model/ietf/ietf-type-util/src/main/java/org/opendaylight/mdsal/model/ietf/util/AbstractIetfInetUtil.java index 87c5beb893..aca74d459f 100644 --- a/model/ietf/ietf-type-util/src/main/java/org/opendaylight/mdsal/model/ietf/util/AbstractIetfInetUtil.java +++ b/model/ietf/ietf-type-util/src/main/java/org/opendaylight/mdsal/model/ietf/util/AbstractIetfInetUtil.java @@ -478,8 +478,6 @@ public abstract class AbstractIetfInetUtil= 0 && mask <= 128, "Invalid mask %s", mask); return prefix6Factory.newInstance(addressStringV6(addr) + '/' + mask); } @@ -683,13 +677,19 @@ public abstract class AbstractIetfInetUtil