Skip to content

Commit

Permalink
support IPv6 (fate #316261)
Browse files Browse the repository at this point in the history
  • Loading branch information
gabi2 committed Oct 10, 2013
1 parent 737e8e8 commit d964e29
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 20 deletions.
8 changes: 6 additions & 2 deletions src/include/iscsi-lio-server/widgets.rb
Original file line number Diff line number Diff line change
Expand Up @@ -886,13 +886,13 @@ def initModify(key)
UI.ChangeWidget(
Id(:ipaddr),
:Value,
Ops.get(Builtins.splitstring(ipp, ":"), 0, "")
Ops.get(IscsiLioData.GetIpAndPort(ipp), 0, "")
)
UI.ChangeWidget(Id(:ipaddr), :Enabled, true)
UI.ChangeWidget(
Id(:port),
:Value,
Ops.get(Builtins.splitstring(ipp, ":"), 1, "3260")
Ops.get(IscsiLioData.GetIpAndPort(ipp), 1, "3260")
)
UI.ChangeWidget(Id(:port), :Enabled, true)
UI.ChangeWidget(
Expand Down Expand Up @@ -1008,6 +1008,9 @@ def storeModify(option_id, option_map)
ip = Convert.to_string(UI.QueryWidget(:ipaddr, :Value))
port = Builtins.tointeger(UI.QueryWidget(:port, :Value))
Builtins.y2milestone("storeModify ip:%1 port:%2 ipp:%3", ip, port, ipp)
if IP.Check6(ip)
ip = "[#{ip}]" # brackets needed around IPv6
end
np = Builtins.sformat("%1:%2", ip, port)
if !Builtins.isempty(ip) && np != ipp
chg = true
Expand Down Expand Up @@ -1146,6 +1149,7 @@ def initAddTarget(key)
:from => "any",
:to => "list <term>"
)
Builtins.y2milestone("Items: %1", ip)
s = Ops.get_string(ip, [0, 1], "")
Builtins.y2milestone("initAddTarget ip:%1", s)
UI.ChangeWidget(Id(:ipaddr), :Value, s)
Expand Down
56 changes: 38 additions & 18 deletions src/modules/IscsiLioData.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,16 @@ def SplitStringNE(str, delim)
end
end

def GetIpAndPort(np)
if !np.start_with?("[")
ret = Builtins.splitstring(np, ":")
else
match_data = np.match(/\[([:\w]+)\]:(\d+)/)
ret = [match_data[1] || "", match_data[2] || ""]
end
ret
end

def MyFind(s, pat)
ret = Builtins.search(s, pat)
ret = -1 if ret == nil
Expand Down Expand Up @@ -357,14 +367,16 @@ def GetLunList(tgt, tpg)
end

def GetNetworkPortal(tgt, tpg)
Builtins.y2milestone("Data: %1, tgt: %2, tpg: %3", @data, tgt, tpg)
ret = Builtins.maplist(
Ops.get_list(@data, ["tgt", tgt, tpg, "ep", "np"], [])
) do |n|
Builtins.sformat(
"%1:%2",
Ops.get_string(n, "ip", ""),
Ops.get_integer(n, "port", 1)
)
ip = n["ip"] || ""
if IP.Check6(ip)
ip = "[#{ip}]"
end
port = n["port"] || 1
ipp = Builtins.sformat("%1:%2", ip, port )
end
deep_copy(ret)
end
Expand Down Expand Up @@ -537,17 +549,26 @@ def GetIpAddr
out = Convert.to_map(
SCR.Execute(path(".target.bash_output"), "LC_ALL=POSIX /sbin/ifconfig")
)
ls = Builtins.filter(
Builtins.splitstring(Ops.get_string(out, "stdout", ""), "\n")
) { |ln| Builtins.search(ln, "inet addr:") != nil }
ls = Builtins.splitstring(out["stdout"]|| "", "\n")
ls = ls.delete_if{ |line| !line.include?("inet") || line.include?("Scope:Link") }

ls = Builtins.maplist(ls) do |s|
pos = Builtins.search(s, "inet addr:")
s = Builtins.substring(s, Ops.add(pos, 10))
pos = Builtins.findfirstof(s, "\t ")
s = Builtins.substring(s, 0, pos) if pos != nil
s
if ((pos = Builtins.search(s, "inet addr:")) != nil)
s = Builtins.substring(s, Ops.add(pos, 10)) # inet addr:
pos = Builtins.findfirstof(s, "\t ")
s = Builtins.substring(s, 0, pos) if pos != nil
s
elsif ((pos = Builtins.search(s, "inet6 addr:")) != nil)
s = Builtins.substring(s, Ops.add(pos, 12)) # inet6 addr:_
pos = Builtins.findfirstof(s, "/")
s = Builtins.substring(s, 0, pos) if pos != nil
s
else
s
end
end
ls = Builtins.filter(ls) { |s| Builtins.substring(s, 0, 4) != "127." }
ls = Builtins.filter(ls) { |s| Builtins.substring(s, 0, 4) != "127." } # lo IPv4
ls = Builtins.filter(ls) { |s| Builtins.substring(s, 0, 3) != "::1" } # lo IPv6
ls = Builtins.add(ls, "") if Builtins.size(ls) == 0
Builtins.y2milestone("GetIpAddr ls:%1", ls)
deep_copy(ls)
Expand Down Expand Up @@ -783,10 +804,8 @@ def ParseConfigLio
Builtins.search(Ops.get(ls, i, ""), "TPG Network Portals:") != nil
i = Ops.add(i, 1)
while Ops.greater_than(MyFind(Ops.get(ls, i, ""), "-> "), 0)
tls = SplitStringNE(
Ops.get(SplitStringNE(Ops.get(ls, i, ""), " "), 1, ""),
":"
)
np = Ops.get(SplitStringNE(Ops.get(ls, i, ""), " "), 1, "")
tls = GetIpAndPort(np)
port = Builtins.tointeger(Ops.get(tls, 1, ""))
if port != nil
Ops.set(
Expand All @@ -797,6 +816,7 @@ def ParseConfigLio
{ "ip" => Ops.get(tls, 0, ""), "port" => port }
)
)
Builtins.y2milestone("Set ip to: %1", Ops.get(tls, 0, ""))
end
i = Ops.add(i, 1)
end
Expand Down

0 comments on commit d964e29

Please sign in to comment.