aboutsummaryrefslogtreecommitdiff
path: root/net/pbr/files/etc/uci-defaults
diff options
context:
space:
mode:
Diffstat (limited to 'net/pbr/files/etc/uci-defaults')
-rw-r--r--net/pbr/files/etc/uci-defaults/90-pbr41
-rw-r--r--net/pbr/files/etc/uci-defaults/91-pbr31
2 files changed, 46 insertions, 26 deletions
diff --git a/net/pbr/files/etc/uci-defaults/90-pbr b/net/pbr/files/etc/uci-defaults/90-pbr
index 95fe37768..db69f779c 100644
--- a/net/pbr/files/etc/uci-defaults/90-pbr
+++ b/net/pbr/files/etc/uci-defaults/90-pbr
@@ -1,19 +1,33 @@
#!/bin/sh
-# shellcheck disable=SC1091,SC3037,SC3043
-readonly __OK__='\033[0;32m[\xe2\x9c\x93]\033[0m'
+readonly pbrFunctionsFile='/etc/init.d/pbr'
+if [ -s "$pbrFunctionsFile" ]; then
+# shellcheck source=../../etc/init.d/pbr
+ . "$pbrFunctionsFile"
+else
+ printf "%b: pbr init.d file (%s) not found! \n" '\033[0;31mERROR\033[0m' "$pbrFunctionsFile"
+fi
# Transition from vpn-policy-routing
-if [ -s '/etc/config/vpn-policy-routing' ] && [ ! -s '/etc/config/pbr-opkg' ]; then
+if [ -s '/etc/config/vpn-policy-routing' ] && [ ! -s '/etc/config/pbr-opkg' ] \
+ && [ "$(uci_get pbr config enabled)" = '0' ]; then
if [ -x '/etc/init.d/vpn-policy-routing' ]; then
- echo "Stopping and disabling vpn-policy-routing."
- /etc/init.d/vpn-policy-routing stop
- /etc/init.d/vpn-policy-routing disable
+ output "Stopping and disabling vpn-policy-routing."
+ if /etc/init.d/vpn-policy-routing stop \
+ && /etc/init.d/vpn-policy-routing disable; then
+ output_okn
+ else
+ output_failn
+ fi
+ fi
+ output "Migrating vpn-policy-routing config file."
+ if mv '/etc/config/pbr' '/etc/config/pbr-opkg' \
+ && sed 's/vpn-policy-routing/pbr/g' /etc/config/vpn-policy-routing > /etc/config/pbr \
+ && uci_set vpn-policy-routing config enabled 0 && uci_commit vpn-policy-routing; then
+ output_okn
+ else
+ output_failn
fi
- echo "Migrating vpn-policy-routing config file."
- mv '/etc/config/pbr' '/etc/config/pbr-opkg'
- sed 's/vpn-policy-routing/pbr/g' /etc/config/vpn-policy-routing > /etc/config/pbr
- uci set vpn-policy-routing.config.enabled=0; uci commit vpn-policy-routing;
fi
# Transition from older versions of pbr
@@ -26,14 +40,17 @@ sed -i "s/'PREROUTING'/'prerouting'/g" /etc/config/pbr
sed -i "s/'POSTROUTING'/'postrouting'/g" /etc/config/pbr
sed -i "s/option fw_mask '0x\(.*\)'/option fw_mask '\1'/g" /etc/config/pbr
sed -i "s/option wan_mark '0x\(.*\)'/option wan_mark '\1'/g" /etc/config/pbr
+sed -i "s|option path '/etc/pbr/|option path '/usr/share/pbr/|g" /etc/config/pbr
-if [ -s '/usr/share/pbr/pbr.firewall.include' ]; then
+# add firewall include file to fw4 config
+# shellcheck source=../../usr/share/pbr/firewall.include
+if [ -s '/usr/share/pbr/firewall.include' ]; then
uci -q batch <<-EOT
delete firewall.pbr
set firewall.pbr='include'
set firewall.pbr.fw4_compatible='1'
set firewall.pbr.type='script'
- set firewall.pbr.path='/usr/share/pbr/pbr.firewall.include'
+ set firewall.pbr.path='/usr/share/pbr/firewall.include'
commit firewall
EOT
fi
diff --git a/net/pbr/files/etc/uci-defaults/91-pbr b/net/pbr/files/etc/uci-defaults/91-pbr
index 16693864f..9fc47e4bb 100644
--- a/net/pbr/files/etc/uci-defaults/91-pbr
+++ b/net/pbr/files/etc/uci-defaults/91-pbr
@@ -1,8 +1,13 @@
#!/bin/sh
-# shellcheck disable=SC1091,SC3037,SC3043
+# shellcheck disable=SC3037,SC3043
-readonly packageName='pbr'
-readonly __OK__='\033[0;32m[\xe2\x9c\x93]\033[0m'
+readonly pbrFunctionsFile='/etc/init.d/pbr'
+if [ -s "$pbrFunctionsFile" ]; then
+# shellcheck source=../../etc/init.d/pbr
+ . "$pbrFunctionsFile"
+else
+ printf "%b: pbr init.d file (%s) not found! \n" '\033[0;31mERROR\033[0m' "$pbrFunctionsFile"
+fi
# shellcheck disable=SC2317
pbr_iface_setup() {
@@ -15,17 +20,17 @@ pbr_iface_setup() {
case "${proto}" in
(gre*|nebula|relay|vti*|vxlan|xfrm) return 0 ;;
(none)
- uci -q set "network.${iface}_rt=route"
- uci -q set "network.${iface}_rt.interface=${iface}"
- uci -q set "network.${iface}_rt.target=0.0.0.0/0"
- uci -q set "network.${iface}_rt6=route6"
- uci -q set "network.${iface}_rt6.interface=${iface}"
- uci -q set "network.${iface}_rt6.target=::/0"
+ uci_add network route "${iface}_rt"
+ uci_set network "${iface}_rt" interface "${iface}"
+ uci_set network "${iface}_rt" target '0.0.0.0/0'
+ uci_add route6 network "${iface}_rt6"
+ uci_set network "${iface}_rt6" interface "${iface}"
+ uci_set network "${iface}_rt6" target '::/0'
;;
esac
echo -en "Setting up ${packageName} routing tables for ${iface}... "
- uci -q set "network.${iface}.ip4table=${packageName}_${iface%6}"
- uci -q set "network.${iface}.ip6table=${packageName}_${iface%6}"
+ uci_set 'network' "${iface}" 'ip4table' "${packageName}_${iface%6}"
+ uci_set 'network' "${iface}" 'ip6table' "${packageName}_${iface%6}"
if ! grep -q -E -e "^[0-9]+\s+${packageName}_${iface%6}$" /etc/iproute2/rt_tables; then
sed -i -e "\$a $(($(sort -r -n /etc/iproute2/rt_tables | grep -o -E -m 1 "^[0-9]+")+1))\t${packageName}_${iface%6}" \
/etc/iproute2/rt_tables
@@ -33,8 +38,6 @@ pbr_iface_setup() {
echo -e "${__OK__}"
}
-. /lib/functions.sh
-. /lib/functions/network.sh
config_load network
config_foreach pbr_iface_setup interface
network_flush_cache
@@ -51,7 +54,7 @@ set network.default6='rule6'
set network.default6.lookup='${packageName}_${iface6%6}'
set network.default6.priority='80000'
EOF
-uci commit network
+uci_commit network
echo -en "Restarting network... "
/etc/init.d/network restart
echo -e "${__OK__}"