mirror of
https://github.com/Ysurac/openmptcprouter-feeds.git
synced 2025-03-09 15:40:03 +00:00
Fix macvlan interface support and add interface in wizard using device
This commit is contained in:
parent
2f13420592
commit
2153472351
5 changed files with 70 additions and 10 deletions
|
@ -2,6 +2,7 @@ local tools = require "luci.tools.status"
|
|||
local sys = require "luci.sys"
|
||||
local json = require("luci.json")
|
||||
local fs = require("nixio.fs")
|
||||
local net = require "luci.model.network".init()
|
||||
local ucic = luci.model.uci.cursor()
|
||||
module("luci.controller.openmptcprouter", package.seeall)
|
||||
|
||||
|
@ -20,8 +21,21 @@ function index()
|
|||
entry({"admin", "system", "openmptcprouter", "mptcp_check_trace"}, post("mptcp_check_trace")).leaf = true
|
||||
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")
|
||||
if ifacename == dev then
|
||||
return ifacen
|
||||
end
|
||||
end
|
||||
return ""
|
||||
end
|
||||
|
||||
|
||||
function wizard_add()
|
||||
local add_interface = luci.http.formvalue("add_interface") or ""
|
||||
local add_interface_ifname = luci.http.formvalue("add_interface_ifname") or ""
|
||||
local gostatus = true
|
||||
if add_interface ~= "" then
|
||||
local i = 1
|
||||
|
@ -35,11 +49,29 @@ function wizard_add()
|
|||
multipath_master = true
|
||||
end
|
||||
end)
|
||||
local defif = ucic:get("network","wan1_dev","ifname") or "eth0"
|
||||
local defif = "eth0"
|
||||
if add_interface_ifname == "" then
|
||||
local defif1 = ucic:get("network","wan1_dev","ifname") or ""
|
||||
if defif1 ~= "" then
|
||||
defif = defif1
|
||||
end
|
||||
else
|
||||
defif = add_interface_ifname
|
||||
end
|
||||
|
||||
local ointf = interface_from_device(defif) or ""
|
||||
if ointf ~= "" then
|
||||
if ucic:get("network",ointf,"type") == "" then
|
||||
ucic:set("network",ointf,"type","macvlan")
|
||||
end
|
||||
end
|
||||
|
||||
ucic:set("network","wan" .. i,"interface")
|
||||
ucic:set("network","wan" .. i,"ifname",defif)
|
||||
ucic:set("network","wan" .. i,"proto","static")
|
||||
ucic:set("network","wan" .. i,"type","macvlan")
|
||||
if ointf ~= "" then
|
||||
ucic:set("network","wan" .. i,"type","macvlan")
|
||||
end
|
||||
ucic:set("network","wan" .. i,"ip4table","wan")
|
||||
if multipath_master then
|
||||
ucic:set("network","wan" .. i,"multipath","on")
|
||||
|
|
|
@ -4,7 +4,8 @@
|
|||
local uci = require("luci.model.uci").cursor()
|
||||
local net = require "luci.model.network".init()
|
||||
local fs = require "nixio.fs"
|
||||
local ifaces = net:get_interfaces()
|
||||
local sys = require "luci.sys"
|
||||
local ifaces = sys.net:devices()
|
||||
local servers_ip = {}
|
||||
local server_ip = uci:get("shadowsocks-libev","sss0","server")
|
||||
if server_ip == '127.0.0.1' then
|
||||
|
@ -16,8 +17,22 @@
|
|||
else
|
||||
table.insert(servers_ip,server_ip)
|
||||
end
|
||||
|
||||
function device_notvirtual(dev)
|
||||
for _, iface in ipairs(net:get_networks()) do
|
||||
local ifacen = iface:name()
|
||||
local ifacename = uci:get("network",ifacen,"ifname")
|
||||
local ifacetype = uci:get("network",ifacen,"type") or ""
|
||||
local ifaceproto = uci:get("network",ifacen,"proto") or ""
|
||||
if ifacename == dev and (ifacetype == "macvlan" or ifacetype == "bridge" or ifaceproto == "6in4") then
|
||||
return false
|
||||
end
|
||||
end
|
||||
return true
|
||||
end
|
||||
|
||||
%>
|
||||
<script type="text/javascript" src="<%=resource%>/cbi.js" data-strings="{"path":{"resource":"\/luci-static\/resources","browser":"\/cgi-bin\/luci\/admin\/filebrowser"}}"></script>
|
||||
<script type="text/javascript" src="<%=resource%>/cbi.js?v=git-18.243.49640-2f13420" data-strings="{"path":{"resource":"\/luci-static\/resources","browser":"\/cgi-bin\/luci\/admin\/filebrowser"}}"></script>
|
||||
|
||||
<% if stderr and #stderr > 0 then %><pre class="error"><%=pcdata(stderr)%></pre><% end %>
|
||||
<form class="inline" method="post" action="<%=url('admin/system/openmptcprouter/wizard_add')%>" enctype="multipart/form-data">
|
||||
|
@ -204,6 +219,17 @@
|
|||
%>
|
||||
|
||||
<div class="cbi-section-create">
|
||||
<select class="cbi-section-create-name" name="add_interface_ifname">
|
||||
<%
|
||||
for _, ifacea in ipairs(ifaces) do
|
||||
if not (ifacea == "lo" or ifacea == "6in4-omr6in4" or ifacea:match("^ifb.*") or ifacea:match("^sit.*")) and device_notvirtual(ifacea) then
|
||||
%>
|
||||
<option value="<%=ifacea%>"><%=ifacea%></option>
|
||||
<%
|
||||
end
|
||||
end
|
||||
%>
|
||||
</select>
|
||||
<input class="cbi-button cbi-button-add" type="submit" name="add_interface" value="<%:Add an interface%>" title="<%:Add an interface%>" />
|
||||
</div>
|
||||
</fieldset>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue