1
0
Fork 0
mirror of https://github.com/Ysurac/openmptcprouter-feeds.git synced 2025-02-12 18:41:51 +00:00

Fix macvlan interface support and add interface in wizard using device

This commit is contained in:
Ycarus 2018-09-01 21:59:02 +02:00
parent 2f13420592
commit 2153472351
5 changed files with 70 additions and 10 deletions

View file

@ -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")

View file

@ -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="{&#34;path&#34;:{&#34;resource&#34;:&#34;\/luci-static\/resources&#34;,&#34;browser&#34;:&#34;\/cgi-bin\/luci\/admin\/filebrowser&#34;}}"></script>
<script type="text/javascript" src="<%=resource%>/cbi.js?v=git-18.243.49640-2f13420" data-strings="{&#34;path&#34;:{&#34;resource&#34;:&#34;\/luci-static\/resources&#34;,&#34;browser&#34;:&#34;\/cgi-bin\/luci\/admin\/filebrowser&#34;}}"></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>

View file

@ -306,7 +306,7 @@ if not net:is_virtual() then
-- macsource.rmempty = true
end
macvlanmaster = s:taboption("physical", Value, "interface", translate("Master interface"))
macvlanmaster = s:taboption("physical", Value, "masterintf", translate("Master interface"))
macvlanmaster.default = "eth0"
macvlanmaster:depends("type", "macvlan")

View file

@ -33,11 +33,11 @@ _setup_interface() {
uci -q get "network.$1_dev.ifname" >/dev/null && {
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" ] || {
uci -q batch <<-EOF
delete network.$1_dev
commit network
EOF
}
[ "$_type" = "macvlan" ] && {
@ -47,10 +47,10 @@ _setup_interface() {
uci -q batch <<-EOF
delete network.$1.interface
set network.$1_dev.ifname=$_interface
commit network
EOF
}
}
uci -q commit network
return 0
}
@ -62,12 +62,13 @@ _setup_interface() {
set network.$1_dev.type=macvlan
set network.$1_dev.ifname=$_ifname
set network.$1.ifname=$1
set network.$1.masterintf=$_ifname
set network.$1.type=macvlan
set network.$1.defaultroute=0
EOF
_macaddr=$(uci -q get "network.$1.macaddr")
_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 commit network
}

View file

@ -23,10 +23,11 @@ _setup_macvlan() {
set network.$1_dev.type=macvlan
set network.$1_dev.ifname=$_ifname
set network.$1.ifname=$1
set network.$1.type=macvlan
set network.$1.masterintf=$_ifname
EOF
_macaddr=$(uci -q get "network.$1.macaddr")
_setup_macaddr "$1" "${_macaddr:-auto$(date +%s)}"
uci -q set "network.$1.type=macvlan" # legacy
}
_setup_multipath_off() {