Parse IPv4-mapped IPv6 address as an IPv6 address 83/86783/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:26 +0000 (11:30 +0100)
commit8fddf396866ccf5f629d501639ef5124b1225ea4
tree1075c5fcbb407a45908f50aa22c15d7e1fd457ee
parent40fa981a47c2706830862878c942cbf08d8fe2a8
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