diff options
-rw-r--r-- | debian/changelog | 15 | ||||
-rw-r--r-- | lib/Vyatta/Interface.pm | 20 | ||||
-rwxr-xr-x | lib/Vyatta/Misc.pm | 45 | ||||
-rw-r--r-- | tests/interface.pl | 2 |
4 files changed, 47 insertions, 35 deletions
diff --git a/debian/changelog b/debian/changelog index e2fb4e4..4149cb9 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,18 @@ +vyatta-cfg (0.14.30) unstable; urgency=low + + [ slioch ] + * fixed preservation of def file when committing configuration. + default leafs + + [ Stig Thormodsrud ] + * Remove duplicate constants. + * When an IP address is configured on a loopback, + getInterfacesIPadresses('all') doesn't include them. Include + loopback addresses. + * Add loopback as a type for getInterfacesIPadresses(). + + -- Stig Thormodsrud <stig@io.vyatta.com> Mon, 02 Mar 2009 15:53:28 -0800 + vyatta-cfg (0.14.29) unstable; urgency=low * Fix call to Vyatta::Misc::getIP() 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..fad3eb2 100755 --- a/lib/Vyatta/Misc.pm +++ b/lib/Vyatta/Misc.pm @@ -122,58 +122,35 @@ 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', + 'loopback' => 'is_loopback', ); # getInterfacesIPadresses() returns IPv4 addresses for the interface type -# possible type of interfaces : 'broadcast', 'pointopoint', 'multicast', 'all' -# the loopback IP address is never returned with any of the above parameters +# possible type of interfaces : 'broadcast', 'pointtopoint', 'multicast', 'all' +# and 'loopback' 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; + if (defined $type_func) { + next unless $intf->$type_func(); } my @addresses = $intf->address(4); diff --git a/tests/interface.pl b/tests/interface.pl index 86ec96e..9ebeb60 100644 --- a/tests/interface.pl +++ b/tests/interface.pl @@ -13,7 +13,7 @@ my @interfaces = getInterfaces(); print "Interfaces: ", join(' ',@interfaces),"\n"; print "IP\n"; -foreach my $type (qw/all broadcast multicast pointtopoint/) { +foreach my $type (qw/all broadcast multicast pointtopoint loopback/) { print "\t$type = "; foreach my $addr (Vyatta::Misc::getInterfacesIPadresses($type)) { print $addr, '(', is_ip_v4_or_v6($addr), ') '; |