Skip to content

Commit

Permalink
Remove broadcast address check.
Browse files Browse the repository at this point in the history
This was supposed to just help the user, in case they misconfigured something.
Broadcast is an ipv4 only thing, the only way you can really detect its a broadcast
address, is to look and see if an interface has that address as its broadcast address.

But we cannot trust that container interfaces won't have a crazy setup...

Closes elastic#13327
  • Loading branch information
rmuir committed Sep 3, 2015
1 parent 3e9daa1 commit 529ad7f
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 58 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@

import java.io.IOException;
import java.net.InetAddress;
import java.net.InterfaceAddress;
import java.net.NetworkInterface;
import java.net.UnknownHostException;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
Expand Down Expand Up @@ -120,14 +118,6 @@ public InetAddress[] resolveBindHostAddress(String bindHost) throws IOException
if (address.isMulticastAddress()) {
throw new IllegalArgumentException("bind address: {" + NetworkAddress.format(address) + "} is invalid: multicast address");
}
// check if its broadcast: flat out mistake
for (NetworkInterface nic : NetworkUtils.getInterfaces()) {
for (InterfaceAddress intf : nic.getInterfaceAddresses()) {
if (address.equals(intf.getBroadcast())) {
throw new IllegalArgumentException("bind address: {" + NetworkAddress.format(address) + "} is invalid: broadcast address");
}
}
}
}
}
return addresses;
Expand Down Expand Up @@ -161,14 +151,6 @@ public InetAddress resolvePublishHostAddress(String publishHost) throws IOExcept
if (address.isMulticastAddress()) {
throw new IllegalArgumentException("publish address: {" + NetworkAddress.format(address) + "} is invalid: multicast address");
}
// check if its broadcast: flat out mistake
for (NetworkInterface nic : NetworkUtils.getInterfaces()) {
for (InterfaceAddress intf : nic.getInterfaceAddresses()) {
if (address.equals(intf.getBroadcast())) {
throw new IllegalArgumentException("publish address: {" + NetworkAddress.format(address) + "} is invalid: broadcast address");
}
}
}
// wildcard address, probably set by network.host
if (address.isAnyLocalAddress()) {
InetAddress old = address;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,6 @@
import org.elasticsearch.test.ESTestCase;

import java.net.InetAddress;
import java.net.InterfaceAddress;
import java.net.NetworkInterface;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
* Tests for network service... try to keep them safe depending upon configuration
Expand Down Expand Up @@ -87,41 +82,6 @@ public void testPublishMulticastV6() throws Exception {
}
}

/**
* ensure exception if we bind/publish to broadcast address
*/
public void testBindPublishBroadcast() throws Exception {
NetworkService service = new NetworkService(Settings.EMPTY);
// collect any broadcast addresses on the system
List<InetAddress> addresses = new ArrayList<>();
for (NetworkInterface nic : Collections.list(NetworkInterface.getNetworkInterfaces())) {
for (InterfaceAddress intf : nic.getInterfaceAddresses()) {
InetAddress address = intf.getBroadcast();
if (address != null) {
addresses.add(address);
}
}
}
// can easily happen (ipv6-only, localhost-only, ...)
assumeTrue("test requires broadcast addresses configured", addresses.size() > 0);
// make sure we fail on each one
for (InetAddress address : addresses) {
try {
service.resolveBindHostAddress(NetworkAddress.formatAddress(address));
fail("should have hit exception for broadcast address: " + address);
} catch (IllegalArgumentException e) {
assertTrue(e.getMessage().contains("invalid: broadcast"));
}

try {
service.resolvePublishHostAddress(NetworkAddress.formatAddress(address));
fail("should have hit exception for broadcast address: " + address);
} catch (IllegalArgumentException e) {
assertTrue(e.getMessage().contains("invalid: broadcast"));
}
}
}

/**
* ensure specifying wildcard ipv4 address will bind to all interfaces
*/
Expand Down

0 comments on commit 529ad7f

Please sign in to comment.