Package io.netty.handler.ipfilter
Class IpSubnetFilterRule
java.lang.Object
io.netty.handler.ipfilter.IpSubnetFilterRule
- All Implemented Interfaces:
IpFilterRule
,Comparable<IpSubnetFilterRule>
public final class IpSubnetFilterRule
extends Object
implements IpFilterRule, Comparable<IpSubnetFilterRule>
Use this class to create rules for
RuleBasedIpFilter
that group IP addresses into subnets.
Supports both, IPv4 and IPv6.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescription(package private) static final class
(package private) static final class
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionIpSubnetFilterRule
(String ipAddress, int cidrPrefix, IpFilterRuleType ruleType) Create a newIpSubnetFilterRule
instanceIpSubnetFilterRule
(String ipAddressWithCidr, IpFilterRuleType ruleType) Create a newIpSubnetFilterRule
instanceIpSubnetFilterRule
(InetAddress ipAddress, int cidrPrefix, IpFilterRuleType ruleType) Create a newIpSubnetFilterRule
instance -
Method Summary
Modifier and TypeMethodDescriptionprivate static int
compareInt
(int x, int y) Equivalent toInteger.compare(int, int)
int
compareTo
(IpSubnetFilterRule ipSubnetFilterRule) (package private) int
compareTo
(InetSocketAddress inetSocketAddress) It'll compare IP address withIpSubnetFilterRule.Ip4SubnetFilterRule.networkAddress
orIpSubnetFilterRule.Ip6SubnetFilterRule.networkAddress
.(package private) IpFilterRule
(package private) String
Get IP Address of this ruleboolean
matches
(InetSocketAddress remoteAddress) ruleType()
private static IpFilterRule
selectFilterRule
(InetAddress ipAddress, int cidrPrefix, IpFilterRuleType ruleType)
-
Field Details
-
filterRule
-
ipAddress
-
-
Constructor Details
-
IpSubnetFilterRule
Create a newIpSubnetFilterRule
instance- Parameters:
ipAddressWithCidr
- IP Address with CIDR notation, e.g. (192.168.0.0/16) or (2001:db8::/32)ruleType
-IpFilterRuleType
to use
-
IpSubnetFilterRule
Create a newIpSubnetFilterRule
instance- Parameters:
ipAddress
- IP Address asString
cidrPrefix
- CIDR PrefixruleType
-IpFilterRuleType
to use
-
IpSubnetFilterRule
Create a newIpSubnetFilterRule
instance- Parameters:
ipAddress
- IP Address asInetAddress
cidrPrefix
- CIDR PrefixruleType
-IpFilterRuleType
to use
-
-
Method Details
-
selectFilterRule
private static IpFilterRule selectFilterRule(InetAddress ipAddress, int cidrPrefix, IpFilterRuleType ruleType) -
matches
- Specified by:
matches
in interfaceIpFilterRule
- Returns:
- This method should return true if remoteAddress is valid according to your criteria. False otherwise.
-
ruleType
- Specified by:
ruleType
in interfaceIpFilterRule
- Returns:
- This method should return
IpFilterRuleType.ACCEPT
if allIpFilterRule.matches(InetSocketAddress)
for whichIpFilterRule.matches(InetSocketAddress)
returns true should the accepted. If you want to exclude all of those IP addresses thenIpFilterRuleType.REJECT
should be returned.
-
getIpAddress
String getIpAddress()Get IP Address of this rule -
getFilterRule
IpFilterRule getFilterRule() -
compareTo
- Specified by:
compareTo
in interfaceComparable<IpSubnetFilterRule>
-
compareTo
It'll compare IP address withIpSubnetFilterRule.Ip4SubnetFilterRule.networkAddress
orIpSubnetFilterRule.Ip6SubnetFilterRule.networkAddress
.- Parameters:
inetSocketAddress
-InetSocketAddress
to match- Returns:
- 0 if IP Address match else difference index.
-
compareInt
private static int compareInt(int x, int y) Equivalent toInteger.compare(int, int)
-