methods/in_osx.rb
# Check PF is configure on OS X 10.10 and later
Check PF is configure on OS X 10.10 and later
Check PF is configure on OS X 10 . 10 and later
def check_osx_pfctl(options,gw_if_name,if_name)
  output = check_osx_ip_forwarding(options,gw_if_name)
  if not output.to_s.match(/#{gw_if_name}/) or not output.to_s.match(/#{if_name}/) or output.to_s.match(/killswitch/) or options['force'] == true
    pf_file = options['workdir']+"/pfctl_config"
    if File.exist?(pf_file)
      File.delete(pf_file)
    end
    output = File.open(pf_file,"w")
    if options['verbose'] == true
      handle_output(options,"Information:\tEnabling forwarding between #{gw_if_name} and #{if_name}")
    end
    output.write("nat on #{gw_if_name} from #{if_name}:network to any -> (#{gw_if_name})\n")
    output.write("pass inet proto icmp all\n")
    output.write("pass in on #{if_name} proto udp from any to any port domain keep state\n")
    output.write("pass in on #{if_name} proto tcp from any to any port domain keep state\n")
    output.write("pass quick on #{gw_if_name} proto udp from any to any port domain keep state\n")
    output.write("pass quick on #{gw_if_name} proto tcp from any to any port domain keep state\n")
    output.close
    message = "Enabling:\tPacket filtering"
    command = "sudo sh -c \"pfctl -e\""
    execute_command(options,message,command)
    message = "Loading:\yFilters from "+pf_file
    command = "sudo sh -c \"pfctl -F all -f #{pf_file}\""
    execute_command(options,message,command)
  end
  return
end
def check_osx_pfctl ( options , gw_if_name , if_name ) output = check_osx_ip_forwarding ( options , gw_if_name ) if not output . to_s . match ( / #{ gw_if_name } / ) or not output . to_s . match ( / #{ if_name } / ) or output . to_s . match ( / killswitch / ) or options [ 'force' ] == true pf_file = options [ 'workdir' ] + "/pfctl_config" if File . exist? ( pf_file ) File . delete ( pf_file ) end output = File . open ( pf_file , "w" ) if options [ 'verbose' ] == true handle_output ( options , "Information:\tEnabling forwarding between #{gw_if_name} and #{if_name}" ) end output . write ( "nat on #{gw_if_name} from #{if_name}:network to any -> (#{gw_if_name})\n" ) output . write ( "pass inet proto icmp all\n" ) output . write ( "pass in on #{if_name} proto udp from any to any port domain keep state\n" ) output . write ( "pass in on #{if_name} proto tcp from any to any port domain keep state\n" ) output . write ( "pass quick on #{gw_if_name} proto udp from any to any port domain keep state\n" ) output . write ( "pass quick on #{gw_if_name} proto tcp from any to any port domain keep state\n" ) output . close message = "Enabling:\tPacket filtering" command = "sudo sh -c \"pfctl -e\"" execute_command ( options , message , command ) message = "Loading:\yFilters from " + pf_file command = "sudo sh -c \"pfctl -F all -f #{pf_file}\"" execute_command ( options , message , command ) end return end
Check PF is configure on OS X 10.10 and later
Check PF is configure on OS X 10 . 10 and later
options
<not_specific>
gw_if_name
<not_specific>
if_name
<not_specific>