init package from x-wrt

Signed-off-by: sbwml <admin@cooluc.com>
This commit is contained in:
sbwml 2024-09-03 11:20:59 +08:00
commit 8593dd97f4
4 changed files with 147 additions and 0 deletions

80
Makefile Normal file
View File

@ -0,0 +1,80 @@
#
# Copyright (C) 2017-2019 Chen Minqiang <ptpt52@gmail.com>
#
# This is free software, licensed under the GNU General Public License v2.
# See /LICENSE for more information.
#
include $(TOPDIR)/rules.mk
include $(INCLUDE_DIR)/kernel.mk
PKG_NAME:=natflow
PKG_VERSION:=20240812
PKG_SOURCE_URL:=https://codeload.github.com/ptpt52/natflow/tar.gz/$(PKG_VERSION)?
PKG_HASH:=6481e58eb4c22c36d9ed93f01519b0fff84c29ce088dc960639e65d1d58ccfc0
PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz
PKG_MAINTAINER:=Chen Minqiang <ptpt52@gmail.com>
PKG_LICENSE:=GPL-2.0
include $(INCLUDE_DIR)/package.mk
define KernelPackage/natflow
CATEGORY:=X
SUBMENU:=Fast Forward Stacks
TITLE:=natflow kernel driver
KCONFIG:= \
CONFIG_NF_CONNTRACK_MARK=y \
CONFIG_NETFILTER_INGRESS=y
FILES:=$(PKG_BUILD_DIR)/natflow.ko
AUTOLOAD:=$(call AutoLoad,96,natflow)
DEPENDS:= +kmod-ipt-conntrack +kmod-ipt-nat +kmod-ipt-ipset +kmod-br-netfilter
endef
define KernelPackage/natflow/description
fast nat forward kmod
endef
include $(INCLUDE_DIR)/kernel-defaults.mk
EXTRA_CFLAGS += -Wno-stringop-overread
EXTRA_CFLAGS += -DCONFIG_NATFLOW_PATH -DCONFIG_NATFLOW_URLLOGGER -DNATFLOW_VERSION=\\\"$(PKG_VERSION)-$(shell echo $(PKG_HASH) | head -c7)\\\"
ifneq ($(CONFIG_TARGET_mediatek_mt7622),)
EXTRA_CFLAGS += -DCONFIG_HWNAT_EXTDEV_USE_VLAN_HASH
endif
define Build/Compile/natflow
+$(MAKE) $(PKG_JOBS) -C "$(LINUX_DIR)" \
EXTRA_CFLAGS="$(EXTRA_CFLAGS)" \
$(KERNEL_MAKE_FLAGS) \
ARCH="$(LINUX_KARCH)" \
CROSS_COMPILE="$(KERNEL_CROSS)" \
M="$(PKG_BUILD_DIR)" \
$(if $(CONFIG_KERNEL_DEBUG_INFO),,NO_DEBUG=1) \
modules
endef
define Build/Compile
$(call Build/Compile/natflow)
endef
define Package/natflow
SECTION:=net
CATEGORY:=Network
TITLE:=Natflow init script
DEPENDS:=+ethtool +kmod-natflow
endef
define Package/natflow/install
$(INSTALL_DIR) $(1)/etc/uci-defaults
$(INSTALL_BIN) ./files/70-luci-firewall-natflow $(1)/etc/uci-defaults
$(INSTALL_DIR) $(1)/etc/init.d
$(INSTALL_BIN) ./files/natflow.init $(1)/etc/init.d/natflow
$(INSTALL_DIR) $(1)/etc/hotplug.d/iface
$(INSTALL_DATA) ./files/21-natflow.hotplug $(1)/etc/hotplug.d/iface/21-natflow
endef
$(eval $(call KernelPackage,natflow))
$(eval $(call BuildPackage,natflow))

7
files/21-natflow.hotplug Normal file
View File

@ -0,0 +1,7 @@
#!/bin/sh
[ "$ACTION" = ifup -o "$ACTION" = ifupdate ] || exit 0
[ "$ACTION" = ifupdate -a -z "$IFUPDATE_ADDRESSES" -a -z "$IFUPDATE_DATA" ] && exit 0
logger -t natflow "reloading natflow due to $ACTION of $INTERFACE ($DEVICE)"
/etc/init.d/natflow start &

View File

@ -0,0 +1,10 @@
#!/bin/sh
uci -q batch <<-EOF >/dev/null
delete ucitrack.@firewall[3]
add ucitrack firewall
set ucitrack.@firewall[3].init=natflow
commit ucitrack
EOF
exit 0

50
files/natflow.init Normal file
View File

@ -0,0 +1,50 @@
#!/bin/sh /etc/rc.common
# Copyright (C) 2006-2011 OpenWrt.org
START=95
disable_gro_gso() {
for eth in $(ifconfig | grep "^eth\|^dsa|^lan|^wan" | awk '{print $1}' | sort | uniq); do
ethtool -k "$eth" | grep -q "generic-receive-offload: off" || {
ethtool -K "$eth" gro off
logger -t natflow "disable gro for <$eth>"
}
ethtool -k "$eth" | grep -q "generic-segmentation-offload: off" || {
ethtool -K "$eth" gso off
logger -t natflow "disable gso for <$eth>"
}
done
}
enable_gro_gso() {
for eth in $(ifconfig | grep "^eth\|^dsa|^lan|^wan" | awk '{print $1}' | sort | uniq); do
ethtool -k "$eth" | grep -q "generic-receive-offload: on" || {
ethtool -K "$eth" gro on
logger -t natflow "enable gro for <$eth>"
}
ethtool -k "$eth" | grep -q "generic-segmentation-offload: on" || {
ethtool -K "$eth" gso on
logger -t natflow "enable gro for <$eth>"
}
done
}
start() {
test -c /dev/natflow_ctl || return 0
[ "$(uci -q get firewall.@defaults[0].natflow)" != 1 ] && return 0
disable_gro_gso
delay_pkts=$(uci -q get firewall.@defaults[0].natflow_delay_pkts || echo 0)
echo disabled=0 >/dev/natflow_ctl
echo "delay_pkts=$delay_pkts" >/dev/natflow_ctl
echo ifname_clear >/dev/natflow_ctl
}
stop() {
test -c /dev/natflow_ctl || return 0
enable_gro_gso
echo disabled=1 >/dev/natflow_ctl
}
restart() {
start
}