Blob Blame History Raw
#!/bin/bash
# modified reproducer from upstream issue
# https://gitlab.isc.org/isc-projects/bind9/-/issues/2852

# Pause bind on loading this file
mkfifo _bind.nta

named -g -c <(echo "options { port 5300; listen-on { any; }; listen-on-v6 { any; }; };") -n 1 &
NAMED_PID=$!

sleep 2
for i in {2..32}; do
	sleep 0.05
	sudo ip addr add 127.0.0.$i/32 dev lo
	[ "$i" = 6 ] && echo -n '' > _bind.nta && GO=1
done

lsof -n -p ${NAMED_PID} | grep :domain
TCP=$(lsof -n -p ${NAMED_PID} | grep 'TCP 127.0.0.' | wc -l)
UDP=$(lsof -n -p ${NAMED_PID} | grep 'UDP 127.0.0.' | wc -l)
echo "TCP: $TCP UDP: $UDP"

sleep 5
#echo "Done adding addresses, press ENTER to terminate."
#read

kill -TERM "${NAMED_PID}"
timeout 5 cat _bind.nta
wait "${NAMED_PID}"
rm -f _bind.nta

for i in {2..32}; do
	sudo ip addr del 127.0.0.$i/32 dev lo
done
echo "TCP: $TCP UDP: $UDP"
if [ "$TCP" -ne "$UDP" ]; then
	echo "Mismatching listeners!"
	exit 1
fi