summaryrefslogtreecommitdiffstats
path: root/interfaces-model.lua
diff options
context:
space:
mode:
Diffstat (limited to 'interfaces-model.lua')
-rw-r--r--interfaces-model.lua29
1 files changed, 15 insertions, 14 deletions
diff --git a/interfaces-model.lua b/interfaces-model.lua
index c955937..40b9542 100644
--- a/interfaces-model.lua
+++ b/interfaces-model.lua
@@ -41,7 +41,7 @@ local get_options = function (family, method)
return optional
end
--- return true or false + the index of array entry matching "name"
+-- return the index of array entry matching "name"
local arrayindex = function (name)
if name and #name > 0 then
if array == nil then
@@ -50,12 +50,12 @@ local arrayindex = function (name)
for k,v in ipairs(array) do
if name == v.value.name.value then
- return true, k
+ return k
end
end
end
- return false, 0
+ return nil
end
local appendentry = function (self, value, prefix)
@@ -242,8 +242,8 @@ get_iface_by_name = function(self, clientdata)
-- if the name is blank, then return a blank iface with error
local ret
unpack_interfaces()
- local rc, idx = arrayindex(clientdata.name or "")
- if rc == false then
+ local idx = arrayindex(clientdata.name or "")
+ if not idx then
ret = get_blank_iface()
ret.value.name.value = name
ret.value.name.errtxt = "Interface does not exist"
@@ -260,10 +260,9 @@ end
create_iface = function(self, def)
unpack_interfaces()
- local rc
- rc = validate_interface( def )
+ local success = validate_interface( def )
- if rc then
+ if success then
idx = #array
table.insert( array, idx+1, def )
commit_interfaces()
@@ -277,14 +276,16 @@ end
update_iface = function(self, def)
unpack_interfaces()
-- if the def by that name doesn't exist, fail
- local rc, idx = arrayindex(def.value.name.value or "" )
- if rc == false then
+ local success
+ local idx = arrayindex(def.value.name.value or "" )
+ if not idx then
def.value.name.errtxt = "This is an invalid interface name"
+ success = false
else
- rc = validate_interface( def )
+ success = validate_interface( def )
end
- if rc then
+ if success then
array[idx] = def
commit_interfaces()
else
@@ -306,8 +307,8 @@ delete_iface_by_name = function(self, deleterequest)
if success then
unpack_interfaces()
- local rc, idx = arrayindex(deleterequest.value.name.value)
- if rc then
+ local idx = arrayindex(deleterequest.value.name.value)
+ if idx then
table.remove (array, idx )
commit_interfaces()
deleterequest.descr = "Interface deleted"