From 1478867e58e0040c851955c9ee578fd6755689b6 Mon Sep 17 00:00:00 2001 From: Stan Grishin Date: Thu, 22 Dec 2022 18:52:41 +0000 Subject: [PATCH] pbr: bugfix: Makefile, rt_tables fix Signed-off-by: Stan Grishin (cherry picked from commit edbcb97b78d36a813e6aa04f6b6ff9bc20be2eb3) --- net/pbr/Makefile | 4 ++-- net/pbr/files/etc/init.d/pbr.init | 15 ++++++++++----- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/net/pbr/Makefile b/net/pbr/Makefile index e5b967ff04..7ec156ac77 100644 --- a/net/pbr/Makefile +++ b/net/pbr/Makefile @@ -5,7 +5,7 @@ include $(TOPDIR)/rules.mk PKG_NAME:=pbr PKG_VERSION:=1.0.1 -PKG_RELEASE:=1 +PKG_RELEASE:=3 PKG_LICENSE:=GPL-3.0-or-later PKG_MAINTAINER:=Stan Grishin @@ -20,7 +20,7 @@ define Package/pbr/default URL:=https://docs.openwrt.melmac.net/pbr/ DEPENDS:=+ip-full +jshn +jsonfilter +resolveip CONFLICTS:=vpnbypass vpn-policy-routing - PROVIDES:=pbr vpnbypass vpn-policy-routing + PROVIDES:=vpnbypass vpn-policy-routing PKGARCH:=all endef diff --git a/net/pbr/files/etc/init.d/pbr.init b/net/pbr/files/etc/init.d/pbr.init index 3ee9a9b8c7..16aae0596f 100755 --- a/net/pbr/files/etc/init.d/pbr.init +++ b/net/pbr/files/etc/init.d/pbr.init @@ -264,8 +264,8 @@ is_service_running_nft() { [ -x "$nft" ] && [ -n "$(get_mark_nft_chains)" ]; } # is_service_running_nft() { [ -x "$nft" ] && [ -s "$nftPermFile" ]; } is_service_running() { if is_nft; then is_service_running_nft; else is_service_running_iptables; fi; } is_netifd_table() { local iface="$1"; [ "$(uci -q get "network.${iface}.ip4table")" = "${packageName}_${iface%6}" ]; } -get_rt_tables_id() { grep "${packageName}_${iface}" /etc/iproute2/rt_tables | awk '{print $1;}'; } -get_rt_tables_next_id() { echo "$(($(sort -r -n /etc/iproute2/rt_tables | grep -o -E -m 1 "^[0-9]+")+1))"; } +get_rt_tables_id() { local iface="$1"; grep "${packageName}_${iface}" '/etc/iproute2/rt_tables' | awk '{print $1;}'; } +get_rt_tables_next_id() { echo "$(($(sort -r -n '/etc/iproute2/rt_tables' | grep -o -E -m 1 "^[0-9]+")+1))"; } _check_config() { local en; config_get_bool en "$1" 'enabled' 1; [ "$en" -gt 0 ] && _cfg_enabled=0; } is_config_enabled() { local cfg="$1" _cfg_enabled=1 @@ -1658,12 +1658,16 @@ interface_routing() { $ip_full -6 rule add fwmark "${mark}/${fw_mask}" table "$tid" priority "$priority" || ipv6_error=1 fi else - sed -i "/${ipTablePrefix}_${iface}/d" /etc/iproute2/rt_tables + if ! grep -q "$tid ${ipTablePrefix}_${iface}" '/etc/iproute2/rt_tables'; then + sed -i "/${ipTablePrefix}_${iface}/d" '/etc/iproute2/rt_tables' + sync + echo "$tid ${ipTablePrefix}_${iface}" >> '/etc/iproute2/rt_tables' + sync + fi $ip_full -4 rule del fwmark "${mark}/${fw_mask}" table "$tid" >/dev/null 2>&1 $ip_full -4 route flush table "$tid" >/dev/null 2>&1 if [ -n "$gw4" ] || [ "$strict_enforcement" -ne 0 ]; then ipv4_error=0 - echo "$tid ${ipTablePrefix}_${iface}" >> /etc/iproute2/rt_tables if [ -z "$gw4" ]; then $ip_full -4 route add unreachable default table "$tid" >/dev/null 2>&1 || ipv4_error=1 else @@ -1754,7 +1758,8 @@ EOF $ip_full rule del fwmark "${mark}/${fw_mask}" table "$tid" >/dev/null 2>&1 if ! is_netifd_table "$iface"; then $ip_full route flush table "$tid" >/dev/null 2>&1 - sed -i "/${ipTablePrefix}_${iface}/d" /etc/iproute2/rt_tables + sed -i "/${ipTablePrefix}_${iface}/d" '/etc/iproute2/rt_tables' + sync fi return "$s" ;; -- 2.30.2