Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Added ipv6 support #97

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions overlay/etc/bind/named.conf.options
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ options {
allow-query-cache { any; };
listen-on { any; };
listen-on-v6 { any; };
response-policy { zone "rpz"; };
rrset-order { order cyclic; };
response-policy { zone "rpz"; } qname-wait-recurse no;
rrset-order { order cyclic; };
#ENABLE_UPSTREAM_DNS#forwarders { dns_ip; };
forward only;
};

logging {
Expand Down
48 changes: 38 additions & 10 deletions overlay/hooks/entrypoint-pre.d/10_generate_config.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,30 @@ RPZ_ZONE="${ZONEPATH}rpz.db"
DOMAINS_PATH="/opt/cache-domains"
UPSTREAM_DNS=${UPSTREAM_DNS:-8.8.8.8}

reverseip () {
local IFS
IFS=.
set -- $1
echo $4.$3.$2.$1
reverse4name () {
local IFS
IFS=.
set -- $1
echo "32.$4.$3.$2.$1.rpz-client-ip"
}

reverse6name () {
local IFS
IFS=:
set -- $1

for i in "$@"
do
if [ -z "$i" ] && [ $zz ]; then continue; fi
if [ -z "$i" ]; then i="zz"; zz=true; fi
if [ -z "$addr" ]; then addr=$i; else addr="$i.$addr"; fi
done

echo "128.$addr.rpz-client-ip"
}

isipv6 () {
[[ "$1" == *":"* ]]
}

export GIT_SSH_COMMAND="ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no"
Expand Down Expand Up @@ -141,8 +160,14 @@ cat services.json | jq -r '.cache_domains[] | .name, .domain_files[]' | while re
echo "Enabling service with ip(s): $C_IP";
echo ";## ${SERVICE}" >> ${RPZ_ZONE}
for IP in $C_IP; do
echo "$SERVICE IN A $IP;" >> $CACHE_ZONE
echo "32.$(reverseip $IP).rpz-client-ip CNAME rpz-passthru.;" >> ${RPZ_ZONE}
if isipv6 "$IP";
then
echo "$SERVICE IN AAAA $IP;" >> $CACHE_ZONE
echo "$(reverse6name $IP) CNAME rpz-passthru.;" >> ${RPZ_ZONE}
else
echo "$SERVICE IN A $IP;" >> $CACHE_ZONE
echo "$(reverse4name $IP) CNAME rpz-passthru.;" >> ${RPZ_ZONE}
fi
done
CONTINUE=true
else
Expand Down Expand Up @@ -177,9 +202,12 @@ echo " --- "
echo ""

if ! [ -z "${PASSTHRU_IPS}" ]; then
for IP in ${PASSTHRU_IPS}; do
echo ";## Additional RPZ passthroughs"
echo "32.$(reverseip $IP).rpz-client-ip CNAME rpz-passthru." >> ${RPZ_ZONE}
for IP in ${PASSTHRU_IPS}; do
echo ";## Additional RPZ passthroughs"
if isipv6 "$IP";
then echo "$(reverse6name $IP) CNAME rpz-passthru." >> ${RPZ_ZONE}
else echo "$(reverse4name $IP) CNAME rpz-passthru." >> ${RPZ_ZONE}
fi
done
fi

Expand Down