1 |
root |
1.1 |
=head1 NAME |
2 |
|
|
|
3 |
|
|
Net::SNMP::XS - speed up Net::SNMP by decoding in XS, with limitations |
4 |
|
|
|
5 |
|
|
=head1 SYNOPSIS |
6 |
|
|
|
7 |
|
|
use Net::SNMP::XS; |
8 |
|
|
|
9 |
|
|
# loading it is enough, there are no public symbols |
10 |
|
|
|
11 |
|
|
=head1 DESCRIPTION |
12 |
|
|
|
13 |
|
|
This module tries to speed up Net::SNMP response packet decoding. |
14 |
|
|
|
15 |
|
|
It does this by overriding a few selected internal method by (almost) |
16 |
|
|
equivalent XS methods. |
17 |
|
|
|
18 |
root |
1.5 |
This currently reduces decode time by a factor of ten for typical bulk |
19 |
root |
1.3 |
responses. |
20 |
root |
1.1 |
|
21 |
|
|
There are currently the following limitations when using this module: |
22 |
|
|
|
23 |
|
|
=over 4 |
24 |
|
|
|
25 |
root |
1.6 |
=item overriding internal functions might cause the module to |
26 |
|
|
malfunction with future versions of Net::SNMP |
27 |
|
|
|
28 |
root |
1.3 |
=item error messages will be simpler/different |
29 |
|
|
|
30 |
root |
1.1 |
=item translation will be ignored (all values will be delivered "raw") |
31 |
|
|
|
32 |
root |
1.2 |
=item a moderately modern (>= C99) C compiler is required |
33 |
|
|
|
34 |
root |
1.7 |
=item only tested with 5.10, no intentions to port to older perls |
35 |
root |
1.2 |
|
36 |
root |
1.5 |
=item duplicate OIDs are not supported |
37 |
|
|
|
38 |
|
|
=item REPORT PDUs are not supported |
39 |
|
|
|
40 |
root |
1.1 |
=back |
41 |
|
|
|
42 |
|
|
=cut |
43 |
|
|
|
44 |
|
|
package Net::SNMP::XS; |
45 |
|
|
|
46 |
|
|
use strict qw(vars subs); |
47 |
|
|
no warnings; |
48 |
|
|
|
49 |
|
|
use Guard; |
50 |
|
|
|
51 |
root |
1.8 |
use Net::SNMP (); |
52 |
root |
1.1 |
use Net::SNMP::PDU (); |
53 |
|
|
use Net::SNMP::Message (); |
54 |
|
|
use Net::SNMP::MessageProcessing (); |
55 |
|
|
|
56 |
|
|
our $VERSION; |
57 |
|
|
|
58 |
|
|
BEGIN { |
59 |
root |
1.14 |
$VERSION = 1.31; |
60 |
root |
1.1 |
|
61 |
root |
1.10 |
# this overrides many methods inside Net::SNMP and it's submodules |
62 |
root |
1.1 |
require XSLoader; |
63 |
|
|
XSLoader::load Net::SNMP::XS, $VERSION; |
64 |
|
|
} |
65 |
|
|
|
66 |
root |
1.8 |
package Net::SNMP::Message; |
67 |
|
|
|
68 |
|
|
Net::SNMP::XS::set_type INTEGER , \&_process_integer32; |
69 |
|
|
Net::SNMP::XS::set_type OCTET_STRING , \&_process_octet_string; |
70 |
|
|
Net::SNMP::XS::set_type NULL , \&_process_null; |
71 |
|
|
Net::SNMP::XS::set_type OBJECT_IDENTIFIER, \&_process_object_identifier; |
72 |
|
|
Net::SNMP::XS::set_type SEQUENCE , \&_process_sequence; |
73 |
|
|
Net::SNMP::XS::set_type IPADDRESS , \&_process_ipaddress; |
74 |
|
|
Net::SNMP::XS::set_type COUNTER , \&_process_counter; |
75 |
|
|
Net::SNMP::XS::set_type GAUGE , \&_process_gauge; |
76 |
|
|
Net::SNMP::XS::set_type TIMETICKS , \&_process_timeticks; |
77 |
|
|
Net::SNMP::XS::set_type OPAQUE , \&_process_opaque; |
78 |
|
|
Net::SNMP::XS::set_type COUNTER64 , \&_process_counter64; |
79 |
|
|
Net::SNMP::XS::set_type NOSUCHOBJECT , \&_process_nosuchobject; |
80 |
|
|
Net::SNMP::XS::set_type NOSUCHINSTANCE , \&_process_nosuchinstance; |
81 |
|
|
Net::SNMP::XS::set_type ENDOFMIBVIEW , \&_process_endofmibview; |
82 |
|
|
Net::SNMP::XS::set_type GET_REQUEST , \&_process_get_request; |
83 |
|
|
Net::SNMP::XS::set_type GET_NEXT_REQUEST , \&_process_get_next_request; |
84 |
|
|
Net::SNMP::XS::set_type GET_RESPONSE , \&_process_get_response; |
85 |
|
|
Net::SNMP::XS::set_type SET_REQUEST , \&_process_set_request; |
86 |
|
|
Net::SNMP::XS::set_type TRAP , \&_process_trap; |
87 |
|
|
Net::SNMP::XS::set_type GET_BULK_REQUEST , \&_process_get_bulk_request; |
88 |
|
|
Net::SNMP::XS::set_type INFORM_REQUEST , \&_process_inform_request; |
89 |
|
|
Net::SNMP::XS::set_type SNMPV2_TRAP , \&_process_v2_trap; |
90 |
|
|
Net::SNMP::XS::set_type REPORT , \&_process_report; |
91 |
|
|
|
92 |
|
|
package Net::SNMP::PDU; |
93 |
|
|
|
94 |
root |
1.10 |
# var_bind_list hardcodes oid_lex_sort. *sigh* |
95 |
root |
1.8 |
# we copy it 1:1, except for using oid_lex_sort. |
96 |
|
|
|
97 |
|
|
sub var_bind_list |
98 |
root |
1.1 |
{ |
99 |
root |
1.8 |
my ($this, $vbl, $types) = @_; |
100 |
|
|
|
101 |
|
|
return if defined($this->{_error}); |
102 |
|
|
|
103 |
|
|
if (@_ > 1) { |
104 |
|
|
# The VarBindList HASH is being updated from an external |
105 |
|
|
# source. We need to update the VarBind names ARRAY to |
106 |
|
|
# correspond to the new keys of the HASH. If the updated |
107 |
|
|
# information is valid, we will use lexicographical ordering |
108 |
|
|
# for the ARRAY entries since we do not have a PDU to use |
109 |
|
|
# to determine the ordering. The ASN.1 types HASH is also |
110 |
|
|
# updated here if a cooresponding HASH is passed. We double |
111 |
|
|
# check the mapping by populating the hash with the keys of |
112 |
|
|
# the VarBindList HASH. |
113 |
|
|
|
114 |
|
|
if (!defined($vbl) || (ref($vbl) ne 'HASH')) { |
115 |
|
|
|
116 |
|
|
$this->{_var_bind_list} = undef; |
117 |
|
|
$this->{_var_bind_names} = []; |
118 |
|
|
$this->{_var_bind_types} = undef; |
119 |
|
|
|
120 |
|
|
} else { |
121 |
|
|
|
122 |
|
|
$this->{_var_bind_list} = $vbl; |
123 |
|
|
|
124 |
|
|
@{$this->{_var_bind_names}} = Net::SNMP::oid_lex_sort keys %$vbl; |
125 |
|
|
|
126 |
|
|
if (!defined($types) || (ref($types) ne 'HASH')) { |
127 |
|
|
$types = {}; |
128 |
|
|
} |
129 |
|
|
|
130 |
|
|
map { |
131 |
|
|
$this->{_var_bind_types}->{$_} = |
132 |
|
|
exists($types->{$_}) ? $types->{$_} : undef; |
133 |
|
|
} keys(%{$vbl}); |
134 |
|
|
|
135 |
|
|
} |
136 |
|
|
|
137 |
|
|
} |
138 |
root |
1.1 |
|
139 |
root |
1.8 |
$this->{_var_bind_list}; |
140 |
root |
1.1 |
} |
141 |
|
|
|
142 |
|
|
1; |
143 |
|
|
|
144 |
|
|
=head1 AUTHOR |
145 |
|
|
|
146 |
|
|
Marc Lehmann <schmorp@schmorp.de> |
147 |
|
|
http://home.schmorp.de/ |
148 |
|
|
|
149 |
|
|
=cut |
150 |
|
|
|