1
0
Fork 0
mirror of https://github.com/Ysurac/openmptcprouter-feeds.git synced 2025-03-09 15:40:03 +00:00

Update luci-proto-bonding

This commit is contained in:
Ycarus (Yannick Chabanois) 2020-04-29 16:17:02 +02:00
parent d054fd8423
commit 6ad526f972

View file

@ -2,24 +2,30 @@
'require ui'; 'require ui';
'require uci'; 'require uci';
'require form'; 'require form';
'require fs';
'require network'; 'require network';
'require tools.widgets as widgets';
function getSelectableSlaves(section_id) { function getSelectableSlaves(section_id) {
var rv = []; var rv = [];
var NonUsableMac = /^(00:00:00:00:00:00|null)/;
var interfaces = uci.sections('network', 'interface'); var interfaces = uci.sections('network', 'interface');
return network.getDevices().then(function(devices) { return network.getDevices().then(function(devices) {
for (var i = 0; i < devices.length; i++) { for (var i = 0; i < devices.length; i++) {
var in_use = false; var in_use = false;
if (devices[i].ifname.match(/eth/)) { var NotUsable = NonUsableMac.test(devices[i].getMAC());
// Only "real" interfaces for slaves needed
if (NotUsable == false) {
for (var j = 0; j < interfaces.length; j++) { for (var j = 0; j < interfaces.length; j++) {
if (uci.get('network', interfaces[j]['.name'], 'proto') == 'bonding') { if (uci.get('network', interfaces[j]['.name'], 'proto') == 'bonding') {
var slaves = uci.get('network', interfaces[j]['.name'], 'slaves'); var slaves = L.toArray(uci.get('network', interfaces[j]['.name'], 'slaves'));
if (slaves != null) {
for (var k = 0; k < slaves.length; k++) { for (var k = 0; k < slaves.length; k++) {
if (devices[i].ifname == slaves[k] && interfaces[j]['.name'] != section_id) { if (devices[i].ifname == slaves[k] && interfaces[j]['.name'] != section_id) {
in_use = true; in_use = true;
}
} }
} }
} }
@ -43,6 +49,21 @@ function validateEmpty(section, value) {
} }
} }
function updatePrimaries(section, value) {
var opt = this.map.lookupOption('slaves', section);
var selected_slaves = opt[0].formvalue(section);
var uielem = this.map.lookupOption('primary', section)[0].getUIElement(section);
uielem.clearChoices();
for (var i = 0; i < selected_slaves.length; i++) {
uielem.addChoices(selected_slaves[i], selected_slaves[i]);
}
return true;
}
function validate_arp_policy(section, value) { function validate_arp_policy(section, value) {
var opt = this.map.lookupOption('link_monitoring', section); var opt = this.map.lookupOption('link_monitoring', section);
@ -80,8 +101,6 @@ function validate_arp_ip_targets(section, value) {
function validate_primary_interface(section, value) { function validate_primary_interface(section, value) {
var primary_valid = 'false';
var opt = this.map.lookupOption('bonding_policy', section); var opt = this.map.lookupOption('bonding_policy', section);
var selected_policy = opt[0].formvalue(section); var selected_policy = opt[0].formvalue(section);
@ -92,17 +111,9 @@ function validate_primary_interface(section, value) {
var selected_primary = opt[0].formvalue(section); var selected_primary = opt[0].formvalue(section);
if (selected_policy == 'active-backup' || selected_policy == 'balance-tlb' || selected_policy == 'balance-alb') { if (selected_policy == 'active-backup' || selected_policy == 'balance-tlb' || selected_policy == 'balance-alb') {
if (selected_slaves.filter(function(slave) { return slave == selected_primary }).length == 0)
for (var i = 0; i < selected_slaves.length; i++) {
if (selected_slaves[i] == selected_primary) {
primary_valid = 'true';
}
}
if (primary_valid == 'false') {
return _('You must select a primary interface which is included in selected slave interfaces!'); return _('You must select a primary interface which is included in selected slave interfaces!');
} }
}
return true; return true;
} }
@ -151,13 +162,14 @@ return network.registerProtocol('bonding', {
_('IPv4 address'), _('IPv4 address'),
_('The local IPv4 address')); _('The local IPv4 address'));
o.datatype = 'ip4addr'; o.datatype = 'ip4addr';
o.validate = validateEmpty; o.rmempty = false;
o = s.taboption('general', form.Value, 'netmask', o = s.taboption('general', form.Value, 'netmask',
_('IPv4 netmask'), _('IPv4 netmask'),
_('The local IPv4 netmask')); _('The local IPv4 netmask'));
o.datatype = 'ip4addr'; o.datatype = 'ip4addr';
o.validate = validateEmpty; o.validate = validateEmpty;
o.rmempty = false;
o.value("255.255.255.0"); o.value("255.255.255.0");
o.value("255.255.0.0"); o.value("255.255.0.0");
o.value("255.0.0.0"); o.value("255.0.0.0");
@ -165,7 +177,6 @@ return network.registerProtocol('bonding', {
o = s.taboption('advanced', form.MultiValue, 'slaves', o = s.taboption('advanced', form.MultiValue, 'slaves',
_('Slave Interfaces'), _('Slave Interfaces'),
_('Specifies which slave interfaces should be attached to this bonding interface')); _('Specifies which slave interfaces should be attached to this bonding interface'));
o.load = function(section_id) { o.load = function(section_id) {
return getSelectableSlaves(section_id).then(L.bind(function(devices) { return getSelectableSlaves(section_id).then(L.bind(function(devices) {
for (var i = 0; i < devices.length; i++) { for (var i = 0; i < devices.length; i++) {
@ -178,19 +189,11 @@ return network.registerProtocol('bonding', {
return ''; return '';
} }
var if_slaves = uci.get('network', section_id, 'slaves'); return uci.get('network', section_id, 'slaves');
if (if_slaves != null) {
return if_slaves;
}
return;
}, this)); }, this));
}; };
o.cfgvalue = function(section_id) { o.validate = updatePrimaries;
return uci.get('network', section_id, 'slaves'); o.rmempty = false;
};
o.validate = validateEmpty;
o = s.taboption('advanced', form.ListValue, 'bonding_policy', o = s.taboption('advanced', form.ListValue, 'bonding_policy',
_('Bonding Policy'), _('Bonding Policy'),
@ -204,36 +207,16 @@ return network.registerProtocol('bonding', {
o.value('balance-tlb', _('Adaptive transmit load balancing (balance-tlb, 5)')); o.value('balance-tlb', _('Adaptive transmit load balancing (balance-tlb, 5)'));
o.value('balance-alb', _('Adaptive load balancing (balance-alb, 6)')); o.value('balance-alb', _('Adaptive load balancing (balance-alb, 6)'));
o = s.taboption('advanced', form.ListValue, 'primary', o = s.taboption('advanced', widgets.DeviceSelect, 'primary',
_('Primary Slave'), _('Primary Slave'),
_('Specifies which slave is the primary device. It will always be the active slave while it is available')); _('Specifies which slave is the primary device. It will always be the active slave while it is available'));
o.depends('bonding_policy', 'active-backup'); o.depends('bonding_policy', 'active-backup');
o.depends('bonding_policy', 'balance-tlb'); o.depends('bonding_policy', 'balance-tlb');
o.depends('bonding_policy', 'balance-alb'); o.depends('bonding_policy', 'balance-alb');
o.filter = function(section_id, value) {
o.load = function(section_id) { // Never return anything as valid, as the valid possibilities
return getSelectableSlaves(section_id).then(L.bind(function(devices) { // will be set in the slaves validate function
for (var i = 0; i < devices.length; i++) { return false;
this.value(devices[i], devices[i]);
}
if (devices.length == 0) {
this.placeholder = _('No more primaries available, can not save interface');
this.value('', '');
return '';
}
var primary = uci.get('network', section_id, 'primary');
if (primary != null) {
return primary;
}
return;
}, this));
};
o.cfgvalue = function(section_id) {
return uci.get('network', section_id, 'primary');
}; };
o.validate = validate_primary_interface; o.validate = validate_primary_interface;
@ -253,7 +236,7 @@ return network.registerProtocol('bonding', {
_('Specifies the minimum number of links that must be active before asserting carrier')); _('Specifies the minimum number of links that must be active before asserting carrier'));
o.datatype = 'uinteger'; o.datatype = 'uinteger';
o.default = 0; o.default = 0;
o.validate = validateEmpty; o.rmempty = false;
o.depends('bonding_policy', '802.3ad'); o.depends('bonding_policy', '802.3ad');
o = s.taboption('advanced', form.Value, 'ad_actor_sys_prio', o = s.taboption('advanced', form.Value, 'ad_actor_sys_prio',
@ -261,7 +244,7 @@ return network.registerProtocol('bonding', {
_('Specifies the system priority')); _('Specifies the system priority'));
o.datatype = 'range(1,65535)'; o.datatype = 'range(1,65535)';
o.default = 65535; o.default = 65535;
o.validate = validateEmpty; o.rmempty = false;
o.depends('bonding_policy', '802.3ad'); o.depends('bonding_policy', '802.3ad');
o = s.taboption('advanced', form.Value, 'ad_actor_system', o = s.taboption('advanced', form.Value, 'ad_actor_system',
@ -293,7 +276,7 @@ return network.registerProtocol('bonding', {
_("Specifies the number of packets to transmit through a slave before moving to the next one")); _("Specifies the number of packets to transmit through a slave before moving to the next one"));
o.datatype = 'range(0,65535)'; o.datatype = 'range(0,65535)';
o.default = '1'; o.default = '1';
o.validate = validateEmpty; o.rmempty = false;
o.depends('bonding_policy', 'balance-rr'); o.depends('bonding_policy', 'balance-rr');
o = s.taboption('advanced', form.Value, 'lp_interval', o = s.taboption('advanced', form.Value, 'lp_interval',
@ -301,7 +284,7 @@ return network.registerProtocol('bonding', {
_("Specifies the number of seconds between instances where the bonding driver sends learning packets to each slaves peer switch")); _("Specifies the number of seconds between instances where the bonding driver sends learning packets to each slaves peer switch"));
o.datatype = 'range(1,2147483647)'; o.datatype = 'range(1,2147483647)';
o.default = '1'; o.default = '1';
o.validate = validateEmpty; o.rmempty = false;
o.depends('bonding_policy', 'balance-tlb'); o.depends('bonding_policy', 'balance-tlb');
o.depends('bonding_policy', 'balance-alb'); o.depends('bonding_policy', 'balance-alb');
@ -327,7 +310,7 @@ return network.registerProtocol('bonding', {
_("Specifies the number of peer notifications (gratuitous ARPs and unsolicited IPv6 Neighbor Advertisements) to be issued after a failover event")); _("Specifies the number of peer notifications (gratuitous ARPs and unsolicited IPv6 Neighbor Advertisements) to be issued after a failover event"));
o.datatype = 'range(0,255)'; o.datatype = 'range(0,255)';
o.default = '1'; o.default = '1';
o.validate = validateEmpty; o.rmempty = false;
o.depends('bonding_policy', 'active-backup'); o.depends('bonding_policy', 'active-backup');
o = s.taboption('advanced', form.ListValue, 'xmit_hash_policy', o = s.taboption('advanced', form.ListValue, 'xmit_hash_policy',
@ -350,7 +333,7 @@ return network.registerProtocol('bonding', {
_("Specifies the number of IGMP membership reports to be issued after a failover event in 200ms intervals")); _("Specifies the number of IGMP membership reports to be issued after a failover event in 200ms intervals"));
o.datatype = 'range(0,255)'; o.datatype = 'range(0,255)';
o.default = '1'; o.default = '1';
o.validate = validateEmpty; o.rmempty = false;
o.depends('bonding_policy', 'balance-tlb'); o.depends('bonding_policy', 'balance-tlb');
o.depends('bonding_policy', 'balance-alb'); o.depends('bonding_policy', 'balance-alb');
@ -375,7 +358,7 @@ return network.registerProtocol('bonding', {
_("Specifies the ARP link monitoring frequency in milliseconds")); _("Specifies the ARP link monitoring frequency in milliseconds"));
o.datatype = 'uinteger'; o.datatype = 'uinteger';
o.default = '0'; o.default = '0';
o.validate = validateEmpty; o.rmempty = false;
o.depends('link_monitoring', 'arp'); o.depends('link_monitoring', 'arp');
o = s.taboption('advanced', form.DynamicList, 'arp_ip_target', o = s.taboption('advanced', form.DynamicList, 'arp_ip_target',
@ -412,7 +395,7 @@ return network.registerProtocol('bonding', {
_("Specifies the MII link monitoring frequency in milliseconds")); _("Specifies the MII link monitoring frequency in milliseconds"));
o.datatype = 'uinteger'; o.datatype = 'uinteger';
o.default = '0'; o.default = '0';
o.validate = validateEmpty; o.rmempty = false;
o.depends('link_monitoring', 'mii'); o.depends('link_monitoring', 'mii');
o = s.taboption('advanced', form.Value, 'downdelay', o = s.taboption('advanced', form.Value, 'downdelay',
@ -420,7 +403,7 @@ return network.registerProtocol('bonding', {
_("Specifies the time in milliseconds to wait before disabling a slave after a link failure detection")); _("Specifies the time in milliseconds to wait before disabling a slave after a link failure detection"));
o.datatype = 'uinteger'; o.datatype = 'uinteger';
o.default = '0'; o.default = '0';
o.validate = validateEmpty; o.rmempty = false;
o.depends('link_monitoring', 'mii'); o.depends('link_monitoring', 'mii');
o = s.taboption('advanced', form.Value, 'updelay', o = s.taboption('advanced', form.Value, 'updelay',
@ -428,7 +411,7 @@ return network.registerProtocol('bonding', {
_("Specifies the time in milliseconds to wait before enabling a slave after a link recovery detection")); _("Specifies the time in milliseconds to wait before enabling a slave after a link recovery detection"));
o.datatype = 'uinteger'; o.datatype = 'uinteger';
o.default = '0'; o.default = '0';
o.validate = validateEmpty; o.rmempty = false;
o.depends('link_monitoring', 'mii'); o.depends('link_monitoring', 'mii');
o = s.taboption('advanced', form.ListValue, 'use_carrier', o = s.taboption('advanced', form.ListValue, 'use_carrier',