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