Documentation ¶
Overview ¶
IPTsave is a library that provides IPtables type that can read iptables-save output and create a tokenized representation of it. Also it can render current tree into output suiteable for iptables-restore.
Provides a Lexer struct that extracts tokens from iptables-save output.
Provides a definition of Item for the Lexer.
Index ¶
- Variables
- type ActionType
- type IPchain
- func (ic *IPchain) AppendRule(rule *IPrule)
- func (ic *IPchain) DeleteRule(rule *IPrule)
- func (ic *IPchain) InsertRule(index int, rule *IPrule)
- func (ic IPchain) IsBuiltin() bool
- func (ic IPchain) RenderFooter() string
- func (ic IPchain) RenderHeader() string
- func (ic IPchain) RuleInChain(rule *IPrule) bool
- func (ic IPchain) String() string
- type IPrule
- type IPtable
- type IPtables
- type IPtablesAction
- type IPtablesComment
- type Item
- type ItemType
- type Lexer
- type Match
- type RenderState
Constants ¶
This section is empty.
Variables ¶
var BuiltinChains = []string{"INPUT", "OUTPUT", "FORWARD", "PREROUTING", "POSTROUTING"}
Functions ¶
This section is empty.
Types ¶
type IPchain ¶
type IPchain struct { Name string Policy string Counters string Rules []*IPrule RenderState RenderState }
IPchain represents a chain in iptables.
func MergeTables ¶
MergeTables merges source IPtable into destination IPtable, returns a list of chains with only rules from source table that were propagated into destination table.
func (*IPchain) AppendRule ¶
AppendRule appends new rule to the chain.
func (*IPchain) DeleteRule ¶
DeleteRule appends new rule to the chain and sets rule render state to Delete.
func (*IPchain) InsertRule ¶
InsertRule inserts new rule into the chain at given index. If index is larger then size of rules slice, this method will append the rule.
func (IPchain) RenderFooter ¶
RenderFooter returns string representation of the rules in the chain e.g. -A MYCHAIN <match> -j <action> -D MYCHAIN <othermatch> -j <otheraction)
func (IPchain) RenderHeader ¶
RenderHeader returns string representation of chains header e.g. :MYCHAIN ACCEPT [0:0]
func (IPchain) RuleInChain ¶
RuleInChain tests if the chain contains given rule.
type IPrule ¶
type IPrule struct { RenderState RenderState // From iptables man page. // rule-specification = [matches...] [target] // match = -m matchname [per-match-options] Match []*Match Action IPtablesAction }
IPrule represents a rule in iptables.
func DiffRules ¶
DiffRules compares 2 lists of iptables rules and returns 3 new lists, 1. return argument, rules that only found in first list 2. return argument, rules that only found in second list 3. return argumant, rules that found in bouth input lists
func MergeChains ¶
MergeChains merges source IPchain into destination IPchain, returns a list of rules that were added.
func MergeUserChains ¶
MergeUserChains merges rules from the source chain into the destination chain produces list of rules that combines rules from both chains with order preserved as much as possible.
type IPtable ¶
IPtable represents table in iptables.
func (*IPtable) ChainByName ¶
ChainByName looks for IPchain with corresponding name and returns a pointer to it.
func (IPtable) RenderFooter ¶
Renders footer of iptables table.
func (IPtable) RenderHeader ¶
Renders header of iptables table.
type IPtables ¶
type IPtables struct { Tables []*IPtable // contains filtered or unexported fields }
IPtables represents iptables configuration.
func (*IPtables) Render ¶
Render produces iptables-restore compatible representation of current structure.
func (*IPtables) TableByName ¶
TableByName returns pointer to the IPtable with corresponding name. e.g. iptables "filter" table.
type IPtablesAction ¶
type IPtablesAction struct { Type ActionType Body string }
IPtablesAction represents an action in iptables rule. e.g. "-j DROP"
"-j DNAT --to-destination 1.2.3.4"
func (IPtablesAction) String ¶
func (ia IPtablesAction) String() string
type IPtablesComment ¶
type IPtablesComment string
IPtablesComment represents a comment in iptables.
type Lexer ¶
type Lexer struct {
// contains filtered or unexported fields
}
Lexer extracts iptables lexical items from the input stream.
type Match ¶
Match is a string representation of a simple boolean expressio in iptables terms. e.g. "-o eth1"
"-m comment --comment HelloWorld" "! -p tcp --dport 80"
type RenderState ¶
type RenderState int
const ( RenderAppendRule RenderState = 0 RenderDeleteRule RenderState = 1 )
func (RenderState) String ¶
func (r RenderState) String() string