Commit e8772536 authored by anonym's avatar anonym
Browse files

Convert `iptables_parse()` instance.

parent c2d0b3ea
......@@ -57,7 +57,7 @@ end
def iptables_chains_parse(iptables, table = "filter", &block)
assert(block_given?)
cmd = "#{iptables}-save -t #{table} | iptables-xml"
cmd = "#{iptables}-save -c -t #{table} | iptables-xml"
xml_str = $vm.execute_successfully(cmd).stdout
rexml = REXML::Document.new(xml_str)
rexml.get_elements('iptables-rules/table/chain').each do |element|
......
......@@ -180,11 +180,12 @@ end
Then /^the clearnet user has (|not )sent packets out to the Internet$/ do |sent|
pkts = 0
uid = $vm.execute_successfully("id -u clearnet").stdout.chomp.to_i
iptables_output = $vm.execute_successfully("iptables -vnL").stdout.chomp
output_chain = iptables_parse(iptables_output)["OUTPUT"]
output_chain["rules"].each do |rule|
if /owner UID match \b#{uid}\b/.match(rule["extra"])
pkts += rule["pkts"]
ip4tables_chains do |name, _, rules|
next unless name == "OUTPUT"
rules.each do |rule|
if rule.elements["conditions/owner/uid-owner[text()=#{uid}]"]
pkts += rule.attribute('packet-count').to_s.to_i
end
end
end
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment