… | |
… | |
13 | This module tries to speed up Net::SNMP response packet decoding. |
13 | This module tries to speed up Net::SNMP response packet decoding. |
14 | |
14 | |
15 | It does this by overriding a few selected internal method by (almost) |
15 | It does this by overriding a few selected internal method by (almost) |
16 | equivalent XS methods. |
16 | equivalent XS methods. |
17 | |
17 | |
18 | This currently reduces decode time by a factor of four for typical bulk |
18 | This currently reduces decode time by a factor of ten for typical bulk |
19 | responses. |
19 | responses. |
20 | |
20 | |
21 | There are currently the following limitations when using this module: |
21 | There are currently the following limitations when using this module: |
22 | |
22 | |
23 | =over 4 |
23 | =over 4 |
24 | |
24 | |
25 | =item only leading dots for oids are supported |
25 | =item overriding internal functions might cause the module to |
26 | |
26 | malfunction with future versions of Net::SNMP |
27 | =item error handling is currently broken (but parse errors will be detected) |
|
|
28 | |
27 | |
29 | =item error messages will be simpler/different |
28 | =item error messages will be simpler/different |
30 | |
29 | |
31 | =item oid components are limited to unsigned 32 bit integers |
|
|
32 | |
|
|
33 | =item translation will be ignored (all values will be delivered "raw") |
30 | =item translation will be ignored (all values will be delivered "raw") |
34 | |
|
|
35 | =item a 64 bit perl is required |
|
|
36 | |
31 | |
37 | =item a moderately modern (>= C99) C compiler is required |
32 | =item a moderately modern (>= C99) C compiler is required |
38 | |
33 | |
39 | =item only tested with 5.10 |
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 |
40 | |
39 | |
41 | =back |
40 | =back |
42 | |
41 | |
43 | =cut |
42 | =cut |
44 | |
43 | |
… | |
… | |
47 | use strict qw(vars subs); |
46 | use strict qw(vars subs); |
48 | no warnings; |
47 | no warnings; |
49 | |
48 | |
50 | use Guard; |
49 | use Guard; |
51 | |
50 | |
|
|
51 | use Net::SNMP (); |
52 | use Net::SNMP::PDU (); |
52 | use Net::SNMP::PDU (); |
53 | use Net::SNMP::Message (); |
53 | use Net::SNMP::Message (); |
54 | use Net::SNMP::MessageProcessing (); |
54 | use Net::SNMP::MessageProcessing (); |
55 | |
55 | |
56 | our $VERSION; |
56 | our $VERSION; |
57 | our $old_prepare; |
|
|
58 | |
57 | |
59 | BEGIN { |
58 | BEGIN { |
60 | $VERSION = '0.01'; |
59 | $VERSION = '1.1'; |
61 | |
60 | |
62 | $old_prepare = \&Net::SNMP::MessageProcessing::prepare_data_elements; |
61 | # this overrides many methods inside Net::SNMP and it's submodules |
63 | |
|
|
64 | # this overrides many methods inside |
|
|
65 | require XSLoader; |
62 | require XSLoader; |
66 | XSLoader::load Net::SNMP::XS, $VERSION; |
63 | XSLoader::load Net::SNMP::XS, $VERSION; |
67 | } |
64 | } |
68 | |
65 | |
69 | sub Net::SNMP::MessageProcessing::prepare_data_elements { |
66 | package Net::SNMP::Message; |
70 | my ($self, $msg) = @_; |
|
|
71 | |
67 | |
72 | set_msg $msg, $msg->{_buffer}; |
68 | Net::SNMP::XS::set_type INTEGER , \&_process_integer32; |
73 | scope_guard \&clr_msg; |
69 | Net::SNMP::XS::set_type OCTET_STRING , \&_process_octet_string; |
74 | &$old_prepare |
70 | Net::SNMP::XS::set_type NULL , \&_process_null; |
75 | } |
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; |
76 | |
91 | |
|
|
92 | package Net::SNMP::PDU; |
|
|
93 | |
|
|
94 | # var_bind_list hardcodes oid_lex_sort. *sigh* |
|
|
95 | # we copy it 1:1, except for using oid_lex_sort. |
|
|
96 | |
|
|
97 | sub var_bind_list |
77 | { |
98 | { |
78 | package Net::SNMP::Message; |
99 | my ($this, $vbl, $types) = @_; |
79 | |
100 | |
80 | Net::SNMP::XS::set_type INTEGER , \&_process_integer32; |
101 | return if defined($this->{_error}); |
81 | Net::SNMP::XS::set_type OCTET_STRING , \&_process_octet_string; |
102 | |
82 | Net::SNMP::XS::set_type NULL , \&_process_null; |
103 | if (@_ > 1) { |
83 | Net::SNMP::XS::set_type OBJECT_IDENTIFIER, \&_process_object_identifier; |
104 | # The VarBindList HASH is being updated from an external |
84 | Net::SNMP::XS::set_type SEQUENCE , \&_process_sequence; |
105 | # source. We need to update the VarBind names ARRAY to |
85 | Net::SNMP::XS::set_type IPADDRESS , \&_process_ipaddress; |
106 | # correspond to the new keys of the HASH. If the updated |
86 | Net::SNMP::XS::set_type COUNTER , \&_process_counter; |
107 | # information is valid, we will use lexicographical ordering |
87 | Net::SNMP::XS::set_type GAUGE , \&_process_gauge; |
108 | # for the ARRAY entries since we do not have a PDU to use |
88 | Net::SNMP::XS::set_type TIMETICKS , \&_process_timeticks; |
109 | # to determine the ordering. The ASN.1 types HASH is also |
89 | Net::SNMP::XS::set_type OPAQUE , \&_process_opaque; |
110 | # updated here if a cooresponding HASH is passed. We double |
90 | Net::SNMP::XS::set_type COUNTER64 , \&_process_counter64; |
111 | # check the mapping by populating the hash with the keys of |
91 | Net::SNMP::XS::set_type NOSUCHOBJECT , \&_process_nosuchobject; |
112 | # the VarBindList HASH. |
92 | Net::SNMP::XS::set_type NOSUCHINSTANCE , \&_process_nosuchinstance; |
113 | |
93 | Net::SNMP::XS::set_type ENDOFMIBVIEW , \&_process_endofmibview; |
114 | if (!defined($vbl) || (ref($vbl) ne 'HASH')) { |
94 | Net::SNMP::XS::set_type GET_REQUEST , \&_process_get_request; |
115 | |
95 | Net::SNMP::XS::set_type GET_NEXT_REQUEST , \&_process_get_next_request; |
116 | $this->{_var_bind_list} = undef; |
96 | Net::SNMP::XS::set_type GET_RESPONSE , \&_process_get_response; |
117 | $this->{_var_bind_names} = []; |
97 | Net::SNMP::XS::set_type SET_REQUEST , \&_process_set_request; |
118 | $this->{_var_bind_types} = undef; |
98 | Net::SNMP::XS::set_type TRAP , \&_process_trap; |
119 | |
99 | Net::SNMP::XS::set_type GET_BULK_REQUEST , \&_process_get_bulk_request; |
120 | } else { |
100 | Net::SNMP::XS::set_type INFORM_REQUEST , \&_process_inform_request; |
121 | |
101 | Net::SNMP::XS::set_type SNMPV2_TRAP , \&_process_v2_trap; |
122 | $this->{_var_bind_list} = $vbl; |
102 | Net::SNMP::XS::set_type REPORT , \&_process_report; |
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 | |
|
|
139 | $this->{_var_bind_list}; |
103 | } |
140 | } |
104 | |
141 | |
105 | 1; |
142 | 1; |
106 | |
143 | |
107 | =head1 AUTHOR |
144 | =head1 AUTHOR |