Skip to content

Commit

Permalink
🍉 Sync 2022-03-25 13:44:43
Browse files Browse the repository at this point in the history
  • Loading branch information
github-actions[bot] committed Mar 25, 2022
1 parent f6931eb commit 76ee905
Show file tree
Hide file tree
Showing 8 changed files with 231 additions and 0 deletions.
80 changes: 80 additions & 0 deletions luci-app-macvlan/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
#
# Copyright (C) 2017-2019 Chen Minqiang <[email protected]>
#
# 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:=6

PKG_LICENSE:=GPLv3
PKG_LICENSE_FILES:=LICENSE
PKG_MAINTAINER:=Chen Minqiang <[email protected]>

PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME)

include $(INCLUDE_DIR)/package.mk

define Package/luci-app-macvlan
CATEGORY:=X
SUBMENU:=Macvlan
TITLE:=LuCI Support for macvlan
PKGARCH:=all
DEPENDS:=+kmod-macvlan +kmod-ipvlan +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
$(INSTALL_DIR) $(1)/usr/share/rpcd/acl.d
$(INSTALL_DATA) ./root/usr/share/rpcd/acl.d/*.json $(1)/usr/share/rpcd/acl.d/
endef

$(eval $(call BuildPackage,luci-app-macvlan))
11 changes: 11 additions & 0 deletions luci-app-macvlan/files/luci/controller/macvlan.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
-- Copyright (C) 2019 X-WRT <[email protected]>

module("luci.controller.macvlan", package.seeall)

function index()
local page

page = entry({"admin", "network", "macvlan"}, cbi("macvlan/macvlan"), _("Macvlan"))
page.leaf = true
page.acl_depends = { "luci-app-macvlan" }
end
14 changes: 14 additions & 0 deletions luci-app-macvlan/files/luci/i18n/macvlan.zh-cn.po
Original file line number Diff line number Diff line change
@@ -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 "序号"
31 changes: 31 additions & 0 deletions luci-app-macvlan/files/luci/model/cbi/macvlan/macvlan.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
-- Copyright (C) 2019 X-WRT <[email protected]>

m = Map("macvlan", translate("Macvlan"))

s = m:section(TypedSection, "macvlan", translate("Macvlan Settings"))
s.addremove = true
s.anonymous = true
s.template = "cbi/tblsection"

o = s:option(Value, "ifname", translate("Interface"))
o.datatype = "string"
o.rmempty = false

o = s:option(Value, "index", translate("Index"))
o.datatype = "and(uinteger,min(0),max(255))"
o.rmempty = false

o = s:option(ListValue, "type", translate("Type"))
o:value("macvlan", translate("macvlan"))
o:value("ipvlan", translate("ipvlan"))

o = s:option(ListValue, "mode", translate("Mode"))
o:value("l2", translate("l2"))
o:value("l3", translate("l3"))

o = s:option(ListValue, "flag", translate("Flag"))
o:value("bridge", translate("bridge"))
o:value("private", translate("private"))
o:value("vepa", translate("vepa"))

return m
Empty file.
74 changes: 74 additions & 0 deletions luci-app-macvlan/files/root/etc/init.d/macvlan
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
#!/bin/sh /etc/rc.common

START=19

MC=/tmp/macvlan_cleanup.sh

stop_macvlan() {
local idx=0
test -f $MC && {
cat $MC | while read line; do
echo "$idx#$line"
idx=$((idx+1))
done | sort -nr | while read line; do
cmd=`echo "$line" | cut -d"#" -f2`
$cmd
done
rm -f $MC
}
}

add_macvlan() {
local cfg="$1"
local ifname index type mode flag
local mvname

config_get ifname "$cfg" ifname
config_get index "$cfg" index
config_get type "$cfg" type
config_get mode "$cfg" mode
config_get flag "$cfg" flag

test -n "$ifname" || return 1
test -n "$index" || return 1
test -n "$type" || return 1

mvname="${type}${index}${ifname}"

echo "$ifname" | grep -q "^[a-zA-Z].*\.[0-9]*$" && {
ifn=`echo $ifname | cut -d"." -f 1`
iid=`echo $ifname | cut -d"." -f 2`
test -n "$ifn" && ifconfig $ifn >/dev/null 2>&1 || return 1
ifconfig $ifn up 2>/dev/null
vconfig set_name_type DEV_PLUS_VID_NO_PAD
vconfig add $ifn $iid 2>/dev/null && echo ip link del $ifname >>$MC
mvname="${type}${index}${ifn}t${iid}"
}

ifconfig $ifname >/dev/null 2>&1 || return 1

ifconfig $ifname up 2>/dev/null
if [ "${type}" = "macvlan" ]; then
ip link add link $ifname $mvname type ${type} 2>/dev/null && echo ip link del $mvname >>$MC
elif [ "${type}" = "ipvlan" ]; then
case "$mode" in
"l2")
ip link add link $ifname $mvname type ${type} mode ${mode} ${flag} 2>/dev/null && echo ip link del $mvname >>$MC
;;
"l3")
ip link add link $ifname $mvname type ${type} 2>/dev/null && echo ip link del $mvname >>$MC
;;
esac
fi
}

start() {
stop_macvlan
echo -n >$MC
config_load macvlan
config_foreach add_macvlan macvlan
}

stop() {
stop_macvlan
}
10 changes: 10 additions & 0 deletions luci-app-macvlan/files/root/etc/uci-defaults/40_luci-app-macvlan
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@

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
11 changes: 11 additions & 0 deletions luci-app-macvlan/root/usr/share/rpcd/acl.d/luci-app-macvlan.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"luci-app-macvlan": {
"description": "Grant UCI access for luci-app-macvlan",
"read": {
"uci": [ "macvlan" ]
},
"write": {
"uci": [ "macvlan" ]
}
}
}

0 comments on commit 76ee905

Please sign in to comment.