- java.lang.Object
-
- io.netty5.handler.ipfilter.AbstractRemoteAddressFilter<InetSocketAddress>
-
- io.netty5.handler.ipfilter.IpSubnetFilter
-
- All Implemented Interfaces:
ChannelHandler
public class IpSubnetFilter extends AbstractRemoteAddressFilter<InetSocketAddress>
This class allows one to filter new
Channels based on theIpSubnetFilters passed to its constructor. If no rules are provided, all connections will be accepted sinceacceptIfNotFoundistrueby default.If you would like to explicitly take action on rejected
Channels, you should overrideAbstractRemoteAddressFilter.channelRejected(ChannelHandlerContext, SocketAddress).Few Points to keep in mind:
- Since
IpSubnetFilteruses Binary search algorithm, it's a good idea to insert IP addresses in incremental order. - Remove any over-lapping CIDR.
-
-
Constructor Summary
Constructors Constructor Description IpSubnetFilter(boolean acceptIfNotFound, IpSubnetFilterRule... rules)Create newIpSubnetFilterInstance with specifiedIpSubnetFilterRuleas array and specify if we'll accept a connection if we don't find it in the rule(s).IpSubnetFilter(boolean acceptIfNotFound, List<IpSubnetFilterRule> rules)Create newIpSubnetFilterInstance with specifiedIpSubnetFilterRuleasListand specify if we'll accept a connection if we don't find it in the rule(s).IpSubnetFilter(IpSubnetFilterRule... rules)Create newIpSubnetFilterInstance with specifiedIpSubnetFilterRuleas array.IpSubnetFilter(List<IpSubnetFilterRule> rules)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected booleanaccept(ChannelHandlerContext ctx, InetSocketAddress remoteAddress)This method is called immediately after aChannelgets registered.booleanisSharable()Returnstrueif this handler is sharable and thus can be added to more than oneChannelPipeline.-
Methods inherited from class io.netty5.handler.ipfilter.AbstractRemoteAddressFilter
channelAccepted, channelActive, channelRegistered, channelRejected
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface io.netty5.channel.ChannelHandler
bind, channelExceptionCaught, channelInactive, channelInboundEvent, channelRead, channelReadComplete, channelShutdown, channelUnregistered, channelWritabilityChanged, close, connect, deregister, disconnect, flush, handlerAdded, handlerRemoved, pendingOutboundBytes, read, register, sendOutboundEvent, shutdown, write
-
-
-
-
Constructor Detail
-
IpSubnetFilter
public IpSubnetFilter(IpSubnetFilterRule... rules)
Create new
IpSubnetFilterInstance with specifiedIpSubnetFilterRuleas array.acceptIfNotFoundis set totrue.- Parameters:
rules-IpSubnetFilterRuleas an array
-
IpSubnetFilter
public IpSubnetFilter(boolean acceptIfNotFound, IpSubnetFilterRule... rules)Create new
IpSubnetFilterInstance with specifiedIpSubnetFilterRuleas array and specify if we'll accept a connection if we don't find it in the rule(s).- Parameters:
acceptIfNotFound-trueif we'll accept connection if not found in rule(s).rules-IpSubnetFilterRuleas an array
-
IpSubnetFilter
public IpSubnetFilter(List<IpSubnetFilterRule> rules)
Create new
IpSubnetFilterInstance with specifiedIpSubnetFilterRuleasList.acceptIfNotFoundis set totrue.- Parameters:
rules-IpSubnetFilterRuleas aList
-
IpSubnetFilter
public IpSubnetFilter(boolean acceptIfNotFound, List<IpSubnetFilterRule> rules)Create new
IpSubnetFilterInstance with specifiedIpSubnetFilterRuleasListand specify if we'll accept a connection if we don't find it in the rule(s).- Parameters:
acceptIfNotFound-trueif we'll accept connection if not found in rule(s).rules-IpSubnetFilterRuleas aList
-
-
Method Detail
-
isSharable
public boolean isSharable()
Description copied from interface:ChannelHandlerReturnstrueif this handler is sharable and thus can be added to more than oneChannelPipeline. By default, this method returnsfalse. If this method returnsfalse, you have to create a new handler instance every time you add it to a pipeline because it has unshared state such as member variables.
-
accept
protected boolean accept(ChannelHandlerContext ctx, InetSocketAddress remoteAddress)
Description copied from class:AbstractRemoteAddressFilterThis method is called immediately after aChannelgets registered.- Specified by:
acceptin classAbstractRemoteAddressFilter<InetSocketAddress>- Returns:
- Return true if connections from this IP address and port should be accepted. False otherwise.
-
-