mirror of
https://github.com/cunnie/sslip.io.git
synced 2025-10-07 00:23:44 +08:00
sslip.io returns AAAA (IPv6) records
- api.system.2a01-4f8-c17-b8f--2.sslip.io ➡ 2a01:4f8:c17:b8f::2 - `dashed` domains only (e.g. only "fe80-2a01-4f8-c17--de0e" not "fe80.2a01.4f8.c17..de0e"; DNS doesn't allow two dots next to each other. - mirrored from https://github.com/cunnie/bin/blob/master/pdns_pipe.sh which has colocated tests.
This commit is contained in:
@@ -43,6 +43,7 @@ pdns_pipe: |
|
|||||||
# `A` queries for the top-level domain will return this list of addresses.
|
# `A` queries for the top-level domain will return this list of addresses.
|
||||||
# CHANGEME: change this to your domain's webserver's address
|
# CHANGEME: change this to your domain's webserver's address
|
||||||
XIP_ROOT_ADDRESSES=( "52.0.56.137" )
|
XIP_ROOT_ADDRESSES=( "52.0.56.137" )
|
||||||
|
XIP_ROOT_ADDRESSES_AAAA=( "2a01:4f8:c17:b8f::2" )
|
||||||
|
|
||||||
# The public IP addresses on which this xip-pdns server will run.
|
# The public IP addresses on which this xip-pdns server will run.
|
||||||
# `NS` queries for the top-level domain will return this list of addresses.
|
# `NS` queries for the top-level domain will return this list of addresses.
|
||||||
@@ -115,11 +116,12 @@ pdns_pipe: |
|
|||||||
#
|
#
|
||||||
# xip.io domain helpers
|
# xip.io domain helpers
|
||||||
#
|
#
|
||||||
# note we insert "x{0}" to separate the double parentheses "((" to
|
IP_PATTERN="(^|\.)(((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?))($|\.)"
|
||||||
# avoid BOSH interpolation getting confused and thinking it needs to insert
|
DASHED_IP_PATTERN="(^|-|\.)(((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)-){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?))($|-|\.)"
|
||||||
# a variable.
|
# https://stackoverflow.com/questions/53497/regular-expression-that-matches-valid-ipv6-addresses
|
||||||
IP_PATTERN="(^|\.)(x{0}(x{0}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?))($|\.)"
|
# We don't use "dotted" IPv6 because DNS doesn't allow two dots next to each other
|
||||||
DASHED_IP_PATTERN="(^|-|\.)(x{0}(x{0}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)-){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?))($|-|\.)"
|
# e.g. "::1" -> "1..sslip.io" isn't allowed (dig error: `is not a legal name (empty label)`)
|
||||||
|
DASHED_IPV6_PATTERN="(^|\.)(([0-9a-fA-F]{1,4}-){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}-){1,7}-|([0-9a-fA-F]{1,4}-){1,6}-[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}-){1,5}(-[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}-){1,4}(-[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}-){1,3}(-[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}-){1,2}(-[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}-((-[0-9a-fA-F]{1,4}){1,6})|-((-[0-9a-fA-F]{1,4}){1,7}|-))(\.|$)"
|
||||||
|
|
||||||
qtype_is() {
|
qtype_is() {
|
||||||
[ "$QTYPE" = "$1" ] || [ "$QTYPE" = "ANY" ]
|
[ "$QTYPE" = "$1" ] || [ "$QTYPE" = "ANY" ]
|
||||||
@@ -137,6 +139,10 @@ pdns_pipe: |
|
|||||||
[[ "$QNAME" =~ $DASHED_IP_PATTERN ]]
|
[[ "$QNAME" =~ $DASHED_IP_PATTERN ]]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
subdomain_is_dashed_ipv6() {
|
||||||
|
[[ "$QNAME" =~ $DASHED_IPV6_PATTERN ]]
|
||||||
|
}
|
||||||
|
|
||||||
resolve_ns_subdomain() {
|
resolve_ns_subdomain() {
|
||||||
local index="${SUBDOMAIN:3}"
|
local index="${SUBDOMAIN:3}"
|
||||||
echo "${XIP_NS_ADDRESSES[$index-1]}"
|
echo "${XIP_NS_ADDRESSES[$index-1]}"
|
||||||
@@ -152,6 +158,11 @@ pdns_pipe: |
|
|||||||
echo "${BASH_REMATCH[2]//-/.}"
|
echo "${BASH_REMATCH[2]//-/.}"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
resolve_dashed_ipv6_subdomain() {
|
||||||
|
[[ "$QNAME" =~ $DASHED_IPV6_PATTERN ]] || true
|
||||||
|
echo "${BASH_REMATCH[2]//-/:}"
|
||||||
|
}
|
||||||
|
|
||||||
answer_soa_query() {
|
answer_soa_query() {
|
||||||
send_answer "SOA" "$XIP_SOA"
|
send_answer "SOA" "$XIP_SOA"
|
||||||
}
|
}
|
||||||
@@ -171,6 +182,13 @@ pdns_pipe: |
|
|||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
|
answer_root_aaaa_query() {
|
||||||
|
local address
|
||||||
|
for address in "${XIP_ROOT_ADDRESSES_AAAA[@]}"; do
|
||||||
|
send_answer "AAAA" "$address"
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
answer_mx_query() {
|
answer_mx_query() {
|
||||||
set -- "${XIP_MX_RECORDS[@]}"
|
set -- "${XIP_MX_RECORDS[@]}"
|
||||||
while [ $# -gt 1 ]; do
|
while [ $# -gt 1 ]; do
|
||||||
@@ -187,6 +205,14 @@ pdns_pipe: |
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
answer_subdomain_aaaa_query_for() {
|
||||||
|
local type="$1"
|
||||||
|
local address="$(resolve_${type}_subdomain)"
|
||||||
|
if [ -n "$address" ]; then
|
||||||
|
send_answer "AAAA" "$address"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
#
|
#
|
||||||
# PowerDNS pipe backend implementation
|
# PowerDNS pipe backend implementation
|
||||||
@@ -219,5 +245,15 @@ pdns_pipe: |
|
|||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
if qtype_is "AAAA"; then
|
||||||
|
if [ $QNAME == $XIP_DOMAIN ]; then
|
||||||
|
answer_root_aaaa_query
|
||||||
|
else
|
||||||
|
if subdomain_is_dashed_ipv6; then
|
||||||
|
answer_subdomain_aaaa_query_for dashed_ipv6
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
send_cmd "END"
|
send_cmd "END"
|
||||||
done
|
done
|
||||||
|
Reference in New Issue
Block a user