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 sys = require "luci.sys"
|
||||||
local json = require("luci.json")
|
local json = require("luci.json")
|
||||||
local fs = require("nixio.fs")
|
local fs = require("nixio.fs")
|
||||||
|
local net = require "luci.model.network".init()
|
||||||
local ucic = luci.model.uci.cursor()
|
local ucic = luci.model.uci.cursor()
|
||||||
module("luci.controller.openmptcprouter", package.seeall)
|
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
|
entry({"admin", "system", "openmptcprouter", "mptcp_check_trace"}, post("mptcp_check_trace")).leaf = true
|
||||||
end
|
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()
|
function wizard_add()
|
||||||
local add_interface = luci.http.formvalue("add_interface") or ""
|
local add_interface = luci.http.formvalue("add_interface") or ""
|
||||||
|
local add_interface_ifname = luci.http.formvalue("add_interface_ifname") or ""
|
||||||
local gostatus = true
|
local gostatus = true
|
||||||
if add_interface ~= "" then
|
if add_interface ~= "" then
|
||||||
local i = 1
|
local i = 1
|
||||||
|
@ -35,11 +49,29 @@ function wizard_add()
|
||||||
multipath_master = true
|
multipath_master = true
|
||||||
end
|
end
|
||||||
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,"interface")
|
||||||
ucic:set("network","wan" .. i,"ifname",defif)
|
ucic:set("network","wan" .. i,"ifname",defif)
|
||||||
ucic:set("network","wan" .. i,"proto","static")
|
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")
|
ucic:set("network","wan" .. i,"ip4table","wan")
|
||||||
if multipath_master then
|
if multipath_master then
|
||||||
ucic:set("network","wan" .. i,"multipath","on")
|
ucic:set("network","wan" .. i,"multipath","on")
|
||||||
|
|
|
@ -4,7 +4,8 @@
|
||||||
local uci = require("luci.model.uci").cursor()
|
local uci = require("luci.model.uci").cursor()
|
||||||
local net = require "luci.model.network".init()
|
local net = require "luci.model.network".init()
|
||||||
local fs = require "nixio.fs"
|
local fs = require "nixio.fs"
|
||||||
local ifaces = net:get_interfaces()
|
local sys = require "luci.sys"
|
||||||
|
local ifaces = sys.net:devices()
|
||||||
local servers_ip = {}
|
local servers_ip = {}
|
||||||
local server_ip = uci:get("shadowsocks-libev","sss0","server")
|
local server_ip = uci:get("shadowsocks-libev","sss0","server")
|
||||||
if server_ip == '127.0.0.1' then
|
if server_ip == '127.0.0.1' then
|
||||||
|
@ -16,8 +17,22 @@
|
||||||
else
|
else
|
||||||
table.insert(servers_ip,server_ip)
|
table.insert(servers_ip,server_ip)
|
||||||
end
|
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 %>
|
<% 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">
|
<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">
|
<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%>" />
|
<input class="cbi-button cbi-button-add" type="submit" name="add_interface" value="<%:Add an interface%>" title="<%:Add an interface%>" />
|
||||||
</div>
|
</div>
|
||||||
</fieldset>
|
</fieldset>
|
||||||
|
|
|
@ -306,7 +306,7 @@ if not net:is_virtual() then
|
||||||
-- macsource.rmempty = true
|
-- macsource.rmempty = true
|
||||||
end
|
end
|
||||||
|
|
||||||
macvlanmaster = s:taboption("physical", Value, "interface", translate("Master interface"))
|
macvlanmaster = s:taboption("physical", Value, "masterintf", translate("Master interface"))
|
||||||
macvlanmaster.default = "eth0"
|
macvlanmaster.default = "eth0"
|
||||||
macvlanmaster:depends("type", "macvlan")
|
macvlanmaster:depends("type", "macvlan")
|
||||||
|
|
||||||
|
|
|
@ -33,11 +33,11 @@ _setup_interface() {
|
||||||
|
|
||||||
uci -q get "network.$1_dev.ifname" >/dev/null && {
|
uci -q get "network.$1_dev.ifname" >/dev/null && {
|
||||||
uci -q set network.$1_dev.mtu=$(uci -q get network.$1.mtu)
|
uci -q set network.$1_dev.mtu=$(uci -q get network.$1.mtu)
|
||||||
uci -q commit network
|
[ -n "$(uci -q get network.$1.masterintf)" ] && uci -q set network.$1_dev.ifname=$(uci -q get network.$1.masterintf)
|
||||||
|
[ -z "$(uci -q get network.$1.masterintf)" ] && uci -q set network.$1.masterintf=$(uci -q get network.$1_dev.ifname)
|
||||||
[ "$_type" = "macvlan" ] || {
|
[ "$_type" = "macvlan" ] || {
|
||||||
uci -q batch <<-EOF
|
uci -q batch <<-EOF
|
||||||
delete network.$1_dev
|
delete network.$1_dev
|
||||||
commit network
|
|
||||||
EOF
|
EOF
|
||||||
}
|
}
|
||||||
[ "$_type" = "macvlan" ] && {
|
[ "$_type" = "macvlan" ] && {
|
||||||
|
@ -47,10 +47,10 @@ _setup_interface() {
|
||||||
uci -q batch <<-EOF
|
uci -q batch <<-EOF
|
||||||
delete network.$1.interface
|
delete network.$1.interface
|
||||||
set network.$1_dev.ifname=$_interface
|
set network.$1_dev.ifname=$_interface
|
||||||
commit network
|
|
||||||
EOF
|
EOF
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
uci -q commit network
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -62,12 +62,13 @@ _setup_interface() {
|
||||||
set network.$1_dev.type=macvlan
|
set network.$1_dev.type=macvlan
|
||||||
set network.$1_dev.ifname=$_ifname
|
set network.$1_dev.ifname=$_ifname
|
||||||
set network.$1.ifname=$1
|
set network.$1.ifname=$1
|
||||||
|
set network.$1.masterintf=$_ifname
|
||||||
|
set network.$1.type=macvlan
|
||||||
set network.$1.defaultroute=0
|
set network.$1.defaultroute=0
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
_macaddr=$(uci -q get "network.$1.macaddr")
|
_macaddr=$(uci -q get "network.$1.macaddr")
|
||||||
_setup_macaddr "$1" "${_macaddr:-auto$(date +%s)}"
|
_setup_macaddr "$1" "${_macaddr:-auto$(date +%s)}"
|
||||||
uci -q set "network.$1.type=macvlan" # legacy
|
|
||||||
uci -q set network.$1_dev.mtu=$(uci -q get network.$1.mtu)
|
uci -q set network.$1_dev.mtu=$(uci -q get network.$1.mtu)
|
||||||
uci -q commit network
|
uci -q commit network
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,10 +23,11 @@ _setup_macvlan() {
|
||||||
set network.$1_dev.type=macvlan
|
set network.$1_dev.type=macvlan
|
||||||
set network.$1_dev.ifname=$_ifname
|
set network.$1_dev.ifname=$_ifname
|
||||||
set network.$1.ifname=$1
|
set network.$1.ifname=$1
|
||||||
|
set network.$1.type=macvlan
|
||||||
|
set network.$1.masterintf=$_ifname
|
||||||
EOF
|
EOF
|
||||||
_macaddr=$(uci -q get "network.$1.macaddr")
|
_macaddr=$(uci -q get "network.$1.macaddr")
|
||||||
_setup_macaddr "$1" "${_macaddr:-auto$(date +%s)}"
|
_setup_macaddr "$1" "${_macaddr:-auto$(date +%s)}"
|
||||||
uci -q set "network.$1.type=macvlan" # legacy
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_setup_multipath_off() {
|
_setup_multipath_off() {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue