diff options
author | Marek Gradzki <mgradzki@cisco.com> | 2017-11-20 14:00:32 +0100 |
---|---|---|
committer | Marek Gradzki <mgradzki@cisco.com> | 2017-11-20 14:00:35 +0100 |
commit | c3524b9d3b8579f1aa79bf8c123299a94f4dcc18 (patch) | |
tree | a15cdec8ef50b5e0ad05acaea65df622a1e82e0e /vpp-common/vpp-translate-utils/src/main/java/io | |
parent | 87e37b4f78ff60e3b8c84c3c6670e20c18e20b04 (diff) |
Use InetAddresses.forString instead of InetAddress.getByName
Unlike InetAddress.getByName(), Guava's InetAddresses.forString()
never cause DNS services to be accessed.
JDK equivalents whenever you are expecting
to handle only IP address string literals,
so there is no blocking DNS penalty for a malformed string.
See:
https://google.github.io/guava/releases/22.0/api/docs/com/google/common/net/InetAddresses.html#forString-java.lang.String-
Change-Id: I7972c09f1f0a3a2688021302acbf6df112be7f72
Signed-off-by: Marek Gradzki <mgradzki@cisco.com>
Diffstat (limited to 'vpp-common/vpp-translate-utils/src/main/java/io')
-rw-r--r-- | vpp-common/vpp-translate-utils/src/main/java/io/fd/hc2vpp/common/translate/util/Ipv6Translator.java | 23 |
1 files changed, 1 insertions, 22 deletions
diff --git a/vpp-common/vpp-translate-utils/src/main/java/io/fd/hc2vpp/common/translate/util/Ipv6Translator.java b/vpp-common/vpp-translate-utils/src/main/java/io/fd/hc2vpp/common/translate/util/Ipv6Translator.java index d2f046302..6a71d6af2 100644 --- a/vpp-common/vpp-translate-utils/src/main/java/io/fd/hc2vpp/common/translate/util/Ipv6Translator.java +++ b/vpp-common/vpp-translate-utils/src/main/java/io/fd/hc2vpp/common/translate/util/Ipv6Translator.java @@ -43,17 +43,7 @@ public interface Ipv6Translator extends ByteDataTranslator { * @return byte array with address bytes */ default byte[] ipv6AddressNoZoneToArray(@Nonnull final Ipv6Address address) { - return Impl.ipv6AddressNoZoneToArray(address.getValue()); - } - - /** - * Transform Ipv6 address to a byte array acceptable by VPP. VPP expects incoming byte array to be in the same order - * as the address. - * - * @return byte array with address bytes - */ - default byte[] ipv6AddressNoZoneToArray(@Nonnull final Ipv6AddressNoZone ipv6Addr) { - return Impl.ipv6AddressNoZoneToArray(ipv6Addr.getValue()); + return InetAddresses.forString(address.getValue()).getAddress(); } /** @@ -138,15 +128,4 @@ public interface Ipv6Translator extends ByteDataTranslator { "Cannot create prefix for address[" + Arrays.toString(address) + "],prefix[" + prefix + "]", e); } } - - class Impl { - private static byte[] ipv6AddressNoZoneToArray(@Nonnull final String address){ - try { - // No lookup performed for literal ipv6 addresses - return InetAddress.getByName(address).getAddress(); - } catch (UnknownHostException e) { - throw new IllegalArgumentException("Invalid address supplied", e); - } - } - } } |