mirror of
https://github.com/Ysurac/openmptcprouter-feeds.git
synced 2025-02-12 18:41:51 +00:00
Use an app for macvlan
This commit is contained in:
parent
bd80da9204
commit
f9e7d0d30f
8 changed files with 265 additions and 0 deletions
78
luci-app-macvlan/Makefile
Normal file
78
luci-app-macvlan/Makefile
Normal file
|
@ -0,0 +1,78 @@
|
|||
#
|
||||
# Copyright (C) 2017-2019 Chen Minqiang <ptpt52@gmail.com>
|
||||
#
|
||||
# This is free software, licensed under the GNU General Public License v3.
|
||||
# See /LICENSE for more information.
|
||||
#
|
||||
|
||||
include $(TOPDIR)/rules.mk
|
||||
|
||||
PKG_NAME:=luci-app-macvlan
|
||||
PKG_VERSION:=1.0.0
|
||||
PKG_RELEASE:=1
|
||||
|
||||
PKG_LICENSE:=GPLv3
|
||||
PKG_LICENSE_FILES:=LICENSE
|
||||
PKG_MAINTAINER:=Chen Minqiang <ptpt52@gmail.com>
|
||||
|
||||
PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME)
|
||||
|
||||
include $(INCLUDE_DIR)/package.mk
|
||||
|
||||
define Package/luci-app-macvlan
|
||||
CATEGORY:=OpenMPTCProuter
|
||||
SUBMENU:=Macvlan
|
||||
TITLE:=LuCI Support for macvlan
|
||||
PKGARCH:=all
|
||||
DEPENDS:=+kmod-macvlan +busybox +@BUSYBOX_CUSTOM +@BUSYBOX_CONFIG_VCONFIG
|
||||
endef
|
||||
|
||||
define Package/luci-app-macvlan/description
|
||||
LuCI Support for macvlan.
|
||||
endef
|
||||
|
||||
define Build/Prepare
|
||||
$(foreach po,$(wildcard ${CURDIR}/files/luci/i18n/*.po), \
|
||||
po2lmo $(po) $(PKG_BUILD_DIR)/$(patsubst %.po,%.lmo,$(notdir $(po)));)
|
||||
endef
|
||||
|
||||
define Build/Configure
|
||||
endef
|
||||
|
||||
define Build/Compile
|
||||
endef
|
||||
|
||||
define Package/luci-app-macvlan/postinst
|
||||
#!/bin/sh
|
||||
if [ -z "$${IPKG_INSTROOT}" ]; then
|
||||
rm -rf /tmp/luci-indexcache /tmp/luci-modulecache
|
||||
fi
|
||||
|
||||
if [ -z "$$IPKG_INSTROOT" ]; then
|
||||
( . /etc/uci-defaults/40_luci-app-macvlan )
|
||||
rm -f /etc/uci-defaults/40_luci-app-macvlan
|
||||
fi
|
||||
|
||||
exit 0
|
||||
endef
|
||||
|
||||
define Package/luci-app-macvlan/conffiles
|
||||
/etc/config/macvlan
|
||||
endef
|
||||
|
||||
define Package/luci-app-macvlan/install
|
||||
$(INSTALL_DIR) $(1)/usr/lib/lua/luci/i18n
|
||||
$(INSTALL_DATA) $(PKG_BUILD_DIR)/macvlan.*.lmo $(1)/usr/lib/lua/luci/i18n/
|
||||
$(INSTALL_DIR) $(1)/usr/lib/lua/luci/controller
|
||||
$(INSTALL_DATA) ./files/luci/controller/*.lua $(1)/usr/lib/lua/luci/controller/
|
||||
$(INSTALL_DIR) $(1)/usr/lib/lua/luci/model/cbi/macvlan
|
||||
$(INSTALL_DATA) ./files/luci/model/cbi/macvlan/*.lua $(1)/usr/lib/lua/luci/model/cbi/macvlan/
|
||||
$(INSTALL_DIR) $(1)/etc/config
|
||||
$(INSTALL_DATA) ./files/root/etc/config/macvlan $(1)/etc/config/macvlan
|
||||
$(INSTALL_DIR) $(1)/etc/init.d
|
||||
$(INSTALL_BIN) ./files/root/etc/init.d/macvlan $(1)/etc/init.d/macvlan
|
||||
$(INSTALL_DIR) $(1)/etc/uci-defaults
|
||||
$(INSTALL_DATA) ./files/root/etc/uci-defaults/40_luci-app-macvlan $(1)/etc/uci-defaults/40_luci-app-macvlan
|
||||
endef
|
||||
|
||||
$(eval $(call BuildPackage,luci-app-macvlan))
|
10
luci-app-macvlan/files/luci/controller/macvlan.lua
Normal file
10
luci-app-macvlan/files/luci/controller/macvlan.lua
Normal file
|
@ -0,0 +1,10 @@
|
|||
-- Copyright (C) 2019 X-WRT <dev@x-wrt.com>
|
||||
|
||||
module("luci.controller.macvlan", package.seeall)
|
||||
|
||||
function index()
|
||||
local page
|
||||
|
||||
page = entry({"admin", "network", "macvlan"}, cbi("macvlan/macvlan"), _("Macvlan"))
|
||||
page.leaf = true
|
||||
end
|
14
luci-app-macvlan/files/luci/i18n/macvlan.zh-cn.po
Normal file
14
luci-app-macvlan/files/luci/i18n/macvlan.zh-cn.po
Normal file
|
@ -0,0 +1,14 @@
|
|||
msgid ""
|
||||
msgstr "Content-Type: text/plain; charset=UTF-8\n"
|
||||
|
||||
msgid "Macvlan"
|
||||
msgstr "Macvlan"
|
||||
|
||||
msgid "Macvlan Settings"
|
||||
msgstr "Macvlan设置"
|
||||
|
||||
msgid "Interface"
|
||||
msgstr "网络接口"
|
||||
|
||||
msgid "Index"
|
||||
msgstr "序号"
|
22
luci-app-macvlan/files/luci/model/cbi/macvlan/macvlan.lua
Normal file
22
luci-app-macvlan/files/luci/model/cbi/macvlan/macvlan.lua
Normal file
|
@ -0,0 +1,22 @@
|
|||
-- Copyright (C) 2019 X-WRT <dev@x-wrt.com>
|
||||
|
||||
local net = require "luci.model.network".init()
|
||||
local ifaces = net:get_interfaces() or { net:get_interface() }
|
||||
|
||||
m = Map("macvlan", translate("Macvlan"))
|
||||
|
||||
s = m:section(TypedSection, "macvlan", translate("Macvlan Settings"))
|
||||
s.addremove = true
|
||||
s.anonymous = false
|
||||
s.template = "cbi/tblsection"
|
||||
|
||||
hn = s:option(ListValue, "ifname", translate("Interface"))
|
||||
hn.rmempty = false
|
||||
|
||||
for _, iface in ipairs(ifaces) do
|
||||
if iface:type() ~= "macvlan" then
|
||||
hn:value(iface:name(),"%s" % iface:name())
|
||||
end
|
||||
end
|
||||
|
||||
return m
|
0
luci-app-macvlan/files/root/etc/config/macvlan
Normal file
0
luci-app-macvlan/files/root/etc/config/macvlan
Normal file
127
luci-app-macvlan/files/root/etc/init.d/macvlan
Executable file
127
luci-app-macvlan/files/root/etc/init.d/macvlan
Executable file
|
@ -0,0 +1,127 @@
|
|||
#!/bin/sh /etc/rc.common
|
||||
|
||||
START=4
|
||||
USE_PROCD=1
|
||||
|
||||
_setup_macaddr() {
|
||||
uci -q get "network.$1_dev.macaddr" >/dev/null && return
|
||||
uci -q set "network.$1_dev.macaddr=$2"
|
||||
}
|
||||
|
||||
_save_macaddr() {
|
||||
local _ifname
|
||||
local _macaddr
|
||||
uci -q get "network.$1_dev.ifname" >/dev/null && {
|
||||
_ifname=$(uci -q get "network.$1.ifname")
|
||||
if [ -n "$(uci -q get network.$1.macaddr)" ] && [ "$(uci -q get network.$1.macaddr)" != "$(uci -q get network.$1_dev.macaddr)" ]; then
|
||||
uci -q set network.$1_dev.macaddr="$(uci -q get network.$1.macaddr)"
|
||||
else
|
||||
_macaddr=$(ip link show dev $_ifname 2>/dev/null | grep link | awk '{print $2}')
|
||||
[ -n "$_macaddr" ] && {
|
||||
uci -q set network.$1_dev.macaddr=$_macaddr
|
||||
uci -q set network.$1.macaddr=$_macaddr
|
||||
}
|
||||
fi
|
||||
}
|
||||
[ -z "$(uci -q get network.$1.macaddr)" ] && {
|
||||
_ifname=$(uci -q get "network.$1.ifname")
|
||||
[ -n "$_ifname" ] && {
|
||||
_macaddr=$(ip link show dev $_ifname 2>/dev/null | grep link | awk '{print $2}')
|
||||
[ -n "$_macaddr" ] && {
|
||||
uci -q set network.$1.macaddr=$_macaddr
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
# Configuration by interface
|
||||
_setup_interface() {
|
||||
local _ifname
|
||||
config_get _ifname "$1" ifname
|
||||
[ -z "$_ifname" ] && config_get _ifname "$1" ifname
|
||||
# do not create macvlan for vlan
|
||||
#case "$_ifname" in
|
||||
# eth*.*) return ;;
|
||||
#esac
|
||||
|
||||
[ "$(echo $1 | grep _dev)" != "" ] && {
|
||||
local _intfdev=$(sed 's/_dev//' $1)
|
||||
uci -q get "network.$_intfdev.ifname" >/dev/null || {
|
||||
logger -t "macvlan" "Remove network.$1"
|
||||
uci -q batch <<-EOF
|
||||
delete network.$1
|
||||
commit network
|
||||
delete macvlan.$1
|
||||
commit macvlan
|
||||
EOF
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
local _type
|
||||
config_get _type "$1" type
|
||||
if [ "$(uci -q get macvlan.$1)" != "" ]; then
|
||||
_type="macvlan"
|
||||
fi
|
||||
|
||||
uci -q get "network.$1_dev.ifname" >/dev/null && {
|
||||
uci -q set network.$1_dev.mtu=$(uci -q get network.$1.mtu)
|
||||
[ -n "$(uci -q get macvlan.$1.ifname)" ] && uci -q set network.$1_dev.ifname=$(uci -q get macvlan.$1.ifname)
|
||||
[ -z "$(uci -q get network.$1.masterintf)" ] && uci -q set network.$1.masterintf=$(uci -q get network.$1_dev.ifname)
|
||||
[ -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.macaddr)" ] && uci -q set network.$1_dev.macaddr=$(uci -q get network.$1.macaddr)
|
||||
[ "$_type" = "macvlan" ] || {
|
||||
logger -t "macvlan" "Remove network.$1_dev"
|
||||
uci -q batch <<-EOF
|
||||
delete network.$1_dev
|
||||
EOF
|
||||
}
|
||||
[ "$_type" = "macvlan" ] && {
|
||||
local interface
|
||||
config_get _interface "$1" interface
|
||||
[ -n "$_interface" ] && {
|
||||
logger -t "macvlan" "Remove network.$1_dev"
|
||||
uci -q batch <<-EOF
|
||||
delete network.$1.interface
|
||||
set network.$1_dev.ifname=$_interface
|
||||
EOF
|
||||
}
|
||||
}
|
||||
uci -q commit network
|
||||
return 0
|
||||
}
|
||||
|
||||
[ "$_type" = "macvlan" ] || return 0
|
||||
[ -z "$_ifname" ] && _ifname=$(uci -q get macvlan.$1.ifname)
|
||||
uci -q batch <<-EOF
|
||||
set network.$1_dev=device
|
||||
set network.$1_dev.name=$1
|
||||
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_dev.mtu=$(uci -q get network.$1.mtu)
|
||||
uci -q commit network
|
||||
}
|
||||
|
||||
start_service() {
|
||||
. /lib/functions.sh
|
||||
config_load network
|
||||
config_foreach _setup_interface interface
|
||||
config_foreach _save_macaddr interface
|
||||
uci -q commit network
|
||||
}
|
||||
|
||||
reload_service() {
|
||||
start
|
||||
}
|
||||
|
||||
service_triggers() {
|
||||
procd_add_reload_trigger network
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
#!/bin/sh
|
||||
|
||||
uci -q batch <<-EOF >/dev/null
|
||||
delete ucitrack.@macvlan[-1]
|
||||
add ucitrack macvlan
|
||||
set ucitrack.@macvlan[-1].init=macvlan
|
||||
commit ucitrack
|
||||
EOF
|
||||
|
||||
rm -f /tmp/luci-indexcache
|
||||
exit 0
|
|
@ -103,6 +103,7 @@ function wizard_add()
|
|||
ucic:set("network","wan" .. i,"proto","static")
|
||||
if ointf ~= "" then
|
||||
ucic:set("network","wan" .. i,"type","macvlan")
|
||||
ucic:set("macvlan","wan" .. i,"macvlan")
|
||||
end
|
||||
ucic:set("network","wan" .. i,"ip4table","wan")
|
||||
if multipath_master then
|
||||
|
@ -114,6 +115,8 @@ function wizard_add()
|
|||
end
|
||||
ucic:set("network","wan" .. i,"defaultroute","0")
|
||||
ucic:reorder("network","wan" .. i, i + 2)
|
||||
ucic:save("macvlan")
|
||||
ucic:commit("macvlan")
|
||||
ucic:save("network")
|
||||
ucic:commit("network")
|
||||
ucic:save("openmptcprouter")
|
||||
|
|
Loading…
Reference in a new issue