Merge branch 'Toastman-RT' into Toastman-RT-N
[tomato.git] / release / src / router / www / advanced-vlan.asp
blob49894c60073207075bed1c04848833a149c279b2
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 For use with Tomato Firmware only.
12 No part of this file may be used without permission.
13 -->
14 <html>
15 <head>
16 <meta http-equiv='content-type' content='text/html;charset=utf-8'>
17 <meta name='robots' content='noindex,nofollow'>
18 <title>[<% ident(); %>] Advanced: VLAN</title>
19 <link rel='stylesheet' type='text/css' href='tomato.css'>
20 <% css(); %>
21 <script type='text/javascript' src='tomato.js'></script>
22 <style type='text/css'>
23 #vlan-grid .co1,
24 #vlan-grid .co2,
25 #vlan-grid .co3,
26 #vlan-grid .co4,
27 #vlan-grid .co5,
28 #vlan-grid .co6,
29 #vlan-grid .co7,
30 #vlan-grid .co8,
31 #vlan-grid .co9,
32 #vlan-grid .co10,
33 #vlan-grid .co11,
34 #vlan-grid .co12,
35 #vlan-grid .co13,
36 #vlan-grid .co14 {
37 text-align: center;
39 #vlan-grid .co2 {
40 width: 60px;
42 #vlan-grid .centered {
43 text-align: center;
45 </style>
46 <script type='text/javascript' src='wireless.jsx?_http_id=<% nv(http_id); %>'></script>
47 <script type='text/javascript' src='interfaces.js'></script>
48 <script type='text/javascript'>
49 <% 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,vlan0tag,vlan0vid,vlan1vid,vlan2vid,vlan3vid,vlan4vid,vlan5vid,vlan6vid,vlan7vid,vlan8vid,vlan9vid,vlan10vid,vlan11vid,vlan12vid,vlan13vid,vlan14vid,vlan15vid");%>
51 var port_vlan_supported = 0;
52 var trunk_vlan_supported = 0;
54 // does not seem to be strictly necessary for boardflags as it's supposed to be a bitmap
55 nvram['boardflags'] = ((nvram['boardflags'].toLowerCase().indexOf('0x') != -1) ? '0x' : '') + String('0000' + ((nvram['boardflags'].toLowerCase()).replace('0x',''))).slice(-4);
56 // 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
57 nvram['boardtype'] = ((nvram['boardtype'].toLowerCase().indexOf('0x') != -1) ? '0x' : '') + String('0000' + ((nvram['boardtype'].toLowerCase()).replace('0x',''))).slice(-4);
59 // see http://www.dd-wrt.com/wiki/index.php/Hardware#Boardflags and router/shared/id.c
60 if(nvram['boardflags'] & 0x0100) { // BFL_ENETVLAN = this board has vlan capability
61 port_vlan_supported = 1;
64 // TESTED ONLY ON WRT54G v2 (boardtype 0x0101) and WRT54GL v1.1 (boardtype 0x0467)
65 // attempt of cross-referencing boardtypes/routers mentioned on id.c and the wiki page above
66 switch(nvram['boardtype']) {
67 case '0x0467': // WRT54GL 1.x, WRT54GS 3.x/4.x
68 case '0x048e': // WL-520GU, WL-500G Premium v2
69 case '0x04ef': // WRT320N/E2000
70 case '0x04cf': // WRT610Nv2/E3000, RT-N16
71 case '0xf52c': // E4200v1
72 case '0xf582': // RT-N66
73 trunk_vlan_supported = 1;
74 break;
75 default:
76 break;
79 // TESTED ONLY ON WRT54G v2 (boardtype 0x0101),WRT54GL v1.1 (boardtype 0x0467) and WNR3500L (boardtype 0x04cf)
80 // info on some of these boardtypes/routers obtained from
81 // http://wiki.openwrt.org/toh/asus/start
82 // http://wiki.openwrt.org/toh/linksys/start
83 // http://wiki.openwrt.org/toh/start
84 switch(nvram['boardtype']) {
85 case '0x0467': // WRT54GL 1.x, WRT54GS 3.x/4.x
86 if (nvram['boardrev'] == '0x13') { // WHR-G54S
87 COL_P0N = '1';
88 COL_P1N = '2';
89 COL_P2N = '3';
90 COL_P3N = '4';
91 COL_P4N = '0';
92 break;
94 case '0x048e': // WL-520GU, WL-500G Premium v2
95 COL_P0N = '3';
96 COL_P1N = '2';
97 COL_P2N = '1';
98 COL_P3N = '0';
99 COL_P4N = '4';
100 break;
101 case '0x04ef': // WRT320N/E2000
102 case '0x04cf': // WRT610Nv2/E3000, RT-N16, WNR3500L
103 case '0xf582': // RT-N66: not tested
104 COL_P0N = '4';
105 COL_P1N = '3';
106 COL_P2N = '2';
107 COL_P3N = '1';
108 COL_P4N = '0';
109 break;
110 case '0xf53a': // E1000v2.1/E1200v1
111 case '0xf53b': // E1000v2/E1500
112 if (((nvram['boot_hw_model'] == 'E1200') && (nvram['boot_hw_ver'] == '1.0')) || (nvram['boot_hw_model'] == 'E1500')) {
113 COL_P0N = '0';
114 COL_P1N = '1';
115 COL_P2N = '2';
116 COL_P3N = '3';
117 COL_P4N = '4';
118 break;
120 COL_P0N = '1';
121 COL_P1N = '2';
122 COL_P2N = '3';
123 COL_P3N = '4';
124 COL_P4N = '0';
125 break;
126 case '0xc550': // E1550
127 case '0xf550': // E2500
128 case '0x058e': // E900
129 case '0xf52a': // E3200
130 case '0xf52c': // E4200v1
131 COL_P0N = '0';
132 COL_P1N = '1';
133 COL_P2N = '2';
134 COL_P3N = '3';
135 COL_P4N = '4';
136 break;
137 case '0x052b':
138 if (nvram['boardrev'] == '02') { //WNR3500Lv2
139 COL_P0N = '4';
140 COL_P1N = '3';
141 COL_P2N = '2';
142 COL_P3N = '1';
143 COL_P4N = '0';
144 break;
146 if (nvram['boardrev'] == '0x1204') { //rt-n15u
147 COL_P0N = '3';
148 COL_P1N = '2';
149 COL_P2N = '1';
150 COL_P3N = '0';
151 COL_P4N = '4';
152 break;
154 // should work on WRT54G v2/v3, WRT54GS v1/v2 and others
155 default:
156 COL_P0N = '1';
157 COL_P1N = '2';
158 COL_P2N = '3';
159 COL_P3N = '4';
160 COL_P4N = '0';
161 break;
164 var COL_VID = 0;
165 var COL_MAP = 1;
166 var COL_P0 = 2;
167 var COL_P0T = 3;
168 var COL_P1 = 4;
169 var COL_P1T = 5;
170 var COL_P2 = 6;
171 var COL_P2T = 7;
172 var COL_P3 = 8;
173 var COL_P3T = 9;
174 var COL_P4 = 10;
175 var COL_P4T = 11;
176 var COL_VID_DEF = 12;
177 var COL_BRI = 13;
179 var vlt = nvram.vlan0tag | '0';
181 // set to either 5 or 8 when nvram settings are read (FastE or GigE routers)
182 var SWITCH_INTERNAL_PORT=0;
183 // option made available for experimental purposes on routers known to support port-based VLANs, but not confirmed to support 801.11q trunks
184 var PORT_VLAN_SUPPORT_OVERRIDE = ((nvram['trunk_vlan_so'] == '1') ? 1 : 0);
186 function verifyFields(focused, quiet){
187 PORT_VLAN_SUPPORT_OVERRIDE=(E('_f_trunk_vlan_so').checked ? 1 : 0);
188 for (var uidx = 0; uidx < wl_ifaces.length; ++uidx) {
189 var u = wl_fface(uidx);
190 var wlan = E('_f_bridge_wlan'+u+'_to');
191 if(nvram.lan_ifname.length < 1)
192 wlan.options[0].disabled=true;
193 if(nvram.lan1_ifname.length < 1)
194 wlan.options[1].disabled=true;
195 if(nvram.lan2_ifname.length < 1)
196 wlan.options[2].disabled=true;
197 if(nvram.lan3_ifname.length < 1)
198 wlan.options[3].disabled=true;
200 var e = E('_vlan0tag');
201 if (!v_range('_vlan0tag', quiet, 0, 4080)) return 0;
202 var v = parseInt(e.value);
203 e.value = v - (v % 16);
204 if ((e.value != vlt) && (typeof(vlg) != 'undefined')) {
205 vlg.populate();
206 vlt = e.value;
208 return 1;
211 function save() {
212 if (vlg.isEditing()) return;
214 var fom = E('_fom');
215 fom.trunk_vlan_so.value = (E('_f_trunk_vlan_so').checked ? 1 : 0);
216 // wipe out relevant fields just in case this is not the first time we try to submit
217 for (var i = 0 ; i <= MAX_VLAN_ID ; i++) {
218 fom['vlan' + i + 'ports'].value = '';
219 fom['vlan' + i + 'hwname'].value = '';
220 fom['vlan' + i + 'vid'].value = '';
222 fom['wan_ifnameX'].value = '';
223 fom['lan_ifnames'].value = '';
224 fom['lan1_ifnames'].value = '';
225 fom['lan2_ifnames'].value = '';
226 fom['lan3_ifnames'].value = '';
228 var v = '';
229 var d = vlg.getAllData();
231 for (var i = 0; i < d.length; ++i) {
232 var p = '';
233 p += (d[i][COL_P0].toString() != '0') ? COL_P0N : '';
234 p += (((trunk_vlan_supported) || (PORT_VLAN_SUPPORT_OVERRIDE)) && (d[i][COL_P0T].toString() != '0')) ? 't' : '';
235 p += trailingSpace(p);
237 p += (d[i][COL_P1].toString() != '0') ? COL_P1N : '';
238 p += (((trunk_vlan_supported) || (PORT_VLAN_SUPPORT_OVERRIDE)) && (d[i][COL_P1T].toString() != '0')) ? 't' : '';
239 p += trailingSpace(p);
241 p += (d[i][COL_P2].toString() != '0') ? COL_P2N : '';
242 p += (((trunk_vlan_supported) || (PORT_VLAN_SUPPORT_OVERRIDE)) && (d[i][COL_P2T].toString() != '0')) ? 't' : '';
243 p += trailingSpace(p);
245 p += (d[i][COL_P3].toString() != '0') ? COL_P3N : '';
246 p += (((trunk_vlan_supported) || (PORT_VLAN_SUPPORT_OVERRIDE)) && (d[i][COL_P3T].toString() != '0')) ? 't' : '';
247 p += trailingSpace(p);
249 p += (d[i][COL_P4].toString() != '0') ? COL_P4N : '';
250 p += (((trunk_vlan_supported) || (PORT_VLAN_SUPPORT_OVERRIDE)) && (d[i][COL_P4T].toString() != '0')) ? 't' : '';
251 p += trailingSpace(p);
253 p += (d[i][COL_VID_DEF].toString() != '0') ? (SWITCH_INTERNAL_PORT + '*') : SWITCH_INTERNAL_PORT;
255 // arrange port numbers in ascending order just to be safe (not sure if this is really needed... mostly, cosmetics?)
256 p = p.split(" ");
257 p = p.sort(cmpInt);
258 p = p.join(" ");
260 v += (d[i][COL_VID_DEF].toString() != '0') ? d[i][0] : '';
262 fom['vlan'+d[i][COL_VID]+'ports'].value = p;
263 fom['vlan'+d[i][COL_VID]+'hwname'].value = 'et0';
264 fom['vlan'+d[i][COL_VID]+'vid'].value = ((d[i][COL_MAP].toString() != '') && (d[i][COL_MAP].toString() != '0')) ? d[i][COL_MAP] : '';
266 fom['wan_ifnameX'].value += (d[i][COL_BRI] == '2') ? 'vlan'+d[i][0] : '';
267 fom['lan_ifnames'].value += (d[i][COL_BRI] == '3') ? 'vlan'+d[i][0] : '';
268 /* REMOVE-BEGIN
269 // fom['lan_ifnames'].value += trailingSpace(fom['lan_ifnames'].value);
270 // 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);
271 REMOVE-END */
272 fom['lan1_ifnames'].value += (d[i][COL_BRI] == '4') ? 'vlan'+d[i][0] : '';
273 fom['lan2_ifnames'].value += (d[i][COL_BRI] == '5') ? 'vlan'+d[i][0] : '';
274 fom['lan3_ifnames'].value += (d[i][COL_BRI] == '6') ? 'vlan'+d[i][0] : '';
277 for (var uidx = 0; uidx < wl_ifaces.length; ++uidx) {
278 var u = wl_fface(uidx);
279 var wlan = E('_f_bridge_wlan'+u+'_to');
280 /* REMOVE-BEGIN
281 // var wlan = E('_f_bridge_wlan_to');
282 // alert(wlan.selectedIndex);
283 REMOVE-END */
284 switch(parseInt(wlan.selectedIndex)) {
285 case 0:
286 fom['lan_ifnames'].value += ' ' + wl_ifaces[uidx][0];
287 break;
288 case 1:
289 fom['lan1_ifnames'].value += ' ' + wl_ifaces[uidx][0];
290 break;
291 case 2:
292 fom['lan2_ifnames'].value += ' ' + wl_ifaces[uidx][0];
293 break;
294 case 3:
295 fom['lan3_ifnames'].value += ' ' + wl_ifaces[uidx][0];
296 break;
299 /* REMOVE-BEGIN
300 // var lif = nvram['lan_ifnames'].split(' ');
301 // for (var j = 0; j < lif.length; j++) {
302 // fom['lan_ifnames'].value += (lif[j].indexOf('vlan') != -1) ? '' : lif[j];
303 // fom['lan_ifnames'].value += trailingSpace(fom['lan_ifnames'].value);
304 // }
305 // alert('lan_ifnames=' + fom['lan_ifnames'].value + '\n' +
306 // 'lan1_ifnames=' + fom['lan1_ifnames'].value + '\n' +
307 // 'lan2_ifnames=' + fom['lan2_ifnames'].value + '\n' +
308 // 'lan3_ifnames=' + fom['lan3_ifnames'].value);
309 REMOVE-END */
311 // for some models, Tomato checks for a few vital/crucial nvram settings at init time
312 // in some cases, if some/any of them are not found, a full nvram reset/clean could be triggered
313 // so, to (try to) play it safe, we check for the 1st needed/available/required
314 // VLAN for FastE (vlan0 is usually LAN) and GigE routers (vlan1 is usually LAN)
315 if((fom['vlan0ports'].value.length < 1) || (fom['vlan0hwname'].value.length < 1) ||
316 (fom['vlan1ports'].value.length < 1) || (fom['vlan1hwname'].value.length < 1))
317 fom['manual_boot_nv'].value = '1';
318 else
319 fom['manual_boot_nv'].value = nvram['manual_boot_nv'];
321 var e = E('footer-msg');
323 if(vlg.countWan() != 1) {
324 e.innerHTML = 'Cannot proceed: one VID must be assigned to WAN.';
325 e.style.visibility = 'visible';
326 setTimeout(
327 function() {
328 e.innerHTML = '';
329 e.style.visibility = 'hidden';
330 }, 5000);
331 return;
334 if(vlg.countLan(0) != 1) {
335 e.innerHTML = 'Cannot proceed: one and only one VID must be assigned to the primary LAN (br0).';
336 e.style.visibility = 'visible';
337 setTimeout(
338 function() {
339 e.innerHTML = '';
340 e.style.visibility = 'hidden';
341 }, 5000);
342 return;
345 if (v.length < 1) {
346 e.innerHTML = 'Cannot proceed without setting a default VID';
347 e.style.visibility = 'visible';
348 setTimeout(
349 function() {
350 e.innerHTML = '';
351 e.style.visibility = 'hidden';
352 }, 5000);
353 return;
356 if (confirm("Router must be rebooted to proceed. Commit changes to NVRAM and reboot now?"))
357 form.submit(fom, 0);
360 function trailingSpace(s)
362 return ((s.length>0)&&(s.charAt(s.length-1) != ' ')) ? ' ' : '';
365 if(port_vlan_supported) { // aka if(supported_hardware) block
366 var vlg = new TomatoGrid();
367 vlg.setup = function() {
368 this.init('vlan-grid', '', (MAX_VLAN_ID + 1), [
369 { 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>' },
370 { type: 'text', maxlen: 4, prefix: '<div class="centered">', suffix: '</div>' },
371 { type: 'checkbox', prefix: '<div class="centered">', suffix: '</div>' },
372 { type: 'checkbox', prefix: '<div class="centered">', suffix: '</div>' },
373 { type: 'checkbox', prefix: '<div class="centered">', suffix: '</div>' },
374 { type: 'checkbox', prefix: '<div class="centered">', suffix: '</div>' },
375 { type: 'checkbox', prefix: '<div class="centered">', suffix: '</div>' },
376 { type: 'checkbox', prefix: '<div class="centered">', suffix: '</div>' },
377 { type: 'checkbox', prefix: '<div class="centered">', suffix: '</div>' },
378 { type: 'checkbox', prefix: '<div class="centered">', suffix: '</div>' },
379 { type: 'checkbox', prefix: '<div class="centered">', suffix: '</div>' },
380 { type: 'checkbox', prefix: '<div class="centered">', suffix: '</div>' },
381 { type: 'checkbox', prefix: '<div class="centered">', suffix: '</div>' },
382 { 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>' }]);
384 this.headerSet(['VLAN', 'VID', 'Port 1', 'Tagged', 'Port 2', 'Tagged', 'Port 3', 'Tagged', 'Port 4', 'Tagged', 'WAN Port', 'Tagged', 'Default', 'Bridge']);
386 vlg.populate();
387 vlg.canDelete = false;
388 vlg.sort(0);
389 vlg.showNewEditor();
390 vlg.resetNewEditor();
393 vlg.populate = function() {
394 vlg.removeAllData();
396 // find out which vlans are supposed to be bridged to each LAN
397 var bridged = [];
399 for (var i = 0 ; i <= MAX_BRIDGE_ID ; i++) {
400 var j = (i == 0) ? '' : i.toString();
401 var l = nvram['lan' + j + '_ifnames'].split(' ');
402 /* REMOVE-BEGIN
403 // alert('lan' + j + '_ifnames=' + l);
404 REMOVE-END */
405 for (var k = 0 ; k < l.length; k++) {
406 /* REMOVE-BEGIN
407 // alert("bridge br" + i + "=vlan" + parseInt(l[k].replace('vlan','')));
408 REMOVE-END */
409 if(l[k].indexOf('vlan') != -1) {
410 /* REMOVE-BEGIN
411 // alert('lan' + j + '_ifname=br' + nvram['lan' + j + '_ifname'].replace('br',''));
412 REMOVE-END */
413 if (nvram['lan' + j + '_ifname'] != '')
414 bridged[parseInt(l[k].replace('vlan',''))] = (3 + parseInt(nvram['lan' + j + '_ifname'].replace('br',''))).toString();
415 else
416 bridged[parseInt(l[k].replace('vlan',''))] = '1';
418 // WLAN
419 for (var uidx = 0; uidx < wl_ifaces.length; ++uidx) {
420 if(l[k].indexOf(wl_ifaces[uidx][0]) != -1) {
421 E('_f_bridge_wlan'+wl_fface(uidx)+'_to').selectedIndex=i;
427 // WAN port
428 bridged[parseInt(nvram['wan_ifnameX'].replace('vlan',''))] = '2';
430 // go thru all possible VLANs
431 for (var i = 0 ; i <= MAX_VLAN_ID ; i++) {
432 var port = [];
433 var tagged = [];
434 if ((nvram['vlan' + i + 'hwname'].length > 0) || (nvram['vlan' + i + 'ports'].length > 0)) {
435 // (re)initialize our bitmap for this particular iteration
436 for (var j=0; j <= MAX_PORT_ID ; j++) {
437 port[j] = '0';
438 tagged[j] = '0';
440 // which ports are members of this VLAN?
441 var m=nvram['vlan' + i + 'ports'].split(' ');
442 for (var j = 0; j < (m.length) ; j++) {
443 port[parseInt(m[j].charAt(0))] = '1';
444 tagged[parseInt(m[j].charAt(0))] = (((trunk_vlan_supported) || (PORT_VLAN_SUPPORT_OVERRIDE)) && (m[j].indexOf('t') != -1)) ? '1' : '0';
447 if (port_vlan_supported) {
448 if((nvram['vlan' + i + 'ports']).indexOf('*') != -1)
449 SWITCH_INTERNAL_PORT=(nvram['vlan' + i + 'ports']).charAt((nvram['vlan' + i + 'ports']).indexOf('*')-1);
451 vlg.insertData(-1, [ i.toString(),
452 ((nvram['vlan' + i + 'vid'] != '') && (nvram['vlan' + i + 'vid'] > 0)) ? (nvram['vlan' + i + 'vid']).toString() : '0',
453 port[COL_P0N], tagged[COL_P0N],
454 port[COL_P1N], tagged[COL_P1N],
455 port[COL_P2N], tagged[COL_P2N],
456 port[COL_P3N], tagged[COL_P3N],
457 port[COL_P4N], tagged[COL_P4N],
458 (((nvram['vlan' + i + 'ports']).indexOf('*') != -1) ? '1' : '0' ),
459 (bridged[i] != null) ? bridged[i] : '1' ]);
465 vlg.countElem = function(f, v)
467 var data = this.getAllData();
468 var total = 0;
469 for (var i = 0; i < data.length; ++i) {
470 total += (data[i][f] == v) ? 1 : 0;
472 return total;
475 vlg.countDefaultVID = function()
477 return this.countElem(COL_VID_DEF,1);
480 vlg.countVID = function (v)
482 return this.countElem(COL_VID,v);
485 vlg.countWan = function()
487 return this.countElem(COL_BRI,2);
490 vlg.countLan = function(l)
492 return this.countElem(COL_BRI,l+3);
495 vlg.verifyFields = function(row, quiet) {
496 var valid = 1;
497 var f = fields.getAll(row);
499 for(var i=0; i<= MAX_VLAN_ID ; i++) {
500 f[COL_VID].options[i].disabled = (this.countVID(i) > 0);
503 for (var i=0; i <= MAX_BRIDGE_ID; i++) {
504 var j = (i==0) ? '' : i.toString();
505 f[COL_BRI].options[i+2].disabled = (nvram['lan' + j + '_ifname'].length < 1);
508 if (!v_range(f[COL_MAP], quiet, 0, 4094)) valid = 0;
510 if(((trunk_vlan_supported) || (PORT_VLAN_SUPPORT_OVERRIDE)) && (f[COL_P0].checked == 1)) {
511 f[COL_P0T].disabled=0;
512 /* REMOVE-BEGIN
513 // if((f[COL_P0T].checked==0) || (this.countElem(COL_P0,1)>0) )
514 // if(this.countElem(COL_P0,1)>0) {
515 // }
516 REMOVE-END */
517 } else {
518 f[COL_P0T].disabled=1;
519 f[COL_P0T].checked=0;
521 if(((trunk_vlan_supported) || (PORT_VLAN_SUPPORT_OVERRIDE)) && (f[COL_P1].checked == 1)) {
522 f[COL_P1T].disabled=0;
523 } else {
524 f[COL_P1T].disabled=1;
525 f[COL_P1T].checked=0;
527 if(((trunk_vlan_supported) || (PORT_VLAN_SUPPORT_OVERRIDE)) && (f[COL_P2].checked == 1)) {
528 f[COL_P2T].disabled=0;
529 } else {
530 f[COL_P2T].disabled=1;
531 f[COL_P2T].checked=0;
533 if(((trunk_vlan_supported) || (PORT_VLAN_SUPPORT_OVERRIDE)) && (f[COL_P3].checked == 1)) {
534 f[COL_P3T].disabled=0;
535 } else {
536 f[COL_P3T].disabled=1;
537 f[COL_P3T].checked=0;
539 if(((trunk_vlan_supported) || (PORT_VLAN_SUPPORT_OVERRIDE)) && (f[COL_P4].checked == 1)) {
540 f[COL_P4T].disabled=0;
541 } else {
542 f[COL_P4T].disabled=1;
543 f[COL_P4T].checked=0;
546 if ((f[COL_P0].checked == 1) && (this.countElem(COL_P0,1)>0)) {
547 if (((this.countElem(COL_P0,1) != this.countElem(COL_P0T,1)) || (f[COL_P0T].checked==0))) {
548 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);
549 valid=0;
550 } else {
551 ferror.clear(f[COL_P0T]);
554 if ((f[COL_P1].checked == 1) && (this.countElem(COL_P1,1)>0)) {
555 if (((this.countElem(COL_P1,1) != this.countElem(COL_P1T,1)) || (f[COL_P1T].checked==0))) {
556 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);
557 valid=0;
558 } else {
559 ferror.clear(f[COL_P1T]);
562 if ((f[COL_P2].checked == 1) && (this.countElem(COL_P2,1)>0)) {
563 if (((this.countElem(COL_P2,1) != this.countElem(COL_P2T,1)) || (f[COL_P2T].checked==0))) {
564 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);
565 valid=0;
566 } else {
567 ferror.clear(f[COL_P2T]);
570 if ((f[COL_P3].checked == 1) && (this.countElem(COL_P3,1)>0)) {
571 if (((this.countElem(COL_P3,1) != this.countElem(COL_P3T,1)) || (f[COL_P3T].checked==0))) {
572 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);
573 valid=0;
574 } else {
575 ferror.clear(f[COL_P3T]);
578 if ((f[COL_P4].checked == 1) && (this.countElem(COL_P4,1)>0)) {
579 if (((this.countElem(COL_P4,1) != this.countElem(COL_P4T,1)) || (f[COL_P4T].checked==0))) {
580 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);
581 valid=0;
582 } else {
583 ferror.clear(f[COL_P4T]);
587 if(this.countDefaultVID() > 0) {
588 f[COL_VID_DEF].disabled=1;
589 f[COL_VID_DEF].checked=0;
592 if((this.countDefaultVID() > 0) && (f[COL_VID_DEF].checked ==1)) {
593 ferror.set(f[COL_VID_DEF], 'Only one VID can be selected as the default VID', quiet);
594 valid = 0;
595 } else {
596 ferror.clear(f[COL_VID_DEF]);
599 if(this.countVID(f[COL_VID].selectedIndex) > 0) {
600 ferror.set(f[COL_VID], 'Cannot add more than one entry with VID ' + f[0].selectedIndex, quiet);
601 valid = 0;
602 } else {
603 ferror.clear(f[COL_VID]);
606 if ((this.countWan() > 0) && (f[COL_BRI].selectedIndex == 1)) {
607 ferror.set(f[COL_BRI],'Only one VID can be used as WAN at any time', quiet);
608 valid = 0;
609 } else {
610 ferror.clear(f[COL_BRI]);
613 for(var i=0; i<4; i++) {
614 if ((this.countLan(i) > 0) && (f[COL_BRI].selectedIndex == (i+2))) {
615 ferror.set(f[COL_BRI],'One and only one VID can be used for LAN' + ((i==0) ? '' : i ) + ' (br'+i+') at any time', quiet);
616 valid = 0;
617 } else {
618 ferror.clear(f[COL_BRI]);
622 return valid;
625 vlg.dataToView = function(data) {
626 return [data[COL_VID],
627 ((data[COL_MAP].toString() == '') || (data[COL_MAP].toString() == '0')) ? (parseInt(E('_vlan0tag').value) * 1 + data[COL_VID] *1 ).toString() : data[COL_MAP].toString(),
628 (data[COL_P0].toString() != '0') ? 'Yes' : '',
629 (data[COL_P0T].toString() != '0') ? 'On' : '',
630 (data[COL_P1].toString() != '0') ? 'Yes' : '',
631 (data[COL_P1T].toString() != '0') ? 'On' : '',
632 (data[COL_P2].toString() != '0') ? 'Yes' : '',
633 (data[COL_P2T].toString() != '0') ? 'On' : '',
634 (data[COL_P3].toString() != '0') ? 'Yes' : '',
635 (data[COL_P3T].toString() != '0') ? 'On' : '',
636 (data[COL_P4].toString() != '0') ? 'Yes' : '',
637 (data[COL_P4T].toString() != '0') ? 'On' : '',
638 (data[COL_VID_DEF].toString() != '0') ? '*' : '',
639 ['', 'WAN', 'LAN (br0)', 'LAN1 (br1)', 'LAN2 (br2)', 'LAN3 (br3)' ][data[COL_BRI] - 1]];
642 vlg.dataToFieldValues = function (data) {
643 return [data[COL_VID],
644 data[COL_MAP],
645 (data[COL_P0] != 0) ? 'checked' : '',
646 (data[COL_P0T] != 0) ? 'checked' : '',
647 (data[COL_P1] != 0) ? 'checked' : '',
648 (data[COL_P1T] != 0) ? 'checked' : '',
649 (data[COL_P2] != 0) ? 'checked' : '',
650 (data[COL_P2T] != 0) ? 'checked' : '',
651 (data[COL_P3] != 0) ? 'checked' : '',
652 (data[COL_P3T] != 0) ? 'checked' : '',
653 (data[COL_P4] != 0) ? 'checked' : '',
654 (data[COL_P4T] != 0) ? 'checked' : '',
655 (data[COL_VID_DEF] != 0) ? 'checked' : '',
656 data[COL_BRI]];
659 vlg.fieldValuesToData = function(row) {
660 var f = fields.getAll(row);
661 return [f[COL_VID].value,
662 f[COL_MAP].value,
663 f[COL_P0].checked ? 1 : 0,
664 f[COL_P0T].checked ? 1 : 0,
665 f[COL_P1].checked ? 1 : 0,
666 f[COL_P1T].checked ? 1 : 0,
667 f[COL_P2].checked ? 1 : 0,
668 f[COL_P2T].checked ? 1 : 0,
669 f[COL_P3].checked ? 1 : 0,
670 f[COL_P3T].checked ? 1 : 0,
671 f[COL_P4].checked ? 1 : 0,
672 f[COL_P4T].checked ? 1 : 0,
673 f[COL_VID_DEF].checked ? 1 : 0,
674 f[COL_BRI].value];
677 vlg.onCancel = function() {
678 this.removeEditor();
679 this.showSource();
680 this.disableNewEditor(false);
682 this.resetNewEditor();
685 vlg.onAdd = function() {
686 var data;
688 this.moving = null;
689 this.rpHide();
691 if (!this.verifyFields(this.newEditor, false)) return;
693 data = this.fieldValuesToData(this.newEditor);
694 this.insertData(-1, data);
696 this.disableNewEditor(false);
697 this.resetNewEditor();
699 this.resort();
702 vlg.onOK = function() {
703 var i, data, view;
705 if (!this.verifyFields(this.editor, false)) return;
707 data = this.fieldValuesToData(this.editor);
708 view = this.dataToView(data);
710 this.source.setRowData(data);
711 for (i = 0; i < this.source.cells.length; ++i) {
712 this.source.cells[i].innerHTML = view[i];
715 this.removeEditor();
716 this.showSource();
717 this.disableNewEditor(false);
719 this.resetNewEditor();
720 this.resort();
723 vlg.onDelete = function() {
724 this.removeEditor();
725 elem.remove(this.source);
726 this.source = null;
727 this.disableNewEditor(false);
729 this.resetNewEditor();
732 vlg.sortCompare = function(a, b) {
733 var obj = TGO(a);
734 var col = obj.sortColumn;
735 if (this.sortColumn == 0) {
736 var r = cmpInt(parseInt(a.cells[col].innerHTML), parseInt(b.cells[col].innerHTML));
737 } else {
738 var r = cmpText(a.cells[col].innerHTML, b.cells[col].innerHTML);
740 return obj.sortAscending ? r : -r;
743 vlg.resetNewEditor = function() {
744 var f = fields.getAll(this.newEditor);
746 for (var i=0; i <= MAX_BRIDGE_ID; i++) {
747 var j = (i==0) ? '' : i.toString();
748 f[COL_BRI].options[i+2].disabled = (nvram['lan' + j + '_ifname'].length < 1);
751 f[COL_MAP].value = '0';
753 f[COL_VID].selectedIndex=0;
754 var t = MAX_VLAN_ID;
755 while((this.countVID(f[COL_VID].selectedIndex) > 0) && (t > 0)) {
756 f[COL_VID].selectedIndex = (f[COL_VID].selectedIndex%(MAX_VLAN_ID))+1;
757 t--;
760 for(var i=0; i<= MAX_VLAN_ID ; i++) {
761 f[COL_VID].options[i].disabled = (this.countVID(i) > 0);
764 f[COL_P0].checked = 0;
765 f[COL_P0T].checked = 0;
766 f[COL_P0T].disabled = 1;
767 f[COL_P1].checked = 0;
768 f[COL_P1T].checked = 0;
769 f[COL_P1T].disabled = 1;
770 f[COL_P2].checked = 0;
771 f[COL_P2T].checked = 0;
772 f[COL_P2T].disabled = 1;
773 f[COL_P3].checked = 0;
774 f[COL_P3T].checked = 0;
775 f[COL_P3T].disabled = 1;
776 f[COL_P4].checked = 0;
777 f[COL_P4T].checked = 0;
778 f[COL_P4T].disabled = 1;
779 f[COL_VID_DEF].checked = 0;
780 if (this.countDefaultVID()>0)
781 f[COL_VID_DEF].disabled = 1;
782 f[COL_BRI].selectedIndex = 0;
783 ferror.clearAll(fields.getAll(this.newEditor));
785 } // end of the so-called if(supported_device) block
787 function init() {
788 if(port_vlan_supported) {
789 vlg.recolor();
790 vlg.resetNewEditor();
791 var c;
792 if (((c = cookie.get('advanced_vlan_notes_vis')) != null) && (c == '1')) toggleVisibility("notes");
793 if (((c = cookie.get('advanced_vlan_wireless_vis')) != null) && (c == '1')) toggleVisibility("wireless");
794 if (((c = cookie.get('advanced_vlan_vidmap_vis')) != null) && (c == '1')) toggleVisibility("vidmap");
798 function toggleVisibility(whichone) {
799 if (E('sesdiv_' + whichone).style.display == '') {
800 E('sesdiv_' + whichone).style.display = 'none';
801 E('sesdiv_' + whichone + '_showhide').innerHTML = '(Click here to show)';
802 cookie.set('advanced_vlan_' + whichone + '_vis', 0);
803 } else {
804 E('sesdiv_' + whichone).style.display='';
805 E('sesdiv_' + whichone + '_showhide').innerHTML = '(Click here to hide)';
806 cookie.set('advanced_vlan_' + whichone + '_vis', 1);
810 function earlyInit() {
811 if(!port_vlan_supported) {
812 E('save-button').disabled = 1;
813 return;
815 PORT_VLAN_SUPPORT_OVERRIDE = ((nvram['trunk_vlan_so'] == '1') ? 1 : 0);
818 </script>
819 </head>
820 <body onload='init()'>
821 <form id='_fom' method='post' action='tomato.cgi'>
822 <table id='container' cellspacing=0>
823 <tr><td colspan=2 id='header'>
824 <div class='title'>Tomato</div>
825 <div class='version'>Version <% version(); %></div>
826 </td></tr>
827 <tr id='body'><td id='navi'><script type='text/javascript'>navi()</script></td>
828 <td id='content'>
829 <div id='ident'><% ident(); %></div>
830 <input type='hidden' name='_nextpage' value='advanced-vlan.asp'>
831 <input type='hidden' name='_nextwait' value='30'>
832 <input type='hidden' name='_reboot' value='1'>
833 <input type='hidden' name='_nvset' value='1'>
834 <input type='hidden' name='_commit' value='1'>
835 <input type='hidden' name='vlan0ports'>
836 <input type='hidden' name='vlan1ports'>
837 <input type='hidden' name='vlan2ports'>
838 <input type='hidden' name='vlan3ports'>
839 <input type='hidden' name='vlan4ports'>
840 <input type='hidden' name='vlan5ports'>
841 <input type='hidden' name='vlan6ports'>
842 <input type='hidden' name='vlan7ports'>
843 <input type='hidden' name='vlan8ports'>
844 <input type='hidden' name='vlan9ports'>
845 <input type='hidden' name='vlan10ports'>
846 <input type='hidden' name='vlan11ports'>
847 <input type='hidden' name='vlan12ports'>
848 <input type='hidden' name='vlan13ports'>
849 <input type='hidden' name='vlan14ports'>
850 <input type='hidden' name='vlan15ports'>
851 <input type='hidden' name='vlan0hwname'>
852 <input type='hidden' name='vlan1hwname'>
853 <input type='hidden' name='vlan2hwname'>
854 <input type='hidden' name='vlan3hwname'>
855 <input type='hidden' name='vlan4hwname'>
856 <input type='hidden' name='vlan5hwname'>
857 <input type='hidden' name='vlan6hwname'>
858 <input type='hidden' name='vlan7hwname'>
859 <input type='hidden' name='vlan8hwname'>
860 <input type='hidden' name='vlan9hwname'>
861 <input type='hidden' name='vlan10hwname'>
862 <input type='hidden' name='vlan11hwname'>
863 <input type='hidden' name='vlan12hwname'>
864 <input type='hidden' name='vlan13hwname'>
865 <input type='hidden' name='vlan14hwname'>
866 <input type='hidden' name='vlan15hwname'>
867 <input type='hidden' name='wan_ifnameX'>
868 <input type='hidden' name='manual_boot_nv'>
869 <input type='hidden' name='lan_ifnames'>
870 <input type='hidden' name='lan1_ifnames'>
871 <input type='hidden' name='lan2_ifnames'>
872 <input type='hidden' name='lan3_ifnames'>
873 <input type='hidden' name='trunk_vlan_so'>
874 <input type='hidden' name='vlan0vid'>
875 <input type='hidden' name='vlan1vid'>
876 <input type='hidden' name='vlan2vid'>
877 <input type='hidden' name='vlan3vid'>
878 <input type='hidden' name='vlan4vid'>
879 <input type='hidden' name='vlan5vid'>
880 <input type='hidden' name='vlan6vid'>
881 <input type='hidden' name='vlan7vid'>
882 <input type='hidden' name='vlan8vid'>
883 <input type='hidden' name='vlan9vid'>
884 <input type='hidden' name='vlan10vid'>
885 <input type='hidden' name='vlan11vid'>
886 <input type='hidden' name='vlan12vid'>
887 <input type='hidden' name='vlan13vid'>
888 <input type='hidden' name='vlan14vid'>
889 <input type='hidden' name='vlan15vid'>
891 <div id='sesdiv' style='display:none'>
892 <div class='section-title'>VLAN</div>
893 <div class='section'>
894 <table class='tomato-grid' cellspacing=1 id='vlan-grid'></table>
895 </div>
897 <!-- / / / -->
899 <div class='section-title'>VID Offset <small><i><a href='javascript:toggleVisibility("vidmap");'><span id='sesdiv_vidmap_showhide'>(Click here to show)</span></a></i></small></div>
900 <div class='section' id='sesdiv_vidmap' style='display:none'>
901 <script type='text/javascript'>
902 createFieldTable('', [
903 { title: 'First 802.1Q VLAN tag', name: 'vlan0tag', type: 'text', maxlen:4, size:6,
904 value: fixInt(nvram.vlan0tag, 0, 4080, 0),
905 suffix: ' <small><i>(range: 0 - 4080; must be a multiple of 16; set to 0 to disable)</i></small>' }
907 </script>
908 </div>
910 <!-- / / / -->
912 <div class='section-title'>Wireless <small><i><a href='javascript:toggleVisibility("wireless");'><span id='sesdiv_wireless_showhide'>(Click here to show)</span></a></i></small></div>
913 <div class='section' id='sesdiv_wireless' style='display:none'>
914 <script type='text/javascript'>
915 var f = [];
916 for (var uidx = 0; uidx < wl_ifaces.length; ++uidx) {
917 var u = wl_fface(uidx);
918 f.push(
919 { title: ('Bridge ' + wl_ifaces[uidx][0] + ' to'), name: ('f_bridge_wlan'+u+'_to'), type: 'select',
920 options: [[0,'LAN (br0)'],[1,'LAN1 (br1)'],[2,'LAN2 (br2)'],[3,'LAN3 (br3)'],[4,'none']], value: 4 } );
922 createFieldTable('',f);
923 if(port_vlan_supported) vlg.setup();
924 </script>
925 </div>
927 <!-- / / / -->
929 <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>
930 <div class='section' id='sesdiv_notes' style='display:none'>
931 <ul>
932 <li><b>VLAN</b> - Unique identifier of a VLAN.</li>
933 <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>
934 <li><b>Ports 1-4 &amp; WAN</b> - Which ethernet ports on the router should be members of this VLAN.</li>
935 <li><b>Tagged</b> - Enable 802.1Q tagging of ethernet frames on a particular port/VLAN
936 <script type='text/javascript'>
937 if(!trunk_vlan_supported)
938 W(' <i>(not known to be supported on this model)</i>');
939 </script>
940 </li>
941 <li><b>Default</b> - VLAN ID assigned to untagged frames received by the router.</li>
942 <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>
943 </ul>
945 <ul>
946 <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>
947 </ul>
949 <ul>
950 <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>
951 </ul>
953 <small>
954 <ul>
955 <li><b>Other relevant notes/hints:</b>
956 <ul>
957 <li>One VID <i>must</i> be assigned to WAN.</li>
958 <li>One VID <i>must</i> be selected as the default.</li>
959 <script type='text/javascript'>
960 if((trunk_vlan_supported) || (nvram.trunk_vlan_so == '1')) {
961 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>');
962 W('<li>It may be also recommended to avoid using VID "1" as some vendors consider it special/reserved (for management purposes).</li>');
964 </script>
965 </ul>
966 <br>
967 <ul>
968 <li>This is highly <b>experimental</b> 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>
969 <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>
970 <li>You've been warned!</li>
971 </ul>
972 </ul>
973 <div id='trunk_vlan_override' style='display:none'>
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>
982 </div>
983 </div>
984 </small>
985 </div>
986 </div>
987 <script type='text/javascript'>
988 if(!port_vlan_supported)
989 W('<i>This feature is not supported on this router.</i>');
990 else {
991 E('sesdiv').style.display = '';
992 if(!trunk_vlan_supported)
993 E('trunk_vlan_override').style.display = '';
995 </script>
996 </td></tr>
997 <tr><td id='footer' colspan=2>
998 <span id='footer-msg'></span>
999 <input type='button' value='Save' id='save-button' onclick='save()'>
1000 <input type='button' value='Cancel' id='cancel-button' onclick='javascript:reloadPage();'>
1001 </td></tr>
1002 </table>
1003 </form>
1004 <script type='text/javascript'>earlyInit(); verifyFields(null,1);</script>
1005 </body>
1006 </html>