diff options
Diffstat (limited to 'lib/snmp/src/agent/snmpa_mpd.erl')
-rw-r--r-- | lib/snmp/src/agent/snmpa_mpd.erl | 70 |
1 files changed, 48 insertions, 22 deletions
diff --git a/lib/snmp/src/agent/snmpa_mpd.erl b/lib/snmp/src/agent/snmpa_mpd.erl index 0d40840d35..9c520a7071 100644 --- a/lib/snmp/src/agent/snmpa_mpd.erl +++ b/lib/snmp/src/agent/snmpa_mpd.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 1997-2020. All Rights Reserved. +%% Copyright Ericsson AB 1997-2023. All Rights Reserved. %% %% Licensed under the Apache License, Version 2.0 (the "License"); %% you may not use this file except in compliance with the License. @@ -28,6 +28,13 @@ process_taddrs/1, generate_req_id/0]). +%% This is just for debugging and testing +-export([ + empty_msg/0, + empty_msg_size/0 + ]). + + -define(SNMP_USE_V3, true). -include("snmp_types.hrl"). -include("SNMP-MPD-MIB.hrl"). @@ -39,7 +46,11 @@ -include("snmp_verbosity.hrl"). -include("snmpa_internal.hrl"). +-ifdef(empty_pdu_size). +-define(empty_msg_size, ?empty_pdu_size + 3). +-else. -define(empty_msg_size, 24). +-endif. -record(state, {v1 = false, v2c = false, v3 = false}). -record(note, {sec_engine_id, @@ -51,9 +62,9 @@ disco = false, req_id}). - + %%%----------------------------------------------------------------- -%%% This module implemets the Message Processing and Dispatch part of +%%% This module implements the Message Processing and Dispatch part of %%% the multi-lingual SNMP agent. %%% %%% The MPD is responsible for: @@ -70,7 +81,7 @@ %%% the counters only, it does not provide instrumentation functions %%% for the counters. %%% -%%% With the terms defined in rfc2271, this module implememts part +%%% With the terms defined in rfc2271, this module implements part %%% of the Dispatcher and the Message Processing functionality. %%%----------------------------------------------------------------- init(Vsns) -> @@ -88,14 +99,13 @@ reset() -> ok. -%%----------------------------------------------------------------- -%% Purpose: We must calculate the length of a -%% message with an empty Pdu, and zero-length community -%% string. This length is used to calculate the max -%% pdu size allowed for each request. This size is -%% dependent on two dynamic fields, the community string -%% and the pdu (varbinds actually). It is calculated -%% as EmptySize + length(CommunityString) + 4. +%%-------------------------------------------------------------------------- +%% Purpose: We must calculate the length of a message with an empty Pdu +%% and zero-length community string. +%% This length is used to calculate the max pdu size allowed for +%% each request. This size is dependent on two dynamic fields; +%% the community string and the pdu (varbinds actually). +%% It is calculated as EmptySize + length(CommunityString) + 4. %% We assume that the length of the CommunityString is %% less than 128 (thus requiring just one octet for the %% length field (the same as the zero-length community @@ -104,13 +114,28 @@ reset() -> %% expressed. One 7bit octet is already present in the %% empty msg, leaving 4 more 7bit octets. %% Actually, this function is not used, we use a constant instead. -%%----------------------------------------------------------------- +%%-------------------------------------------------------------------------- %% Ret: 24 -%empty_msg() -> -% M = #message{version = 'version-1', community = "", data = -% #pdu{type = 'get-response', request_id = 1, -% error_status = noError, error_index = 0, varbinds = []}}, -% length(snmp_pdus:enc_message(M)) + 4. +%%empty_msg() -> +%% M = #message{version = 'version-1', community = "", data = +%% #pdu{type = 'get-response', request_id = 1, +%% error_status = noError, error_index = 0, varbinds = []}}, +%% length(snmp_pdus:enc_message(M)) + 4. + +-ifdef(SNMP_USE_V3). +empty_msg() -> + {message, 'version-1', "", snmpa_get:empty_pdu()}. +-else. +empty_msg() -> + #message{version = 'version-1', + community = "", + data = snmpa_get:empty_pdu()}. +-endif. + +empty_msg_size() -> + ?empty_msg_size. + + %%----------------------------------------------------------------- %% Func: process_packet(Packet, Domain, Address, State, Log) -> @@ -648,7 +673,7 @@ generate_response_msg(Vsn, RePdu, Type, {discarded, Reason}; Packet -> MMS = get_engine_max_message_size(LocalEngineID), - case size(Packet) of + case byte_size(Packet) of Len when Len =< MMS -> Log(Type, Packet), inc_snmp_cnt_vars(Type, RePdu), @@ -717,7 +742,7 @@ generate_response_msg(Vsn, RePdu, Type, %% because of the calculation we do when we %% receive the bulk-request. Packet = list_to_binary(OutMsg), - case size(Packet) of + case byte_size(Packet) of Len when Len =< AgentMS -> if SecLevel =:= 3 -> @@ -907,7 +932,7 @@ generate_msg(Vsn, _NoteStore, Pdu, {community, Community}, LocalEngineID, To) -> {discarded, Reason}; Packet -> AgentMax = get_engine_max_message_size(LocalEngineID), - case size(Packet) of + case byte_size(Packet) of Len when Len =< AgentMax -> {ok, mk_v1_v2_packet_list(To, Packet, Len, Pdu)}; Len -> @@ -1296,7 +1321,7 @@ mk_v3_packet_entry(NoteStore, Domain, Addr, %% Store in cache for 150 sec. Packet = list_to_binary(OutMsg), ?vdebug("mk_v3_packet_entry -> generated: ~w bytes", - [size(Packet)]), + [byte_size(Packet)]), Data = if SecLevel =:= 3 -> @@ -1535,3 +1560,4 @@ user_err(F, A) -> config_err(F, A) -> snmpa_error:config_err(F, A). + |