summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xscripts/vyatta-bonding.pl45
-rw-r--r--templates/interfaces/bonding/node.tag/hash-policy/node.def3
2 files changed, 39 insertions, 9 deletions
diff --git a/scripts/vyatta-bonding.pl b/scripts/vyatta-bonding.pl
index 3ecffdda..41602079 100755
--- a/scripts/vyatta-bonding.pl
+++ b/scripts/vyatta-bonding.pl
@@ -58,6 +58,16 @@ sub set_mode {
or die "Error: $intf can not set mode $val:$!\n";
}
+sub set_hash_policy {
+ my ( $intf, $hash ) = @_;
+
+ open my $fm, '>', "/sys/class/net/$intf/bonding/xmit_hash_policy"
+ or die "Error: $intf is not a bonding device:$!\n";
+ print {$fm} $hash, "\n";
+ close $fm
+ or die "Error: $intf can not set hash $val:$!\n";
+}
+
sub get_slaves {
my $intf = shift;
@@ -131,26 +141,44 @@ sub if_up {
and die "Could not set $intf up ($!)\n";
}
+# Can't change mode when bond device is up and slaves are attached
sub change_mode {
my ( $intf, $mode ) = @_;
my $interface = new Vyatta::Interface($intf);
die "$intf is not a valid interface" unless $interface;
- my $primary = primary_slave( $intf, $interface->hw_address() );
+ my $bond_up = $interface->up();
+
+ if_down($intf) if ($bond_up);
+
+ # Remove all interfaces; do primary last
+ my $primary = primary_slave( $intf, $interface->hw_address());
my @slaves = get_slaves($intf);
+
foreach my $slave (@slaves) {
- remove_slave( $intf, $slave ) unless ( $primary && $slave eq $primary );
+ remove_slave( $intf, $slave ) unless ( $primary && $slave eq $primary );
}
remove_slave( $intf, $primary ) if ($primary);
- my $bond_up = $interface->up();
- if_down($intf) if $bond_up;
set_mode( $intf, $mode );
- if_up($intf) if $bond_up;
+ add_slave( $intf, $primary) if ($primary);
foreach my $slave ( @slaves ) {
- add_slave( $intf, $slave );
+ add_slave( $intf, $slave ) unless ($primary && $slave eq $primary);
}
+ if_up($intf) if ($bond_up);
+}
+
+# Can't change hash when bond device is up
+sub change_hash {
+ my ( $intf, $hash ) = @_;
+ my $interface = new Vyatta::Interface($intf);
+ die "$intf is not a valid interface" unless $interface;
+ my $bond_up = $interface->up();
+
+ if_down($intf) if $bond_up;
+ set_hash_policy( $intf, $hash );
+ if_up($intf) if $bond_up;
}
# bonding requires interface to be down before enslaving
@@ -179,6 +207,7 @@ sub remove_port {
sub usage {
print "Usage: $0 --dev=bondX --mode={mode}\n";
+ print " $0 --dev=bondX --hash=layerX\n";
print " $0 --dev=bondX --add=ethX\n";
print " $0 --dev=bondX --remove=ethX\n";
print print "modes := ", join( ',', sort( keys %modes ) ), "\n";
@@ -186,11 +215,12 @@ sub usage {
exit 1;
}
-my ( $dev, $mode, $add_port, $rem_port );
+my ( $dev, $mode, $hash, $add_port, $rem_port );
GetOptions(
'dev=s' => \$dev,
'mode=s' => \$mode,
+ 'hash=s' => \$hash,
'add=s' => \$add_port,
'remove=s' => \$rem_port,
) or usage();
@@ -198,5 +228,6 @@ GetOptions(
die "$0: device not specified\n" unless $dev;
change_mode( $dev, $mode ) if $mode;
+change_hash( $dev, $hash ) if $hash;
add_port( $dev, $add_port ) if $add_port;
remove_port( $dev, $rem_port ) if $rem_port;
diff --git a/templates/interfaces/bonding/node.tag/hash-policy/node.def b/templates/interfaces/bonding/node.tag/hash-policy/node.def
index 54c2bb0f..842410d9 100644
--- a/templates/interfaces/bonding/node.tag/hash-policy/node.def
+++ b/templates/interfaces/bonding/node.tag/hash-policy/node.def
@@ -5,8 +5,7 @@ syntax:expression: $VAR(@) in "layer2", "layer2+3", "layer3+4" \
; "hash_policy must be layer2 layer3+4 or layer2+3"
help: Bonding transmit hash policy
-update: sudo sh -c \
- "echo $VAR(@) >/sys/class/net/$VAR(../@)/bonding/xmit_hash_policy"
+update: sudo ${vyatta_sbindir}/vyatta-bonding.pl --dev=$VAR(../@) --hash=$VAR(@)
val_help: layer2; use MAC addresses to generate the hash (802.3ad)
val_help: layer2+3; combine MAC address and IP address to make hash