Skip to content

Commit

Permalink
Further cleanup in Lan#readIPv6
Browse files Browse the repository at this point in the history
  • Loading branch information
mchf committed Sep 14, 2016
1 parent 11e2481 commit 9f8e78d
Showing 1 changed file with 15 additions and 25 deletions.
40 changes: 15 additions & 25 deletions src/modules/Lan.rb
Expand Up @@ -220,36 +220,26 @@ def isAnyInterfaceDown
def readIPv6
@ipv6 = true

methods = {
"builtin" => {
"filelist" => ["sysctl.conf"],
"filepath" => "/etc",
"regexp" => /^[[:space:]]*(net.ipv6.conf.all.disable_ipv6)[[:space:]]*=[[:space:]]*1/
}
}

methods.each do |_, method|
filelist = method["filelist"] || []
filepath = method["filepath"] || ""
regexp = method["regexp"] || ""

filelist.each do |file|
filename = "#{filepath}/#{file}"
next if !FileUtils.Exists(filename)
sysctl_path = "/etc/sysctl.conf"
ipv6_regexp = /^[[:space:]]*(net.ipv6.conf.all.disable_ipv6)[[:space:]]*=[[:space:]]*1/

begin
lines = (SCR.Read(path(".target.string"), filename) || []).split("\n")
rescue ArgumentError => e
log.error("readIPv6: an error when parsing #{filename}")
log.error(e.message)
# sysctl.conf is kind of "mandatory" config file
if !FileUtils.Exists(sysctl_path)
log.error("readIPv6: #{sysctl_path} is missing")
return false
end

return false
end
begin
lines = (SCR.Read(path(".target.string"), sysctl_path) || []).split("\n")
rescue ArgumentError => e
log.error("readIPv6: an error when parsing #{sysctl_path}")
log.error(e.message)

@ipv6 = false if lines.any? { |row| row =~ regexp }
end
return false
end

@ipv6 = false if lines.any? { |row| row =~ ipv6_regexp }

log.info("readIPv6: IPv6 is #{@ipv6 ? "enabled" : "disabled"}")

true
Expand Down

0 comments on commit 9f8e78d

Please sign in to comment.