From 0f402acf382c7e27c130c7d75a5886d0150e8d0e Mon Sep 17 00:00:00 2001 From: Stephen Hemminger Date: Fri, 31 Jul 2009 21:59:46 -0700 Subject: BONDING: handle change of bond-group Use similar action to new bridge-group Bug 4768 --- scripts/vyatta-bonding.pl | 26 +++++++++++++++++----- .../ethernet/node.tag/bond-group/node.def | 17 +++++++++----- 2 files changed, 31 insertions(+), 12 deletions(-) diff --git a/scripts/vyatta-bonding.pl b/scripts/vyatta-bonding.pl index 66417f9f..b9ea0bcf 100755 --- a/scripts/vyatta-bonding.pl +++ b/scripts/vyatta-bonding.pl @@ -30,6 +30,7 @@ use lib "/opt/vyatta/share/perl5/"; use Vyatta::Interface; +use Vyatta::Config; use Getopt::Long; use strict; @@ -136,13 +137,9 @@ sub change_mode { my @slaves = get_slaves($intf); foreach my $slave (@slaves) { - if_down($slave); remove_slave( $intf, $slave ) unless ( $primary && $slave eq $primary ); } - if ($primary) { - if_down($primary); - remove_slave( $intf, $primary ); - } + remove_slave( $intf, $primary ) if ($primary); my $bond_up = $interface->up(); if_down($intf) if $bond_up; @@ -154,6 +151,23 @@ sub change_mode { } } +# bonding requires interface to be down before enslaving +# but enslaving automatically brings interface up! +sub add_port { + my ( $intf, $slave ) = @_; + my $slaveif = new Vyatta::Interface($slave); + + if ($slaveif->up()) { + if_down($slave); + } else { + my $cfg = new Vyatta::Config; + $cfg->setLevel($slaveif->path()); + die "Can not add disabled interface $slave to bond-group $intf\n" + if $cfg->exists('disable'); + } + add_slave ($intf, $slave); +} + sub usage { print "Usage: $0 --dev=bondX --mode={mode}\n"; print " $0 --dev=bondX --add-port=ethX\n"; @@ -175,5 +189,5 @@ GetOptions( die "$0: device not specified\n" unless $dev; change_mode( $dev, $mode ) if $mode; -add_slave( $dev, $add_port ) if $add_port; +add_port( $dev, $add_port ) if $add_port; remove_slave( $dev, $rem_port ) if $rem_port; diff --git a/templates/interfaces/ethernet/node.tag/bond-group/node.def b/templates/interfaces/ethernet/node.tag/bond-group/node.def index 4c5c38c3..d2a398a1 100644 --- a/templates/interfaces/ethernet/node.tag/bond-group/node.def +++ b/templates/interfaces/ethernet/node.tag/bond-group/node.def @@ -3,9 +3,14 @@ help: Add this interface to a bonding group commit:expression: exec \ "/opt/vyatta/sbin/vyatta-interfaces.pl --dev=$VAR(@) --check=bonding" allowed: /opt/vyatta/sbin/vyatta-interfaces.pl --show=bonding -create: sudo sh -c "ip link set $VAR(../@) down 2>/dev/null"; - sudo sh -c "echo +$VAR(../@) > /sys/class/net/$VAR(@)/bonding/slaves"; - sudo sh -c "ip link set $VAR(../@) up 2>/dev/null" - -delete: sudo sh -c "echo -$VAR(../@) > /sys/class/net/$VAR(@)/bonding/slaves" - +end: ethif=$VAR(../@) + old=`/opt/vyatta/sbin/vyatta-cli-expand-var.pl \$\(/interfaces/ethernet/$ethif/bond-group/@\)` + new=$VAR(@) + if [ ${COMMIT_ACTION} = 'SET' ]; then + sudo ${vyatta_sbindir}/vyatta-bonding.pl --dev=$new --add=$ethif + elif [ ${COMMIT_ACTION} = 'DELETE' ]; then + sudo ${vyatta_sbindir}/vyatta-bonding.pl --dev=$new --remove=$ethif + elif [ "$old" != "$new" ]; then + sudo ${vyatta_sbindir}/vyatta-bonding.pl --dev=$old --remove=$ethif + sudo ${vyatta_sbindir}/vyatta-bonding.pl --dev=$new --add=$ethif + fi -- cgit v1.2.3