protocols: fix keepalive settings for pppd based protocols
[project/luci.git] / protocols / luci-proto-ppp / luasrc / model / cbi / admin_network / proto_pppoe.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
15 local username, password, ac, service
16 local ipv6, defaultroute, metric, peerdns, dns,
17       keepalive_failure, keepalive_interval, demand, mtu
18
19
20 username = section:taboption("general", Value, "username", translate("PAP/CHAP username"))
21
22
23 password = section:taboption("general", Value, "password", translate("PAP/CHAP password"))
24 password.password = true
25
26
27 ac = section:taboption("general", Value, "ac",
28         translate("Access Concentrator"),
29         translate("Leave empty to autodetect"))
30
31 ac.placeholder = translate("auto")
32
33
34 service = section:taboption("general", Value, "service",
35         translate("Service Name"),
36         translate("Leave empty to autodetect"))
37
38 service.placeholder = translate("auto")
39
40
41 if luci.model.network:has_ipv6() then
42
43         ipv6 = section:taboption("advanced", Flag, "ipv6",
44                 translate("Enable IPv6 negotiation on the PPP link"))
45
46         ipv6.default = ipv6.disabled
47
48 end
49
50
51 defaultroute = section:taboption("advanced", Flag, "defaultroute",
52         translate("Use default gateway"),
53         translate("If unchecked, no default route is configured"))
54
55 defaultroute.default = defaultroute.enabled
56
57
58 metric = section:taboption("advanced", Value, "metric",
59         translate("Use gateway metric"))
60
61 metric.placeholder = "0"
62 metric.datatype    = "uinteger"
63 metric:depends("defaultroute", defaultroute.enabled)
64
65
66 peerdns = section:taboption("advanced", Flag, "peerdns",
67         translate("Use DNS servers advertised by peer"),
68         translate("If unchecked, the advertised DNS server addresses are ignored"))
69
70 peerdns.default = peerdns.enabled
71
72
73 dns = section:taboption("advanced", DynamicList, "dns",
74         translate("Use custom DNS servers"))
75
76 dns:depends("peerdns", "")
77 dns.datatype = "ipaddr"
78 dns.cast     = "string"
79
80
81 keepalive_failure = section:taboption("advanced", Value, "_keepalive_failure",
82         translate("LCP echo failure threshold"),
83         translate("Presume peer to be dead after given amount of LCP echo failures, use 0 to ignore failures"))
84
85 function keepalive_failure.cfgvalue(self, section)
86         local v = m:get(section, "keepalive")
87         if v and #v > 0 then
88                 return tonumber(v:match("^(%d+)[ ,]+%d+") or v)
89         end
90 end
91
92 keepalive_failure.placeholder = "0"
93 keepalive_failure.datatype    = "uinteger"
94
95
96 keepalive_interval = section:taboption("advanced", Value, "_keepalive_interval",
97         translate("LCP echo interval"),
98         translate("Send LCP echo requests at the given interval in seconds, only effective in conjunction with failure threshold"))
99
100 function keepalive_interval.cfgvalue(self, section)
101         local v = m:get(section, "keepalive")
102         if v and #v > 0 then
103                 return tonumber(v:match("^%d+[ ,]+(%d+)"))
104         end
105 end
106
107 function keepalive_interval.write(self, section, value)
108         local f = tonumber(keepalive_failure:formvalue(section)) or 0
109         local i = tonumber(value) or 5
110         if i < 1 then i = 1 end
111         if f > 0 then
112                 m:set(section, "keepalive", "%d %d" %{ f, i })
113         else
114                 m:del(section, "keepalive")
115         end
116 end
117
118 keepalive_interval.remove      = keepalive_interval.write
119 keepalive_failure.write        = keepalive_interval.write
120 keepalive_failure.remove       = keepalive_interval.write
121 keepalive_interval.placeholder = "5"
122 keepalive_interval.datatype    = "min(1)"
123
124
125 demand = section:taboption("advanced", Value, "demand",
126         translate("Inactivity timeout"),
127         translate("Close inactive connection after the given amount of seconds, use 0 to persist connection"))
128
129 demand.placeholder = "0"
130 demand.datatype    = "uinteger"
131
132
133 mtu = section:taboption("advanced", Value, "mtu", translate("Override MTU"))
134 mtu.placeholder = "1500"
135 mtu.datatype    = "max(9200)"