From c3524b9d3b8579f1aa79bf8c123299a94f4dcc18 Mon Sep 17 00:00:00 2001 From: Marek Gradzki Date: Mon, 20 Nov 2017 14:00:32 +0100 Subject: 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 --- .../common/translate/util/Ipv6Translator.java | 23 +--------------------- 1 file changed, 1 insertion(+), 22 deletions(-) (limited to 'vpp-common/vpp-translate-utils') 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); - } - } - } } -- cgit 1.2.3-korg