summaryrefslogtreecommitdiff
path: root/scripts/vyatta-bonding.pl
diff options
context:
space:
mode:
authorStephen Hemminger <stephen.hemminger@vyatta.com>2008-09-17 17:01:54 -0700
committerStephen Hemminger <stephen.hemminger@vyatta.com>2008-09-17 17:01:54 -0700
commit133b72347631663ee595312579dd2991059280cb (patch)
tree909aaf53dfe5abf1551284e06030f2ad2a38d9e8 /scripts/vyatta-bonding.pl
parent8db79c9b0aa8052e4dee0f073e945d68370a0210 (diff)
downloadvyatta-cfg-quagga-133b72347631663ee595312579dd2991059280cb.tar.gz
vyatta-cfg-quagga-133b72347631663ee595312579dd2991059280cb.zip
Add support for bonding
Bugfix 3173 Add support for bonding device creation and adding slaves
Diffstat (limited to 'scripts/vyatta-bonding.pl')
-rwxr-xr-xscripts/vyatta-bonding.pl106
1 files changed, 106 insertions, 0 deletions
diff --git a/scripts/vyatta-bonding.pl b/scripts/vyatta-bonding.pl
new file mode 100755
index 00000000..4e44d67b
--- /dev/null
+++ b/scripts/vyatta-bonding.pl
@@ -0,0 +1,106 @@
+#!/usr/bin/perl
+#
+# **** License ****
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License version 2 as
+# published by the Free Software Foundation.
+#
+# This program is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# General Public License for more details.
+#
+# A copy of the GNU General Public License is available as
+# `/usr/share/common-licenses/GPL' in the Debian GNU/Linux distribution
+# or on the World Wide Web at `http://www.gnu.org/copyleft/gpl.html'.
+# You can also obtain it by writing to the Free Software Foundation,
+# Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
+# MA 02110-1301, USA.
+#
+# This code was originally developed by Vyatta, Inc.
+# Portions created by Vyatta are Copyright (C) 2007 Vyatta, Inc.
+# All Rights Reserved.
+#
+# Author: Stephen Hemminger
+# Date: September 2008
+# Description: Script to setup bonding interfaces
+#
+# **** End License ****
+#
+
+use lib "/opt/vyatta/share/perl5/";
+use VyattaConfig;
+
+use Getopt::Long;
+use strict;
+use warnings;
+
+my %modes = (
+ "round-robin" => 0,
+ "active-backup" => 1,
+ "xor-hash" => 2,
+ "broadcast" => 3,
+ "802.3ad" => 4,
+ "transmit-load-balance" => 5,
+ "adaptive-load-balance" => 6,
+);
+
+sub create_bond {
+ my $bond = shift;
+ my $config = new VyattaConfig;
+
+ $config->setLevel("interfaces bonding $bond");
+ my $mode = $modes{$config->returnValue("mode")};
+ defined $mode or die "bonding mode not defined";
+
+ system("sudo modprobe -o \"$bond\" bonding mode=$mode") == 0
+ or die "modprobe of bonding failed: $!\n";
+
+ system("sudo ip link set \"$bond\" up") == 0
+ or die "enabling $bond failed: $!\n";
+
+ $config->setLevel("interfaces ethernet");
+ for my $intf ( $config->listNodes() ) {
+ my $group = $config->returnValue("bond-group");
+ if (defined $group && $group eq $bond ) {
+ system("sudo ifenslave $bond $intf") == 0
+ or die "Adding $intf to $bond failed\n";
+ }
+ }
+}
+
+sub delete_bond {
+ my $bond = shift;
+ system("sudo rmmod \"$bond\"") == 0
+ or die "removal of bonding module failed: $!\n";
+}
+
+# See if bonding device exists and the mode has changed
+sub change_bond {
+ my $bond = shift;
+ my $config = new VyattaConfig;
+
+ $config->setLevel("interfaces bonding");
+ if ( !( $config->isAdded($bond) || $config->isDeleted($bond) )
+ && $config->isChanged("$bond mode") )
+ {
+ delete_bond($bond);
+ create_bond($bond);
+ }
+ exit 0;
+}
+
+sub usage {
+ print "Usage: $0 --create bondX\n";
+ print " --delete bondX\n";
+ print " --mode-change bondX\n";
+ exit 1;
+}
+
+GetOptions(
+ 'create=s' => sub { create_bond( $_[1] ); },
+ 'delete=s' => sub { delete_bond( $_[1] ); },
+ 'mode-change=s' => sub { change_bond( $_[1] ); },
+) or usage();
+
+