pbr: bugfix: Makefile, rt_tables fix 20160/head
authorStan Grishin <stangri@melmac.ca>
Thu, 22 Dec 2022 18:52:41 +0000 (18:52 +0000)
committerStan Grishin <stangri@melmac.ca>
Thu, 22 Dec 2022 21:31:47 +0000 (21:31 +0000)
Signed-off-by: Stan Grishin <stangri@melmac.ca>
(cherry picked from commit edbcb97b78d36a813e6aa04f6b6ff9bc20be2eb3)

net/pbr/Makefile
net/pbr/files/etc/init.d/pbr.init

index e5b967ff0421d906d03f702a9f7f535b55d8934c..7ec156ac77c03b36a64eb863acc556eab9579d16 100644 (file)
@@ -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 <stangri@melmac.ca>
 
@@ -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
 
index 3ee9a9b8c768b77a8c8fa331fae39a45116f12d0..16aae0596f6c3cfabce2aeae1a90dee940b949ba 100755 (executable)
@@ -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"
                ;;