diff options
author | Stephen Hemminger <stephen.hemminger@vyatta.com> | 2008-09-17 17:01:54 -0700 |
---|---|---|
committer | Stephen Hemminger <stephen.hemminger@vyatta.com> | 2008-09-17 17:01:54 -0700 |
commit | 133b72347631663ee595312579dd2991059280cb (patch) | |
tree | 909aaf53dfe5abf1551284e06030f2ad2a38d9e8 /scripts/vyatta-bonding.pl | |
parent | 8db79c9b0aa8052e4dee0f073e945d68370a0210 (diff) | |
download | vyatta-cfg-system-133b72347631663ee595312579dd2991059280cb.tar.gz vyatta-cfg-system-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-x | scripts/vyatta-bonding.pl | 106 |
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(); + + |