Class: PacketThief::Impl::Netfilter::IPTablesRule

Inherits:
RedirectRule
  • Object
show all
Defined in:
lib/packetthief/impl/netfilter.rb

Overview

Adds IPTables specific details to a Redirectrule.

Instance Attribute Summary collapse

Attributes inherited from RedirectRule

#handler, #redirectspec, #rulespec

Instance Method Summary collapse

Methods inherited from RedirectRule

#redirect, #run, #where

Constructor Details

#initialize(handler, table, chain) ⇒ IPTablesRule

Returns a new instance of IPTablesRule.



62
63
64
65
66
# File 'lib/packetthief/impl/netfilter.rb', line 62

def initialize(handler, table, chain)
  super(handler)
  @table = table
  @chain = chain
end

Instance Attribute Details

#chainObject

Returns the value of attribute chain.



60
61
62
# File 'lib/packetthief/impl/netfilter.rb', line 60

def chain
  @chain
end

#tableObject

Returns the value of attribute table.



59
60
61
# File 'lib/packetthief/impl/netfilter.rb', line 59

def table
  @table
end

Instance Method Details

#to_netfilter_commandObject



68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/packetthief/impl/netfilter.rb', line 68

def to_netfilter_command
  args = []

  if self.rulespec
    args << '-p' << self.rulespec[:protocol].to_s if self.rulespec.has_key? :protocol
    args << '--destination-port' << self.rulespec[:dest_port].to_s if self.rulespec.has_key? :dest_port
    args << '--in-interface' << self.rulespec[:in_interface].to_s if self.rulespec.has_key? :in_interface
  end

  if self.redirectspec
    args << '-j' << 'REDIRECT'
    args << '--to-ports' << self.redirectspec[:to_ports].to_s if self.redirectspec.has_key? :to_ports
  end

  args
end