Parse IPv4-mapped IPv6 address as an IPv6 address 57/86757/3
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:01:36 +0000 (11:01 +0100)
commit1d8897caf5cec5f044f870f949a15fa57de54d71
treefb0aaf2e837333dc201166a9cc9f3cc2f893968b
parent4b26656c945b9af5e67d28d10b014b0ed37cc510
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>
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