com.eurotech.framework.linux.net.iptables
Class NATRule

java.lang.Object
  extended by com.eurotech.framework.linux.net.iptables.NATRule

public class NATRule
extends 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) -> "sourceInterface" | "destinationInterface" PARAM (optional) -> "masquerade" VALUE -> (value of the specified parameter) EXAMPLE: NATRule0_sourceInterface=eth0 NATRule0_destinationInterface=wlan0 NATRule0_masquerade=true


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

Constructor Detail

NATRule

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

Parameters:
sourceInterface - interface name of source network (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 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} -j MASQUERADE;

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

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

Overrides:
toString in class Object
Returns:
A String representation of the NATRule.

setSourceInterface

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

Parameters:
sourceInterface - A String representing the sourceInterface.

setDestinationInterface

public void setDestinationInterface(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.

getSourceInterface

public String getSourceInterface()
Getter for the sourceInterface.

Returns:
sourceInterface A String representing the sourceInterface.

getDestinationInterface

public String getDestinationInterface()
Getter for the destinationInterface.

Returns:
destinationInterface A String representing the destinationInterface.

isMasquerade

public boolean isMasquerade()
Getter for the masquerade.

Returns:
masquerade A boolean representing the masquerade.

equals

public boolean equals(Object o)
Overrides:
equals in class Object

hashCode

public int hashCode()
Overrides:
hashCode in class Object


Copyright © 2013. All Rights Reserved.