Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix code formatting.
  • Loading branch information
tjuchniewicz committed Jul 8, 2016
commit 918b687c17742b10531d2f33506e6e231498be55
Original file line number Diff line number Diff line change
Expand Up @@ -129,23 +129,22 @@ else if (result != null) {
}

boolean ignoreAddress(InetAddress address) {

if (this.properties.isUseOnlySiteLocalInterfaces() && !address.isSiteLocalAddress()) {
log.trace("Ignoring address: " + address.getHostAddress());
return true;
}

for (String regex : this.properties.getPreferredNetworks()) {
if (address.getHostAddress().matches(regex) || address.getHostAddress().startsWith(regex)) {
log.trace("Ignoring address: " + address.getHostAddress());
return true;
}
}

return false;
}

boolean ignoreInterface(String interfaceName) {

if (this.properties.isUseOnlySiteLocalInterfaces() && !address.isSiteLocalAddress()) {
log.trace("Ignoring address: " + address.getHostAddress());
return true;
}

for (String regex : this.properties.getPreferredNetworks()) {
Copy link
Member

@spencergibb spencergibb Aug 17, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm a bit confused here. Why is prefferedNetworks being ignored?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Look like a bug.

if (address.getHostAddress().matches(regex) || address.getHostAddress().startsWith(regex))

must be replaced by:

if (!address.getHostAddress().matches(regex) && !address.getHostAddress().startsWith(regex))

Now I use only useOnlySiteLocalInterfaces on production. prefferedNetworks is planned to be used in next months.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

if (address.getHostAddress().matches(regex) || address.getHostAddress().startsWith(regex)) {
log.trace("Ignoring address: " + address.getHostAddress());
return true;
}
}
return false;
}

boolean ignoreInterface(String interfaceName) {
for (String regex : this.properties.getIgnoredInterfaces()) {
if (interfaceName.matches(regex)) {
log.trace("Ignoring interface: " + interfaceName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public class InetUtilsProperties {
private boolean useOnlySiteLocalInterfaces = false;

/**
* List of Java regex expressions for network addresses that will be ignored.
*/
* List of Java regex expressions for network addresses that will be ignored.
*/
private List<String> preferredNetworks = new ArrayList<>();
}
Original file line number Diff line number Diff line change
Expand Up @@ -87,35 +87,35 @@ public void testDefaultIgnoreInterface() {
}

@Test
public void testSiteLocalAddresses() throws Exception {
InetUtilsProperties properties = new InetUtilsProperties();
properties.setUseOnlySiteLocalInterfaces(true);
try (InetUtils utils = new InetUtils(properties)) {
assertFalse(utils.ignoreAddress(InetAddress.getByName("192.168.0.1")));
assertTrue(utils.ignoreAddress(InetAddress.getByName("5.5.8.1")));
}
public void testSiteLocalAddresses() throws Exception {
InetUtilsProperties properties = new InetUtilsProperties();
properties.setUseOnlySiteLocalInterfaces(true);

try (InetUtils utils = new InetUtils(properties)) {
assertFalse(utils.ignoreAddress(InetAddress.getByName("192.168.0.1")));
assertTrue(utils.ignoreAddress(InetAddress.getByName("5.5.8.1")));
}
}

@Test
public void testPrefferedNetworksRegex() throws Exception {
InetUtilsProperties properties = new InetUtilsProperties();
properties.setPreferredNetworks(Arrays.asList("192.168.*"));
try (InetUtils utils = new InetUtils(properties)) {
assertTrue(utils.ignoreAddress(InetAddress.getByName("192.168.0.1")));
assertFalse(utils.ignoreAddress(InetAddress.getByName("5.5.8.1")));
}
}
public void testPrefferedNetworksRegex() throws Exception {
InetUtilsProperties properties = new InetUtilsProperties();
properties.setPreferredNetworks(Arrays.asList("192.168.*"));

try (InetUtils utils = new InetUtils(properties)) {
assertTrue(utils.ignoreAddress(InetAddress.getByName("192.168.0.1")));
assertFalse(utils.ignoreAddress(InetAddress.getByName("5.5.8.1")));
}
}

@Test
public void testPrefferedNetworksSimple() throws Exception {
InetUtilsProperties properties = new InetUtilsProperties();
properties.setPreferredNetworks(Arrays.asList("192"));
try (InetUtils utils = new InetUtils(properties)) {
assertTrue(utils.ignoreAddress(InetAddress.getByName("192.168.0.1")));
assertFalse(utils.ignoreAddress(InetAddress.getByName("5.5.8.1")));
}
InetUtilsProperties properties = new InetUtilsProperties();
properties.setPreferredNetworks(Arrays.asList("192"));
try (InetUtils utils = new InetUtils(properties)) {
assertTrue(utils.ignoreAddress(InetAddress.getByName("192.168.0.1")));
assertFalse(utils.ignoreAddress(InetAddress.getByName("5.5.8.1")));
}
}
}