From 80f85801b57a030459cb6846bb229ca87d18cc5a Mon Sep 17 00:00:00 2001 From: Stephen Hemminger Date: Mon, 12 Jan 2009 15:48:44 -0800 Subject: Use new interfaces routines Unify all code that does name -> interface attribute translation into one place. No need to pass interface path to scripts, and handle addresses correctly in DHCP code. Use 'undef' consitently for false in perl code. --- lib/Vyatta/Interface.pm | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) (limited to 'lib/Vyatta/Interface.pm') diff --git a/lib/Vyatta/Interface.pm b/lib/Vyatta/Interface.pm index e71aacb..cce703a 100644 --- a/lib/Vyatta/Interface.pm +++ b/lib/Vyatta/Interface.pm @@ -138,7 +138,7 @@ sub mtu { return $config->returnValue("mtu"); } -sub dhcp { +sub using_dhcp { my $self = shift; my $config = new Vyatta::Config; $config->setLevel( $self->{path} ); @@ -149,20 +149,29 @@ sub dhcp { return $addr[0]; } -# return array of static address (if any) +## System checks + +# return array of current addresses (on system) sub address { my $self = shift; - my $config = new Vyatta::Config; - $config->setLevel( $self->{path} ); - my @addr = grep { $_ ne 'dhcp' } $config->returnOrigValues('address'); + open my $ipcmd, "ip addr show dev $self->{name} |" + or die "ip addr command failed: $!"; - return @addr if (wantarray); - return if ($#addr < 0); - return $addr[0]; + my @addresses; + <$ipcmd>; + while (<$ipcmd>) { + my ($proto, $addr) = split; + next unless ($proto =~ /inet/); + push @addresses, $addr; + } + close $ipcmd; + + return @addresses; } -## System checks +# return + sub exists { my $self = shift; -- cgit v1.2.3