From 80a924e8b4033109b6fa23ceb9811a083c7345e8 Mon Sep 17 00:00:00 2001 From: Stephen Hemminger Date: Mon, 8 Nov 2010 11:42:05 -0800 Subject: Don't produce warnings for drivers that don't support ethtool Bug 5552 For devices like Xen that don't do ethtool speed/duplex, allow auto to work but produce error for any other value. --- scripts/vyatta-interfaces.pl | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/scripts/vyatta-interfaces.pl b/scripts/vyatta-interfaces.pl index c8d6f263..982cf0ee 100755 --- a/scripts/vyatta-interfaces.pl +++ b/scripts/vyatta-interfaces.pl @@ -571,10 +571,11 @@ sub show_interfaces { print join(' ', @match), "\n"; } +# Determine current values for speed, duplex and autonegotiation sub get_ethtool { my $dev = shift; - open( my $ethtool, "-|", "$ETHTOOL $dev 2>/dev/null" ) + open( my $ethtool, '-|', "$ETHTOOL $dev 2>&1" ) or die "ethtool failed: $!\n"; # ethtool produces: @@ -589,6 +590,8 @@ sub get_ethtool { my ($rate, $duplex, $autoneg); while (<$ethtool>) { chomp; + return if ( /^Cannot get device settings/ ); + if ( /^\s+Speed: ([0-9]+)Mb\/s|^\s+Speed: (Unknown)/ ) { $rate = $1; } elsif ( /^\s+Duplex:\s(.*)$/ ) { @@ -606,7 +609,16 @@ sub set_speed_duplex { die "Missing --dev argument\n" unless $intf; my ($ospeed, $oduplex, $autoneg) = get_ethtool($intf); - if ($ospeed) { + + # Some devices do not support speed/duplex + unless (defined($ospeed)) { + die "$intf: does not support speed/duplex selection\n" + if ($nspeed ne 'auto' || $nduplex ne 'auto'); + return; + } + + # Check if already the correct settings to avoid flapping link + if ($ospeed ne 'Unknown') { if ($autoneg) { # Device is in autonegotiation mode return if ($nspeed eq 'auto'); -- cgit v1.2.3