module PacketThief::Impl::PFRdr::PFRdrRuleHandler

Attributes

active_rules[RW]

Public Instance Methods

revert() click to toggle source

Reverts all executed rules that this handler knows about.

# File lib/packetthief/impl/pf_rdr.rb, line 80
def revert
  return if @active_rules == nil or @active_rules.empty?

  args = %W{pfctl -q -a packetthief -F all}
  unless system(*args)
    raise "Command #{args.inspect} exited with error code #{$?.inspect}"
  end
  #        end

  @active_rules = []
end
run(rule) click to toggle source

Executes a rule and holds onto it for later removal.

# File lib/packetthief/impl/pf_rdr.rb, line 62
def run(rule)
  @active_rules ||= []

  @active_rules << rule
  rulestrs = @active_rules.map { |r| r.to_pf_command.join(" ") }

  rulestrs.each { |rule| logdebug rule }
  args = %W{pfctl -q -a packetthief -f -}
  IO.popen(args, "w+") do |pfctlio|
    rulestrs.each { |rule| pfctlio.puts rule }
  end
  unless $?.exitstatus == 0
    raise "Command #{args.inspect} exited with error code #{$?.inspect}"
  end

end