From 72f5756eb5949de5c838b7948c97652225f2f37c Mon Sep 17 00:00:00 2001 From: "Ycarus (Yannick Chabanois)" Date: Fri, 25 Jun 2021 19:42:03 +0200 Subject: [PATCH] Change in luci-app-openmptcprouter to use device setting --- .../luasrc/controller/openmptcprouter.lua | 46 +++++++++++++++---- .../luasrc/view/openmptcprouter/wizard.htm | 8 ++-- .../root/etc/init.d/openmptcprouter | 6 ++- .../root/usr/libexec/rpcd/openmptcprouter | 21 +++++---- 4 files changed, 58 insertions(+), 23 deletions(-) diff --git a/luci-app-openmptcprouter/luasrc/controller/openmptcprouter.lua b/luci-app-openmptcprouter/luasrc/controller/openmptcprouter.lua index 3d243b210..cca82d950 100644 --- a/luci-app-openmptcprouter/luasrc/controller/openmptcprouter.lua +++ b/luci-app-openmptcprouter/luasrc/controller/openmptcprouter.lua @@ -26,7 +26,11 @@ end function interface_from_device(dev) for _, iface in ipairs(net:get_networks()) do local ifacen = iface:name() - local ifacename = ucic:get("network",ifacen,"ifname") + local ifacename = "" + ifacename = ucic:get("network",ifacen,"device") + if ifacename == "" then + ifacename = ucic:get("network",ifacen,"ifname") + end if ifacename == dev then return ifacen end @@ -113,7 +117,10 @@ function wizard_add() end) local defif = "eth0" if add_interface_ifname == "" then - local defif1 = ucic:get("network","wan1_dev","ifname") or "" + local defif1 = ucic:get("network","wan1_dev","device") or "" + if defif1 == "" then + defif1 = ucic:get("network","wan1_dev","ifname") or "" + end if defif1 ~= "" then defif = defif1 end @@ -126,17 +133,29 @@ function wizard_add() if ointf ~= "" then if ucic:get("network",ointf,"type") == "" then ucic:set("network",ointf,"type","macvlan") + ucic:set("network",ointf,"device",ointf) + ucic:set("network",ointf .. "_dev","device") + ucic:set("network",ointf .. "_dev","type","macvlan") + ucic:set("network",ointf .. "_dev","mode","vepa") + ucic:set("network",ointf .. "_dev","ifname",defif) + ucic:set("network",ointf .. "_dev","name",ointf) end wanif = "wan" .. i end ucic:set("network","wan" .. i,"interface") - ucic:set("network","wan" .. i,"ifname",defif) + ucic:set("network","wan" .. i,"device",defif) ucic:set("network","wan" .. i,"proto","static") ucic:set("openmptcprouter","wan" .. i,"interface") if ointf ~= "" then ucic:set("network","wan" .. i,"type","macvlan") + ucic:set("network","wan" .. i,"device","wan" .. i) ucic:set("network","wan" .. i,"masterintf",defif) + ucic:set("network","wan" .. i .. "_dev","device") + ucic:set("network","wan" .. i .. "_dev","type","macvlan") + ucic:set("network","wan" .. i .. "_dev","mode","vepa") + ucic:set("network","wan" .. i .. "_dev","ifname",defif) + ucic:set("network","wan" .. i .. "_dev","name","wan" .. i) end ucic:set("network","wan" .. i,"ip4table","wan") if multipath_master then @@ -197,7 +216,10 @@ function wizard_add() local delete_intf = luci.http.formvaluetable("delete") or "" if delete_intf ~= "" then for intf, _ in pairs(delete_intf) do - local defif = ucic:get("network",intf,"ifname") + local defif = ucic:get("network",intf,"ifname") or "" + if defif == "" then + defif = ucic:get("network",intf,"ifname") + end ucic:delete("network",intf) if ucic:get("network",intf .. "_dev") ~= "" then ucic:delete("network",intf .. "_dev") @@ -262,9 +284,14 @@ function wizard_add() end if typeintf == "macvlan" and masterintf ~= "" then ucic:set("network",intf,"type","macvlan") + ucic:set("network",intf .. "_dev","device") + ucic:set("network",intf .. "_dev","type","macvlan") + ucic:set("network",intf .. "_dev","ifname",masterinf) + ucic:set("network",intf .. "_dev","mode","vepa") + ucic:set("network",intf .. "_dev","name",intf) ucic:set("network",intf,"masterintf",masterintf) elseif typeintf == "" and ifname ~= "" and (proto == "static" or proto == "dhcp" or proto == "dhcpv6") then - ucic:set("network",intf,"ifname",ifname) + ucic:set("network",intf,"device",ifname) elseif typeintf == "" and device ~= "" and proto == "ncm" then ucic:set("network",intf,"device",device_ncm) elseif typeintf == "" and device ~= "" and proto == "qmi" then @@ -342,7 +369,10 @@ function wizard_add() if not ucic:get("sqm",intf) ~= "" then local defif = get_device(intf) if defif == "" then - defif = ucic:get("network",intf,"ifname") or "" + defif = ucic:get("network",intf,"device") or "" + if defif == "" then + defif = ucic:get("network",intf,"ifname") or "" + end end ucic:set("sqm",intf,"queue") ucic:set("sqm",intf,"interface",defif) @@ -442,7 +472,7 @@ function wizard_add() ucic:set("network","omrvpn","proto","bonding") end if vpn_intf ~= "" then - ucic:set("network","omrvpn","ifname",vpn_intf) + ucic:set("network","omrvpn","device",vpn_intf) ucic:set("sqm","omrvpn","interface",vpn_intf) ucic:save("network") ucic:commit("network") @@ -894,7 +924,7 @@ function wizard_add() -- Restart all menuentry = ucic:get("openmptcprouter","settings","menu") or "openmptcprouter" if gostatus == true then - luci.sys.call("/etc/init.d/macvlan restart >/dev/null 2>/dev/null") + --luci.sys.call("/etc/init.d/macvlan restart >/dev/null 2>/dev/null") luci.sys.call("(env -i /bin/ubus call network reload) >/dev/null 2>/dev/null") luci.sys.call("ip addr flush dev tun0 >/dev/null 2>/dev/null") luci.sys.call("/etc/init.d/omr-tracker stop >/dev/null 2>/dev/null") diff --git a/luci-app-openmptcprouter/luasrc/view/openmptcprouter/wizard.htm b/luci-app-openmptcprouter/luasrc/view/openmptcprouter/wizard.htm index 2c33cfa2d..13cbffcf2 100644 --- a/luci-app-openmptcprouter/luasrc/view/openmptcprouter/wizard.htm +++ b/luci-app-openmptcprouter/luasrc/view/openmptcprouter/wizard.htm @@ -473,7 +473,7 @@ if not (ifacea == "lo" or ifacea == "6in4-omr6in4" or ifacea == "mlvpn0" or ifacea:match("^ifb.*") or ifacea:match("^sit.*") or ifacea:match("^gre.*") or ifacea:match("^ip6.*") or ifacea:match("^teql.*") or ifacea:match("^erspan.*") or ifacea:match("^tun.*") or ifacea:match("^bond.*")) and device_notvirtual(ifacea) then if uci:get("network",ifname,"proto") ~= "macvlan" then %> - + <% else %> @@ -483,9 +483,9 @@ end end if uci:get("network",ifname,"proto") ~= "macvlan" then - if iffind == 0 and uci:get("network",ifname,"ifname") ~= nil then + if iffind == 0 and uci:get("network",ifname,"device") ~= nil then %> - + <% end else @@ -616,7 +616,7 @@