cleanup
[tomato.git] / release / src / router / www / advanced-vlan.asp
blob5da5cc0667de6b8b39ad57e6447d892218847988
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,boardnum,boardrev,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,model");%>
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 trunk_vlan_supported = 1;
73 break;
74 default:
75 break;
78 // TESTED ONLY ON WRT54G v2 (boardtype 0x0101),WRT54GL v1.1 (boardtype 0x0467) and WNR3500L (boardtype 0x04cf)
79 // info on some of these boardtypes/routers obtained from
80 // http://wiki.openwrt.org/toh/asus/start
81 // http://wiki.openwrt.org/toh/linksys/start
82 // http://wiki.openwrt.org/toh/start
83 switch(nvram['boardtype']) {
84 case '0x0467': // WRT54GL 1.x, WRT54GS 3.x/4.x
85 if (nvram['boardrev'] == '0x13') { // WHR-G54S
86 COL_P0N = '1';
87 COL_P1N = '2';
88 COL_P2N = '3';
89 COL_P3N = '4';
90 COL_P4N = '0';
91 break;
93 case '0xa4cf': // Belkin F7D3301
94 if (nvram['boardrev'] == '0x1100'){ //Belkin F5D8235-4 v3
95 COL_P0N = '1';
96 COL_P1N = '2';
97 COL_P2N = '3';
98 COL_P3N = '4';
99 COL_P4N = '0';
100 break;
102 case '0xd4cf': // Belkin F7D4301
103 case '0x048e': // WL-520GU, WL-500G Premium v2
104 COL_P0N = '3';
105 COL_P1N = '2';
106 COL_P2N = '1';
107 COL_P3N = '0';
108 COL_P4N = '4';
109 break;
110 case '0x04ef': // WRT320N/E2000
111 case '0x04cf': // WRT610Nv2/E3000, RT-N16, WNR3500L
112 COL_P0N = '4';
113 COL_P1N = '3';
114 COL_P2N = '2';
115 COL_P3N = '1';
116 COL_P4N = '0';
117 break;
118 case '0xf52c': // E4200v1
119 COL_P0N = '0';
120 COL_P1N = '1';
121 COL_P2N = '2';
122 COL_P3N = '3';
123 COL_P4N = '4';
124 break;
125 // should work on WRT54G v2/v3, WRT54GS v1/v2 and others
126 default:
127 COL_P0N = '1';
128 COL_P1N = '2';
129 COL_P2N = '3';
130 COL_P3N = '4';
131 COL_P4N = '0';
132 break;
135 var COL_VID = 0;
136 var COL_MAP = 1;
137 var COL_P0 = 2;
138 var COL_P0T = 3;
139 var COL_P1 = 4;
140 var COL_P1T = 5;
141 var COL_P2 = 6;
142 var COL_P2T = 7;
143 var COL_P3 = 8;
144 var COL_P3T = 9;
145 var COL_P4 = 10;
146 var COL_P4T = 11;
147 var COL_VID_DEF = 12;
148 var COL_BRI = 13;
150 var vlt = nvram.vlan0tag | '0';
152 // set to either 5 or 8 when nvram settings are read (FastE or GigE routers)
153 var SWITCH_INTERNAL_PORT=0;
154 // option made available for experimental purposes on routers known to support port-based VLANs, but not confirmed to support 801.11q trunks
155 var PORT_VLAN_SUPPORT_OVERRIDE = ((nvram['trunk_vlan_so'] == '1') ? 1 : 0);
157 function verifyFields(focused, quiet){
158 PORT_VLAN_SUPPORT_OVERRIDE=(E('_f_trunk_vlan_so').checked ? 1 : 0);
159 for (var uidx = 0; uidx < wl_ifaces.length; ++uidx) {
160 var u = wl_fface(uidx);
161 var wlan = E('_f_bridge_wlan'+u+'_to');
162 if(nvram.lan_ifname.length < 1)
163 wlan.options[0].disabled=true;
164 if(nvram.lan1_ifname.length < 1)
165 wlan.options[1].disabled=true;
166 if(nvram.lan2_ifname.length < 1)
167 wlan.options[2].disabled=true;
168 if(nvram.lan3_ifname.length < 1)
169 wlan.options[3].disabled=true;
171 var e = E('_vlan0tag');
172 if (!v_range('_vlan0tag', quiet, 0, 4080)) return 0;
173 var v = parseInt(e.value);
174 e.value = v - (v % 16);
175 if ((e.value != vlt) && (typeof(vlg) != 'undefined')) {
176 vlg.populate();
177 vlt = e.value;
179 return 1;
182 function save() {
183 if (vlg.isEditing()) return;
185 var fom = E('_fom');
186 fom.trunk_vlan_so.value = (E('_f_trunk_vlan_so').checked ? 1 : 0);
187 // wipe out relevant fields just in case this is not the first time we try to submit
188 for (var i = 0 ; i <= MAX_VLAN_ID ; i++) {
189 fom['vlan' + i + 'ports'].value = '';
190 fom['vlan' + i + 'hwname'].value = '';
191 fom['vlan' + i + 'vid'].value = '';
193 fom['wan_ifnameX'].value = '';
194 fom['lan_ifnames'].value = '';
195 fom['lan1_ifnames'].value = '';
196 fom['lan2_ifnames'].value = '';
197 fom['lan3_ifnames'].value = '';
199 var v = '';
200 var d = vlg.getAllData();
202 for (var i = 0; i < d.length; ++i) {
203 var p = '';
204 p += (d[i][COL_P0].toString() != '0') ? COL_P0N : '';
205 p += (((trunk_vlan_supported) || (PORT_VLAN_SUPPORT_OVERRIDE)) && (d[i][COL_P0T].toString() != '0')) ? 't' : '';
206 p += trailingSpace(p);
208 p += (d[i][COL_P1].toString() != '0') ? COL_P1N : '';
209 p += (((trunk_vlan_supported) || (PORT_VLAN_SUPPORT_OVERRIDE)) && (d[i][COL_P1T].toString() != '0')) ? 't' : '';
210 p += trailingSpace(p);
212 p += (d[i][COL_P2].toString() != '0') ? COL_P2N : '';
213 p += (((trunk_vlan_supported) || (PORT_VLAN_SUPPORT_OVERRIDE)) && (d[i][COL_P2T].toString() != '0')) ? 't' : '';
214 p += trailingSpace(p);
216 p += (d[i][COL_P3].toString() != '0') ? COL_P3N : '';
217 p += (((trunk_vlan_supported) || (PORT_VLAN_SUPPORT_OVERRIDE)) && (d[i][COL_P3T].toString() != '0')) ? 't' : '';
218 p += trailingSpace(p);
220 p += (d[i][COL_P4].toString() != '0') ? COL_P4N : '';
221 p += (((trunk_vlan_supported) || (PORT_VLAN_SUPPORT_OVERRIDE)) && (d[i][COL_P4T].toString() != '0')) ? 't' : '';
222 p += trailingSpace(p);
224 p += (d[i][COL_VID_DEF].toString() != '0') ? (SWITCH_INTERNAL_PORT + '*') : SWITCH_INTERNAL_PORT;
226 // arrange port numbers in ascending order just to be safe (not sure if this is really needed... mostly, cosmetics?)
227 p = p.split(" ");
228 p = p.sort(cmpInt);
229 p = p.join(" ");
231 v += (d[i][COL_VID_DEF].toString() != '0') ? d[i][0] : '';
233 fom['vlan'+d[i][COL_VID]+'ports'].value = p;
234 fom['vlan'+d[i][COL_VID]+'hwname'].value = 'et0';
235 fom['vlan'+d[i][COL_VID]+'vid'].value = ((d[i][COL_MAP].toString() != '') && (d[i][COL_MAP].toString() != '0')) ? d[i][COL_MAP] : '';
237 fom['wan_ifnameX'].value += (d[i][COL_BRI] == '2') ? 'vlan'+d[i][0] : '';
238 fom['lan_ifnames'].value += (d[i][COL_BRI] == '3') ? 'vlan'+d[i][0] : '';
239 /* REMOVE-BEGIN
240 // fom['lan_ifnames'].value += trailingSpace(fom['lan_ifnames'].value);
241 // 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);
242 REMOVE-END */
243 fom['lan1_ifnames'].value += (d[i][COL_BRI] == '4') ? 'vlan'+d[i][0] : '';
244 fom['lan2_ifnames'].value += (d[i][COL_BRI] == '5') ? 'vlan'+d[i][0] : '';
245 fom['lan3_ifnames'].value += (d[i][COL_BRI] == '6') ? 'vlan'+d[i][0] : '';
248 for (var uidx = 0; uidx < wl_ifaces.length; ++uidx) {
249 var u = wl_fface(uidx);
250 var wlan = E('_f_bridge_wlan'+u+'_to');
251 /* REMOVE-BEGIN
252 // var wlan = E('_f_bridge_wlan_to');
253 // alert(wlan.selectedIndex);
254 REMOVE-END */
255 switch(parseInt(wlan.selectedIndex)) {
256 case 0:
257 fom['lan_ifnames'].value += ' ' + wl_ifaces[uidx][0];
258 break;
259 case 1:
260 fom['lan1_ifnames'].value += ' ' + wl_ifaces[uidx][0];
261 break;
262 case 2:
263 fom['lan2_ifnames'].value += ' ' + wl_ifaces[uidx][0];
264 break;
265 case 3:
266 fom['lan3_ifnames'].value += ' ' + wl_ifaces[uidx][0];
267 break;
270 /* REMOVE-BEGIN
271 // var lif = nvram['lan_ifnames'].split(' ');
272 // for (var j = 0; j < lif.length; j++) {
273 // fom['lan_ifnames'].value += (lif[j].indexOf('vlan') != -1) ? '' : lif[j];
274 // fom['lan_ifnames'].value += trailingSpace(fom['lan_ifnames'].value);
275 // }
276 // alert('lan_ifnames=' + fom['lan_ifnames'].value + '\n' +
277 // 'lan1_ifnames=' + fom['lan1_ifnames'].value + '\n' +
278 // 'lan2_ifnames=' + fom['lan2_ifnames'].value + '\n' +
279 // 'lan3_ifnames=' + fom['lan3_ifnames'].value);
280 REMOVE-END */
282 fom['manual_boot_nv'].value = 1 //Prevent vlan reset to default
284 var e = E('footer-msg');
286 if(vlg.countWan() != 1) {
287 e.innerHTML = 'Cannot proceed: one VID must be assigned to WAN.';
288 e.style.visibility = 'visible';
289 setTimeout(
290 function() {
291 e.innerHTML = '';
292 e.style.visibility = 'hidden';
293 }, 5000);
294 return;
297 if(vlg.countLan(0) != 1) {
298 e.innerHTML = 'Cannot proceed: one and only one VID must be assigned to the primary LAN (br0).';
299 e.style.visibility = 'visible';
300 setTimeout(
301 function() {
302 e.innerHTML = '';
303 e.style.visibility = 'hidden';
304 }, 5000);
305 return;
308 if (v.length < 1) {
309 e.innerHTML = 'Cannot proceed without setting a default VID';
310 e.style.visibility = 'visible';
311 setTimeout(
312 function() {
313 e.innerHTML = '';
314 e.style.visibility = 'hidden';
315 }, 5000);
316 return;
319 if (confirm("Router must be rebooted to proceed. Commit changes to NVRAM and reboot now?"))
320 form.submit(fom, 0);
323 function trailingSpace(s)
325 return ((s.length>0)&&(s.charAt(s.length-1) != ' ')) ? ' ' : '';
328 if(port_vlan_supported) { // aka if(supported_hardware) block
329 var vlg = new TomatoGrid();
330 vlg.setup = function() {
331 this.init('vlan-grid', '', (MAX_VLAN_ID + 1), [
332 { 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>' },
333 { type: 'text', maxlen: 4, prefix: '<div class="centered">', suffix: '</div>' },
334 { type: 'checkbox', prefix: '<div class="centered">', suffix: '</div>' },
335 { type: 'checkbox', prefix: '<div class="centered">', suffix: '</div>' },
336 { type: 'checkbox', prefix: '<div class="centered">', suffix: '</div>' },
337 { type: 'checkbox', prefix: '<div class="centered">', suffix: '</div>' },
338 { type: 'checkbox', prefix: '<div class="centered">', suffix: '</div>' },
339 { type: 'checkbox', prefix: '<div class="centered">', suffix: '</div>' },
340 { type: 'checkbox', prefix: '<div class="centered">', suffix: '</div>' },
341 { type: 'checkbox', prefix: '<div class="centered">', suffix: '</div>' },
342 { type: 'checkbox', prefix: '<div class="centered">', suffix: '</div>' },
343 { type: 'checkbox', prefix: '<div class="centered">', suffix: '</div>' },
344 { type: 'checkbox', prefix: '<div class="centered">', suffix: '</div>' },
345 { type: 'select', options: [[1, 'none'],[2, 'WAN'],[3, 'LAN (br0)'],[4, 'LAN1 (br1)'],[5, 'LAN2 (br2)'],[6, 'LAN3 (br3)'],
346 ], prefix: '<div class="centered">', suffix: '</div>' }]);
348 this.headerSet(['VLAN', 'VID', 'Port 1', 'Tagged', 'Port 2', 'Tagged', 'Port 3', 'Tagged', 'Port 4', 'Tagged', 'WAN Port', 'Tagged', 'Default', 'Bridge']);
350 vlg.populate();
351 vlg.canDelete = false;
352 vlg.sort(0);
353 vlg.showNewEditor();
354 vlg.resetNewEditor();
357 vlg.populate = function() {
358 vlg.removeAllData();
360 // find out which vlans are supposed to be bridged to each LAN
361 var bridged = [];
363 for (var i = 0 ; i <= MAX_BRIDGE_ID ; i++) {
364 var j = (i == 0) ? '' : i.toString();
365 var l = nvram['lan' + j + '_ifnames'].split(' ');
366 /* REMOVE-BEGIN
367 // alert('lan' + j + '_ifnames=' + l);
368 REMOVE-END */
369 for (var k = 0 ; k < l.length; k++) {
370 /* REMOVE-BEGIN
371 // alert("bridge br" + i + "=vlan" + parseInt(l[k].replace('vlan','')));
372 REMOVE-END */
373 if(l[k].indexOf('vlan') != -1) {
374 /* REMOVE-BEGIN
375 // alert('lan' + j + '_ifname=br' + nvram['lan' + j + '_ifname'].replace('br',''));
376 REMOVE-END */
377 if (nvram['lan' + j + '_ifname'] != '')
378 bridged[parseInt(l[k].replace('vlan',''))] = (3 + parseInt(nvram['lan' + j + '_ifname'].replace('br',''))).toString();
379 else
380 bridged[parseInt(l[k].replace('vlan',''))] = '1';
382 // WLAN
383 for (var uidx = 0; uidx < wl_ifaces.length; ++uidx) {
384 if(l[k].indexOf(wl_ifaces[uidx][0]) != -1) {
385 E('_f_bridge_wlan'+wl_fface(uidx)+'_to').selectedIndex=i;
391 // WAN port
392 bridged[parseInt(nvram['wan_ifnameX'].replace('vlan',''))] = '2';
394 // go thru all possible VLANs
395 for (var i = 0 ; i <= MAX_VLAN_ID ; i++) {
396 var port = [];
397 var tagged = [];
398 if ((nvram['vlan' + i + 'hwname'].length > 0) || (nvram['vlan' + i + 'ports'].length > 0)) {
399 // (re)initialize our bitmap for this particular iteration
400 for (var j=0; j <= MAX_PORT_ID ; j++) {
401 port[j] = '0';
402 tagged[j] = '0';
404 // which ports are members of this VLAN?
405 var m=nvram['vlan' + i + 'ports'].split(' ');
406 for (var j = 0; j < (m.length) ; j++) {
407 port[parseInt(m[j].charAt(0))] = '1';
408 tagged[parseInt(m[j].charAt(0))] = (((trunk_vlan_supported) || (PORT_VLAN_SUPPORT_OVERRIDE)) && (m[j].indexOf('t') != -1)) ? '1' : '0';
411 if (port_vlan_supported) {
412 if((nvram['vlan' + i + 'ports']).indexOf('*') != -1)
413 SWITCH_INTERNAL_PORT=(nvram['vlan' + i + 'ports']).charAt((nvram['vlan' + i + 'ports']).indexOf('*')-1);
415 vlg.insertData(-1, [ i.toString(),
416 ((nvram['vlan' + i + 'vid'] != '') && (nvram['vlan' + i + 'vid'] > 0)) ? (nvram['vlan' + i + 'vid']).toString() : '0',
417 port[COL_P0N], tagged[COL_P0N],
418 port[COL_P1N], tagged[COL_P1N],
419 port[COL_P2N], tagged[COL_P2N],
420 port[COL_P3N], tagged[COL_P3N],
421 port[COL_P4N], tagged[COL_P4N],
422 (((nvram['vlan' + i + 'ports']).indexOf('*') != -1) ? '1' : '0' ),
423 (bridged[i] != null) ? bridged[i] : '1' ]);
429 vlg.countElem = function(f, v)
431 var data = this.getAllData();
432 var total = 0;
433 for (var i = 0; i < data.length; ++i) {
434 total += (data[i][f] == v) ? 1 : 0;
436 return total;
439 vlg.countDefaultVID = function()
441 return this.countElem(COL_VID_DEF,1);
444 vlg.countVID = function (v)
446 return this.countElem(COL_VID,v);
449 vlg.countWan = function()
451 return this.countElem(COL_BRI,2);
454 vlg.countLan = function(l)
456 return this.countElem(COL_BRI,l+3);
459 vlg.verifyFields = function(row, quiet) {
460 var valid = 1;
461 var f = fields.getAll(row);
463 for(var i=0; i<= MAX_VLAN_ID ; i++) {
464 f[COL_VID].options[i].disabled = (this.countVID(i) > 0);
467 for (var i=0; i <= MAX_BRIDGE_ID; i++) {
468 var j = (i==0) ? '' : i.toString();
469 f[COL_BRI].options[i+2].disabled = (nvram['lan' + j + '_ifname'].length < 1);
472 if (!v_range(f[COL_MAP], quiet, 0, 4094)) valid = 0;
474 if(((trunk_vlan_supported) || (PORT_VLAN_SUPPORT_OVERRIDE)) && (f[COL_P0].checked == 1)) {
475 f[COL_P0T].disabled=0;
476 /* REMOVE-BEGIN
477 // if((f[COL_P0T].checked==0) || (this.countElem(COL_P0,1)>0) )
478 // if(this.countElem(COL_P0,1)>0) {
479 // }
480 REMOVE-END */
481 } else {
482 f[COL_P0T].disabled=1;
483 f[COL_P0T].checked=0;
485 if(((trunk_vlan_supported) || (PORT_VLAN_SUPPORT_OVERRIDE)) && (f[COL_P1].checked == 1)) {
486 f[COL_P1T].disabled=0;
487 } else {
488 f[COL_P1T].disabled=1;
489 f[COL_P1T].checked=0;
491 if(((trunk_vlan_supported) || (PORT_VLAN_SUPPORT_OVERRIDE)) && (f[COL_P2].checked == 1)) {
492 f[COL_P2T].disabled=0;
493 } else {
494 f[COL_P2T].disabled=1;
495 f[COL_P2T].checked=0;
497 if(((trunk_vlan_supported) || (PORT_VLAN_SUPPORT_OVERRIDE)) && (f[COL_P3].checked == 1)) {
498 f[COL_P3T].disabled=0;
499 } else {
500 f[COL_P3T].disabled=1;
501 f[COL_P3T].checked=0;
503 if(((trunk_vlan_supported) || (PORT_VLAN_SUPPORT_OVERRIDE)) && (f[COL_P4].checked == 1)) {
504 f[COL_P4T].disabled=0;
505 } else {
506 f[COL_P4T].disabled=1;
507 f[COL_P4T].checked=0;
510 if ((f[COL_P0].checked == 1) && (this.countElem(COL_P0,1)>0)) {
511 if (((this.countElem(COL_P0,1) != this.countElem(COL_P0T,1)) || (f[COL_P0T].checked==0))) {
512 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);
513 valid=0;
514 } else {
515 ferror.clear(f[COL_P0T]);
518 if ((f[COL_P1].checked == 1) && (this.countElem(COL_P1,1)>0)) {
519 if (((this.countElem(COL_P1,1) != this.countElem(COL_P1T,1)) || (f[COL_P1T].checked==0))) {
520 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);
521 valid=0;
522 } else {
523 ferror.clear(f[COL_P1T]);
526 if ((f[COL_P2].checked == 1) && (this.countElem(COL_P2,1)>0)) {
527 if (((this.countElem(COL_P2,1) != this.countElem(COL_P2T,1)) || (f[COL_P2T].checked==0))) {
528 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);
529 valid=0;
530 } else {
531 ferror.clear(f[COL_P2T]);
534 if ((f[COL_P3].checked == 1) && (this.countElem(COL_P3,1)>0)) {
535 if (((this.countElem(COL_P3,1) != this.countElem(COL_P3T,1)) || (f[COL_P3T].checked==0))) {
536 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);
537 valid=0;
538 } else {
539 ferror.clear(f[COL_P3T]);
542 if ((f[COL_P4].checked == 1) && (this.countElem(COL_P4,1)>0)) {
543 if (((this.countElem(COL_P4,1) != this.countElem(COL_P4T,1)) || (f[COL_P4T].checked==0))) {
544 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);
545 valid=0;
546 } else {
547 ferror.clear(f[COL_P4T]);
551 if(this.countDefaultVID() > 0) {
552 f[COL_VID_DEF].disabled=1;
553 f[COL_VID_DEF].checked=0;
556 if((this.countDefaultVID() > 0) && (f[COL_VID_DEF].checked ==1)) {
557 ferror.set(f[COL_VID_DEF], 'Only one VID can be selected as the default VID', quiet);
558 valid = 0;
559 } else {
560 ferror.clear(f[COL_VID_DEF]);
563 if(this.countVID(f[COL_VID].selectedIndex) > 0) {
564 ferror.set(f[COL_VID], 'Cannot add more than one entry with VID ' + f[0].selectedIndex, quiet);
565 valid = 0;
566 } else {
567 ferror.clear(f[COL_VID]);
570 if ((this.countWan() > 0) && (f[COL_BRI].selectedIndex == 1)) {
571 ferror.set(f[COL_BRI],'Only one VID can be used as WAN at any time', quiet);
572 valid = 0;
573 } else {
574 ferror.clear(f[COL_BRI]);
577 for(var i=0; i<4; i++) {
578 if ((this.countLan(i) > 0) && (f[COL_BRI].selectedIndex == (i+2))) {
579 ferror.set(f[COL_BRI],'One and only one VID can be used for LAN' + ((i==0) ? '' : i ) + ' (br'+i+') at any time', quiet);
580 valid = 0;
581 } else {
582 ferror.clear(f[COL_BRI]);
586 return valid;
589 vlg.dataToView = function(data) {
590 return [data[COL_VID],
591 ((data[COL_MAP].toString() == '') || (data[COL_MAP].toString() == '0')) ? (parseInt(E('_vlan0tag').value) * 1 + data[COL_VID] *1 ).toString() : data[COL_MAP].toString(),
592 (data[COL_P0].toString() != '0') ? 'Yes' : '',
593 (data[COL_P0T].toString() != '0') ? 'On' : '',
594 (data[COL_P1].toString() != '0') ? 'Yes' : '',
595 (data[COL_P1T].toString() != '0') ? 'On' : '',
596 (data[COL_P2].toString() != '0') ? 'Yes' : '',
597 (data[COL_P2T].toString() != '0') ? 'On' : '',
598 (data[COL_P3].toString() != '0') ? 'Yes' : '',
599 (data[COL_P3T].toString() != '0') ? 'On' : '',
600 (data[COL_P4].toString() != '0') ? 'Yes' : '',
601 (data[COL_P4T].toString() != '0') ? 'On' : '',
602 (data[COL_VID_DEF].toString() != '0') ? '*' : '',
603 ['', 'WAN', 'LAN (br0)', 'LAN1 (br1)', 'LAN2 (br2)', 'LAN3 (br3)'
604 ][data[COL_BRI] - 1]];
607 vlg.dataToFieldValues = function (data) {
608 return [data[COL_VID],
609 data[COL_MAP],
610 (data[COL_P0] != 0) ? 'checked' : '',
611 (data[COL_P0T] != 0) ? 'checked' : '',
612 (data[COL_P1] != 0) ? 'checked' : '',
613 (data[COL_P1T] != 0) ? 'checked' : '',
614 (data[COL_P2] != 0) ? 'checked' : '',
615 (data[COL_P2T] != 0) ? 'checked' : '',
616 (data[COL_P3] != 0) ? 'checked' : '',
617 (data[COL_P3T] != 0) ? 'checked' : '',
618 (data[COL_P4] != 0) ? 'checked' : '',
619 (data[COL_P4T] != 0) ? 'checked' : '',
620 (data[COL_VID_DEF] != 0) ? 'checked' : '',
621 data[COL_BRI]];
624 vlg.fieldValuesToData = function(row) {
625 var f = fields.getAll(row);
626 return [f[COL_VID].value,
627 f[COL_MAP].value,
628 f[COL_P0].checked ? 1 : 0,
629 f[COL_P0T].checked ? 1 : 0,
630 f[COL_P1].checked ? 1 : 0,
631 f[COL_P1T].checked ? 1 : 0,
632 f[COL_P2].checked ? 1 : 0,
633 f[COL_P2T].checked ? 1 : 0,
634 f[COL_P3].checked ? 1 : 0,
635 f[COL_P3T].checked ? 1 : 0,
636 f[COL_P4].checked ? 1 : 0,
637 f[COL_P4T].checked ? 1 : 0,
638 f[COL_VID_DEF].checked ? 1 : 0,
639 f[COL_BRI].value];
642 vlg.onCancel = function() {
643 this.removeEditor();
644 this.showSource();
645 this.disableNewEditor(false);
647 this.resetNewEditor();
650 vlg.onAdd = function() {
651 var data;
653 this.moving = null;
654 this.rpHide();
656 if (!this.verifyFields(this.newEditor, false)) return;
658 data = this.fieldValuesToData(this.newEditor);
659 this.insertData(-1, data);
661 this.disableNewEditor(false);
662 this.resetNewEditor();
664 this.resort();
667 vlg.onOK = function() {
668 var i, data, view;
670 if (!this.verifyFields(this.editor, false)) return;
672 data = this.fieldValuesToData(this.editor);
673 view = this.dataToView(data);
675 this.source.setRowData(data);
676 for (i = 0; i < this.source.cells.length; ++i) {
677 this.source.cells[i].innerHTML = view[i];
680 this.removeEditor();
681 this.showSource();
682 this.disableNewEditor(false);
684 this.resetNewEditor();
685 this.resort();
688 vlg.onDelete = function() {
689 this.removeEditor();
690 elem.remove(this.source);
691 this.source = null;
692 this.disableNewEditor(false);
694 this.resetNewEditor();
697 vlg.sortCompare = function(a, b) {
698 var obj = TGO(a);
699 var col = obj.sortColumn;
700 if (this.sortColumn == 0) {
701 var r = cmpInt(parseInt(a.cells[col].innerHTML), parseInt(b.cells[col].innerHTML));
702 } else {
703 var r = cmpText(a.cells[col].innerHTML, b.cells[col].innerHTML);
705 return obj.sortAscending ? r : -r;
708 vlg.resetNewEditor = function() {
709 var f = fields.getAll(this.newEditor);
711 for (var i=0; i <= MAX_BRIDGE_ID; i++) {
712 var j = (i==0) ? '' : i.toString();
713 f[COL_BRI].options[i+2].disabled = (nvram['lan' + j + '_ifname'].length < 1);
716 f[COL_MAP].value = '0';
718 f[COL_VID].selectedIndex=0;
719 var t = MAX_VLAN_ID;
720 while((this.countVID(f[COL_VID].selectedIndex) > 0) && (t > 0)) {
721 f[COL_VID].selectedIndex = (f[COL_VID].selectedIndex%(MAX_VLAN_ID))+1;
722 t--;
725 for(var i=0; i<= MAX_VLAN_ID ; i++) {
726 f[COL_VID].options[i].disabled = (this.countVID(i) > 0);
729 f[COL_P0].checked = 0;
730 f[COL_P0T].checked = 0;
731 f[COL_P0T].disabled = 1;
732 f[COL_P1].checked = 0;
733 f[COL_P1T].checked = 0;
734 f[COL_P1T].disabled = 1;
735 f[COL_P2].checked = 0;
736 f[COL_P2T].checked = 0;
737 f[COL_P2T].disabled = 1;
738 f[COL_P3].checked = 0;
739 f[COL_P3T].checked = 0;
740 f[COL_P3T].disabled = 1;
741 f[COL_P4].checked = 0;
742 f[COL_P4T].checked = 0;
743 f[COL_P4T].disabled = 1;
744 f[COL_VID_DEF].checked = 0;
745 if (this.countDefaultVID()>0)
746 f[COL_VID_DEF].disabled = 1;
747 f[COL_BRI].selectedIndex = 0;
748 ferror.clearAll(fields.getAll(this.newEditor));
750 } // end of the so-called if(supported_device) block
752 function init() {
753 if(port_vlan_supported) {
754 vlg.recolor();
755 vlg.resetNewEditor();
756 var c;
757 if (((c = cookie.get('advanced_vlan_notes_vis')) != null) && (c == '1')) toggleVisibility("notes");
761 function toggleVisibility(whichone) {
762 if (E('sesdiv_' + whichone).style.display == '') {
763 E('sesdiv_' + whichone).style.display = 'none';
764 E('sesdiv_' + whichone + '_showhide').innerHTML = '(Click here to show)';
765 cookie.set('advanced_vlan_' + whichone + '_vis', 0);
766 } else {
767 E('sesdiv_' + whichone).style.display='';
768 E('sesdiv_' + whichone + '_showhide').innerHTML = '(Click here to hide)';
769 cookie.set('advanced_vlan_' + whichone + '_vis', 1);
773 function earlyInit() {
774 if(!port_vlan_supported) {
775 E('save-button').disabled = 1;
776 return;
778 PORT_VLAN_SUPPORT_OVERRIDE = ((nvram['trunk_vlan_so'] == '1') ? 1 : 0);
781 </script>
782 </head>
783 <body onload='init()'>
784 <form id='_fom' method='post' action='tomato.cgi'>
785 <table id='container' cellspacing=0>
786 <tr><td colspan=2 id='header'>
787 <div class='title'>Tomato</div>
788 <div class='version'>Version <% version(); %></div>
789 </td></tr>
790 <tr id='body'><td id='navi'><script type='text/javascript'>navi()</script></td>
791 <td id='content'>
792 <div id='ident'><% ident(); %></div>
793 <input type='hidden' name='_nextpage' value='advanced-vlan.asp'>
794 <input type='hidden' name='_nextwait' value='30'>
795 <input type='hidden' name='_reboot' value='1'>
796 <input type='hidden' name='_nvset' value='1'>
797 <input type='hidden' name='_commit' value='1'>
798 <input type='hidden' name='vlan0ports'>
799 <input type='hidden' name='vlan1ports'>
800 <input type='hidden' name='vlan2ports'>
801 <input type='hidden' name='vlan3ports'>
802 <input type='hidden' name='vlan4ports'>
803 <input type='hidden' name='vlan5ports'>
804 <input type='hidden' name='vlan6ports'>
805 <input type='hidden' name='vlan7ports'>
806 <input type='hidden' name='vlan8ports'>
807 <input type='hidden' name='vlan9ports'>
808 <input type='hidden' name='vlan10ports'>
809 <input type='hidden' name='vlan11ports'>
810 <input type='hidden' name='vlan12ports'>
811 <input type='hidden' name='vlan13ports'>
812 <input type='hidden' name='vlan14ports'>
813 <input type='hidden' name='vlan15ports'>
814 <input type='hidden' name='vlan0hwname'>
815 <input type='hidden' name='vlan1hwname'>
816 <input type='hidden' name='vlan2hwname'>
817 <input type='hidden' name='vlan3hwname'>
818 <input type='hidden' name='vlan4hwname'>
819 <input type='hidden' name='vlan5hwname'>
820 <input type='hidden' name='vlan6hwname'>
821 <input type='hidden' name='vlan7hwname'>
822 <input type='hidden' name='vlan8hwname'>
823 <input type='hidden' name='vlan9hwname'>
824 <input type='hidden' name='vlan10hwname'>
825 <input type='hidden' name='vlan11hwname'>
826 <input type='hidden' name='vlan12hwname'>
827 <input type='hidden' name='vlan13hwname'>
828 <input type='hidden' name='vlan14hwname'>
829 <input type='hidden' name='vlan15hwname'>
830 <input type='hidden' name='wan_ifnameX'>
831 <input type='hidden' name='manual_boot_nv'>
832 <input type='hidden' name='lan_ifnames'>
833 <input type='hidden' name='lan1_ifnames'>
834 <input type='hidden' name='lan2_ifnames'>
835 <input type='hidden' name='lan3_ifnames'>
836 <input type='hidden' name='trunk_vlan_so'>
837 <input type='hidden' name='vlan0vid'>
838 <input type='hidden' name='vlan1vid'>
839 <input type='hidden' name='vlan2vid'>
840 <input type='hidden' name='vlan3vid'>
841 <input type='hidden' name='vlan4vid'>
842 <input type='hidden' name='vlan5vid'>
843 <input type='hidden' name='vlan6vid'>
844 <input type='hidden' name='vlan7vid'>
845 <input type='hidden' name='vlan8vid'>
846 <input type='hidden' name='vlan9vid'>
847 <input type='hidden' name='vlan10vid'>
848 <input type='hidden' name='vlan11vid'>
849 <input type='hidden' name='vlan12vid'>
850 <input type='hidden' name='vlan13vid'>
851 <input type='hidden' name='vlan14vid'>
852 <input type='hidden' name='vlan15vid'>
854 <div id='sesdiv' style='display:none'>
855 <div class='section-title'>VLAN</div>
856 <div class='section'>
857 <table class='tomato-grid' cellspacing=1 id='vlan-grid'></table>
858 </div>
860 <!-- / / / -->
862 <div class='section-title'>VID Offset</div>
863 <div class='section'>
864 <script type='text/javascript'>
865 createFieldTable('', [
866 { title: 'First 802.1Q VLAN tag', name: 'vlan0tag', type: 'text', maxlen:4, size:6,
867 value: fixInt(nvram.vlan0tag, 0, 4080, 0),
868 suffix: ' <small><i>(range: 0 - 4080; must be a multiple of 16; set to 0 to disable)</i></small>' }
870 </script>
871 </div>
873 <!-- / / / -->
875 <div class='section-title'>Wireless</div>
876 <div class='section'>
877 <script type='text/javascript'>
878 var f = [];
879 for (var uidx = 0; uidx < wl_ifaces.length; ++uidx) {
880 var u = wl_fface(uidx);
881 f.push(
882 { title: ('Bridge ' + wl_ifaces[uidx][0] + ' to'), name: ('f_bridge_wlan'+u+'_to'), type: 'select',
883 options: [[0,'LAN (br0)'],[1,'LAN1 (br1)'],[2,'LAN2 (br2)'],[3,'LAN3 (br3)'],[4,'none']], value: 4 } );
885 createFieldTable('',f);
886 if(port_vlan_supported) vlg.setup();
887 </script>
888 </div>
890 <!-- / / / -->
891 <div class='section-title'>Trunk VLAN support override (experimental)</div>
892 <div class='section'>
893 <script type='text/javascript'>
894 createFieldTable('', [
895 { title: 'Enable', name: 'f_trunk_vlan_so', type: 'checkbox', value: nvram.trunk_vlan_so == '1' },
897 </script>
898 </div>
900 <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>
901 <div class='section' id='sesdiv_notes' style='display:none'>
902 <ul>
903 <li><b>VLAN</b> - Unique identifier of a VLAN.</li>
904 <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>
905 <li><b>Ports 1-4 &amp; WAN</b> - Which ethernet ports on the router should be members of this VLAN.</li>
906 <li><b>Tagged</b> - Enable 802.1Q tagging of ethernet frames on a particular port/VLAN
907 <script type='text/javascript'>
908 if(!trunk_vlan_supported)
909 W(' <i>(not known to be supported on this model)</i>');
910 </script>
911 </li>
912 <li><b>Default</b> - VLAN ID assigned to untagged frames received by the router.</li>
913 <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>
914 </ul>
916 <ul>
917 <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>
918 </ul>
920 <ul>
921 <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>
922 </ul>
924 <small>
925 <ul>
926 <li><b>Other relevant notes/hints:</b>
927 <ul>
928 <li>One VID <i>must</i> be assigned to WAN.</li>
929 <li>One VID <i>must</i> be selected as the default.</li>
930 <script type='text/javascript'>
931 if((trunk_vlan_supported) || (nvram.trunk_vlan_so == '1')) {
932 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>');
933 W('<li>It may be also recommended to avoid using VID "1" as some vendors consider it special/reserved (for management purposes).</li>');
935 </script>
936 </ul>
937 <br>
938 <ul>
939 <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>
940 <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>
941 <li>You've been warned!</li>
942 </ul>
943 </ul>
944 </div>
945 </div>
946 </small>
947 </div>
948 </div>
949 <script type='text/javascript'>
950 if(!port_vlan_supported)
951 W('<i>This feature is not supported on this router.</i>');
952 else {
953 E('sesdiv').style.display = '';
954 if(!trunk_vlan_supported)
955 E('trunk_vlan_override').style.display = '';
957 </script>
958 </td></tr>
959 <tr><td id='footer' colspan=2>
960 <span id='footer-msg'></span>
961 <input type='button' value='Save' id='save-button' onclick='save()'>
962 <input type='button' value='Cancel' id='cancel-button' onclick='javascript:reloadPage();'>
963 </td></tr>
964 </table>
965 </form>
966 <script type='text/javascript'>earlyInit(); verifyFields(null,1);</script>
967 </body>
968 </html>