Commit 2ad597c6 authored by anonym's avatar anonym
Browse files

Adapt packet counting code to the new iptables parser.

parent 505e3064
......@@ -247,18 +247,11 @@ When /^I disable all networking in the Tails Greeter$/ do
end
Then /^network traffic is (not )?generated during the Tails session$/ do |not_generated|
pkts = 0
iptables_output = $vm.execute_successfully("iptables -vnL").stdout.chomp
['INPUT', 'OUTPUT', 'FORWARD', 'lan'].each do |chain|
iptables_parse(iptables_output)[chain]["rules"].each do |rule|
pkts += rule["pkts"]
end
end
pkts = ip4tables_packet_counter_sum
if not_generated
assert_equal(0, pkts)
else
assert_not_equal(0, pkts)
end
debug_log("#{pkts} packets found.", :color => :green)
debug_log("#{pkts} packets found")
end
......@@ -35,6 +35,18 @@ def ip6tables_rules(chain, table = "filter")
iptables_rules_parse("ip6tables", chain, table)
end
def ip4tables_packet_counter_sum(filters = {})
pkts = 0
ip4tables_chains do |name, _, rules|
next if filters[:tables] && not(filters[:tables].include?(name))
rules.each do |rule|
next if filters[:uid] && not(rule.elements["conditions/owner/uid-owner[text()=#{filters[:uid]}]"])
pkts += rule.attribute('packet-count').to_s.to_i
end
end
return pkts
end
def try_xml_element_text(element, xpath, default = nil)
node = element.elements[xpath]
(node.nil? or not(node.has_text?)) ? default : node.text
......
......@@ -178,17 +178,8 @@ But /^checking for updates is disabled in the Unsafe Browser's configuration$/ d
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
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
pkts = ip4tables_packet_counter_sum(:tables => ['OUTPUT'], :uid => uid)
case sent
when ''
assert(pkts > 0, "Packets have not gone out to the internet.")
......
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