Implements lists of allowed and blocked IP addresses for use in TCP candidate allocation.
This commit is contained in:
parent
d937a29022
commit
707d258084
@ -151,6 +151,25 @@ public class StackProperties
|
|||||||
public static final String BLOCKED_INTERFACES
|
public static final String BLOCKED_INTERFACES
|
||||||
= "org.ice4j.ice.harvest.BLOCKED_INTERFACES";
|
= "org.ice4j.ice.harvest.BLOCKED_INTERFACES";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The name of the property which specifies a ";"-separated list of IP
|
||||||
|
* addresses that are allowed to be used for host candidate allocations.
|
||||||
|
*
|
||||||
|
* NOTE: this is currently only supported by
|
||||||
|
* {@link org.ice4j.ice.harvest.MultiplexingTcpHostHarvester}.
|
||||||
|
*/
|
||||||
|
public static final String ALLOWED_ADDRESSES
|
||||||
|
= "org.ice4j.ice.harvest.ALLOWED_ADDRESSES";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The name of the property which specifies a ";"-separated list of IP
|
||||||
|
* addresses that are not allowed to be used for host candidate allocations.
|
||||||
|
*
|
||||||
|
* NOTE: this is currently only supported by
|
||||||
|
* {@link org.ice4j.ice.harvest.MultiplexingTcpHostHarvester}.
|
||||||
|
*/
|
||||||
|
public static final String BLOCKED_ADDRESSES
|
||||||
|
= "org.ice4j.ice.harvest.BLOCKED_ADDRESSES";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the String value of the specified property (minus all
|
* Returns the String value of the specified property (minus all
|
||||||
|
|||||||
@ -172,7 +172,7 @@ public class MultiplexingTcpHostHarvester
|
|||||||
throws IOException
|
throws IOException
|
||||||
{
|
{
|
||||||
this.ssltcp = ssltcp;
|
this.ssltcp = ssltcp;
|
||||||
this.localAddresses.addAll(transportAddresses);
|
addLocalAddresses(transportAddresses);
|
||||||
init();
|
init();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -203,7 +203,7 @@ public class MultiplexingTcpHostHarvester
|
|||||||
throws IOException
|
throws IOException
|
||||||
{
|
{
|
||||||
this.ssltcp = ssltcp;
|
this.ssltcp = ssltcp;
|
||||||
initializeLocalAddresses(port, interfaces);
|
addLocalAddresses(getLocalAddresses(port, interfaces));
|
||||||
init();
|
init();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -232,20 +232,21 @@ public class MultiplexingTcpHostHarvester
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initializes {@link #localAddresses}.
|
* Returns a list of all addresses on the interfaces in <tt>interfaces</tt>
|
||||||
|
* which are found suitable for candidate allocations (are not loopback,
|
||||||
|
* are up, and are allowed by the configuration.
|
||||||
*
|
*
|
||||||
* @param port the port to use.
|
* @param port the port to use.
|
||||||
* @param interfaces the list of interfaces to use.
|
* @param interfaces the list of interfaces to use.
|
||||||
*/
|
*/
|
||||||
private void initializeLocalAddresses(
|
private List<TransportAddress> getLocalAddresses(
|
||||||
int port,
|
int port,
|
||||||
List<NetworkInterface> interfaces)
|
List<NetworkInterface> interfaces)
|
||||||
throws IOException
|
throws IOException
|
||||||
|
|
||||||
{
|
{
|
||||||
boolean useIPv6 = !StackProperties.getBoolean(
|
List<TransportAddress> addresses
|
||||||
StackProperties.DISABLE_IPv6,
|
= new LinkedList<TransportAddress>();
|
||||||
false);
|
|
||||||
|
|
||||||
for (NetworkInterface iface : interfaces)
|
for (NetworkInterface iface : interfaces)
|
||||||
{
|
{
|
||||||
@ -257,29 +258,124 @@ public class MultiplexingTcpHostHarvester
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
Enumeration<InetAddress> addresses = iface.getInetAddresses();
|
Enumeration<InetAddress> ifaceAddresses = iface.getInetAddresses();
|
||||||
|
|
||||||
while(addresses.hasMoreElements())
|
while(ifaceAddresses.hasMoreElements())
|
||||||
{
|
{
|
||||||
InetAddress addr = addresses.nextElement();
|
InetAddress addr = ifaceAddresses.nextElement();
|
||||||
|
|
||||||
if (addr.isLoopbackAddress())
|
TransportAddress transportAddress
|
||||||
|
= new TransportAddress(addr,
|
||||||
|
port,
|
||||||
|
Transport.TCP);
|
||||||
|
addresses.add(transportAddress);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return addresses;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds to {@link #localAddresses} those addresses from
|
||||||
|
* <tt>transportAddresses</tt> which are found suitable for candidate
|
||||||
|
* allocation.
|
||||||
|
*
|
||||||
|
* @param transportAddresses the list of addresses to add.
|
||||||
|
*/
|
||||||
|
private void addLocalAddresses(List<TransportAddress> transportAddresses)
|
||||||
|
throws IOException
|
||||||
|
{
|
||||||
|
boolean useIPv6 = !StackProperties.getBoolean(
|
||||||
|
StackProperties.DISABLE_IPv6,
|
||||||
|
false);
|
||||||
|
|
||||||
|
// White list from the configuration
|
||||||
|
String[] allowedAddressesStr
|
||||||
|
= StackProperties.getStringArray(StackProperties.ALLOWED_ADDRESSES,
|
||||||
|
";");
|
||||||
|
InetAddress[] allowedAddresses = null;
|
||||||
|
if (allowedAddressesStr != null)
|
||||||
|
{
|
||||||
|
allowedAddresses = new InetAddress[allowedAddressesStr.length];
|
||||||
|
for (int i = 0; i < allowedAddressesStr.length; i++)
|
||||||
|
{
|
||||||
|
allowedAddresses[i]
|
||||||
|
= InetAddress.getByName(allowedAddressesStr[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Black list from the configuration
|
||||||
|
String[] blockedAddressesStr
|
||||||
|
= StackProperties.getStringArray(StackProperties.BLOCKED_ADDRESSES,
|
||||||
|
";");
|
||||||
|
InetAddress[] blockedAddresses = null;
|
||||||
|
if (blockedAddressesStr != null)
|
||||||
|
{
|
||||||
|
blockedAddresses = new InetAddress[blockedAddressesStr.length];
|
||||||
|
for (int i = 0; i < blockedAddressesStr.length; i++)
|
||||||
|
{
|
||||||
|
blockedAddresses[i]
|
||||||
|
= InetAddress.getByName(blockedAddressesStr[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (TransportAddress transportAddress : transportAddresses)
|
||||||
|
{
|
||||||
|
InetAddress address = transportAddress.getAddress();
|
||||||
|
|
||||||
|
if (address.isLoopbackAddress())
|
||||||
{
|
{
|
||||||
//loopback again
|
//loopback again
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if((addr instanceof Inet4Address) || useIPv6)
|
if (!useIPv6 && (address instanceof Inet6Address))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (allowedAddresses != null)
|
||||||
{
|
{
|
||||||
TransportAddress transportAddress
|
boolean found = false;
|
||||||
= new TransportAddress(addr,
|
for (InetAddress allowedAddress : allowedAddresses)
|
||||||
port,
|
{
|
||||||
Transport.TCP);
|
if (allowedAddress.equals(address))
|
||||||
|
{
|
||||||
|
found = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!found)
|
||||||
|
{
|
||||||
|
logger.info("Not using " + address +" for TCP candidates, "
|
||||||
|
+ "because it is not in the allowed list.");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (blockedAddresses != null)
|
||||||
|
{
|
||||||
|
boolean found = false;
|
||||||
|
for (InetAddress blockedAddress : blockedAddresses)
|
||||||
|
{
|
||||||
|
if (blockedAddress.equals(address))
|
||||||
|
{
|
||||||
|
found = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (found)
|
||||||
|
{
|
||||||
|
logger.info("Not using " + address + " for TCP candidates, "
|
||||||
|
+ "because it is in the blocked list.");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Passed all checks
|
||||||
localAddresses.add(transportAddress);
|
localAddresses.add(transportAddress);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the <tt>Component</tt> instance, if any, for a given local
|
* Returns the <tt>Component</tt> instance, if any, for a given local
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user