com.esf.net.firewall.service
Class NATRule

java.lang.Object
  extended bycom.esf.net.firewall.service.NATRule

public class NATRule
extends java.lang.Object

Creates an iptables command for a NAT Rule. CONFIGURATION Configuration will be accepted in the form of key/value pairs. The key/value pairs are strictly defined here: CONFIG_ENTRY -> KEY + "=" + VALUE KEY -> TYPE + INDEX + "_" + PARAM TYPE -> "NATRule" INDEX -> "0" | "1" | "2" | ... | "N" PARAM (required) -> "natSourceNetwork" | "sourceInterface" | "destinationInterface" PARAM (optional) -> "masquerade" VALUE -> (value of the specified parameter) EXAMPLE: NATRule0_natSourceNetwork=192.168.1.1 NATRule0_sourceInterface=eth0 NATRule0_destinationInterface=wlan0 NATRule0_masquerade=true


Constructor Summary
NATRule()
          Constructor of NATRule object.
NATRule(java.lang.String natSourceNetwork, java.lang.String sourceInterface, java.lang.String destinationInterface, boolean masquerade)
          Constructor of NATRule object.
 
Method Summary
 java.lang.String getDestinationInterface()
          Getter for the destinationInterface.
 boolean getMasquerade()
          Getter for the masquerade.
 java.lang.String getNatSourceNetwork()
          Getter for the natSourceNetwork.
 java.lang.String getSourceInterface()
          Getter for the sourceInterface.
 boolean isComplete()
          Returns true if the NATRule parameters have all been set.
 void setDestinationInterface(java.lang.String destinationInterface)
          Setter for the destinationInterface.
 void setMasquerade(boolean masquerade)
          Setter for the masquerade.
 void setNatSourceNetwork(java.lang.String natSourceNetwork)
          Setter for the natSourceNetwork.
 void setSourceInterface(java.lang.String sourceInterface)
          Setter for the sourceInterface.
 java.lang.String toString()
          Converts the NATRule to a String.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

NATRule

public NATRule(java.lang.String natSourceNetwork,
               java.lang.String sourceInterface,
               java.lang.String destinationInterface,
               boolean masquerade)
Constructor of NATRule object.

Parameters:
natSourceNetwork - source network or ip address from which NAT is allowed (such as 192.168.1.0)
sourceInterface - interface name of sourceNetwork (such as eth0)
destinationInterface - interface name of destination network to be reached via NAT (such as ppp0)
masquerade - add masquerade entry

NATRule

public NATRule()
Constructor of NATRule object.

Method Detail

isComplete

public boolean isComplete()
Returns true if the NATRule parameters have all been set. Returns false otherwise.

Returns:
A boolean representing whether all parameters have been set.

toString

public java.lang.String toString()
Converts the NATRule to a String. Returns single iptables string based on the NATRule, which establishes the MASQUERADE and FORWARD rules:

iptables -t nat -A POSTROUTING -o {destinationInterface} -s {natSourceNetwork} -j MASQUERADE;

iptables -A FORWARD -i {sourceInterface} -o {destinationInterface} -j ACCEPT;

iptables -A FORWARD -i {destinationInterface} -o {sourceInterface} -j ACCEPT

Returns:
A String representation of the NATRule.

setNatSourceNetwork

public void setNatSourceNetwork(java.lang.String natSourceNetwork)
Setter for the natSourceNetwork.

Parameters:
natSourceNetwork - A String representing the natSourceNetwork.

setSourceInterface

public void setSourceInterface(java.lang.String sourceInterface)
Setter for the sourceInterface.

Parameters:
sourceInterface - A String representing the sourceInterface.

setDestinationInterface

public void setDestinationInterface(java.lang.String destinationInterface)
Setter for the destinationInterface.

Parameters:
destinationInterface - A String representing the destinationInterface.

setMasquerade

public void setMasquerade(boolean masquerade)
Setter for the masquerade.

Parameters:
masquerade - A boolean representing the masquerade.

getNatSourceNetwork

public java.lang.String getNatSourceNetwork()
Getter for the natSourceNetwork.

Returns:
natSourceNetwork A String representing the natSourceNetwork.

getSourceInterface

public java.lang.String getSourceInterface()
Getter for the sourceInterface.

Returns:
sourceInterface A String representing the sourceInterface.

getDestinationInterface

public java.lang.String getDestinationInterface()
Getter for the destinationInterface.

Returns:
destinationInterface A String representing the destinationInterface.

getMasquerade

public boolean getMasquerade()
Getter for the masquerade.

Returns:
masquerade A boolean representing the masquerade.


Copyright © 2009 Eurotech Inc. All rights reserved.