Parse IPv4-mapped IPv6 address as an IPv6 address 84/86784/1
authorAjay Lele <ajayslele@gmail.com>
Mon, 6 Jan 2020 18:49:50 +0000 (10:49 -0800)
committerRobert Varga <robert.varga@pantheon.tech>
Tue, 7 Jan 2020 10:30:43 +0000 (11:30 +0100)
commit2250cb68002d1c3c6a93d2786731694b6f82d510
tree3502221e5fc4b309dbc84cfbcf586b600888006a
parent02d183b718d11ac6cf8dbbd43b859218135ee8fe
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 <ajayslele@gmail.com>
Change-Id: Ife4cc9e57bd49b45f2beb73462a865ad84483d8f
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
(cherry picked from commit 1d8897caf5cec5f044f870f949a15fa57de54d71)
model/ietf/ietf-type-util/src/main/java/org/opendaylight/mdsal/model/ietf/util/AbstractIetfInetUtil.java
model/ietf/ietf-type-util/src/test/java/org/opendaylight/mdsal/model/ietf/util/AbstractIetfInetUtilTest.java