From: Ajay Lele Date: Mon, 6 Jan 2020 18:49:50 +0000 (-0800) Subject: Parse IPv4-mapped IPv6 address as an IPv6 address X-Git-Tag: v4.0.9~6 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=mdsal.git;a=commitdiff_plain;h=2250cb68002d1c3c6a93d2786731694b6f82d510 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 (cherry picked from commit 1d8897caf5cec5f044f870f949a15fa57de54d71) --- 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