Info/Layer3/CiscoASA.pm untested

filter: Statementstmt 0.0% 0 / 55 Branchbran 0.0% 0 / 14 Conditioncond 0.0% 0 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 0.0% 0 / 9 Podpod 0.0% 0 / 4 totaltotal 0.0% 0 / 85 CC 8 SCAR 28.9
CC
8
Cov
0%
parse_inetaddress
42.0
b_mac
6.0
i_description
6.0
CRAP 18.0
1 # SNMP::Info::Layer3::CiscoASA
2 #
3 # Copyright (c) 2013 Moe Kraus
4 # All rights reserved.
5 #
6 # Redistribution and use in source and binary forms, with or without
7 # modification, are permitted provided that the following conditions are met:
8 #
9 # * Redistributions of source code must retain the above copyright notice,
10 # this list of conditions and the following disclaimer.
11 # * Redistributions in binary form must reproduce the above copyright
12 # notice, this list of conditions and the following disclaimer in the
13 # documentation and/or other materials provided with the distribution.
14 # * Neither the name of the University of California, Santa Cruz nor the
15 # names of its contributors may be used to endorse or promote products
16 # derived from this software without specific prior written permission.
17 #
18 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
22 # LIABLE FOR
23 # ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 # POSSIBILITY OF SUCH DAMAGE.
30  
31 package SNMP::Info::Layer3::CiscoASA;
32  
33 use strict;
34 use warnings;
35 use Exporter;
36 use SNMP::Info::CiscoStats;
37 use SNMP::Info::Layer3;
38  
39 @SNMP::Info::Layer3::CiscoASA::ISA = qw/
40 SNMP::Info::CiscoStats
41 SNMP::Info::Layer3
42 Exporter/;
43 @SNMP::Info::Layer3::CiscoASA::EXPORT_OK = qw//;
44  
45 our ($VERSION, %GLOBALS, %MIBS, %FUNCS, %MUNGE);
46  
47 $VERSION = '3.985003';
48  
49 %MIBS = ( %SNMP::Info::Layer3::MIBS, %SNMP::Info::CiscoStats::MIBS, );
50  
51 %GLOBALS
52 = ( %SNMP::Info::Layer3::GLOBALS, %SNMP::Info::CiscoStats::GLOBALS, );
53  
54 %FUNCS = (
55 %SNMP::Info::Layer3::FUNCS,
56 %SNMP::Info::CiscoStats::FUNCS,
57 'mac_table' => 'ifPhysAddress',
58 );
59  
60 %MUNGE = (
61 %SNMP::Info::Layer3::MUNGE,
62 %SNMP::Info::CiscoStats::MUNGE,
63 'mac_table' => \&SNMP::Info::munge_mac,
64 );
65  
66 sub b_mac {
67 my ($asa) = shift;
68 my $macs = $asa->mac_table();
69 my @macs;
70  
71 # gather physical addresses
72 foreach my $i ( keys %$macs ) {
73 my $mac = $macs->{$i};
74  
75 # don't catch the bad macs with bogus OUI
76 if ( $mac !~ m/(0{1,2}:){2}(00|01)/ ) {
77 push( @macs, $mac );
78 }
79 @macs = sort(@macs);
80 }
81  
82 # return the least mac
83 return $macs[0];
84 }
85  
86 sub i_description {
87 my $self = shift;
88 my $partial = shift;
89  
90 my $i_descr = $self->orig_i_description($partial) || {};
91  
92 foreach my $ifindex ( keys %$i_descr ) {
93 $i_descr->{$ifindex} = $1
94 if $i_descr->{$ifindex} =~ /'(.*)'/;
95 }
96  
97 return $i_descr;
98 }
99  
100 sub parse_inetaddress {
101 my ($info, $inetaddress) = @_;
102 my @parts = split(/\./, $inetaddress);
103 # first part is the InetAddressType
104 my $addrtype = shift @parts;
105 # second part should be the number of octets but is missing on Cisco ASA
106 # InetAddressIPv4
107 if ($addrtype == 1) {
108 my @ipv4 = @parts[0..3];
109 return {
110 type => $addrtype,
111 address => join('.', @ipv4),
112 };
113 }
114 # InetAddressIPv6
115 if ($addrtype == 2) {
116 my @ipv6 = @parts[0..15];
117 return {
118 type => $addrtype,
119 address => join(':', unpack('(H4)*', pack('C*', @ipv6))),
120 };
121 }
122 # InetAddressIPv4z
123 elsif ($addrtype == 3) {
124 my @ipv4 = @parts[0..3];
125 return {
126 type => $addrtype,
127 address => join('.', @ipv4),
128 };
129 }
130 # InetAddressIPv6z
131 elsif ($addrtype == 4) {
132 my @ipv6 = @parts[0..15];
133 return {
134 type => $addrtype,
135 address => join(':', unpack('(H4)*', pack('C*', @ipv6))),
136 };
137 }
138 elsif ($info->debug()) {
139 print("unsupported address type '$addrtype'\n");
140 }
141  
142 return;
143 }
144  
145 # IPV6-MIB rows are keyed with an octet count, which parse_inetaddress()
146 # above would misread.
147 sub _i6_addr_column { return }
148  
149 1;
150 __END__