Fix nvram size for router with more than 32kB of nvram.
[tomato.git] / release / src / router / www / basic-ipv6.asp
blob525dc42a48ed30935e965cf2190c44dc3770d243
1 <!DOCTYPE HTML PUBLIC '-//W3C//DTD HTML 4.0//EN'>
2 <!--
3 Tomato GUI
4 Copyright (C) 2006-2010 Jonathan Zarate
5 http://www.polarcloud.com/tomato/
7 For use with Tomato Firmware only.
8 No part of this file may be used without permission.
9 -->
10 <html>
11 <head>
12 <meta http-equiv='content-type' content='text/html;charset=utf-8'>
13 <meta name='robots' content='noindex,nofollow'>
14 <title>[<% ident(); %>] Basic: IPv6</title>
15 <link rel='stylesheet' type='text/css' href='tomato.css'>
16 <link rel='stylesheet' type='text/css' href='color.css'>
17 <script type='text/javascript' src='tomato.js'></script>
19 <!-- / / / -->
21 <script type='text/javascript' src='debug.js'></script>
23 <script type='text/javascript'>
24 // <% nvram("ipv6_prefix,ipv6_prefix_length,ipv6_radvd,ipv6_accept_ra,ipv6_rtr_addr,ipv6_service,ipv6_dns,ipv6_tun_addr,ipv6_tun_addrlen,ipv6_ifname,ipv6_tun_v4end,ipv6_relay,ipv6_tun_mtu,ipv6_tun_ttl"); %>
26 nvram.ipv6_accept_ra = fixInt(nvram.ipv6_accept_ra, 0, 3, 0);
28 function verifyFields(focused, quiet)
30 var i;
31 var ok = 1;
32 var a, b, c;
34 // --- visibility ---
36 var vis = {
37 _ipv6_service: 1,
38 _f_ipv6_prefix: 1,
39 _f_ipv6_prefix_length: 1,
40 _f_ipv6_rtr_addr_auto: 1,
41 _f_ipv6_rtr_addr: 1,
42 _f_ipv6_dns_1: 1,
43 _f_ipv6_dns_2: 1,
44 _f_ipv6_dns_3: 1,
45 _f_ipv6_radvd: 1,
46 _f_ipv6_accept_ra_wan: 1,
47 _f_ipv6_accept_ra_lan: 1,
48 _ipv6_tun_v4end: 1,
49 _ipv6_relay: 1,
50 _ipv6_ifname: 1,
51 _ipv6_tun_addr: 1,
52 _ipv6_tun_addrlen: 1,
53 _ipv6_tun_ttl: 1,
54 _ipv6_tun_mtu: 1
57 c = E('_ipv6_service').value;
58 switch(c) {
59 case '':
60 vis._ipv6_ifname = 0;
61 vis._f_ipv6_rtr_addr_auto = 0;
62 vis._f_ipv6_rtr_addr = 0;
63 vis._f_ipv6_dns_1 = 0;
64 vis._f_ipv6_dns_2 = 0;
65 vis._f_ipv6_dns_3 = 0;
66 vis._f_ipv6_radvd = 0;
67 vis._f_ipv6_accept_ra_wan = 0;
68 vis._f_ipv6_accept_ra_lan = 0;
69 // fall through
70 case 'other':
71 vis._f_ipv6_prefix = 0;
72 vis._f_ipv6_prefix_length = 0;
73 vis._ipv6_tun_v4end = 0;
74 vis._ipv6_relay = 0;
75 vis._ipv6_tun_addr = 0;
76 vis._ipv6_tun_addrlen = 0;
77 vis._ipv6_tun_ttl = 0;
78 vis._ipv6_tun_mtu = 0;
79 if (c == 'other') {
80 E('_f_ipv6_rtr_addr_auto').value = 1;
81 vis._f_ipv6_rtr_addr_auto = 2;
83 break;
84 case 'native-pd':
85 vis._f_ipv6_prefix = 0;
86 vis._f_ipv6_rtr_addr_auto = 0;
87 vis._f_ipv6_rtr_addr = 0;
88 // fall through
89 case 'native':
90 vis._ipv6_ifname = 0;
91 vis._ipv6_tun_v4end = 0;
92 vis._ipv6_relay = 0;
93 vis._ipv6_tun_addr = 0;
94 vis._ipv6_tun_addrlen = 0;
95 vis._ipv6_tun_ttl = 0;
96 vis._ipv6_tun_mtu = 0;
97 break;
98 case '6to4':
99 vis._ipv6_ifname = 0;
100 vis._f_ipv6_prefix = 0;
101 vis._f_ipv6_rtr_addr_auto = 0;
102 vis._f_ipv6_rtr_addr = 0;
103 vis._ipv6_tun_v4end = 0;
104 vis._ipv6_tun_addr = 0;
105 vis._ipv6_tun_addrlen = 0;
106 vis._f_ipv6_accept_ra_wan = 0;
107 vis._f_ipv6_accept_ra_lan = 0;
108 break;
109 case 'sit':
110 vis._ipv6_ifname = 0;
111 vis._ipv6_relay = 0;
112 vis._f_ipv6_accept_ra_wan = 0;
113 vis._f_ipv6_accept_ra_lan = 0;
114 break;
117 if (vis._f_ipv6_rtr_addr_auto && E('_f_ipv6_rtr_addr_auto').value == 0) {
118 vis._f_ipv6_rtr_addr = 2;
121 if (E('_f_ipv6_radvd').checked) {
122 if (vis._f_ipv6_accept_ra_lan) vis._f_ipv6_accept_ra_lan = 2;
123 E('_f_ipv6_accept_ra_lan').checked = false;
126 for (a in vis) {
127 b = E(a);
128 c = vis[a];
129 b.disabled = (c != 1);
130 PR(b).style.display = c ? '' : 'none';
133 // --- verify ---
135 if (vis._ipv6_ifname == 1) {
136 if (E('_ipv6_service').value != 'other') {
137 if (!v_length('_ipv6_ifname', quiet || !ok, 2)) ok = 0;
139 else ferror.clear('_ipv6_ifname');
142 /* REMOVE-BEGIN
143 // Length
144 a = [['_ipv6_ifname', 2]];
145 for (i = a.length - 1; i >= 0; --i) {
146 v = a[i];
147 if ((vis[v[0]]) && (!v_length(v[0], quiet || !ok, v[1]))) ok = 0;
149 REMOVE-END */
151 // IP address
152 a = ['_ipv6_tun_v4end'];
153 for (i = a.length - 1; i >= 0; --i)
154 if ((vis[a[i]]) && (!v_ip(a[i], quiet || !ok))) ok = 0;
156 // range
157 a = [['_f_ipv6_prefix_length', 3, 64], ['_ipv6_tun_addrlen', 3, 127], ['_ipv6_tun_ttl', 0, 255], ['_ipv6_relay', 1, 254]];
158 for (i = a.length - 1; i >= 0; --i) {
159 b = a[i];
160 if ((vis[b[0]]) && (!v_range(b[0], quiet || !ok, b[1], b[2]))) ok = 0;
163 // mtu
164 b = '_ipv6_tun_mtu';
165 if (vis[b]) {
166 if ((!v_range(b, 1, 0, 0)) && (!v_range(b, quiet || !ok, 1280, 1480))) ok = 0;
167 else ferror.clear(E(b));
170 // IPv6 prefix
171 b = '_f_ipv6_prefix';
172 c = vis._f_ipv6_accept_ra_wan && (E('_f_ipv6_accept_ra_wan').checked || E('_f_ipv6_accept_ra_lan').checked);
173 if (vis[b] && (E(b).value.length > 0 || (!c))) {
174 if (!v_ipv6_addr(b, quiet || !ok)) ok = 0;
176 else ferror.clear(b);
178 // IPv6 address
179 a = ['_ipv6_tun_addr'];
180 for (i = a.length - 1; i >= 0; --i)
181 if ((vis[a[i]]) && (!v_ipv6_addr(a[i], quiet || !ok))) ok = 0;
183 if (vis._f_ipv6_rtr_addr == 2) {
184 b = E('_f_ipv6_prefix');
185 ip = (b.value.length > 0) ? ZeroIPv6PrefixBits(b.value, E('_f_ipv6_prefix_length').value) : '';
186 b.value = CompressIPv6Address(ip);
187 E('_f_ipv6_rtr_addr').value = (ip.length > 0) ? CompressIPv6Address(ip + '1') : '';
190 // optional IPv6 address
191 a = ['_f_ipv6_rtr_addr', '_f_ipv6_dns_1', '_f_ipv6_dns_2', '_f_ipv6_dns_3'];
192 for (i = a.length - 1; i >= 0; --i)
193 if ((vis[a[i]]==1) && (E(a[i]).value.length > 0) && (!v_ipv6_addr(a[i], quiet || !ok))) ok = 0;
195 return ok;
198 function earlyInit()
200 verifyFields(null, 1);
203 function joinIPv6Addr(a) {
204 var r, i, s;
206 r = [];
207 for (i = 0; i < a.length; ++i) {
208 s = CompressIPv6Address(a[i]);
209 if ((s) && (s != '')) r.push(s);
211 return r.join(' ');
214 function save()
216 var a, b, c;
217 var i;
219 if (!verifyFields(null, false)) return;
221 var fom = E('_fom');
223 fom.ipv6_dns.value = joinIPv6Addr([fom.f_ipv6_dns_1.value, fom.f_ipv6_dns_2.value, fom.f_ipv6_dns_3.value]);
224 fom.ipv6_radvd.value = fom.f_ipv6_radvd.checked ? 1 : 0;
226 fom.ipv6_accept_ra.value = 0;
227 if (fom.f_ipv6_accept_ra_wan.checked && !fom.f_ipv6_accept_ra_wan.disabled)
228 fom.ipv6_accept_ra.value |= 1;
229 if (fom.f_ipv6_accept_ra_lan.checked && !fom.f_ipv6_accept_ra_lan.disabled)
230 fom.ipv6_accept_ra.value |= 2;
232 fom.ipv6_prefix_length.value = fom.f_ipv6_prefix_length.value;
233 fom.ipv6_prefix.value = fom.f_ipv6_prefix.value;
235 switch(E('_ipv6_service').value) {
236 case 'other':
237 fom.ipv6_prefix_length.value = 64;
238 fom.ipv6_prefix.value = '';
239 fom.ipv6_rtr_addr.value = fom.f_ipv6_rtr_addr.value;
240 break;
241 case '6to4':
242 case 'native-pd':
243 fom.ipv6_prefix.value = '';
244 fom.ipv6_rtr_addr.value = '';
245 break;
246 default:
247 fom.ipv6_rtr_addr.disabled = fom.f_ipv6_rtr_addr_auto.disabled;
248 if (fom.f_ipv6_rtr_addr_auto.value == 1)
249 fom.ipv6_rtr_addr.value = fom.f_ipv6_rtr_addr.value;
250 else
251 fom.ipv6_rtr_addr.value = '';
252 break;
255 form.submit(fom, 1);
258 </script>
260 </head>
261 <body>
262 <form id='_fom' method='post' action='tomato.cgi'>
263 <table id='container' cellspacing=0>
264 <tr><td colspan=2 id='header'>
265 <div class='title'>Tomato</div>
266 <div class='version'>Version <% version(); %></div>
267 </td></tr>
268 <tr id='body'><td id='navi'><script type='text/javascript'>navi()</script></td>
269 <td id='content'>
270 <div id='ident'><% ident(); %></div>
272 <!-- / / / -->
274 <input type='hidden' name='_nextpage' value='basic-ipv6.asp'>
275 <input type='hidden' name='_nextwait' value='10'>
276 <input type='hidden' name='_service' value='*'>
278 <input type='hidden' name='ipv6_radvd'>
279 <input type='hidden' name='ipv6_dns'>
280 <input type='hidden' name='ipv6_prefix'>
281 <input type='hidden' name='ipv6_prefix_length'>
282 <input type='hidden' name='ipv6_rtr_addr'>
283 <input type='hidden' name='ipv6_accept_ra'>
285 <div class='section-title'>IPv6 Configuration</div>
286 <div class='section'>
287 <script type='text/javascript'>
288 dns = nvram.ipv6_dns.split(/\s+/);
290 createFieldTable('', [
291 { title: 'IPv6 Service Type', name: 'ipv6_service', type: 'select',
292 options: [['', 'Disabled'],['native','Native IPv6 from ISP'],['native-pd','DHCPv6 with Prefix Delegation'],['6to4','6to4 Anycast Relay'],['sit','6in4 Static Tunnel'],['other','Other (Manual Configuration)']],
293 value: nvram.ipv6_service },
294 { title: 'IPv6 WAN Interface', name: 'ipv6_ifname', type: 'text', maxlen: 8, size: 10, value: nvram.ipv6_ifname },
295 null,
296 { title: 'Assigned / Routed Prefix', name: 'f_ipv6_prefix', type: 'text', maxlen: 46, size: 48, value: nvram.ipv6_prefix },
297 { title: 'Prefix Length', name: 'f_ipv6_prefix_length', type: 'text', maxlen: 3, size: 5, value: nvram.ipv6_prefix_length },
298 { title: 'Router IPv6 Address', multi: [
299 { name: 'f_ipv6_rtr_addr_auto', type: 'select', options: [['0', 'Default'],['1','Manual']], value: (nvram.ipv6_rtr_addr == '' ? '0' : '1') },
300 { name: 'f_ipv6_rtr_addr', type: 'text', maxlen: 46, size: 48, value: nvram.ipv6_rtr_addr }
301 ] },
302 { title: 'Static DNS', name: 'f_ipv6_dns_1', type: 'text', maxlen: 46, size: 48, value: dns[0] || '' },
303 { title: '', name: 'f_ipv6_dns_2', type: 'text', maxlen: 46, size: 48, value: dns[1] || '' },
304 { title: '', name: 'f_ipv6_dns_3', type: 'text', maxlen: 46, size: 48, value: dns[2] || '' },
305 { title: 'Enable Router Advertisements', name: 'f_ipv6_radvd', type: 'checkbox', value: nvram.ipv6_radvd == '1' },
306 { title: 'Accept RA from', multi: [
307 { suffix: '&nbsp; WAN &nbsp;&nbsp;&nbsp;', name: 'f_ipv6_accept_ra_wan', type: 'checkbox', value: (nvram.ipv6_accept_ra & 1) },
308 { suffix: '&nbsp; LAN &nbsp;', name: 'f_ipv6_accept_ra_lan', type: 'checkbox', value: (nvram.ipv6_accept_ra & 2) }
309 ] },
310 null,
311 { title: 'Tunnel Remote Endpoint (IPv4 Address)', name: 'ipv6_tun_v4end', type: 'text', maxlen: 15, size: 17, value: nvram.ipv6_tun_v4end },
312 { title: 'Relay Anycast Address', name: 'ipv6_relay', type: 'text', maxlen: 3, size: 5, prefix: '192.88.99.&nbsp&nbsp', value: nvram.ipv6_relay },
313 { title: 'Tunnel Client IPv6 Address', multi: [
314 { name: 'ipv6_tun_addr', type: 'text', maxlen: 46, size: 48, value: nvram.ipv6_tun_addr, suffix: ' / ' },
315 { name: 'ipv6_tun_addrlen', type: 'text', maxlen: 3, size: 5, value: nvram.ipv6_tun_addrlen }
316 ] },
317 { title: 'Tunnel MTU', name: 'ipv6_tun_mtu', type: 'text', maxlen: 4, size: 8, value: nvram.ipv6_tun_mtu, suffix: ' <small>(0 for default)</small>' },
318 { title: 'Tunnel TTL', name: 'ipv6_tun_ttl', type: 'text', maxlen: 3, size: 8, value: nvram.ipv6_tun_ttl }
320 </script>
321 </div>
323 <br>
324 <script type='text/javascript'>show_notice1('<% notice("ip6tables"); %>');</script>
326 <!-- / / / -->
328 </td></tr>
329 <tr><td id='footer' colspan=2>
330 <span id='footer-msg'></span>
331 <input type='button' value='Save' id='save-button' onclick='save()'>
332 <input type='button' value='Cancel' id='cancel-button' onclick='reloadPage();'>
333 </td></tr>
334 </table>
335 </form>
336 <script type='text/javascript'>earlyInit()</script>
337 <div style='height:100px'></div>
338 </body>
339 </html>