~ubuntu-branches/debian/squeeze/erlang/squeeze

« back to all changes in this revision

Viewing changes to lib/snmp/src/agent/snmpa_net_if.erl

  • Committer: Bazaar Package Importer
  • Author(s): Sergei Golovan
  • Date: 2010-03-09 17:34:57 UTC
  • mfrom: (10.1.2 sid)
  • Revision ID: james.westby@ubuntu.com-20100309173457-4yd6hlcb2osfhx31
Tags: 1:13.b.4-dfsg-3
Manpages in section 1 are needed even if only arch-dependent packages are
built. So, re-enabled them.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
%%
2
2
%% %CopyrightBegin%
3
 
%% 
4
 
%% Copyright Ericsson AB 2004-2009. All Rights Reserved.
5
 
%% 
 
3
%%
 
4
%% Copyright Ericsson AB 2004-2010. All Rights Reserved.
 
5
%%
6
6
%% The contents of this file are subject to the Erlang Public License,
7
7
%% Version 1.1, (the "License"); you may not use this file except in
8
8
%% compliance with the License. You should have received a copy of the
9
9
%% Erlang Public License along with this software. If not, it can be
10
10
%% retrieved online at http://www.erlang.org/.
11
 
%% 
 
11
%%
12
12
%% Software distributed under the License is distributed on an "AS IS"
13
13
%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
14
14
%% the License for the specific language governing rights and limitations
15
15
%% under the License.
16
 
%% 
 
16
%%
17
17
%% %CopyrightEnd%
18
18
%%
19
19
-module(snmpa_net_if).
55
55
-define(DEFAULT_FILTER_MODULE, snmpa_net_if_filter).
56
56
-define(DEFAULT_FILTER_OPTS,   [{module, ?DEFAULT_FILTER_MODULE}]).
57
57
 
 
58
-define(ATL_SEQNO_INITIAL, 1).
 
59
-define(ATL_SEQNO_MAX,     2147483647).
 
60
 
58
61
 
59
62
%%%-----------------------------------------------------------------
60
63
%%% This module implements the default Network Interface part
194
197
            {error, {udp_open, UDPPort, Reason}}
195
198
    end.
196
199
 
 
200
 
197
201
create_log() ->
198
202
    case ets:lookup(snmp_agent_table, audit_trail_log) of
199
203
        [] ->
200
204
            {undefined, []};
201
205
        [{audit_trail_log, AtlOpts}] ->
202
 
            ?vtrace("AtlOpts: ~p",[AtlOpts]),
 
206
            ?vtrace("AtlOpts: ~p", [AtlOpts]),
203
207
            Type   = get_atl_type(AtlOpts),
204
208
            Dir    = get_atl_dir(AtlOpts),
205
209
            Size   = get_atl_size(AtlOpts),
206
210
            Repair = get_atl_repair(AtlOpts),
207
211
            Name   = ?audit_trail_log_name,
208
212
            File   = filename:absname(?audit_trail_log_file, Dir),
209
 
            case snmp_log:create(Name, File, Size, Repair, true) of
210
 
                {ok, Log} ->
211
 
                    ?vdebug("log created: ~w",[Log]),
212
 
                    {Log, Type};
213
 
                {error, Reason} ->
214
 
                    throw({error, {create_log, Reason}})
 
213
            case get_atl_seqno(AtlOpts) of
 
214
                true ->
 
215
                    Initial  = ?ATL_SEQNO_INITIAL,
 
216
                    Max      = ?ATL_SEQNO_MAX, 
 
217
                    Module   = snmpa_agent, 
 
218
                    Function = increment_counter, 
 
219
                    Args     = [atl_seqno, Initial, Max], 
 
220
                    SeqNoGen = {Module, Function, Args}, 
 
221
                    case snmp_log:create(Name, File, 
 
222
                                         SeqNoGen, Size, Repair, true) of
 
223
                        {ok, Log} ->
 
224
                            ?vdebug("log created: ~w", [Log]),
 
225
                            {Log, Type};
 
226
                        {error, Reason} ->
 
227
                            throw({error, {create_log, Reason}})
 
228
                    end;
 
229
                _ ->
 
230
                    case snmp_log:create(Name, File, Size, Repair, true) of
 
231
                        {ok, Log} ->
 
232
                            ?vdebug("log created: ~w", [Log]),
 
233
                            {Log, Type};
 
234
                        {error, Reason} ->
 
235
                            throw({error, {create_log, Reason}})
 
236
                    end
215
237
            end
216
238
    end.
217
239
 
918
940
    loop(S).
919
941
 
920
942
system_terminate(Reason, _Parent, _Dbg, #state{log = Log}) ->
 
943
    ?vlog("system-terminate -> entry with"
 
944
          "~n   Reason: ~p", [Reason]),
921
945
    do_close_log(Log),
922
946
    exit(Reason).
923
947
 
924
 
system_code_change(OldState, _Module, _OldVsn, upgrade_from_pre_4_10) ->
925
 
    {state, 
926
 
     parent       = Parent, 
927
 
     note_store   = NS,
928
 
     master_agent = MA, 
929
 
     usock        = Sock, 
930
 
     usock_opts   = SockOpts, 
931
 
     mpd_state    = MpdState, 
932
 
     log          = Log,
933
 
     reqs         = Reqs, 
934
 
     debug        = Dbg,
935
 
     limit        = Limit,
936
 
     rcnt         = RCNT} = OldState,
937
 
    NewState = #state{parent       = Parent, 
938
 
                      note_store   = NS,
939
 
                      master_agent = MA, 
940
 
                      usock        = Sock, 
941
 
                      usock_opts   = SockOpts, 
942
 
                      mpd_state    = MpdState, 
943
 
                      log          = Log,
944
 
                      reqs         = Reqs, 
945
 
                      debug        = Dbg,
946
 
                      limit        = Limit,
947
 
                      rcnt         = RCNT,
948
 
                      filter       = create_filter(?DEFAULT_FILTER_OPTS)},
949
 
    {ok, NewState};
950
 
system_code_change(OldState, _Module, _OldVsn, downgrade_to_pre_4_10) ->
951
 
    #state{parent       = Parent, 
952
 
           note_store   = NS,
953
 
           master_agent = MA, 
954
 
           usock        = Sock, 
955
 
           usock_opts   = SockOpts, 
956
 
           mpd_state    = MpdState, 
957
 
           log          = Log,
958
 
           reqs         = Reqs, 
959
 
           debug        = Dbg,
960
 
           limit        = Limit,
961
 
           rcnt         = RCNT} = OldState,
962
 
    NewState = 
963
 
        {state, 
964
 
         parent       = Parent, 
965
 
         note_store   = NS,
966
 
         master_agent = MA, 
967
 
         usock        = Sock, 
968
 
         usock_opts   = SockOpts, 
969
 
         mpd_state    = MpdState, 
970
 
         log          = Log,
971
 
         reqs         = Reqs, 
972
 
         debug        = Dbg,
973
 
         limit        = Limit,
974
 
         rcnt         = RCNT},
975
 
    {ok, NewState};
 
948
system_code_change(OldState, _Module, _OldVsn, downgrade_to_pre_4_16) ->
 
949
    {OldLog, Type} = OldState#state.log, 
 
950
    NewLog   = snmp_log:downgrade(OldLog), 
 
951
    NewState = OldState#state{log = {NewLog, Type}}, 
 
952
    {ok, NewState};
 
953
 
 
954
system_code_change(OldState, _Module, _OldVsn, upgrade_from_pre_4_16) ->
 
955
    Initial  = ?ATL_SEQNO_INITIAL,
 
956
    Max      = ?ATL_SEQNO_MAX, 
 
957
    Module   = snmpa_agent, 
 
958
    Function = increment_counter, 
 
959
    Args     = [atl_seqno, Initial, Max], 
 
960
    SeqNoGen = {Module, Function, Args}, 
 
961
    {OldLog, Type} = OldState#state.log, 
 
962
    NewLog   = snmp_log:upgrade(OldLog, SeqNoGen), 
 
963
    NewState = OldState#state{log = {NewLog, Type}}, 
 
964
    {ok, NewState};
 
965
 
976
966
system_code_change(S, _Module, _OldVsn, _Extra) ->
977
967
    {ok, S}.
978
968
 
1111
1101
get_atl_repair(Opts) ->
1112
1102
    snmp_misc:get_option(repair, Opts, true).
1113
1103
 
 
1104
get_atl_seqno(Opts) ->
 
1105
    snmp_misc:get_option(seqno, Opts, false).
 
1106
 
1114
1107
get_verbosity(Opts) ->
1115
1108
    snmp_misc:get_option(verbosity, Opts, ?default_verbosity).
1116
1109