11 'require tools.widgets as widgets';
12 'require tools.network as nettools';
14 var isReadonlyView
= !L
.hasViewPermission() || null;
16 function count_changes(section_id
) {
17 var changes
= ui
.changes
.changes
, n
= 0;
19 if (!L
.isObject(changes
))
22 if (Array
.isArray(changes
.network
))
23 for (var i
= 0; i
< changes
.network
.length
; i
++)
24 n
+= (changes
.network
[i
][1] == section_id
);
26 if (Array
.isArray(changes
.dhcp
))
27 for (var i
= 0; i
< changes
.dhcp
.length
; i
++)
28 n
+= (changes
.dhcp
[i
][1] == section_id
);
33 function render_iface(dev
, alias
) {
34 var type
= dev
? dev
.getType() : 'ethernet',
35 up
= dev
? dev
.isUp() : false;
37 return E('span', { class: 'cbi-tooltip-container' }, [
38 E('img', { 'class' : 'middle', 'src': L
.resource('icons/%s%s.png').format(
39 alias
? 'alias' : type
,
40 up
? '' : '_disabled') }),
41 E('span', { 'class': 'cbi-tooltip ifacebadge large' }, [
42 E('img', { 'src': L
.resource('icons/%s%s.png').format(
43 type
, up
? '' : '_disabled') }),
44 L
.itemlist(E('span', { 'class': 'left' }), [
45 _('Type'), dev
? dev
.getTypeI18n() : null,
46 _('Device'), dev
? dev
.getName() : _('Not present'),
47 _('Connected'), up
? _('yes') : _('no'),
48 _('MAC'), dev
? dev
.getMAC() : null,
49 _('RX'), dev
? '%.2mB (%d %s)'.format(dev
.getRXBytes(), dev
.getRXPackets(), _('Pkts.')) : null,
50 _('TX'), dev
? '%.2mB (%d %s)'.format(dev
.getTXBytes(), dev
.getTXPackets(), _('Pkts.')) : null
56 function render_status(node
, ifc
, with_device
) {
57 var desc
= null, c
= [];
60 desc
= _('Virtual dynamic interface');
61 else if (ifc
.isAlias())
62 desc
= _('Alias Interface');
63 else if (!uci
.get('network', ifc
.getName()))
64 return L
.itemlist(node
, [
65 null, E('em', _('Interface is marked for deletion'))
68 var i18n
= ifc
.getI18n();
70 desc
= desc
? '%s (%s)'.format(desc
, i18n
) : i18n
;
72 var changecount
= with_device
? 0 : count_changes(ifc
.getName()),
73 ipaddrs
= changecount
? [] : ifc
.getIPAddrs(),
74 ip6addrs
= changecount
? [] : ifc
.getIP6Addrs(),
75 errors
= ifc
.getErrors(),
76 maindev
= ifc
.getL3Device() || ifc
.getDevice(),
77 macaddr
= maindev
? maindev
.getMAC() : null;
79 return L
.itemlist(node
, [
80 _('Protocol'), with_device
? null : (desc
|| '?'),
81 _('Device'), with_device
? (maindev
? maindev
.getShortName() : E('em', _('Not present'))) : null,
82 _('Uptime'), (!changecount
&& ifc
.isUp()) ? '%t'.format(ifc
.getUptime()) : null,
83 _('MAC'), (!changecount
&& !ifc
.isDynamic() && !ifc
.isAlias() && macaddr
) ? macaddr
: null,
84 _('RX'), (!changecount
&& !ifc
.isDynamic() && !ifc
.isAlias() && maindev
) ? '%.2mB (%d %s)'.format(maindev
.getRXBytes(), maindev
.getRXPackets(), _('Pkts.')) : null,
85 _('TX'), (!changecount
&& !ifc
.isDynamic() && !ifc
.isAlias() && maindev
) ? '%.2mB (%d %s)'.format(maindev
.getTXBytes(), maindev
.getTXPackets(), _('Pkts.')) : null,
86 _('IPv4'), ipaddrs
[0],
87 _('IPv4'), ipaddrs
[1],
88 _('IPv4'), ipaddrs
[2],
89 _('IPv4'), ipaddrs
[3],
90 _('IPv4'), ipaddrs
[4],
91 _('IPv6'), ip6addrs
[0],
92 _('IPv6'), ip6addrs
[1],
93 _('IPv6'), ip6addrs
[2],
94 _('IPv6'), ip6addrs
[3],
95 _('IPv6'), ip6addrs
[4],
96 _('IPv6'), ip6addrs
[5],
97 _('IPv6'), ip6addrs
[6],
98 _('IPv6'), ip6addrs
[7],
99 _('IPv6'), ip6addrs
[8],
100 _('IPv6'), ip6addrs
[9],
101 _('IPv6-PD'), changecount
? null : ifc
.getIP6Prefix(),
102 _('Information'), with_device
? null : (ifc
.get('auto') != '0' ? null : _('Not started on boot')),
103 _('Error'), errors
? errors
[0] : null,
104 _('Error'), errors
? errors
[1] : null,
105 _('Error'), errors
? errors
[2] : null,
106 _('Error'), errors
? errors
[3] : null,
107 _('Error'), errors
? errors
[4] : null,
108 null, changecount
? E('a', {
110 click
: L
.bind(ui
.changes
.displayChanges
, ui
.changes
)
111 }, _('Interface has %d pending changes').format(changecount
)) : null
115 function render_modal_status(node
, ifc
) {
116 var dev
= ifc
? (ifc
.getDevice() || ifc
.getL3Device() || ifc
.getL3Device()) : null;
120 'src': L
.resource('icons/%s%s.png').format(dev
? dev
.getType() : 'ethernet', (dev
&& dev
.isUp()) ? '' : '_disabled'),
121 'title': dev
? dev
.getTypeI18n() : _('Not present')
123 ifc
? render_status(E('span'), ifc
, true) : E('em', _('Interface not present or not connected yet.'))
129 function render_ifacebox_status(node
, ifc
) {
130 var dev
= ifc
.getL3Device() || ifc
.getDevice(),
131 subdevs
= ifc
.getDevices(),
132 c
= [ render_iface(dev
, ifc
.isAlias()) ];
134 if (subdevs
&& subdevs
.length
) {
137 for (var j
= 0; j
< subdevs
.length
; j
++)
138 sifs
.push(render_iface(subdevs
[j
]));
142 c
.push(E('span', {}, sifs
));
146 c
.push(E('small', {}, ifc
.isAlias() ? _('Alias of "%s"').format(ifc
.isAlias())
147 : (dev
? dev
.getName() : E('em', _('Not present')))));
149 dom
.content(node
, c
);
151 return firewall
.getZoneByNetwork(ifc
.getName()).then(L
.bind(function(zone
) {
152 this.style
.backgroundColor
= zone
? zone
.getColor() : '#EEEEEE';
153 this.title
= zone
? _('Part of zone %q').format(zone
.getName()) : _('No zone assigned');
154 }, node
.previousElementSibling
));
157 function iface_updown(up
, id
, ev
, force
) {
158 var row
= document
.querySelector('.cbi-section-table-row[data-sid="%s"]'.format(id
)),
159 dsc
= row
.querySelector('[data-name="_ifacestat"] > div'),
160 btns
= row
.querySelectorAll('.cbi-section-actions .reconnect, .cbi-section-actions .down');
163 btns
[+!up
].classList
.add('spinning');
165 btns
[0].disabled
= true;
166 btns
[1].disabled
= true;
169 L
.resolveDefault(fs
.exec_direct('/usr/libexec/luci-peeraddr')).then(function(res
) {
170 var info
= null; try { info
= JSON
.parse(res
); } catch(e
) {}
172 if (L
.isObject(info
) &&
173 Array
.isArray(info
.inbound_interfaces
) &&
174 info
.inbound_interfaces
.filter(function(i
) { return i
== id
})[0]) {
176 ui
.showModal(_('Confirm disconnect'), [
177 E('p', _('You appear to be currently connected to the device via the "%h" interface. Do you really want to shut down the interface?').format(id
)),
178 E('div', { 'class': 'right' }, [
180 'class': 'cbi-button cbi-button-neutral',
181 'click': function(ev
) {
182 btns
[1].classList
.remove('spinning');
183 btns
[1].disabled
= false;
184 btns
[0].disabled
= false;
191 'class': 'cbi-button cbi-button-negative important',
192 'click': function(ev
) {
193 dsc
.setAttribute('disconnect', '');
194 dom
.content(dsc
, E('em', _('Interface is shutting down...')));
203 dsc
.setAttribute('disconnect', '');
204 dom
.content(dsc
, E('em', _('Interface is shutting down...')));
209 dsc
.setAttribute(up
? 'reconnect' : 'disconnect', force
? 'force' : '');
210 dom
.content(dsc
, E('em', up
? _('Interface is reconnecting...') : _('Interface is shutting down...')));
214 function get_netmask(s
, use_cfgvalue
) {
215 var readfn
= use_cfgvalue
? 'cfgvalue' : 'formvalue',
216 addrs
= L
.toArray(s
[readfn
](s
.section
, 'ipaddr')),
217 mask
= s
[readfn
](s
.section
, 'netmask'),
218 firstsubnet
= mask
? addrs
[0] + '/' + mask
: addrs
.filter(function(a
) { return a
.indexOf('/') > 0 })[0];
220 if (firstsubnet
== null)
223 var subnetmask
= firstsubnet
.split('/')[1];
225 if (!isNaN(subnetmask
))
226 subnetmask
= network
.prefixToMask(+subnetmask
);
232 poll_status: function(map
, networks
) {
233 var resolveZone
= null;
235 for (var i
= 0; i
< networks
.length
; i
++) {
236 var ifc
= networks
[i
],
237 row
= map
.querySelector('.cbi-section-table-row[data-sid="%s"]'.format(ifc
.getName()));
242 var dsc
= row
.querySelector('[data-name="_ifacestat"] > div'),
243 box
= row
.querySelector('[data-name="_ifacebox"] .ifacebox-body'),
244 btn1
= row
.querySelector('.cbi-section-actions .reconnect'),
245 btn2
= row
.querySelector('.cbi-section-actions .down'),
246 stat
= document
.querySelector('[id="%s-ifc-status"]'.format(ifc
.getName())),
247 resolveZone
= render_ifacebox_status(box
, ifc
),
248 disabled
= ifc
? !ifc
.isUp() : true,
249 dynamic
= ifc
? ifc
.isDynamic() : false;
251 if (dsc
.hasAttribute('reconnect')) {
252 dom
.content(dsc
, E('em', _('Interface is starting...')));
254 else if (dsc
.hasAttribute('disconnect')) {
255 dom
.content(dsc
, E('em', _('Interface is stopping...')));
257 else if (ifc
.getProtocol() || uci
.get('network', ifc
.getName()) == null) {
258 render_status(dsc
, ifc
, false);
260 else if (!ifc
.getProtocol()) {
261 var e
= map
.querySelector('[id="cbi-network-%s"] .cbi-button-edit'.format(ifc
.getName()));
262 if (e
) e
.disabled
= true;
264 var link
= L
.url('admin/system/opkg') + '?query=luci-proto';
266 E('em', _('Unsupported protocol type.')), E('br'),
267 E('a', { href
: link
}, _('Install protocol extensions...'))
271 dom
.content(dsc
, E('em', _('Interface not present or not connected yet.')));
275 var dev
= ifc
.getDevice();
278 'src': L
.resource('icons/%s%s.png').format(dev
? dev
.getType() : 'ethernet', (dev
&& dev
.isUp()) ? '' : '_disabled'),
279 'title': dev
? dev
.getTypeI18n() : _('Not present')
281 render_status(E('span'), ifc
, true)
285 btn1
.disabled
= isReadonlyView
|| btn1
.classList
.contains('spinning') || btn2
.classList
.contains('spinning') || dynamic
;
286 btn2
.disabled
= isReadonlyView
|| btn1
.classList
.contains('spinning') || btn2
.classList
.contains('spinning') || dynamic
|| disabled
;
289 return Promise
.all([ resolveZone
, network
.flushCache() ]);
294 network
.getDSLModemType(),
295 network
.getDevices(),
296 fs
.lines('/etc/iproute2/rt_tables'),
297 fs
.read('/usr/lib/opkg/info/netifd.control'),
302 interfaceBridgeWithIfnameSections: function() {
303 return uci
.sections('network', 'interface').filter(function(ns
) {
304 return ns
.type
== 'bridge' && !ns
.ports
&& ns
.ifname
;
308 deviceWithIfnameSections: function() {
309 return uci
.sections('network', 'device').filter(function(ns
) {
310 return ns
.type
== 'bridge' && !ns
.ports
&& ns
.ifname
;
314 interfaceWithIfnameSections: function() {
315 return uci
.sections('network', 'interface').filter(function(ns
) {
316 return !ns
.device
&& ns
.ifname
;
320 handleBridgeMigration: function(ev
) {
323 this.interfaceBridgeWithIfnameSections().forEach(function(ns
) {
324 var device_name
= 'br-' + ns
['.name'];
326 tasks
.push(uci
.callAdd('network', 'device', null, {
329 'ports': L
.toArray(ns
.ifname
)
332 tasks
.push(uci
.callSet('network', ns
['.name'], {
335 'device': device_name
339 return Promise
.all(tasks
)
340 .then(L
.bind(ui
.changes
.init
, ui
.changes
))
341 .then(L
.bind(ui
.changes
.apply
, ui
.changes
));
344 renderBridgeMigration: function() {
345 ui
.showModal(_('Network bridge configuration migration'), [
346 E('p', _('The existing network configuration needs to be changed for LuCI to function properly.')),
347 E('p', _('Upon pressing "Continue", bridges configuration will be updated and the network will be restarted to apply the updated configuration.')),
348 E('div', { 'class': 'right' },
350 'class': 'btn cbi-button-action important',
351 'click': ui
.createHandlerFn(this, 'handleBridgeMigration')
356 handleIfnameMigration: function(ev
) {
359 this.deviceWithIfnameSections().forEach(function(ds
) {
360 tasks
.push(uci
.add('network', ds
['.name'], {
362 'ports': L
.toArray(ds
.ifname
)
366 this.interfaceWithIfnameSections().forEach(function(ns
) {
367 tasks
.push(uci
.callSet('network', ns
['.name'], {
373 return Promise
.all(tasks
)
374 .then(L
.bind(ui
.changes
.init
, ui
.changes
))
375 .then(L
.bind(ui
.changes
.apply
, ui
.changes
));
378 renderIfnameMigration: function() {
379 ui
.showModal(_('Network ifname configuration migration'), [
380 E('p', _('The existing network configuration needs to be changed for LuCI to function properly.')),
381 E('p', _('Upon pressing "Continue", ifname options will get renamed and the network will be restarted to apply the updated configuration.')),
382 E('div', { 'class': 'right' },
384 'class': 'btn cbi-button-action important',
385 'click': ui
.createHandlerFn(this, 'handleIfnameMigration')
390 render: function(data
) {
391 var netifdVersion
= (data
[3] || '').match(/Version: ([^\n]+)/);
393 if (netifdVersion
&& netifdVersion
[1] >= "2021-05-26") {
394 if (this.interfaceBridgeWithIfnameSections().length
)
395 return this.renderBridgeMigration();
396 else if (this.deviceWithIfnameSections().length
|| this.interfaceWithIfnameSections().length
)
397 return this.renderIfnameMigration();
400 var dslModemType
= data
[0],
404 var rtTables
= data
[2].map(function(l
) {
405 var m
= l
.trim().match(/^(\d+)\s+(\S+)$/);
406 return m
? [ +m
[1], m
[2] ] : null;
407 }).filter(function(e
) {
408 return e
&& e
[0] > 0;
411 m
= new form
.Map('network');
415 s
= m
.section(form
.GridSection
, 'interface', _('Interfaces'));
418 s
.addbtntitle
= _('Add new interface...');
420 s
.load = function() {
422 network
.getNetworks(),
424 ]).then(L
.bind(function(data
) {
425 this.networks
= data
[0];
426 this.zones
= data
[1];
430 s
.tab('general', _('General Settings'));
431 s
.tab('advanced', _('Advanced Settings'));
432 s
.tab('physical', _('Physical Settings'));
433 s
.tab('brport', _('Bridge port specific options'));
434 s
.tab('bridgevlan', _('Bridge VLAN filtering'));
435 s
.tab('firewall', _('Firewall Settings'));
436 s
.tab('dhcp', _('DHCP Server'));
438 s
.cfgsections = function() {
439 return this.networks
.map(function(n
) { return n
.getName() })
440 .filter(function(n
) { return n
!= 'loopback' });
443 s
.modaltitle = function(section_id
) {
444 return _('Interfaces') + ' » ' + section_id
.toUpperCase();
447 s
.renderRowActions = function(section_id
) {
448 var tdEl
= this.super('renderRowActions', [ section_id
, _('Edit') ]),
449 net
= this.networks
.filter(function(n
) { return n
.getName() == section_id
})[0],
450 disabled
= net
? !net
.isUp() : true,
451 dynamic
= net
? net
.isDynamic() : false;
453 dom
.content(tdEl
.lastChild
, [
455 'class': 'cbi-button cbi-button-neutral reconnect',
456 'click': iface_updown
.bind(this, true, section_id
),
457 'title': _('Reconnect this interface'),
458 'disabled': dynamic
? 'disabled' : null
461 'class': 'cbi-button cbi-button-neutral down',
462 'click': iface_updown
.bind(this, false, section_id
),
463 'title': _('Shutdown this interface'),
464 'disabled': (dynamic
|| disabled
) ? 'disabled' : null
466 tdEl
.lastChild
.firstChild
,
467 tdEl
.lastChild
.lastChild
470 if (!dynamic
&& net
&& !uci
.get('network', net
.getName())) {
471 tdEl
.lastChild
.childNodes
[0].disabled
= true;
472 tdEl
.lastChild
.childNodes
[2].disabled
= true;
473 tdEl
.lastChild
.childNodes
[3].disabled
= true;
479 s
.addModalOptions = function(s
) {
480 var protoval
= uci
.get('network', s
.section
, 'proto'),
481 protoclass
= protoval
? network
.getProtocol(protoval
) : null,
482 o
, proto_select
, proto_switch
, type
, stp
, igmp
, ss
, so
;
487 return network
.getNetwork(s
.section
).then(L
.bind(function(ifc
) {
488 var protocols
= network
.getProtocols();
490 protocols
.sort(function(a
, b
) {
491 return a
.getProtocol() > b
.getProtocol();
494 o
= s
.taboption('general', form
.DummyValue
, '_ifacestat_modal', _('Status'));
496 o
.cfgvalue
= L
.bind(function(section_id
) {
497 var net
= this.networks
.filter(function(n
) { return n
.getName() == section_id
})[0];
499 return render_modal_status(E('div', {
500 'id': '%s-ifc-status'.format(section_id
),
501 'class': 'ifacebadge large'
504 o
.write = function() {};
506 o
= s
.taboption('general', widgets
.DeviceSelect
, 'device', _('Device'));
509 o
.network
= ifc
.getName();
511 proto_select
= s
.taboption('general', form
.ListValue
, 'proto', _('Protocol'));
512 proto_select
.modalonly
= true;
514 proto_switch
= s
.taboption('general', form
.Button
, '_switch_proto');
515 proto_switch
.modalonly
= true;
516 proto_switch
.title
= _('Really switch protocol?');
517 proto_switch
.inputtitle
= _('Switch protocol');
518 proto_switch
.inputstyle
= 'apply';
519 proto_switch
.onclick
= L
.bind(function(ev
) {
521 .then(L
.bind(m
.load
, m
))
522 .then(L
.bind(m
.render
, m
))
523 .then(L
.bind(this.renderMoreOptionsModal
, this, s
.section
));
526 o
= s
.taboption('general', form
.Flag
, 'auto', _('Bring up on boot'));
528 o
.default = o
.enabled
;
530 if (L
.hasSystemFeature('firewall')) {
531 o
= s
.taboption('firewall', widgets
.ZoneSelect
, '_zone', _('Create / Assign firewall-zone'), _('Choose the firewall zone you want to assign to this interface. Select <em>unspecified</em> to remove the interface from the associated zone or fill out the <em>custom</em> field to define a new zone and attach the interface to it.'));
532 o
.network
= ifc
.getName();
535 o
.cfgvalue = function(section_id
) {
536 return firewall
.getZoneByNetwork(ifc
.getName()).then(function(zone
) {
537 return (zone
!= null ? zone
.getName() : null);
541 o
.write
= o
.remove = function(section_id
, value
) {
543 firewall
.getZoneByNetwork(ifc
.getName()),
544 (value
!= null) ? firewall
.getZone(value
) : null
545 ]).then(function(data
) {
546 var old_zone
= data
[0],
549 if (old_zone
== null && new_zone
== null && (value
== null || value
== ''))
552 if (old_zone
!= null && new_zone
!= null && old_zone
.getName() == new_zone
.getName())
555 if (old_zone
!= null)
556 old_zone
.deleteNetwork(ifc
.getName());
558 if (new_zone
!= null)
559 new_zone
.addNetwork(ifc
.getName());
560 else if (value
!= null)
561 return firewall
.addZone(value
).then(function(new_zone
) {
562 new_zone
.addNetwork(ifc
.getName());
568 for (var i
= 0; i
< protocols
.length
; i
++) {
569 proto_select
.value(protocols
[i
].getProtocol(), protocols
[i
].getI18n());
571 if (protocols
[i
].getProtocol() != uci
.get('network', s
.section
, 'proto'))
572 proto_switch
.depends('proto', protocols
[i
].getProtocol());
575 if (L
.hasSystemFeature('dnsmasq') || L
.hasSystemFeature('odhcpd')) {
576 o
= s
.taboption('dhcp', form
.SectionValue
, '_dhcp', form
.TypedSection
, 'dhcp');
577 o
.depends('proto', 'static');
580 ss
.uciconfig
= 'dhcp';
581 ss
.addremove
= false;
584 ss
.tab('general', _('General Setup'));
585 ss
.tab('advanced', _('Advanced Settings'));
586 ss
.tab('ipv6', _('IPv6 Settings'));
588 ss
.filter = function(section_id
) {
589 return (uci
.get('dhcp', section_id
, 'interface') == ifc
.getName());
592 ss
.renderSectionPlaceholder = function() {
593 return E('div', { 'class': 'cbi-section-create' }, [
594 E('p', _('No DHCP Server configured for this interface') + '   '),
596 'class': 'cbi-button cbi-button-add',
597 'title': _('Setup DHCP Server'),
598 'click': ui
.createHandlerFn(this, function(section_id
, ev
) {
599 this.map
.save(function() {
600 uci
.add('dhcp', 'dhcp', section_id
);
601 uci
.set('dhcp', section_id
, 'interface', section_id
);
602 uci
.set('dhcp', section_id
, 'start', 100);
603 uci
.set('dhcp', section_id
, 'limit', 150);
604 uci
.set('dhcp', section_id
, 'leasetime', '12h');
607 }, _('Setup DHCP Server'))
611 ss
.taboption('general', form
.Flag
, 'ignore', _('Ignore interface'), _('Disable <abbr title="Dynamic Host Configuration Protocol">DHCP</abbr> for this interface.'));
613 so
= ss
.taboption('general', form
.Value
, 'start', _('Start'), _('Lowest leased address as offset from the network address.'));
615 so
.datatype
= 'or(uinteger,ip4addr("nomask"))';
618 so
= ss
.taboption('general', form
.Value
, 'limit', _('Limit'), _('Maximum number of leased addresses.'));
620 so
.datatype
= 'uinteger';
623 so
= ss
.taboption('general', form
.Value
, 'leasetime', _('Lease time'), _('Expiry time of leased addresses, minimum is 2 minutes (<code>2m</code>).'));
627 so
= ss
.taboption('advanced', form
.Flag
, 'dynamicdhcp', _('Dynamic <abbr title="Dynamic Host Configuration Protocol">DHCP</abbr>'), _('Dynamically allocate DHCP addresses for clients. If disabled, only clients having static leases will be served.'));
628 so
.default = so
.enabled
;
630 ss
.taboption('advanced', form
.Flag
, 'force', _('Force'), _('Force DHCP on this network even if another server is detected.'));
632 // XXX: is this actually useful?
633 //ss.taboption('advanced', form.Value, 'name', _('Name'), _('Define a name for this network.'));
635 so
= ss
.taboption('advanced', form
.Value
, 'netmask', _('<abbr title="Internet Protocol Version 4">IPv4</abbr>-Netmask'), _('Override the netmask sent to clients. Normally it is calculated from the subnet that is served.'));
637 so
.datatype
= 'ip4addr';
639 so
.render = function(option_index
, section_id
, in_table
) {
640 this.placeholder
= get_netmask(s
, true);
641 return form
.Value
.prototype.render
.apply(this, [ option_index
, section_id
, in_table
]);
644 so
.validate = function(section_id
, value
) {
645 var uielem
= this.getUIElement(section_id
);
647 uielem
.setPlaceholder(get_netmask(s
, false));
648 return form
.Value
.prototype.validate
.apply(this, [ section_id
, value
]);
651 ss
.taboption('advanced', form
.DynamicList
, 'dhcp_option', _('DHCP-Options'), _('Define additional DHCP options, \
652 for example "<code>6,192.168.2.1,192.168.2.2</code>" which advertises different DNS servers to clients.'));
654 for (var i
= 0; i
< ss
.children
.length
; i
++)
655 if (ss
.children
[i
].option
!= 'ignore')
656 ss
.children
[i
].depends('ignore', '0');
658 so
= ss
.taboption('ipv6', form
.ListValue
, 'ra', _('<abbr title="Router Advertisement">RA</abbr>-Service'), _('<ul style="list-style-type:none;">\
659 <li><strong>server mode</strong>: Router advertises itself as the default IPv6 gateway \
660 via <abbr title="Router Advertisement, ICMPv6 Type 134">RA</abbr> messages \
661 (to <code>ff02::1</code>) and provides <abbr title="Prefix Delegation">PD</abbr> to downstream devices.</li>\
662 <li><strong>relay mode</strong>: Router relays <abbr title="Router Advertisement, ICMPv6 Type 134">RA</abbr> from upstream, \
663 and extends upstream (e.g. WAN) interface config and prefix to downstream (e.g. LAN) interfaces.</li>\
664 <li><strong>hybrid mode</strong>: Router does both server+relay; extends upstream config and prefix downstream, and \
665 uses <abbr title="Prefix Delegation">PD</abbr> locally.</li></ul>'));
666 so
.value('', _('disabled'));
667 so
.value('server', _('server mode'));
668 so
.value('relay', _('relay mode'));
669 so
.value('hybrid', _('hybrid mode'));
671 so
= ss
.taboption('ipv6', form
.Value
, 'ra_maxinterval', _('Max <abbr title="Router Advertisement">RA</abbr> interval'), _('Maximum time allowed \
672 between sending unsolicited <abbr title="Router Advertisement, ICMPv6 Type 134">RA</abbr>. Default is 600 seconds (<code>600</code>).'));
674 so
.placeholder
= '600';
675 so
.depends('ra', 'server');
676 so
.depends('ra', 'hybrid');
677 so
.depends('ra', 'relay');
680 so
= ss
.taboption('ipv6', form
.Value
, 'ra_mininterval', _('Min <abbr title="Router Advertisement">RA</abbr> interval'), _('Minimum time allowed \
681 between sending unsolicited <abbr title="Router Advertisement, ICMPv6 Type 134">RA</abbr>. Default is 200 seconds (<code>200</code>).'));
683 so
.placeholder
= '200';
684 so
.depends('ra', 'server');
685 so
.depends('ra', 'hybrid');
686 so
.depends('ra', 'relay');
688 so
= ss
.taboption('ipv6', form
.Value
, 'ra_lifetime', _('<abbr title="Router Advertisement">RA</abbr> Lifetime'), _('Router Lifetime published \
689 in <abbr title="Router Advertisement, ICMPv6 Type 134">RA</abbr> messages. Default is 1800 seconds (<code>1800</code>). \
690 Max 9000 seconds.'));
692 so
.depends('ra', 'server');
693 so
.depends('ra', 'hybrid');
694 so
.depends('ra', 'relay');
696 so
= ss
.taboption('ipv6', form
.Value
, 'ra_mtu', _('<abbr title="Router Advertisement">RA</abbr> MTU'), _('The <abbr title="Maximum Transmission Unit">MTU</abbr> \
697 to be published in <abbr title="Router Advertisement, ICMPv6 Type 134">RA</abbr> messages. Default is 0 (<code>0</code>).\
700 so
.depends('ra', 'server');
701 so
.depends('ra', 'hybrid');
702 so
.depends('ra', 'relay');
704 so
= ss
.taboption('ipv6', form
.Value
, 'ra_hoplimit', _('<abbr title="Router Advertisement">RA</abbr> Hop Limit'), _('The maximum hops \
705 to be published in <abbr title="Router Advertisement">RA</abbr> messages.<br />Default is 0 (<code>0</code>), meaning unspecified.\
708 so
.depends('ra', 'server');
709 so
.depends('ra', 'hybrid');
710 so
.depends('ra', 'relay');
712 so
= ss
.taboption('ipv6', form
.ListValue
, 'ra_management', _('DHCPv6-Mode'), _('Default is stateless + stateful<br />\
713 <ul style="list-style-type:none;">\
714 <li><strong>stateless</strong>: Router advertises prefixes, host uses <abbr title="Stateless Address Auto Config">SLAAC</abbr> \
715 to self assign its own address. No DHCPv6.</li>\
716 <li><strong>stateless + stateful</strong>: SLAAC. In addition, router assigns an IPv6 address to a host via DHCPv6.</li>\
717 <li><strong>stateful-only</strong>: No SLAAC. Router assigns an IPv6 address to a host via DHCPv6.</li></ul>'));
718 so
.value('0', _('stateless'));
719 so
.value('1', _('stateless + stateful'));
720 so
.value('2', _('stateful-only'));
721 so
.depends('dhcpv6', 'server');
722 so
.depends('dhcpv6', 'hybrid');
725 so
= ss
.taboption('ipv6', form
.ListValue
, 'dhcpv6', _('DHCPv6-Service'), _('<ul style="list-style-type:none;">\
726 <li><strong>server mode</strong>: Router assigns IPs and delegates prefixes \
727 (<abbr title="Prefix Delegation">PD</abbr>) to downstream interfaces.</li>\
728 <li><strong>relay mode</strong>: Router relays WAN interface config downstream. Helps support upstream \
729 links that lack <abbr title="Prefix Delegation">PD</abbr>.</li>\
730 <li><strong>hybrid mode</strong>: Router does combination of server+relay.</li></ul>'));
731 so
.value('', _('disabled'));
732 so
.value('server', _('server mode'));
733 so
.value('relay', _('relay mode'));
734 so
.value('hybrid', _('hybrid mode'));
736 so
= ss
.taboption('ipv6', form
.ListValue
, 'ndp', _('<abbr title="Neighbour Discovery Protocol">NDP</abbr>-Proxy'), _('Reverts to \
737 disabled internally if there are no interfaces with boolean <code>ndproxy_slave</code> set to 1. Think of \
738 <abbr title="Neighbour Discovery Protocol">NDP</abbr> Proxy as Proxy ARP for IPv6: unify hosts on different physical \
739 hardware segments into the same IP subnet. Consists of <abbr title="Neighbour Solicitation, Type 135">NS</abbr> and \
740 <abbr title="Neighbour Advertisement, Type 136">NA</abbr> messages. <abbr title="Neighbour Discovery Protocol">NDP</abbr>-Proxy \
741 listens for <abbr title="Neighbour Solicitation, Type 135">NS</abbr> on an interface marked with boolean \
742 <code>master</code> as 1 (i.e. upstream), then queries the slave/internal interfaces for that target IP before finally \
743 sending an <abbr title="Neighbour Advertisement, Type 136">NA</abbr> message. \
744 <abbr title="Neighbour Discovery Protocol">NDP</abbr> is effectively ARP for IPv6. \
745 <abbr title="Neighbour Solicitation, Type 135">NS</abbr> and <abbr title="Neighbour Advertisement, Type 136">NA</abbr> \
746 detect reachability and duplicate addresses on a link, themselves also a prerequisite for SLAAC autoconfig.<br />\
747 <ul style="list-style-type:none;">\
748 <li><strong>disabled</strong>: No <abbr title="Neighbour Discovery Protocol">NDP</abbr> messages are proxied through to \
749 <code>ndproxy_slave</code> true interfaces.</li> \
750 <li><strong>relay mode</strong>: Proxies <abbr title="Neighbour Discovery Protocol">NDP</abbr> messages from <code>master</code> to \
751 <code>ndproxy_slave</code> true interfaces. Helps to support provider links without \
752 <abbr title="Prefix Delegation">PD</abbr>, and to firewall proxied hosts.</li>\
753 <li><strong>hybrid mode</strong>: Relay mode is disabled unless the interface boolean <code>master</code> is 1.</li></ul>'));
754 so
.value('', _('disabled'));
755 so
.value('relay', _('relay mode'));
756 so
.value('hybrid', _('hybrid mode'));
758 so
= ss
.taboption('ipv6', form
.Flag
, 'ndproxy_routing', _('Learn routes from NDP'), _('Default is on.'));
762 so
= ss
.taboption('ipv6', form
.Flag
, 'ndproxy_slave', _('NDP-Proxy slave'), _('Set interface as NDP-Proxy external slave. Default is off.'));
764 so
= ss
.taboption('ipv6', form
.DynamicList
, 'ndproxy_static', _('Static NDP-Proxy prefixes'));
766 so
= ss
.taboption('ipv6', form
.Flag
, 'master', _('Master'), _('Set this interface as master for the dhcpv6 relay.'));
767 so
.depends('dhcpv6', 'relay');
768 so
.depends('dhcpv6', 'hybrid');
770 so
= ss
.taboption('ipv6', form
.Flag
, 'master', _('Master'), _('Set this interface as master for the dhcpv6 relay.'));
771 so
.depends('dhcpv6', 'relay');
772 so
.depends('dhcpv6', 'hybrid');
774 so
= ss
.taboption('ipv6', form
.Flag
, 'ra_default', _('Announce as default router'), _('Always, even if no public prefix is available.'));
775 so
.depends('ra', 'server');
776 so
.depends('ra', 'hybrid');
778 ss
.taboption('ipv6', form
.DynamicList
, 'dns', _('Announced DNS servers'));
779 ss
.taboption('ipv6', form
.DynamicList
, 'domain', _('Announced DNS domains'));
782 ifc
.renderFormOptions(s
);
784 // Common interface options
785 o
= nettools
.replaceOption(s
, 'advanced', form
.Flag
, 'defaultroute', _('Use default gateway'), _('If unchecked, no default route is configured'));
786 o
.default = o
.enabled
;
788 if (protoval
!= 'static') {
789 o
= nettools
.replaceOption(s
, 'advanced', form
.Flag
, 'peerdns', _('Use DNS servers advertised by peer'), _('If unchecked, the advertised DNS server addresses are ignored'));
790 o
.default = o
.enabled
;
793 o
= nettools
.replaceOption(s
, 'advanced', form
.DynamicList
, 'dns', _('Use custom DNS servers'));
794 if (protoval
!= 'static')
795 o
.depends('peerdns', '0');
796 o
.datatype
= 'ipaddr';
798 o
= nettools
.replaceOption(s
, 'advanced', form
.DynamicList
, 'dns_search', _('DNS search domains'));
799 if (protoval
!= 'static')
800 o
.depends('peerdns', '0');
801 o
.datatype
= 'hostname';
803 o
= nettools
.replaceOption(s
, 'advanced', form
.Value
, 'dns_metric', _('DNS weight'), _('The DNS server entries in the local resolv.conf are primarily sorted by the weight specified here'));
804 o
.datatype
= 'uinteger';
807 o
= nettools
.replaceOption(s
, 'advanced', form
.Value
, 'metric', _('Use gateway metric'));
808 o
.datatype
= 'uinteger';
811 o
= nettools
.replaceOption(s
, 'advanced', form
.Value
, 'ip4table', _('Override IPv4 routing table'));
812 o
.datatype
= 'or(uinteger, string)';
813 for (var i
= 0; i
< rtTables
.length
; i
++)
814 o
.value(rtTables
[i
][1], '%s (%d)'.format(rtTables
[i
][1], rtTables
[i
][0]));
816 o
= nettools
.replaceOption(s
, 'advanced', form
.Value
, 'ip6table', _('Override IPv6 routing table'));
817 o
.datatype
= 'or(uinteger, string)';
818 for (var i
= 0; i
< rtTables
.length
; i
++)
819 o
.value(rtTables
[i
][1], '%s (%d)'.format(rtTables
[i
][0], rtTables
[i
][1]));
821 o
= nettools
.replaceOption(s
, 'advanced', form
.Flag
, 'delegate', _('Delegate IPv6 prefixes'), _('Enable downstream delegation of IPv6 prefixes available on this interface'));
822 o
.default = o
.enabled
;
824 o
= nettools
.replaceOption(s
, 'advanced', form
.Value
, 'ip6assign', _('IPv6 assignment length'), _('Assign a part of given length of every public IPv6-prefix to this interface'));
825 o
.value('', _('disabled'));
827 o
.datatype
= 'max(128)';
829 o
= nettools
.replaceOption(s
, 'advanced', form
.Value
, 'ip6hint', _('IPv6 assignment hint'), _('Assign prefix parts using this hexadecimal subprefix ID for this interface.'));
831 o
.validate = function(section_id
, value
) {
832 if (value
== null || value
== '')
835 var n
= parseInt(value
, 16);
837 if (!/^(0x)?[0-9a-fA-F]+$/.test(value
) || isNaN(n
) || n
>= 0xffffffff)
838 return _('Expecting a hexadecimal assignment hint');
842 for (var i
= 33; i
<= 64; i
++)
843 o
.depends('ip6assign', String(i
));
846 o
= nettools
.replaceOption(s
, 'advanced', form
.DynamicList
, 'ip6class', _('IPv6 prefix filter'), _('If set, downstream subnets are only allocated from the given IPv6 prefix classes.'));
847 o
.value('local', 'local (%s)'.format(_('Local ULA')));
849 var prefixClasses
= {};
851 this.networks
.forEach(function(net
) {
852 var prefixes
= net
._ubus('ipv6-prefix');
853 if (Array
.isArray(prefixes
)) {
854 prefixes
.forEach(function(pfx
) {
855 if (L
.isObject(pfx
) && typeof(pfx
['class']) == 'string') {
856 prefixClasses
[pfx
['class']] = prefixClasses
[pfx
['class']] || {};
857 prefixClasses
[pfx
['class']][net
.getName()] = true;
863 Object
.keys(prefixClasses
).sort().forEach(function(c
) {
864 var networks
= Object
.keys(prefixClasses
[c
]).sort().join(', ');
865 o
.value(c
, (c
!= networks
) ? '%s (%s)'.format(c
, networks
) : c
);
869 o
= nettools
.replaceOption(s
, 'advanced', form
.Value
, 'ip6ifaceid', _('IPv6 suffix'), _("Optional. Allowed values: 'eui64', 'random', fixed value like '::1' or '::1:2'. When IPv6 prefix (like 'a:b:c:d::') is received from a delegating server, use the suffix (like '::1') to form the IPv6 address ('a:b:c:d::1') for the interface."));
870 o
.datatype
= 'ip6hostid';
871 o
.placeholder
= '::1';
873 o
= nettools
.replaceOption(s
, 'advanced', form
.Value
, 'ip6weight', _('IPv6 preference'), _('When delegating prefixes to multiple downstreams, interfaces with a higher preference value are considered first when allocating subnets.'));
874 o
.datatype
= 'uinteger';
877 for (var i
= 0; i
< s
.children
.length
; i
++) {
886 case '_switch_proto':
887 case '_ifacestat_modal':
890 case 'igmp_snooping':
894 for (var j
= 0; j
< protocols
.length
; j
++) {
895 if (!protocols
[j
].isVirtual()) {
897 for (var k
= 0; k
< o
.deps
.length
; k
++)
898 deps
.push(Object
.assign({ proto
: protocols
[j
].getProtocol() }, o
.deps
[k
]));
900 deps
.push({ proto
: protocols
[j
].getProtocol() });
908 for (var j
= 0; j
< o
.deps
.length
; j
++)
909 o
.deps
[j
].proto
= protoval
;
911 o
.depends('proto', protoval
);
915 this.activeSection
= s
.section
;
919 s
.handleModalCancel = function(/* ... */) {
920 var type
= uci
.get('network', this.activeSection
|| this.addedSection
, 'type'),
921 device
= (type
== 'bridge') ? 'br-%s'.format(this.activeSection
|| this.addedSection
) : null;
923 uci
.sections('network', 'bridge-vlan', function(bvs
) {
924 if (device
!= null && bvs
.device
== device
)
925 uci
.remove('network', bvs
['.name']);
928 return form
.GridSection
.prototype.handleModalCancel
.apply(this, arguments
);
931 s
.handleAdd = function(ev
) {
932 var m2
= new form
.Map('network'),
933 s2
= m2
.section(form
.NamedSection
, '_new_'),
934 protocols
= network
.getProtocols(),
937 protocols
.sort(function(a
, b
) {
938 return a
.getProtocol() > b
.getProtocol();
941 s2
.render = function() {
944 this.renderUCISection('_new_')
945 ]).then(this.renderContents
.bind(this));
948 name
= s2
.option(form
.Value
, 'name', _('Name'));
949 name
.rmempty
= false;
950 name
.datatype
= 'uciname';
951 name
.placeholder
= _('New interface name…');
952 name
.validate = function(section_id
, value
) {
953 if (uci
.get('network', value
) != null)
954 return _('The interface name is already used');
956 var pr
= network
.getProtocol(proto
.formvalue(section_id
), value
),
957 ifname
= pr
.isVirtual() ? '%s-%s'.format(pr
.getProtocol(), value
) : 'br-%s'.format(value
);
959 if (value
.length
> 15)
960 return _('The interface name is too long');
965 proto
= s2
.option(form
.ListValue
, 'proto', _('Protocol'));
966 proto
.validate
= name
.validate
;
968 device
= s2
.option(widgets
.DeviceSelect
, 'device', _('Device'));
969 device
.noaliases
= false;
970 device
.optional
= false;
972 for (var i
= 0; i
< protocols
.length
; i
++) {
973 proto
.value(protocols
[i
].getProtocol(), protocols
[i
].getI18n());
975 if (!protocols
[i
].isVirtual())
976 device
.depends('proto', protocols
[i
].getProtocol());
979 m2
.render().then(L
.bind(function(nodes
) {
980 ui
.showModal(_('Add new interface...'), [
982 E('div', { 'class': 'right' }, [
985 'click': ui
.hideModal
986 }, _('Cancel')), ' ',
988 'class': 'cbi-button cbi-button-positive important',
989 'click': ui
.createHandlerFn(this, function(ev
) {
990 var nameval
= name
.isValid('_new_') ? name
.formvalue('_new_') : null,
991 protoval
= proto
.isValid('_new_') ? proto
.formvalue('_new_') : null,
992 protoclass
= protoval
? network
.getProtocol(protoval
, nameval
) : null;
994 if (nameval
== null || protoval
== null || nameval
== '' || protoval
== '')
997 return protoclass
.isCreateable(nameval
).then(function(checkval
) {
998 if (checkval
!= null) {
999 ui
.addNotification(null,
1000 E('p', _('New interface for "%s" can not be created: %s').format(protoclass
.getI18n(), checkval
)));
1005 return m
.save(function() {
1006 var section_id
= uci
.add('network', 'interface', nameval
);
1008 protoclass
.set('proto', protoval
);
1009 protoclass
.addDevice(device
.formvalue('_new_'));
1011 m
.children
[0].addedSection
= section_id
;
1012 }).then(L
.bind(m
.children
[0].renderMoreOptionsModal
, m
.children
[0], nameval
));
1015 }, _('Create interface'))
1019 nodes
.querySelector('[id="%s"] input[type="text"]'.format(name
.cbid('_new_'))).focus();
1023 s
.handleRemove = function(section_id
, ev
) {
1024 return network
.deleteNetwork(section_id
).then(L
.bind(function(section_id
, ev
) {
1025 return form
.GridSection
.prototype.handleRemove
.apply(this, [section_id
, ev
]);
1026 }, this, section_id
, ev
));
1029 o
= s
.option(form
.DummyValue
, '_ifacebox');
1030 o
.modalonly
= false;
1031 o
.textvalue = function(section_id
) {
1032 var net
= this.section
.networks
.filter(function(n
) { return n
.getName() == section_id
})[0],
1033 zone
= net
? this.section
.zones
.filter(function(z
) { return !!z
.getNetworks().filter(function(n
) { return n
== section_id
})[0] })[0] : null;
1038 var node
= E('div', { 'class': 'ifacebox' }, [
1040 'class': 'ifacebox-head',
1041 'style': 'background-color:%s'.format(zone
? zone
.getColor() : '#EEEEEE'),
1042 'title': zone
? _('Part of zone %q').format(zone
.getName()) : _('No zone assigned')
1043 }, E('strong', net
.getName().toUpperCase())),
1045 'class': 'ifacebox-body',
1046 'id': '%s-ifc-devices'.format(section_id
),
1047 'data-network': section_id
1050 'src': L
.resource('icons/ethernet_disabled.png'),
1051 'style': 'width:16px; height:16px'
1053 E('br'), E('small', '?')
1057 render_ifacebox_status(node
.childNodes
[1], net
);
1062 o
= s
.option(form
.DummyValue
, '_ifacestat');
1063 o
.modalonly
= false;
1064 o
.textvalue = function(section_id
) {
1065 var net
= this.section
.networks
.filter(function(n
) { return n
.getName() == section_id
})[0];
1070 var node
= E('div', { 'id': '%s-ifc-description'.format(section_id
) });
1072 render_status(node
, net
, false);
1077 o
= s
.taboption('advanced', form
.Flag
, 'delegate', _('Use builtin IPv6-management'));
1079 o
.default = o
.enabled
;
1081 o
= s
.taboption('advanced', form
.Flag
, 'force_link', _('Force link'), _('Set interface properties regardless of the link carrier (If set, carrier sense events do not invoke hotplug handlers).'));
1084 '1': [{ proto
: 'static' }],
1089 // Device configuration
1090 s
= m
.section(form
.GridSection
, 'device', _('Devices'));
1093 s
.addbtntitle
= _('Add device configuration…');
1095 s
.cfgsections = function() {
1096 var sections
= uci
.sections('network', 'device'),
1097 section_ids
= sections
.sort(function(a
, b
) { return a
.name
> b
.name
}).map(function(s
) { return s
['.name'] });
1099 for (var i
= 0; i
< netDevs
.length
; i
++) {
1100 if (sections
.filter(function(s
) { return s
.name
== netDevs
[i
].getName() }).length
)
1103 if (netDevs
[i
].getType() == 'wifi' && !netDevs
[i
].isUp())
1106 /* Unless http://lists.openwrt.org/pipermail/openwrt-devel/2020-July/030397.html is implemented,
1107 we cannot properly redefine bridges as devices, so filter them away for now... */
1109 var m
= netDevs
[i
].isBridge() ? netDevs
[i
].getName().match(/^br-([A-Za-z0-9_]+)$/) : null,
1110 s
= m
? uci
.get('network', m
[1]) : null;
1112 if (s
&& s
['.type'] == 'interface' && s
.type
== 'bridge')
1115 section_ids
.push('dev:%s'.format(netDevs
[i
].getName()));
1121 s
.renderMoreOptionsModal = function(section_id
, ev
) {
1122 var m
= section_id
.match(/^dev:(.+)$/);
1125 var devtype
= getDevType(section_id
);
1127 section_id
= uci
.add('network', 'device');
1129 uci
.set('network', section_id
, 'name', m
[1]);
1130 uci
.set('network', section_id
, 'type', (devtype
!= 'ethernet') ? devtype
: null);
1132 this.addedSection
= section_id
;
1135 return this.super('renderMoreOptionsModal', [section_id
, ev
]);
1138 s
.renderRowActions = function(section_id
) {
1139 var trEl
= this.super('renderRowActions', [ section_id
, _('Configure…') ]),
1140 deleteBtn
= trEl
.querySelector('button:last-child');
1142 deleteBtn
.firstChild
.data
= _('Reset');
1143 deleteBtn
.disabled
= section_id
.match(/^dev:/) ? true : null;
1148 s
.modaltitle = function(section_id
) {
1149 var m
= section_id
.match(/^dev:(.+)$/),
1150 name
= m
? m
[1] : uci
.get('network', section_id
, 'name');
1152 return name
? '%s: %q'.format(getDevTypeDesc(section_id
), name
) : _('Add device configuration');
1155 s
.addModalOptions = function(s
) {
1156 var isNew
= (uci
.get('network', s
.section
, 'name') == null),
1157 dev
= getDevice(s
.section
);
1159 nettools
.addDeviceOptions(s
, dev
, isNew
);
1162 s
.handleModalCancel = function(/* ... */) {
1163 var name
= uci
.get('network', this.addedSection
, 'name')
1165 uci
.sections('network', 'bridge-vlan', function(bvs
) {
1166 if (name
!= null && bvs
.device
== name
)
1167 uci
.remove('network', bvs
['.name']);
1170 return form
.GridSection
.prototype.handleModalCancel
.apply(this, arguments
);
1173 function getDevice(section_id
) {
1174 var m
= section_id
.match(/^dev:(.+)$/),
1175 name
= m
? m
[1] : uci
.get('network', section_id
, 'name');
1177 return netDevs
.filter(function(d
) { return d
.getName() == name
})[0];
1180 function getDevType(section_id
) {
1181 var cfgtype
= uci
.get('network', section_id
, 'type'),
1182 dev
= getDevice(section_id
);
1184 switch (cfgtype
|| (dev
? dev
.getType() : '')) {
1216 function getDevTypeDesc(section_id
) {
1217 switch (getDevType(section_id
) || '') {
1219 return E('em', [ _('Device not present') ]);
1222 return _('VLAN (802.1q)');
1225 return _('VLAN (802.1ad)');
1228 return _('Bridge device');
1231 return _('Tunnel device');
1234 return _('MAC VLAN');
1237 return _('Virtual Ethernet');
1240 return _('Network device');
1244 o
= s
.option(form
.DummyValue
, 'name', _('Device'));
1245 o
.modalonly
= false;
1246 o
.textvalue = function(section_id
) {
1247 var dev
= getDevice(section_id
),
1248 ext
= section_id
.match(/^dev:/),
1249 icon
= render_iface(dev
);
1252 icon
.querySelector('img').style
.opacity
= '.5';
1254 return E('span', { 'class': 'ifacebadge' }, [
1256 E('span', { 'style': ext
? 'opacity:.5' : null }, [
1257 dev
? dev
.getName() : (uci
.get('network', section_id
, 'name') || '?')
1262 o
= s
.option(form
.DummyValue
, 'type', _('Type'));
1263 o
.textvalue
= getDevTypeDesc
;
1264 o
.modalonly
= false;
1266 o
= s
.option(form
.DummyValue
, 'macaddr', _('MAC Address'));
1267 o
.modalonly
= false;
1268 o
.textvalue = function(section_id
) {
1269 var dev
= getDevice(section_id
),
1270 val
= uci
.get('network', section_id
, 'macaddr'),
1271 mac
= dev
? dev
.getMAC() : null;
1273 return val
? E('strong', {
1274 'data-tooltip': _('The value is overridden by configuration. Original: %s').format(mac
|| _('unknown'))
1275 }, [ val
.toUpperCase() ]) : (mac
|| '-');
1278 o
= s
.option(form
.DummyValue
, 'mtu', _('MTU'));
1279 o
.modalonly
= false;
1280 o
.textvalue = function(section_id
) {
1281 var dev
= getDevice(section_id
),
1282 val
= uci
.get('network', section_id
, 'mtu'),
1283 mtu
= dev
? dev
.getMTU() : null;
1285 return val
? E('strong', {
1286 'data-tooltip': _('The value is overridden by configuration. Original: %s').format(mtu
|| _('unknown'))
1287 }, [ val
]) : (mtu
|| '-').toString();
1290 s
= m
.section(form
.TypedSection
, 'globals', _('Global network options'));
1291 s
.addremove
= false;
1294 o
= s
.option(form
.Value
, 'ula_prefix', _('IPv6 ULA-Prefix'), _('Unique Local Address - in the range <code>fc00::/7</code>. \
1295 Typically only within the ‘local’ half <code>fd00::/8</code>. ULA for IPv6 is analogous to IPv4 private network addressing.\
1296 This prefix is randomly generated at first install.'));
1297 o
.datatype
= 'cidr6';
1299 o
= s
.option(form
.Flag
, 'packet_steering', _('Packet Steering'), _('Enable packet steering across all CPUs. May help or hinder network speed.'));
1303 if (dslModemType
!= null) {
1304 s
= m
.section(form
.TypedSection
, 'dsl', _('DSL'));
1307 o
= s
.option(form
.ListValue
, 'annex', _('Annex'));
1308 o
.value('a', _('Annex A + L + M (all)'));
1309 o
.value('b', _('Annex B (all)'));
1310 o
.value('j', _('Annex J (all)'));
1311 o
.value('m', _('Annex M (all)'));
1312 o
.value('bdmt', _('Annex B G.992.1'));
1313 o
.value('b2', _('Annex B G.992.3'));
1314 o
.value('b2p', _('Annex B G.992.5'));
1315 o
.value('at1', _('ANSI T1.413'));
1316 o
.value('admt', _('Annex A G.992.1'));
1317 o
.value('alite', _('Annex A G.992.2'));
1318 o
.value('a2', _('Annex A G.992.3'));
1319 o
.value('a2p', _('Annex A G.992.5'));
1320 o
.value('l', _('Annex L G.992.3 POTS 1'));
1321 o
.value('m2', _('Annex M G.992.3'));
1322 o
.value('m2p', _('Annex M G.992.5'));
1324 o
= s
.option(form
.ListValue
, 'tone', _('Tone'));
1325 o
.value('', _('auto'));
1326 o
.value('a', _('A43C + J43 + A43'));
1327 o
.value('av', _('A43C + J43 + A43 + V43'));
1328 o
.value('b', _('B43 + B43C'));
1329 o
.value('bv', _('B43 + B43C + V43'));
1331 if (dslModemType
== 'vdsl') {
1332 o
= s
.option(form
.ListValue
, 'xfer_mode', _('Encapsulation mode'));
1333 o
.value('', _('auto'));
1334 o
.value('atm', _('ATM (Asynchronous Transfer Mode)'));
1335 o
.value('ptm', _('PTM/EFM (Packet Transfer Mode)'));
1337 o
= s
.option(form
.ListValue
, 'line_mode', _('DSL line mode'));
1338 o
.value('', _('auto'));
1339 o
.value('adsl', _('ADSL'));
1340 o
.value('vdsl', _('VDSL'));
1342 o
= s
.option(form
.ListValue
, 'ds_snr_offset', _('Downstream SNR offset'));
1345 for (var i
= -100; i
<= 100; i
+= 5)
1346 o
.value(i
, _('%.1f dB').format(i
/ 10));
1349 s
.option(form
.Value
, 'firmware', _('Firmware File'));
1353 // Show ATM bridge section if we have the capabilities
1354 if (L
.hasSystemFeature('br2684ctl')) {
1355 s
= m
.section(form
.TypedSection
, 'atm-bridge', _('ATM Bridges'), _('ATM bridges expose encapsulated ethernet in AAL5 connections as virtual Linux network interfaces which can be used in conjunction with DHCP or PPP to dial into the provider network.'));
1359 s
.addbtntitle
= _('Add ATM Bridge');
1361 s
.handleAdd = function(ev
) {
1362 var sections
= uci
.sections('network', 'atm-bridge'),
1365 for (var i
= 0; i
< sections
.length
; i
++) {
1366 var unit
= +sections
[i
].unit
;
1368 if (!isNaN(unit
) && unit
> max_unit
)
1372 return this.map
.save(function() {
1373 var sid
= uci
.add('network', 'atm-bridge');
1375 uci
.set('network', sid
, 'unit', max_unit
+ 1);
1376 uci
.set('network', sid
, 'atmdev', 0);
1377 uci
.set('network', sid
, 'encaps', 'llc');
1378 uci
.set('network', sid
, 'payload', 'bridged');
1379 uci
.set('network', sid
, 'vci', 35);
1380 uci
.set('network', sid
, 'vpi', 8);
1384 s
.tab('general', _('General Setup'));
1385 s
.tab('advanced', _('Advanced Settings'));
1387 o
= s
.taboption('general', form
.Value
, 'vci', _('ATM Virtual Channel Identifier (VCI)'));
1388 s
.taboption('general', form
.Value
, 'vpi', _('ATM Virtual Path Identifier (VPI)'));
1390 o
= s
.taboption('general', form
.ListValue
, 'encaps', _('Encapsulation mode'));
1391 o
.value('llc', _('LLC'));
1392 o
.value('vc', _('VC-Mux'));
1394 s
.taboption('advanced', form
.Value
, 'atmdev', _('ATM device number'));
1395 s
.taboption('advanced', form
.Value
, 'unit', _('Bridge unit number'));
1397 o
= s
.taboption('advanced', form
.ListValue
, 'payload', _('Forwarding mode'));
1398 o
.value('bridged', _('bridged'));
1399 o
.value('routed', _('routed'));
1403 return m
.render().then(L
.bind(function(m
, nodes
) {
1404 poll
.add(L
.bind(function() {
1405 var section_ids
= m
.children
[0].cfgsections(),
1408 for (var i
= 0; i
< section_ids
.length
; i
++) {
1409 var row
= nodes
.querySelector('.cbi-section-table-row[data-sid="%s"]'.format(section_ids
[i
])),
1410 dsc
= row
.querySelector('[data-name="_ifacestat"] > div'),
1411 btn1
= row
.querySelector('.cbi-section-actions .reconnect'),
1412 btn2
= row
.querySelector('.cbi-section-actions .down');
1414 if (dsc
.getAttribute('reconnect') == '') {
1415 dsc
.setAttribute('reconnect', '1');
1416 tasks
.push(fs
.exec('/sbin/ifup', [section_ids
[i
]]).catch(function(e
) {
1417 ui
.addNotification(null, E('p', e
.message
));
1420 else if (dsc
.getAttribute('disconnect') == '') {
1421 dsc
.setAttribute('disconnect', '1');
1422 tasks
.push(fs
.exec('/sbin/ifdown', [section_ids
[i
]]).catch(function(e
) {
1423 ui
.addNotification(null, E('p', e
.message
));
1426 else if (dsc
.getAttribute('reconnect') == '1') {
1427 dsc
.removeAttribute('reconnect');
1428 btn1
.classList
.remove('spinning');
1429 btn1
.disabled
= false;
1431 else if (dsc
.getAttribute('disconnect') == '1') {
1432 dsc
.removeAttribute('disconnect');
1433 btn2
.classList
.remove('spinning');
1434 btn2
.disabled
= false;
1438 return Promise
.all(tasks
)
1439 .then(L
.bind(network
.getNetworks
, network
))
1440 .then(L
.bind(this.poll_status
, this, nodes
));