From 67522a2434fbf4b7ce25a5c5b5fcc833a6280828 Mon Sep 17 00:00:00 2001 From: Wang Sen Di Date: Tue, 25 Nov 2025 14:27:12 +0800 Subject: [PATCH] - --- netflow/iptables.sh | 26 +++++++++----------------- 1 file changed, 9 insertions(+), 17 deletions(-) diff --git a/netflow/iptables.sh b/netflow/iptables.sh index f6a7718..3319f6f 100644 --- a/netflow/iptables.sh +++ b/netflow/iptables.sh @@ -3,28 +3,20 @@ if [[ -d "/host/proc/1/" ]]; then source /apps/gitrce/hook/singleton.sh "$0"; fi -__main() { - : - # 切换到系统默认的legacy 有些不支持iptabes-nft或者nftables - update-alternatives --set iptables /usr/sbin/iptables-legacy +_owner_id=50000 +_chain="output_netflow_owner_${_owner_id}" - _owner_id=50000 - _chain_name="output_netflow_owner_${_owner_id}" - # 创建链(如果不存在) - iptables -t mangle -N "${_chain_name}" 2>/dev/null +for cmd in iptables ip6tables; do + $cmd -t mangle -N "$_chain" 2>/dev/null || true - # 检查主链 OUTPUT 是否已有跳转规则 - if ! iptables -t mangle -C OUTPUT -m owner --gid-owner "${_owner_id}" -j "${_chain_name}" 2>/dev/null; then - iptables -t mangle -A OUTPUT -m owner --gid-owner "${_owner_id}" -j "${_chain_name}" + if ! $cmd -t mangle -C OUTPUT -m owner --gid-owner "$_owner_id" -j "$_chain" 2>/dev/null; then + $cmd -t mangle -A OUTPUT -m owner --gid-owner "$_owner_id" -j "$_chain" fi - # 检查子链是否已有 RETURN - if ! iptables -t mangle -C "${_chain_name}" -j RETURN 2>/dev/null; then - iptables -t mangle -A "${_chain_name}" -j RETURN + if ! $cmd -t mangle -C "$_chain" -j RETURN 2>/dev/null; then + $cmd -t mangle -A "$_chain" -j RETURN fi -} - -__main +done __help() { cat >/dev/null <<-'EOF'