From 76e9c68368dfd9ec20181939511e2baf93fc73d9 Mon Sep 17 00:00:00 2001 From: Micael Karlberg Date: Wed, 3 Feb 2010 18:00:01 +0000 Subject: OTP-8395: Sequence number in Audit Trail Logs. --- lib/snmp/src/manager/snmpm_config.erl | 62 ++++++++++++++++++++++++++------ lib/snmp/src/manager/snmpm_net_if.erl | 66 +++++++++++++++++++---------------- 2 files changed, 87 insertions(+), 41 deletions(-) (limited to 'lib/snmp/src/manager') diff --git a/lib/snmp/src/manager/snmpm_config.erl b/lib/snmp/src/manager/snmpm_config.erl index 1a5400bf8e..e4069485ad 100644 --- a/lib/snmp/src/manager/snmpm_config.erl +++ b/lib/snmp/src/manager/snmpm_config.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% %% %% ------------------------------------------------------------------------- @@ -63,6 +63,7 @@ cre_counter/2, incr_counter/2, + increment_counter/3, increment_counter/4, cre_stats_counter/2, maybe_cre_stats_counter/2, @@ -792,6 +793,34 @@ incr_counter(Counter, Incr, Wrap) -> end. +%% +increment_counter(Counter, Initial, Max) -> + Increment = 1, + increment_counter(Counter, Initial, Increment, Max). + +increment_counter(Counter, Initial, Increment, Max) -> + %% This is to make sure no one else increments our counter + Key = {Counter, self()}, + + %% Counter data + Position = 2, + Threshold = Max, + SetValue = Initial, + UpdateOp = {Position, Increment, Threshold, SetValue}, + + %% And now for the actual increment + Tab = snmpm_counter_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. +%% + + maybe_cre_stats_counter(Counter, Initial) -> case ets:lookup(snmpm_stats_table, Counter) of [_] -> @@ -1013,14 +1042,16 @@ do_init(Opts) -> AuditTrailLogOpts -> ?vtrace("ATL options: ~p", [AuditTrailLogOpts]), ets:insert(snmpm_config_table, {audit_trail_log, true}), - LogDir = get_atl_dir(AuditTrailLogOpts), - LogType = get_atl_type(AuditTrailLogOpts), - LogSize = get_atl_size(AuditTrailLogOpts), - LogRep = get_atl_repair(AuditTrailLogOpts), + LogDir = get_atl_dir(AuditTrailLogOpts), + LogType = get_atl_type(AuditTrailLogOpts), + LogSize = get_atl_size(AuditTrailLogOpts), + LogRep = get_atl_repair(AuditTrailLogOpts), + LogSeqNo = get_atl_seqno(AuditTrailLogOpts), ets:insert(snmpm_config_table, {audit_trail_log_dir, LogDir}), ets:insert(snmpm_config_table, {audit_trail_log_type, LogType}), ets:insert(snmpm_config_table, {audit_trail_log_size, LogSize}), - ets:insert(snmpm_config_table, {audit_trail_log_repair, LogRep}) + ets:insert(snmpm_config_table, {audit_trail_log_repair, LogRep}), + ets:insert(snmpm_config_table, {audit_trail_log_seqno, LogSeqNo}) end, %% -- System default agent config -- @@ -1398,6 +1429,9 @@ verify_audit_trail_log_opts([{size, Size}|Opts]) -> verify_audit_trail_log_opts([{repair, Repair}|Opts]) -> verify_log_repair(Repair), verify_audit_trail_log_opts(Opts); +verify_audit_trail_log_opts([{seqno, SeqNo}|Opts]) -> + verify_log_seqno(SeqNo), + verify_audit_trail_log_opts(Opts); verify_audit_trail_log_opts([Opt|_Opts]) -> error({invalid_audit_trail_log_option, Opt}). @@ -1440,6 +1474,11 @@ verify_log_repair(truncate) -> ok; verify_log_repair(Repair) -> error({invalid_audit_trail_log_repair, Repair}). +verify_log_seqno(true) -> ok; +verify_log_seqno(false) -> ok; +verify_log_seqno(SeqNo) -> + error({invalid_audit_trail_log_seqno, SeqNo}). + verify_module(_, Mod) when is_atom(Mod) -> ok; @@ -3040,6 +3079,9 @@ get_atl_size(Opts) -> get_atl_repair(Opts) -> get_opt(repair, Opts, truncate). +get_atl_seqno(Opts) -> + get_opt(seqno, Opts, false). + %%---------------------------------------------------------------------- diff --git a/lib/snmp/src/manager/snmpm_net_if.erl b/lib/snmp/src/manager/snmpm_net_if.erl index 14d39933dc..4ec24af7f3 100644 --- a/lib/snmp/src/manager/snmpm_net_if.erl +++ b/lib/snmp/src/manager/snmpm_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% %% @@ -81,6 +81,9 @@ -define(IRGC_TIMEOUT, timer:minutes(5)). +-define(ATL_SEQNO_INITIAL, 1). +-define(ATL_SEQNO_MAX, 2147483647). + %%%------------------------------------------------------------------- %%% API @@ -297,11 +300,29 @@ do_init_log(true) -> {ok, Repair} = snmpm_config:system_info(audit_trail_log_repair), 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} -> - {Log, Type}; - {error, Reason} -> - throw({error, {failed_create_audit_log, Reason}}) + case snmpm_config:system_info(audit_trail_log_seqno) of + {ok, true} -> + Initial = ?ATL_SEQNO_INITIAL, + Max = ?ATL_SEQNO_MAX, + Module = snmpm_config, + 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, {failed_create_audit_log, Reason}}) + end; + _ -> + case snmp_log:create(Name, File, Size, Repair, true) of + {ok, Log} -> + {Log, Type}; + {error, Reason} -> + throw({error, {failed_create_audit_log, Reason}}) + end end. @@ -441,32 +462,15 @@ do_close_log(_) -> %% Returns: {ok, NewState} %%---------------------------------------------------------------------- -code_change({down, _Vsn}, OldState, downgrade_to_pre45) -> +code_change({down, _Vsn}, OldState, downgrade_to_pre_4_16) -> ?d("code_change(down) -> entry", []), - #state{server = Server, - note_store = NoteStore, - sock = Sock, - mpd_state = MpdState, - log = Log, - irgc = IrGcRef} = OldState, - irgc_stop(IrGcRef), - (catch ets:delete(snmpm_inform_request_table)), - State = {state, Server, NoteStore, Sock, MpdState, Log}, + State = OldState#state{log = snmp_log:downgrade(OldState#state.log)}, {ok, State}; % upgrade -code_change(_Vsn, OldState, upgrade_from_pre45) -> +code_change(_Vsn, OldState, upgrade_from_pre_4_16) -> ?d("code_change(up) -> entry", []), - {state, Server, NoteStore, Sock, MpdState, Log} = OldState, - State = #state{server = Server, - note_store = NoteStore, - sock = Sock, - mpd_state = MpdState, - log = Log, - irb = auto, - irgc = undefined}, - ets:new(snmpm_inform_request_table, - [set, protected, named_table, {keypos, 1}]), + State = OldState#state{log = snmp_log:upgrade(OldState#state.log)}, {ok, State}; code_change(_Vsn, State, _Extra) -> -- cgit v1.2.3