1 <!DOCTYPE HTML PUBLIC '-//W3C//DTD HTML
4.0//EN'
>
4 Copyright (C) 2011-2012 Augusto Bott
5 http://code.google.com/p/tomato-sdhc-vlan/
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.
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'
>
21 <script type='text/javascript' src='tomato.js'
></script>
22 <style type='text/css'
>
42 #vlan-grid .centered
{
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;
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
94 case '0xa4cf': // Belkin F7D3301
95 if (nvram
['boardrev'] == '0x1100'){ //Belkin F5D8235-4 v3
103 case '0xd4cf': // Belkin F7D4301
104 case '0x048e': // WL-520GU, WL-500G Premium v2
105 case '0x0550': // RT-N53 (boardrev = 0x1442), RT-N10U ( boardrev = 0x1102)
106 if (nvram
['boardrev'] == '0x1102') { //RT-N10U
114 if (nvram
['boardrev'] == '0x1100') { //CW-5358U
128 case '0x04ef': // WRT320N/E2000
129 case '0x04cf': // WRT610Nv2/E3000, RT-N16, WNR3500L
130 case '0xf582': // RT-N66
137 case '0xf53a': // E1000v2.1/E1200v1
138 case '0xf53b': // E1000v2/E1500
139 if (((nvram
['boot_hw_model'] == 'E1200') && (nvram
['boot_hw_ver'] == '1.0')) || (nvram
['boot_hw_model'] == 'E1500')) {
153 case '0xc550': // E1550
154 case '0xf550': // E2500
155 case '0x058e': // E900
156 case '0xf52a': // E3200
157 case '0xf52c': // E4200v1
158 case '0x1202': // HG320 - not sure, need test
159 if (nvram
['boardrev'] == '0x1153') { //RG200E-CA type 0x058e same as E900
174 if (nvram
['boardrev'] == '02') { //WNR3500Lv2
182 if (nvram
['boardrev'] == '0x1204') { //rt-n15u
190 // should work on WRT54G v2/v3, WRT54GS v1/v2 and others
212 var COL_VID_DEF
= 12;
215 var vlt
= nvram
.vlan0tag
| '0';
217 // set to either 5 or 8 when nvram settings are read (FastE or GigE routers)
218 var SWITCH_INTERNAL_PORT
=0;
219 // option made available for experimental purposes on routers known to support port-based VLANs, but not confirmed to support 801.11q trunks
220 var PORT_VLAN_SUPPORT_OVERRIDE
= ((nvram
['trunk_vlan_so'] == '1') ? 1 : 0);
222 function verifyFields(focused
, quiet
){
223 PORT_VLAN_SUPPORT_OVERRIDE
=(E('_f_trunk_vlan_so').checked
? 1 : 0);
224 for (var uidx
= 0; uidx
< wl_ifaces
.length
; ++uidx
) {
225 var u
= wl_fface(uidx
);
226 var wlan
= E('_f_bridge_wlan'+u
+'_to');
227 if(nvram
.lan_ifname
.length
< 1)
228 wlan
.options
[0].disabled
=true;
229 if(nvram
.lan1_ifname
.length
< 1)
230 wlan
.options
[1].disabled
=true;
231 if(nvram
.lan2_ifname
.length
< 1)
232 wlan
.options
[2].disabled
=true;
233 if(nvram
.lan3_ifname
.length
< 1)
234 wlan
.options
[3].disabled
=true;
236 var e
= E('_vlan0tag');
237 if (!v_range('_vlan0tag', quiet
, 0, 4080)) return 0;
238 var v
= parseInt(e
.value
);
239 e
.value
= v
- (v
% 16);
240 if ((e
.value
!= vlt
) && (typeof(vlg
) != 'undefined')) {
248 if (vlg
.isEditing()) return;
251 fom
.trunk_vlan_so
.value
= (E('_f_trunk_vlan_so').checked
? 1 : 0);
252 // wipe out relevant fields just in case this is not the first time we try to submit
253 for (var i
= 0 ; i
<= MAX_VLAN_ID
; i
++) {
254 fom
['vlan' + i
+ 'ports'].value
= '';
255 fom
['vlan' + i
+ 'hwname'].value
= '';
256 fom
['vlan' + i
+ 'vid'].value
= '';
258 fom
['wan_ifnameX'].value
= '';
259 fom
['lan_ifnames'].value
= '';
260 fom
['lan1_ifnames'].value
= '';
261 fom
['lan2_ifnames'].value
= '';
262 fom
['lan3_ifnames'].value
= '';
265 var d
= vlg
.getAllData();
267 for (var i
= 0; i
< d
.length
; ++i
) {
269 p
+= (d
[i
][COL_P0
].toString() != '0') ? COL_P0N
: '';
270 p
+= (((trunk_vlan_supported
) || (PORT_VLAN_SUPPORT_OVERRIDE
)) && (d
[i
][COL_P0T
].toString() != '0')) ? 't' : '';
271 p
+= trailingSpace(p
);
273 p
+= (d
[i
][COL_P1
].toString() != '0') ? COL_P1N
: '';
274 p
+= (((trunk_vlan_supported
) || (PORT_VLAN_SUPPORT_OVERRIDE
)) && (d
[i
][COL_P1T
].toString() != '0')) ? 't' : '';
275 p
+= trailingSpace(p
);
277 p
+= (d
[i
][COL_P2
].toString() != '0') ? COL_P2N
: '';
278 p
+= (((trunk_vlan_supported
) || (PORT_VLAN_SUPPORT_OVERRIDE
)) && (d
[i
][COL_P2T
].toString() != '0')) ? 't' : '';
279 p
+= trailingSpace(p
);
281 p
+= (d
[i
][COL_P3
].toString() != '0') ? COL_P3N
: '';
282 p
+= (((trunk_vlan_supported
) || (PORT_VLAN_SUPPORT_OVERRIDE
)) && (d
[i
][COL_P3T
].toString() != '0')) ? 't' : '';
283 p
+= trailingSpace(p
);
285 p
+= (d
[i
][COL_P4
].toString() != '0') ? COL_P4N
: '';
286 p
+= (((trunk_vlan_supported
) || (PORT_VLAN_SUPPORT_OVERRIDE
)) && (d
[i
][COL_P4T
].toString() != '0')) ? 't' : '';
287 p
+= trailingSpace(p
);
289 p
+= (d
[i
][COL_VID_DEF
].toString() != '0') ? (SWITCH_INTERNAL_PORT
+ '*') : SWITCH_INTERNAL_PORT
;
291 // arrange port numbers in ascending order just to be safe (not sure if this is really needed... mostly, cosmetics?)
296 v
+= (d
[i
][COL_VID_DEF
].toString() != '0') ? d
[i
][0] : '';
298 fom
['vlan'+d
[i
][COL_VID
]+'ports'].value
= p
;
299 fom
['vlan'+d
[i
][COL_VID
]+'hwname'].value
= 'et0';
300 fom
['vlan'+d
[i
][COL_VID
]+'vid'].value
= ((d
[i
][COL_MAP
].toString() != '') && (d
[i
][COL_MAP
].toString() != '0')) ? d
[i
][COL_MAP
] : '';
302 fom
['wan_ifnameX'].value
+= (d
[i
][COL_BRI
] == '2') ? 'vlan'+d
[i
][0] : '';
303 fom
['lan_ifnames'].value
+= (d
[i
][COL_BRI
] == '3') ? 'vlan'+d
[i
][0] : '';
305 // fom['lan_ifnames'].value += trailingSpace(fom['lan_ifnames'].value);
306 // 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);
308 fom
['lan1_ifnames'].value
+= (d
[i
][COL_BRI
] == '4') ? 'vlan'+d
[i
][0] : '';
309 fom
['lan2_ifnames'].value
+= (d
[i
][COL_BRI
] == '5') ? 'vlan'+d
[i
][0] : '';
310 fom
['lan3_ifnames'].value
+= (d
[i
][COL_BRI
] == '6') ? 'vlan'+d
[i
][0] : '';
313 for (var uidx
= 0; uidx
< wl_ifaces
.length
; ++uidx
) {
314 var u
= wl_fface(uidx
);
315 var wlan
= E('_f_bridge_wlan'+u
+'_to');
317 // var wlan = E('_f_bridge_wlan_to');
318 // alert(wlan.selectedIndex);
320 switch(parseInt(wlan
.selectedIndex
)) {
322 fom
['lan_ifnames'].value
+= ' ' + wl_ifaces
[uidx
][0];
325 fom
['lan1_ifnames'].value
+= ' ' + wl_ifaces
[uidx
][0];
328 fom
['lan2_ifnames'].value
+= ' ' + wl_ifaces
[uidx
][0];
331 fom
['lan3_ifnames'].value
+= ' ' + wl_ifaces
[uidx
][0];
336 // var lif = nvram['lan_ifnames'].split(' ');
337 // for (var j = 0; j < lif.length; j++) {
338 // fom['lan_ifnames'].value += (lif[j].indexOf('vlan') != -1) ? '' : lif[j];
339 // fom['lan_ifnames'].value += trailingSpace(fom['lan_ifnames'].value);
341 // alert('lan_ifnames=' + fom['lan_ifnames'].value + '\n' +
342 // 'lan1_ifnames=' + fom['lan1_ifnames'].value + '\n' +
343 // 'lan2_ifnames=' + fom['lan2_ifnames'].value + '\n' +
344 // 'lan3_ifnames=' + fom['lan3_ifnames'].value);
347 // for some models, Tomato checks for a few vital/crucial nvram settings at init time
348 // in some cases, if some/any of them are not found, a full nvram reset/clean could be triggered
349 // so, to (try to) play it safe, we check for the 1st needed/available/required
350 // VLAN for FastE (vlan0 is usually LAN) and GigE routers (vlan1 is usually LAN)
351 if((fom
['vlan0ports'].value
.length
< 1) || (fom
['vlan0hwname'].value
.length
< 1) ||
352 (fom
['vlan1ports'].value
.length
< 1) || (fom
['vlan1hwname'].value
.length
< 1))
353 fom
['manual_boot_nv'].value
= '1';
355 fom
['manual_boot_nv'].value
= nvram
['manual_boot_nv'];
357 var e
= E('footer-msg');
359 if(vlg
.countWan() != 1) {
360 e
.innerHTML
= 'Cannot proceed: one VID must be assigned to WAN.';
361 e
.style
.visibility
= 'visible';
365 e
.style
.visibility
= 'hidden';
370 if(vlg
.countLan(0) != 1) {
371 e
.innerHTML
= 'Cannot proceed: one and only one VID must be assigned to the primary LAN (br0).';
372 e
.style
.visibility
= 'visible';
376 e
.style
.visibility
= 'hidden';
382 e
.innerHTML
= 'Cannot proceed without setting a default VID';
383 e
.style
.visibility
= 'visible';
387 e
.style
.visibility
= 'hidden';
392 if (confirm("Router must be rebooted to proceed. Commit changes to NVRAM and reboot now?"))
396 function trailingSpace(s
)
398 return ((s
.length
>0)&&(s
.charAt(s
.length
-1) != ' ')) ? ' ' : '';
401 if(port_vlan_supported
) { // aka if(supported_hardware) block
402 var vlg
= new TomatoGrid();
403 vlg
.setup = function() {
404 this.init('vlan-grid', '', (MAX_VLAN_ID
+ 1), [
405 { 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>' },
406 { type
: 'text', maxlen
: 4, prefix
: '<div class="centered">', suffix
: '</div>' },
407 { type
: 'checkbox', prefix
: '<div class="centered">', suffix
: '</div>' },
408 { type
: 'checkbox', prefix
: '<div class="centered">', suffix
: '</div>' },
409 { type
: 'checkbox', prefix
: '<div class="centered">', suffix
: '</div>' },
410 { type
: 'checkbox', prefix
: '<div class="centered">', suffix
: '</div>' },
411 { type
: 'checkbox', prefix
: '<div class="centered">', suffix
: '</div>' },
412 { type
: 'checkbox', prefix
: '<div class="centered">', suffix
: '</div>' },
413 { type
: 'checkbox', prefix
: '<div class="centered">', suffix
: '</div>' },
414 { type
: 'checkbox', prefix
: '<div class="centered">', suffix
: '</div>' },
415 { type
: 'checkbox', prefix
: '<div class="centered">', suffix
: '</div>' },
416 { type
: 'checkbox', prefix
: '<div class="centered">', suffix
: '</div>' },
417 { type
: 'checkbox', prefix
: '<div class="centered">', suffix
: '</div>' },
418 { 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>' }]);
420 this.headerSet(['VLAN', 'VID', 'Port 1', 'Tagged', 'Port 2', 'Tagged', 'Port 3', 'Tagged', 'Port 4', 'Tagged', 'WAN Port', 'Tagged', 'Default', 'Bridge']);
423 vlg
.canDelete
= false;
426 vlg
.resetNewEditor();
429 vlg
.populate = function() {
432 // find out which vlans are supposed to be bridged to each LAN
435 for (var i
= 0 ; i
<= MAX_BRIDGE_ID
; i
++) {
436 var j
= (i
== 0) ? '' : i
.toString();
437 var l
= nvram
['lan' + j
+ '_ifnames'].split(' ');
439 // alert('lan' + j + '_ifnames=' + l);
441 for (var k
= 0 ; k
< l
.length
; k
++) {
443 // alert("bridge br" + i + "=vlan" + parseInt(l[k].replace('vlan','')));
445 if(l
[k
].indexOf('vlan') != -1) {
447 // alert('lan' + j + '_ifname=br' + nvram['lan' + j + '_ifname'].replace('br',''));
449 if (nvram
['lan' + j
+ '_ifname'] != '')
450 bridged
[parseInt(l
[k
].replace('vlan',''))] = (3 + parseInt(nvram
['lan' + j
+ '_ifname'].replace('br',''))).toString();
452 bridged
[parseInt(l
[k
].replace('vlan',''))] = '1';
455 for (var uidx
= 0; uidx
< wl_ifaces
.length
; ++uidx
) {
456 if(l
[k
].indexOf(wl_ifaces
[uidx
][0]) != -1) {
457 E('_f_bridge_wlan'+wl_fface(uidx
)+'_to').selectedIndex
=i
;
464 bridged
[parseInt(nvram
['wan_ifnameX'].replace('vlan',''))] = '2';
466 // go thru all possible VLANs
467 for (var i
= 0 ; i
<= MAX_VLAN_ID
; i
++) {
470 if ((nvram
['vlan' + i
+ 'hwname'].length
> 0) || (nvram
['vlan' + i
+ 'ports'].length
> 0)) {
471 // (re)initialize our bitmap for this particular iteration
472 for (var j
=0; j
<= MAX_PORT_ID
; j
++) {
476 // which ports are members of this VLAN?
477 var m
=nvram
['vlan' + i
+ 'ports'].split(' ');
478 for (var j
= 0; j
< (m
.length
) ; j
++) {
479 port
[parseInt(m
[j
].charAt(0))] = '1';
480 tagged
[parseInt(m
[j
].charAt(0))] = (((trunk_vlan_supported
) || (PORT_VLAN_SUPPORT_OVERRIDE
)) && (m
[j
].indexOf('t') != -1)) ? '1' : '0';
483 if (port_vlan_supported
) {
484 if((nvram
['vlan' + i
+ 'ports']).indexOf('*') != -1)
485 SWITCH_INTERNAL_PORT
=(nvram
['vlan' + i
+ 'ports']).charAt((nvram
['vlan' + i
+ 'ports']).indexOf('*')-1);
487 vlg
.insertData(-1, [ i
.toString(),
488 ((nvram
['vlan' + i
+ 'vid'] != '') && (nvram
['vlan' + i
+ 'vid'] > 0)) ? (nvram
['vlan' + i
+ 'vid']).toString() : '0',
489 port
[COL_P0N
], tagged
[COL_P0N
],
490 port
[COL_P1N
], tagged
[COL_P1N
],
491 port
[COL_P2N
], tagged
[COL_P2N
],
492 port
[COL_P3N
], tagged
[COL_P3N
],
493 port
[COL_P4N
], tagged
[COL_P4N
],
494 (((nvram
['vlan' + i
+ 'ports']).indexOf('*') != -1) ? '1' : '0' ),
495 (bridged
[i
] != null) ? bridged
[i
] : '1' ]);
501 vlg
.countElem = function(f
, v
)
503 var data
= this.getAllData();
505 for (var i
= 0; i
< data
.length
; ++i
) {
506 total
+= (data
[i
][f
] == v
) ? 1 : 0;
511 vlg
.countDefaultVID = function()
513 return this.countElem(COL_VID_DEF
,1);
516 vlg
.countVID = function (v
)
518 return this.countElem(COL_VID
,v
);
521 vlg
.countWan = function()
523 return this.countElem(COL_BRI
,2);
526 vlg
.countLan = function(l
)
528 return this.countElem(COL_BRI
,l
+3);
531 vlg
.verifyFields = function(row
, quiet
) {
533 var f
= fields
.getAll(row
);
535 for(var i
=0; i
<= MAX_VLAN_ID
; i
++) {
536 f
[COL_VID
].options
[i
].disabled
= (this.countVID(i
) > 0);
539 for (var i
=0; i
<= MAX_BRIDGE_ID
; i
++) {
540 var j
= (i
==0) ? '' : i
.toString();
541 f
[COL_BRI
].options
[i
+2].disabled
= (nvram
['lan' + j
+ '_ifname'].length
< 1);
544 if (!v_range(f
[COL_MAP
], quiet
, 0, 4094)) valid
= 0;
546 if(((trunk_vlan_supported
) || (PORT_VLAN_SUPPORT_OVERRIDE
)) && (f
[COL_P0
].checked
== 1)) {
547 f
[COL_P0T
].disabled
=0;
549 // if((f[COL_P0T].checked==0) || (this.countElem(COL_P0,1)>0) )
550 // if(this.countElem(COL_P0,1)>0) {
554 f
[COL_P0T
].disabled
=1;
555 f
[COL_P0T
].checked
=0;
557 if(((trunk_vlan_supported
) || (PORT_VLAN_SUPPORT_OVERRIDE
)) && (f
[COL_P1
].checked
== 1)) {
558 f
[COL_P1T
].disabled
=0;
560 f
[COL_P1T
].disabled
=1;
561 f
[COL_P1T
].checked
=0;
563 if(((trunk_vlan_supported
) || (PORT_VLAN_SUPPORT_OVERRIDE
)) && (f
[COL_P2
].checked
== 1)) {
564 f
[COL_P2T
].disabled
=0;
566 f
[COL_P2T
].disabled
=1;
567 f
[COL_P2T
].checked
=0;
569 if(((trunk_vlan_supported
) || (PORT_VLAN_SUPPORT_OVERRIDE
)) && (f
[COL_P3
].checked
== 1)) {
570 f
[COL_P3T
].disabled
=0;
572 f
[COL_P3T
].disabled
=1;
573 f
[COL_P3T
].checked
=0;
575 if(((trunk_vlan_supported
) || (PORT_VLAN_SUPPORT_OVERRIDE
)) && (f
[COL_P4
].checked
== 1)) {
576 f
[COL_P4T
].disabled
=0;
578 f
[COL_P4T
].disabled
=1;
579 f
[COL_P4T
].checked
=0;
582 if ((f
[COL_P0
].checked
== 1) && (this.countElem(COL_P0
,1)>0)) {
583 if (((this.countElem(COL_P0
,1) != this.countElem(COL_P0T
,1)) || (f
[COL_P0T
].checked
==0))) {
584 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
);
587 ferror
.clear(f
[COL_P0T
]);
590 if ((f
[COL_P1
].checked
== 1) && (this.countElem(COL_P1
,1)>0)) {
591 if (((this.countElem(COL_P1
,1) != this.countElem(COL_P1T
,1)) || (f
[COL_P1T
].checked
==0))) {
592 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
);
595 ferror
.clear(f
[COL_P1T
]);
598 if ((f
[COL_P2
].checked
== 1) && (this.countElem(COL_P2
,1)>0)) {
599 if (((this.countElem(COL_P2
,1) != this.countElem(COL_P2T
,1)) || (f
[COL_P2T
].checked
==0))) {
600 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
);
603 ferror
.clear(f
[COL_P2T
]);
606 if ((f
[COL_P3
].checked
== 1) && (this.countElem(COL_P3
,1)>0)) {
607 if (((this.countElem(COL_P3
,1) != this.countElem(COL_P3T
,1)) || (f
[COL_P3T
].checked
==0))) {
608 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
);
611 ferror
.clear(f
[COL_P3T
]);
614 if ((f
[COL_P4
].checked
== 1) && (this.countElem(COL_P4
,1)>0)) {
615 if (((this.countElem(COL_P4
,1) != this.countElem(COL_P4T
,1)) || (f
[COL_P4T
].checked
==0))) {
616 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
);
619 ferror
.clear(f
[COL_P4T
]);
623 if(this.countDefaultVID() > 0) {
624 f
[COL_VID_DEF
].disabled
=1;
625 f
[COL_VID_DEF
].checked
=0;
628 if((this.countDefaultVID() > 0) && (f
[COL_VID_DEF
].checked
==1)) {
629 ferror
.set(f
[COL_VID_DEF
], 'Only one VID can be selected as the default VID', quiet
);
632 ferror
.clear(f
[COL_VID_DEF
]);
635 if(this.countVID(f
[COL_VID
].selectedIndex
) > 0) {
636 ferror
.set(f
[COL_VID
], 'Cannot add more than one entry with VID ' + f
[0].selectedIndex
, quiet
);
639 ferror
.clear(f
[COL_VID
]);
642 if ((this.countWan() > 0) && (f
[COL_BRI
].selectedIndex
== 1)) {
643 ferror
.set(f
[COL_BRI
],'Only one VID can be used as WAN at any time', quiet
);
646 ferror
.clear(f
[COL_BRI
]);
649 for(var i
=0; i
<4; i
++) {
650 if ((this.countLan(i
) > 0) && (f
[COL_BRI
].selectedIndex
== (i
+2))) {
651 ferror
.set(f
[COL_BRI
],'One and only one VID can be used for LAN' + ((i
==0) ? '' : i
) + ' (br'+i
+') at any time', quiet
);
654 ferror
.clear(f
[COL_BRI
]);
661 vlg
.dataToView = function(data
) {
662 return [data
[COL_VID
],
663 ((data
[COL_MAP
].toString() == '') || (data
[COL_MAP
].toString() == '0')) ? (parseInt(E('_vlan0tag').value
) * 1 + data
[COL_VID
] *1 ).toString() : data
[COL_MAP
].toString(),
664 (data
[COL_P0
].toString() != '0') ? 'Yes' : '',
665 (data
[COL_P0T
].toString() != '0') ? 'On' : '',
666 (data
[COL_P1
].toString() != '0') ? 'Yes' : '',
667 (data
[COL_P1T
].toString() != '0') ? 'On' : '',
668 (data
[COL_P2
].toString() != '0') ? 'Yes' : '',
669 (data
[COL_P2T
].toString() != '0') ? 'On' : '',
670 (data
[COL_P3
].toString() != '0') ? 'Yes' : '',
671 (data
[COL_P3T
].toString() != '0') ? 'On' : '',
672 (data
[COL_P4
].toString() != '0') ? 'Yes' : '',
673 (data
[COL_P4T
].toString() != '0') ? 'On' : '',
674 (data
[COL_VID_DEF
].toString() != '0') ? '*' : '',
675 ['', 'WAN', 'LAN (br0)', 'LAN1 (br1)', 'LAN2 (br2)', 'LAN3 (br3)' ][data
[COL_BRI
] - 1]];
678 vlg
.dataToFieldValues = function (data
) {
679 return [data
[COL_VID
],
681 (data
[COL_P0
] != 0) ? 'checked' : '',
682 (data
[COL_P0T
] != 0) ? 'checked' : '',
683 (data
[COL_P1
] != 0) ? 'checked' : '',
684 (data
[COL_P1T
] != 0) ? 'checked' : '',
685 (data
[COL_P2
] != 0) ? 'checked' : '',
686 (data
[COL_P2T
] != 0) ? 'checked' : '',
687 (data
[COL_P3
] != 0) ? 'checked' : '',
688 (data
[COL_P3T
] != 0) ? 'checked' : '',
689 (data
[COL_P4
] != 0) ? 'checked' : '',
690 (data
[COL_P4T
] != 0) ? 'checked' : '',
691 (data
[COL_VID_DEF
] != 0) ? 'checked' : '',
695 vlg
.fieldValuesToData = function(row
) {
696 var f
= fields
.getAll(row
);
697 return [f
[COL_VID
].value
,
699 f
[COL_P0
].checked
? 1 : 0,
700 f
[COL_P0T
].checked
? 1 : 0,
701 f
[COL_P1
].checked
? 1 : 0,
702 f
[COL_P1T
].checked
? 1 : 0,
703 f
[COL_P2
].checked
? 1 : 0,
704 f
[COL_P2T
].checked
? 1 : 0,
705 f
[COL_P3
].checked
? 1 : 0,
706 f
[COL_P3T
].checked
? 1 : 0,
707 f
[COL_P4
].checked
? 1 : 0,
708 f
[COL_P4T
].checked
? 1 : 0,
709 f
[COL_VID_DEF
].checked
? 1 : 0,
713 vlg
.onCancel = function() {
716 this.disableNewEditor(false);
718 this.resetNewEditor();
721 vlg
.onAdd = function() {
727 if (!this.verifyFields(this.newEditor
, false)) return;
729 data
= this.fieldValuesToData(this.newEditor
);
730 this.insertData(-1, data
);
732 this.disableNewEditor(false);
733 this.resetNewEditor();
738 vlg
.onOK = function() {
741 if (!this.verifyFields(this.editor
, false)) return;
743 data
= this.fieldValuesToData(this.editor
);
744 view
= this.dataToView(data
);
746 this.source
.setRowData(data
);
747 for (i
= 0; i
< this.source
.cells
.length
; ++i
) {
748 this.source
.cells
[i
].innerHTML
= view
[i
];
753 this.disableNewEditor(false);
755 this.resetNewEditor();
759 vlg
.onDelete = function() {
761 elem
.remove(this.source
);
763 this.disableNewEditor(false);
765 this.resetNewEditor();
768 vlg
.sortCompare = function(a
, b
) {
770 var col
= obj
.sortColumn
;
771 if (this.sortColumn
== 0) {
772 var r
= cmpInt(parseInt(a
.cells
[col
].innerHTML
), parseInt(b
.cells
[col
].innerHTML
));
774 var r
= cmpText(a
.cells
[col
].innerHTML
, b
.cells
[col
].innerHTML
);
776 return obj
.sortAscending
? r
: -r
;
779 vlg
.resetNewEditor = function() {
780 var f
= fields
.getAll(this.newEditor
);
782 for (var i
=0; i
<= MAX_BRIDGE_ID
; i
++) {
783 var j
= (i
==0) ? '' : i
.toString();
784 f
[COL_BRI
].options
[i
+2].disabled
= (nvram
['lan' + j
+ '_ifname'].length
< 1);
787 f
[COL_MAP
].value
= '0';
789 f
[COL_VID
].selectedIndex
=0;
791 while((this.countVID(f
[COL_VID
].selectedIndex
) > 0) && (t
> 0)) {
792 f
[COL_VID
].selectedIndex
= (f
[COL_VID
].selectedIndex
%(MAX_VLAN_ID
))+1;
796 for(var i
=0; i
<= MAX_VLAN_ID
; i
++) {
797 f
[COL_VID
].options
[i
].disabled
= (this.countVID(i
) > 0);
800 f
[COL_P0
].checked
= 0;
801 f
[COL_P0T
].checked
= 0;
802 f
[COL_P0T
].disabled
= 1;
803 f
[COL_P1
].checked
= 0;
804 f
[COL_P1T
].checked
= 0;
805 f
[COL_P1T
].disabled
= 1;
806 f
[COL_P2
].checked
= 0;
807 f
[COL_P2T
].checked
= 0;
808 f
[COL_P2T
].disabled
= 1;
809 f
[COL_P3
].checked
= 0;
810 f
[COL_P3T
].checked
= 0;
811 f
[COL_P3T
].disabled
= 1;
812 f
[COL_P4
].checked
= 0;
813 f
[COL_P4T
].checked
= 0;
814 f
[COL_P4T
].disabled
= 1;
815 f
[COL_VID_DEF
].checked
= 0;
816 if (this.countDefaultVID()>0)
817 f
[COL_VID_DEF
].disabled
= 1;
818 f
[COL_BRI
].selectedIndex
= 0;
819 ferror
.clearAll(fields
.getAll(this.newEditor
));
821 } // end of the so-called if(supported_device) block
824 if(port_vlan_supported
) {
826 vlg
.resetNewEditor();
828 if (((c
= cookie
.get('advanced_vlan_notes_vis')) != null) && (c
== '1')) toggleVisibility("notes");
829 if (((c
= cookie
.get('advanced_vlan_wireless_vis')) != null) && (c
== '1')) toggleVisibility("wireless");
830 if (((c
= cookie
.get('advanced_vlan_vidmap_vis')) != null) && (c
== '1')) toggleVisibility("vidmap");
834 function toggleVisibility(whichone
) {
835 if (E('sesdiv_' + whichone
).style
.display
== '') {
836 E('sesdiv_' + whichone
).style
.display
= 'none';
837 E('sesdiv_' + whichone
+ '_showhide').innerHTML
= '(Click here to show)';
838 cookie
.set('advanced_vlan_' + whichone
+ '_vis', 0);
840 E('sesdiv_' + whichone
).style
.display
='';
841 E('sesdiv_' + whichone
+ '_showhide').innerHTML
= '(Click here to hide)';
842 cookie
.set('advanced_vlan_' + whichone
+ '_vis', 1);
846 function earlyInit() {
847 if(!port_vlan_supported
) {
848 E('save-button').disabled
= 1;
851 PORT_VLAN_SUPPORT_OVERRIDE
= ((nvram
['trunk_vlan_so'] == '1') ? 1 : 0);
856 <body onload='init()'
>
857 <form id='_fom' method='post' action='tomato.cgi'
>
858 <table id='container' cellspacing=
0>
859 <tr><td colspan=
2 id='header'
>
860 <div class='title'
>Tomato
</div>
861 <div class='version'
>Version <%
version(); %></div>
863 <tr id='body'
><td id='navi'
><script type='text/javascript'
>navi()</script></td>
865 <div id='ident'
><%
ident(); %></div>
866 <input type='hidden' name='_nextpage' value='advanced-vlan.asp'
>
867 <input type='hidden' name='_nextwait' value='
30'
>
868 <input type='hidden' name='_reboot' value='
1'
>
869 <input type='hidden' name='_nvset' value='
1'
>
870 <input type='hidden' name='_commit' value='
1'
>
871 <input type='hidden' name='vlan0ports'
>
872 <input type='hidden' name='vlan1ports'
>
873 <input type='hidden' name='vlan2ports'
>
874 <input type='hidden' name='vlan3ports'
>
875 <input type='hidden' name='vlan4ports'
>
876 <input type='hidden' name='vlan5ports'
>
877 <input type='hidden' name='vlan6ports'
>
878 <input type='hidden' name='vlan7ports'
>
879 <input type='hidden' name='vlan8ports'
>
880 <input type='hidden' name='vlan9ports'
>
881 <input type='hidden' name='vlan10ports'
>
882 <input type='hidden' name='vlan11ports'
>
883 <input type='hidden' name='vlan12ports'
>
884 <input type='hidden' name='vlan13ports'
>
885 <input type='hidden' name='vlan14ports'
>
886 <input type='hidden' name='vlan15ports'
>
887 <input type='hidden' name='vlan0hwname'
>
888 <input type='hidden' name='vlan1hwname'
>
889 <input type='hidden' name='vlan2hwname'
>
890 <input type='hidden' name='vlan3hwname'
>
891 <input type='hidden' name='vlan4hwname'
>
892 <input type='hidden' name='vlan5hwname'
>
893 <input type='hidden' name='vlan6hwname'
>
894 <input type='hidden' name='vlan7hwname'
>
895 <input type='hidden' name='vlan8hwname'
>
896 <input type='hidden' name='vlan9hwname'
>
897 <input type='hidden' name='vlan10hwname'
>
898 <input type='hidden' name='vlan11hwname'
>
899 <input type='hidden' name='vlan12hwname'
>
900 <input type='hidden' name='vlan13hwname'
>
901 <input type='hidden' name='vlan14hwname'
>
902 <input type='hidden' name='vlan15hwname'
>
903 <input type='hidden' name='wan_ifnameX'
>
904 <input type='hidden' name='manual_boot_nv'
>
905 <input type='hidden' name='lan_ifnames'
>
906 <input type='hidden' name='lan1_ifnames'
>
907 <input type='hidden' name='lan2_ifnames'
>
908 <input type='hidden' name='lan3_ifnames'
>
909 <input type='hidden' name='trunk_vlan_so'
>
910 <input type='hidden' name='vlan0vid'
>
911 <input type='hidden' name='vlan1vid'
>
912 <input type='hidden' name='vlan2vid'
>
913 <input type='hidden' name='vlan3vid'
>
914 <input type='hidden' name='vlan4vid'
>
915 <input type='hidden' name='vlan5vid'
>
916 <input type='hidden' name='vlan6vid'
>
917 <input type='hidden' name='vlan7vid'
>
918 <input type='hidden' name='vlan8vid'
>
919 <input type='hidden' name='vlan9vid'
>
920 <input type='hidden' name='vlan10vid'
>
921 <input type='hidden' name='vlan11vid'
>
922 <input type='hidden' name='vlan12vid'
>
923 <input type='hidden' name='vlan13vid'
>
924 <input type='hidden' name='vlan14vid'
>
925 <input type='hidden' name='vlan15vid'
>
927 <div id='sesdiv' style='display:none'
>
928 <div class='section-title'
>VLAN
</div>
929 <div class='section'
>
930 <table class='tomato-grid' cellspacing=
1 id='vlan-grid'
></table>
935 <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>
936 <div class='section' id='sesdiv_vidmap' style='display:none'
>
937 <script type='text/javascript'
>
938 createFieldTable('', [
939 { title
: 'First 802.1Q VLAN tag', name
: 'vlan0tag', type
: 'text', maxlen
:4, size
:6,
940 value
: fixInt(nvram
.vlan0tag
, 0, 4080, 0),
941 suffix
: ' <small><i>(range: 0 - 4080; must be a multiple of 16; set to 0 to disable)</i></small>' }
948 <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>
949 <div class='section' id='sesdiv_wireless' style='display:none'
>
950 <script type='text/javascript'
>
952 for (var uidx
= 0; uidx
< wl_ifaces
.length
; ++uidx
) {
953 var u
= wl_fface(uidx
);
955 { title
: ('Bridge ' + wl_ifaces
[uidx
][0] + ' to'), name
: ('f_bridge_wlan'+u
+'_to'), type
: 'select',
956 options
: [[0,'LAN (br0)'],[1,'LAN1 (br1)'],[2,'LAN2 (br2)'],[3,'LAN3 (br3)'],[4,'none']], value
: 4 } );
958 createFieldTable('',f
);
959 if(port_vlan_supported
) vlg
.setup();
965 <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>
966 <div class='section' id='sesdiv_notes' style='display:none'
>
968 <li><b>VLAN
</b> - Unique identifier of a VLAN.
</li>
969 <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>
970 <li><b>Ports
1-
4 & WAN
</b> - Which ethernet ports on the router should be members of this VLAN.
</li>
971 <li><b>Tagged
</b> - Enable
802.1Q tagging of ethernet frames on a particular port/VLAN
972 <script type='text/javascript'
>
973 if(!trunk_vlan_supported
)
974 W(' <i>(not known to be supported on this model)</i>');
977 <li><b>Default
</b> - VLAN ID assigned to untagged frames received by the router.
</li>
978 <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>
982 <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>
986 <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>
991 <li><b>Other relevant notes/hints:
</b>
993 <li>One VID
<i>must
</i> be assigned to WAN.
</li>
994 <li>One VID
<i>must
</i> be selected as the default.
</li>
995 <script type='text/javascript'
>
996 if((trunk_vlan_supported
) || (nvram
.trunk_vlan_so
== '1')) {
997 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>');
998 W('<li>It may be also recommended to avoid using VID "1" as some vendors consider it special/reserved (for management purposes).</li>');
1004 <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>
1005 <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>
1006 <li>You've been warned!
</li>
1009 <div id='trunk_vlan_override' style='display:none'
>
1010 <div class='section-title'
>Trunk VLAN support override (experimental)
</div>
1011 <div class='section'
>
1012 <script type='text/javascript'
>
1013 createFieldTable('', [
1014 { title
: 'Enable', name
: 'f_trunk_vlan_so', type
: 'checkbox', value
: nvram
.trunk_vlan_so
== '1' },
1023 <script type='text/javascript'
>
1024 if(!port_vlan_supported
)
1025 W('<i>This feature is not supported on this router.</i>');
1027 E('sesdiv').style
.display
= '';
1028 if(!trunk_vlan_supported
)
1029 E('trunk_vlan_override').style
.display
= '';
1033 <tr><td id='footer' colspan=
2>
1034 <span id='footer-msg'
></span>
1035 <input type='button' value='Save' id='save-button' onclick='save()'
>
1036 <input type='button' value='Cancel' id='cancel-button' onclick='javascript:reloadPage();'
>
1040 <script type='text/javascript'
>earlyInit(); verifyFields(null,1);</script>