From fb7b44fa0eb4051ffec21f809ce20b8d840b0eb8 Mon Sep 17 00:00:00 2001 From: Ted Trask Date: Mon, 12 Apr 2010 15:30:50 +0000 Subject: Added support for dynamic-map keyword. --- opennhrp-model.lua | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/opennhrp-model.lua b/opennhrp-model.lua index 36c3480..554c041 100644 --- a/opennhrp-model.lua +++ b/opennhrp-model.lua @@ -83,6 +83,18 @@ local function parseconfigfile(configfilecontent) i = i+1 end table.insert(config[currentinterface].map, temp) + elseif word == "dynamic-map" then + -- there may be more than one dynamic-map statement + if not config[currentinterface]["dynamic-map"] then + config[currentinterface]["dynamic-map"] = {} + end + local temp = {words[i+1], words[i+2]} + i = i+2 + if words[i+1] == "register" then + temp[3] = words[i+1] + i = i+1 + end + table.insert(config[currentinterface]["dynamic-map"], temp) elseif word == "cisco-authentication" then config[currentinterface]["cisco-authentication"] = {words[i+1]} i = i+1 @@ -138,6 +150,15 @@ local function validateinterfacedetails(interfacedetails) break end end + for i,map in ipairs(interfacedetails.value["dynamic-map"].value) do + local words = {} + for word in string.gmatch(map, "%S+") do words[#words+1] = word end + if not words[1] or not words[2] or (words[3] and words[3] ~= "register") or words[4] then + interfacedetails.value["dynamic-map"].errtxt = "Syntax error on line "..i + success = false + break + end + end if not interfacedetails.value.interface.value or string.find(interfacedetails.value.interface.value, "%s") then interfacedetails.value.interface.errtxt = "Invalid interface name" success = false @@ -192,6 +213,7 @@ function getinterfacedetails(interface) details.interface = cfe({ value=interface, label="Interface" }) details.type = cfe({ type="select", value="Unused", label="Interface type", option={"Unused", "NHRP Enabled", "Shortcut Destination"} }) details.map = cfe({ type="list", value={}, label="Static Peers", descr="List of static peer mappings of protocol-address to nbma-address. Optional 'register' parameter specifies Registration Request sent to this peer on startup. (protocol-address[/prefix] nbma-address [register])" }) + details["dynamic-map"] = cfe({ type="list", value={}, label="Dynamic Peers", descr="List of dynamic peer mappings of protocol-address to nbma-address. Optional 'register' parameter specifies Registration Request sent to this peer on startup. (protocol-address[/prefix] nbma-address [register])" }) configfilecontent = configfilecontent or fs.read_file(configfile) or "" config = config or parseconfigfile(configfilecontent) @@ -204,6 +226,9 @@ function getinterfacedetails(interface) for i,map in ipairs(config[interface].map or {}) do table.insert(details.map.value, table.concat(map, " ")) end + for i,map in ipairs(config[interface]["dynamic-map"] or {}) do + table.insert(details["dynamic-map"].value, table.concat(map, " ")) + end details.interface.errtxt = config[interface].errtxt end @@ -235,13 +260,16 @@ function updateinterfacedetails(interfacedetails) for i,map in ipairs(interfacedetails.value.map.value) do table.insert(intflines, "\tmap "..map) end + for i,map in ipairs(interfacedetails.value["dynamic-map"].value) do + table.insert(intflines, "\tdynamic-map "..map) + end config = config or parseconfigfile(configfilecontent) local intfconfig = config[interfacedetails.value.interface.value] or {} intfconfig.map = nil + intfconfig["dynamic-map"] = nil intfconfig["shortcut-destination"] = nil for name,arr in pairs(intfconfig) do -APP.logevent(name) if type(name) ~= "number" and name ~= "errtxt" then table.insert(intflines, "\t"..name.." "..table.concat(arr, " ")) end -- cgit v1.2.3