diff options
author | Stephen Hemminger <stephen.hemminger@vyatta.com> | 2011-08-05 20:54:06 -0700 |
---|---|---|
committer | Stephen Hemminger <stephen.hemminger@vyatta.com> | 2011-08-05 20:54:06 -0700 |
commit | a128ba95095178dd268e382982e5c7f857b7e038 (patch) | |
tree | 135351c5628b3b16851758ad6c1a06b8959eb6c2 | |
parent | 5c9468830faaad8976bf9739d250363aef171f40 (diff) | |
parent | 8b49f93b06cfe494182c533dc00499abc8452660 (diff) | |
download | vyatta-cfg-system-a128ba95095178dd268e382982e5c7f857b7e038.tar.gz vyatta-cfg-system-a128ba95095178dd268e382982e5c7f857b7e038.zip |
Merge branch 'oxnard' of nehalam:vyatta/oxnard/vyatta-cfg-system into oxnard
-rwxr-xr-x | scripts/vyatta-interfaces.pl | 39 | ||||
-rw-r--r-- | 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 |