From bbba109b96309778b875ecdb1a291e53a6519cf2 Mon Sep 17 00:00:00 2001 From: bergware Date: Sun, 5 Jun 2016 14:43:11 +0200 Subject: [PATCH 1/8] Enhanced network settings - allow multiple interfaces in bridge --- plugins/dynamix/Eth0.page | 80 +++++++++++++++++++++++-------- plugins/dynamix/EthX.page | 26 +++++++++- plugins/dynamix/scripts/netconfig | 40 ++++++++++++---- 3 files changed, 116 insertions(+), 30 deletions(-) diff --git a/plugins/dynamix/Eth0.page b/plugins/dynamix/Eth0.page index 019b9a01e..229c25cd4 100644 --- a/plugins/dynamix/Eth0.page +++ b/plugins/dynamix/Eth0.page @@ -65,8 +65,7 @@ refresh(); // automatically include new ethernet ports Array.prototype.dups = function(){return this.sort().filter(function(v,i,o){return i&&v===o[i-1]?v:0;}).length;} function prepareSettings(form) { - var bonding = form.BONDING !== undefined; - if (bonding) { + if (form.BONDING !== undefined) { var member = ''; for (var i=0,item; item=form.BONDNICS.options[i]; i++) { if (item.selected) { @@ -79,8 +78,19 @@ function prepareSettings(form) { item.value = member; item.selected = true; item.disabled = false; - form.BONDNICS.disabled = false; - if (form.BONDING.value=='yes') form.BRNICS.value = form.BONDNAME.value; + var member = ''; + for (var i=0,item; item=form.BRNICS.options[i]; i++) { + if (item.selected) { + if (member.length) member += ','; + member += item.value; + item.selected = false; + } + } + item = form.BRNICS.options[0]; + item.value = form.BONDING.value=='yes' ? form.BONDNAME.value : member; + item.selected = true; + item.disabled = false; + if (member.indexOf(',')>0) form.BRSTP.value = 'yes'; } if (form.TYPE.value == 'access') { $(form).find('input[name^="VLANID:"]').prop('disabled',true); @@ -143,13 +153,27 @@ function checkDNSSettings(form) { function checkBondingSettings(form,ctrl) { var disabled = form.BONDING.value=='no'; var mode = form.BONDING_MODE.value; - if (ctrl) { - form.BONDING_MODE.disabled = disabled; - form.BONDNICS.disabled = disabled; - $('#bond0').dropdownchecklist(disabled?'disable':'enable'); + if (ctrl>=0) { + var me = ctrl==0 ? null : 'slow'; + if (disabled) { + $('#bond-members').hide(me); + } else { + $('#bond-members').show(me); + $('#bond0').dropdownchecklist('destroy').dropdownchecklist({emptyText:'None', width:131}); + } + if (ctrl==1) checkBridgingSettings(form,1); } if (mode==1 || mode>4 || disabled) {$('#attention0').hide();} else {$('#attention0').show();} } +function checkBridgingSettings(form,ctrl) { + var me = ctrl==0 ? null : 'slow'; + if (form.BRIDGING.value=='yes' && form.BONDING.value=='no') { + $('#bridge-members').show(me); + $('#bridge0').dropdownchecklist('destroy').dropdownchecklist({emptyText:'None', width:131}); + } else { + $('#bridge-members').hide(me); + } +} function checkNetworkAccess(form,port) { if (form.TYPE.value=='access') { $('.access-'+port).hide(); @@ -190,23 +214,26 @@ function exitCode(form,key) { } } $(function() { + var ctrl = ""; var form = document.eth0_settings; - - $('#tab1').bind({click:function(){ - $('#bond0').dropdownchecklist('destroy').dropdownchecklist({emptyText:'None', width:131}); - checkBondingSettings(form,true); - }}); - $('#bond0').dropdownchecklist({emptyText:'None', width:130}); - checkBondingSettings(form,true); + $('#bridge0').dropdownchecklist({emptyText:'None', width:130}); + checkBondingSettings(form,0); + checkBridgingSettings(form,0); checkNetworkAccess(form,'eth0'); checkNetworkSettings(form); disableForm(form); $('#bond0').dropdownchecklist('disable'); + $('#bridge0').dropdownchecklist('disable'); checkDNSSettings(form); + + $('.tabs').append(ctrl); + + $('div[id=title]').append(ctrl); + });
@@ -218,7 +245,6 @@ $(function() { - @@ -231,7 +257,7 @@ MAC address: > When tagging is enabled all VLANs on this interface will share the same hardware address. Enable bonding: -: @@ -240,8 +266,9 @@ Enable bonding: > This can be used to improve the connection redundancy and/or throughput of the system. > Different bonding modes are supported (see below), but some modes require proper switch support. + Enable bridging: -: @@ -273,6 +301,18 @@ Enable bridging: > Bridging is a feature which creates a virtual bridge and allows VMs to communicate directly with the physical Ethernet port. > Both bonding and bridging can be combined to let VMs communicate over a *bonded* interface. + Type of access: : Stopped to change" : ""?> +: Stopped to change" : ""?>
diff --git a/plugins/dynamix/EthX.page b/plugins/dynamix/EthX.page index cb9aaa907..7c326c5f0 100644 --- a/plugins/dynamix/EthX.page +++ b/plugins/dynamix/EthX.page @@ -24,15 +24,37 @@ if (isset($ethX)) foreach ($ethX as $key => $val) if (substr($key,0,6)=='VLANID' // get bond membership $bond_ethX = $eth0['BONDING']=='yes' ? in_array('ethX',explode(',',$eth0['BONDNICS'])) : false; + +// get bridge membership +$bridge_ethX = $eth0['BRIDGING']=='yes' ? in_array('ethX',explode(',',$eth0['BRNICS'])) : false; + +if ($disabled) + $locked = "VMs must be STOPPED to change"; +elseif ($bond_ethX) + $locked = "Interface must be removed as Bonding member to change"; +elseif ($bridge_ethX) + $locked = "Interface must be removed as Bridging member to change"; +else + $locked = ""; ?>
@@ -161,5 +183,5 @@ Network mask:   -: Unbonded to change" : ($disabled ? "VMs must be Stopped to change" : "")?> +:
diff --git a/plugins/dynamix/scripts/netconfig b/plugins/dynamix/scripts/netconfig index 196ea1850..76abded35 100755 --- a/plugins/dynamix/scripts/netconfig +++ b/plugins/dynamix/scripts/netconfig @@ -17,12 +17,20 @@ $run = $set != 'none'; $ini = parse_ini_file('/var/local/emhttp/network.ini',true); ksort($ini,SORT_NATURAL); $cfg = '/boot/config/network.cfg'; +function ifname($name) { + global $old; + for ($i=0; $i<$old['SYSNICS']; $i++) { + $nics = $old['BONDNICS'][$i] ?: $old['BRNICS'][$i]; + if (strpos("$nics ","$name ")!==false) return $old['IFNAME'][$i]; + } + return $name; +} + if ($run && file_exists($cfg)) { $old = parse_ini_file($cfg); - $i = preg_replace('/[^\d]/','',$set); if (isset($old['SYSNICS'])) { // new syntax - $ifname = isset($old['IFNAME'][$i]) ? $old['IFNAME'][$i] : $set; + $ifname = ifname($set); } else { // legacy syntax if ($i==0) $ifname = $old['BRIDGING']=='yes' ? $old['BRNAME'] : ($old['BONDING']=='yes' ? $old['BONDNAME'] : $set); @@ -33,25 +41,41 @@ if ($run && file_exists($cfg)) { // don't execute when only interface description has changed if ($run) exec("/etc/rc.d/rc.inet1 {$ifname}_stop >/dev/null"); -if ($bonding = isset($ini['eth0']) && $ini['eth0']['BONDING']=='yes') { +if ($bonding = $ini['eth0']['BONDING']=='yes') { $ini['eth0']['BONDNICS'] = str_replace(',',' ',$ini['eth0']['BONDNICS']); - $members = explode(' ',trim(str_replace('eth0','',$ini['eth0']['BONDNICS']))); + $bond0 = explode(' ',trim(str_replace('eth0','',$ini['eth0']['BONDNICS']))); +// ensure additional NICs in bond are set free + if ($run && $set=='eth0') foreach ($bond0 as $nic) { + if (isset($old['SYSNICS'])) $nic = ifname($nic); + exec("/etc/rc.d/rc.inet1 {$nic}_stop >/dev/null"); + } +} + +if ($bridging = $ini['eth0']['BRIDGING']=='yes') { + $ini['eth0']['BRNICS'] = str_replace(',',' ',$ini['eth0']['BRNICS']); + $br0 = explode(' ',trim(str_replace('eth0','',$ini['eth0']['BRNICS']))); +// ensure additional NICs in bridge are set free + if ($run && $set=='eth0') foreach ($br0 as $nic) { + if (isset($old['SYSNICS'])) $nic = ifname($nic); + exec("/etc/rc.d/rc.inet1 {$nic}_stop >/dev/null"); + } } // create configuration file for all available interfaces $i = 0; $new = []; $new[] = "# Generated settings:"; foreach ($ini as $name => $port) { - if ($bonding && in_array($name,$members)) continue; - $bridging = $port['BRIDGING']=='yes'; + if ($bonding && in_array($name,$bond0)) continue; + if ($bridging && in_array($name,$br0)) continue; + $bridge = $port['BRIDGING']=='yes'; $trunk = $port['TYPE']=='trunk'; $j = 0; $x0 = 0; - $iface = $bridging ? $port['BRNAME'] : ($bonding && $name=='eth0' ? $port['BONDNAME'] : $name); + $iface = $bridge ? $port['BRNAME'] : ($bonding && $name=='eth0' ? $port['BONDNAME'] : $name); $new[] = "IFNAME[$i]=\"$iface\""; if ($set==$name) $ifname = $iface; foreach ($port as $key => $val) { if (preg_match('/^(TYPE|BONDING$|BRIDGING)/',$key)) continue; if (!$bonding && preg_match('/^(BONDING_MODE|BONDING_MIIMON|BONDNICS|BONDNAME)/',$key)) continue; - if (!$bridging && preg_match('/^(BRSTP|BRFD|BRNICS|BRNAME)/',$key)) continue; + if (!$bridge && preg_match('/^(BRSTP|BRFD|BRNICS|BRNAME)/',$key)) continue; list($item,$x) = explode(':',$key,2); if ($trunk && $x>0 && preg_match('/^(VLANID|USE_DHCP|IPADDR|NETMASK|DESCRIPTION)/',$key)) { if ($x0 != $x) {$x0 = $x; $j++;} From fdf74080be95a56f3552ba5cccc78a117a08e166 Mon Sep 17 00:00:00 2001 From: bergware Date: Sun, 5 Jun 2016 15:13:39 +0200 Subject: [PATCH 2/8] netconfig: added interface presence check --- plugins/dynamix/scripts/netconfig | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/dynamix/scripts/netconfig b/plugins/dynamix/scripts/netconfig index 76abded35..86ac35ab3 100755 --- a/plugins/dynamix/scripts/netconfig +++ b/plugins/dynamix/scripts/netconfig @@ -47,7 +47,7 @@ if ($bonding = $ini['eth0']['BONDING']=='yes') { // ensure additional NICs in bond are set free if ($run && $set=='eth0') foreach ($bond0 as $nic) { if (isset($old['SYSNICS'])) $nic = ifname($nic); - exec("/etc/rc.d/rc.inet1 {$nic}_stop >/dev/null"); + if ($nic) exec("/etc/rc.d/rc.inet1 {$nic}_stop >/dev/null"); } } @@ -57,7 +57,7 @@ if ($bridging = $ini['eth0']['BRIDGING']=='yes') { // ensure additional NICs in bridge are set free if ($run && $set=='eth0') foreach ($br0 as $nic) { if (isset($old['SYSNICS'])) $nic = ifname($nic); - exec("/etc/rc.d/rc.inet1 {$nic}_stop >/dev/null"); + if ($nic) exec("/etc/rc.d/rc.inet1 {$nic}_stop >/dev/null"); } } From 92749903a16e1499a93041ae5f9859df3dd5884f Mon Sep 17 00:00:00 2001 From: bergware Date: Sun, 5 Jun 2016 16:10:56 +0200 Subject: [PATCH 3/8] netconfig: fix regression error --- plugins/dynamix/scripts/netconfig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/dynamix/scripts/netconfig b/plugins/dynamix/scripts/netconfig index 86ac35ab3..9147ef91f 100755 --- a/plugins/dynamix/scripts/netconfig +++ b/plugins/dynamix/scripts/netconfig @@ -33,7 +33,7 @@ if ($run && file_exists($cfg)) { $ifname = ifname($set); } else { // legacy syntax - if ($i==0) $ifname = $old['BRIDGING']=='yes' ? $old['BRNAME'] : ($old['BONDING']=='yes' ? $old['BONDNAME'] : $set); + if ($set=='eth0') $ifname = $old['BRIDGING']=='yes' ? $old['BRNAME'] : ($old['BONDING']=='yes' ? $old['BONDNAME'] : $set); } } From f1cd69fb34f4be822f8e793a4fd4f930b3ead06a Mon Sep 17 00:00:00 2001 From: bergware Date: Sun, 5 Jun 2016 17:08:40 +0200 Subject: [PATCH 4/8] Improved 'interface not configured' detection --- plugins/dynamix/EthX.page | 2 +- plugins/dynamix/include/update.ethernet.php | 12 +++++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/plugins/dynamix/EthX.page b/plugins/dynamix/EthX.page index 7c326c5f0..add4d734e 100644 --- a/plugins/dynamix/EthX.page +++ b/plugins/dynamix/EthX.page @@ -16,7 +16,7 @@ Png="ethernet.png" ?> ]'"))==0; +$down = empty($ethX) || strlen(exec("ip link show ethX|grep -om1 ',UP[,>]'"))==0; // get VLAN interfaces $vlan_ethX = [0]; diff --git a/plugins/dynamix/include/update.ethernet.php b/plugins/dynamix/include/update.ethernet.php index 0c2439b07..4ea55919f 100644 --- a/plugins/dynamix/include/update.ethernet.php +++ b/plugins/dynamix/include/update.ethernet.php @@ -11,5 +11,15 @@ */ ?> \ No newline at end of file From a54bf85dcd898bcd18298bb3d9687514bf71f08b Mon Sep 17 00:00:00 2001 From: bergware Date: Sun, 5 Jun 2016 18:33:47 +0200 Subject: [PATCH 5/8] Renamed and moved field "Enable VLANs" (previously "Type of access") --- plugins/dynamix/Eth0.page | 153 ++++++++++++++++++++++++++------------ plugins/dynamix/EthX.page | 85 +++++++++++++++++---- 2 files changed, 174 insertions(+), 64 deletions(-) diff --git a/plugins/dynamix/Eth0.page b/plugins/dynamix/Eth0.page index 229c25cd4..11b2140b1 100644 --- a/plugins/dynamix/Eth0.page +++ b/plugins/dynamix/Eth0.page @@ -53,7 +53,7 @@ $vlan_eth0 = [0]; if (isset($eth0)) foreach ($eth0 as $key => $val) if (substr($key,0,6)=='VLANID') $vlan_eth0[] = substr($key,7); ?>