diff options
author | Stig Thormodsrud <stig@io.vyatta.com> | 2009-03-02 15:33:40 -0800 |
---|---|---|
committer | Stig Thormodsrud <stig@io.vyatta.com> | 2009-03-02 15:33:40 -0800 |
commit | 863b6c71f0cc802809db61843dff99af0efd0999 (patch) | |
tree | be7fed78b6f122229e7bbb911b13748c59664149 /lib | |
parent | f99deef50eda86d063338c92ceed768b5578fb0b (diff) | |
download | vyatta-cfg-863b6c71f0cc802809db61843dff99af0efd0999.tar.gz vyatta-cfg-863b6c71f0cc802809db61843dff99af0efd0999.zip |
Remove duplicate constants.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Vyatta/Interface.pm | 20 | ||||
-rwxr-xr-x | lib/Vyatta/Misc.pm | 41 |
2 files changed, 29 insertions, 32 deletions
diff --git a/lib/Vyatta/Interface.pm b/lib/Vyatta/Interface.pm index 73b8c6b..f83f58f 100644 --- a/lib/Vyatta/Interface.pm +++ b/lib/Vyatta/Interface.pm @@ -216,6 +216,26 @@ sub flags { return hex($val); } +sub is_broadcast { + my $self = shift; + return $self->flags() & IFF_BROADCAST; +} + +sub is_multicast { + my $self = shift; + return $self->flags() & IFF_MULTICAST; +} + +sub is_pointtopoint { + my $self = shift; + return $self->flags() & IFF_POINTOPOINT; +} + +sub is_loopback { + my $self = shift; + return $self->flags() & IFF_LOOPBACK; +} + # device exists and is online sub up { my $self = shift; diff --git a/lib/Vyatta/Misc.pm b/lib/Vyatta/Misc.pm index 9140d4c..57c2ac2 100755 --- a/lib/Vyatta/Misc.pm +++ b/lib/Vyatta/Misc.pm @@ -122,32 +122,11 @@ sub getIP { return @addresses; } -use constant { - 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 %type_hash = ( - 'broadcast' => IFF_BROADCAST, - 'multicast' => IFF_MULTICAST, - 'pointtopoint' => IFF_POINTOPOINT, + 'broadcast' => 'is_broadcast', + 'multicast' => 'is_multicast', + 'pointtopoint' => 'is_pointtopoint', ); # getInterfacesIPadresses() returns IPv4 addresses for the interface type @@ -155,25 +134,23 @@ my %type_hash = ( # the loopback IP address is never returned with any of the above parameters sub getInterfacesIPadresses { my $type = shift; - my $mask; + my $type_func; my @ips; $type or die "Interface type not defined"; if ($type ne 'all') { - $mask = $type_hash{$type}; + $type_func = $type_hash{$type}; die "Invalid type specified to retreive IP addresses for: $type" - unless $mask; + unless $type_func; } foreach my $name (getInterfaces()) { my $intf = new Vyatta::Interface($name); next unless $intf; - - my $flags = $intf->flags(); - next if ($flags & IFF_LOOPBACK); - if (defined $mask) { - next unless $flags & $mask; + next if $intf->loopback(); + if (defined $type_func) { + next unless $intf->$type_func(); } my @addresses = $intf->address(4); |