Class IpSubnetFilter
- All Implemented Interfaces:
ChannelHandler, ChannelInboundHandler
This class allows one to filter new Channels based on the
IpSubnetFilters passed to its constructor. If no rules are provided, all connections
will be accepted since acceptIfNotFound is true by default.
If you would like to explicitly take action on rejected Channels, you should override
AbstractRemoteAddressFilter.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.
-
Nested Class Summary
Nested classes/interfaces inherited from interface ChannelHandler
ChannelHandler.SharableModifier and TypeInterfaceDescriptionstatic @interfaceIndicates that the same instance of the annotatedChannelHandlercan be added to one or moreChannelPipelines multiple times without a race condition. -
Constructor Summary
ConstructorsConstructorDescriptionIpSubnetFilter(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
Modifier and TypeMethodDescriptionprotected booleanaccept(ChannelHandlerContext ctx, InetSocketAddress remoteAddress) This method is called immediately after aChannelgets registered.Methods inherited from class AbstractRemoteAddressFilter
channelAccepted, channelActive, channelRegistered, channelRejectedModifier and TypeMethodDescriptionprotected voidchannelAccepted(ChannelHandlerContext ctx, InetSocketAddress remoteAddress) This method is called ifremoteAddressgets accepted byAbstractRemoteAddressFilter.accept(ChannelHandlerContext, SocketAddress).voidCallsChannelHandlerContext.fireChannelActive()to forward to the nextChannelInboundHandlerin theChannelPipeline.voidCallsChannelHandlerContext.fireChannelRegistered()to forward to the nextChannelInboundHandlerin theChannelPipeline.protected ChannelFuturechannelRejected(ChannelHandlerContext ctx, InetSocketAddress remoteAddress) This method is called ifremoteAddressgets rejected byAbstractRemoteAddressFilter.accept(ChannelHandlerContext, SocketAddress).Methods inherited from class ChannelInboundHandlerAdapter
channelInactive, channelRead, channelReadComplete, channelUnregistered, channelWritabilityChanged, exceptionCaught, userEventTriggeredModifier and TypeMethodDescriptionvoidCallsChannelHandlerContext.fireChannelInactive()to forward to the nextChannelInboundHandlerin theChannelPipeline.voidchannelRead(ChannelHandlerContext ctx, Object msg) CallsChannelHandlerContext.fireChannelRead(Object)to forward to the nextChannelInboundHandlerin theChannelPipeline.voidCallsChannelHandlerContext.fireChannelReadComplete()to forward to the nextChannelInboundHandlerin theChannelPipeline.voidCallsChannelHandlerContext.fireChannelUnregistered()to forward to the nextChannelInboundHandlerin theChannelPipeline.voidCallsChannelHandlerContext.fireChannelWritabilityChanged()to forward to the nextChannelInboundHandlerin theChannelPipeline.voidexceptionCaught(ChannelHandlerContext ctx, Throwable cause) CallsChannelHandlerContext.fireExceptionCaught(Throwable)to forward to the nextChannelHandlerin theChannelPipeline.voiduserEventTriggered(ChannelHandlerContext ctx, Object evt) CallsChannelHandlerContext.fireUserEventTriggered(Object)to forward to the nextChannelInboundHandlerin theChannelPipeline.Methods inherited from class ChannelHandlerAdapter
ensureNotSharable, handlerAdded, handlerRemoved, isSharableModifier and TypeMethodDescriptionprotected voidvoidDo nothing by default, sub-classes may override this method.voidDo nothing by default, sub-classes may override this method.booleanReturntrueif the implementation isChannelHandler.Sharableand so can be added to differentChannelPipelines.
-
Constructor Details
-
IpSubnetFilter
Create new
IpSubnetFilterInstance with specifiedIpSubnetFilterRuleas array.acceptIfNotFoundis set totrue.- Parameters:
rules-IpSubnetFilterRuleas an array
-
IpSubnetFilter
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
Create new
IpSubnetFilterInstance with specifiedIpSubnetFilterRuleasList.acceptIfNotFoundis set totrue.- Parameters:
rules-IpSubnetFilterRuleas aList
-
IpSubnetFilter
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 Details
-
accept
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.
-