diff --git a/src/etc/rc.update_bogons b/src/etc/rc.update_bogons index 98f3d6d7f..073ed6bfb 100755 --- a/src/etc/rc.update_bogons +++ b/src/etc/rc.update_bogons @@ -2,15 +2,18 @@ CORE_ABI=$(cat /usr/local/opnsense/version/opnsense.abi 2> /dev/null) SYS_ABI=$(opnsense-verify -a 2> /dev/null) -URL="https://pkg.opnsense.org" +URL="https://pkg.opnsense.org" if [ -n "${CORE_ABI}" -a -n "${SYS_ABI}" ]; then # expand url to new mirror layout per release URL="${URL}/${SYS_ABI}/${CORE_ABI}" fi - URL="${URL}/sets/bogons.txz" +DESTDIR="/usr/local/etc" +WORKDIR="/tmp/bogons" +FETCH="fetch -aqT 30" + proc_error= echo "rc.update_bogons is starting up." | logger @@ -25,19 +28,19 @@ fi echo "rc.update_bogons is beginning the update cycle." | logger -rm -rf /tmp/bogons -mkdir -p /tmp/bogons +rm -rf ${WORKDIR} +mkdir -p ${WORKDIR} -fetch -a -T 30 -q -o /tmp/bogons/bogons.txz.sig "${URL}.sig" -fetch -a -T 30 -q -o /tmp/bogons/bogons.txz "${URL}" +${FETCH} -o ${WORKDIR}/bogons.txz.sig "${URL}.sig" +${FETCH} -o ${WORKDIR}/bogons.txz "${URL}" -if [ ! -f /tmp/bogons/bogons.txz ]; then +if [ ! -f ${WORKDIR}/bogons.txz ]; then echo "Could not download ${URL}" | logger proc_error="true" -elif ! opnsense-verify -q /tmp/bogons/bogons.txz; then +elif ! opnsense-verify -q ${WORKDIR}/bogons.txz; then echo "Could not verify ${URL}" | logger proc_error="true" -elif ! tar -C /tmp/bogons -xJf /tmp/bogons/bogons.txz; then +elif ! tar -C ${WORKDIR} -xJf ${WORKDIR}/bogons.txz; then echo "Could not extract ${URL}" | logger proc_error="true" fi @@ -51,13 +54,13 @@ fi ENTRIES_MAX=`pfctl -s memory | awk '/table-entries/ { print $4 }'` ENTRIES_TOT=`pfctl -vvsTables | awk '/Addresses/ {s+=$2}; END {print s}'` ENTRIES_V4=`pfctl -vvsTables | awk '/-\tbogons$/ {getline; print $2}'` -LINES_V4=`wc -l /tmp/bogons/fullbogons-ipv4.txt | awk '{ print $1 }'` +LINES_V4=`wc -l ${WORKDIR}/fullbogons-ipv4.txt | awk '{ print $1 }'` if [ $ENTRIES_MAX -gt $((2*ENTRIES_TOT-${ENTRIES_V4:-0}+LINES_V4)) ]; then # These bogons are removed as they are private. I'm not going # to question this now, adding a big WARNING instead. Here be # dragons... - egrep -v "^100.64.0.0/10|^192.168.0.0/16|^172.16.0.0/12|^10.0.0.0/8" /tmp/bogons/fullbogons-ipv4.txt > /usr/local/etc/bogons - RESULT=`/sbin/pfctl -t bogons -T replace -f /usr/local/etc/bogons 2>&1` + egrep -v "^100.64.0.0/10|^192.168.0.0/16|^172.16.0.0/12|^10.0.0.0/8" ${WORKDIR}/fullbogons-ipv4.txt > ${DESTDIR}/bogons + RESULT=`/sbin/pfctl -t bogons -T replace -f ${DESTDIR}/bogons 2>&1` echo "$RESULT" | awk '{ print "Bogons V4 file downloaded: " $0 }' | logger else echo "Not updating IPv4 bogons (increase table-entries limit)" | logger @@ -67,19 +70,19 @@ ENTRIES_MAX=`pfctl -s memory | awk '/table-entries/ { print $4 }'` ENTRIES_TOT=`pfctl -vvsTables | awk '/Addresses/ {s+=$2}; END {print s}'` BOGONS_V6_TABLE_COUNT=`pfctl -sTables | grep ^bogonsv6$ | wc -l | awk '{ print $1 }'` ENTRIES_TOT=`pfctl -vvsTables | awk '/Addresses/ {s+=$2}; END {print s}'` -LINES_V6=`wc -l /tmp/bogons/fullbogons-ipv6.txt | awk '{ print $1 }'` +LINES_V6=`wc -l ${WORKDIR}/fullbogons-ipv6.txt | awk '{ print $1 }'` if [ $BOGONS_V6_TABLE_COUNT -gt 0 ]; then ENTRIES_V6=`pfctl -vvsTables | awk '/-\tbogonsv6$/ {getline; print $2}'` if [ $ENTRIES_MAX -gt $((2*ENTRIES_TOT-${ENTRIES_V6:-0}+LINES_V6)) ]; then - egrep -iv "^fc00::/7" /tmp/bogons/fullbogons-ipv6.txt > /usr/local/etc/bogonsv6 - RESULT=`/sbin/pfctl -t bogonsv6 -T replace -f /usr/local/etc/bogonsv6 2>&1` + egrep -iv "^fc00::/7" ${WORKDIR}/fullbogons-ipv6.txt > ${DESTDIR}/bogonsv6 + RESULT=`/sbin/pfctl -t bogonsv6 -T replace -f ${DESTDIR}/bogonsv6 2>&1` echo "$RESULT" | awk '{ print "Bogons V6 file downloaded: " $0 }' | logger else echo "Not saving or updating IPv6 bogons (increase table-entries limit)" | logger fi else if [ $ENTRIES_MAX -gt $((2*ENTRIES_TOT+LINES_V6)) ]; then - egrep -iv "^fc00::/7" /tmp/bogons/fullbogons-ipv6.txt > /usr/local/etc/bogonsv6 + egrep -iv "^fc00::/7" ${WORKDIR}/fullbogons-ipv6.txt > ${DESTDIR}/bogonsv6 echo "Bogons V6 file downloaded but not updating IPv6 bogons table because IPv6 Allow is off" | logger else echo "Not saving IPv6 bogons table (IPv6 Allow is off and table-entries limit is potentially too low)" | logger