summaryrefslogtreecommitdiff
path: root/lib/Vyatta/Interface.pm
diff options
context:
space:
mode:
authorStephen Hemminger <stephen.hemminger@vyatta.com>2009-01-12 15:48:44 -0800
committerStephen Hemminger <stephen.hemminger@vyatta.com>2009-01-12 16:35:54 -0800
commit80f85801b57a030459cb6846bb229ca87d18cc5a (patch)
tree906ddae03b96176a50856153483d6e3a78eb3f86 /lib/Vyatta/Interface.pm
parente12098cc7b7d44636a78e4d69983590a528438b5 (diff)
downloadvyatta-cfg-80f85801b57a030459cb6846bb229ca87d18cc5a.tar.gz
vyatta-cfg-80f85801b57a030459cb6846bb229ca87d18cc5a.zip
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.
Diffstat (limited to 'lib/Vyatta/Interface.pm')
-rw-r--r--lib/Vyatta/Interface.pm27
1 files changed, 18 insertions, 9 deletions
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;