806d5cd31504726e0abd4e5c2f03ca09732d981d
[project/luci.git] / protocols / core / luasrc / model / cbi / admin_network / proto_dhcp.lua
1 --[[
2 LuCI - Lua Configuration Interface
3
4 Copyright 2011 Jo-Philipp Wich <xm@subsignal.org>
5
6 Licensed under the Apache License, Version 2.0 (the "License");
7 you may not use this file except in compliance with the License.
8 You may obtain a copy of the License at
9
10 http://www.apache.org/licenses/LICENSE-2.0
11 ]]--
12
13 local map, section, net = ...
14 local ifc = net:get_interface()
15
16 local hostname, accept_ra, send_rs
17 local bcast, no_gw, no_dns, dns, metric, clientid, vendorclass
18
19
20 hostname = section:taboption("general", Value, "hostname",
21 translate("Hostname to send when requesting DHCP"))
22
23 hostname.placeholder = luci.sys.hostname()
24 hostname.datatype = "hostname"
25
26
27 if luci.model.network:has_ipv6() then
28
29 accept_ra = s:taboption("general", Flag, "accept_ra", translate("Accept router advertisements"))
30 accept_ra.default = accept_ra.enabled
31
32
33 send_rs = s:taboption("general", Flag, "send_rs", translate("Send router solicitations"))
34 send_rs.default = send_rs.disabled
35 send_rs:depends("accept_ra", "")
36
37 end
38
39 bcast = section:taboption("advanced", Flag, "broadcast",
40 translate("Use broadcast flag"),
41 translate("Required for certain ISPs, e.g. Charter with DOCSIS 3"))
42
43 bcast.default = bcast.disabled
44
45
46 no_gw = section:taboption("advanced", Flag, "gateway",
47 translate("Use default gateway"),
48 translate("If unchecked, no default route is configured"))
49
50 no_gw.default = no_gw.enabled
51
52 function no_gw.cfgvalue(...)
53 return Flag.cfgvalue(...) == "0.0.0.0" and "0" or "1"
54 end
55
56 function no_gw.write(self, section, value)
57 if value == "1" then
58 m:set(section, "gateway", nil)
59 else
60 m:set(section, "gateway", "0.0.0.0")
61 end
62 end
63
64
65 no_dns = section:taboption("advanced", Flag, "_no_dns",
66 translate("Use DNS servers advertised by peer"),
67 translate("If unchecked, the advertised DNS server addresses are ignored"))
68
69 no_dns.default = no_dns.enabled
70
71 function no_dns.cfgvalue(self, section)
72 local addr
73 for addr in luci.util.imatch(m:get(section, "dns")) do
74 return self.disabled
75 end
76 return self.enabled
77 end
78
79 function no_dns.remove(self, section)
80 return m:del(section, "dns")
81 end
82
83 function no_dns.write() end
84
85
86 dns = section:taboption("advanced", DynamicList, "dns",
87 translate("Use custom DNS servers"))
88
89 dns:depends("_no_dns", "")
90 dns.datatype = "ipaddr"
91
92
93 metric = section:taboption("advanced", Value, "metric",
94 translate("Use gateway metric"))
95
96 metric.placeholder = "0"
97 metric.datatype = "uinteger"
98 metric:depends("gateway", "1")
99
100
101 clientid = section:taboption("advanced", Value, "clientid",
102 translate("Client ID to send when requesting DHCP"))
103
104
105 vendorclass = section:taboption("advanced", Value, "vendorclass",
106 translate("Vendor Class to send when requesting DHCP"))
107
108
109 macaddr = section:taboption("advanced", Value, "macaddr", translate("Override MAC address"))
110 macaddr.placeholder = ifc and ifc:mac() or "00:00:00:00:00:00"
111 macaddr.datatype = "macaddr"
112
113
114 mtu = section:taboption("advanced", Value, "mtu", translate("Override MTU"))
115 mtu.placeholder = "1500"
116 mtu.datatype = "max(1500)"