Home / Class/ Ip6SubnetFilterRule Class — netty Architecture

Ip6SubnetFilterRule Class — netty Architecture

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

Entity Profile

Dependency Diagram

graph TD
  a1c6509b_4e14_64de_a61c_a7f2fad1afd0["Ip6SubnetFilterRule"]
  1cb34468_689d_d5ec_e45e_875dc8626c30["IpSubnetFilterRule.java"]
  a1c6509b_4e14_64de_a61c_a7f2fad1afd0 -->|defined in| 1cb34468_689d_d5ec_e45e_875dc8626c30
  d87ce269_a09c_3dc3_d503_251ebc514d86["Ip6SubnetFilterRule()"]
  a1c6509b_4e14_64de_a61c_a7f2fad1afd0 -->|method| d87ce269_a09c_3dc3_d503_251ebc514d86
  53ff307f_4e59_bb83_2a45_0922d99d7721["matches()"]
  a1c6509b_4e14_64de_a61c_a7f2fad1afd0 -->|method| 53ff307f_4e59_bb83_2a45_0922d99d7721
  b98ae95d_cba7_a4b8_1336_d815aabb5dff["IpFilterRuleType()"]
  a1c6509b_4e14_64de_a61c_a7f2fad1afd0 -->|method| b98ae95d_cba7_a4b8_1336_d815aabb5dff
  0f2fb401_b634_c64b_f115_66f184c14243["BigInteger()"]
  a1c6509b_4e14_64de_a61c_a7f2fad1afd0 -->|method| 0f2fb401_b634_c64b_f115_66f184c14243

Relationship Graph

Source Code

handler/src/main/java/io/netty/handler/ipfilter/IpSubnetFilterRule.java lines 210–254

    static final class Ip6SubnetFilterRule implements IpFilterRule {

        private static final BigInteger MINUS_ONE = BigInteger.valueOf(-1);

        private final BigInteger networkAddress;
        private final BigInteger subnetMask;
        private final IpFilterRuleType ruleType;

        private Ip6SubnetFilterRule(Inet6Address ipAddress, int cidrPrefix, IpFilterRuleType ruleType) {
            if (cidrPrefix < 0 || cidrPrefix > 128) {
                throw new IllegalArgumentException(String.format("IPv6 requires the subnet prefix to be in range of "
                        + "[0,128]. The prefix was: %d", cidrPrefix));
            }

            subnetMask = prefixToSubnetMask(cidrPrefix);
            networkAddress = ipToInt(ipAddress).and(subnetMask);
            this.ruleType = ruleType;
        }

        @Override
        public boolean matches(InetSocketAddress remoteAddress) {
            final InetAddress inetAddress = remoteAddress.getAddress();
            if (inetAddress instanceof Inet6Address) {
                BigInteger ipAddress = ipToInt((Inet6Address) inetAddress);
                return ipAddress.and(subnetMask).equals(subnetMask) || ipAddress.and(subnetMask).equals(networkAddress);
            }
            return false;
        }

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

        private static BigInteger ipToInt(Inet6Address ipAddress) {
            byte[] octets = ipAddress.getAddress();
            assert octets.length == 16;

            return new BigInteger(octets);
        }

        private static BigInteger prefixToSubnetMask(int cidrPrefix) {
            return MINUS_ONE.shiftLeft(128 - cidrPrefix);
        }
    }

Frequently Asked Questions

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

Analyze Your Own Codebase

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

Try Supermodel Free