From 58700597c58c23ad969fb3cb290c353eeb6d98fb Mon Sep 17 00:00:00 2001 From: Azureit <1774476+Azureit@users.noreply.github.com> Date: Fri, 13 Jan 2023 23:16:55 +0000 Subject: [PATCH 1/5] siproxd: init requires that interface_inbound and interface_outbound be set siproxd will not work without if_inbound and if_outbound defined in the config file. Tell meaningful error about interface_inbound and interface_outbound Signed-off-by: Azureit <1774476+Azureit@users.noreply.github.com> --- net/siproxd/files/siproxd.init | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/net/siproxd/files/siproxd.init b/net/siproxd/files/siproxd.init index dd932bd7f..14e765b56 100644 --- a/net/siproxd/files/siproxd.init +++ b/net/siproxd/files/siproxd.init @@ -6,6 +6,12 @@ START=50 USE_PROCD=1 +die() { + local err=$1; shift + echo "siproxd[ERROR]: $*" >&2 + exit $err +} + PROG="/usr/sbin/siproxd" CONF_DIR="/var/etc/siproxd" REG_DIR="/var/lib/siproxd" @@ -49,11 +55,15 @@ setup_networks() { local _dev_inbound _dev_outbound config_get _int_inbound "$sec" interface_inbound + [ -z $_int_inbound ] && die 1 "$sec.interface_inbound not defined" config_get _int_outbound "$sec" interface_outbound + [ -z $_int_outbound ] && die 1 "$sec.interface_outbound not defined" . /lib/functions/network.sh network_get_physdev _dev_inbound $_int_inbound + [ -z $_dev_inbound ] && die 1 "$sec.interface_inbound, $_int_inbound isn't a valid interface" network_get_physdev _dev_outbound $_int_outbound + [ -z $_dev_outbound ] && die 1 "$sec.interface_outbound, $_int_outbound isn't a valid interface" default_conf if_inbound $_dev_inbound default_conf if_outbound $_dev_outbound From 734ef753ee6b4c397aecd338b6192f3607247e68 Mon Sep 17 00:00:00 2001 From: Azureit <1774476+Azureit@users.noreply.github.com> Date: Fri, 13 Jan 2023 23:59:20 +0000 Subject: [PATCH 2/5] wait for interfaces to be available Signed-off-by: Azureit <1774476+Azureit@users.noreply.github.com> --- net/siproxd/files/siproxd.init | 2 ++ 1 file changed, 2 insertions(+) diff --git a/net/siproxd/files/siproxd.init b/net/siproxd/files/siproxd.init index 14e765b56..99c0f72c6 100644 --- a/net/siproxd/files/siproxd.init +++ b/net/siproxd/files/siproxd.init @@ -60,8 +60,10 @@ setup_networks() { [ -z $_int_outbound ] && die 1 "$sec.interface_outbound not defined" . /lib/functions/network.sh + ubus -t 30 wait_for network.interface network.$_int_inbound 2>/dev/null network_get_physdev _dev_inbound $_int_inbound [ -z $_dev_inbound ] && die 1 "$sec.interface_inbound, $_int_inbound isn't a valid interface" + ubus -t 30 wait_for network.interface network.$_int_outbound 2>/dev/null network_get_physdev _dev_outbound $_int_outbound [ -z $_dev_outbound ] && die 1 "$sec.interface_outbound, $_int_outbound isn't a valid interface" From 1c7e82840dec52931ce43486e45c49e6e896ff04 Mon Sep 17 00:00:00 2001 From: Azureit <1774476+Azureit@users.noreply.github.com> Date: Sat, 14 Jan 2023 02:33:38 +0000 Subject: [PATCH 3/5] problem with wireguard interface Function 'network_get_physdev' doesn't work with wireguard interfaces, fix this by changing the function to 'network_get_device' Signed-off-by: Azureit <1774476+Azureit@users.noreply.github.com> --- net/siproxd/files/siproxd.init | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/net/siproxd/files/siproxd.init b/net/siproxd/files/siproxd.init index 99c0f72c6..1e89181e3 100644 --- a/net/siproxd/files/siproxd.init +++ b/net/siproxd/files/siproxd.init @@ -61,10 +61,10 @@ setup_networks() { . /lib/functions/network.sh ubus -t 30 wait_for network.interface network.$_int_inbound 2>/dev/null - network_get_physdev _dev_inbound $_int_inbound + network_get_device _dev_inbound $_int_inbound [ -z $_dev_inbound ] && die 1 "$sec.interface_inbound, $_int_inbound isn't a valid interface" ubus -t 30 wait_for network.interface network.$_int_outbound 2>/dev/null - network_get_physdev _dev_outbound $_int_outbound + network_get_device _dev_outbound $_int_outbound [ -z $_dev_outbound ] && die 1 "$sec.interface_outbound, $_int_outbound isn't a valid interface" default_conf if_inbound $_dev_inbound From a5b972211668216e92a4189c7274c2d4113cde5c Mon Sep 17 00:00:00 2001 From: Azureit <1774476+Azureit@users.noreply.github.com> Date: Thu, 26 Jan 2023 13:35:32 +0000 Subject: [PATCH 4/5] fix ubus object Signed-off-by: Azureit <1774476+Azureit@users.noreply.github.com> --- net/siproxd/files/siproxd.init | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/net/siproxd/files/siproxd.init b/net/siproxd/files/siproxd.init index 1e89181e3..d8bd183fe 100644 --- a/net/siproxd/files/siproxd.init +++ b/net/siproxd/files/siproxd.init @@ -60,10 +60,10 @@ setup_networks() { [ -z $_int_outbound ] && die 1 "$sec.interface_outbound not defined" . /lib/functions/network.sh - ubus -t 30 wait_for network.interface network.$_int_inbound 2>/dev/null + ubus -t 30 wait_for network.interface.$_int_inbound 2>/dev/null network_get_device _dev_inbound $_int_inbound [ -z $_dev_inbound ] && die 1 "$sec.interface_inbound, $_int_inbound isn't a valid interface" - ubus -t 30 wait_for network.interface network.$_int_outbound 2>/dev/null + ubus -t 30 wait_for network.interface.$_int_outbound 2>/dev/null network_get_device _dev_outbound $_int_outbound [ -z $_dev_outbound ] && die 1 "$sec.interface_outbound, $_int_outbound isn't a valid interface" From a9e75db49a6740b1ddc0cffbaf5583eb4f73e260 Mon Sep 17 00:00:00 2001 From: Azureit <1774476+Azureit@users.noreply.github.com> Date: Sun, 29 Jan 2023 21:05:59 +0000 Subject: [PATCH 5/5] rewrite the setup_network Signed-off-by: Azureit <1774476+Azureit@users.noreply.github.com> --- net/siproxd/files/siproxd.init | 40 +++++++++++++++++++--------------- 1 file changed, 22 insertions(+), 18 deletions(-) diff --git a/net/siproxd/files/siproxd.init b/net/siproxd/files/siproxd.init index d8bd183fe..8ccc0abd1 100644 --- a/net/siproxd/files/siproxd.init +++ b/net/siproxd/files/siproxd.init @@ -51,24 +51,28 @@ append_conf() { setup_networks() { local sec="$1" - local _int_inbound _int_outbound - local _dev_inbound _dev_outbound - - config_get _int_inbound "$sec" interface_inbound - [ -z $_int_inbound ] && die 1 "$sec.interface_inbound not defined" - config_get _int_outbound "$sec" interface_outbound - [ -z $_int_outbound ] && die 1 "$sec.interface_outbound not defined" - - . /lib/functions/network.sh - ubus -t 30 wait_for network.interface.$_int_inbound 2>/dev/null - network_get_device _dev_inbound $_int_inbound - [ -z $_dev_inbound ] && die 1 "$sec.interface_inbound, $_int_inbound isn't a valid interface" - ubus -t 30 wait_for network.interface.$_int_outbound 2>/dev/null - network_get_device _dev_outbound $_int_outbound - [ -z $_dev_outbound ] && die 1 "$sec.interface_outbound, $_int_outbound isn't a valid interface" - - default_conf if_inbound $_dev_inbound - default_conf if_outbound $_dev_outbound + local _int _dev _up + + for _role in inbound outbound; do + config_get _int "$sec" interface_$_role + [ -z $_int ] && die 1 "$sec.interface_$_role not defined" + + ubus -t 30 wait_for network.interface.$_int 2> /dev/null || die 1 "$sec.interface_$_role - $_int isn't a valid interface" + + for i in `seq 30`; do + if [ -z $_dev ]; then + _dev=`ifstatus $_int | jsonfilter -qe '$.l3_device'` + else + _up=`ifstatus $_int | jsonfilter -qe '$.up'` + [ $_up = true ] && break + fi + + [ $i -eq 30 ] && die 1 "$sec.interface_$_role - $_int timeout, interface not up" + sleep 1 + done + + default_conf if_$_role $_dev + done } # Apply default values to key options if unset in user's UCI config.