| 1 | # SNMP::Info::Layer3::CiscoFWSM | ||
| 2 | # | ||
| 3 | # Copyright (c) 2010 Brian De Wolf | ||
| 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 # ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
| 23 | # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
| 24 | # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
| 25 | # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||
| 26 | # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
| 27 | # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
| 28 | # POSSIBILITY OF SUCH DAMAGE. | ||
| 29 | |||
| 30 | package SNMP::Info::Layer3::CiscoFWSM; | ||
| 31 | |||
| 32 | use strict; | ||
| 33 | use warnings; | ||
| 34 | use Exporter; | ||
| 35 | use SNMP::Info::CiscoStats; | ||
| 36 | use SNMP::Info::Layer3; | ||
| 37 | |||
| 38 | @SNMP::Info::Layer3::CiscoFWSM::ISA = qw/SNMP::Info::CiscoStats | ||
| 39 | SNMP::Info::Layer3 | ||
| 40 | Exporter/; | ||
| 41 | @SNMP::Info::Layer3::CiscoFWSM::EXPORT_OK = qw//; | ||
| 42 | |||
| 43 | our ($VERSION, %GLOBALS, %MIBS, %FUNCS, %MUNGE); | ||
| 44 | |||
| 45 | $VERSION = '3.985003'; | ||
| 46 | |||
| 47 | %MIBS = ( %SNMP::Info::Layer3::MIBS, %SNMP::Info::CiscoStats::MIBS, ); | ||
| 48 | |||
| 49 | %GLOBALS | ||
| 50 | = ( %SNMP::Info::Layer3::GLOBALS, %SNMP::Info::CiscoStats::GLOBALS, ); | ||
| 51 | |||
| 52 | %FUNCS = ( | ||
| 53 | %SNMP::Info::Layer3::FUNCS, | ||
| 54 | %SNMP::Info::CiscoStats::FUNCS, | ||
| 55 | ); | ||
| 56 | |||
| 57 | %MUNGE = ( %SNMP::Info::Layer3::MUNGE, %SNMP::Info::CiscoStats::MUNGE, ); | ||
| 58 | |||
| 59 | # For FWSMs, the ipNetToPhysicalPhysAddress table appears to be of the form: | ||
| 60 | # $ifindex.$inetaddresstype.$proto.$ip_address -> $mac_address | ||
| 61 | # | ||
| 62 | # Using the output of ipNetToPhysicalPhysAddress, we can emulate the other | ||
| 63 | # functions. | ||
| 64 | # | ||
| 65 | # This doesn't really line up to what at_* return, so we munge it | ||
| 66 | |||
| 67 | sub at_paddr { | ||
| 68 | my ($fwsm) = shift; | ||
| 69 | my ($partial) = shift; | ||
| 70 | |||
| 71 | my $paddrs = $fwsm->n2p_paddr($partial); | ||
| 72 | my $n_paddrs = {}; | ||
| 73 | |||
| 74 | foreach my $key ( keys %$paddrs ) { | ||
| 75 | my $paddr = $paddrs->{$key}; | ||
| 76 | my @parts = split /\./, $key; | ||
| 77 | my ( $ifindex, $addrtype, $proto ) = splice @parts, 0, 3; | ||
| 78 | my $ip = join ".", @parts; | ||
| 79 | |||
| 80 | next if ( $proto != 4 ); # at_paddr doesn't support non-IPv4 | ||
| 81 | |||
| 82 | $n_paddrs->{"$ifindex.$ip"} = $paddr; | ||
| 83 | } | ||
| 84 | return $n_paddrs; | ||
| 85 | } | ||
| 86 | |||
| 87 | sub at_netaddr { | ||
| 88 | my ($fwsm) = shift; | ||
| 89 | my ($partial) = shift; | ||
| 90 | |||
| 91 | my $paddrs = $fwsm->n2p_paddr($partial); | ||
| 92 | |||
| 93 | my $netaddrs = {}; | ||
| 94 | |||
| 95 | foreach my $key ( keys %$paddrs ) { | ||
| 96 | my $paddr = $paddrs->{$key}; | ||
| 97 | my @parts = split /\./, $key; | ||
| 98 | my ( $ifindex, $addrtype, $proto ) = splice @parts, 0, 3; | ||
| 99 | my $ip = join ".", @parts; | ||
| 100 | |||
| 101 | next if ( $proto != 4 ); # at_netaddr doesn't support non-IPv4 | ||
| 102 | |||
| 103 | $netaddrs->{"$ifindex.$ip"} = $ip; | ||
| 104 | } | ||
| 105 | return $netaddrs; | ||
| 106 | } | ||
| 107 | |||
| 108 | sub at_ifaddr { | ||
| 109 | my ($fwsm) = shift; | ||
| 110 | my ($partial) = shift; | ||
| 111 | |||
| 112 | my $paddrs = $fwsm->n2p_paddr($partial); | ||
| 113 | |||
| 114 | my $ifaddrs = {}; | ||
| 115 | |||
| 116 | foreach my $key ( keys %$paddrs ) { | ||
| 117 | my $paddr = $paddrs->{$key}; | ||
| 118 | my @parts = split /\./, $key; | ||
| 119 | my ( $ifindex, $addrtype, $proto ) = splice @parts, 0, 3; | ||
| 120 | my $ip = join ".", @parts; | ||
| 121 | |||
| 122 | next if ( $proto != 4 ); # at_ifaddr doesn't support non-IPv4 | ||
| 123 | |||
| 124 | $ifaddrs->{"$ifindex.$ip"} = $ip; | ||
| 125 | } | ||
| 126 | return $ifaddrs; | ||
| 127 | } | ||
| 128 | |||
| 129 | 1; | ||
| 130 | __END__ |