class PacketThief::Impl::PFDivert::PFDivertRule

Attributes

rule_number[RW]

Public Class Methods

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

Public Instance Methods

to_pf_command() click to toggle source
# File lib/packetthief/impl/pf_divert.rb, line 106
def to_pf_command
  args = []

  args << "pass" << "in"

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

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

    args << 'from'
    args << self.rulespec.fetch(:source_address, 'any').to_s
    args << 'port' << 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 << 'port' << self.rulespec[:dest_port].to_s if self.rulespec.has_key? :dest_port
  end

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


  args
end