class PacketThief::Impl::Ipfw::IpfwRule

Attributes

rule_number[RW]

Public Class Methods

new(handler, rule_number=nil) click to toggle source
# File lib/packetthief/impl/ipfw.rb, line 78
def initialize(handler, rule_number=nil)
  super(handler)
  @rule_number = rule_number
end

Public Instance Methods

to_ipfw_command() click to toggle source
# File lib/packetthief/impl/ipfw.rb, line 83
def to_ipfw_command
  args = []

  if self.redirectspec
    if self.redirectspec.has_key? :to_ports
      args << 'fwd'
      args << "127.0.0.1,#{self.redirectspec[:to_ports].to_s}"
    else
      raise "Rule lacks a valid redirect: #{self.inspect}"
    end
  end

  if self.rulespec
    args << self.rulespec.fetch(:protocol,'ip').to_s

    args << 'from'
    args << self.rulespec.fetch(:source_address, 'any').to_s
    args << self.rulespec[:source_port].to_s if self.rulespec.has_key? :source_port

    args << 'to'
    args << self.rulespec.fetch(:dest_address, 'any').to_s
    args << 'dst-port' << self.rulespec[:dest_port].to_s if self.rulespec.has_key? :dest_port

    args << 'recv' << self.rulespec[:in_interface].to_s if self.rulespec.has_key? :in_interface
  end

  args
end