Home / Class/ IpSubnetFilterRule Class — netty Architecture

IpSubnetFilterRule Class — netty Architecture

Architecture documentation for the IpSubnetFilterRule class in IpSubnetFilterRule.java from the netty codebase.

Entity Profile

Dependency Diagram

graph TD
  f3ff08cb_4fe1_1314_ac18_a2892f03b352["IpSubnetFilterRule"]
  1cb34468_689d_d5ec_e45e_875dc8626c30["IpSubnetFilterRule.java"]
  f3ff08cb_4fe1_1314_ac18_a2892f03b352 -->|defined in| 1cb34468_689d_d5ec_e45e_875dc8626c30
  cfd105c1_5e22_3655_bdaa_174dc8af73c3["IpSubnetFilterRule()"]
  f3ff08cb_4fe1_1314_ac18_a2892f03b352 -->|method| cfd105c1_5e22_3655_bdaa_174dc8af73c3
  021189c4_31cf_f5ee_f75f_612646c6334d["IpFilterRule()"]
  f3ff08cb_4fe1_1314_ac18_a2892f03b352 -->|method| 021189c4_31cf_f5ee_f75f_612646c6334d
  ec366950_3e90_b539_9c00_ab6de6f6b6e4["matches()"]
  f3ff08cb_4fe1_1314_ac18_a2892f03b352 -->|method| ec366950_3e90_b539_9c00_ab6de6f6b6e4
  fc756036_d09f_c555_46ac_e6354e01cd03["IpFilterRuleType()"]
  f3ff08cb_4fe1_1314_ac18_a2892f03b352 -->|method| fc756036_d09f_c555_46ac_e6354e01cd03
  28d772b0_687e_e29e_f448_439ad456be43["String()"]
  f3ff08cb_4fe1_1314_ac18_a2892f03b352 -->|method| 28d772b0_687e_e29e_f448_439ad456be43
  504651e3_45ca_f2dc_e951_3be528e05eca["compareTo()"]
  f3ff08cb_4fe1_1314_ac18_a2892f03b352 -->|method| 504651e3_45ca_f2dc_e951_3be528e05eca
  da7578a7_2316_10a2_5138_1894640b38b8["compareInt()"]
  f3ff08cb_4fe1_1314_ac18_a2892f03b352 -->|method| da7578a7_2316_10a2_5138_1894640b38b8

Relationship Graph

Source Code

handler/src/main/java/io/netty/handler/ipfilter/IpSubnetFilterRule.java lines 33–255

public final class IpSubnetFilterRule implements IpFilterRule, Comparable<IpSubnetFilterRule> {

    private final IpFilterRule filterRule;
    private final String ipAddress;

    /**
     * Create a new {@link IpSubnetFilterRule} instance
     *
     * @param ipAddressWithCidr IP Address with CIDR notation, e.g. (192.168.0.0/16) or (2001:db8::/32)
     * @param ruleType {@link IpFilterRuleType} to use
     */
    public IpSubnetFilterRule(String ipAddressWithCidr, IpFilterRuleType ruleType) {
        try {
            String[] ipAndCidr = ipAddressWithCidr.split("/");
            if (ipAndCidr.length != 2) {
                throw new IllegalArgumentException("ipAddressWithCidr: " + ipAddressWithCidr +
                        " (expected: \"<ip-address>/<mask-size>\")");
            }

            ipAddress = ipAndCidr[0];
            int cidrPrefix = Integer.parseInt(ipAndCidr[1]);
            filterRule = selectFilterRule(SocketUtils.addressByName(ipAddress), cidrPrefix, ruleType);
        } catch (UnknownHostException e) {
            throw new IllegalArgumentException("ipAddressWithCidr", e);
        }
    }

    /**
     * Create a new {@link IpSubnetFilterRule} instance
     *
     * @param ipAddress IP Address as {@link String}
     * @param cidrPrefix CIDR Prefix
     * @param ruleType {@link IpFilterRuleType} to use
     */
    public IpSubnetFilterRule(String ipAddress, int cidrPrefix, IpFilterRuleType ruleType) {
        try {
            this.ipAddress = ipAddress;
            filterRule = selectFilterRule(SocketUtils.addressByName(ipAddress), cidrPrefix, ruleType);
        } catch (UnknownHostException e) {
            throw new IllegalArgumentException("ipAddress", e);
        }
    }

    /**
     * Create a new {@link IpSubnetFilterRule} instance
     *
     * @param ipAddress IP Address as {@link InetAddress}
     * @param cidrPrefix CIDR Prefix
     * @param ruleType {@link IpFilterRuleType} to use
     */
    public IpSubnetFilterRule(InetAddress ipAddress, int cidrPrefix, IpFilterRuleType ruleType) {
        this.ipAddress = ipAddress.getHostAddress();
        filterRule = selectFilterRule(ipAddress, cidrPrefix, ruleType);
    }

    private static IpFilterRule selectFilterRule(InetAddress ipAddress, int cidrPrefix, IpFilterRuleType ruleType) {
        ObjectUtil.checkNotNull(ipAddress, "ipAddress");
        ObjectUtil.checkNotNull(ruleType, "ruleType");

        if (ipAddress instanceof Inet4Address) {
            return new Ip4SubnetFilterRule((Inet4Address) ipAddress, cidrPrefix, ruleType);
        } else if (ipAddress instanceof Inet6Address) {
            return new Ip6SubnetFilterRule((Inet6Address) ipAddress, cidrPrefix, ruleType);
        } else {
            throw new IllegalArgumentException("Only IPv4 and IPv6 addresses are supported");
        }
    }

    @Override
    public boolean matches(InetSocketAddress remoteAddress) {
        return filterRule.matches(remoteAddress);
    }

    @Override
    public IpFilterRuleType ruleType() {
        return filterRule.ruleType();
    }

    /**
     * Get IP Address of this rule
     */

Frequently Asked Questions

What is the IpSubnetFilterRule class?
IpSubnetFilterRule is a class in the netty codebase, defined in handler/src/main/java/io/netty/handler/ipfilter/IpSubnetFilterRule.java.
Where is IpSubnetFilterRule defined?
IpSubnetFilterRule is defined in handler/src/main/java/io/netty/handler/ipfilter/IpSubnetFilterRule.java at line 33.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free