File: //proc/25618/cwd/bin/iptables-restore
#!/bin/sh
# Copyright (c) 2000-2016 Synology Inc. All rights reserved.
#
# A iptables-restore wrapper that aims to replace with original iptables-restore
# This wrapper will excute the orginal iptables-restores and retry when EAGAIN is received
RETRY_TIMES=5
RETRY_INTERVAL_MIN_MSECS=1000000
RETRY_INTERVAL_MAX_MSECS=3000000
PIPE_INFO=""
if [ -e "/proc/$$/fd/0" ] && grep -sq '^flags.*[02]$' "/proc/$$/fdinfo/0" && [ ! -t 0 ]; then
while read -r line; do
PIPE_INFO=$(printf "%s\n%s" "${PIPE_INFO}" "${line}")
done
fi
i=0
while [ ${i} -lt ${RETRY_TIMES} ]; do
if [ -z "${PIPE_INFO}" ];then
/usr/bin/xtables-legacy-multi iptables-restore "$@"
else
echo "${PIPE_INFO}" | /usr/bin/xtables-legacy-multi iptables-restore "$@"
fi
originalExitCode=$?
# Resource problem (resource temporarily unavailable)
if [ ${originalExitCode} -ne 1 ]; then
if [ ${originalExitCode} -ne 0 ]; then
logger -p err -t "iptable_debug" "iptables-restore failed, error=${originalExitCode}"
fi
exit ${originalExitCode}
fi
usleep $((RETRY_INTERVAL_MIN_MSECS + ((RANDOM * 100) % (RETRY_INTERVAL_MAX_MSECS - RETRY_INTERVAL_MIN_MSECS))))
i=$((i+1))
logger -p err -t "iptable_debug" "iptables-restore retry, error=${originalExitCode}, times=$i"
done
exit ${originalExitCode}