Class: IP::Table
- Inherits:
-
Object
- Object
- IP::Table
- Defined in:
- lib/iptable/ip.rb
Instance Attribute Summary collapse
-
#chains ⇒ Object
readonly
Returns the value of attribute chains.
Instance Method Summary collapse
- #add_chain(options) ⇒ Object
-
#initialize(load_iptables = true) ⇒ Table
constructor
A new instance of Table.
- #load_chains ⇒ Object
- #match_chain(line) ⇒ Object
- #refresh ⇒ Object
Constructor Details
#initialize(load_iptables = true) ⇒ Table
Returns a new instance of Table.
8 9 10 11 |
# File 'lib/iptable/ip.rb', line 8 def initialize(load_iptables = true) @chains = {} load_chains if load_iptables end |
Instance Attribute Details
#chains ⇒ Object (readonly)
Returns the value of attribute chains.
6 7 8 |
# File 'lib/iptable/ip.rb', line 6 def chains @chains end |
Instance Method Details
#add_chain(options) ⇒ Object
27 28 29 30 31 |
# File 'lib/iptable/ip.rb', line 27 def add_chain() new_chain = Chain.new() new_chain.save @chains[[:name]] = new_chain end |
#load_chains ⇒ Object
18 19 20 21 22 23 24 25 |
# File 'lib/iptable/ip.rb', line 18 def load_chains IO.popen("/sbin/iptables -L -n -v -x") do |output| output.readlines.each do |line| next if match_chain(line) @current_chain.match_rule(line) if @current_chain end end end |
#match_chain(line) ⇒ Object
33 34 35 36 37 38 39 40 |
# File 'lib/iptable/ip.rb', line 33 def match_chain(line) if match = line.match(CHAIN_RE) name = match[1] @current_chain = @chains[name] = Chain.new(:name => name) return true end false end |
#refresh ⇒ Object
13 14 15 16 |
# File 'lib/iptable/ip.rb', line 13 def refresh @chains = {} load_chains end |