Merge pull request #1742 from fantom-x/dhcp_cachesize_max
[project/luci.git] / modules / luci-mod-admin-full / luasrc / model / cbi / admin_network / dhcp.lua
1 -- Copyright 2008 Steven Barth <steven@midlink.org>
2 -- Licensed to the public under the Apache License 2.0.
3
4 local ipc = require "luci.ip"
5 local sys = require "luci.sys"
6 local o
7 require "luci.util"
8
9 m = Map("dhcp", translate("DHCP and DNS"),
10         translate("Dnsmasq is a combined <abbr title=\"Dynamic Host Configuration Protocol" ..
11                 "\">DHCP</abbr>-Server and <abbr title=\"Domain Name System\">DNS</abbr>-" ..
12                 "Forwarder for <abbr title=\"Network Address Translation\">NAT</abbr> " ..
13                 "firewalls"))
14
15 s = m:section(TypedSection, "dnsmasq", translate("Server Settings"))
16 s.anonymous = true
17 s.addremove = false
18
19 s:tab("general", translate("General Settings"))
20 s:tab("files", translate("Resolv and Hosts Files"))
21 s:tab("tftp", translate("TFTP Settings"))
22 s:tab("advanced", translate("Advanced Settings"))
23
24 s:taboption("general", Flag, "domainneeded",
25         translate("Domain required"),
26         translate("Don't forward <abbr title=\"Domain Name System\">DNS</abbr>-Requests without " ..
27                 "<abbr title=\"Domain Name System\">DNS</abbr>-Name"))
28
29 s:taboption("general", Flag, "authoritative",
30         translate("Authoritative"),
31         translate("This is the only <abbr title=\"Dynamic Host Configuration Protocol\">DHCP</" ..
32                 "abbr> in the local network"))
33
34
35 s:taboption("files", Flag, "readethers",
36         translate("Use <code>/etc/ethers</code>"),
37         translate("Read <code>/etc/ethers</code> to configure the <abbr title=\"Dynamic Host " ..
38                 "Configuration Protocol\">DHCP</abbr>-Server"))
39
40 s:taboption("files", Value, "leasefile",
41         translate("Leasefile"),
42         translate("file where given <abbr title=\"Dynamic Host Configuration Protocol\">DHCP</" ..
43                 "abbr>-leases will be stored"))
44
45 s:taboption("files", Flag, "noresolv",
46         translate("Ignore resolve file")).optional = true
47
48 rf = s:taboption("files", Value, "resolvfile",
49         translate("Resolve file"),
50         translate("local <abbr title=\"Domain Name System\">DNS</abbr> file"))
51
52 rf:depends("noresolv", "")
53 rf.optional = true
54
55
56 s:taboption("files", Flag, "nohosts",
57         translate("Ignore <code>/etc/hosts</code>")).optional = true
58
59 s:taboption("files", DynamicList, "addnhosts",
60         translate("Additional Hosts files")).optional = true
61
62 qu = s:taboption("advanced", Flag, "quietdhcp",
63         translate("Suppress logging"),
64         translate("Suppress logging of the routine operation of these protocols"))
65 qu.optional = true
66
67 se = s:taboption("advanced", Flag, "sequential_ip",
68         translate("Allocate IP sequentially"),
69         translate("Allocate IP addresses sequentially, starting from the lowest available address"))
70 se.optional = true
71
72 bp = s:taboption("advanced", Flag, "boguspriv",
73         translate("Filter private"),
74         translate("Do not forward reverse lookups for local networks"))
75 bp.default = bp.enabled
76
77 s:taboption("advanced", Flag, "filterwin2k",
78         translate("Filter useless"),
79         translate("Do not forward requests that cannot be answered by public name servers"))
80
81
82 s:taboption("advanced", Flag, "localise_queries",
83         translate("Localise queries"),
84         translate("Localise hostname depending on the requesting subnet if multiple IPs are available"))
85
86 local have_dnssec_support = luci.util.checklib("/usr/sbin/dnsmasq", "libhogweed.so")
87
88 if have_dnssec_support then
89         o = s:taboption("advanced", Flag, "dnssec",
90                 translate("DNSSEC"))
91         o.optional = true
92
93         o = s:taboption("advanced", Flag, "dnsseccheckunsigned",
94                 translate("DNSSEC check unsigned"),
95                 translate("Requires upstream supports DNSSEC; verify unsigned domain responses really come from unsigned domains"))
96         o.optional = true
97 end
98
99 s:taboption("general", Value, "local",
100         translate("Local server"),
101         translate("Local domain specification. Names matching this domain are never forwarded and are resolved from DHCP or hosts files only"))
102
103 s:taboption("general", Value, "domain",
104         translate("Local domain"),
105         translate("Local domain suffix appended to DHCP names and hosts file entries"))
106
107 s:taboption("advanced", Flag, "expandhosts",
108         translate("Expand hosts"),
109         translate("Add local domain suffix to names served from hosts files"))
110
111 s:taboption("advanced", Flag, "nonegcache",
112         translate("No negative cache"),
113         translate("Do not cache negative replies, e.g. for not existing domains"))
114
115 s:taboption("advanced", Value, "serversfile",
116         translate("Additional servers file"),
117         translate("This file may contain lines like 'server=/domain/1.2.3.4' or 'server=1.2.3.4' for"..
118                 "domain-specific or full upstream <abbr title=\"Domain Name System\">DNS</abbr> servers."))
119
120 s:taboption("advanced", Flag, "strictorder",
121         translate("Strict order"),
122         translate("<abbr title=\"Domain Name System\">DNS</abbr> servers will be queried in the " ..
123                 "order of the resolvfile")).optional = true
124
125
126 bn = s:taboption("advanced", DynamicList, "bogusnxdomain", translate("Bogus NX Domain Override"),
127         translate("List of hosts that supply bogus NX domain results"))
128
129 bn.optional = true
130 bn.placeholder = "67.215.65.132"
131
132
133 s:taboption("general", Flag, "logqueries",
134         translate("Log queries"),
135         translate("Write received DNS requests to syslog")).optional = true
136
137 df = s:taboption("general", DynamicList, "server", translate("DNS forwardings"),
138         translate("List of <abbr title=\"Domain Name System\">DNS</abbr> " ..
139                         "servers to forward requests to"))
140
141 df.optional = true
142 df.placeholder = "/example.org/10.1.2.3"
143
144
145 rp = s:taboption("general", Flag, "rebind_protection",
146         translate("Rebind protection"),
147         translate("Discard upstream RFC1918 responses"))
148
149 rp.rmempty = false
150
151
152 rl = s:taboption("general", Flag, "rebind_localhost",
153         translate("Allow localhost"),
154         translate("Allow upstream responses in the 127.0.0.0/8 range, e.g. for RBL services"))
155
156 rl:depends("rebind_protection", "1")
157
158
159 rd = s:taboption("general", DynamicList, "rebind_domain",
160         translate("Domain whitelist"),
161         translate("List of domains to allow RFC1918 responses for"))
162 rd.optional = true
163
164 rd:depends("rebind_protection", "1")
165 rd.datatype = "host(1)"
166 rd.placeholder = "ihost.netflix.com"
167
168
169 pt = s:taboption("advanced", Value, "port",
170         translate("<abbr title=\"Domain Name System\">DNS</abbr> server port"),
171         translate("Listening port for inbound DNS queries"))
172
173 pt.optional = true
174 pt.datatype = "port"
175 pt.placeholder = 53
176
177
178 qp = s:taboption("advanced", Value, "queryport",
179         translate("<abbr title=\"Domain Name System\">DNS</abbr> query port"),
180         translate("Fixed source port for outbound DNS queries"))
181
182 qp.optional = true
183 qp.datatype = "port"
184 qp.placeholder = translate("any")
185
186
187 lm = s:taboption("advanced", Value, "dhcpleasemax",
188         translate("<abbr title=\"maximal\">Max.</abbr> <abbr title=\"Dynamic Host Configuration " ..
189                 "Protocol\">DHCP</abbr> leases"),
190         translate("Maximum allowed number of active DHCP leases"))
191
192 lm.optional = true
193 lm.datatype = "uinteger"
194 lm.placeholder = translate("unlimited")
195
196
197 em = s:taboption("advanced", Value, "ednspacket_max",
198         translate("<abbr title=\"maximal\">Max.</abbr> <abbr title=\"Extension Mechanisms for " ..
199                 "Domain Name System\">EDNS0</abbr> packet size"),
200         translate("Maximum allowed size of EDNS.0 UDP packets"))
201
202 em.optional = true
203 em.datatype = "uinteger"
204 em.placeholder = 1280
205
206
207 cq = s:taboption("advanced", Value, "dnsforwardmax",
208         translate("<abbr title=\"maximal\">Max.</abbr> concurrent queries"),
209         translate("Maximum allowed number of concurrent DNS queries"))
210
211 cq.optional = true
212 cq.datatype = "uinteger"
213 cq.placeholder = 150
214
215 cs = s:taboption("advanced", Value, "cachesize",
216         translate("Size of DNS query cache"),
217         translate("Number of cached DNS entries (max is 10000, 0 is no caching)"))
218 cs.optional = true
219 cs.datatype = "range(0,10000)"
220 cs.placeholder = 150
221
222 s:taboption("tftp", Flag, "enable_tftp",
223         translate("Enable TFTP server")).optional = true
224
225 tr = s:taboption("tftp", Value, "tftp_root",
226         translate("TFTP server root"),
227         translate("Root directory for files served via TFTP"))
228
229 tr.optional = true
230 tr:depends("enable_tftp", "1")
231 tr.placeholder = "/"
232
233
234 db = s:taboption("tftp", Value, "dhcp_boot",
235         translate("Network boot image"),
236         translate("Filename of the boot image advertised to clients"))
237
238 db.optional = true
239 db:depends("enable_tftp", "1")
240 db.placeholder = "pxelinux.0"
241
242 o = s:taboption("general", Flag, "localservice",
243         translate("Local Service Only"),
244         translate("Limit DNS service to subnets interfaces on which we are serving DNS."))
245 o.optional = false
246 o.rmempty = false
247
248 o = s:taboption("general", Flag, "nonwildcard",
249         translate("Non-wildcard"),
250         translate("Bind only to specific interfaces rather than wildcard address."))
251 o.optional = false
252 o.rmempty = false
253
254 o = s:taboption("general", DynamicList, "interface",
255         translate("Listen Interfaces"),
256         translate("Limit listening to these interfaces, and loopback."))
257 o.optional = true
258 o:depends("nonwildcard", true)
259
260 o = s:taboption("general", DynamicList, "notinterface",
261         translate("Exclude interfaces"),
262         translate("Prevent listening on these interfaces."))
263 o.optional = true
264 o:depends("nonwildcard", true)
265
266 m:section(SimpleSection).template = "admin_network/lease_status"
267
268 s = m:section(TypedSection, "host", translate("Static Leases"),
269         translate("Static leases are used to assign fixed IP addresses and symbolic hostnames to " ..
270                 "DHCP clients. They are also required for non-dynamic interface configurations where " ..
271                 "only hosts with a corresponding lease are served.") .. "<br />" ..
272         translate("Use the <em>Add</em> Button to add a new lease entry. The <em>MAC-Address</em> " ..
273                 "indentifies the host, the <em>IPv4-Address</em> specifies the fixed address to " ..
274                 "use, and the <em>Hostname</em> is assigned as a symbolic name to the requesting host. " ..
275                 "The optional <em>Lease time</em> can be used to set non-standard host-specific " ..
276                 "lease time, e.g. 12h, 3d or infinite."))
277
278 s.addremove = true
279 s.anonymous = true
280 s.template = "cbi/tblsection"
281
282 name = s:option(Value, "name", translate("Hostname"))
283 name.datatype = "hostname('strict')"
284 name.rmempty  = true
285
286 function name.write(self, section, value)
287         Value.write(self, section, value)
288         m:set(section, "dns", "1")
289 end
290
291 function name.remove(self, section)
292         Value.remove(self, section)
293         m:del(section, "dns")
294 end
295
296 mac = s:option(Value, "mac", translate("<abbr title=\"Media Access Control\">MAC</abbr>-Address"))
297 mac.datatype = "list(macaddr)"
298 mac.rmempty  = true
299
300 ip = s:option(Value, "ip", translate("<abbr title=\"Internet Protocol Version 4\">IPv4</abbr>-Address"))
301 ip.datatype = "or(ip4addr,'ignore')"
302
303 time = s:option(Value, "leasetime", translate("Lease time"))
304 time.rmempty = true
305
306 duid = s:option(Value, "duid", translate("<abbr title=\"The DHCP Unique Identifier\">DUID</abbr>"))
307 duid.datatype = "and(rangelength(20,36),hexstring)"
308 fp = io.open("/var/hosts/odhcpd")
309 if fp then
310         for line in fp:lines() do
311                 local net_val, duid_val = string.match(line, "# (%S+)%s+(%S+)")
312                 if duid_val then
313                         duid:value(duid_val, duid_val)
314                 end
315         end
316         fp:close()
317 end
318
319 hostid = s:option(Value, "hostid", translate("<abbr title=\"Internet Protocol Version 6\">IPv6</abbr>-Suffix (hex)"))
320
321 sys.net.host_hints(function(m, v4, v6, name)
322         if m and v4 then
323                 ip:value(v4)
324                 mac:value(m, "%s (%s)" %{ m, name or v4 })
325         end
326 end)
327
328 function ip.validate(self, value, section)
329         local m = mac:formvalue(section) or ""
330         local n = name:formvalue(section) or ""
331         if value and #n == 0 and #m == 0 then
332                 return nil, translate("One of hostname or mac address must be specified!")
333         end
334         return Value.validate(self, value, section)
335 end
336
337
338 return m