Skip to content

Commit

Permalink
Docker: Add included and excluded routes.
Browse files Browse the repository at this point in the history
  • Loading branch information
heiher committed Oct 15, 2023
1 parent 11d1b2b commit 06dfdd4
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
2 changes: 2 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,7 @@ ENV IPV4=198.18.0.1
ENV SOCKS5_ADDR=172.17.0.1
ENV SOCKS5_PORT=1080
ENV SOCKS5_UDP_MODE=udp
ENV IPV4_INCLUDED_ROUTES=0.0.0.0/0
ENV IPV4_EXCLUDED_ROUTES=172.17.0.0/16

ENTRYPOINT ["/entrypoint.sh"]
20 changes: 10 additions & 10 deletions docker/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

TUN="${TUN:-tun0}"
MTU="${MTU:-8500}"
NET="${NET:-172.17.0.0/16}"
IPV4="${IPV4:-198.18.0.1}"
SOCKS5_ADDR="${SOCKS5_ADDR:-192.168.0.1}"
SOCKS5_PORT="${SOCKS5_PORT:-1080}"
Expand Down Expand Up @@ -35,16 +34,17 @@ EOF
}

config_route() {
ip route flush table ${TABLE} > /dev/null 2>&1
ip route add default dev ${TUN} table ${TABLE}
ip rule delete pref 10 > /dev/null 2>&1
ip rule delete pref 11 > /dev/null 2>&1
ip rule delete pref 12 > /dev/null 2>&1
ip rule delete pref 20 > /dev/null 2>&1
ip rule add fwmark 0x${MARK} lookup main pref 10
ip rule add from ${NET} lookup main pref 11
ip rule add to ${NET} lookup main pref 12
ip rule add lookup ${TABLE} pref 20

for addr in $(echo ${IPV4_INCLUDED_ROUTES} | tr ',' '\n'); do
ip rule add to ${addr} table ${TABLE}
done

for addr in $(echo ${IPV4_EXCLUDED_ROUTES} | tr ',' '\n'); do
ip rule add to ${addr} table main
done

ip rule add fwmark 0x${MARK} table main pref 1
}

run() {
Expand Down

0 comments on commit 06dfdd4

Please sign in to comment.