diff options
Diffstat (limited to 'lib/snmp/src/agent')
-rw-r--r-- | lib/snmp/src/agent/snmpa.erl | 17 | ||||
-rw-r--r-- | lib/snmp/src/agent/snmpa_agent.erl | 130 | ||||
-rw-r--r-- | lib/snmp/src/agent/snmpa_net_if.erl | 112 | ||||
-rw-r--r-- | lib/snmp/src/agent/snmpa_usm.erl | 18 |
4 files changed, 122 insertions, 155 deletions
diff --git a/lib/snmp/src/agent/snmpa.erl b/lib/snmp/src/agent/snmpa.erl index 79493bd892..a113bba3a7 100644 --- a/lib/snmp/src/agent/snmpa.erl +++ b/lib/snmp/src/agent/snmpa.erl @@ -1,19 +1,19 @@ %% %% %CopyrightBegin% -%% -%% Copyright Ericsson AB 2004-2009. All Rights Reserved. -%% +%% +%% Copyright Ericsson AB 2004-2010. All Rights Reserved. +%% %% The contents of this file are subject to the Erlang Public License, %% Version 1.1, (the "License"); you may not use this file except in %% compliance with the License. You should have received a copy of the %% Erlang Public License along with this software. If not, it can be %% retrieved online at http://www.erlang.org/. -%% +%% %% Software distributed under the License is distributed on an "AS IS" %% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See %% the License for the specific language governing rights and limitations %% under the License. -%% +%% %% %CopyrightEnd% %% -module(snmpa). @@ -83,6 +83,7 @@ %% Audit Trail Log functions -export([log_to_txt/2, log_to_txt/3, log_to_txt/4, log_to_txt/5, log_to_txt/6, log_to_txt/7, + log_info/0, change_log_size/1, get_log_type/0, get_log_type/1, change_log_type/1, change_log_type/2, @@ -535,6 +536,7 @@ get_agent_caps() -> %%%----------------------------------------------------------------- %%% Audit Trail Log functions %%%----------------------------------------------------------------- + log_to_txt(LogDir, Mibs) -> OutFile = "snmpa_log.txt", LogName = ?audit_trail_log_name, @@ -555,6 +557,11 @@ log_to_txt(LogDir, Mibs, OutFile, LogName, LogFile, Start, Stop) -> snmp:log_to_txt(LogDir, Mibs, OutFile, LogName, LogFile, Start, Stop). +log_info() -> + LogName = ?audit_trail_log_name, + snmp_log:info(LogName). + + change_log_size(NewSize) -> LogName = ?audit_trail_log_name, % The old (agent) default snmp:change_log_size(LogName, NewSize). diff --git a/lib/snmp/src/agent/snmpa_agent.erl b/lib/snmp/src/agent/snmpa_agent.erl index 508a1da514..fb04fca632 100644 --- a/lib/snmp/src/agent/snmpa_agent.erl +++ b/lib/snmp/src/agent/snmpa_agent.erl @@ -1,19 +1,19 @@ %% %% %CopyrightBegin% -%% -%% Copyright Ericsson AB 1996-2009. All Rights Reserved. -%% +%% +%% Copyright Ericsson AB 1996-2010. All Rights Reserved. +%% %% The contents of this file are subject to the Erlang Public License, %% Version 1.1, (the "License"); you may not use this file except in %% compliance with the License. You should have received a copy of the %% Erlang Public License along with this software. If not, it can be %% retrieved online at http://www.erlang.org/. -%% +%% %% Software distributed under the License is distributed on an "AS IS" %% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See %% the License for the specific language governing rights and limitations %% under the License. -%% +%% %% %CopyrightEnd% %% -module(snmpa_agent). @@ -58,6 +58,7 @@ -export([get_log_type/1, set_log_type/2]). -export([get_request_limit/1, set_request_limit/2]). -export([invalidate_ca_cache/0]). +-export([increment_counter/3]). -export([restart_worker/1, restart_set_worker/1]). %% Internal exports @@ -259,6 +260,29 @@ update_mibs_cache_age(Agent, Age) -> call(Agent, {mibs_cache_request, {update_age, Age}}). +increment_counter(Counter, Initial, Max) -> + %% This is to make sure no one else increments our counter + Key = {Counter, self()}, + + %% Counter data + Position = 2, + Increment = 1, + Threshold = Max, + SetValue = Initial, + UpdateOp = {Position, Increment, Threshold, SetValue}, + + %% And now for the actual increment + Tab = snmp_agent_table, + case (catch ets:update_counter(Tab, Key, UpdateOp)) of + {'EXIT', {badarg, _}} -> + %% Oups, first time + ets:insert(Tab, {Key, Initial}), + Initial; + Next when is_integer(Next) -> + Next + end. + + init([Prio, Parent, Ref, Options]) -> ?d("init -> entry with" "~n Prio: ~p" @@ -1223,79 +1247,23 @@ handle_mibs_cache_request(MibServer, Req) -> %% Downgrade %% -code_change({down, _Vsn}, S, downgrade_to_pre_4_13) -> - S1 = workers_restart(S), - case S1#state.disco of - undefined -> - ok; - #disco{from = From, - sender = Sender, - stage = Stage} -> - gen_server:reply(From, {error, {upgrade, Stage, Sender}}), - exit(Sender, kill) - end, - S2 = {state, - S1#state.type, - S1#state.parent, - S1#state.worker, - S1#state.worker_state, - S1#state.set_worker, - S1#state.multi_threaded, - S1#state.ref, - S1#state.vsns, - S1#state.nfilters, - S1#state.note_store, - S1#state.mib_server, - S1#state.net_if, - S1#state.net_if_mod, - S1#state.backup, - S1#state.disco}, - {ok, S2}; +%% code_change({down, _Vsn}, S, downgrade_to_pre_4_13) -> +%% {ok, S2}; %% Upgrade %% -code_change(_Vsn, S, upgrade_from_pre_4_13) -> - {state, - Type, - Parent, - Worker, - WorkerState, - SetWorker, - MultiThreaded, - Ref, - Vsns, - NFilters = [], - NoteStore, - MibServer, %% Currently unused - NetIf, %% Currently unused - NetIfMod, - Backup} = S, - S1 = #state{type = Type, - parent = Parent, - worker = Worker, - worker_state = WorkerState, - set_worker = SetWorker, - multi_threaded = MultiThreaded, - ref = Ref, - vsns = Vsns, - nfilters = NFilters, - note_store = NoteStore, - mib_server = MibServer, - net_if = NetIf, - net_if_mod = NetIfMod, - backup = Backup}, - S2 = workers_restart(S1), - {ok, S2}; +%% code_change(_Vsn, S, upgrade_from_pre_4_13) -> +%% {ok, S2}; code_change(_Vsn, S, _Extra) -> {ok, S}. -workers_restart(#state{worker = W, set_worker = SW} = S) -> - Worker = worker_restart(W), - SetWorker = set_worker_restart(SW), - S#state{worker = Worker, - set_worker = SetWorker}. +%% workers_restart(#state{worker = W, set_worker = SW} = S) -> +%% Worker = worker_restart(W), +%% SetWorker = set_worker_restart(SW), +%% S#state{worker = Worker, +%% set_worker = SetWorker}. %%----------------------------------------------------------------- @@ -1321,8 +1289,8 @@ set_worker_start() -> worker_start(Dict) -> proc_lib:spawn_link(?MODULE, worker, [self(), Dict]). -worker_stop(Pid) -> - worker_stop(Pid, infinity). +%% worker_stop(Pid) -> +%% worker_stop(Pid, infinity). worker_stop(Pid, Timeout) when is_pid(Pid) -> Pid ! terminate, @@ -1336,17 +1304,17 @@ worker_stop(Pid, Timeout) when is_pid(Pid) -> worker_stop(_, _) -> ok. -set_worker_restart(Pid) -> - worker_restart(Pid, [{master, self()} | get()]). +%% set_worker_restart(Pid) -> +%% worker_restart(Pid, [{master, self()} | get()]). -worker_restart(Pid) -> - worker_restart(Pid, get()). +%% worker_restart(Pid) -> +%% worker_restart(Pid, get()). -worker_restart(Pid, Dict) when is_pid(Pid) -> - worker_stop(Pid), - worker_start(Dict); -worker_restart(Any, _Dict) -> - Any. +%% worker_restart(Pid, Dict) when is_pid(Pid) -> +%% worker_stop(Pid), +%% worker_start(Dict); +%% worker_restart(Any, _Dict) -> +%% Any. %%----------------------------------------------------------------- diff --git a/lib/snmp/src/agent/snmpa_net_if.erl b/lib/snmp/src/agent/snmpa_net_if.erl index d703e5ac55..bc0777a7dd 100644 --- a/lib/snmp/src/agent/snmpa_net_if.erl +++ b/lib/snmp/src/agent/snmpa_net_if.erl @@ -1,19 +1,19 @@ %% %% %CopyrightBegin% -%% -%% Copyright Ericsson AB 2004-2009. All Rights Reserved. -%% +%% +%% Copyright Ericsson AB 2004-2010. All Rights Reserved. +%% %% The contents of this file are subject to the Erlang Public License, %% Version 1.1, (the "License"); you may not use this file except in %% compliance with the License. You should have received a copy of the %% Erlang Public License along with this software. If not, it can be %% retrieved online at http://www.erlang.org/. -%% +%% %% Software distributed under the License is distributed on an "AS IS" %% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See %% the License for the specific language governing rights and limitations %% under the License. -%% +%% %% %CopyrightEnd% %% -module(snmpa_net_if). @@ -55,6 +55,9 @@ -define(DEFAULT_FILTER_MODULE, snmpa_net_if_filter). -define(DEFAULT_FILTER_OPTS, [{module, ?DEFAULT_FILTER_MODULE}]). +-define(ATL_SEQNO_INITIAL, 1). +-define(ATL_SEQNO_MAX, 2147483647). + %%%----------------------------------------------------------------- %%% This module implements the default Network Interface part @@ -194,24 +197,43 @@ do_init(Prio, NoteStore, MasterAgent, Parent, Opts) -> {error, {udp_open, UDPPort, Reason}} end. + create_log() -> case ets:lookup(snmp_agent_table, audit_trail_log) of [] -> {undefined, []}; [{audit_trail_log, AtlOpts}] -> - ?vtrace("AtlOpts: ~p",[AtlOpts]), + ?vtrace("AtlOpts: ~p", [AtlOpts]), Type = get_atl_type(AtlOpts), Dir = get_atl_dir(AtlOpts), Size = get_atl_size(AtlOpts), Repair = get_atl_repair(AtlOpts), Name = ?audit_trail_log_name, File = filename:absname(?audit_trail_log_file, Dir), - case snmp_log:create(Name, File, Size, Repair, true) of - {ok, Log} -> - ?vdebug("log created: ~w",[Log]), - {Log, Type}; - {error, Reason} -> - throw({error, {create_log, Reason}}) + case get_atl_seqno(AtlOpts) of + true -> + Initial = ?ATL_SEQNO_INITIAL, + Max = ?ATL_SEQNO_MAX, + Module = snmpa_agent, + Function = increment_counter, + Args = [atl_seqno, Initial, Max], + SeqNoGen = {Module, Function, Args}, + case snmp_log:create(Name, File, + SeqNoGen, Size, Repair, true) of + {ok, Log} -> + ?vdebug("log created: ~w", [Log]), + {Log, Type}; + {error, Reason} -> + throw({error, {create_log, Reason}}) + end; + _ -> + case snmp_log:create(Name, File, Size, Repair, true) of + {ok, Log} -> + ?vdebug("log created: ~w", [Log]), + {Log, Type}; + {error, Reason} -> + throw({error, {create_log, Reason}}) + end end end. @@ -918,60 +940,23 @@ system_continue(_Parent, _Dbg, S) -> loop(S). system_terminate(Reason, _Parent, _Dbg, #state{log = Log}) -> + ?vlog("system-terminate -> entry with" + "~n Reason: ~p", [Reason]), do_close_log(Log), exit(Reason). -system_code_change(OldState, _Module, _OldVsn, upgrade_from_pre_4_10) -> - {state, - parent = Parent, - note_store = NS, - master_agent = MA, - usock = Sock, - usock_opts = SockOpts, - mpd_state = MpdState, - log = Log, - reqs = Reqs, - debug = Dbg, - limit = Limit, - rcnt = RCNT} = OldState, - NewState = #state{parent = Parent, - note_store = NS, - master_agent = MA, - usock = Sock, - usock_opts = SockOpts, - mpd_state = MpdState, - log = Log, - reqs = Reqs, - debug = Dbg, - limit = Limit, - rcnt = RCNT, - filter = create_filter(?DEFAULT_FILTER_OPTS)}, +system_code_change(OldState, _Module, _OldVsn, upgrade_from_pre_4_16) -> + Initial = ?ATL_SEQNO_INITIAL, + Max = ?ATL_SEQNO_MAX, + Module = snmpa_agent, + Function = increment_counter, + Args = [atl_seqno, Initial, Max], + SeqNoGen = {Module, Function, Args}, + NewLog = snmp_log:upgrade(OldState#state.log, SeqNoGen), + NewState = OldState#state{log = NewLog}, {ok, NewState}; -system_code_change(OldState, _Module, _OldVsn, downgrade_to_pre_4_10) -> - #state{parent = Parent, - note_store = NS, - master_agent = MA, - usock = Sock, - usock_opts = SockOpts, - mpd_state = MpdState, - log = Log, - reqs = Reqs, - debug = Dbg, - limit = Limit, - rcnt = RCNT} = OldState, - NewState = - {state, - parent = Parent, - note_store = NS, - master_agent = MA, - usock = Sock, - usock_opts = SockOpts, - mpd_state = MpdState, - log = Log, - reqs = Reqs, - debug = Dbg, - limit = Limit, - rcnt = RCNT}, +system_code_change(OldState, _Module, _OldVsn, downgrade_to_pre_4_16) -> + NewState = OldState#state{log = snmp_log:downgrade(OldState#state.log)}, {ok, NewState}; system_code_change(S, _Module, _OldVsn, _Extra) -> {ok, S}. @@ -1111,6 +1096,9 @@ get_atl_size(Opts) -> get_atl_repair(Opts) -> snmp_misc:get_option(repair, Opts, true). +get_atl_seqno(Opts) -> + snmp_misc:get_option(seqno, Opts, false). + get_verbosity(Opts) -> snmp_misc:get_option(verbosity, Opts, ?default_verbosity). diff --git a/lib/snmp/src/agent/snmpa_usm.erl b/lib/snmp/src/agent/snmpa_usm.erl index a8c395534f..12a6b996ff 100644 --- a/lib/snmp/src/agent/snmpa_usm.erl +++ b/lib/snmp/src/agent/snmpa_usm.erl @@ -1,19 +1,19 @@ %% %% %CopyrightBegin% -%% -%% Copyright Ericsson AB 1999-2009. All Rights Reserved. -%% +%% +%% Copyright Ericsson AB 1999-2010. All Rights Reserved. +%% %% The contents of this file are subject to the Erlang Public License, %% Version 1.1, (the "License"); you may not use this file except in %% compliance with the License. You should have received a copy of the %% Erlang Public License along with this software. If not, it can be %% retrieved online at http://www.erlang.org/. -%% +%% %% Software distributed under the License is distributed on an "AS IS" %% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See %% the License for the specific language governing rights and limitations %% under the License. -%% +%% %% %CopyrightEnd% %% -module(snmpa_usm). @@ -396,7 +396,9 @@ try_decrypt(?usmDESPrivProtocol, case (catch des_decrypt(PrivKey, UsmSecParams, EncryptedPDU)) of {ok, DecryptedData} -> DecryptedData; - _ -> + Error -> + ?vlog("try_decrypt -> failed DES decrypt" + "~n Error: ~p", [Error]), error(usmStatsDecryptionErrors, ?usmStatsDecryptionErrors_instance, % OTP-5464 SecName) @@ -406,7 +408,9 @@ try_decrypt(?usmAesCfb128Protocol, case (catch aes_decrypt(PrivKey, UsmSecParams, EncryptedPDU)) of {ok, DecryptedData} -> DecryptedData; - _ -> + Error -> + ?vlog("try_decrypt -> failed AES decrypt" + "~n Error: ~p", [Error]), error(usmStatsDecryptionErrors, ?usmStatsDecryptionErrors_instance, % OTP-5464 SecName) |