1 <!DOCTYPE HTML PUBLIC '-//W3C//DTD HTML
4.0//EN'
>
4 Copyright (C) 2011 Augusto Bott
5 http://code.google.com/p/tomato-sdhc-vlan/
6 For use with Tomato Firmware only.
7 No part of this file may be used without permission.
11 <meta http-equiv='content-type' content='text/html;charset=utf-
8'
>
12 <meta name='robots' content='noindex,nofollow'
>
13 <title>[<%
ident(); %>] Advanced: VLAN
</title>
14 <link rel='stylesheet' type='text/css' href='tomato.css'
>
16 <script type='text/javascript' src='tomato.js'
></script>
17 <style type='text/css'
>
33 #vlan-grid .centered
{
37 <script type='text/javascript' src='wireless.jsx?_http_id=<%
nv(http_id
); %>'
></script>
38 <script type='text/javascript' src='interfaces.js'
></script>
39 <script type='text/javascript'
>
40 <% 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");%>
42 var port_vlan_supported
= 0;
43 var trunk_vlan_supported
= 0;
45 // does not seem to be strictly necessary for boardflags as it's supposed to be a bitmap
46 nvram
['boardflags'] = ((nvram
['boardflags'].toLowerCase().indexOf('0x') != -1) ? '0x' : '') + String('0000' + ((nvram
['boardflags'].toLowerCase()).replace('0x',''))).slice(-4);
47 // 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
48 nvram
['boardtype'] = ((nvram
['boardtype'].toLowerCase().indexOf('0x') != -1) ? '0x' : '') + String('0000' + ((nvram
['boardtype'].toLowerCase()).replace('0x',''))).slice(-4);
50 // see http://www.dd-wrt.com/wiki/index.php/Hardware#Boardflags and router/shared/id.c
51 if(nvram
['boardflags'] & 0x0100) { // BFL_ENETVLAN = this board has vlan capability
52 port_vlan_supported
= 1;
55 // TESTED ONLY ON WRT54G v2 (boardtype 0x0101) and WRT54GL v1.1 (boardtype 0x0467)
56 // attempt of cross-referencing boardtypes/routers mentioned on id.c and the wiki page above
57 switch(nvram
['boardtype']) {
58 case '0x0467': // WRT54GL 1.x, WRT54GS 3.x/4.x
59 case '0x048e': // WL-520GU, WL-500G Premium v2
60 case '0x04ef': // WRT320N/E2000
61 case '0x04cf': // WRT610Nv2/E3000, RT-N16
62 trunk_vlan_supported
= 1;
68 // TESTED ONLY ON WRT54G v2 (boardtype 0x0101),WRT54GL v1.1 (boardtype 0x0467) and WNR3500L (boardtype 0x04cf)
69 // info on some of these boardtypes/routers obtained from
70 // http://wiki.openwrt.org/toh/asus/start
71 // http://wiki.openwrt.org/toh/linksys/start
72 // http://wiki.openwrt.org/toh/start
73 switch(nvram
['boardtype']) {
74 case '0x0467': // WRT54GL 1.x, WRT54GS 3.x/4.x
75 case '0x048e': // WL-520GU, WL-500G Premium v2
82 case '0x04ef': // WRT320N/E2000
83 case '0x04cf': // WRT610Nv2/E3000, RT-N16, WNR3500L
90 // should work on WRT54G v2/v3, WRT54GS v1/v2 and others
111 var COL_VID_DEF
= 11;
114 // set to either 5 or 8 when nvram settings are read (FastE or GigE routers)
115 var SWITCH_INTERNAL_PORT
=0;
116 // option made available for experimental purposes on routers known to support port-based VLANs, but not confirmed to support 801.11q trunks
117 var PORT_VLAN_SUPPORT_OVERRIDE
=0;
119 function verifyFields(focused
, quiet
){
120 PORT_VLAN_SUPPORT_OVERRIDE
=(E('_f_trunk_vlan_so').checked
? 1 : 0);
121 var wlan
= E('_f_bridge_wlan_to');
122 if (wl_ifaces
.length
< 1) {
125 if(nvram
.lan_ifname
.length
< 1)
126 wlan
.options
[0].disabled
=true;
127 if(nvram
.lan1_ifname
.length
< 1)
128 wlan
.options
[1].disabled
=true;
129 if(nvram
.lan2_ifname
.length
< 1)
130 wlan
.options
[2].disabled
=true;
131 if(nvram
.lan3_ifname
.length
< 1)
132 wlan
.options
[3].disabled
=true;
137 if (vlg
.isEditing()) return;
140 fom
.trunk_vlan_so
.value
= (E('_f_trunk_vlan_so').checked
? 1 : 0);
141 // wipe out relevant fields just in case this is not the first time we try to submit
142 for (var i
= 0 ; i
<= MAX_VLAN_ID
; i
++) {
143 fom
['vlan' + i
+ 'ports'].value
= '';
144 fom
['vlan' + i
+ 'hwname'].value
= '';
146 fom
['wan_ifnameX'].value
= '';
147 fom
['lan_ifnames'].value
= '';
148 fom
['lan1_ifnames'].value
= '';
149 fom
['lan2_ifnames'].value
= '';
150 fom
['lan3_ifnames'].value
= '';
153 var d
= vlg
.getAllData();
155 for (var i
= 0; i
< d
.length
; ++i
) {
157 p
+= (d
[i
][COL_P0
].toString() != '0') ? COL_P0N
: '';
158 p
+= (((trunk_vlan_supported
) || (PORT_VLAN_SUPPORT_OVERRIDE
)) && (d
[i
][COL_P0T
].toString() != '0')) ? 't' : '';
159 p
+= trailingSpace(p
);
161 p
+= (d
[i
][COL_P1
].toString() != '0') ? COL_P1N
: '';
162 p
+= (((trunk_vlan_supported
) || (PORT_VLAN_SUPPORT_OVERRIDE
)) && (d
[i
][COL_P1T
].toString() != '0')) ? 't' : '';
163 p
+= trailingSpace(p
);
165 p
+= (d
[i
][COL_P2
].toString() != '0') ? COL_P2N
: '';
166 p
+= (((trunk_vlan_supported
) || (PORT_VLAN_SUPPORT_OVERRIDE
)) && (d
[i
][COL_P2T
].toString() != '0')) ? 't' : '';
167 p
+= trailingSpace(p
);
169 p
+= (d
[i
][COL_P3
].toString() != '0') ? COL_P3N
: '';
170 p
+= (((trunk_vlan_supported
) || (PORT_VLAN_SUPPORT_OVERRIDE
)) && (d
[i
][COL_P3T
].toString() != '0')) ? 't' : '';
171 p
+= trailingSpace(p
);
173 p
+= (d
[i
][COL_P4
].toString() != '0') ? COL_P4N
: '';
174 p
+= (((trunk_vlan_supported
) || (PORT_VLAN_SUPPORT_OVERRIDE
)) && (d
[i
][COL_P4T
].toString() != '0')) ? 't' : '';
175 p
+= trailingSpace(p
);
177 p
+= (d
[i
][COL_VID_DEF
].toString() != '0') ? (SWITCH_INTERNAL_PORT
+ '*') : SWITCH_INTERNAL_PORT
;
179 // arrange port numbers in ascending order just to be safe (not sure if this is really needed... mostly, cosmetics?)
184 v
+= (d
[i
][COL_VID_DEF
].toString() != '0') ? d
[i
][0] : '';
186 fom
['vlan'+d
[i
][COL_VID
]+'ports'].value
= p
;
187 fom
['vlan'+d
[i
][COL_VID
]+'hwname'].value
= 'et0';
189 fom
['wan_ifnameX'].value
+= (d
[i
][COL_BRI
] == '2') ? 'vlan'+d
[i
][0] : '';
190 fom
['lan_ifnames'].value
+= (d
[i
][COL_BRI
] == '3') ? 'vlan'+d
[i
][0] : '';
192 // fom['lan_ifnames'].value += trailingSpace(fom['lan_ifnames'].value);
193 // 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);
195 fom
['lan1_ifnames'].value
+= (d
[i
][COL_BRI
] == '4') ? 'vlan'+d
[i
][0] : '';
196 fom
['lan2_ifnames'].value
+= (d
[i
][COL_BRI
] == '5') ? 'vlan'+d
[i
][0] : '';
197 fom
['lan3_ifnames'].value
+= (d
[i
][COL_BRI
] == '6') ? 'vlan'+d
[i
][0] : '';
200 var wlan
= E('_f_bridge_wlan_to');
202 // alert(wlan.selectedIndex);
204 switch(parseInt(wlan
.selectedIndex
)) {
206 fom
['lan_ifnames'].value
+= ' ' + wl_ifaces
[0][0];
209 fom
['lan1_ifnames'].value
+= ' ' + wl_ifaces
[0][0];
212 fom
['lan2_ifnames'].value
+= ' ' + wl_ifaces
[0][0];
215 fom
['lan3_ifnames'].value
+= ' ' + wl_ifaces
[0][0];
219 // var lif = nvram['lan_ifnames'].split(' ');
220 // for (var j = 0; j < lif.length; j++) {
221 // fom['lan_ifnames'].value += (lif[j].indexOf('vlan') != -1) ? '' : lif[j];
222 // fom['lan_ifnames'].value += trailingSpace(fom['lan_ifnames'].value);
224 // alert('lan_ifnames=' + fom['lan_ifnames'].value);
225 // alert('lan1_ifnames=' + fom['lan1_ifnames'].value);
226 // alert('lan2_ifnames=' + fom['lan2_ifnames'].value);
227 // alert('lan3_ifnames=' + fom['lan3_ifnames'].value);
230 // for some models, Tomato checks for a few vital/crucial nvram settings at init time
231 // in some cases, if some/any of them are not found, a full nvram reset/clean could be triggered
232 // so, to (try to) play it safe, we check for the 1st needed/available/required
233 // VLAN for FastE (vlan0 is usually LAN) and GigE routers (vlan1 is usually LAN)
234 if((fom
['vlan0ports'].value
.length
< 1) || (fom
['vlan0hwname'].value
.length
< 1) ||
235 (fom
['vlan1ports'].value
.length
< 1) || (fom
['vlan1hwname'].value
.length
< 1))
236 fom
['manual_boot_nv'].value
= '1';
238 fom
['manual_boot_nv'].value
= nvram
['manual_boot_nv'];
240 var e
= E('footer-msg');
242 if(vlg
.countWan() != 1) {
243 e
.innerHTML
= 'Cannot proceed: one VID must be assigned to WAN.';
244 e
.style
.visibility
= 'visible';
248 e
.style
.visibility
= 'hidden';
253 if(vlg
.countLan(0) != 1) {
254 e
.innerHTML
= 'Cannot proceed: one and only one VID must be assigned to the primary LAN (br0).';
255 e
.style
.visibility
= 'visible';
259 e
.style
.visibility
= 'hidden';
265 e
.innerHTML
= 'Cannot proceed without setting a default VID';
266 e
.style
.visibility
= 'visible';
270 e
.style
.visibility
= 'hidden';
276 if (confirm("Network will be restarted on this router. Proceed?"))
278 if (confirm("Router must be rebooted to proceed. Commit changes to NVRAM and reboot now?"))
282 function trailingSpace(s
)
284 return ((s
.length
>0)&&(s
.charAt(s
.length
-1) != ' ')) ? ' ' : '';
287 if(port_vlan_supported
) { // aka if(supported_hardware) block
288 var vlg
= new TomatoGrid();
289 vlg
.setup = function() {
290 this.init('vlan-grid', '', (MAX_VLAN_ID
+ 1), [
291 { 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>' },
292 { type
: 'checkbox', prefix
: '<div class="centered">', suffix
: '</div>' },
293 { type
: 'checkbox', prefix
: '<div class="centered">', suffix
: '</div>' },
294 { type
: 'checkbox', prefix
: '<div class="centered">', suffix
: '</div>' },
295 { type
: 'checkbox', prefix
: '<div class="centered">', suffix
: '</div>' },
296 { type
: 'checkbox', prefix
: '<div class="centered">', suffix
: '</div>' },
297 { type
: 'checkbox', prefix
: '<div class="centered">', suffix
: '</div>' },
298 { type
: 'checkbox', prefix
: '<div class="centered">', suffix
: '</div>' },
299 { type
: 'checkbox', prefix
: '<div class="centered">', suffix
: '</div>' },
300 { type
: 'checkbox', prefix
: '<div class="centered">', suffix
: '</div>' },
301 { type
: 'checkbox', prefix
: '<div class="centered">', suffix
: '</div>' },
302 { type
: 'checkbox', prefix
: '<div class="centered">', suffix
: '</div>' },
303 { 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>' }]);
305 this.headerSet(['VID', 'Port 1', 'Tagged', 'Port 2', 'Tagged', 'Port 3', 'Tagged', 'Port 4', 'Tagged', 'WAN Port', 'Tagged', 'Default', 'Bridge']);
307 // find out which vlans are supposed to be bridged to each LAN
310 for (var i
= 0 ; i
<= MAX_BRIDGE_ID
; i
++) {
311 var j
= (i
== 0) ? '' : i
.toString();
312 var l
= nvram
['lan' + j
+ '_ifnames'].split(' ');
314 // alert('lan' + j + '_ifnames=' + l);
316 for (var k
= 0 ; k
< l
.length
; k
++) {
318 // alert("bridge br" + i + "=vlan" + parseInt(l[k].replace('vlan','')));
320 if(l
[k
].indexOf('vlan') != -1) {
322 // alert('lan' + j + '_ifname=br' + nvram['lan' + j + '_ifname'].replace('br',''));
324 if (nvram
['lan' + j
+ '_ifname'] != '')
325 bridged
[parseInt(l
[k
].replace('vlan',''))] = (3 + parseInt(nvram
['lan' + j
+ '_ifname'].replace('br',''))).toString();
327 bridged
[parseInt(l
[k
].replace('vlan',''))] = '1';
330 for (var uidx
= 0; uidx
< wl_ifaces
.length
; ++uidx
) {
331 if(l
[k
].indexOf(wl_ifaces
[uidx
][0]) != -1) {
332 E('_f_bridge_wlan_to').selectedIndex
=i
;
339 bridged
[parseInt(nvram
['wan_ifnameX'].replace('vlan',''))] = '2';
341 // go thru all possible VLANs
342 for (var i
= 0 ; i
<= MAX_VLAN_ID
; i
++) {
345 if ((nvram
['vlan' + i
+ 'hwname'].length
> 0) || (nvram
['vlan' + i
+ 'ports'].length
> 0)) {
346 // (re)initialize our bitmap for this particular iteration
347 for (var j
=0; j
<= MAX_PORT_ID
; j
++) {
351 // which ports are members of this VLAN?
352 var m
=nvram
['vlan' + i
+ 'ports'].split(' ');
353 for (var j
= 0; j
< (m
.length
) ; j
++) {
354 port
[parseInt(m
[j
].charAt(0))] = '1';
355 tagged
[parseInt(m
[j
].charAt(0))] = (((trunk_vlan_supported
) || (PORT_VLAN_SUPPORT_OVERRIDE
)) && (m
[j
].indexOf('t') != -1)) ? '1' : '0';
358 if (port_vlan_supported
) {
359 if((nvram
['vlan' + i
+ 'ports']).indexOf('*') != -1)
360 SWITCH_INTERNAL_PORT
=(nvram
['vlan' + i
+ 'ports']).charAt((nvram
['vlan' + i
+ 'ports']).indexOf('*')-1);
362 vlg
.insertData(-1, [ i
.toString(),
363 port
[COL_P0N
], tagged
[COL_P0N
],
364 port
[COL_P1N
], tagged
[COL_P1N
],
365 port
[COL_P2N
], tagged
[COL_P2N
],
366 port
[COL_P3N
], tagged
[COL_P3N
],
367 port
[COL_P4N
], tagged
[COL_P4N
],
368 (((nvram
['vlan' + i
+ 'ports']).indexOf('*') != -1) ? '1' : '0' ),
369 (bridged
[i
] != null) ? bridged
[i
] : '1' ]);
373 vlg
.canDelete
= false;
376 vlg
.resetNewEditor();
379 vlg
.countElem = function(f
, v
)
381 var data
= this.getAllData();
383 for (var i
= 0; i
< data
.length
; ++i
) {
384 total
+= (data
[i
][f
] == v
) ? 1 : 0;
389 vlg
.countDefaultVID = function()
391 return this.countElem(COL_VID_DEF
,1);
394 vlg
.countVID = function (v
)
396 return this.countElem(COL_VID
,v
);
399 vlg
.countWan = function()
401 return this.countElem(COL_BRI
,2);
404 vlg
.countLan = function(l
)
406 return this.countElem(COL_BRI
,l
+3);
409 vlg
.verifyFields = function(row
, quiet
) {
411 var f
= fields
.getAll(row
);
413 for(var i
=0; i
<= MAX_VLAN_ID
; i
++) {
414 f
[COL_VID
].options
[i
].disabled
= (this.countVID(i
) > 0);
417 for (var i
=0; i
<= MAX_BRIDGE_ID
; i
++) {
418 var j
= (i
==0) ? '' : i
.toString();
419 f
[COL_BRI
].options
[i
+2].disabled
= (nvram
['lan' + j
+ '_ifname'].length
< 1);
422 if(((trunk_vlan_supported
) || (PORT_VLAN_SUPPORT_OVERRIDE
)) && (f
[COL_P0
].checked
== 1)) {
423 f
[COL_P0T
].disabled
=0;
425 f
[COL_P0T
].disabled
=1;
426 f
[COL_P0T
].checked
=0;
428 if(((trunk_vlan_supported
) || (PORT_VLAN_SUPPORT_OVERRIDE
)) && (f
[COL_P1
].checked
== 1)) {
429 f
[COL_P1T
].disabled
=0;
431 f
[COL_P1T
].disabled
=1;
432 f
[COL_P1T
].checked
=0;
434 if(((trunk_vlan_supported
) || (PORT_VLAN_SUPPORT_OVERRIDE
)) && (f
[COL_P2
].checked
== 1)) {
435 f
[COL_P2T
].disabled
=0;
437 f
[COL_P2T
].disabled
=1;
438 f
[COL_P2T
].checked
=0;
440 if(((trunk_vlan_supported
) || (PORT_VLAN_SUPPORT_OVERRIDE
)) && (f
[COL_P3
].checked
== 1)) {
441 f
[COL_P3T
].disabled
=0;
443 f
[COL_P3T
].disabled
=1;
444 f
[COL_P3T
].checked
=0;
446 if(((trunk_vlan_supported
) || (PORT_VLAN_SUPPORT_OVERRIDE
)) && (f
[COL_P4
].checked
== 1)) {
447 f
[COL_P4T
].disabled
=0;
449 f
[COL_P4T
].disabled
=1;
450 f
[COL_P4T
].checked
=0;
453 if(this.countDefaultVID() > 0) {
454 f
[COL_VID_DEF
].disabled
=1;
455 f
[COL_VID_DEF
].checked
=0;
458 if((this.countDefaultVID() > 0) && (f
[COL_VID_DEF
].checked
==1)) {
459 ferror
.set(f
[COL_VID_DEF
], 'Only one VID can be selected as the default VID', quiet
);
462 ferror
.clear(f
[COL_VID_DEF
]);
465 if(this.countVID(f
[COL_VID
].selectedIndex
) > 0) {
466 ferror
.set(f
[COL_VID
], 'Cannot add more than one entry with VID ' + f
[0].selectedIndex
, quiet
);
469 ferror
.clear(f
[COL_VID
]);
472 if ((this.countWan() > 0) && (f
[COL_BRI
].selectedIndex
== 1)) {
473 ferror
.set(f
[COL_BRI
],'Only one VID can be used as WAN at any time', quiet
);
476 ferror
.clear(f
[COL_BRI
]);
479 for(var i
=0; i
<4; i
++) {
480 if ((this.countLan(i
) > 0) && (f
[COL_BRI
].selectedIndex
== (i
+2))) {
481 ferror
.set(f
[COL_BRI
],'One and only one VID can be used for LAN' + ((i
==0) ? '' : i
) + ' (br'+i
+') at any time', quiet
);
484 ferror
.clear(f
[COL_BRI
]);
491 vlg
.dataToView = function(data
) {
492 return [data
[COL_VID
],
493 (data
[COL_P0
].toString() != '0') ? 'Yes' : '',
494 (data
[COL_P0T
].toString() != '0') ? 'On' : '',
495 (data
[COL_P1
].toString() != '0') ? 'Yes' : '',
496 (data
[COL_P1T
].toString() != '0') ? 'On' : '',
497 (data
[COL_P2
].toString() != '0') ? 'Yes' : '',
498 (data
[COL_P2T
].toString() != '0') ? 'On' : '',
499 (data
[COL_P3
].toString() != '0') ? 'Yes' : '',
500 (data
[COL_P3T
].toString() != '0') ? 'On' : '',
501 (data
[COL_P4
].toString() != '0') ? 'Yes' : '',
502 (data
[COL_P4T
].toString() != '0') ? 'On' : '',
503 (data
[COL_VID_DEF
].toString() != '0') ? '*' : '',
504 ['', 'WAN', 'LAN (br0)', 'LAN1 (br1)', 'LAN2 (br2)', 'LAN3 (br3)' ][data
[COL_BRI
] - 1]];
507 vlg
.dataToFieldValues = function (data
) {
508 return [data
[COL_VID
],
509 (data
[COL_P0
] != 0) ? 'checked' : '',
510 (data
[COL_P0T
] != 0) ? 'checked' : '',
511 (data
[COL_P1
] != 0) ? 'checked' : '',
512 (data
[COL_P1T
] != 0) ? 'checked' : '',
513 (data
[COL_P2
] != 0) ? 'checked' : '',
514 (data
[COL_P2T
] != 0) ? 'checked' : '',
515 (data
[COL_P3
] != 0) ? 'checked' : '',
516 (data
[COL_P3T
] != 0) ? 'checked' : '',
517 (data
[COL_P4
] != 0) ? 'checked' : '',
518 (data
[COL_P4T
] != 0) ? 'checked' : '',
519 (data
[COL_VID_DEF
] != 0) ? 'checked' : '',
523 vlg
.fieldValuesToData = function(row
) {
524 var f
= fields
.getAll(row
);
525 return [f
[COL_VID
].value
,
526 f
[COL_P0
].checked
? 1 : 0,
527 f
[COL_P0T
].checked
? 1 : 0,
528 f
[COL_P1
].checked
? 1 : 0,
529 f
[COL_P1T
].checked
? 1 : 0,
530 f
[COL_P2
].checked
? 1 : 0,
531 f
[COL_P2T
].checked
? 1 : 0,
532 f
[COL_P3
].checked
? 1 : 0,
533 f
[COL_P3T
].checked
? 1 : 0,
534 f
[COL_P4
].checked
? 1 : 0,
535 f
[COL_P4T
].checked
? 1 : 0,
536 f
[COL_VID_DEF
].checked
? 1 : 0,
540 vlg
.onCancel = function() {
543 this.disableNewEditor(false);
545 this.resetNewEditor();
548 vlg
.onAdd = function() {
554 if (!this.verifyFields(this.newEditor
, false)) return;
556 data
= this.fieldValuesToData(this.newEditor
);
557 this.insertData(-1, data
);
559 this.disableNewEditor(false);
560 this.resetNewEditor();
565 vlg
.onOK = function() {
568 if (!this.verifyFields(this.editor
, false)) return;
570 data
= this.fieldValuesToData(this.editor
);
571 view
= this.dataToView(data
);
573 this.source
.setRowData(data
);
574 for (i
= 0; i
< this.source
.cells
.length
; ++i
) {
575 this.source
.cells
[i
].innerHTML
= view
[i
];
580 this.disableNewEditor(false);
582 this.resetNewEditor();
586 vlg
.onDelete = function() {
588 elem
.remove(this.source
);
590 this.disableNewEditor(false);
592 this.resetNewEditor();
595 vlg
.sortCompare = function(a
, b
) {
597 var col
= obj
.sortColumn
;
598 if (this.sortColumn
== 0) {
599 var r
= cmpInt(parseInt(a
.cells
[col
].innerHTML
), parseInt(b
.cells
[col
].innerHTML
));
601 var r
= cmpText(a
.cells
[col
].innerHTML
, b
.cells
[col
].innerHTML
);
603 return obj
.sortAscending
? r
: -r
;
606 vlg
.resetNewEditor = function() {
607 var f
= fields
.getAll(this.newEditor
);
609 for (var i
=0; i
<= MAX_BRIDGE_ID
; i
++) {
610 var j
= (i
==0) ? '' : i
.toString();
611 f
[COL_BRI
].options
[i
+2].disabled
= (nvram
['lan' + j
+ '_ifname'].length
< 1);
614 f
[COL_VID
].selectedIndex
=0;
616 while((this.countVID(f
[COL_VID
].selectedIndex
) > 0) && (t
> 0)) {
617 f
[COL_VID
].selectedIndex
= (f
[COL_VID
].selectedIndex
%(MAX_VLAN_ID
))+1;
621 for(var i
=0; i
<= MAX_VLAN_ID
; i
++) {
622 f
[COL_VID
].options
[i
].disabled
= (this.countVID(i
) > 0);
625 f
[COL_P0
].checked
= 0;
626 f
[COL_P0T
].checked
= 0;
627 f
[COL_P0T
].disabled
= 1;
628 f
[COL_P1
].checked
= 0;
629 f
[COL_P1T
].checked
= 0;
630 f
[COL_P1T
].disabled
= 1;
631 f
[COL_P2
].checked
= 0;
632 f
[COL_P2T
].checked
= 0;
633 f
[COL_P2T
].disabled
= 1;
634 f
[COL_P3
].checked
= 0;
635 f
[COL_P3T
].checked
= 0;
636 f
[COL_P3T
].disabled
= 1;
637 f
[COL_P4
].checked
= 0;
638 f
[COL_P4T
].checked
= 0;
639 f
[COL_P4T
].disabled
= 1;
640 f
[COL_VID_DEF
].checked
= 0;
641 if (this.countDefaultVID()>0)
642 f
[COL_VID_DEF
].disabled
= 1;
643 f
[COL_BRI
].selectedIndex
= 0;
644 ferror
.clearAll(fields
.getAll(this.newEditor
));
646 } // end of the so-called if(supported_device) block
650 if(port_vlan_supported
) {
652 vlg
.resetNewEditor();
658 if(!port_vlan_supported
) {
659 E('save-button').disabled
= 1;
662 PORT_VLAN_SUPPORT_OVERRIDE
= ((nvram
['trunk_vlan_so'] == '1') ? 1 : 0);
667 <body onload='init()'
>
668 <form id='_fom' method='post' action='tomato.cgi'
>
669 <table id='container' cellspacing=
0>
670 <tr><td colspan=
2 id='header'
>
671 <div class='title'
>Tomato
</div>
672 <div class='version'
>Version <%
version(); %></div>
674 <tr id='body'
><td id='navi'
><script type='text/javascript'
>navi()</script></td>
676 <div id='ident'
><%
ident(); %></div>
677 <input type='hidden' name='_nextpage' value='advanced-vlan.asp'
>
678 <input type='hidden' name='_nextwait' value='
30'
>
679 <input type='hidden' name='_reboot' value='
1'
>
680 <input type='hidden' name='_nvset' value='
1'
>
681 <input type='hidden' name='_commit' value='
1'
>
682 <input type='hidden' name='vlan0ports'
>
683 <input type='hidden' name='vlan1ports'
>
684 <input type='hidden' name='vlan2ports'
>
685 <input type='hidden' name='vlan3ports'
>
686 <input type='hidden' name='vlan4ports'
>
687 <input type='hidden' name='vlan5ports'
>
688 <input type='hidden' name='vlan6ports'
>
689 <input type='hidden' name='vlan7ports'
>
690 <input type='hidden' name='vlan8ports'
>
691 <input type='hidden' name='vlan9ports'
>
692 <input type='hidden' name='vlan10ports'
>
693 <input type='hidden' name='vlan11ports'
>
694 <input type='hidden' name='vlan12ports'
>
695 <input type='hidden' name='vlan13ports'
>
696 <input type='hidden' name='vlan14ports'
>
697 <input type='hidden' name='vlan15ports'
>
698 <input type='hidden' name='vlan0hwname'
>
699 <input type='hidden' name='vlan1hwname'
>
700 <input type='hidden' name='vlan2hwname'
>
701 <input type='hidden' name='vlan3hwname'
>
702 <input type='hidden' name='vlan4hwname'
>
703 <input type='hidden' name='vlan5hwname'
>
704 <input type='hidden' name='vlan6hwname'
>
705 <input type='hidden' name='vlan7hwname'
>
706 <input type='hidden' name='vlan8hwname'
>
707 <input type='hidden' name='vlan9hwname'
>
708 <input type='hidden' name='vlan10hwname'
>
709 <input type='hidden' name='vlan11hwname'
>
710 <input type='hidden' name='vlan12hwname'
>
711 <input type='hidden' name='vlan13hwname'
>
712 <input type='hidden' name='vlan14hwname'
>
713 <input type='hidden' name='vlan15hwname'
>
714 <input type='hidden' name='wan_ifnameX'
>
715 <input type='hidden' name='manual_boot_nv'
>
716 <input type='hidden' name='lan_ifnames'
>
717 <input type='hidden' name='lan1_ifnames'
>
718 <input type='hidden' name='lan2_ifnames'
>
719 <input type='hidden' name='lan3_ifnames'
>
720 <input type='hidden' name='trunk_vlan_so'
>
722 <div id='sesdiv' style='display:none'
>
723 <div class='section-title'
>VLAN
</div>
724 <div class='section'
>
725 <table class='tomato-grid' cellspacing=
1 id='vlan-grid'
></table>
726 <script type='text/javascript'
>
727 createFieldTable('', [
728 { title
: 'Bridge WLAN to', name
: 'f_bridge_wlan_to', type
: 'select', options
: [[0,'LAN (br0)'],[1,'LAN1 (br1)'],[2,'LAN2 (br2)'],[3,'LAN3 (br3)'],[4,'none']] }
730 if(port_vlan_supported
) vlg
.setup();
734 <div class='section-title'
>Notes
</div>
735 <div class='section'
>
737 <li><b>VID
</b> - Unique identifier of a VLAN.
</li>
738 <li><b>Ports
1-
4 & WAN
</b> - Which ethernet ports on the router should be members of this VLAN.
</li>
739 <li><b>Tagged
</b> - Enable
802.1q tagging of ethernet frames on a particular port/VLAN
740 <script type='text/javascript'
>
741 if(!trunk_vlan_supported
)
742 W(' <i>(not known to be supported on this model)</i>');
745 <li><b>Default
</b> - VLAN ID assigned to untagged frames received by the router.
</li>
746 <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>
750 <li><b>Other relevant notes/hints:
</b>
752 <li>One VID
<i>must
</i> be assigned to WAN.
</li>
753 <li>One VID
<i>must
</i> be selected as the default.
</li>
754 <script type='text/javascript'
>
755 if((trunk_vlan_supported
) || (nvram
.trunk_vlan_so
== '1'))
756 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.</li>');
760 <div id='trunk_vlan_override' style='display:none'
>
761 <div class='section-title'
>Trunk VLAN support override (experimental)
</div>
762 <div class='section'
>
763 <script type='text/javascript'
>
764 createFieldTable('', [
765 { title
: 'Enable', name
: 'f_trunk_vlan_so', type
: 'checkbox', value
: nvram
.trunk_vlan_so
== '1' },
774 <script type='text/javascript'
>
775 if(!port_vlan_supported
)
776 W('<i>This feature is not supported on this router.</i>');
778 E('sesdiv').style
.display
= '';
779 if(!trunk_vlan_supported
)
780 E('trunk_vlan_override').style
.display
= '';
784 <tr><td id='footer' colspan=
2>
785 <span id='footer-msg'
></span>
786 <input type='button' value='Save' id='save-button' onclick='save()'
>
787 <input type='button' value='Cancel' id='cancel-button' onclick='javascript:reloadPage();'
>
791 <script type='text/javascript'
>earlyInit(); verifyFields(null,1);</script>