IPv6 updates
[project/luci.git] / protocols / luci-proto-ppp / luasrc / model / cbi / admin_network / proto_ppp.lua
1 -- Copyright 2011 Jo-Philipp Wich <jow@openwrt.org>
2 -- Licensed to the public under the Apache License 2.0.
3
4 local map, section, net = ...
5
6 local device, username, password
7 local ipv6, defaultroute, metric, peerdns, dns,
8           keepalive_failure, keepalive_interval, demand, mtu
9
10
11 device = section:taboption("general", Value, "device", translate("Modem device"))
12 device.rmempty = false
13
14 local device_suggestions = nixio.fs.glob("/dev/tty*S*")
15         or nixio.fs.glob("/dev/tts/*")
16
17 if device_suggestions then
18         local node
19         for node in device_suggestions do
20                 device:value(node)
21         end
22 end
23
24
25 username = section:taboption("general", Value, "username", translate("PAP/CHAP username"))
26
27
28 password = section:taboption("general", Value, "password", translate("PAP/CHAP password"))
29 password.password = true
30
31
32 if luci.model.network:has_ipv6() then
33
34         ipv6 = section:taboption("advanced", ListValue, "ipv6")
35         ipv6:value("auto", translate("Automatic"))
36         ipv6:value("0", translate("Disabled"))
37         ipv6:value("1", translate("Manual"))
38         ipv6.default = "auto"
39
40 end
41
42
43 defaultroute = section:taboption("advanced", Flag, "defaultroute",
44         translate("Use default gateway"),
45         translate("If unchecked, no default route is configured"))
46
47 defaultroute.default = defaultroute.enabled
48
49
50 metric = section:taboption("advanced", Value, "metric",
51         translate("Use gateway metric"))
52
53 metric.placeholder = "0"
54 metric.datatype    = "uinteger"
55 metric:depends("defaultroute", defaultroute.enabled)
56
57
58 peerdns = section:taboption("advanced", Flag, "peerdns",
59         translate("Use DNS servers advertised by peer"),
60         translate("If unchecked, the advertised DNS server addresses are ignored"))
61
62 peerdns.default = peerdns.enabled
63
64
65 dns = section:taboption("advanced", DynamicList, "dns",
66         translate("Use custom DNS servers"))
67
68 dns:depends("peerdns", "")
69 dns.datatype = "ipaddr"
70 dns.cast     = "string"
71
72
73 keepalive_failure = section:taboption("advanced", Value, "_keepalive_failure",
74         translate("LCP echo failure threshold"),
75         translate("Presume peer to be dead after given amount of LCP echo failures, use 0 to ignore failures"))
76
77 function keepalive_failure.cfgvalue(self, section)
78         local v = m:get(section, "keepalive")
79         if v and #v > 0 then
80                 return tonumber(v:match("^(%d+)[ ,]+%d+") or v)
81         end
82 end
83
84 keepalive_failure.placeholder = "0"
85 keepalive_failure.datatype    = "uinteger"
86
87
88 keepalive_interval = section:taboption("advanced", Value, "_keepalive_interval",
89         translate("LCP echo interval"),
90         translate("Send LCP echo requests at the given interval in seconds, only effective in conjunction with failure threshold"))
91
92 function keepalive_interval.cfgvalue(self, section)
93         local v = m:get(section, "keepalive")
94         if v and #v > 0 then
95                 return tonumber(v:match("^%d+[ ,]+(%d+)"))
96         end
97 end
98
99 function keepalive_interval.write(self, section, value)
100         local f = tonumber(keepalive_failure:formvalue(section)) or 0
101         local i = tonumber(value) or 5
102         if i < 1 then i = 1 end
103         if f > 0 then
104                 m:set(section, "keepalive", "%d %d" %{ f, i })
105         else
106                 m:del(section, "keepalive")
107         end
108 end
109
110 keepalive_interval.remove      = keepalive_interval.write
111 keepalive_failure.write        = keepalive_interval.write
112 keepalive_failure.remove       = keepalive_interval.write
113 keepalive_interval.placeholder = "5"
114 keepalive_interval.datatype    = "min(1)"
115
116
117 demand = section:taboption("advanced", Value, "demand",
118         translate("Inactivity timeout"),
119         translate("Close inactive connection after the given amount of seconds, use 0 to persist connection"))
120
121 demand.placeholder = "0"
122 demand.datatype    = "uinteger"
123
124
125 mtu = section:taboption("advanced", Value, "mtu", translate("Override MTU"))
126 mtu.placeholder = "1500"
127 mtu.datatype    = "max(9200)"