Skip to content

Instantly share code, notes, and snippets.

@farrokhi
Created August 16, 2016 09:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save farrokhi/619e6fbd66f9761e2efb21022602b18d to your computer and use it in GitHub Desktop.
Save farrokhi/619e6fbd66f9761e2efb21022602b18d to your computer and use it in GitHub Desktop.
Split default route into multiple smaller routes (FreeBSD)
#!/bin/sh
#
# Split default route into 8 smaller routes to avoid
# lock contention during route lookup
#
# If a default router is not specified, it will be
# taken from rc.conf.
#
ROUTECMD="/sbin/route -q "
ROUTES="0.0.0.0/3 32.0.0.0/3 64.0.0.0/3 96.0.0.0/3 128.0.0.0/3 160.0.0.0/3 192.0.0.0/3 224.0.0.0/3"
if [ $# -lt 1 ]; then
echo "syntax: $0 [start|stop]"
exit 1
fi
case $1 in
start)
GW=`sysrc -n defaultrouter`
for R in ${ROUTES}; do
${ROUTECMD} add -net ${R} ${GW}
done
;;
stop)
for R in ${ROUTES}; do
${ROUTECMD} delete -net ${R}
done
;;
esac
# no need to remove default route since it will never be matched
#${ROUTECMD} delete default
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment