Skip to content

Commit

Permalink
Merge pull request #23 from manuelbuil/dual-stack
Browse files Browse the repository at this point in the history
Provide support for ipv6
  • Loading branch information
vadorovsky authored Sep 29, 2021
2 parents 8833220 + bf2ef6f commit 8264933
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 7 deletions.
18 changes: 13 additions & 5 deletions entry
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,21 @@ set -e -x

trap exit TERM INT

if [ `cat /proc/sys/net/ipv4/ip_forward` != 1 ]; then
exit 1
if echo ${DEST_IP} | grep -Eq ":"
then
if [ `cat /proc/sys/net/ipv6/conf/all/forwarding` != 1 ]; then
exit 1
fi
ip6tables -t nat -I PREROUTING ! -s ${DEST_IP}/128 -p ${DEST_PROTO} --dport ${SRC_PORT} -j DNAT --to ${DEST_IP}:${DEST_PORT}
ip6tables -t nat -I POSTROUTING -d ${DEST_IP}/128 -p ${DEST_PROTO} -j MASQUERADE
else
if [ `cat /proc/sys/net/ipv4/ip_forward` != 1 ]; then
exit 1
fi
iptables -t nat -I PREROUTING ! -s ${DEST_IP}/32 -p ${DEST_PROTO} --dport ${SRC_PORT} -j DNAT --to ${DEST_IP}:${DEST_PORT}
iptables -t nat -I POSTROUTING -d ${DEST_IP}/32 -p ${DEST_PROTO} -j MASQUERADE
fi

iptables -t nat -I PREROUTING ! -s ${DEST_IP}/32 -p ${DEST_PROTO} --dport ${SRC_PORT} -j DNAT --to ${DEST_IP}:${DEST_PORT}
iptables -t nat -I POSTROUTING -d ${DEST_IP}/32 -p ${DEST_PROTO} -j MASQUERADE

if [ ! -e /pause ]; then
mkfifo /pause
fi
Expand Down
2 changes: 1 addition & 1 deletion package/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM alpine:3.12
RUN apk add -U --no-cache iptables
RUN apk add -U --no-cache iptables ip6tables
COPY entry /usr/bin/
CMD ["entry"]
2 changes: 1 addition & 1 deletion package/Dockerfile.arm
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Alpine has a different image for arm https://github.com/docker-library/repo-info/blob/master/repos/alpine/remote/3.12.8.md
FROM alpine@sha256:a296b4c6f6ee2b88f095b61e95c7ef4f51ba25598835b4978c9256d8c8ace48a
RUN apk add -U --no-cache iptables
RUN apk add -U --no-cache iptables ip6tables
COPY entry /usr/bin/
CMD ["entry"]

0 comments on commit 8264933

Please sign in to comment.