summaryrefslogtreecommitdiff
path: root/lib/Vyatta/Interface.pm
diff options
context:
space:
mode:
authorStephen Hemminger <stephen.hemminger@vyatta.com>2009-01-12 18:16:37 -0800
committerStephen Hemminger <stephen.hemminger@vyatta.com>2009-01-12 18:16:37 -0800
commitc368665647b9ac72efc161c6e291cba8c3674628 (patch)
tree8bb0073da537f2ecd41ebcb17ddc1b04d16de738 /lib/Vyatta/Interface.pm
parentab1ede4439fa63a44de6b2e0db5e6df5ba495df1 (diff)
downloadvyatta-cfg-c368665647b9ac72efc161c6e291cba8c3674628.tar.gz
vyatta-cfg-c368665647b9ac72efc161c6e291cba8c3674628.zip
Better version of getIPadresses and getInterfacesdebian/0.14.2
Use new Vyatta::Interface and sysfs to avoid using ifconfig and ip command unnecessarily.
Diffstat (limited to 'lib/Vyatta/Interface.pm')
-rw-r--r--lib/Vyatta/Interface.pm32
1 files changed, 27 insertions, 5 deletions
diff --git a/lib/Vyatta/Interface.pm b/lib/Vyatta/Interface.pm
index cce703a..ead45fd 100644
--- a/lib/Vyatta/Interface.pm
+++ b/lib/Vyatta/Interface.pm
@@ -22,10 +22,32 @@ package Vyatta::Interface;
use strict;
use warnings;
use Vyatta::Config;
+use base 'Exporter';
+our @EXPORT = qw(IFF_UP IFF_BROADCAST IFF_DEBUG IFF_LOOPBACK
+ IFF_POINTOPOINT IFF_RUNNING IFF_NOARP
+ IFF_PROMISC IFF_MULTICAST);
+
use constant {
- IFF_UP => 0x1,
- IFF_RUNNING => 0x40,
+ IFF_UP => 0x1, # interface is up
+ IFF_BROADCAST => 0x2, # broadcast address valid
+ IFF_DEBUG => 0x4, # turn on debugging
+ IFF_LOOPBACK => 0x8, # is a loopback net
+ IFF_POINTOPOINT => 0x10, # interface is has p-p link
+ IFF_NOTRAILERS => 0x20, # avoid use of trailers
+ IFF_RUNNING => 0x40, # interface RFC2863 OPER_UP
+ IFF_NOARP => 0x80, # no ARP protocol
+ IFF_PROMISC => 0x100, # receive all packets
+ IFF_ALLMULTI => 0x200, # receive all multicast packets
+ IFF_MASTER => 0x400, # master of a load balancer
+ IFF_SLAVE => 0x800, # slave of a load balancer
+ IFF_MULTICAST => 0x1000, # Supports multicast
+ IFF_PORTSEL => 0x2000, # can set media type
+ IFF_AUTOMEDIA => 0x4000, # auto media select active
+ IFF_DYNAMIC => 0x8000, # dialup device with changing addresses
+ IFF_LOWER_UP => 0x10000, # driver signals L1 up
+ IFF_DORMANT => 0x20000, # driver signals dormant
+ IFF_ECHO => 0x40000, # echo sent packets
};
my %net_prefix = (
@@ -178,7 +200,7 @@ sub exists {
return ( -d "/sys/class/net/$self->{name}" );
}
-sub _flags {
+sub flags {
my $self = shift;
open my $flags, '<', "/sys/class/net/$self->{name}/flags"
@@ -193,7 +215,7 @@ sub _flags {
# device exists and is online
sub up {
my $self = shift;
- my $flags = $self->_flags();
+ my $flags = $self->flags();
return $flags && ( $flags & IFF_UP );
}
@@ -201,7 +223,7 @@ sub up {
# device exists and is running (ie carrier present)
sub running {
my $self = shift;
- my $flags = $self->_flags();
+ my $flags = $self->flags();
return $flags && ( $flags & IFF_RUNNING );
}