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

Add network to iptables command #72

Merged
merged 6 commits into from
Jun 11, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
32 changes: 18 additions & 14 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ FROM alpine:3.20.0
LABEL maintainer="Amin Vakil <info@aminvakil.com>, Dmitry Romashov <dmitry@romashov.tech>"

ENV OC_VERSION=1.3.0
ENV OC_IPV4_NETWORK="192.168.99.0"
ENV OC_IPV4_NETMASK="255.255.255.0"

RUN apk add --no-cache bash

Expand Down Expand Up @@ -45,26 +47,28 @@ RUN buildDeps=( \
| sort -u \
)" \
&& readarray runDepsArr <<< "$runDeps" \
&& apk add --virtual .run-deps "${runDepsArr[@]}" gnutls-utils iptables libnl3 readline libseccomp-dev lz4-dev \
&& apk add --virtual .run-deps "${runDepsArr[@]}" gnutls-utils iptables libnl3 readline libseccomp-dev lz4-dev gettext-envsubst \
&& apk del .build-deps \
&& rm -rf /var/cache/apk/*

# Setup config
COPY routes.txt /tmp/
RUN set -x \
&& sed -i 's/\.\/sample\.passwd/\/etc\/ocserv\/ocpasswd/' /etc/ocserv/ocserv.conf \
&& sed -i 's/\(max-same-clients = \)2/\110/' /etc/ocserv/ocserv.conf \
&& sed -i 's/\.\.\/tests/\/etc\/ocserv/' /etc/ocserv/ocserv.conf \
&& sed -i 's/#\(compression.*\)/\1/' /etc/ocserv/ocserv.conf \
&& sed -i '/^ipv4-network = /{s/192.168.1.0/192.168.99.0/}' /etc/ocserv/ocserv.conf \
&& sed -i 's/192.168.1.2/8.8.8.8/' /etc/ocserv/ocserv.conf \
&& sed -i 's/^route/#route/' /etc/ocserv/ocserv.conf \
&& sed -i 's/^no-route/#no-route/' /etc/ocserv/ocserv.conf \
&& sed -i '/\[vhost:www.example.com\]/,$d' /etc/ocserv/ocserv.conf \
&& sed -i '/^cookie-timeout = /{s/300/3600/}' /etc/ocserv/ocserv.conf \
&& sed -i 's/^isolate-workers/#isolate-workers/' /etc/ocserv/ocserv.conf \
&& cat /tmp/routes.txt >> /etc/ocserv/ocserv.conf \
&& rm -rf /tmp/routes.txt
&& sed -e 's/\.\/sample\.passwd/\/etc\/ocserv\/ocpasswd/' \
-e 's/\(max-same-clients = \)2/\110/' \
-e 's/\.\.\/tests/\/etc\/ocserv/' \
-e 's/#\(compression.*\)/\1/' \
-e '/^ipv4-network = /{s/192.168.1.0/${OC_IPV4_NETWORK}/}' \
-e '/^ipv4-netmask = /{s/255.255.255.0/${OC_IPV4_NETMASK}/}' \
-e 's/192.168.1.2/8.8.8.8/' \
-e 's/^route/#route/' \
-e 's/^no-route/#no-route/' \
-e '/\[vhost:www.example.com\]/,$d' \
-e '/^cookie-timeout = /{s/300/3600/}' \
-e 's/^isolate-workers/#isolate-workers/' /etc/ocserv/ocserv.conf > /tmp/ocserv.conf \
&& cat /tmp/routes.txt >> /tmp/ocserv.conf \
&& envsubst < /tmp/ocserv.conf > /etc/ocserv/ocserv.conf \
&& rm -f /tmp/ocserv.conf

WORKDIR /etc/ocserv

Expand Down
2 changes: 1 addition & 1 deletion docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ fi
sysctl -w net.ipv4.ip_forward=1

# Enable NAT forwarding
iptables -t nat -A POSTROUTING -j MASQUERADE
iptables -t nat -A POSTROUTING -j MASQUERADE -s "${OC_IPV4_NETWORK}"/"${OC_IPV4_NETMASK}"
iptables -A FORWARD -p tcp --tcp-flags SYN,RST SYN -j TCPMSS --clamp-mss-to-pmtu

# Enable TUN device
Expand Down
2 changes: 1 addition & 1 deletion routes.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
route=default
route = 192.168.99.0/255.255.255.0
route = ${OC_IPV4_NETWORK}/${OC_IPV4_NETMASK}
no-route = 192.168.0.0/255.255.0.0
no-route = 10.0.0.0/255.0.0.0
no-route = 172.16.0.0/255.240.0.0
Expand Down
Loading