Skip to content

Commit 4507771

Browse files
committed
Adding MAX_CACHE_SIZE
1 parent 5b053f5 commit 4507771

File tree

2 files changed

+56
-10
lines changed

2 files changed

+56
-10
lines changed

Dockerfiles/data/docker-entrypoint.sh

+40-2
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ DEFAULT_REFRESH_TIME=1200
7676
DEFAULT_RETRY_TIME=180
7777
DEFAULT_EXPIRY_TIME=1209600
7878
DEFAULT_MAX_CACHE_TIME=10800
79+
DEFAULT_MAX_CACHE_SIZE="90%"
7980

8081

8182

@@ -285,13 +286,15 @@ add_options() {
285286
local allow_query="${4}"
286287
local allow_recursion="${5}"
287288
local response_policy="${6}"
289+
local max_cache_size="${7}"
288290

289291
{
290292
echo "options {"
291293
echo " directory \"/var/cache/bind\";"
292294
echo " dnssec-validation ${dnssec_validate};"
293295
echo " auth-nxdomain no; # conform to RFC1035"
294296
echo " listen-on-v6 { any; };"
297+
echo " max-cache-size ${max_cache_size};"
295298
if [ -n "${response_policy}" ]; then
296299
echo " response-policy { zone \"${response_policy}\"; };"
297300
fi
@@ -650,6 +653,39 @@ else
650653
MAX_CACHE_TIME="${DEFAULT_MAX_CACHE_TIME}"
651654
fi
652655

656+
if printenv MAX_CACHE_SIZE >/dev/null 2>&1 && [ -n "$( printenv MAX_CACHE_SIZE )" ]; then
657+
MAX_CACHE_SIZE="$( printenv MAX_CACHE_SIZE )"
658+
if [ "${MAX_CACHE_SIZE}" = "unlimited" ]; then
659+
log "info" "Changing DNS Max Cache size to: ${MAX_CACHE_SIZE}" "${DEBUG_ENTRYPOINT}"
660+
elif [ "${MAX_CACHE_SIZE}" = "0" ]; then
661+
log "info" "Changing DNS Max Cache size to: ${MAX_CACHE_SIZE}" "${DEBUG_ENTRYPOINT}"
662+
# Extract value and unit
663+
else
664+
MAX_CACHE_SIZE_VALUE="$( echo "${MAX_CACHE_SIZE}" | grep -Eo '[0-9]+' )"
665+
MAX_CACHE_SIZE_UNIT="$( echo "${MAX_CACHE_SIZE}" | grep -Eo '[^0-9]+' )" # Allowed: %, k, K, m, M, g, G or empty
666+
667+
if [ -z "${MAX_CACHE_SIZE_VALUE}" ]; then
668+
log "warn" "Wrong value for \$MAX_CACHE_SIZE '${MAX_CACHE_SIZE}', defaultint to: ${DEFAULT_MAX_CACHE_SIZE}" "${DEBUG_ENTRYPOINT}"
669+
MAX_CACHE_SIZE="${DEFAULT_MAX_CACHE_SIZE}"
670+
elif [ -z "${MAX_CACHE_SIZE_UNIT}" ]; then
671+
log "info" "Changing DNS Max Cache size to: ${MAX_CACHE_SIZE}" "${DEBUG_ENTRYPOINT}"
672+
MAX_CACHE_SIZE="${MAX_CACHE_SIZE_VALUE}"
673+
else
674+
# Validate correct unit
675+
if ! echo "${MAX_CACHE_SIZE_UNIT}" | grep -E '[%kKmMgG]' >/dev/null; then
676+
log "warn" "Wrong unit for \$MAX_CACHE_SIZE '${MAX_CACHE_SIZE_UNIT}', defaultint to: ${DEFAULT_MAX_CACHE_SIZE}" "${DEBUG_ENTRYPOINT}"
677+
MAX_CACHE_SIZE="${DEFAULT_MAX_CACHE_SIZE}"
678+
else
679+
log "info" "Changing DNS Max Cache size to: ${MAX_CACHE_SIZE}" "${DEBUG_ENTRYPOINT}"
680+
MAX_CACHE_SIZE="${MAX_CACHE_SIZE_VALUE}${MAX_CACHE_SIZE_UNIT}"
681+
fi
682+
fi
683+
fi
684+
else
685+
log "info" "Using default DNS Max Cache size: ${DEFAULT_MAX_CACHE_SIZE}" "${DEBUG_ENTRYPOINT}"
686+
MAX_CACHE_SIZE="${DEFAULT_MAX_CACHE_SIZE}"
687+
fi
688+
653689

654690

655691
####################################################################################################
@@ -872,7 +908,8 @@ if ! printenv DNS_FORWARDER >/dev/null 2>&1; then
872908
"" \
873909
"${_allow_query_block}" \
874910
"${_allow_recursion_block}" \
875-
"${FWD_ZONES}"
911+
"${FWD_ZONES}" \
912+
"${MAX_CACHE_SIZE}"
876913
else
877914

878915
# To be pupulated
@@ -908,7 +945,8 @@ else
908945
"${_forwarders_block}" \
909946
"${_allow_query_block}" \
910947
"${_allow_recursion_block}" \
911-
"${FWD_ZONES}"
948+
"${FWD_ZONES}" \
949+
"${MAX_CACHE_SIZE}"
912950
fi
913951

914952

README.md

+16-8
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,14 @@ Bind caching DNS server based on Debian slim with support for DNS forwarders, in
5454
5. [DNS_PTR](#dns_ptr)
5555
6. [DNSSEC_VALIDATE](#dnssec_validate)
5656
7. [DNS_FORWARDER](#dns_forwarder)
57-
8. [TTL_TIME](#ttl_time)
58-
9. [REFRESH_TIME](#refresh_time)
59-
10. [RETRY_TIME](#retry_time)
60-
11. [EXPIRY_TIME](#expiry_time)
61-
12. [MAX_CACHE_TIME](#max_cache_time)
62-
13. [ALLOW_QUERY](#allow_query)
63-
14. [ALLOW_RECURSION](#allow_recursion)
57+
8. [MAX_CACHE_SIZE](#max_cache_size)
58+
9. [TTL_TIME](#ttl_time)
59+
10. [REFRESH_TIME](#refresh_time)
60+
11. [RETRY_TIME](#retry_time)
61+
12. [EXPIRY_TIME](#expiry_time)
62+
13. [MAX_CACHE_TIME](#max_cache_time)
63+
14. [ALLOW_QUERY](#allow_query)
64+
15. [ALLOW_RECURSION](#allow_recursion)
6465
2. [Default mountpoints](#default-mountpoints)
6566
3. [Default ports](#default-ports)
6667
4. [Examples](#examples)
@@ -96,7 +97,8 @@ Bind caching DNS server based on Debian slim with support for DNS forwarders, in
9697
| `DNS_PTR` | string | | Comma separated list of PTR records (reverse DNS). |
9798
| `DNSSEC_VALIDATE` | string | `no` | Control the behaviour of DNSSEC validation. The default is to not validate: `no`. Other possible values are: `yes` and `auto`. |
9899
| `DNS_FORWARDER` | string | | Specify a comma separated list of IP addresses as custom DNS resolver. This is useful if your LAN already has a DNS server which adds custom/internal domains and you still want to keep them in this DNS server<br/>Example: `DNS_FORWARDER=8.8.8.8,8.8.4.4` |
99-
| `TTL_TIME` | int | `3600` | (Time in seconds) See [BIND TTL](http://www.zytrax.com/books/dns/apa/ttl.html) and [BIND SOA](http://www.zytrax.com/books/dns/ch8/soa.html)|
100+
| `MAX_CACHE_SIZE` | size | `90%` | Amount of memory used by the server (cached results) |
101+
| `ttl_time` | int | `3600` | (time in seconds) see [bind ttl](http://www.zytrax.com/books/dns/apa/ttl.html) and [bind soa](http://www.zytrax.com/books/dns/ch8/soa.html)|
100102
| `REFRESH_TIME` | int | `1200` | (Time in seconds) See [BIND SOA](http://www.zytrax.com/books/dns/ch8/soa.html) |
101103
| `RETRY_TIME` | int | `180` | (Time in seconds) See [BIND SOA](http://www.zytrax.com/books/dns/ch8/soa.html) |
102104
| `EXPIRY_TIME` | int | `1209600` | (Time in seconds) See [BIND SOA](http://www.zytrax.com/books/dns/ch8/soa.html) |
@@ -202,6 +204,12 @@ Some examples
202204
DNS_FORWARDER='8.8.8.8'
203205
DNS_FORWARDER='8.8.8.8,192.168.0.10'
204206
```
207+
#### MAX_CACHE_SIZE
208+
The amount of RAM used by the server to store results. You can use relative (percent) or absolute (bytes) values.
209+
Examples:
210+
* `MAX_CACHE_SIZE=30%` (Use 30% of the systems memory)
211+
* `MAX_CACHE_SIZE=512M` (Use 512 Megabytes)
212+
* `MAX_CACHE_SIZE=2G` (Use 2 Gigabytes)
205213

206214
#### TTL_TIME
207215
Specify time in seconds.

0 commit comments

Comments
 (0)