From 8b49f93b06cfe494182c533dc00499abc8452660 Mon Sep 17 00:00:00 2001 From: Stephen Hemminger Date: Fri, 5 Aug 2011 20:51:06 -0700 Subject: ethernet: avoid needlessly setting mac address Bug 7408 Only set mac address if it is different, and try first with link up (many drivers allow it). Don't use hw-id as mac address, hw-id is meant for corelating names with addresses (in udev). --- scripts/vyatta-interfaces.pl | 39 +++++++++++++++++----------------- templates/interfaces/ethernet/node.def | 11 +++------- 2 files changed, 23 insertions(+), 27 deletions(-) diff --git a/scripts/vyatta-interfaces.pl b/scripts/vyatta-interfaces.pl index a5bb2553..0365266c 100755 --- a/scripts/vyatta-interfaces.pl +++ b/scripts/vyatta-interfaces.pl @@ -39,7 +39,6 @@ use Vyatta::File qw(touch); use Vyatta::Interface; use Getopt::Long; -use POSIX; use strict; use warnings; @@ -225,27 +224,29 @@ sub stop_dhclient { } sub update_mac { - my ($mac, $intf) = @_; + my ($mac, $name) = @_; + my $intf = new Vyatta::Interface($name); + $intf or die "Unknown interface name/type: $name\n"; - open my $fh, "<", "/sys/class/net/$intf/flags" - or die "Error: $intf is not a network device\n"; - - my $flags = <$fh>; - chomp $flags; - close $fh or die "Error: can't read state\n"; - - if (POSIX::strtoul($flags) & 1) { - # NB: Perl 5 system return value is bass-ackwards - system "ip link set $intf down" - and die "Could not set $intf down ($!)\n"; - system "ip link set $intf address $mac" - and die "Could not set $intf address ($!)\n"; - system "ip link set $intf up" - and die "Could not set $intf up ($!)\n"; + # maybe nothing needs to change + my $oldmac = $intf->hw_address(); + exit 0 if (lc($oldmac) eq lc($mac)); + + # try the direct approach + if (system "ip link set $name address $mac" == 0) { + exit 0; + } elsif ($intf->up()) { + # some hardware can not change MAC address if up + system "ip link set $name down" + and die "Could not set $name down\n"; + system "ip link set $name address $mac" + and die "Could not set $name address\n"; + system "ip link set $name up" + and die "Could not set $name up\n"; } else { - system "ip link set $intf address $mac" - and die "Could not set $intf address ($!)\n"; + die "Could not set mac address for $name\n"; } + exit 0; } diff --git a/templates/interfaces/ethernet/node.def b/templates/interfaces/ethernet/node.def index a9113e7a..426f8f87 100644 --- a/templates/interfaces/ethernet/node.def +++ b/templates/interfaces/ethernet/node.def @@ -14,15 +14,10 @@ syntax:expression: exec \ fi" begin: rm -f /tmp/speed-duplex.$VAR(@) - if [ -d "/sys/class/net/$VAR(@)" ]; then - s_mac="$VAR(hw-id/@)" - if [ -n "$VAR(mac/@)" ]; then - s_mac="$VAR(mac/@)" - fi - if [ -n "$s_mac" ]; then + if [ -n "$VAR(mac/@)" ] && + [ -d "/sys/class/net/$VAR(@)" ]; then /opt/vyatta/sbin/vyatta-interfaces.pl --dev $VAR(@) \ - --set-mac $s_mac - fi + --set-mac "$VAR(mac/@)" fi create: ip link set "$VAR(@)" up -- cgit v1.2.3 From 68692d40c6e1e0faefc8cfe0226f68332ff9207b Mon Sep 17 00:00:00 2001 From: Stephen Hemminger Date: Fri, 5 Aug 2011 20:55:41 -0700 Subject: 0.19.107 --- debian/changelog | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/debian/changelog b/debian/changelog index a7b07c9a..c5b52a50 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,9 @@ +vyatta-cfg-system (0.19.107) unstable; urgency=low + + * ethernet: avoid needlessly setting mac address + + -- Stephen Hemminger Fri, 05 Aug 2011 20:55:41 -0700 + vyatta-cfg-system (0.19.106) unstable; urgency=low * Added to make "force" op-mode command accessible to user type -- cgit v1.2.3 From 212625fe726db86d896003c8d926d4b0ccb54ab9 Mon Sep 17 00:00:00 2001 From: Stephen Hemminger Date: Sun, 7 Aug 2011 20:41:29 -0700 Subject: Force dependency on later vyatta-cfg package Since the code here now refers to is_uniq_address, current of this package needs to depend on the matching vyatta-cfg. --- debian/control | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/debian/control b/debian/control index b9b6eb52..c917da9d 100644 --- a/debian/control +++ b/debian/control @@ -15,7 +15,7 @@ Depends: acpid, procps (>= 1:3.2.7-3), coreutils (>= 5.97-5.3), libpam-radius-auth, - vyatta-cfg (>= 0.18.58), + vyatta-cfg (>= 0.99.8) libc6 (>= 2.7-6), libpam-runtime (>= 1.0.1-5), vyatta-bash | bash (>= 3.1), -- cgit v1.2.3 From 03f2844131b85dea67bfc98634eaff3345c0c073 Mon Sep 17 00:00:00 2001 From: Stephen Hemminger Date: Sun, 7 Aug 2011 20:42:34 -0700 Subject: 0.19.108 --- debian/changelog | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/debian/changelog b/debian/changelog index c5b52a50..760433a9 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,9 @@ +vyatta-cfg-system (0.19.108) unstable; urgency=low + + * Force dependency on later vyatta-cfg package + + -- Stephen Hemminger Sun, 07 Aug 2011 20:42:34 -0700 + vyatta-cfg-system (0.19.107) unstable; urgency=low * ethernet: avoid needlessly setting mac address -- cgit v1.2.3 From ef2988e739b3e9771ac249b627145a504f91364e Mon Sep 17 00:00:00 2001 From: Stephen Hemminger Date: Sun, 7 Aug 2011 20:45:23 -0700 Subject: 0.19.108 --- debian/changelog | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/debian/changelog b/debian/changelog index 760433a9..2b778fe0 100644 --- a/debian/changelog +++ b/debian/changelog @@ -2,7 +2,7 @@ vyatta-cfg-system (0.19.108) unstable; urgency=low * Force dependency on later vyatta-cfg package - -- Stephen Hemminger Sun, 07 Aug 2011 20:42:34 -0700 + -- Stephen Hemminger Sun, 07 Aug 2011 20:45:23 -0700 vyatta-cfg-system (0.19.107) unstable; urgency=low -- cgit v1.2.3 From a7a95c217320ecb37cb9a47849c7609203f1695c Mon Sep 17 00:00:00 2001 From: Stephen Hemminger Date: Sun, 7 Aug 2011 20:46:02 -0700 Subject: fix missing command in debian/control --- debian/control | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/debian/control b/debian/control index c917da9d..0b06b260 100644 --- a/debian/control +++ b/debian/control @@ -15,7 +15,7 @@ Depends: acpid, procps (>= 1:3.2.7-3), coreutils (>= 5.97-5.3), libpam-radius-auth, - vyatta-cfg (>= 0.99.8) + vyatta-cfg (>= 0.99.8), libc6 (>= 2.7-6), libpam-runtime (>= 1.0.1-5), vyatta-bash | bash (>= 3.1), -- cgit v1.2.3 From 08615f465009878cf977f27d72ad1a9d3c8fb80e Mon Sep 17 00:00:00 2001 From: Stephen Hemminger Date: Sun, 7 Aug 2011 20:46:26 -0700 Subject: 0.19.109 --- debian/changelog | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/debian/changelog b/debian/changelog index 2b778fe0..1ac5eb5d 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,10 @@ +vyatta-cfg-system (0.19.109) unstable; urgency=low + + * 0.19.108 + * fix missing command in debian/control + + -- Stephen Hemminger Sun, 07 Aug 2011 20:46:26 -0700 + vyatta-cfg-system (0.19.108) unstable; urgency=low * Force dependency on later vyatta-cfg package -- cgit v1.2.3