New routers supported
[tomato.git] / release / src / router / www / advanced-vlan.asp
blob3588fb0aaaa3ee3eb3a4af1b4d25fe98debf2f5f
1 <!DOCTYPE HTML PUBLIC '-//W3C//DTD HTML 4.0//EN'>
2 <!--
3 Tomato VLAN GUI
4 Copyright (C) 2011-2012 Augusto Bott
5 http://code.google.com/p/tomato-sdhc-vlan/
7 Tomato GUI
8 Copyright (C) 2006-2007 Jonathan Zarate
9 http://www.polarcloud.com/tomato/
11 Tomato VLAN update and bug correction
12 Copyright (C) 2011-2012 Vicente Soriano
13 http://tomatoraf.com
15 For use with Tomato Firmware only.
16 No part of this file may be used without permission.
17 -->
18 <html>
19 <head>
20 <meta http-equiv='content-type' content='text/html;charset=utf-8'>
21 <meta name='robots' content='noindex,nofollow'>
22 <title>[<% ident(); %>] Advanced: VLAN</title>
23 <link rel='stylesheet' type='text/css' href='tomato.css'>
24 <% css(); %>
25 <script type='text/javascript' src='tomato.js'></script>
26 <style type='text/css'>
27 #vlan-grid .co1,
28 #vlan-grid .co2,
29 #vlan-grid .co3,
30 #vlan-grid .co4,
31 #vlan-grid .co5,
32 #vlan-grid .co6,
33 #vlan-grid .co7,
34 #vlan-grid .co8,
35 #vlan-grid .co9,
36 #vlan-grid .co10,
37 #vlan-grid .co11,
38 #vlan-grid .co12,
39 #vlan-grid .co13,
40 #vlan-grid .co14 {
41 text-align: center;
43 #vlan-grid .co2 {
44 width: 60px;
46 #vlan-grid .centered {
47 text-align: center;
49 </style>
50 <script type='text/javascript' src='wireless.jsx?_http_id=<% nv(http_id); %>'></script>
51 <script type='text/javascript' src='interfaces.js'></script>
52 <script type='text/javascript'>
53 <% nvram ("vlan0ports,vlan1ports,vlan2ports,vlan3ports,vlan4ports,vlan5ports,vlan6ports,vlan7ports,vlan8ports,vlan9ports,vlan10ports,vlan11ports,vlan12ports,vlan13ports,vlan14ports,vlan15ports,vlan0hwname,vlan1hwname,vlan2hwname,vlan3hwname,vlan4hwname,vlan5hwname,vlan6hwname,vlan7hwname,vlan8hwname,vlan9hwname,vlan10hwname,vlan11hwname,vlan12hwname,vlan13hwname,vlan14hwname,vlan15hwname,wan_ifnameX,manual_boot_nv,boardtype,boardflags,trunk_vlan_so,lan_ifname,lan_ifnames,lan1_ifname,lan1_ifnames,lan2_ifname,lan2_ifnames,lan3_ifname,lan3_ifnames,boardrev,boardnum,vlan0tag,vlan0vid,vlan1vid,vlan2vid,vlan3vid,vlan4vid,vlan5vid,vlan6vid,vlan7vid,vlan8vid,vlan9vid,vlan10vid,vlan11vid,vlan12vid,vlan13vid,vlan14vid,vlan15vid");%>
55 var port_vlan_supported = 0;
56 var trunk_vlan_supported = 0;
58 // does not seem to be strictly necessary for boardflags as it's supposed to be a bitmap
59 nvram['boardflags'] = ((nvram['boardflags'].toLowerCase().indexOf('0x') != -1) ? '0x' : '') + String('0000' + ((nvram['boardflags'].toLowerCase()).replace('0x',''))).slice(-4);
60 // but the contents of router/shared/id.c seem to indicate string formatting/padding might be required for some models as we check if strings match
61 nvram['boardtype'] = ((nvram['boardtype'].toLowerCase().indexOf('0x') != -1) ? '0x' : '') + String('0000' + ((nvram['boardtype'].toLowerCase()).replace('0x',''))).slice(-4);
63 // see http://www.dd-wrt.com/wiki/index.php/Hardware#Boardflags and router/shared/id.c
64 if(nvram['boardflags'] & 0x0100) { // BFL_ENETVLAN = this board has vlan capability
65 port_vlan_supported = 1;
68 // TESTED ONLY ON WRT54G v2 (boardtype 0x0101) and WRT54GL v1.1 (boardtype 0x0467)
69 // attempt of cross-referencing boardtypes/routers mentioned on id.c and the wiki page above
70 switch(nvram['boardtype']) {
71 case '0x0467': // WRT54GL 1.x, WRT54GS 3.x/4.x
72 case '0x048e': // WL-520GU, WL-500G Premium v2
73 case '0x04ef': // WRT320N/E2000
74 case '0x04cf': // WRT610Nv2/E3000, RT-N16
75 case '0xf52c': // E4200v1
76 case '0xf5b2': // RT-N66
77 trunk_vlan_supported = 1;
78 break;
79 default:
80 break;
83 // TESTED ONLY ON WRT54G v2 (boardtype 0x0101),WRT54GL v1.1 (boardtype 0x0467) and WNR3500L (boardtype 0x04cf)
84 // info on some of these boardtypes/routers obtained from
85 // http://wiki.openwrt.org/toh/asus/start
86 // http://wiki.openwrt.org/toh/linksys/start
87 // http://wiki.openwrt.org/toh/start
88 switch(nvram['boardtype']) {
89 case '0x0467': // WRT54GL 1.x, WRT54GS 3.x/4.x
90 if (nvram['boardrev'] == '0x13') { // WHR-G54S
91 COL_P0N = '1';
92 COL_P1N = '2';
93 COL_P2N = '3';
94 COL_P3N = '4';
95 COL_P4N = '0';
96 break;
98 case '0xa4cf': // Belkin F7D3301
99 if (nvram['boardrev'] == '0x1100'){ //Belkin F5D8235-4 v3
100 COL_P0N = '1';
101 COL_P1N = '2';
102 COL_P2N = '3';
103 COL_P3N = '4';
104 COL_P4N = '0';
105 break;
107 case '0xd4cf': // Belkin F7D4301
108 case '0x048e': // WL-520GU, WL-500G Premium v2
109 case '0x0550': // RT-N53 (boardrev = 0x1442), RT-N10U ( boardrev = 0x1102)
110 if (((nvram['boardrev'] == '0x1102') || (nvram['boardrev'] == '0x1100')) ||(nvram['boardrev'] == '0x1400')) { //RT-N10U, CW-5358U, L600N
111 COL_P0N = '1';
112 COL_P1N = '2';
113 COL_P2N = '3';
114 COL_P3N = '4';
115 COL_P4N = '0';
116 break;
118 if ((nvram['boardrev'] == '0x1446') && (nvram['boardnum'] == '0015')) { //Dir-620 C1
119 COL_P0N = '0';
120 COL_P1N = '1';
121 COL_P2N = '2';
122 COL_P3N = '3';
123 COL_P4N = '4';
124 break;
126 COL_P0N = '3';
127 COL_P1N = '2';
128 COL_P2N = '1';
129 COL_P3N = '0';
130 COL_P4N = '4';
131 break;
132 case '0x04ef': // WRT320N/E2000
133 case '0x04cf': // WRT610Nv2/E3000, RT-N16, WNR3500L
134 case '0xf5b2': // RT-N66
135 COL_P0N = '4';
136 COL_P1N = '3';
137 COL_P2N = '2';
138 COL_P3N = '1';
139 COL_P4N = '0';
140 break;
141 case '0xf53a': // E1000v2.1/E1200v1
142 case '0xf53b': // E1000v2/E1500
143 if (((nvram['boot_hw_model'] == 'E1200') && (nvram['boot_hw_ver'] == '1.0')) || (nvram['boot_hw_model'] == 'E1500')) {
144 COL_P0N = '0';
145 COL_P1N = '1';
146 COL_P2N = '2';
147 COL_P3N = '3';
148 COL_P4N = '4';
149 break;
151 COL_P0N = '1';
152 COL_P1N = '2';
153 COL_P2N = '3';
154 COL_P3N = '4';
155 COL_P4N = '0';
156 break;
157 case '0xc550': // E1550
158 case '0xf550': // E2500
159 case '0x058e': // E900
160 case '0xf52a': // E3200
161 case '0xf52c': // E4200v1
162 case '0x1202': // HG320 - not sure, need test
163 if ((nvram['boardrev'] == '0x1153') && (nvram['boardnum'] == '45')) { //RT-N10P
164 COL_P0N = '3';
165 COL_P1N = '2';
166 COL_P2N = '1';
167 COL_P3N = '0';
168 COL_P4N = '4';
169 break;
171 if (nvram['boardrev'] == '0x1153') { //RG200E-CA type 0x058e same as E900
172 COL_P0N = '4';
173 COL_P1N = '3';
174 COL_P2N = '2';
175 COL_P3N = '1';
176 COL_P4N = '0';
177 break;
179 COL_P0N = '0';
180 COL_P1N = '1';
181 COL_P2N = '2';
182 COL_P3N = '3';
183 COL_P4N = '4';
184 break;
185 case '0x052b':
186 if (nvram['boardrev'] == '02') { //WNR3500Lv2
187 COL_P0N = '4';
188 COL_P1N = '3';
189 COL_P2N = '2';
190 COL_P3N = '1';
191 COL_P4N = '0';
192 break;
194 if (nvram['boardrev'] == '0x1204') { //rt-n15u
195 COL_P0N = '3';
196 COL_P1N = '2';
197 COL_P2N = '1';
198 COL_P3N = '0';
199 COL_P4N = '4';
200 break;
202 // should work on WRT54G v2/v3, WRT54GS v1/v2 and others
203 default:
204 COL_P0N = '1';
205 COL_P1N = '2';
206 COL_P2N = '3';
207 COL_P3N = '4';
208 COL_P4N = '0';
209 break;
212 var COL_VID = 0;
213 var COL_MAP = 1;
214 var COL_P0 = 2;
215 var COL_P0T = 3;
216 var COL_P1 = 4;
217 var COL_P1T = 5;
218 var COL_P2 = 6;
219 var COL_P2T = 7;
220 var COL_P3 = 8;
221 var COL_P3T = 9;
222 var COL_P4 = 10;
223 var COL_P4T = 11;
224 var COL_VID_DEF = 12;
225 var COL_BRI = 13;
227 var vlt = nvram.vlan0tag | '0';
229 // set to either 5 or 8 when nvram settings are read (FastE or GigE routers)
230 var SWITCH_INTERNAL_PORT=0;
231 // option made available for experimental purposes on routers known to support port-based VLANs, but not confirmed to support 801.11q trunks
232 var PORT_VLAN_SUPPORT_OVERRIDE = ((nvram['trunk_vlan_so'] == '1') ? 1 : 0);
234 function verifyFields(focused, quiet){
235 PORT_VLAN_SUPPORT_OVERRIDE=(E('_f_trunk_vlan_so').checked ? 1 : 0);
236 for (var uidx = 0; uidx < wl_ifaces.length; ++uidx) {
237 var u = wl_fface(uidx);
238 var wlan = E('_f_bridge_wlan'+u+'_to');
239 if(nvram.lan_ifname.length < 1)
240 wlan.options[0].disabled=true;
241 if(nvram.lan1_ifname.length < 1)
242 wlan.options[1].disabled=true;
243 if(nvram.lan2_ifname.length < 1)
244 wlan.options[2].disabled=true;
245 if(nvram.lan3_ifname.length < 1)
246 wlan.options[3].disabled=true;
248 var e = E('_vlan0tag');
249 if (!v_range('_vlan0tag', quiet, 0, 4080)) return 0;
250 var v = parseInt(e.value);
251 e.value = v - (v % 16);
252 if ((e.value != vlt) && (typeof(vlg) != 'undefined')) {
253 vlg.populate();
254 vlt = e.value;
256 return 1;
259 function save() {
260 if (vlg.isEditing()) return;
262 var fom = E('_fom');
263 fom.trunk_vlan_so.value = (E('_f_trunk_vlan_so').checked ? 1 : 0);
264 // wipe out relevant fields just in case this is not the first time we try to submit
265 for (var i = 0 ; i <= MAX_VLAN_ID ; i++) {
266 fom['vlan' + i + 'ports'].value = '';
267 fom['vlan' + i + 'hwname'].value = '';
268 fom['vlan' + i + 'vid'].value = '';
270 fom['wan_ifnameX'].value = '';
271 fom['lan_ifnames'].value = '';
272 fom['lan1_ifnames'].value = '';
273 fom['lan2_ifnames'].value = '';
274 fom['lan3_ifnames'].value = '';
276 var v = '';
277 var d = vlg.getAllData();
279 for (var i = 0; i < d.length; ++i) {
280 var p = '';
281 p += (d[i][COL_P0].toString() != '0') ? COL_P0N : '';
282 p += (((trunk_vlan_supported) || (PORT_VLAN_SUPPORT_OVERRIDE)) && (d[i][COL_P0T].toString() != '0')) ? 't' : '';
283 p += trailingSpace(p);
285 p += (d[i][COL_P1].toString() != '0') ? COL_P1N : '';
286 p += (((trunk_vlan_supported) || (PORT_VLAN_SUPPORT_OVERRIDE)) && (d[i][COL_P1T].toString() != '0')) ? 't' : '';
287 p += trailingSpace(p);
289 p += (d[i][COL_P2].toString() != '0') ? COL_P2N : '';
290 p += (((trunk_vlan_supported) || (PORT_VLAN_SUPPORT_OVERRIDE)) && (d[i][COL_P2T].toString() != '0')) ? 't' : '';
291 p += trailingSpace(p);
293 p += (d[i][COL_P3].toString() != '0') ? COL_P3N : '';
294 p += (((trunk_vlan_supported) || (PORT_VLAN_SUPPORT_OVERRIDE)) && (d[i][COL_P3T].toString() != '0')) ? 't' : '';
295 p += trailingSpace(p);
297 p += (d[i][COL_P4].toString() != '0') ? COL_P4N : '';
298 p += (((trunk_vlan_supported) || (PORT_VLAN_SUPPORT_OVERRIDE)) && (d[i][COL_P4T].toString() != '0')) ? 't' : '';
299 p += trailingSpace(p);
301 p += (d[i][COL_VID_DEF].toString() != '0') ? (SWITCH_INTERNAL_PORT + '*') : SWITCH_INTERNAL_PORT;
303 // arrange port numbers in ascending order just to be safe (not sure if this is really needed... mostly, cosmetics?)
304 p = p.split(" ");
305 p = p.sort(cmpInt);
306 p = p.join(" ");
308 v += (d[i][COL_VID_DEF].toString() != '0') ? d[i][0] : '';
310 fom['vlan'+d[i][COL_VID]+'ports'].value = p;
311 fom['vlan'+d[i][COL_VID]+'hwname'].value = 'et0';
312 fom['vlan'+d[i][COL_VID]+'vid'].value = ((d[i][COL_MAP].toString() != '') && (d[i][COL_MAP].toString() != '0')) ? d[i][COL_MAP] : '';
314 fom['wan_ifnameX'].value += (d[i][COL_BRI] == '2') ? 'vlan'+d[i][0] : '';
315 fom['lan_ifnames'].value += (d[i][COL_BRI] == '3') ? 'vlan'+d[i][0] : '';
316 /* REMOVE-BEGIN
317 // fom['lan_ifnames'].value += trailingSpace(fom['lan_ifnames'].value);
318 // alert('vlan'+d[i][0]+'ports='+fom['vlan'+d[i][0]+'ports'].value+'\nvlan'+d[i][0]+'hwname='+fom['vlan'+d[i][0]+'hwname'].value);
319 REMOVE-END */
320 fom['lan1_ifnames'].value += (d[i][COL_BRI] == '4') ? 'vlan'+d[i][0] : '';
321 fom['lan2_ifnames'].value += (d[i][COL_BRI] == '5') ? 'vlan'+d[i][0] : '';
322 fom['lan3_ifnames'].value += (d[i][COL_BRI] == '6') ? 'vlan'+d[i][0] : '';
325 for (var uidx = 0; uidx < wl_ifaces.length; ++uidx) {
326 var u = wl_fface(uidx);
327 var wlan = E('_f_bridge_wlan'+u+'_to');
328 /* REMOVE-BEGIN
329 // var wlan = E('_f_bridge_wlan_to');
330 // alert(wlan.selectedIndex);
331 REMOVE-END */
332 switch(parseInt(wlan.selectedIndex)) {
333 case 0:
334 fom['lan_ifnames'].value += ' ' + wl_ifaces[uidx][0];
335 break;
336 case 1:
337 fom['lan1_ifnames'].value += ' ' + wl_ifaces[uidx][0];
338 break;
339 case 2:
340 fom['lan2_ifnames'].value += ' ' + wl_ifaces[uidx][0];
341 break;
342 case 3:
343 fom['lan3_ifnames'].value += ' ' + wl_ifaces[uidx][0];
344 break;
347 /* REMOVE-BEGIN
348 // var lif = nvram['lan_ifnames'].split(' ');
349 // for (var j = 0; j < lif.length; j++) {
350 // fom['lan_ifnames'].value += (lif[j].indexOf('vlan') != -1) ? '' : lif[j];
351 // fom['lan_ifnames'].value += trailingSpace(fom['lan_ifnames'].value);
352 // }
353 // alert('lan_ifnames=' + fom['lan_ifnames'].value + '\n' +
354 // 'lan1_ifnames=' + fom['lan1_ifnames'].value + '\n' +
355 // 'lan2_ifnames=' + fom['lan2_ifnames'].value + '\n' +
356 // 'lan3_ifnames=' + fom['lan3_ifnames'].value);
357 REMOVE-END */
359 // for some models, Tomato checks for a few vital/crucial nvram settings at init time
360 // in some cases, if some/any of them are not found, a full nvram reset/clean could be triggered
361 // so, to (try to) play it safe, we check for the 1st needed/available/required
362 // VLAN for FastE (vlan0 is usually LAN) and GigE routers (vlan1 is usually LAN)
363 if((fom['vlan0ports'].value.length < 1) || (fom['vlan0hwname'].value.length < 1) ||
364 (fom['vlan1ports'].value.length < 1) || (fom['vlan1hwname'].value.length < 1))
365 fom['manual_boot_nv'].value = '1';
366 else
367 fom['manual_boot_nv'].value = nvram['manual_boot_nv'];
369 var e = E('footer-msg');
371 if(vlg.countWan() != 1) {
372 e.innerHTML = 'Cannot proceed: one VID must be assigned to WAN.';
373 e.style.visibility = 'visible';
374 setTimeout(
375 function() {
376 e.innerHTML = '';
377 e.style.visibility = 'hidden';
378 }, 5000);
379 return;
382 if(vlg.countLan(0) != 1) {
383 e.innerHTML = 'Cannot proceed: one and only one VID must be assigned to the primary LAN (br0).';
384 e.style.visibility = 'visible';
385 setTimeout(
386 function() {
387 e.innerHTML = '';
388 e.style.visibility = 'hidden';
389 }, 5000);
390 return;
393 if (v.length < 1) {
394 e.innerHTML = 'Cannot proceed without setting a default VID';
395 e.style.visibility = 'visible';
396 setTimeout(
397 function() {
398 e.innerHTML = '';
399 e.style.visibility = 'hidden';
400 }, 5000);
401 return;
404 if (confirm("Router must be rebooted to proceed. Commit changes to NVRAM and reboot now?"))
405 form.submit(fom, 0);
408 function trailingSpace(s)
410 return ((s.length>0)&&(s.charAt(s.length-1) != ' ')) ? ' ' : '';
413 if(port_vlan_supported) { // aka if(supported_hardware) block
414 var vlg = new TomatoGrid();
415 vlg.setup = function() {
416 this.init('vlan-grid', '', (MAX_VLAN_ID + 1), [
417 { type: 'select', options: [[0, '0'],[1, '1'],[2, '2'],[3, '3'],[4, '4'],[5, '5'],[6, '6'],[7, '7'],[8, '8'],[9, '9'],[10, '10'],[11, '11'],[12, '12'],[13, '13'],[14, '14'],[15, '15']], prefix: '<div class="centered">', suffix: '</div>' },
418 { type: 'text', maxlen: 4, prefix: '<div class="centered">', suffix: '</div>' },
419 { type: 'checkbox', prefix: '<div class="centered">', suffix: '</div>' },
420 { type: 'checkbox', prefix: '<div class="centered">', suffix: '</div>' },
421 { type: 'checkbox', prefix: '<div class="centered">', suffix: '</div>' },
422 { type: 'checkbox', prefix: '<div class="centered">', suffix: '</div>' },
423 { type: 'checkbox', prefix: '<div class="centered">', suffix: '</div>' },
424 { type: 'checkbox', prefix: '<div class="centered">', suffix: '</div>' },
425 { type: 'checkbox', prefix: '<div class="centered">', suffix: '</div>' },
426 { type: 'checkbox', prefix: '<div class="centered">', suffix: '</div>' },
427 { type: 'checkbox', prefix: '<div class="centered">', suffix: '</div>' },
428 { type: 'checkbox', prefix: '<div class="centered">', suffix: '</div>' },
429 { type: 'checkbox', prefix: '<div class="centered">', suffix: '</div>' },
430 { type: 'select', options: [[1, 'none'],[2, 'WAN'],[3, 'LAN (br0)'],[4, 'LAN1 (br1)'],[5, 'LAN2 (br2)'],[6, 'LAN3 (br3)']], prefix: '<div class="centered">', suffix: '</div>' }]);
432 this.headerSet(['VLAN', 'VID', 'Port 1', 'Tagged', 'Port 2', 'Tagged', 'Port 3', 'Tagged', 'Port 4', 'Tagged', 'WAN Port', 'Tagged', 'Default', 'Bridge']);
434 vlg.populate();
435 vlg.canDelete = false;
436 vlg.sort(0);
437 vlg.showNewEditor();
438 vlg.resetNewEditor();
441 vlg.populate = function() {
442 vlg.removeAllData();
444 // find out which vlans are supposed to be bridged to each LAN
445 var bridged = [];
447 for (var i = 0 ; i <= MAX_BRIDGE_ID ; i++) {
448 var j = (i == 0) ? '' : i.toString();
449 var l = nvram['lan' + j + '_ifnames'].split(' ');
450 /* REMOVE-BEGIN
451 // alert('lan' + j + '_ifnames=' + l);
452 REMOVE-END */
453 for (var k = 0 ; k < l.length; k++) {
454 /* REMOVE-BEGIN
455 // alert("bridge br" + i + "=vlan" + parseInt(l[k].replace('vlan','')));
456 REMOVE-END */
457 if(l[k].indexOf('vlan') != -1) {
458 /* REMOVE-BEGIN
459 // alert('lan' + j + '_ifname=br' + nvram['lan' + j + '_ifname'].replace('br',''));
460 REMOVE-END */
461 if (nvram['lan' + j + '_ifname'] != '')
462 bridged[parseInt(l[k].replace('vlan',''))] = (3 + parseInt(nvram['lan' + j + '_ifname'].replace('br',''))).toString();
463 else
464 bridged[parseInt(l[k].replace('vlan',''))] = '1';
466 // WLAN
467 for (var uidx = 0; uidx < wl_ifaces.length; ++uidx) {
468 if(l[k].indexOf(wl_ifaces[uidx][0]) != -1) {
469 E('_f_bridge_wlan'+wl_fface(uidx)+'_to').selectedIndex=i;
475 // WAN port
476 bridged[parseInt(nvram['wan_ifnameX'].replace('vlan',''))] = '2';
478 // go thru all possible VLANs
479 for (var i = 0 ; i <= MAX_VLAN_ID ; i++) {
480 var port = [];
481 var tagged = [];
482 if ((nvram['vlan' + i + 'hwname'].length > 0) || (nvram['vlan' + i + 'ports'].length > 0)) {
483 // (re)initialize our bitmap for this particular iteration
484 for (var j=0; j <= MAX_PORT_ID ; j++) {
485 port[j] = '0';
486 tagged[j] = '0';
488 // which ports are members of this VLAN?
489 var m=nvram['vlan' + i + 'ports'].split(' ');
490 for (var j = 0; j < (m.length) ; j++) {
491 port[parseInt(m[j].charAt(0))] = '1';
492 tagged[parseInt(m[j].charAt(0))] = (((trunk_vlan_supported) || (PORT_VLAN_SUPPORT_OVERRIDE)) && (m[j].indexOf('t') != -1)) ? '1' : '0';
495 if (port_vlan_supported) {
496 if((nvram['vlan' + i + 'ports']).indexOf('*') != -1)
497 SWITCH_INTERNAL_PORT=(nvram['vlan' + i + 'ports']).charAt((nvram['vlan' + i + 'ports']).indexOf('*')-1);
499 vlg.insertData(-1, [ i.toString(),
500 ((nvram['vlan' + i + 'vid'] != '') && (nvram['vlan' + i + 'vid'] > 0)) ? (nvram['vlan' + i + 'vid']).toString() : '0',
501 port[COL_P0N], tagged[COL_P0N],
502 port[COL_P1N], tagged[COL_P1N],
503 port[COL_P2N], tagged[COL_P2N],
504 port[COL_P3N], tagged[COL_P3N],
505 port[COL_P4N], tagged[COL_P4N],
506 (((nvram['vlan' + i + 'ports']).indexOf('*') != -1) ? '1' : '0' ),
507 (bridged[i] != null) ? bridged[i] : '1' ]);
513 vlg.countElem = function(f, v)
515 var data = this.getAllData();
516 var total = 0;
517 for (var i = 0; i < data.length; ++i) {
518 total += (data[i][f] == v) ? 1 : 0;
520 return total;
523 vlg.countDefaultVID = function()
525 return this.countElem(COL_VID_DEF,1);
528 vlg.countVID = function (v)
530 return this.countElem(COL_VID,v);
533 vlg.countWan = function()
535 return this.countElem(COL_BRI,2);
538 vlg.countLan = function(l)
540 return this.countElem(COL_BRI,l+3);
543 vlg.verifyFields = function(row, quiet) {
544 var valid = 1;
545 var f = fields.getAll(row);
547 for(var i=0; i<= MAX_VLAN_ID ; i++) {
548 f[COL_VID].options[i].disabled = (this.countVID(i) > 0);
551 for (var i=0; i <= MAX_BRIDGE_ID; i++) {
552 var j = (i==0) ? '' : i.toString();
553 f[COL_BRI].options[i+2].disabled = (nvram['lan' + j + '_ifname'].length < 1);
556 if (!v_range(f[COL_MAP], quiet, 0, 4094)) valid = 0;
558 if(((trunk_vlan_supported) || (PORT_VLAN_SUPPORT_OVERRIDE)) && (f[COL_P0].checked == 1)) {
559 f[COL_P0T].disabled=0;
560 /* REMOVE-BEGIN
561 // if((f[COL_P0T].checked==0) || (this.countElem(COL_P0,1)>0) )
562 // if(this.countElem(COL_P0,1)>0) {
563 // }
564 REMOVE-END */
565 } else {
566 f[COL_P0T].disabled=1;
567 f[COL_P0T].checked=0;
569 if(((trunk_vlan_supported) || (PORT_VLAN_SUPPORT_OVERRIDE)) && (f[COL_P1].checked == 1)) {
570 f[COL_P1T].disabled=0;
571 } else {
572 f[COL_P1T].disabled=1;
573 f[COL_P1T].checked=0;
575 if(((trunk_vlan_supported) || (PORT_VLAN_SUPPORT_OVERRIDE)) && (f[COL_P2].checked == 1)) {
576 f[COL_P2T].disabled=0;
577 } else {
578 f[COL_P2T].disabled=1;
579 f[COL_P2T].checked=0;
581 if(((trunk_vlan_supported) || (PORT_VLAN_SUPPORT_OVERRIDE)) && (f[COL_P3].checked == 1)) {
582 f[COL_P3T].disabled=0;
583 } else {
584 f[COL_P3T].disabled=1;
585 f[COL_P3T].checked=0;
587 if(((trunk_vlan_supported) || (PORT_VLAN_SUPPORT_OVERRIDE)) && (f[COL_P4].checked == 1)) {
588 f[COL_P4T].disabled=0;
589 } else {
590 f[COL_P4T].disabled=1;
591 f[COL_P4T].checked=0;
594 if ((f[COL_P0].checked == 1) && (this.countElem(COL_P0,1)>0)) {
595 if (((this.countElem(COL_P0,1) != this.countElem(COL_P0T,1)) || (f[COL_P0T].checked==0))) {
596 ferror.set(f[COL_P0T], 'Port 1 cannot be assigned to more than one VLAN unless frames are tagged on all VLANs Port 1 is member', quiet);
597 valid=0;
598 } else {
599 ferror.clear(f[COL_P0T]);
602 if ((f[COL_P1].checked == 1) && (this.countElem(COL_P1,1)>0)) {
603 if (((this.countElem(COL_P1,1) != this.countElem(COL_P1T,1)) || (f[COL_P1T].checked==0))) {
604 ferror.set(f[COL_P1T], 'Port 2 cannot be assigned to more than one VLAN unless frames are tagged on all VLANs Port 2 is member', quiet);
605 valid=0;
606 } else {
607 ferror.clear(f[COL_P1T]);
610 if ((f[COL_P2].checked == 1) && (this.countElem(COL_P2,1)>0)) {
611 if (((this.countElem(COL_P2,1) != this.countElem(COL_P2T,1)) || (f[COL_P2T].checked==0))) {
612 ferror.set(f[COL_P2T], 'Port 3 cannot be assigned to more than one VLAN unless frames are tagged on all VLANs Port 3 is member', quiet);
613 valid=0;
614 } else {
615 ferror.clear(f[COL_P2T]);
618 if ((f[COL_P3].checked == 1) && (this.countElem(COL_P3,1)>0)) {
619 if (((this.countElem(COL_P3,1) != this.countElem(COL_P3T,1)) || (f[COL_P3T].checked==0))) {
620 ferror.set(f[COL_P3T], 'Port 4 cannot be assigned to more than one VLAN unless frames are tagged on all VLANs Port 4 is member', quiet);
621 valid=0;
622 } else {
623 ferror.clear(f[COL_P3T]);
626 if ((f[COL_P4].checked == 1) && (this.countElem(COL_P4,1)>0)) {
627 if (((this.countElem(COL_P4,1) != this.countElem(COL_P4T,1)) || (f[COL_P4T].checked==0))) {
628 ferror.set(f[COL_P4T], 'WAN port cannot be assigned to more than one VLAN unless frames are tagged on all VLANs WAN port is member', quiet);
629 valid=0;
630 } else {
631 ferror.clear(f[COL_P4T]);
635 if(this.countDefaultVID() > 0) {
636 f[COL_VID_DEF].disabled=1;
637 f[COL_VID_DEF].checked=0;
640 if((this.countDefaultVID() > 0) && (f[COL_VID_DEF].checked ==1)) {
641 ferror.set(f[COL_VID_DEF], 'Only one VID can be selected as the default VID', quiet);
642 valid = 0;
643 } else {
644 ferror.clear(f[COL_VID_DEF]);
647 if(this.countVID(f[COL_VID].selectedIndex) > 0) {
648 ferror.set(f[COL_VID], 'Cannot add more than one entry with VID ' + f[0].selectedIndex, quiet);
649 valid = 0;
650 } else {
651 ferror.clear(f[COL_VID]);
654 if ((this.countWan() > 0) && (f[COL_BRI].selectedIndex == 1)) {
655 ferror.set(f[COL_BRI],'Only one VID can be used as WAN at any time', quiet);
656 valid = 0;
657 } else {
658 ferror.clear(f[COL_BRI]);
661 for(var i=0; i<4; i++) {
662 if ((this.countLan(i) > 0) && (f[COL_BRI].selectedIndex == (i+2))) {
663 ferror.set(f[COL_BRI],'One and only one VID can be used for LAN' + ((i==0) ? '' : i ) + ' (br'+i+') at any time', quiet);
664 valid = 0;
665 } else {
666 ferror.clear(f[COL_BRI]);
670 return valid;
673 vlg.dataToView = function(data) {
674 return [data[COL_VID],
675 ((data[COL_MAP].toString() == '') || (data[COL_MAP].toString() == '0')) ? (parseInt(E('_vlan0tag').value) * 1 + data[COL_VID] *1 ).toString() : data[COL_MAP].toString(),
676 (data[COL_P0].toString() != '0') ? 'Yes' : '',
677 (data[COL_P0T].toString() != '0') ? 'On' : '',
678 (data[COL_P1].toString() != '0') ? 'Yes' : '',
679 (data[COL_P1T].toString() != '0') ? 'On' : '',
680 (data[COL_P2].toString() != '0') ? 'Yes' : '',
681 (data[COL_P2T].toString() != '0') ? 'On' : '',
682 (data[COL_P3].toString() != '0') ? 'Yes' : '',
683 (data[COL_P3T].toString() != '0') ? 'On' : '',
684 (data[COL_P4].toString() != '0') ? 'Yes' : '',
685 (data[COL_P4T].toString() != '0') ? 'On' : '',
686 (data[COL_VID_DEF].toString() != '0') ? '*' : '',
687 ['', 'WAN', 'LAN (br0)', 'LAN1 (br1)', 'LAN2 (br2)', 'LAN3 (br3)' ][data[COL_BRI] - 1]];
690 vlg.dataToFieldValues = function (data) {
691 return [data[COL_VID],
692 data[COL_MAP],
693 (data[COL_P0] != 0) ? 'checked' : '',
694 (data[COL_P0T] != 0) ? 'checked' : '',
695 (data[COL_P1] != 0) ? 'checked' : '',
696 (data[COL_P1T] != 0) ? 'checked' : '',
697 (data[COL_P2] != 0) ? 'checked' : '',
698 (data[COL_P2T] != 0) ? 'checked' : '',
699 (data[COL_P3] != 0) ? 'checked' : '',
700 (data[COL_P3T] != 0) ? 'checked' : '',
701 (data[COL_P4] != 0) ? 'checked' : '',
702 (data[COL_P4T] != 0) ? 'checked' : '',
703 (data[COL_VID_DEF] != 0) ? 'checked' : '',
704 data[COL_BRI]];
707 vlg.fieldValuesToData = function(row) {
708 var f = fields.getAll(row);
709 return [f[COL_VID].value,
710 f[COL_MAP].value,
711 f[COL_P0].checked ? 1 : 0,
712 f[COL_P0T].checked ? 1 : 0,
713 f[COL_P1].checked ? 1 : 0,
714 f[COL_P1T].checked ? 1 : 0,
715 f[COL_P2].checked ? 1 : 0,
716 f[COL_P2T].checked ? 1 : 0,
717 f[COL_P3].checked ? 1 : 0,
718 f[COL_P3T].checked ? 1 : 0,
719 f[COL_P4].checked ? 1 : 0,
720 f[COL_P4T].checked ? 1 : 0,
721 f[COL_VID_DEF].checked ? 1 : 0,
722 f[COL_BRI].value];
725 vlg.onCancel = function() {
726 this.removeEditor();
727 this.showSource();
728 this.disableNewEditor(false);
730 this.resetNewEditor();
733 vlg.onAdd = function() {
734 var data;
736 this.moving = null;
737 this.rpHide();
739 if (!this.verifyFields(this.newEditor, false)) return;
741 data = this.fieldValuesToData(this.newEditor);
742 this.insertData(-1, data);
744 this.disableNewEditor(false);
745 this.resetNewEditor();
747 this.resort();
750 vlg.onOK = function() {
751 var i, data, view;
753 if (!this.verifyFields(this.editor, false)) return;
755 data = this.fieldValuesToData(this.editor);
756 view = this.dataToView(data);
758 this.source.setRowData(data);
759 for (i = 0; i < this.source.cells.length; ++i) {
760 this.source.cells[i].innerHTML = view[i];
763 this.removeEditor();
764 this.showSource();
765 this.disableNewEditor(false);
767 this.resetNewEditor();
768 this.resort();
771 vlg.onDelete = function() {
772 this.removeEditor();
773 elem.remove(this.source);
774 this.source = null;
775 this.disableNewEditor(false);
777 this.resetNewEditor();
780 vlg.sortCompare = function(a, b) {
781 var obj = TGO(a);
782 var col = obj.sortColumn;
783 if (this.sortColumn == 0) {
784 var r = cmpInt(parseInt(a.cells[col].innerHTML), parseInt(b.cells[col].innerHTML));
785 } else {
786 var r = cmpText(a.cells[col].innerHTML, b.cells[col].innerHTML);
788 return obj.sortAscending ? r : -r;
791 vlg.resetNewEditor = function() {
792 var f = fields.getAll(this.newEditor);
794 for (var i=0; i <= MAX_BRIDGE_ID; i++) {
795 var j = (i==0) ? '' : i.toString();
796 f[COL_BRI].options[i+2].disabled = (nvram['lan' + j + '_ifname'].length < 1);
799 f[COL_MAP].value = '0';
801 f[COL_VID].selectedIndex=0;
802 var t = MAX_VLAN_ID;
803 while((this.countVID(f[COL_VID].selectedIndex) > 0) && (t > 0)) {
804 f[COL_VID].selectedIndex = (f[COL_VID].selectedIndex%(MAX_VLAN_ID))+1;
805 t--;
808 for(var i=0; i<= MAX_VLAN_ID ; i++) {
809 f[COL_VID].options[i].disabled = (this.countVID(i) > 0);
812 f[COL_P0].checked = 0;
813 f[COL_P0T].checked = 0;
814 f[COL_P0T].disabled = 1;
815 f[COL_P1].checked = 0;
816 f[COL_P1T].checked = 0;
817 f[COL_P1T].disabled = 1;
818 f[COL_P2].checked = 0;
819 f[COL_P2T].checked = 0;
820 f[COL_P2T].disabled = 1;
821 f[COL_P3].checked = 0;
822 f[COL_P3T].checked = 0;
823 f[COL_P3T].disabled = 1;
824 f[COL_P4].checked = 0;
825 f[COL_P4T].checked = 0;
826 f[COL_P4T].disabled = 1;
827 f[COL_VID_DEF].checked = 0;
828 if (this.countDefaultVID()>0)
829 f[COL_VID_DEF].disabled = 1;
830 f[COL_BRI].selectedIndex = 0;
831 ferror.clearAll(fields.getAll(this.newEditor));
833 } // end of the so-called if(supported_device) block
835 function init() {
836 if(port_vlan_supported) {
837 vlg.recolor();
838 vlg.resetNewEditor();
839 var c;
840 if (((c = cookie.get('advanced_vlan_notes_vis')) != null) && (c == '1')) toggleVisibility("notes");
844 function toggleVisibility(whichone) {
845 if (E('sesdiv_' + whichone).style.display == '') {
846 E('sesdiv_' + whichone).style.display = 'none';
847 E('sesdiv_' + whichone + '_showhide').innerHTML = '(Click here to show)';
848 cookie.set('advanced_vlan_' + whichone + '_vis', 0);
849 } else {
850 E('sesdiv_' + whichone).style.display='';
851 E('sesdiv_' + whichone + '_showhide').innerHTML = '(Click here to hide)';
852 cookie.set('advanced_vlan_' + whichone + '_vis', 1);
856 function earlyInit() {
857 if(!port_vlan_supported) {
858 E('save-button').disabled = 1;
859 return;
861 PORT_VLAN_SUPPORT_OVERRIDE = ((nvram['trunk_vlan_so'] == '1') ? 1 : 0);
864 </script>
865 </head>
866 <body onload='init()'>
867 <form id='_fom' method='post' action='tomato.cgi'>
868 <table id='container' cellspacing=0>
869 <tr><td colspan=2 id='header'>
870 <div class='title'>Tomato</div>
871 <div class='version'>Version <% version(); %></div>
872 </td></tr>
873 <tr id='body'><td id='navi'><script type='text/javascript'>navi()</script></td>
874 <td id='content'>
875 <div id='ident'><% ident(); %></div>
876 <input type='hidden' name='_nextpage' value='advanced-vlan.asp'>
877 <input type='hidden' name='_nextwait' value='30'>
878 <input type='hidden' name='_reboot' value='1'>
879 <input type='hidden' name='_nvset' value='1'>
880 <input type='hidden' name='_commit' value='1'>
881 <input type='hidden' name='vlan0ports'>
882 <input type='hidden' name='vlan1ports'>
883 <input type='hidden' name='vlan2ports'>
884 <input type='hidden' name='vlan3ports'>
885 <input type='hidden' name='vlan4ports'>
886 <input type='hidden' name='vlan5ports'>
887 <input type='hidden' name='vlan6ports'>
888 <input type='hidden' name='vlan7ports'>
889 <input type='hidden' name='vlan8ports'>
890 <input type='hidden' name='vlan9ports'>
891 <input type='hidden' name='vlan10ports'>
892 <input type='hidden' name='vlan11ports'>
893 <input type='hidden' name='vlan12ports'>
894 <input type='hidden' name='vlan13ports'>
895 <input type='hidden' name='vlan14ports'>
896 <input type='hidden' name='vlan15ports'>
897 <input type='hidden' name='vlan0hwname'>
898 <input type='hidden' name='vlan1hwname'>
899 <input type='hidden' name='vlan2hwname'>
900 <input type='hidden' name='vlan3hwname'>
901 <input type='hidden' name='vlan4hwname'>
902 <input type='hidden' name='vlan5hwname'>
903 <input type='hidden' name='vlan6hwname'>
904 <input type='hidden' name='vlan7hwname'>
905 <input type='hidden' name='vlan8hwname'>
906 <input type='hidden' name='vlan9hwname'>
907 <input type='hidden' name='vlan10hwname'>
908 <input type='hidden' name='vlan11hwname'>
909 <input type='hidden' name='vlan12hwname'>
910 <input type='hidden' name='vlan13hwname'>
911 <input type='hidden' name='vlan14hwname'>
912 <input type='hidden' name='vlan15hwname'>
913 <input type='hidden' name='wan_ifnameX'>
914 <input type='hidden' name='manual_boot_nv'>
915 <input type='hidden' name='lan_ifnames'>
916 <input type='hidden' name='lan1_ifnames'>
917 <input type='hidden' name='lan2_ifnames'>
918 <input type='hidden' name='lan3_ifnames'>
919 <input type='hidden' name='trunk_vlan_so'>
920 <input type='hidden' name='vlan0vid'>
921 <input type='hidden' name='vlan1vid'>
922 <input type='hidden' name='vlan2vid'>
923 <input type='hidden' name='vlan3vid'>
924 <input type='hidden' name='vlan4vid'>
925 <input type='hidden' name='vlan5vid'>
926 <input type='hidden' name='vlan6vid'>
927 <input type='hidden' name='vlan7vid'>
928 <input type='hidden' name='vlan8vid'>
929 <input type='hidden' name='vlan9vid'>
930 <input type='hidden' name='vlan10vid'>
931 <input type='hidden' name='vlan11vid'>
932 <input type='hidden' name='vlan12vid'>
933 <input type='hidden' name='vlan13vid'>
934 <input type='hidden' name='vlan14vid'>
935 <input type='hidden' name='vlan15vid'>
937 <div id='sesdiv' style='display:none'>
938 <div class='section-title'>VLAN</div>
939 <div class='section'>
940 <table class='tomato-grid' cellspacing=1 id='vlan-grid'></table>
941 </div>
943 <!-- / / / -->
945 <div class='section-title'>VID Offset</div>
946 <div class='section'>
947 <script type='text/javascript'>
948 createFieldTable('', [
949 { title: 'First 802.1Q VLAN tag', name: 'vlan0tag', type: 'text', maxlen:4, size:6,
950 value: fixInt(nvram.vlan0tag, 0, 4080, 0),
951 suffix: ' <small><i>(range: 0 - 4080; must be a multiple of 16; set to 0 to disable)</i></small>' }
953 </script>
954 </div>
956 <!-- / / / -->
958 <div class='section-title'>Wireless</div>
959 <div class='section'>
960 <script type='text/javascript'>
961 var f = [];
962 for (var uidx = 0; uidx < wl_ifaces.length; ++uidx) {
963 var u = wl_fface(uidx);
964 f.push(
965 { title: ('Bridge ' + wl_ifaces[uidx][0] + ' to'), name: ('f_bridge_wlan'+u+'_to'), type: 'select',
966 options: [[0,'LAN (br0)'],[1,'LAN1 (br1)'],[2,'LAN2 (br2)'],[3,'LAN3 (br3)'],[4,'none']], value: 4 } );
968 createFieldTable('',f);
969 if(port_vlan_supported) vlg.setup();
970 </script>
971 </div>
973 <!-- / / / -->
974 <div class='section-title'>Trunk VLAN support override (experimental)</div>
975 <div class='section'>
976 <script type='text/javascript'>
977 createFieldTable('', [
978 { title: 'Enable', name: 'f_trunk_vlan_so', type: 'checkbox', value: nvram.trunk_vlan_so == '1' },
980 </script>
981 </div>
983 <div class='section-title'>Notes <small><i><a href='javascript:toggleVisibility("notes");'><span id='sesdiv_notes_showhide'>(Click here to show)</span></a></i></small></div>
984 <div class='section' id='sesdiv_notes' style='display:none'>
985 <ul>
986 <li><b>VLAN</b> - Unique identifier of a VLAN.</li>
987 <li><b>VID</b> - <i>EXPERIMENTAL</i> - Allows overriding 'traditional' VLAN/VID mapping with arbitrary VIDs for each VLAN (set to '0' to use 'regular' VLAN/VID mappings instead). Warning: this hasn't been verified/tested on anything but a Cisco/Linksys E3000 and may not be supported by your particular device/model (<small><b><i>see notes on "VID Offset" below</i></b></small>).</li>
988 <li><b>Ports 1-4 &amp; WAN</b> - Which ethernet ports on the router should be members of this VLAN.</li>
989 <li><b>Tagged</b> - Enable 802.1Q tagging of ethernet frames on a particular port/VLAN
990 <script type='text/javascript'>
991 if(!trunk_vlan_supported)
992 W(' <i><b>(unknown support for this model...contact the developper (Victek))</i></b>');
993 </script>
994 </li>
995 <li><b>Default</b> - VLAN ID assigned to untagged frames received by the router.</li>
996 <li><b>Bridge</b> - Determines if this VLAN ID should be treated as WAN, part of a LAN bridge or just left alone (i.e. member of a 802.1Q trunk, being managed manually via scripts, etc...).</li>
997 </ul>
999 <ul>
1000 <li><b>VID Offset</b> - <i>EXPERIMENTAL</i> - First 802.1Q VLAN tag to be used as <i>base/initial tag/VID</i> for VLAN and VID assignments. This allows using VIDs larger than 15 on (older) devices such as the Linksys WRT54GL v1.1 (in contiguous blocks/ranges with up to 16 VLANs/VIDs). Set to '0' (zero) to disable this feature and VLANs will have the very same/identical value for its VID, as usual (from 0 to 15).</li>
1001 </ul>
1003 <ul>
1004 <li><b>Wireless</b> - Assignments of wireless interfaces to different LAN briges. You should probably be using and/or check things on <a href=advanced-wlanvifs.asp>Advanced/Virtual Wireless</a> and <a href=basic-network.asp>Basic/Network</a>.</li>
1005 </ul>
1007 <small>
1008 <ul>
1009 <li><b>Other relevant notes/hints:</b>
1010 <ul>
1011 <li>One VID <i>must</i> be assigned to WAN.</li>
1012 <li>One VID <i>must</i> be selected as the default.</li>
1013 <script type='text/javascript'>
1014 if((trunk_vlan_supported) || (nvram.trunk_vlan_so == '1')) {
1015 W('<li>To prevent 802.1Q compatibility issues, avoid using VID "0" as 802.1Q specifies that frames with a tag of "0" do not belong to any VLAN (the tag contains only user priority information).</li>');
1016 W('<li>It may be also recommended to avoid using VID "1" as some vendors consider it special/reserved (for management purposes).</li>');
1018 </script>
1019 </ul>
1020 <br>
1021 <ul>
1022 <li>This is an <b>experimental</b> feature and hasn't been tested in anything but a Linksys WRT54GL v1.1 running a Teaman-ND K24 build and a Cisco/Linksys E3000 running a Teaman-RT K26 build.</li>
1023 <li>There's lots of things that could go wrong, please do think about what you're doing and take a backup before hitting the 'Save' button on this page!</li>
1024 </ul>
1025 </ul>
1026 </div>
1027 </div>
1028 </small>
1029 </div>
1030 </div>
1031 <script type='text/javascript'>
1032 if(!port_vlan_supported)
1033 W('<i>This feature is not supported on this router.</i>');
1034 else {
1035 E('sesdiv').style.display = '';
1036 if(!trunk_vlan_supported)
1037 E('trunk_vlan_override').style.display = '';
1039 </script>
1040 </td></tr>
1041 <tr><td id='footer' colspan=2>
1042 <span id='footer-msg'></span>
1043 <input type='button' value='Save' id='save-button' onclick='save()'>
1044 <input type='button' value='Cancel' id='cancel-button' onclick='javascript:reloadPage();'>
1045 </td></tr>
1046 </table>
1047 </form>
1048 <script type='text/javascript'>earlyInit(); verifyFields(null,1);</script>
1049 </body>
1050 </html>