Package io.netty.handler.ipfilter
Class IpSubnetFilterRule
- java.lang.Object
-
- io.netty.handler.ipfilter.IpSubnetFilterRule
-
- All Implemented Interfaces:
IpFilterRule,java.lang.Comparable<IpSubnetFilterRule>
public final class IpSubnetFilterRule extends java.lang.Object implements IpFilterRule, java.lang.Comparable<IpSubnetFilterRule>
Use this class to create rules forRuleBasedIpFilterthat group IP addresses into subnets. Supports both, IPv4 and IPv6.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) static classIpSubnetFilterRule.Ip4SubnetFilterRule(package private) static classIpSubnetFilterRule.Ip6SubnetFilterRule
-
Field Summary
Fields Modifier and Type Field Description private IpFilterRulefilterRuleprivate java.lang.StringipAddress
-
Constructor Summary
Constructors Constructor Description IpSubnetFilterRule(java.lang.String ipAddress, int cidrPrefix, IpFilterRuleType ruleType)Create a newIpSubnetFilterRuleinstanceIpSubnetFilterRule(java.lang.String ipAddressWithCidr, IpFilterRuleType ruleType)Create a newIpSubnetFilterRuleinstanceIpSubnetFilterRule(java.net.InetAddress ipAddress, int cidrPrefix, IpFilterRuleType ruleType)Create a newIpSubnetFilterRuleinstance
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private static intcompareInt(int x, int y)Equivalent toInteger.compare(int, int)intcompareTo(IpSubnetFilterRule ipSubnetFilterRule)(package private) intcompareTo(java.net.InetSocketAddress inetSocketAddress)It'll compare IP address withIpSubnetFilterRule.Ip4SubnetFilterRule.networkAddressorIpSubnetFilterRule.Ip6SubnetFilterRule.networkAddress.(package private) IpFilterRulegetFilterRule()(package private) java.lang.StringgetIpAddress()Get IP Address of this rulebooleanmatches(java.net.InetSocketAddress remoteAddress)IpFilterRuleTyperuleType()private static IpFilterRuleselectFilterRule(java.net.InetAddress ipAddress, int cidrPrefix, IpFilterRuleType ruleType)
-
-
-
Field Detail
-
filterRule
private final IpFilterRule filterRule
-
ipAddress
private final java.lang.String ipAddress
-
-
Constructor Detail
-
IpSubnetFilterRule
public IpSubnetFilterRule(java.lang.String ipAddressWithCidr, IpFilterRuleType ruleType)Create a newIpSubnetFilterRuleinstance- Parameters:
ipAddressWithCidr- IP Address with CIDR notation, e.g. (192.168.0.0/16) or (2001:db8::/32)ruleType-IpFilterRuleTypeto use
-
IpSubnetFilterRule
public IpSubnetFilterRule(java.lang.String ipAddress, int cidrPrefix, IpFilterRuleType ruleType)Create a newIpSubnetFilterRuleinstance- Parameters:
ipAddress- IP Address asStringcidrPrefix- CIDR PrefixruleType-IpFilterRuleTypeto use
-
IpSubnetFilterRule
public IpSubnetFilterRule(java.net.InetAddress ipAddress, int cidrPrefix, IpFilterRuleType ruleType)Create a newIpSubnetFilterRuleinstance- Parameters:
ipAddress- IP Address asInetAddresscidrPrefix- CIDR PrefixruleType-IpFilterRuleTypeto use
-
-
Method Detail
-
selectFilterRule
private static IpFilterRule selectFilterRule(java.net.InetAddress ipAddress, int cidrPrefix, IpFilterRuleType ruleType)
-
matches
public boolean matches(java.net.InetSocketAddress remoteAddress)
- Specified by:
matchesin interfaceIpFilterRule- Returns:
- This method should return true if remoteAddress is valid according to your criteria. False otherwise.
-
ruleType
public IpFilterRuleType ruleType()
- Specified by:
ruleTypein interfaceIpFilterRule- Returns:
- This method should return
IpFilterRuleType.ACCEPTif allIpFilterRule.matches(InetSocketAddress)for whichIpFilterRule.matches(InetSocketAddress)returns true should the accepted. If you want to exclude all of those IP addresses thenIpFilterRuleType.REJECTshould be returned.
-
getIpAddress
java.lang.String getIpAddress()
Get IP Address of this rule
-
getFilterRule
IpFilterRule getFilterRule()
-
compareTo
public int compareTo(IpSubnetFilterRule ipSubnetFilterRule)
- Specified by:
compareToin interfacejava.lang.Comparable<IpSubnetFilterRule>
-
compareTo
int compareTo(java.net.InetSocketAddress inetSocketAddress)
It'll compare IP address withIpSubnetFilterRule.Ip4SubnetFilterRule.networkAddressorIpSubnetFilterRule.Ip6SubnetFilterRule.networkAddress.- Parameters:
inetSocketAddress-InetSocketAddressto match- Returns:
- 0 if IP Address match else difference index.
-
compareInt
private static int compareInt(int x, int y)Equivalent toInteger.compare(int, int)
-
-