View Javadoc

1   /*
2    * Copyright 2012 The Netty Project
3    *
4    * The Netty Project licenses this file to you under the Apache License,
5    * version 2.0 (the "License"); you may not use this file except in compliance
6    * with the License. You may obtain a copy of the License at:
7    *
8    *   http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12   * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13   * License for the specific language governing permissions and limitations
14   * under the License.
15   */
16  package org.jboss.netty.handler.ipfilter;
17  
18  import java.net.InetAddress;
19  import java.net.UnknownHostException;
20  
21  /**
22   * Ip V4 and Ip V6 filter rule.<br>
23   * <br>
24   * Note that mix of IPV4 and IPV6 is allowed but it is not recommended. So it is preferable to not
25   * mix IPV4 addresses with IPV6 rules, even if it should work.
26   */
27  public class IpSubnetFilterRule extends IpSubnet implements IpFilterRule {
28      /** Is this IpV4Subnet an ALLOW or DENY rule */
29      private boolean isAllowRule = true;
30  
31      /**
32       * Constructor for a ALLOW or DENY ALL
33       *
34       * @param allow True for ALLOW, False for DENY
35       */
36      public IpSubnetFilterRule(boolean allow) {
37          isAllowRule = allow;
38      }
39  
40      /** @param allow True for ALLOW, False for DENY */
41      public IpSubnetFilterRule(boolean allow, InetAddress inetAddress, int cidrNetMask) throws UnknownHostException {
42          super(inetAddress, cidrNetMask);
43          isAllowRule = allow;
44      }
45  
46      /** @param allow True for ALLOW, False for DENY */
47      public IpSubnetFilterRule(boolean allow, InetAddress inetAddress, String netMask) throws UnknownHostException {
48          super(inetAddress, netMask);
49          isAllowRule = allow;
50      }
51  
52      /** @param allow True for ALLOW, False for DENY */
53      public IpSubnetFilterRule(boolean allow, String netAddress) throws UnknownHostException {
54          super(netAddress);
55          isAllowRule = allow;
56      }
57  
58      public boolean isAllowRule() {
59          return isAllowRule;
60      }
61  
62      public boolean isDenyRule() {
63          return !isAllowRule;
64      }
65  
66  }