summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStephen Hemminger <stephen.hemminger@vyatta.com>2008-09-16 11:31:55 -0700
committerStephen Hemminger <stephen.hemminger@vyatta.com>2008-09-16 11:31:55 -0700
commit8e988dec3b0cd86c58a8d2222e0b142b9b684fa8 (patch)
treef795fe5c7d24a9b4a29a71d4eae2ee39c51fa26c
parent8363358c3010d1f7383e3a09c16d071f9ec5b42f (diff)
downloadvyatta-op-8e988dec3b0cd86c58a8d2222e0b142b9b684fa8.tar.gz
vyatta-op-8e988dec3b0cd86c58a8d2222e0b142b9b684fa8.zip
Add preliminary operational mode support for bonding
Basic infrastructure for show status of bonding interfaces
-rw-r--r--Makefile.am1
-rwxr-xr-xscripts/vyatta-show-bonding.pl129
-rw-r--r--templates/show/interfaces/bonding/node.def2
-rw-r--r--templates/show/interfaces/bonding/node.tag/capture/node.def2
-rw-r--r--templates/show/interfaces/bonding/node.tag/capture/not/node.def1
-rw-r--r--templates/show/interfaces/bonding/node.tag/capture/not/port/node.def1
-rw-r--r--templates/show/interfaces/bonding/node.tag/capture/not/port/node.tag/node.def3
-rw-r--r--templates/show/interfaces/bonding/node.tag/capture/port/node.def1
-rw-r--r--templates/show/interfaces/bonding/node.tag/capture/port/node.tag/node.def3
-rw-r--r--templates/show/interfaces/bonding/node.tag/node.def7
-rw-r--r--templates/show/interfaces/bonding/node.tag/vif/node.def4
-rw-r--r--templates/show/interfaces/bonding/node.tag/vif/node.tag/brief/node.def2
-rw-r--r--templates/show/interfaces/bonding/node.tag/vif/node.tag/capture/node.def2
-rw-r--r--templates/show/interfaces/bonding/node.tag/vif/node.tag/capture/not/node.def1
-rw-r--r--templates/show/interfaces/bonding/node.tag/vif/node.tag/capture/not/port/node.def1
-rw-r--r--templates/show/interfaces/bonding/node.tag/vif/node.tag/capture/not/port/node.tag/node.def3
-rw-r--r--templates/show/interfaces/bonding/node.tag/vif/node.tag/capture/port/node.def1
-rw-r--r--templates/show/interfaces/bonding/node.tag/vif/node.tag/capture/port/node.tag/node.def3
-rw-r--r--templates/show/interfaces/bonding/node.tag/vif/node.tag/node.def5
19 files changed, 172 insertions, 0 deletions
diff --git a/Makefile.am b/Makefile.am
index 627ed32..d8895d4 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -17,6 +17,7 @@ bin_SCRIPTS += scripts/vyatta-show-version
bin_SCRIPTS += scripts/vyatta-show-dhclient.pl
bin_SCRIPTS += scripts/vyatta-show-dmi
bin_SCRIPTS += scripts/vyatta-tshark-interface-port.pl
+bin_SCRIPTS += scripts/vyatta-show-bonding.pl
bin_sudo_users_SCRIPTS = scripts/vyatta-identify-interface.pl
bin_sudo_users_SCRIPTS += scripts/vyatta-delete-log-file.sh
diff --git a/scripts/vyatta-show-bonding.pl b/scripts/vyatta-show-bonding.pl
new file mode 100755
index 0000000..68e65e2
--- /dev/null
+++ b/scripts/vyatta-show-bonding.pl
@@ -0,0 +1,129 @@
+#!/usr/bin/perl
+#
+# Module: vyatta-show-interfaces.pl
+#
+# **** 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.
+#
+# This code was originally developed by Vyatta, Inc.
+# Portions created by Vyatta are Copyright (C) 2008 Vyatta, Inc.
+# All Rights Reserved.
+#
+# Author: Stephen Hemminger
+# Date: September 2008
+# Description: Script to display bonding information
+#
+# **** End License ****
+#
+use Getopt::Long;
+
+use strict;
+use warnings;
+
+sub usage {
+ print "Usage: $0 --brief\n";
+ print " $0 interface(s)\n";
+ exit 1;
+}
+
+sub get_sysfs_value {
+ my ( $intf, $name ) = @_;
+
+ open( my $statf, '<', "/sys/class/net/$intf/$name" )
+ or die "Can't open file /sys/class/net/$intf/$name";
+
+ my $value = <$statf>;
+ chomp $value if defined $value;
+ close $statf;
+ return $value;
+}
+
+sub get_state_link {
+ my $intf = shift;
+ my $state;
+ my $link = 'down';
+ my $flags = get_sysfs_value( $intf, 'flags' );
+
+ my $hex_flags = hex($flags);
+ if ( $hex_flags & 0x1 ) { # IFF_UP
+ $state = 'up';
+ my $carrier = get_sysfs_value( $intf, 'carrier' );
+ if ( $carrier eq '1' ) {
+ $link = "up";
+ }
+ }
+ else {
+ $state = 'down';
+ }
+
+ return ( $state, $link );
+}
+
+sub show_brief {
+ my @interfaces = @_;
+ my $format = "%-12s %-10s %-8s %-6s %s\n";
+
+ printf $format, 'Interface', 'Mode', 'State', 'Link', 'Slaves';
+ foreach my $intf (@interfaces) {
+ my $mode = get_sysfs_value( $intf, "bonding/mode" );
+ $mode =~ s/ [0-9]+$//;
+ my ( $state, $link ) = get_state_link($intf);
+ my $slaves = get_sysfs_value( $intf, "bonding/slaves" );
+ printf $format, $intf, $mode, $state, $link, $slaves;
+ }
+}
+
+sub show {
+ my @interfaces = @_;
+ my $format = "%-16s %-10s %-10s %-10s %-10s\n";
+
+ printf $format, "Interface", "RX: bytes", "packets", "TX: bytes", "packets";
+ foreach my $intf (@interfaces) {
+ my @slaves = split( / /, get_sysfs_value( $intf, "bonding/slaves" ) );
+ printf $format, $intf, get_sysfs_value( $intf, "statistics/rx_bytes" ),
+ get_sysfs_value( $intf, "statistics/rx_packets" ),
+ get_sysfs_value( $intf, "statistics/tx_bytes" ),
+ get_sysfs_value( $intf, "statistics/tx_packets" );
+
+ foreach my $slave (@slaves) {
+ printf $format, ' ' . $slave,
+ get_sysfs_value( $intf, "statistics/rx_bytes" ),
+ get_sysfs_value( $intf, "statistics/rx_packets" ),
+ get_sysfs_value( $intf, "statistics/tx_bytes" ),
+ get_sysfs_value( $intf, "statistics/tx_packets" );
+ }
+ }
+}
+
+my $brief;
+GetOptions( 'brief' => \$brief, ) or usage();
+
+my @bond_intf = ();
+
+if ( $#ARGV == -1 ) {
+ my $sysfs = '/sys/class/net';
+ opendir( my $sysdir, $sysfs ) || die "can't opendir $sysfs";
+ foreach my $intf ( readdir($sysdir) ) {
+ if ( -d "$sysfs/$intf/bonding" ) {
+ unshift @bond_intf, $intf;
+ }
+ }
+ close $sysdir;
+}
+else {
+ @bond_intf = @ARGV;
+}
+
+if ($brief) {
+ show_brief(@bond_intf);
+}
+else {
+ show(@bond_intf);
+}
diff --git a/templates/show/interfaces/bonding/node.def b/templates/show/interfaces/bonding/node.def
new file mode 100644
index 0000000..da85752
--- /dev/null
+++ b/templates/show/interfaces/bonding/node.def
@@ -0,0 +1,2 @@
+help: Show bonding interface information
+run: ${vyatta_bindir}/vyatta-show-bonding.pl --brief
diff --git a/templates/show/interfaces/bonding/node.tag/capture/node.def b/templates/show/interfaces/bonding/node.tag/capture/node.def
new file mode 100644
index 0000000..fe96958
--- /dev/null
+++ b/templates/show/interfaces/bonding/node.tag/capture/node.def
@@ -0,0 +1,2 @@
+help: Show captured traffic on specified bonding interface
+run: /opt/vyatta/bin/vyatta-tshark-interface-port.pl "$4"
diff --git a/templates/show/interfaces/bonding/node.tag/capture/not/node.def b/templates/show/interfaces/bonding/node.tag/capture/not/node.def
new file mode 100644
index 0000000..5896bc8
--- /dev/null
+++ b/templates/show/interfaces/bonding/node.tag/capture/not/node.def
@@ -0,0 +1 @@
+help: Show captured traffic excluding the specified bonding interface
diff --git a/templates/show/interfaces/bonding/node.tag/capture/not/port/node.def b/templates/show/interfaces/bonding/node.tag/capture/not/port/node.def
new file mode 100644
index 0000000..5896bc8
--- /dev/null
+++ b/templates/show/interfaces/bonding/node.tag/capture/not/port/node.def
@@ -0,0 +1 @@
+help: Show captured traffic excluding the specified bonding interface
diff --git a/templates/show/interfaces/bonding/node.tag/capture/not/port/node.tag/node.def b/templates/show/interfaces/bonding/node.tag/capture/not/port/node.tag/node.def
new file mode 100644
index 0000000..61079d5
--- /dev/null
+++ b/templates/show/interfaces/bonding/node.tag/capture/not/port/node.tag/node.def
@@ -0,0 +1,3 @@
+help: Show captured traffic excluding the specified bonding interface
+run: /opt/vyatta/bin/vyatta-tshark-interface-port.pl "$4" "$8" 1
+allowed: echo -n '<1-65535>'
diff --git a/templates/show/interfaces/bonding/node.tag/capture/port/node.def b/templates/show/interfaces/bonding/node.tag/capture/port/node.def
new file mode 100644
index 0000000..0870adc
--- /dev/null
+++ b/templates/show/interfaces/bonding/node.tag/capture/port/node.def
@@ -0,0 +1 @@
+help: Show captured traffic on specified bonding interface
diff --git a/templates/show/interfaces/bonding/node.tag/capture/port/node.tag/node.def b/templates/show/interfaces/bonding/node.tag/capture/port/node.tag/node.def
new file mode 100644
index 0000000..8029ba2
--- /dev/null
+++ b/templates/show/interfaces/bonding/node.tag/capture/port/node.tag/node.def
@@ -0,0 +1,3 @@
+help: Show captured traffic on specified bonding interface
+run: /opt/vyatta/bin/vyatta-tshark-interface-port.pl "$4" "$7" 0
+allowed: echo -n '<1-65535>'
diff --git a/templates/show/interfaces/bonding/node.tag/node.def b/templates/show/interfaces/bonding/node.tag/node.def
new file mode 100644
index 0000000..0cf4016
--- /dev/null
+++ b/templates/show/interfaces/bonding/node.tag/node.def
@@ -0,0 +1,7 @@
+help: Show specified bonding interface information
+allowed: for dev in /sys/class/net/*;
+ do if [[ -d $dev/bonding ]]
+ then echo -n ${dev##*/} " "
+ fi
+ done
+run: ${vyatta_bindir}/vyatta-show-bonding.pl "$4"
diff --git a/templates/show/interfaces/bonding/node.tag/vif/node.def b/templates/show/interfaces/bonding/node.tag/vif/node.def
new file mode 100644
index 0000000..2b74427
--- /dev/null
+++ b/templates/show/interfaces/bonding/node.tag/vif/node.def
@@ -0,0 +1,4 @@
+help: Show specified virtual network interface (vif) information
+run: tput setaf ${COLOR_RED:-1} ;
+ echo error: need to supply vif # ;
+ tput op
diff --git a/templates/show/interfaces/bonding/node.tag/vif/node.tag/brief/node.def b/templates/show/interfaces/bonding/node.tag/vif/node.tag/brief/node.def
new file mode 100644
index 0000000..7aa871e
--- /dev/null
+++ b/templates/show/interfaces/bonding/node.tag/vif/node.tag/brief/node.def
@@ -0,0 +1,2 @@
+help: Show summary of specified virtual network interface (vif) information
+run: ${vyatta_bindir}/vyatta-show-interfaces.pl --intf="$4.$6" --action=show-brief
diff --git a/templates/show/interfaces/bonding/node.tag/vif/node.tag/capture/node.def b/templates/show/interfaces/bonding/node.tag/vif/node.tag/capture/node.def
new file mode 100644
index 0000000..4fb959c
--- /dev/null
+++ b/templates/show/interfaces/bonding/node.tag/vif/node.tag/capture/node.def
@@ -0,0 +1,2 @@
+help: Show captured traffic on specified bonding interface
+run: /opt/vyatta/bin/vyatta-tshark-interface-port.pl "$4.$6"
diff --git a/templates/show/interfaces/bonding/node.tag/vif/node.tag/capture/not/node.def b/templates/show/interfaces/bonding/node.tag/vif/node.tag/capture/not/node.def
new file mode 100644
index 0000000..aef8d8b
--- /dev/null
+++ b/templates/show/interfaces/bonding/node.tag/vif/node.tag/capture/not/node.def
@@ -0,0 +1 @@
+help: Show captured traffic excluding the specified bonding virtual interface port
diff --git a/templates/show/interfaces/bonding/node.tag/vif/node.tag/capture/not/port/node.def b/templates/show/interfaces/bonding/node.tag/vif/node.tag/capture/not/port/node.def
new file mode 100644
index 0000000..5896bc8
--- /dev/null
+++ b/templates/show/interfaces/bonding/node.tag/vif/node.tag/capture/not/port/node.def
@@ -0,0 +1 @@
+help: Show captured traffic excluding the specified bonding interface
diff --git a/templates/show/interfaces/bonding/node.tag/vif/node.tag/capture/not/port/node.tag/node.def b/templates/show/interfaces/bonding/node.tag/vif/node.tag/capture/not/port/node.tag/node.def
new file mode 100644
index 0000000..7e62321
--- /dev/null
+++ b/templates/show/interfaces/bonding/node.tag/vif/node.tag/capture/not/port/node.tag/node.def
@@ -0,0 +1,3 @@
+help: Show captured traffic excluding the specified bonding interface
+run: /opt/vyatta/bin/vyatta-tshark-interface-port.pl "$4.$6" "${10}" 1
+allowed: echo -n '<1-65535>'
diff --git a/templates/show/interfaces/bonding/node.tag/vif/node.tag/capture/port/node.def b/templates/show/interfaces/bonding/node.tag/vif/node.tag/capture/port/node.def
new file mode 100644
index 0000000..0870adc
--- /dev/null
+++ b/templates/show/interfaces/bonding/node.tag/vif/node.tag/capture/port/node.def
@@ -0,0 +1 @@
+help: Show captured traffic on specified bonding interface
diff --git a/templates/show/interfaces/bonding/node.tag/vif/node.tag/capture/port/node.tag/node.def b/templates/show/interfaces/bonding/node.tag/vif/node.tag/capture/port/node.tag/node.def
new file mode 100644
index 0000000..a9a13cf
--- /dev/null
+++ b/templates/show/interfaces/bonding/node.tag/vif/node.tag/capture/port/node.tag/node.def
@@ -0,0 +1,3 @@
+help: Show captured traffic on specified bonding interface
+run: /opt/vyatta/bin/vyatta-tshark-interface-port.pl "$4.$6" "$9" 0
+allowed: echo -n '<1-65535>'
diff --git a/templates/show/interfaces/bonding/node.tag/vif/node.tag/node.def b/templates/show/interfaces/bonding/node.tag/vif/node.tag/node.def
new file mode 100644
index 0000000..52bfbee
--- /dev/null
+++ b/templates/show/interfaces/bonding/node.tag/vif/node.tag/node.def
@@ -0,0 +1,5 @@
+help: Show specified virtual network interface (vif) information
+allowed: local -a array ;
+ array=( /sys/class/net/${COMP_WORDS[3]}.* ) ;
+ echo -n ${array[@]##*.}
+run: ${vyatta_bindir}/vyatta-show-interfaces.pl --intf="$4.$6"