]>
Commit | Line | Data |
---|---|---|
6644c1c7 MT |
1 | From 28de38768e2c7d763b9aa5b7a4d251d5e56bab0b Mon Sep 17 00:00:00 2001 |
2 | From: RinSatsuki <aa65535@live.com> | |
3 | Date: Sat, 10 Jan 2015 15:22:21 +0000 | |
4 | Subject: [PATCH 28/55] Add --min-cache-ttl option. | |
5 | ||
6 | --- | |
7 | CHANGELOG | 7 +++++++ | |
8 | man/dnsmasq.8 | 6 ++++++ | |
9 | src/cache.c | 4 +++- | |
10 | src/config.h | 1 + | |
11 | src/dnsmasq.h | 2 +- | |
12 | src/option.c | 11 +++++++++++ | |
13 | 6 files changed, 29 insertions(+), 2 deletions(-) | |
14 | ||
15 | diff --git a/CHANGELOG b/CHANGELOG | |
16 | index 0bbb7835df4f..23fc6d0530cf 100644 | |
17 | --- a/CHANGELOG | |
18 | +++ b/CHANGELOG | |
19 | @@ -43,6 +43,13 @@ version 2.73 | |
20 | Add --log-queries=extra option, which makes logs easier | |
21 | to search automatically. | |
22 | ||
23 | + Add --min-cache-ttl option. I've resisted this for a long | |
24 | + time, on the grounds that disbelieving TTLs is never a | |
25 | + good idea, but I've been persuaded that there are | |
26 | + sometimes reasons to do it. (Step forward, GFW). | |
27 | + To avoid misuse, there's a hard limit on the TTL | |
28 | + floor of one hour. Thansk to RinSatsuki for the patch. | |
29 | + | |
30 | ||
31 | version 2.72 | |
32 | Add ra-advrouter mode, for RFC-3775 mobile IPv6 support. | |
33 | diff --git a/man/dnsmasq.8 b/man/dnsmasq.8 | |
34 | index 227d74bd80e7..5cfa355dea4a 100644 | |
35 | --- a/man/dnsmasq.8 | |
36 | +++ b/man/dnsmasq.8 | |
37 | @@ -81,6 +81,12 @@ the upstream DNS servers. | |
38 | .B --max-cache-ttl=<time> | |
39 | Set a maximum TTL value for entries in the cache. | |
40 | .TP | |
41 | +.B --min-cache-ttl=<time> | |
42 | +Extend short TTL values to the time given when caching them. Note that | |
43 | +artificially extending TTL values is in general a bad idea, do not do it | |
44 | +unless you have a good reason, and understand what you are doing. | |
45 | +Dnsmasq limits the value of this option to one hour, unless recompiled. | |
46 | +.TP | |
47 | .B --auth-ttl=<time> | |
48 | Set the TTL value returned in answers from the authoritative server. | |
49 | .TP | |
50 | diff --git a/src/cache.c b/src/cache.c | |
51 | index 960bb7938778..945be071a0b6 100644 | |
52 | --- a/src/cache.c | |
53 | +++ b/src/cache.c | |
54 | @@ -461,9 +461,11 @@ struct crec *cache_insert(char *name, struct all_addr *addr, | |
55 | if (flags & (F_IPV4 | F_IPV6 | F_CNAME)) | |
56 | { | |
57 | log_query(flags | F_UPSTREAM, name, addr, NULL); | |
58 | - /* Don;t mess with TTL for DNSSEC records. */ | |
59 | + /* Don't mess with TTL for DNSSEC records. */ | |
60 | if (daemon->max_cache_ttl != 0 && daemon->max_cache_ttl < ttl) | |
61 | ttl = daemon->max_cache_ttl; | |
62 | + if (daemon->min_cache_ttl != 0 && daemon->min_cache_ttl > ttl) | |
63 | + ttl = daemon->min_cache_ttl; | |
64 | } | |
65 | ||
66 | /* if previous insertion failed give up now. */ | |
67 | diff --git a/src/config.h b/src/config.h | |
68 | index 3b88d8193dca..cdca231b4079 100644 | |
69 | --- a/src/config.h | |
70 | +++ b/src/config.h | |
71 | @@ -27,6 +27,7 @@ | |
72 | #define RANDOM_SOCKS 64 /* max simultaneous random ports */ | |
73 | #define LEASE_RETRY 60 /* on error, retry writing leasefile after LEASE_RETRY seconds */ | |
74 | #define CACHESIZ 150 /* default cache size */ | |
75 | +#define TTL_FLOOR_LIMIT 3600 /* don't allow --min-cache-ttl to raise TTL above this under any circumstances */ | |
76 | #define MAXLEASES 1000 /* maximum number of DHCP leases */ | |
77 | #define PING_WAIT 3 /* wait for ping address-in-use test */ | |
78 | #define PING_CACHE_TIME 30 /* Ping test assumed to be valid this long. */ | |
79 | diff --git a/src/dnsmasq.h b/src/dnsmasq.h | |
80 | index 4e9aea401b75..f8275e3ac479 100644 | |
81 | --- a/src/dnsmasq.h | |
82 | +++ b/src/dnsmasq.h | |
83 | @@ -943,7 +943,7 @@ extern struct daemon { | |
84 | int max_logs; /* queue limit */ | |
85 | int cachesize, ftabsize; | |
86 | int port, query_port, min_port; | |
87 | - unsigned long local_ttl, neg_ttl, max_ttl, max_cache_ttl, auth_ttl; | |
88 | + unsigned long local_ttl, neg_ttl, max_ttl, min_cache_ttl, max_cache_ttl, auth_ttl; | |
89 | struct hostsfile *addn_hosts; | |
90 | struct dhcp_context *dhcp, *dhcp6; | |
91 | struct ra_interface *ra_interfaces; | |
92 | diff --git a/src/option.c b/src/option.c | |
93 | index b7372be0a090..8b994098cc9f 100644 | |
94 | --- a/src/option.c | |
95 | +++ b/src/option.c | |
96 | @@ -148,6 +148,7 @@ struct myoption { | |
97 | #define LOPT_DNSSEC_TIME 336 | |
98 | #define LOPT_LOOP_DETECT 337 | |
99 | #define LOPT_IGNORE_ADDR 338 | |
100 | +#define LOPT_MINCTTL 339 | |
101 | ||
102 | ||
103 | #ifdef HAVE_GETOPT_LONG | |
104 | @@ -256,6 +257,7 @@ static const struct myoption opts[] = | |
105 | { "dhcp-broadcast", 2, 0, LOPT_BROADCAST }, | |
106 | { "neg-ttl", 1, 0, LOPT_NEGTTL }, | |
107 | { "max-ttl", 1, 0, LOPT_MAXTTL }, | |
108 | + { "min-cache-ttl", 1, 0, LOPT_MINCTTL }, | |
109 | { "max-cache-ttl", 1, 0, LOPT_MAXCTTL }, | |
110 | { "dhcp-alternate-port", 2, 0, LOPT_ALTPORT }, | |
111 | { "dhcp-scriptuser", 1, 0, LOPT_SCRIPTUSR }, | |
112 | @@ -371,6 +373,8 @@ static struct { | |
113 | { 'T', ARG_ONE, "<integer>", gettext_noop("Specify time-to-live in seconds for replies from /etc/hosts."), NULL }, | |
114 | { LOPT_NEGTTL, ARG_ONE, "<integer>", gettext_noop("Specify time-to-live in seconds for negative caching."), NULL }, | |
115 | { LOPT_MAXTTL, ARG_ONE, "<integer>", gettext_noop("Specify time-to-live in seconds for maximum TTL to send to clients."), NULL }, | |
116 | + { LOPT_MAXCTTL, ARG_ONE, "<integer>", gettext_noop("Specify time-to-live ceiling for cache."), NULL }, | |
117 | + { LOPT_MINCTTL, ARG_ONE, "<integer>", gettext_noop("Specify time-to-live floor for cache."), NULL }, | |
118 | { 'u', ARG_ONE, "<username>", gettext_noop("Change to this user after startup. (defaults to %s)."), CHUSER }, | |
119 | { 'U', ARG_DUP, "set:<tag>,<class>", gettext_noop("Map DHCP vendor class to tag."), NULL }, | |
120 | { 'v', 0, NULL, gettext_noop("Display dnsmasq version and copyright information."), NULL }, | |
121 | @@ -2457,6 +2461,7 @@ static int one_opt(int option, char *arg, char *errstr, char *gen_err, int comma | |
122 | case 'T': /* --local-ttl */ | |
123 | case LOPT_NEGTTL: /* --neg-ttl */ | |
124 | case LOPT_MAXTTL: /* --max-ttl */ | |
125 | + case LOPT_MINCTTL: /* --min-cache-ttl */ | |
126 | case LOPT_MAXCTTL: /* --max-cache-ttl */ | |
127 | case LOPT_AUTHTTL: /* --auth-ttl */ | |
128 | { | |
129 | @@ -2467,6 +2472,12 @@ static int one_opt(int option, char *arg, char *errstr, char *gen_err, int comma | |
130 | daemon->neg_ttl = (unsigned long)ttl; | |
131 | else if (option == LOPT_MAXTTL) | |
132 | daemon->max_ttl = (unsigned long)ttl; | |
133 | + else if (option == LOPT_MINCTTL) | |
134 | + { | |
135 | + if (ttl > TTL_FLOOR_LIMIT) | |
136 | + ttl = TTL_FLOOR_LIMIT; | |
137 | + daemon->min_cache_ttl = (unsigned long)ttl; | |
138 | + } | |
139 | else if (option == LOPT_MAXCTTL) | |
140 | daemon->max_cache_ttl = (unsigned long)ttl; | |
141 | else if (option == LOPT_AUTHTTL) | |
142 | -- | |
143 | 2.1.0 | |
144 |