diff options
Diffstat (limited to 'lib/snmp/src/manager')
-rw-r--r-- | lib/snmp/src/manager/snmpm.erl | 999 | ||||
-rw-r--r-- | lib/snmp/src/manager/snmpm_conf.erl | 4 | ||||
-rw-r--r-- | lib/snmp/src/manager/snmpm_config.erl | 517 | ||||
-rw-r--r-- | lib/snmp/src/manager/snmpm_internal.hrl | 7 | ||||
-rw-r--r-- | lib/snmp/src/manager/snmpm_mpd.erl | 47 | ||||
-rw-r--r-- | lib/snmp/src/manager/snmpm_net_if.erl | 49 | ||||
-rw-r--r-- | lib/snmp/src/manager/snmpm_server.erl | 870 | ||||
-rw-r--r-- | lib/snmp/src/manager/snmpm_usm.erl | 11 |
8 files changed, 1671 insertions, 833 deletions
diff --git a/lib/snmp/src/manager/snmpm.erl b/lib/snmp/src/manager/snmpm.erl index 7e801ebc40..6d2ac8d747 100644 --- a/lib/snmp/src/manager/snmpm.erl +++ b/lib/snmp/src/manager/snmpm.erl @@ -24,6 +24,8 @@ %%---------------------------------------------------------------------- %% User interface +%% Avoid warning for local function demonitor/1 clashing with autoimported BIF. +-compile({no_auto_import,[demonitor/1]}). -export([ %% %% Management API @@ -48,22 +50,23 @@ register_agent/2, register_agent/3, register_agent/4, unregister_agent/2, unregister_agent/3, which_agents/0, which_agents/1, - agent_info/2, update_agent_info/4, + agent_info/2, update_agent_info/3, update_agent_info/4, register_usm_user/3, unregister_usm_user/2, which_usm_users/0, which_usm_users/1, usm_user_info/3, update_usm_user_info/4, %% - %% Basic SNMP API - sync_get/3, sync_get/4, sync_get/5, sync_get/6, - async_get/3, async_get/4, async_get/5, async_get/6, - sync_get_next/3, sync_get_next/4, sync_get_next/5, sync_get_next/6, - async_get_next/3, async_get_next/4, async_get_next/5, async_get_next/6, - sync_set/3, sync_set/4, sync_set/5, sync_set/6, - async_set/3, async_set/4, async_set/5, async_set/6, - sync_get_bulk/5, sync_get_bulk/6, sync_get_bulk/7, sync_get_bulk/8, - async_get_bulk/5, async_get_bulk/6, async_get_bulk/7, async_get_bulk/8, + %% Basic SNMP API (version "3"). + sync_get2/3, sync_get2/4, + async_get2/3, async_get2/4, + sync_get_next2/3, sync_get_next2/4, + async_get_next2/3, async_get_next2/4, + sync_set2/3, sync_set2/4, + async_set2/3, async_set2/4, + sync_get_bulk2/5, sync_get_bulk2/6, + async_get_bulk2/5, async_get_bulk2/6, + cancel_async_request/2, %% @@ -89,7 +92,61 @@ -export([format_reason/1, format_reason/2]). -%% Backward compatibillity exports +%% Backward compatibility exports (API version "2") +-export([ + sync_get/3, sync_get/4, sync_get/5, sync_get/6, + async_get/3, async_get/4, async_get/5, async_get/6, + sync_get_next/3, sync_get_next/4, sync_get_next/5, sync_get_next/6, + async_get_next/3, async_get_next/4, async_get_next/5, async_get_next/6, + sync_set/3, sync_set/4, sync_set/5, sync_set/6, + async_set/3, async_set/4, async_set/5, async_set/6, + sync_get_bulk/5, sync_get_bulk/6, sync_get_bulk/7, sync_get_bulk/8, + async_get_bulk/5, async_get_bulk/6, async_get_bulk/7, async_get_bulk/8 + ]). + +%% Backward compatibility exports (API version "1") +-deprecated({agent_info, 3}). +-deprecated({update_agent_info, 5}). +-deprecated({g, 3}). +-deprecated({g, 4}). +-deprecated({g, 5}). +-deprecated({g, 6}). +-deprecated({g, 7}). +-deprecated({ag, 3}). +-deprecated({ag, 4}). +-deprecated({ag, 5}). +-deprecated({ag, 6}). +-deprecated({ag, 7}). +-deprecated({gn, 3}). +-deprecated({gn, 4}). +-deprecated({gn, 5}). +-deprecated({gn, 6}). +-deprecated({gn, 7}). +-deprecated({agn, 3}). +-deprecated({agn, 4}). +-deprecated({agn, 5}). +-deprecated({agn, 6}). +-deprecated({agn, 7}). +-deprecated({gb, 5}). +-deprecated({gb, 6}). +-deprecated({gb, 7}). +-deprecated({gb, 8}). +-deprecated({gb, 9}). +-deprecated({agb, 5}). +-deprecated({agb, 6}). +-deprecated({agb, 7}). +-deprecated({agb, 8}). +-deprecated({agb, 9}). +-deprecated({s, 3}). +-deprecated({s, 4}). +-deprecated({s, 5}). +-deprecated({s, 6}). +-deprecated({s, 7}). +-deprecated({as, 3}). +-deprecated({as, 4}). +-deprecated({as, 5}). +-deprecated({as, 6}). +-deprecated({as, 7}). -export([ agent_info/3, update_agent_info/5, g/3, g/4, g/5, g/6, g/7, @@ -106,12 +163,13 @@ -export([start_link/3, snmpm_start_verify/2, snmpm_start_verify/3]). --include("snmp_debug.hrl"). +-include_lib("snmp/src/misc/snmp_debug.hrl"). +-include_lib("snmp/include/snmp_types.hrl"). -include("snmpm_atl.hrl"). --include("snmp_types.hrl"). +-include("snmpm_internal.hrl"). +-include("snmp_verbosity.hrl"). -define(DEFAULT_AGENT_PORT, 161). --define(DEFAULT_CONTEXT, ""). %% This function is called when the snmp application @@ -330,23 +388,23 @@ register_agent(UserId, TargetName, Config) is_list(Config)) -> do_register_agent(UserId, TargetName, [{reg_type, target_name} | Config]); -%% Backward compatibillity +%% Backward compatibility %% Note that the agent engine id is a mandatory config option, %% so this function *will* fail! register_agent(UserId, Addr, Port) when is_integer(Port) -> register_agent(UserId, Addr, Port, []); -%% Backward compatibillity +%% Backward compatibility register_agent(UserId, Addr, Config) when is_list(Config) -> register_agent(UserId, Addr, ?DEFAULT_AGENT_PORT, Config). -%% Backward compatibillity +%% Backward compatibility %% Note that the agent engine id is a mandatory config option, %% so this function *will* fail! register_agent(UserId, Addr) -> register_agent(UserId, Addr, ?DEFAULT_AGENT_PORT, []). -%% Backward compatibillity +%% Backward compatibility register_agent(UserId, Addr, Port, Config0) -> case lists:keymember(target_name, 1, Config0) of false -> @@ -366,7 +424,7 @@ register_agent(UserId, Addr, Port, Config0) -> unregister_agent(UserId, TargetName) when is_list(TargetName) -> snmpm_config:unregister_agent(UserId, TargetName); -%% Backward compatibillity functions +%% Backward compatibility functions unregister_agent(UserId, Addr) -> unregister_agent(UserId, Addr, ?DEFAULT_AGENT_PORT). @@ -381,7 +439,7 @@ unregister_agent(UserId, Addr, Port) -> agent_info(TargetName, Item) -> snmpm_config:agent_info(TargetName, Item). -%% Backward compatibillity +%% Backward compatibility agent_info(Addr, Port, Item) -> case target_name(Addr, Port) of {ok, TargetName} -> @@ -390,25 +448,16 @@ agent_info(Addr, Port, Item) -> Error end. +update_agent_info(UserId, TargetName, Info) when is_list(Info) -> + snmpm_config:update_agent_info(UserId, TargetName, Info). + update_agent_info(UserId, TargetName, Item, Val) -> -%% p("update_agent_info -> entry with" -%% "~n UserId: ~p" -%% "~n TargetName: ~p" -%% "~n Item: ~p" -%% "~n Val: ~p", [UserId, TargetName, Item, Val]), - snmpm_config:update_agent_info(UserId, TargetName, Item, Val). - -%% Backward compatibillity functions + update_agent_info(UserId, TargetName, [{Item, Val}]). + +%% Backward compatibility functions update_agent_info(UserId, Addr, Port, Item, Val) -> -%% p("update_agent_info -> entry with" -%% "~n UserId: ~p" -%% "~n Addr: ~p" -%% "~n Port: ~p" -%% "~n Item: ~p" -%% "~n Val: ~p", [UserId, Addr, Port, Item, Val]), case target_name(Addr, Port) of {ok, TargetName} -> -%% p("update_agent_info -> TargetName: ~p", [TargetName]), update_agent_info(UserId, TargetName, Item, Val); Error -> Error @@ -470,47 +519,55 @@ which_usm_users(EngineID) when is_list(EngineID) -> %% --- synchroneous get-request --- %% +sync_get2(UserId, TargetName, Oids) -> + sync_get2(UserId, TargetName, Oids, []). + +sync_get2(UserId, TargetName, Oids, SendOpts) + when is_list(Oids) andalso is_list(SendOpts) -> + snmpm_server:sync_get2(UserId, TargetName, Oids, SendOpts). + +%% <BACKWARD-COMPAT> sync_get(UserId, TargetName, Oids) -> - sync_get(UserId, TargetName, ?DEFAULT_CONTEXT, Oids). - -sync_get(UserId, TargetName, {community, Community}, Oids) - when is_list(Oids) -> - CC = {?DEFAULT_CONTEXT, Community}, - snmpm_server:sync_get(UserId, TargetName, CC, Oids); -sync_get(UserId, TargetName, CC, Oids) when is_list(Oids) -> - snmpm_server:sync_get(UserId, TargetName, CC, Oids); -sync_get(UserId, TargetName, Oids, Timeout) when is_integer(Timeout) -> - sync_get(UserId, TargetName, ?DEFAULT_CONTEXT, Oids, Timeout). - -sync_get(UserId, TargetName, {community, Community}, Oids, Timeout) -> - CC = {?DEFAULT_CONTEXT, Community}, - snmpm_server:sync_get(UserId, TargetName, CC, Oids, Timeout); -sync_get(UserId, TargetName, CC, Oids, Timeout) -> - snmpm_server:sync_get(UserId, TargetName, CC, Oids, Timeout). - -sync_get(UserId, TargetName, {community, Community}, - Oids, Timeout, ExtraInfo) -> - CC = {?DEFAULT_CONTEXT, Community}, - snmpm_server:sync_get(UserId, TargetName, CC, Oids, Timeout, ExtraInfo); -sync_get(UserId, TargetName, CC, Oids, Timeout, ExtraInfo) -> - snmpm_server:sync_get(UserId, TargetName, CC, Oids, Timeout, ExtraInfo). + sync_get2(UserId, TargetName, Oids). + +sync_get(UserId, TargetName, Oids, Timeout) + when is_list(Oids) andalso is_integer(Timeout) -> + SendOpts = [{timeout, Timeout}], + sync_get2(UserId, TargetName, Oids, SendOpts); +sync_get(UserId, TargetName, Context, [OH|_] = Oids) + when is_list(Context) andalso is_list(OH) -> + SendOpts = [{context, Context}], + sync_get2(UserId, TargetName, Oids, SendOpts). + +sync_get(UserId, TargetName, Context, Oids, Timeout) -> + SendOpts = [{context, Context}, {timeout, Timeout}], + sync_get2(UserId, TargetName, Oids, SendOpts). +sync_get(UserId, TargetName, Context, Oids, Timeout, ExtraInfo) -> + SendOpts = [{context, Context}, {timeout, Timeout}, {extra, ExtraInfo}], + sync_get2(UserId, TargetName, Oids, SendOpts). +%% </BACKWARD-COMPAT> + +%% <DEPRECATED> g(UserId, Addr, Oids) -> g(UserId, Addr, ?DEFAULT_AGENT_PORT, Oids). +g(UserId, Addr, CtxName, Oids) when is_list(CtxName) andalso is_list(Oids) -> + g(UserId, Addr, ?DEFAULT_AGENT_PORT, CtxName, Oids); + g(UserId, Addr, Port, Oids) when is_integer(Port) andalso is_list(Oids) -> g(UserId, Addr, Port, ?DEFAULT_CONTEXT, Oids); -g(UserId, Addr, CC, Oids) when is_list(Oids) -> - g(UserId, Addr, ?DEFAULT_AGENT_PORT, CC, Oids); -g(UserId, Addr, Oids, Timeout) when is_integer(Timeout) -> + +g(UserId, Addr, Oids, Timeout) + when is_list(Oids) andalso is_integer(Timeout) -> g(UserId, Addr, ?DEFAULT_AGENT_PORT, Oids, Timeout). -g(UserId, Addr, Port, CC, Oids) - when is_integer(Port) andalso is_list(Oids) -> +g(UserId, Addr, Port, CtxName, Oids) + when is_integer(Port) andalso is_list(CtxName) andalso is_list(Oids) -> case target_name(Addr, Port) of {ok, TargetName} -> - sync_get(UserId, TargetName, CC, Oids); + sync_get(UserId, TargetName, CtxName, Oids); Error -> Error end; @@ -519,25 +576,26 @@ g(UserId, Addr, Port, Oids, Timeout) when is_integer(Port) andalso is_list(Oids) andalso is_integer(Timeout) -> g(UserId, Addr, Port, ?DEFAULT_CONTEXT, Oids, Timeout); -g(UserId, Addr, CC, Oids, Timeout) - when is_list(Oids) andalso is_integer(Timeout) -> - g(UserId, Addr, ?DEFAULT_AGENT_PORT, CC, Oids, Timeout). +g(UserId, Addr, CtxName, Oids, Timeout) + when is_list(CtxName) andalso is_list(Oids) andalso is_integer(Timeout) -> + g(UserId, Addr, ?DEFAULT_AGENT_PORT, CtxName, Oids, Timeout). -g(UserId, Addr, Port, CC, Oids, Timeout) -> +g(UserId, Addr, Port, CtxName, Oids, Timeout) -> case target_name(Addr, Port) of {ok, TargetName} -> - sync_get(UserId, TargetName, CC, Oids, Timeout); + sync_get(UserId, TargetName, CtxName, Oids, Timeout); Error -> Error end. -g(UserId, Addr, Port, CC, Oids, Timeout, ExtraInfo) -> +g(UserId, Addr, Port, CtxName, Oids, Timeout, ExtraInfo) -> case target_name(Addr, Port) of {ok, TargetName} -> - sync_get(UserId, TargetName, CC, Oids, Timeout, ExtraInfo); + sync_get(UserId, TargetName, CtxName, Oids, Timeout, ExtraInfo); Error -> Error end. +%% </DEPRECATED> @@ -547,48 +605,53 @@ g(UserId, Addr, Port, CC, Oids, Timeout, ExtraInfo) -> %% through a call to handle_pdu/5 %% +async_get2(UserId, TargetName, Oids) -> + async_get2(UserId, TargetName, Oids, []). + +async_get2(UserId, TargetName, Oids, SendOpts) + when is_list(Oids) andalso is_list(SendOpts) -> + snmpm_server:async_get2(UserId, TargetName, Oids, SendOpts). + +%% <BACKWARD-COMPAT> async_get(UserId, TargetName, Oids) -> - async_get(UserId, TargetName, ?DEFAULT_CONTEXT, Oids). - -async_get(UserId, TargetName, {community, Community}, Oids) - when is_list(Oids) -> - CC = {?DEFAULT_CONTEXT, Community}, - snmpm_server:async_get(UserId, TargetName, CC, Oids); -async_get(UserId, TargetName, CC, Oids) when is_list(Oids) -> - snmpm_server:async_get(UserId, TargetName, CC, Oids); + async_get2(UserId, TargetName, Oids). + async_get(UserId, TargetName, Oids, Expire) when is_integer(Expire) -> - async_get(UserId, TargetName, ?DEFAULT_CONTEXT, Oids, Expire). + SendOpts = [{timeout, Expire}], + async_get2(UserId, TargetName, Oids, SendOpts); +async_get(UserId, TargetName, Context, Oids) + when is_list(Context) andalso is_list(Oids) -> + SendOpts = [{context, Context}], + async_get2(UserId, TargetName, Oids, SendOpts). -async_get(UserId, TargetName, {community, Community}, Oids, Expire) -> - CC = {?DEFAULT_CONTEXT, Community}, - snmpm_server:async_get(UserId, TargetName, CC, Oids, Expire); -async_get(UserId, TargetName, CC, Oids, Expire) -> - snmpm_server:async_get(UserId, TargetName, CC, Oids, Expire). +async_get(UserId, TargetName, Context, Oids, Expire) -> + SendOpts = [{timeout, Expire}, {context, Context}], + async_get2(UserId, TargetName, Oids, SendOpts). -async_get(UserId, TargetName, {community, Community}, - Oids, Expire, ExtraInfo) -> - CC = {?DEFAULT_CONTEXT, Community}, - snmpm_server:async_get(UserId, TargetName, CC, Oids, Expire, ExtraInfo); -async_get(UserId, TargetName, CC, Oids, Expire, ExtraInfo) -> - snmpm_server:async_get(UserId, TargetName, CC, Oids, Expire, ExtraInfo). +async_get(UserId, TargetName, Context, Oids, Expire, ExtraInfo) -> + SendOpts = [{timeout, Expire}, {context, Context}, {extra, ExtraInfo}], + async_get2(UserId, TargetName, Oids, SendOpts). +%% </BACKWARD-COMPAT> +%% <DEPRECATED> ag(UserId, Addr, Oids) -> ag(UserId, Addr, ?DEFAULT_AGENT_PORT, Oids). ag(UserId, Addr, Port, Oids) when is_integer(Port) andalso is_list(Oids) -> ag(UserId, Addr, Port, ?DEFAULT_CONTEXT, Oids); -ag(UserId, Addr, Oids, Expire) when is_list(Oids) andalso is_integer(Expire) -> - ag(UserId, Addr, ?DEFAULT_AGENT_PORT, ?DEFAULT_CONTEXT, Oids, Expire); -ag(UserId, Addr, CC, Oids) when is_list(Oids) -> - ag(UserId, Addr, ?DEFAULT_AGENT_PORT, CC, Oids). +ag(UserId, Addr, CtxName, Oids) when is_list(CtxName) andalso is_list(Oids) -> + ag(UserId, Addr, ?DEFAULT_AGENT_PORT, CtxName, Oids); + +ag(UserId, Addr, Oids, Expire) when is_list(Oids) andalso is_integer(Expire) -> + ag(UserId, Addr, ?DEFAULT_AGENT_PORT, ?DEFAULT_CONTEXT, Oids, Expire). -ag(UserId, Addr, Port, CC, Oids) - when is_integer(Port) andalso is_list(Oids) -> +ag(UserId, Addr, Port, CtxName, Oids) + when is_integer(Port) andalso is_list(CtxName) andalso is_list(Oids) -> case target_name(Addr, Port) of {ok, TargetName} -> - async_get(UserId, TargetName, CC, Oids); + async_get(UserId, TargetName, CtxName, Oids); Error -> Error end; @@ -596,581 +659,709 @@ ag(UserId, Addr, Port, CC, Oids) ag(UserId, Addr, Port, Oids, Expire) when is_integer(Port) andalso is_list(Oids) andalso is_integer(Expire) -> ag(UserId, Addr, Port, ?DEFAULT_CONTEXT, Oids, Expire); -ag(UserId, Addr, CC, Oids, Expire) - when is_list(Oids) andalso is_integer(Expire) -> - ag(UserId, Addr, ?DEFAULT_AGENT_PORT, CC, Oids, Expire). -ag(UserId, Addr, Port, CC, Oids, Expire) -> +ag(UserId, Addr, CtxName, Oids, Expire) + when is_list(CtxName) andalso is_list(Oids) andalso is_integer(Expire) -> + ag(UserId, Addr, ?DEFAULT_AGENT_PORT, CtxName, Oids, Expire). + +ag(UserId, Addr, Port, CtxName, Oids, Expire) -> case target_name(Addr, Port) of {ok, TargetName} -> - async_get(UserId, TargetName, CC, Oids, Expire); + async_get(UserId, TargetName, CtxName, Oids, Expire); Error -> Error end. -ag(UserId, Addr, Port, CC, Oids, Expire, ExtraInfo) -> +ag(UserId, Addr, Port, CtxName, Oids, Expire, ExtraInfo) -> case target_name(Addr, Port) of {ok, TargetName} -> - async_get(UserId, TargetName, CC, Oids, Expire, ExtraInfo); + async_get(UserId, TargetName, CtxName, Oids, Expire, ExtraInfo); Error -> Error end. +%% </DEPRECATED> %% --- synchroneous get_next-request --- %% +sync_get_next2(UserId, TargetName, Oids) -> + sync_get_next2(UserId, TargetName, Oids, []). + +sync_get_next2(UserId, TargetName, Oids, SendOpts) + when is_list(Oids) andalso is_list(SendOpts) -> + snmpm_server:sync_get_next2(UserId, TargetName, Oids, SendOpts). + +%% <BACKWARD-COMPAT> sync_get_next(UserId, TargetName, Oids) -> - sync_get_next(UserId, TargetName, ?DEFAULT_CONTEXT, Oids). - -sync_get_next(UserId, TargetName, {community, Community}, Oids) - when is_list(Oids) -> - CC = {?DEFAULT_CONTEXT, Community}, - snmpm_server:sync_get_next(UserId, TargetName, CC, Oids); -sync_get_next(UserId, TargetName, CC, Oids) - when is_list(Oids) -> - snmpm_server:sync_get_next(UserId, TargetName, CC, Oids); -sync_get_next(UserId, TargetName, Oids, Timeout) - when is_integer(Timeout) -> - sync_get_next(UserId, TargetName, ?DEFAULT_CONTEXT, Oids, Timeout). + sync_get_next2(UserId, TargetName, Oids). +sync_get_next(UserId, TargetName, Oids, Timeout) + when is_list(Oids) andalso is_integer(Timeout) -> + SendOpts = [{timeout, Timeout}], + sync_get_next2(UserId, TargetName, Oids, SendOpts); +sync_get_next(UserId, TargetName, Context, Oids) + when is_list(Context) andalso is_list(Oids) -> + SendOpts = [{context, Context}], + sync_get_next2(UserId, TargetName, Oids, SendOpts). -sync_get_next(UserId, TargetName, {community, Community}, Oids, Timeout) -> - CC = {?DEFAULT_CONTEXT, Community}, - snmpm_server:sync_get_next(UserId, TargetName, CC, Oids, Timeout); -sync_get_next(UserId, TargetName, CC, Oids, Timeout) -> - snmpm_server:sync_get_next(UserId, TargetName, CC, Oids, Timeout). +sync_get_next(UserId, TargetName, Context, Oids, Timeout) -> + SendOpts = [{timeout, Timeout}, {context, Context}], + sync_get_next2(UserId, TargetName, Oids, SendOpts). -sync_get_next(UserId, TargetName, {community, Community}, - Oids, Timeout, ExtraInfo) -> - CC = {?DEFAULT_CONTEXT, Community}, - snmpm_server:sync_get_next(UserId, TargetName, CC, Oids, Timeout, - ExtraInfo); -sync_get_next(UserId, TargetName, CC, Oids, Timeout, ExtraInfo) -> - snmpm_server:sync_get_next(UserId, TargetName, CC, Oids, Timeout, - ExtraInfo). +sync_get_next(UserId, TargetName, Context, Oids, Timeout, ExtraInfo) -> + SendOpts = [{timeout, Timeout}, {context, Context}, {extra, ExtraInfo}], + sync_get_next2(UserId, TargetName, Oids, SendOpts). +%% </BACKWARD-COMPAT> +%% <DEPRECATED> gn(UserId, Addr, Oids) -> gn(UserId, Addr, ?DEFAULT_AGENT_PORT, Oids). +gn(UserId, Addr, CtxName, Oids) when is_list(CtxName) andalso is_list(Oids) -> + gn(UserId, Addr, ?DEFAULT_AGENT_PORT, CtxName, Oids); + +gn(UserId, Addr, Port, Oids) when is_integer(Port) andalso is_list(Oids) -> + gn(UserId, Addr, Port, ?DEFAULT_CONTEXT, Oids); + gn(UserId, Addr, Oids, Timeout) when is_list(Oids) andalso is_integer(Timeout) -> - gn(UserId, Addr, ?DEFAULT_AGENT_PORT, Oids, Timeout); -gn(UserId, Addr, Port, Oids) - when is_integer(Port) andalso is_list(Oids) -> - gn(UserId, Addr, Port, ?DEFAULT_CONTEXT, Oids); -gn(UserId, Addr, CC, Oids) - when is_list(Oids) -> - gn(UserId, Addr, ?DEFAULT_AGENT_PORT, CC, Oids). + gn(UserId, Addr, ?DEFAULT_AGENT_PORT, Oids, Timeout). -gn(UserId, Addr, Port, Oids, Timeout) - when is_integer(Port) andalso is_list(Oids) andalso is_integer(Timeout) -> - gn(UserId, Addr, Port, ?DEFAULT_CONTEXT, Oids, Timeout); -gn(UserId, Addr, Port, CC, Oids) - when is_integer(Port) andalso is_list(Oids) -> +gn(UserId, Addr, Port, CtxName, Oids) + when is_integer(Port) andalso is_list(CtxName) andalso is_list(Oids) -> case target_name(Addr, Port) of {ok, TargetName} -> - sync_get_next(UserId, TargetName, CC, Oids); + sync_get_next(UserId, TargetName, CtxName, Oids); Error -> Error end; -gn(UserId, Addr, CC, Oids, Timeout) - when is_list(Oids) andalso is_integer(Timeout) -> - gn(UserId, Addr, ?DEFAULT_AGENT_PORT, CC, Oids, Timeout). + +gn(UserId, Addr, Port, Oids, Timeout) + when is_integer(Port) andalso is_list(Oids) andalso is_integer(Timeout) -> + gn(UserId, Addr, Port, ?DEFAULT_CONTEXT, Oids, Timeout); +gn(UserId, Addr, CtxName, Oids, Timeout) + when is_list(CtxName) andalso is_list(Oids) andalso is_integer(Timeout) -> + gn(UserId, Addr, ?DEFAULT_AGENT_PORT, CtxName, Oids, Timeout). -gn(UserId, Addr, Port, CC, Oids, Timeout) -> +gn(UserId, Addr, Port, CtxName, Oids, Timeout) -> case target_name(Addr, Port) of {ok, TargetName} -> - sync_get_next(UserId, TargetName, CC, Oids, Timeout); + sync_get_next(UserId, TargetName, CtxName, Oids, Timeout); Error -> Error end. -gn(UserId, Addr, Port, CC, Oids, Timeout, ExtraInfo) -> +gn(UserId, Addr, Port, CtxName, Oids, Timeout, ExtraInfo) -> case target_name(Addr, Port) of {ok, TargetName} -> - sync_get_next(UserId, TargetName, CC, Oids, Timeout, ExtraInfo); + sync_get_next(UserId, TargetName, CtxName, Oids, Timeout, ExtraInfo); Error -> Error end. +%% </DEPRECATED> %% --- asynchroneous get_next-request --- %% +async_get_next2(UserId, TargetName, Oids) -> + async_get_next2(UserId, TargetName, Oids, []). + +async_get_next2(UserId, TargetName, Oids, SendOpts) + when is_list(Oids) andalso is_list(SendOpts) -> + snmpm_server:async_get_next2(UserId, TargetName, Oids, SendOpts). + +%% <BACKWARD-COMPAT> async_get_next(UserId, TargetName, Oids) -> - async_get_next(UserId, TargetName, ?DEFAULT_CONTEXT, Oids). - -async_get_next(UserId, TargetName, {community, Community}, Oids) - when is_list(Oids) -> - CC = {?DEFAULT_CONTEXT, Community}, - snmpm_server:async_get_next(UserId, TargetName, CC, Oids); -async_get_next(UserId, TargetName, CC, Oids) - when is_list(Oids) -> - snmpm_server:async_get_next(UserId, TargetName, CC, Oids); -async_get_next(UserId, TargetName, Oids, Timeout) - when is_integer(Timeout) -> - async_get_next(UserId, TargetName, ?DEFAULT_CONTEXT, Oids, Timeout). - -async_get_next(UserId, TargetName, {community, Community}, Oids, Timeout) -> - CC = {?DEFAULT_CONTEXT, Community}, - snmpm_server:async_get_next(UserId, TargetName, CC, Oids, Timeout); -async_get_next(UserId, TargetName, CC, Oids, Timeout) -> - snmpm_server:async_get_next(UserId, TargetName, CC, Oids, Timeout). - -async_get_next(UserId, TargetName, {community, Community}, - Oids, Timeout, ExtraInfo) -> - CC = {?DEFAULT_CONTEXT, Community}, - snmpm_server:async_get_next(UserId, TargetName, CC, Oids, Timeout, - ExtraInfo); -async_get_next(UserId, TargetName, CC, Oids, Timeout, ExtraInfo) -> - snmpm_server:async_get_next(UserId, TargetName, CC, Oids, Timeout, - ExtraInfo). + async_get_next2(UserId, TargetName, Oids). +async_get_next(UserId, TargetName, Oids, Expire) + when is_list(Oids) andalso is_integer(Expire) -> + SendOpts = [{timeout, Expire}], + async_get_next2(UserId, TargetName, Oids, SendOpts); +async_get_next(UserId, TargetName, Context, Oids) + when is_list(Context) andalso is_list(Oids) -> + SendOpts = [{context, Context}], + async_get_next2(UserId, TargetName, Oids, SendOpts). + +async_get_next(UserId, TargetName, Context, Oids, Expire) -> + SendOpts = [{timeout, Expire}, {context, Context}], + async_get_next2(UserId, TargetName, Oids, SendOpts). + +async_get_next(UserId, TargetName, Context, Oids, Expire, ExtraInfo) -> + SendOpts = [{timeout, Expire}, {context, Context}, {extra, ExtraInfo}], + async_get_next2(UserId, TargetName, Oids, SendOpts). +%% </BACKWARD-COMPAT> + + +%% <DEPRECATED> agn(UserId, Addr, Oids) -> agn(UserId, Addr, ?DEFAULT_AGENT_PORT, Oids). +agn(UserId, Addr, CtxName, Oids) when is_list(CtxName) andalso is_list(Oids) -> + agn(UserId, Addr, ?DEFAULT_AGENT_PORT, CtxName, Oids); + +agn(UserId, Addr, Port, Oids) when is_integer(Port) andalso is_list(Oids) -> + agn(UserId, Addr, Port, ?DEFAULT_CONTEXT, Oids); + agn(UserId, Addr, Oids, Expire) when is_list(Oids) andalso is_integer(Expire) -> - agn(UserId, Addr, ?DEFAULT_AGENT_PORT, Oids, Expire); -agn(UserId, Addr, Port, Oids) - when is_integer(Port) andalso is_list(Oids) -> - agn(UserId, Addr, Port, ?DEFAULT_CONTEXT, Oids); -agn(UserId, Addr, CC, Oids) - when is_list(Oids) -> - agn(UserId, Addr, ?DEFAULT_AGENT_PORT, CC, Oids). + agn(UserId, Addr, ?DEFAULT_AGENT_PORT, Oids, Expire). -agn(UserId, Addr, Port, Oids, Expire) - when is_integer(Port) andalso is_integer(Expire) -> - agn(UserId, Addr, Port, ?DEFAULT_CONTEXT, Oids, Expire); -agn(UserId, Addr, CC, Oids, Expire) - when is_integer(Expire) -> - agn(UserId, Addr, ?DEFAULT_AGENT_PORT, CC, Oids, Expire); -agn(UserId, Addr, Port, CC, Oids) - when is_integer(Port) andalso is_list(Oids) -> +agn(UserId, Addr, Port, CtxName, Oids) + when is_integer(Port) andalso is_list(CtxName) andalso is_list(Oids) -> case target_name(Addr, Port) of {ok, TargetName} -> - async_get_next(UserId, TargetName, CC, Oids); + async_get_next(UserId, TargetName, CtxName, Oids); Error -> Error - end. + end; + +agn(UserId, Addr, Port, Oids, Expire) + when is_integer(Port) andalso is_list(Oids) andalso is_integer(Expire) -> + agn(UserId, Addr, Port, ?DEFAULT_CONTEXT, Oids, Expire); +agn(UserId, Addr, CtxName, Oids, Expire) + when is_list(CtxName) andalso is_list(CtxName) andalso is_integer(Expire) -> + agn(UserId, Addr, ?DEFAULT_AGENT_PORT, CtxName, Oids, Expire). -agn(UserId, Addr, Port, CC, Oids, Expire) -> +agn(UserId, Addr, Port, CtxName, Oids, Expire) -> case target_name(Addr, Port) of {ok, TargetName} -> - async_get_next(UserId, TargetName, CC, Oids, Expire); + async_get_next(UserId, TargetName, CtxName, Oids, Expire); Error -> Error end. -agn(UserId, Addr, Port, CC, Oids, Expire, ExtraInfo) -> +agn(UserId, Addr, Port, CtxName, Oids, Expire, ExtraInfo) -> case target_name(Addr, Port) of {ok, TargetName} -> - async_get_next(UserId, TargetName, CC, Oids, Expire, ExtraInfo); + async_get_next(UserId, TargetName, CtxName, Oids, Expire, + ExtraInfo); Error -> Error end. +%% </DEPRECATED> %% --- synchroneous set-request --- %% +sync_set2(UserId, TargetName, VarsAndVals) -> + sync_set2(UserId, TargetName, VarsAndVals, []). + +sync_set2(UserId, TargetName, VarsAndVals, SendOpts) + when is_list(VarsAndVals) andalso is_list(SendOpts) -> + snmpm_server:sync_set2(UserId, TargetName, VarsAndVals, SendOpts). + +%% <BACKWARD-COMPAT> sync_set(UserId, TargetName, VarsAndVals) -> - sync_set(UserId, TargetName, ?DEFAULT_CONTEXT, VarsAndVals). + sync_set2(UserId, TargetName, VarsAndVals). sync_set(UserId, TargetName, VarsAndVals, Timeout) when is_list(VarsAndVals) andalso is_integer(Timeout) -> - sync_set(UserId, TargetName, ?DEFAULT_CONTEXT, VarsAndVals, Timeout); -sync_set(UserId, TargetName, {community, Community}, VarsAndVals) - when is_list(VarsAndVals) -> - CC = {?DEFAULT_CONTEXT, Community}, - snmpm_server:sync_set(UserId, TargetName, CC, VarsAndVals); -sync_set(UserId, TargetName, CC, VarsAndVals) - when is_list(VarsAndVals) -> - snmpm_server:sync_set(UserId, TargetName, CC, VarsAndVals). - -sync_set(UserId, TargetName, {community, Community}, VarsAndVals, Timeout) -> - CC = {?DEFAULT_CONTEXT, Community}, - snmpm_server:sync_set(UserId, TargetName, CC, VarsAndVals, Timeout); -sync_set(UserId, TargetName, CC, VarsAndVals, Timeout) -> - snmpm_server:sync_set(UserId, TargetName, CC, VarsAndVals, Timeout). - -sync_set(UserId, TargetName, {community, Community}, - VarsAndVals, Timeout, ExtraInfo) -> - CC = {?DEFAULT_CONTEXT, Community}, - snmpm_server:sync_set(UserId, TargetName, CC, VarsAndVals, Timeout, - ExtraInfo); -sync_set(UserId, TargetName, CC, VarsAndVals, Timeout, ExtraInfo) -> - snmpm_server:sync_set(UserId, TargetName, CC, VarsAndVals, Timeout, - ExtraInfo). + SendOpts = [{timeout, Timeout}], + sync_set2(UserId, TargetName, VarsAndVals, SendOpts); +sync_set(UserId, TargetName, Context, VarsAndVals) + when is_list(Context) andalso is_list(VarsAndVals) -> + SendOpts = [{context, Context}], + sync_set2(UserId, TargetName, VarsAndVals, SendOpts). + +sync_set(UserId, TargetName, Context, VarsAndVals, Timeout) -> + SendOpts = [{timeout, Timeout}, {context, Context}], + sync_set2(UserId, TargetName, VarsAndVals, SendOpts). +sync_set(UserId, TargetName, Context, VarsAndVals, Timeout, ExtraInfo) -> + SendOpts = [{timeout, Timeout}, {context, Context}, {extra, ExtraInfo}], + sync_set2(UserId, TargetName, VarsAndVals, SendOpts). +%% </BACKWARD-COMPAT> + +%% <DEPRECATED> s(UserId, Addr, VarsAndVals) -> s(UserId, Addr, ?DEFAULT_AGENT_PORT, VarsAndVals). s(UserId, Addr, Port, VarsAndVals) when is_integer(Port) andalso is_list(VarsAndVals) -> s(UserId, Addr, Port, ?DEFAULT_CONTEXT, VarsAndVals); + +s(UserId, Addr, CtxName, VarsAndVals) + when is_list(CtxName) andalso is_list(VarsAndVals) -> + s(UserId, Addr, ?DEFAULT_AGENT_PORT, CtxName, VarsAndVals); + s(UserId, Addr, VarsAndVals, Timeout) when is_list(VarsAndVals) andalso is_integer(Timeout) -> - s(UserId, Addr, ?DEFAULT_AGENT_PORT, VarsAndVals, Timeout); -s(UserId, Addr, CC, VarsAndVals) - when is_list(VarsAndVals) -> - s(UserId, Addr, ?DEFAULT_AGENT_PORT, CC, VarsAndVals). - + s(UserId, Addr, ?DEFAULT_AGENT_PORT, VarsAndVals, Timeout). -s(UserId, Addr, Port, VarsAndVals, Timeout) +s(UserId, Addr, Port, CtxName, VarsAndVals) when is_integer(Port) andalso - is_list(VarsAndVals) andalso - is_integer(Timeout) -> - s(UserId, Addr, Port, ?DEFAULT_CONTEXT, VarsAndVals, Timeout); -s(UserId, Addr, Port, CC, VarsAndVals) - when is_integer(Port) andalso is_list(VarsAndVals) -> + is_list(CtxName) andalso + is_list(VarsAndVals) -> case target_name(Addr, Port) of {ok, TargetName} -> - sync_set(UserId, TargetName, CC, VarsAndVals); + sync_set(UserId, TargetName, CtxName, VarsAndVals); Error -> Error end; -s(UserId, Addr, CC, VarsAndVals, Timeout) - when is_list(VarsAndVals) andalso is_integer(Timeout) -> - s(UserId, Addr, ?DEFAULT_AGENT_PORT, CC, VarsAndVals, Timeout). -s(UserId, Addr, Port, CC, VarsAndVals, Timeout) -> +s(UserId, Addr, Port, VarsAndVals, Timeout) + when is_integer(Port) andalso + is_list(VarsAndVals) andalso + is_integer(Timeout) -> + s(UserId, Addr, Port, ?DEFAULT_CONTEXT, VarsAndVals, Timeout); + +s(UserId, Addr, CtxName, VarsAndVals, Timeout) + when is_list(CtxName) andalso + is_list(VarsAndVals) andalso + is_integer(Timeout) -> + s(UserId, Addr, ?DEFAULT_AGENT_PORT, CtxName, VarsAndVals, Timeout). + +s(UserId, Addr, Port, CtxName, VarsAndVals, Timeout) -> case target_name(Addr, Port) of {ok, TargetName} -> - sync_set(UserId, TargetName, CC, VarsAndVals, Timeout); + sync_set(UserId, TargetName, CtxName, VarsAndVals, Timeout); Error -> Error end. -s(UserId, Addr, Port, CC, VarsAndVals, Timeout, ExtraInfo) -> +s(UserId, Addr, Port, CtxName, VarsAndVals, Timeout, ExtraInfo) -> case target_name(Addr, Port) of {ok, TargetName} -> - sync_set(UserId, TargetName, CC, VarsAndVals, Timeout, ExtraInfo); + sync_set(UserId, TargetName, CtxName, VarsAndVals, Timeout, ExtraInfo); Error -> Error end. +%% </DEPRECATED> %% --- asynchroneous set-request --- %% +async_set2(UserId, TargetName, VarsAndVals) -> + async_set2(UserId, TargetName, VarsAndVals, []). + +async_set2(UserId, TargetName, VarsAndVals, SendOpts) + when is_list(VarsAndVals) andalso is_list(SendOpts) -> + snmpm_server:async_set2(UserId, TargetName, VarsAndVals, SendOpts). + +%% <BACKWARD-COMPAT> async_set(UserId, TargetName, VarsAndVals) -> - async_set(UserId, TargetName, ?DEFAULT_CONTEXT, VarsAndVals). + async_set2(UserId, TargetName, VarsAndVals). async_set(UserId, TargetName, VarsAndVals, Expire) when is_list(VarsAndVals) andalso is_integer(Expire) -> - async_set(UserId, TargetName, ?DEFAULT_CONTEXT, VarsAndVals, Expire); -async_set(UserId, TargetName, {community, Community}, VarsAndVals) - when is_list(VarsAndVals) -> - CC = {?DEFAULT_CONTEXT, Community}, - snmpm_server:async_set(UserId, TargetName, CC, VarsAndVals); -async_set(UserId, TargetName, CC, VarsAndVals) - when is_list(VarsAndVals) -> - snmpm_server:async_set(UserId, TargetName, CC, VarsAndVals). - -async_set(UserId, TargetName, {community, Community}, VarsAndVals, Expire) -> - CC = {?DEFAULT_CONTEXT, Community}, - snmpm_server:async_set(UserId, TargetName, CC, VarsAndVals, Expire); -async_set(UserId, TargetName, CC, VarsAndVals, Expire) -> - snmpm_server:async_set(UserId, TargetName, CC, VarsAndVals, Expire). - -async_set(UserId, TargetName, {community, Community}, - VarsAndVals, Expire, ExtraInfo) -> - CC = {?DEFAULT_CONTEXT, Community}, - snmpm_server:async_set(UserId, TargetName, CC, VarsAndVals, Expire, - ExtraInfo); -async_set(UserId, TargetName, CC, VarsAndVals, Expire, ExtraInfo) -> - snmpm_server:async_set(UserId, TargetName, CC, VarsAndVals, Expire, - ExtraInfo). + SendOpts = [{timeout, Expire}], + async_set2(UserId, TargetName, VarsAndVals, SendOpts); +async_set(UserId, TargetName, Context, VarsAndVals) + when is_list(Context) andalso is_list(VarsAndVals) -> + SendOpts = [{context, Context}], + async_set2(UserId, TargetName, VarsAndVals, SendOpts). + +async_set(UserId, TargetName, Context, VarsAndVals, Expire) -> + SendOpts = [{timeout, Expire}, {context, Context}], + async_set2(UserId, TargetName, VarsAndVals, SendOpts). +async_set(UserId, TargetName, Context, VarsAndVals, Expire, ExtraInfo) -> + SendOpts = [{timeout, Expire}, {context, Context}, {extra, ExtraInfo}], + async_set2(UserId, TargetName, VarsAndVals, SendOpts). +%% </BACKWARD-COMPAT> + +%% <DEPRECATED> as(UserId, Addr, VarsAndVals) -> as(UserId, Addr, ?DEFAULT_AGENT_PORT, VarsAndVals). -as(UserId, Addr, VarsAndVals, Expire) - when is_list(VarsAndVals) andalso is_integer(Expire) -> - as(UserId, Addr, ?DEFAULT_AGENT_PORT, VarsAndVals, Expire); as(UserId, Addr, Port, VarsAndVals) when is_integer(Port) andalso is_list(VarsAndVals) -> as(UserId, Addr, Port, ?DEFAULT_CONTEXT, VarsAndVals); -as(UserId, Addr, CC, VarsAndVals) - when is_list(VarsAndVals) -> - as(UserId, Addr, ?DEFAULT_AGENT_PORT, CC, VarsAndVals). +as(UserId, Addr, CtxName, VarsAndVals) + when is_list(CtxName) andalso is_list(VarsAndVals) -> + as(UserId, Addr, ?DEFAULT_AGENT_PORT, CtxName, VarsAndVals); -as(UserId, Addr, Port, VarsAndVals, Expire) +as(UserId, Addr, VarsAndVals, Expire) + when is_list(VarsAndVals) andalso is_integer(Expire) -> + as(UserId, Addr, ?DEFAULT_AGENT_PORT, VarsAndVals, Expire). + +as(UserId, Addr, Port, CtxName, VarsAndVals) when is_integer(Port) andalso - is_list(VarsAndVals) andalso - is_integer(Expire) -> - as(UserId, Addr, Port, ?DEFAULT_CONTEXT, VarsAndVals, Expire); -as(UserId, Addr, Port, CC, VarsAndVals) - when is_integer(Port) andalso is_list(VarsAndVals) -> + is_list(CtxName) andalso + is_list(VarsAndVals) -> case target_name(Addr, Port) of {ok, TargetName} -> - async_set(UserId, TargetName, CC, VarsAndVals); + async_set(UserId, TargetName, CtxName, VarsAndVals); Error -> Error end; -as(UserId, Addr, CC, VarsAndVals, Expire) - when is_list(VarsAndVals) andalso is_integer(Expire) -> - as(UserId, Addr, ?DEFAULT_AGENT_PORT, CC, VarsAndVals, Expire). + +as(UserId, Addr, Port, VarsAndVals, Expire) + when is_integer(Port) andalso + is_list(VarsAndVals) andalso + is_integer(Expire) -> + as(UserId, Addr, Port, ?DEFAULT_CONTEXT, VarsAndVals, Expire); + +as(UserId, Addr, CtxName, VarsAndVals, Expire) + when is_list(CtxName) andalso + is_list(VarsAndVals) andalso + is_integer(Expire) -> + as(UserId, Addr, ?DEFAULT_AGENT_PORT, CtxName, VarsAndVals, Expire). -as(UserId, Addr, Port, CC, VarsAndVals, Expire) -> +as(UserId, Addr, Port, CtxName, VarsAndVals, Expire) -> case target_name(Addr, Port) of {ok, TargetName} -> - async_set(UserId, TargetName, CC, VarsAndVals, Expire); + async_set(UserId, TargetName, CtxName, VarsAndVals, Expire); Error -> Error end. -as(UserId, Addr, Port, CC, VarsAndVals, Expire, ExtraInfo) -> +as(UserId, Addr, Port, CtxName, VarsAndVals, Expire, ExtraInfo) -> case target_name(Addr, Port) of {ok, TargetName} -> - async_set(UserId, TargetName, CC, VarsAndVals, Expire, ExtraInfo); + async_set(UserId, TargetName, CtxName, VarsAndVals, Expire, ExtraInfo); Error -> Error end. - - +%% </DEPRECATED> %% --- synchroneous get-bulk --- %% +sync_get_bulk2(UserId, TargetName, NonRep, MaxRep, Oids) -> + sync_get_bulk2(UserId, TargetName, NonRep, MaxRep, Oids, []). + +sync_get_bulk2(UserId, TargetName, NonRep, MaxRep, Oids, SendOpts) + when is_integer(NonRep) andalso + is_integer(MaxRep) andalso + is_list(Oids) andalso + is_list(SendOpts) -> + %% p("sync_get_bulk -> entry with" + %% "~n UserId: ~p" + %% "~n TargetName: ~p" + %% "~n NonRep: ~p" + %% "~n MaxRep: ~p" + %% "~n Oids: ~p" + %% "~n SendOpts: ~p", + %% [UserId, TargetName, NonRep, MaxRep, Oids, SendOpts]), + snmpm_server:sync_get_bulk2(UserId, TargetName, + NonRep, MaxRep, Oids, SendOpts). + +%% <BACKWARD-COMPAT> sync_get_bulk(UserId, TargetName, NonRep, MaxRep, Oids) -> - sync_get_bulk(UserId, TargetName, NonRep, MaxRep, ?DEFAULT_CONTEXT, Oids). + sync_get_bulk2(UserId, TargetName, NonRep, MaxRep, Oids). sync_get_bulk(UserId, TargetName, NonRep, MaxRep, Oids, Timeout) when is_integer(NonRep) andalso is_integer(MaxRep) andalso is_list(Oids) andalso is_integer(Timeout) -> - sync_get_bulk(UserId, TargetName, NonRep, MaxRep, - ?DEFAULT_CONTEXT, Oids, Timeout); -sync_get_bulk(UserId, TargetName, - NonRep, MaxRep, {community, Community}, Oids) + SendOpts = [{timeout, Timeout}], + sync_get_bulk2(UserId, TargetName, NonRep, MaxRep, Oids, SendOpts); +sync_get_bulk(UserId, TargetName, NonRep, MaxRep, Context, Oids) when is_integer(NonRep) andalso is_integer(MaxRep) andalso + is_list(Context) andalso is_list(Oids) -> - CC = {?DEFAULT_CONTEXT, Community}, - snmpm_server:sync_get_bulk(UserId, TargetName, - NonRep, MaxRep, - CC, Oids); -sync_get_bulk(UserId, TargetName, NonRep, MaxRep, CC, Oids) - when is_integer(NonRep) andalso - is_integer(MaxRep) andalso - is_list(Oids) -> - snmpm_server:sync_get_bulk(UserId, TargetName, - NonRep, MaxRep, - CC, Oids). - -sync_get_bulk(UserId, TargetName, - NonRep, MaxRep, {community, Community}, Oids, Timeout) -> - CC = {?DEFAULT_CONTEXT, Community}, - snmpm_server:sync_get_bulk(UserId, TargetName, - NonRep, MaxRep, CC, Oids, Timeout); -sync_get_bulk(UserId, TargetName, NonRep, MaxRep, CC, Oids, Timeout) -> - snmpm_server:sync_get_bulk(UserId, TargetName, - NonRep, MaxRep, CC, Oids, Timeout). - -sync_get_bulk(UserId, TargetName, - NonRep, MaxRep, {community, Community}, - Oids, Timeout, ExtraInfo) -> - CC = {?DEFAULT_CONTEXT, Community}, - snmpm_server:sync_get_bulk(UserId, TargetName, - NonRep, MaxRep, CC, Oids, Timeout, ExtraInfo); -sync_get_bulk(UserId, TargetName, NonRep, MaxRep, CC, Oids, Timeout, + %% p("sync_get_bulk -> entry with" + %% "~n UserId: ~p" + %% "~n TargetName: ~p" + %% "~n NonRep: ~p" + %% "~n MaxRep: ~p" + %% "~n Context: ~p" + %% "~n Oids: ~p", [UserId, TargetName, NonRep, MaxRep, Context, Oids]), + SendOpts = [{context, Context}], + sync_get_bulk2(UserId, TargetName, NonRep, MaxRep, Oids, SendOpts). + +sync_get_bulk(UserId, TargetName, NonRep, MaxRep, Context, Oids, Timeout) -> + SendOpts = [{timeout, Timeout}, {context, Context}], + sync_get_bulk2(UserId, TargetName, NonRep, MaxRep, Oids, SendOpts). + +sync_get_bulk(UserId, TargetName, NonRep, MaxRep, Context, Oids, Timeout, ExtraInfo) -> - snmpm_server:sync_get_bulk(UserId, TargetName, - NonRep, MaxRep, CC, Oids, Timeout, ExtraInfo). + SendOpts = [{timeout, Timeout}, {context, Context}, {extra, ExtraInfo}], + sync_get_bulk2(UserId, TargetName, NonRep, MaxRep, Oids, SendOpts). +%% </BACKWARD-COMPAT> +%% <DEPRECATED> gb(UserId, Addr, NonRep, MaxRep, Oids) -> + %% p("gb -> entry with" + %% "~n UserId: ~p" + %% "~n Addr: ~p" + %% "~n NonRep: ~p" + %% "~n MaxRep: ~p" + %% "~n Oids: ~p", + %% [UserId, Addr, NonRep, MaxRep, Oids]), gb(UserId, Addr, ?DEFAULT_AGENT_PORT, NonRep, MaxRep, Oids). -gb(UserId, Addr, NonRep, MaxRep, Oids, Timeout) - when is_integer(NonRep) andalso - is_integer(MaxRep) andalso - is_list(Oids) andalso - is_integer(Timeout) -> - gb(UserId, Addr, ?DEFAULT_AGENT_PORT, NonRep, MaxRep, Oids, Timeout); gb(UserId, Addr, Port, NonRep, MaxRep, Oids) when is_integer(Port) andalso is_integer(NonRep) andalso is_integer(MaxRep) andalso is_list(Oids) -> + %% p("gb -> entry with" + %% "~n UserId: ~p" + %% "~n Addr: ~p" + %% "~n Port: ~p" + %% "~n NonRep: ~p" + %% "~n MaxRep: ~p" + %% "~n Oids: ~p", + %% [UserId, Addr, Port, NonRep, MaxRep, Oids]), gb(UserId, Addr, Port, NonRep, MaxRep, ?DEFAULT_CONTEXT, Oids); -gb(UserId, Addr, NonRep, MaxRep, CC, Oids) + +gb(UserId, Addr, NonRep, MaxRep, CtxName, Oids) when is_integer(NonRep) andalso is_integer(MaxRep) andalso + is_list(CtxName) andalso is_list(Oids) -> - gb(UserId, Addr, ?DEFAULT_AGENT_PORT, NonRep, MaxRep, CC, Oids). + %% p("gb -> entry with" + %% "~n UserId: ~p" + %% "~n Addr: ~p" + %% "~n NonRep: ~p" + %% "~n MaxRep: ~p" + %% "~n CtxName: ~p" + %% "~n Oids: ~p", + %% [UserId, Addr, NonRep, MaxRep, CtxName, Oids]), + gb(UserId, Addr, ?DEFAULT_AGENT_PORT, NonRep, MaxRep, CtxName, Oids); -gb(UserId, Addr, Port, NonRep, MaxRep, Oids, Timeout) - when is_integer(Port) andalso - is_integer(NonRep) andalso - is_integer(MaxRep) andalso - is_list(Oids) andalso - is_integer(Timeout) -> - gb(UserId, Addr, Port, NonRep, MaxRep, ?DEFAULT_CONTEXT, Oids, Timeout); -gb(UserId, Addr, NonRep, MaxRep, CC, Oids, Timeout) +gb(UserId, Addr, NonRep, MaxRep, Oids, Timeout) when is_integer(NonRep) andalso is_integer(MaxRep) andalso is_list(Oids) andalso is_integer(Timeout) -> - gb(UserId, Addr, ?DEFAULT_AGENT_PORT, NonRep, MaxRep, CC, Oids, Timeout); -gb(UserId, Addr, Port, NonRep, MaxRep, CC, Oids) + %% p("gb -> entry with" + %% "~n UserId: ~p" + %% "~n Addr: ~p" + %% "~n NonRep: ~p" + %% "~n MaxRep: ~p" + %% "~n Oids: ~p" + %% "~n Timeout: ~p", + %% [UserId, Addr, NonRep, MaxRep, Oids, Timeout]), + gb(UserId, Addr, ?DEFAULT_AGENT_PORT, NonRep, MaxRep, Oids, Timeout). + +gb(UserId, Addr, Port, NonRep, MaxRep, CtxName, Oids) when is_integer(Port) andalso is_integer(NonRep) andalso is_integer(MaxRep) andalso + is_list(CtxName) andalso is_list(Oids) -> + %% p("gb -> entry with" + %% "~n UserId: ~p" + %% "~n Addr: ~p" + %% "~n Port: ~p" + %% "~n NonRep: ~p" + %% "~n MaxRep: ~p" + %% "~n CtxName: ~p" + %% "~n Oids: ~p", + %% [UserId, Addr, Port, NonRep, MaxRep, CtxName, Oids]), case target_name(Addr, Port) of {ok, TargetName} -> - sync_get_bulk(UserId, TargetName, NonRep, MaxRep, CC, Oids); + %% p("gb -> TargetName: ~p", [TargetName]), + sync_get_bulk(UserId, TargetName, NonRep, MaxRep, CtxName, Oids); Error -> Error - end. + end; -gb(UserId, Addr, Port, NonRep, MaxRep, CC, Oids, Timeout) -> +gb(UserId, Addr, Port, NonRep, MaxRep, Oids, Timeout) + when is_integer(Port) andalso + is_integer(NonRep) andalso + is_integer(MaxRep) andalso + is_list(Oids) andalso + is_integer(Timeout) -> + %% p("gb -> entry with" + %% "~n UserId: ~p" + %% "~n Addr: ~p" + %% "~n Port: ~p" + %% "~n NonRep: ~p" + %% "~n MaxRep: ~p" + %% "~n Oids: ~p" + %% "~n Timeout: ~p", + %% [UserId, Addr, Port, NonRep, MaxRep, Oids, Timeout]), + gb(UserId, Addr, Port, NonRep, MaxRep, ?DEFAULT_CONTEXT, Oids, Timeout); + +gb(UserId, Addr, NonRep, MaxRep, CtxName, Oids, Timeout) + when is_integer(NonRep) andalso + is_integer(MaxRep) andalso + is_list(CtxName) andalso + is_list(Oids) andalso + is_integer(Timeout) -> + %% p("gb -> entry with" + %% "~n UserId: ~p" + %% "~n Addr: ~p" + %% "~n NonRep: ~p" + %% "~n MaxRep: ~p" + %% "~n CtxName: ~p" + %% "~n Oids: ~p" + %% "~n Timeout: ~p", + %% [UserId, Addr, NonRep, MaxRep, CtxName, Oids, Timeout]), + gb(UserId, Addr, ?DEFAULT_AGENT_PORT, NonRep, MaxRep, CtxName, Oids, + Timeout). + +gb(UserId, Addr, Port, NonRep, MaxRep, CtxName, Oids, Timeout) -> + %% p("gb -> entry with" + %% "~n UserId: ~p" + %% "~n Addr: ~p" + %% "~n Port: ~p" + %% "~n NonRep: ~p" + %% "~n MaxRep: ~p" + %% "~n CtxName: ~p" + %% "~n Oids: ~p" + %% "~n Timeout: ~p", + %% [UserId, Addr, Port, NonRep, MaxRep, CtxName, Oids, Timeout]), case target_name(Addr, Port) of {ok, TargetName} -> sync_get_bulk(UserId, TargetName, - NonRep, MaxRep, CC, Oids, Timeout); + NonRep, MaxRep, CtxName, Oids, Timeout); Error -> Error end. -gb(UserId, Addr, Port, NonRep, MaxRep, CC, Oids, Timeout, ExtraInfo) -> +gb(UserId, Addr, Port, NonRep, MaxRep, CtxName, Oids, Timeout, ExtraInfo) -> + %% p("gb -> entry with" + %% "~n UserId: ~p" + %% "~n Addr: ~p" + %% "~n Port: ~p" + %% "~n NonRep: ~p" + %% "~n MaxRep: ~p" + %% "~n CtxName: ~p" + %% "~n Oids: ~p" + %% "~n Timeout: ~p" + %% "~n ExtraInfo: ~p", + %% [UserId, Addr, Port, NonRep, MaxRep, CtxName, Oids, Timeout, ExtraInfo]), case target_name(Addr, Port) of {ok, TargetName} -> sync_get_bulk(UserId, TargetName, - NonRep, MaxRep, CC, Oids, Timeout, ExtraInfo); + NonRep, MaxRep, CtxName, Oids, Timeout, ExtraInfo); Error -> Error end. +%% </DEPRECATED> %% --- asynchroneous get-bulk --- %% +async_get_bulk2(UserId, TargetName, NonRep, MaxRep, Oids) -> + async_get_bulk2(UserId, TargetName, NonRep, MaxRep, Oids, []). + +async_get_bulk2(UserId, TargetName, NonRep, MaxRep, Oids, SendOpts) + when is_integer(NonRep) andalso + is_integer(MaxRep) andalso + is_list(Oids) andalso + is_list(SendOpts) -> + snmpm_server:async_get_bulk2(UserId, TargetName, + NonRep, MaxRep, Oids, SendOpts). + +%% <BACKWARD-COMPAT> async_get_bulk(UserId, TargetName, NonRep, MaxRep, Oids) -> - async_get_bulk(UserId, TargetName, NonRep, MaxRep, ?DEFAULT_CONTEXT, Oids). + async_get_bulk2(UserId, TargetName, NonRep, MaxRep, Oids). async_get_bulk(UserId, TargetName, NonRep, MaxRep, Oids, Expire) when is_integer(NonRep) andalso is_integer(MaxRep) andalso is_list(Oids) andalso is_integer(Expire) -> - async_get_bulk(UserId, TargetName, - NonRep, MaxRep, ?DEFAULT_CONTEXT, Oids, Expire); -async_get_bulk(UserId, TargetName, - NonRep, MaxRep, {community, Community}, Oids) + SendOpts = [{timeout, Expire}], + async_get_bulk2(UserId, TargetName, NonRep, MaxRep, Oids, SendOpts); +async_get_bulk(UserId, TargetName, NonRep, MaxRep, Context, Oids) when is_integer(NonRep) andalso is_integer(MaxRep) andalso + is_list(Context) andalso is_list(Oids) -> - CC = {?DEFAULT_CONTEXT, Community}, - snmpm_server:async_get_bulk(UserId, TargetName, - NonRep, MaxRep, CC, Oids); -async_get_bulk(UserId, TargetName, NonRep, MaxRep, CC, Oids) - when is_integer(NonRep) andalso - is_integer(MaxRep) andalso - is_list(Oids) -> - snmpm_server:async_get_bulk(UserId, TargetName, - NonRep, MaxRep, CC, Oids). - -async_get_bulk(UserId, TargetName, NonRep, MaxRep, {community, Community}, - Oids, Expire) -> - CC = {?DEFAULT_CONTEXT, Community}, - snmpm_server:async_get_bulk(UserId, TargetName, - NonRep, MaxRep, CC, Oids, Expire); -async_get_bulk(UserId, TargetName, NonRep, MaxRep, CC, Oids, Expire) -> - snmpm_server:async_get_bulk(UserId, TargetName, - NonRep, MaxRep, CC, Oids, Expire). - -async_get_bulk(UserId, TargetName, - NonRep, MaxRep, {community, Community}, - Oids, Expire, ExtraInfo) -> - CC = {?DEFAULT_CONTEXT, Community}, - snmpm_server:async_get_bulk(UserId, TargetName, - NonRep, MaxRep, CC, Oids, Expire, ExtraInfo); -async_get_bulk(UserId, TargetName, NonRep, MaxRep, CC, Oids, Expire, + SendOpts = [{context, Context}], + async_get_bulk2(UserId, TargetName, NonRep, MaxRep, Oids, SendOpts). + +async_get_bulk(UserId, TargetName, NonRep, MaxRep, Context, Oids, Expire) -> + SendOpts = [{timeout, Expire}, {context, Context}], + async_get_bulk2(UserId, TargetName, NonRep, MaxRep, Oids, SendOpts). + +async_get_bulk(UserId, TargetName, NonRep, MaxRep, Context, Oids, Expire, ExtraInfo) -> - snmpm_server:async_get_bulk(UserId, TargetName, - NonRep, MaxRep, CC, Oids, Expire, ExtraInfo). + SendOpts = [{timeout, Expire}, {context, Context}, {extra, ExtraInfo}], + async_get_bulk2(UserId, TargetName, NonRep, MaxRep, Oids, SendOpts). +%% </BACKWARD-COMPAT> +%% <DEPRECATED> agb(UserId, Addr, NonRep, MaxRep, Oids) -> agb(UserId, Addr, ?DEFAULT_AGENT_PORT, NonRep, MaxRep, Oids). -agb(UserId, Addr, NonRep, MaxRep, Oids, Expire) - when is_integer(NonRep) andalso - is_integer(MaxRep) andalso - is_list(Oids) andalso - is_integer(Expire) -> - agb(UserId, Addr, ?DEFAULT_AGENT_PORT, NonRep, MaxRep, Oids, Expire); agb(UserId, Addr, Port, NonRep, MaxRep, Oids) when is_integer(Port) andalso is_integer(NonRep) andalso is_integer(MaxRep) andalso is_list(Oids) -> agb(UserId, Addr, Port, NonRep, MaxRep, ?DEFAULT_CONTEXT, Oids); -agb(UserId, Addr, NonRep, MaxRep, CC, Oids) + +agb(UserId, Addr, NonRep, MaxRep, CtxName, Oids) when is_integer(NonRep) andalso is_integer(MaxRep) andalso + is_list(CtxName) andalso is_list(Oids) -> - agb(UserId, Addr, ?DEFAULT_AGENT_PORT, NonRep, MaxRep, CC, Oids). + agb(UserId, Addr, ?DEFAULT_AGENT_PORT, NonRep, MaxRep, CtxName, Oids); -agb(UserId, Addr, Port, NonRep, MaxRep, Oids, Expire) - when is_integer(Port) andalso - is_integer(NonRep) andalso - is_integer(MaxRep) andalso - is_list(Oids) andalso - is_integer(Expire) -> - agb(UserId, Addr, Port, NonRep, MaxRep, ?DEFAULT_CONTEXT, Oids, Expire); -agb(UserId, Addr, NonRep, MaxRep, CC, Oids, Expire) +agb(UserId, Addr, NonRep, MaxRep, Oids, Expire) when is_integer(NonRep) andalso is_integer(MaxRep) andalso is_list(Oids) andalso is_integer(Expire) -> - agb(UserId, Addr, ?DEFAULT_AGENT_PORT, NonRep, MaxRep, CC, Oids); -agb(UserId, Addr, Port, NonRep, MaxRep, CC, Oids) + agb(UserId, Addr, ?DEFAULT_AGENT_PORT, NonRep, MaxRep, Oids, Expire). + +agb(UserId, Addr, Port, NonRep, MaxRep, CtxName, Oids) when is_integer(Port) andalso is_integer(NonRep) andalso is_integer(MaxRep), + is_list(CtxName) andalso is_list(Oids) -> case target_name(Addr, Port) of {ok, TargetName} -> async_get_bulk(UserId, TargetName, - NonRep, MaxRep, CC, Oids); + NonRep, MaxRep, CtxName, Oids); Error -> Error - end. + end; + +agb(UserId, Addr, Port, NonRep, MaxRep, Oids, Expire) + when is_integer(Port) andalso + is_integer(NonRep) andalso + is_integer(MaxRep) andalso + is_list(Oids) andalso + is_integer(Expire) -> + agb(UserId, Addr, Port, NonRep, MaxRep, ?DEFAULT_CONTEXT, Oids, Expire); -agb(UserId, Addr, Port, NonRep, MaxRep, CC, Oids, Expire) -> +agb(UserId, Addr, NonRep, MaxRep, CtxName, Oids, Expire) + when is_integer(NonRep) andalso + is_integer(MaxRep) andalso + is_list(CtxName) andalso + is_list(Oids) andalso + is_integer(Expire) -> + agb(UserId, Addr, ?DEFAULT_AGENT_PORT, NonRep, MaxRep, CtxName, Oids). + +agb(UserId, Addr, Port, NonRep, MaxRep, CtxName, Oids, Expire) -> case target_name(Addr, Port) of {ok, TargetName} -> async_get_bulk(UserId, TargetName, - NonRep, MaxRep, CC, Oids, Expire); + NonRep, MaxRep, CtxName, Oids, Expire); Error -> Error end. -agb(UserId, Addr, Port, NonRep, MaxRep, CC, Oids, Expire, ExtraInfo) -> +agb(UserId, Addr, Port, NonRep, MaxRep, CtxName, Oids, Expire, ExtraInfo) -> case target_name(Addr, Port) of {ok, TargetName} -> async_get_bulk(UserId, TargetName, - NonRep, MaxRep, CC, Oids, Expire, ExtraInfo); + NonRep, MaxRep, CtxName, Oids, Expire, + ExtraInfo); Error -> Error end. +%% </DEPRECATED> cancel_async_request(UserId, ReqId) -> @@ -1178,7 +1369,7 @@ cancel_async_request(UserId, ReqId) -> %%%----------------------------------------------------------------- -%%% Audit Trail Log functions (for backward compatibillity) +%%% Audit Trail Log functions (for backward compatibility) %%%----------------------------------------------------------------- log_to_txt(LogDir, Mibs) -> OutFile = "snmpm_log.txt", diff --git a/lib/snmp/src/manager/snmpm_conf.erl b/lib/snmp/src/manager/snmpm_conf.erl index 75f9c09477..e50508c489 100644 --- a/lib/snmp/src/manager/snmpm_conf.erl +++ b/lib/snmp/src/manager/snmpm_conf.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 2006-2009. All Rights Reserved. +%% Copyright Ericsson AB 2006-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 @@ -21,6 +21,8 @@ -include_lib("kernel/include/file.hrl"). +%% Avoid warning for local function error/1 clashing with autoimported BIF. +-compile({no_auto_import,[error/1]}). -export([ %% manager.conf manager_entry/2, diff --git a/lib/snmp/src/manager/snmpm_config.erl b/lib/snmp/src/manager/snmpm_config.erl index b976e8f568..c2e57abddb 100644 --- a/lib/snmp/src/manager/snmpm_config.erl +++ b/lib/snmp/src/manager/snmpm_config.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 2004-2010. All Rights Reserved. +%% Copyright Ericsson AB 2004-2011. 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 @@ -28,13 +28,16 @@ -behaviour(gen_server). %% External exports +%% Avoid warning for local function error/1 clashing with autoimported BIF. +-compile({no_auto_import,[error/1]}). -export([start_link/1, stop/0, is_started/0]). -export([register_user/4, unregister_user/1, which_users/0, user_info/0, user_info/1, user_info/2, register_agent/3, unregister_agent/2, - agent_info/0, agent_info/2, agent_info/3, update_agent_info/4, + agent_info/0, agent_info/2, agent_info/3, + update_agent_info/3, update_agent_info/4, which_agents/0, which_agents/1, is_known_engine_id/2, @@ -82,7 +85,9 @@ backup/1, - mk_target_name/3 + mk_target_name/3, + + default_transport_domain/0 ]). @@ -125,23 +130,24 @@ %% Macros and Constants: --define(SERVER, ?MODULE). --define(BACKUP_DB, snmpm_config_backup). --define(CONFIG_DB, snmpm_config_db). +-define(SERVER, ?MODULE). +-define(BACKUP_DB, snmpm_config_backup). +-define(CONFIG_DB, snmpm_config_db). -define(DEFAULT_USER, default_user). -define(DEFAULT_AGENT_PORT, 161). --define(IRB_DEFAULT, auto). -%% -define(IRB_DEFAULT, {user, timer:seconds(15)}). +-define(IRB_DEFAULT, auto). +%% -define(IRB_DEFAULT, {user, timer:seconds(15)}). --define(USER_MOD_DEFAULT, snmpm_user_default). --define(USER_DATA_DEFAULT, undefined). +-define(USER_MOD_DEFAULT, snmpm_user_default). +-define(USER_DATA_DEFAULT, undefined). %% -define(DEF_ADDR_TAG, default_addr_tag). -define(DEFAULT_TARGETNAME, default_agent). --define(DEF_PORT_TAG, default_port_tag). +-define(DEF_PORT_TAG, default_port_tag). +-define(SUPPORTED_DOMAINS, [transportDomainUdpIpv4, transportDomainUdpIpv6]). -ifdef(snmp_debug). -define(GS_START_LINK(Opts), @@ -157,6 +163,11 @@ %%%------------------------------------------------------------------- %%% API %%%------------------------------------------------------------------- + +default_transport_domain() -> + transportDomainUdpIpv4. + + start_link(Opts) -> ?d("start_link -> entry with" "~n Opts: ~p", [Opts]), @@ -267,9 +278,10 @@ do_user_info(_UserId, BadItem) -> error({not_found, BadItem}). -%% A target-name constructed in this way is a string with the following +%% A target-name constructed in this way is a string with the following: %% <IP-address>:<Port>-<Version> -%% +%% This is intended for backward compatibility and therefor has +%% only support for IPv4 addresses and *no* other transport domain. mk_target_name(Addr0, Port, Config) when is_list(Config) -> Version = case lists:keysearch(version, 1, Config) of @@ -278,7 +290,6 @@ mk_target_name(Addr0, Port, Config) when is_list(Config) -> false -> select_lowest_supported_version() end, -%% p("mk_target_name -> Version: ~p", [Version]), case normalize_address(Addr0) of {A, B, C, D} -> lists:flatten( @@ -306,57 +317,99 @@ select_lowest_supported_version([H|T], Versions) -> end. -register_agent(UserId, _TargetName, _Config) when (UserId =:= user_id) -> +register_agent(UserId, _TargetName, _Config0) when (UserId =:= user_id) -> {error, {bad_user_id, UserId}}; -register_agent(UserId, TargetName, Config) +register_agent(UserId, TargetName, Config0) when (is_list(TargetName) andalso (length(TargetName) > 0) andalso - is_list(Config)) -> + is_list(Config0)) -> -%% p("register_agent -> entry with" -%% "~n UserId: ~p" -%% "~n TargetName: ~p" -%% "~n Config: ~p", [UserId, TargetName, Config]), + ?vtrace("register_agent -> entry with" + "~n UserId: ~p" + "~n TargetName: ~p" + "~n Config0: ~p", [UserId, TargetName, Config0]), %% Check: %% 1) That the mandatory configs are present - %% 2) That the illegal config user_id (used internally) is - %% not present + %% 2) That no illegal config, e.g. user_id (used internally), + %% is not present %% 3) Check that there are no invalid or erroneous configs - %% 4) Chack that the manager is capable to use the selected version - case verify_agent_config(Config) of - ok -> + %% 4) Check that the manager is capable of using the selected version + case verify_agent_config(Config0) of + {ok, Config} -> call({register_agent, UserId, TargetName, Config}); Error -> Error end. -verify_agent_config(Conf) -> - ok = verify_mandatory(Conf, [engine_id, address, reg_type]), - case verify_invalid(Conf, [user_id]) of - ok -> - case verify_agent_config2(Conf) of - ok -> - {ok, Vsns} = system_info(versions), - Vsn = - case lists:keysearch(version, 1, Conf) of - {value, {version, V}} -> - V; - false -> - v1 - end, - case lists:member(Vsn, Vsns) of - true -> - ok; - false -> - {error, {version_not_supported_by_manager, Vsn, Vsns}} - end - end; - Error -> +verify_agent_config(Conf0) -> + try + begin + verify_mandatory(Conf0, [engine_id, address, reg_type]), + verify_invalid(Conf0, [user_id]), + Conf = verify_agent_config3(Conf0), + Vsns = versions(), + Vsn = which_version(Conf), + verify_version(Vsn, Vsns), + {ok, Conf} + end + catch + throw:Error -> Error end. +versions() -> + case system_info(versions) of + {ok, Vsns} -> + Vsns; + {error, _} = ERROR -> + throw(ERROR) + end. + +which_version(Conf) -> + case lists:keysearch(version, 1, Conf) of + {value, {version, V}} -> + V; + false -> + v1 + end. + +verify_version(Vsn, Vsns) -> + case lists:member(Vsn, Vsns) of + true -> + ok; + false -> + Reason = {version_not_supported_by_manager, Vsn, Vsns}, + throw({error, Reason}) + end. + +verify_agent_config3(Conf0) -> + %% Fix (transport) address and domain + {TDomain, Conf1} = + case lists:keysearch(tdomain, 1, Conf0) of + {value, {tdomain, Dom}} -> + {Dom, Conf0}; + false -> + Dom = default_transport_domain(), + {Dom, [{tdomain, Dom} | Conf0]} + end, + Conf2 = case lists:keysearch(address, 1, Conf1) of + {value, {address, Address}} -> + lists:keyreplace(address, 1, Conf1, + {address, {TDomain, Address}}); + false -> + %% This is a mandatory config option, + %% a later test will detect this + Conf1 + end, + case verify_agent2(Conf2) of + {ok, Conf} -> + Conf; + {error, _} = ERROR -> + throw(ERROR) + end. + verify_agent_config2(Conf) -> verify_agent2(Conf). @@ -364,6 +417,7 @@ verify_agent_config2(Conf) -> unregister_agent(UserId, TargetName) -> call({unregister_agent, UserId, TargetName}). +%% This is the old style agent unregistration (using Addr and Port). unregister_agent(UserId, Addr0, Port) -> Addr = normalize_address(Addr0), case do_agent_info(Addr, Port, target_name) of @@ -419,17 +473,51 @@ which_agents(UserId) -> Agents = ets:match(snmpm_agent_table, Pat), [TargetName || [TargetName] <- Agents]. - -update_agent_info(UserId, TargetName, Item, Val0) - when (Item =/= user_id) -> - case (catch verify_val(Item, Val0)) of - {ok, Val} -> - call({update_agent_info, UserId, TargetName, Item, Val}); - Error -> + +verify_agent_info(TargetName, Info0) -> + try + begin + verify_invalid(Info0, [user_id]), + %% Check if address is part of the list and + %% if so update it with the domain info. + Info = + case lists:keysearch(address, 1, Info0) of + {value, {address, Addr}} -> + %% If domain is part of the info, then use it. + %% If not, lookup what is already stored for + %% this agent and use that. + Domain = + case lists:keysearch(tdomain, 1, Info0) of + {value, {tdomain, Dom}} -> + Dom; + false -> + {ok, Dom} = + agent_info(TargetName, tdomain), + Dom + end, + Addr2 = {Domain, Addr}, + lists:keyreplace(address, 1, Info0, {address, Addr2}); + false -> + Info0 + end, + verify_agent2(Info) + end + catch + throw:Error -> Error end. -%% Backward compatibillity +update_agent_info(UserId, TargetName, Info) -> + call({update_agent_info, UserId, TargetName, Info}). + +%% <BACKWARD-COMPAT-2> +%% This is wrapped in the interface module, so this function is +%% only here to catch code-upgrade problems. +update_agent_info(UserId, TargetName, Item, Val) -> + update_agent_info(UserId, TargetName, [{Item, Val}]). +%% </BACKWARD-COMPAT-2> + +%% <BACKWARD-COMPAT-1> update_agent_info(UserId, Addr, Port, Item, Val) -> case agent_info(Addr, Port, target_name) of {ok, TargetName} -> @@ -437,6 +525,7 @@ update_agent_info(UserId, Addr, Port, Item, Val) -> Error -> Error end. +%% </BACKWARD-COMPAT-1> is_known_engine_id(EngineID, TargetName) -> case agent_info(TargetName, engine_id) of @@ -648,22 +737,14 @@ unregister_usm_user(EngineID, Name) call({unregister_usm_user, EngineID, Name}). verify_usm_user_config(EngineID, Name, Config) -> - %% case verify_mandatory(Config, []) of - %% ok -> - %% case verify_invalid(Config, [engine_id, name]) of - %% ok -> - %% verify_usm_user_config2(EngineID, Name, Config); - %% Error -> - %% Error - %% end; - %% Error -> - %% Error - %% end. - ok = verify_mandatory(Config, []), - case verify_invalid(Config, [engine_id, name]) of - ok -> - verify_usm_user_config2(EngineID, Name, Config); - Error -> + try + begin + verify_mandatory(Config, []), + verify_invalid(Config, [engine_id, name]), + verify_usm_user_config2(EngineID, Name, Config) + end + catch + throw:Error -> Error end. @@ -1588,6 +1669,7 @@ check_agent_config2(Agent) -> throw(Err) end. +%% For backward compatibility check_agent_config({UserId, TargetName, Community, @@ -1595,10 +1677,27 @@ check_agent_config({UserId, EngineId, Timeout, MaxMessageSize, Version, SecModel, SecName, SecLevel}) -> + TDomain = default_transport_domain(), + check_agent_config({UserId, + TargetName, + Community, + TDomain, Ip, Port, + EngineId, + Timeout, MaxMessageSize, + Version, SecModel, SecName, SecLevel}); + +check_agent_config({UserId, + TargetName, + Community, + TDomain, Ip, Port, + EngineId, + Timeout, MaxMessageSize, + Version, SecModel, SecName, SecLevel}) -> ?vtrace("check_agent_config -> entry with" "~n UserId: ~p" "~n TargetName: ~p" "~n Community: ~p" + "~n TDomain: ~p" "~n Ip: ~p" "~n Port: ~p" "~n EngineId: ~p" @@ -1608,15 +1707,16 @@ check_agent_config({UserId, "~n SecModel: ~p" "~n SecName: ~p" "~n SecLevel: ~p", - [UserId, TargetName, Community, Ip, Port, + [UserId, TargetName, Community, + TDomain, Ip, Port, EngineId, Timeout, MaxMessageSize, Version, SecModel, SecName, SecLevel]), - Addr = normalize_address(Ip), + Addr = normalize_address(TDomain, Ip), ?vtrace("check_agent_config -> Addr: ~p", [Addr]), Agent = {UserId, TargetName, Community, - Addr, Port, + TDomain, Addr, Port, EngineId, Timeout, MaxMessageSize, Version, SecModel, SecName, SecLevel}, @@ -1642,6 +1742,7 @@ init_agent_config({UserId, TargetName, Config}) -> end. +%% For backward compatibility verify_agent({UserId, TargetName, Comm, @@ -1649,48 +1750,68 @@ verify_agent({UserId, EngineId, Timeout, MMS, Version, SecModel, SecName, SecLevel}) -> - ?vtrace("verify_agent -> entry with" + TDomain = default_transport_domain(), + verify_agent({UserId, + TargetName, + Comm, + TDomain, Ip, Port, + EngineId, + Timeout, MMS, + Version, SecModel, SecName, SecLevel}); + +verify_agent({UserId, + TargetName, + Comm, + TDomain, Ip, Port, + EngineId, + Timeout, MMS, + Version, SecModel, SecName, SecLevel}) -> + ?vdebug("verify_agent -> entry with" "~n UserId: ~p" "~n TargetName: ~p", [UserId, TargetName]), snmp_conf:check_string(TargetName, {gt, 0}), - case verify_val(address, Ip) of - {ok, Addr} -> - snmp_conf:check_integer(Port, {gt, 0}), - Conf = - [{reg_type, target_name}, - {address, Addr}, - {port, Port}, - {community, Comm}, - {engine_id, EngineId}, - {timeout, Timeout}, - {max_message_size, MMS}, - {version, Version}, - {sec_model, SecModel}, - {sec_name, SecName}, - {sec_level, SecLevel} - ], - case verify_agent2(Conf) of - ok -> - {UserId, TargetName, Conf, Version}; - Err -> - throw(Err) - end; - - Error -> - ?vlog("verify_agent -> failed: ~n ~p", [Error]), - throw(Error) + snmp_conf:check_integer(Port, {gt, 0}), + %% Note that the order of Conf *is* important. + %% Some properties may depend on others, so that + %% in order to verify one property, another must + %% be already verified (and present). An example + %% of this is the property 'address', for which + %% the property tdomain is needed. + Conf0 = + [{reg_type, target_name}, + {tdomain, TDomain}, + %% This should be taddress, but what the*... + {address, {TDomain, Ip}}, + {port, Port}, + {community, Comm}, + {engine_id, EngineId}, + {timeout, Timeout}, + {max_message_size, MMS}, + {version, Version}, + {sec_model, SecModel}, + {sec_name, SecName}, + {sec_level, SecLevel} + ], + case verify_agent2(Conf0) of + {ok, Conf} -> + {UserId, TargetName, Conf, Version}; + Err -> + throw(Err) end. -verify_agent2([]) -> - ok; -verify_agent2([{Item, Val}|Items]) -> - case verify_val(Item, Val) of - {ok, _Val} -> - verify_agent2(Items); +verify_agent2(Conf) -> + verify_agent2(Conf, []). + +verify_agent2([], VerifiedConf) -> + {ok, VerifiedConf}; +verify_agent2([{Item, Val0}|Items], VerifiedConf) -> + case verify_val(Item, Val0) of + {ok, Val} -> + verify_agent2(Items, [{Item, Val} | VerifiedConf]); Err -> Err end; -verify_agent2([Bad|_]) -> +verify_agent2([Bad|_], _VerifiedConf) -> {error, {bad_agent_config, Bad}}. @@ -1706,14 +1827,28 @@ read_users_config_file(Dir) -> check_user_config({Id, Mod, Data}) -> + ?vtrace("check_user_config -> entry with" + "~n Id: ~p" + "~n Mod: ~p" + "~n Data: ~p", [Id, Mod, Data]), check_user_config({Id, Mod, Data, []}); -check_user_config({Id, Mod, _Data, DefaultAgentConfig} = User) +check_user_config({Id, Mod, Data, DefaultAgentConfig} = _User) when (Id =/= ?DEFAULT_USER) andalso is_list(DefaultAgentConfig) -> + ?vtrace("check_user_config -> entry with" + "~n Id: ~p" + "~n Mod: ~p" + "~n Data: ~p" + "~n DefaultAgentConfig: ~p", + [Id, Mod, Data, DefaultAgentConfig]), case (catch verify_user_behaviour(Mod)) of ok -> + ?vtrace("check_user_config -> user behaviour verified", []), case verify_user_agent_config(DefaultAgentConfig) of - ok -> - {ok, User}; + {ok, DefAgentConf} -> + ?vtrace("check_user_config -> " + "user agent (default) config verified", []), + User2 = {Id, Mod, Data, DefAgentConf}, + {ok, User2}; {error, Reason} -> error({bad_default_agent_config, Reason}) end; @@ -1754,16 +1889,16 @@ verify_user({Id, UserMod, UserData}) -> verify_user({Id, UserMod, UserData, DefaultAgentConfig}) when (Id =/= ?DEFAULT_USER) andalso is_list(DefaultAgentConfig) -> ?d("verify_user -> entry with" - "~n Id: ~p" - "~n UserMod: ~p" - "~n UserData: ~p" + "~n Id: ~p" + "~n UserMod: ~p" + "~n UserData: ~p" "~n DefaultAgentConfig: ~p", [Id, UserMod, UserData, DefaultAgentConfig]), case (catch verify_user_behaviour(UserMod)) of ok -> case verify_user_agent_config(DefaultAgentConfig) of - ok -> - Config = default_agent_config(DefaultAgentConfig), + {ok, DefAgentConf} -> + Config = default_agent_config(DefAgentConf), {ok, #user{id = Id, mod = UserMod, data = UserData, @@ -1781,10 +1916,15 @@ verify_user({Id, _, _, _}) -> {error, {bad_user_id, Id}}. verify_user_agent_config(Conf) -> - case verify_invalid(Conf, [user_id, engine_id, address]) of - ok -> - verify_agent_config2(Conf); - Error -> + try + begin + verify_invalid(Conf, [user_id, engine_id, address]), + verify_agent_config2(Conf) + end + catch + throw:Error -> + ?vdebug("verify_user_agent_config -> throw" + "~n Error: ~p", [Error]), Error end. @@ -2145,6 +2285,16 @@ handle_call({unregister_agent, UserId, TargetName}, _From, State) -> Reply = handle_unregister_agent(UserId, TargetName), {reply, Reply, State}; +handle_call({update_agent_info, UserId, TargetName, Info}, + _From, State) -> + ?vlog("received update_agent_info request: " + "~n UserId: ~p" + "~n TargetName: ~p" + "~n Info: ~p", [UserId, TargetName, Info]), + Reply = handle_update_agent_info(UserId, TargetName, Info), + {reply, Reply, State}; + +%% <BACKWARD-COMPAT> handle_call({update_agent_info, UserId, TargetName, Item, Val}, _From, State) -> ?vlog("received update_agent_info request: " @@ -2154,6 +2304,7 @@ handle_call({update_agent_info, UserId, TargetName, Item, Val}, "~n Val: ~p", [UserId, TargetName, Item, Val]), Reply = handle_update_agent_info(UserId, TargetName, Item, Val), {reply, Reply, State}; +%% </BACKWARD-COMPAT> handle_call({register_usm_user, User}, _From, State) -> ?vlog("received register_usm_user request: " @@ -2515,16 +2666,27 @@ handle_register_agent(UserId, TargetName, Config) -> "~n Config: ~p", [UserId, TargetName, Config]), case (catch agent_info(TargetName, user_id)) of {error, _} -> + ?vtrace("handle_register_agent -> user_id not found in config", []), case ets:lookup(snmpm_user_table, UserId) of [#user{default_agent_config = DefConfig}] -> + ?vtrace("handle_register_agent -> " + "~n DefConfig: ~p", [DefConfig]), + %% First, insert this users default config + ?vtrace("handle_register_agent -> store default config", []), do_handle_register_agent(TargetName, DefConfig), + %% Second, insert the config for this agent + ?vtrace("handle_register_agent -> store config", []), do_handle_register_agent(TargetName, [{user_id, UserId}|Config]), %% <DIRTY-BACKWARD-COMPATIBILLITY> %% And now for some (backward compatibillity) %% dirty crossref stuff + ?vtrace("handle_register_agent -> lookup address", []), {ok, Addr} = agent_info(TargetName, address), + ?vtrace("handle_register_agent -> Addr: ~p, lookup Port", + [Addr]), {ok, Port} = agent_info(TargetName, port), + ?vtrace("handle_register_agent -> register cross-ref fix", []), ets:insert(snmpm_agent_table, {{Addr, Port, target_name}, TargetName}), %% </DIRTY-BACKWARD-COMPATIBILLITY> @@ -2549,10 +2711,18 @@ handle_register_agent(UserId, TargetName, Config) -> do_handle_register_agent(_TargetName, []) -> ok; do_handle_register_agent(TargetName, [{Item, Val}|Rest]) -> + ?vtrace("handle_register_agent -> entry with" + "~n TargetName: ~p" + "~n Item: ~p" + "~n Val: ~p" + "~n Rest: ~p", [TargetName, Item, Val, Rest]), case (catch do_update_agent_info(TargetName, Item, Val)) of ok -> do_handle_register_agent(TargetName, Rest); {error, Reason} -> + ?vtrace("handle_register_agent -> failed updating ~p" + "~n Item: ~p" + "~n Reason: ~p", [Item, Reason]), ets:match_delete(snmpm_agent_table, {TargetName, '_'}), {error, Reason} end; @@ -2587,41 +2757,61 @@ handle_unregister_agent(UserId, TargetName) -> end. -handle_update_agent_info(UserId, TargetName, Item, Val) -> +handle_update_agent_info(UserId, TargetName, Info) -> ?vdebug("handle_update_agent_info -> entry with" "~n UserId: ~p" "~n TargetName: ~p" - "~n Item: ~p" - "~n Val: ~p", [UserId, TargetName, Item, Val]), + "~n Info: ~p", [UserId, TargetName, Info]), + %% Verify ownership case (catch agent_info(TargetName, user_id)) of - {ok, UserId} -> - do_update_agent_info(TargetName, Item, Val); + {ok, UserId} -> + handle_update_agent_info(TargetName, Info); {ok, OtherUserId} -> {error, {not_owner, OtherUserId}}; Error -> Error end. -do_update_agent_info(TargetName, Item, Val0) -> -%% p("do_update_agent_info -> entry with" -%% "~n TargetName: ~p" -%% "~n Item: ~p" -%% "~n Val0: ~p", [TargetName, Item, Val0]), - case verify_val(Item, Val0) of - {ok, Val} -> -%% p("do_update_agent_info -> verified value" -%% "~n Val: ~p", [Val]), - ets:insert(snmpm_agent_table, {{TargetName, Item}, Val}), - ok; +handle_update_agent_info(TargetName, Info0) -> + ?vtrace("handle_update_agent_info -> entry with" + "~n TargetName: ~p" + "~n Info0: ~p", [TargetName, Info0]), + %% Verify info + try verify_agent_info(TargetName, Info0) of + {ok, Info} -> + do_update_agent_info(TargetName, Info); Error -> - ?vlog("do_update_agent_info -> verify value failed: " - "~n TargetName: ~p" - "~n Item: ~p" - "~n Val0: ~p" - "~n Error: ~p", [TargetName, Item, Val0, Error]), - {error, {bad_agent_val, TargetName, Item, Val0}} + Error + catch + throw:Error -> + Error; + T:E -> + {error, {failed_info_verification, Info0, T, E}} end. +handle_update_agent_info(UserId, TargetName, Item, Val) -> + ?vdebug("handle_update_agent_info -> entry with" + "~n UserId: ~p" + "~n TargetName: ~p" + "~n Item: ~p" + "~n Val: ~p", [UserId, TargetName, Item, Val]), + handle_update_agent_info(TargetName, [{Item, Val}]). + +do_update_agent_info(TargetName, Info) -> + InsertItem = + fun({Item, Val}) -> + ets:insert(snmpm_agent_table, {{TargetName, Item}, Val}) + end, + lists:foreach(InsertItem, Info). + +do_update_agent_info(TargetName, Item, Val) -> + ?vtrace("do_update_agent_info -> entry with" + "~n TargetName: ~p" + "~n Item: ~p" + "~n Val: ~p", [TargetName, Item, Val]), + ets:insert(snmpm_agent_table, {{TargetName, Item}, Val}), + ok. + handle_register_usm_user(#usm_user{engine_id = EngineID, name = Name} = User) -> @@ -2789,7 +2979,7 @@ verify_mandatory(Conf, [Mand|Mands]) -> true -> verify_mandatory(Conf, Mands); false -> - {error, {missing_mandatory_config, Mand}} + throw({error, {missing_mandatory_config, Mand}}) end. verify_invalid(_, []) -> @@ -2799,7 +2989,7 @@ verify_invalid(Conf, [Inv|Invs]) -> false -> verify_invalid(Conf, Invs); true -> - {error, {illegal_config, Inv}} + throw({error, {illegal_config, Inv}}) end. @@ -2808,10 +2998,26 @@ verify_val(user_id, UserId) -> verify_val(reg_type, RegType) when (RegType =:= addr_port) orelse (RegType =:= target_name) -> {ok, RegType}; -verify_val(address, Addr0) -> - case normalize_address(Addr0) of +verify_val(tdomain = Item, snmpUDPDomain = _Domain) -> + verify_val(Item, transportDomainUdpIpv4); +verify_val(tdomain, Domain) -> + case lists:member(Domain, ?SUPPORTED_DOMAINS) of + true -> + {ok, Domain}; + false -> + case lists:member(Domain, snmp_conf:all_domains()) of + true -> + error({unsupported_domain, Domain}); + false -> + error({unknown_domain, Domain}) + end + end; +verify_val(address, {Domain, Addr0}) -> + case normalize_address(Domain, Addr0) of {_A1, _A2, _A3, _A4} = Addr -> {ok, Addr}; + {_A1, _A2, _A3, _A4, _A5, _A6, _A7, _A8} = Addr -> + {ok, Addr}; _ when is_list(Addr0) -> case (catch snmp_conf:check_ip(Addr0)) of ok -> @@ -2822,6 +3028,8 @@ verify_val(address, Addr0) -> _ -> error({bad_address, Addr0}) end; +verify_val(address, BadAddress) -> + error({bad_address, BadAddress}); verify_val(port, Port) -> case (catch snmp_conf:check_integer(Port, {gt, 0})) of ok -> @@ -2873,7 +3081,7 @@ verify_val(sec_name, BadName) -> verify_val(sec_level, Level) -> (catch snmp_conf:check_sec_level(Level)); verify_val(Item, _) -> - {error, {no_such_item, Item}}. + {error, {unknown_item, Item}}. %%%------------------------------------------------------------------- @@ -3032,11 +3240,17 @@ init_mini_mib_elems(MibName, [_|T], Res) -> %%---------------------------------------------------------------------- normalize_address(Addr) -> - case inet:getaddr(Addr, inet) of + normalize_address(snmpUDPDomain, Addr). + +normalize_address(snmpUDPDomain, Addr) -> + normalize_address(transportDomainUdpIpv4, Addr); + +normalize_address(Domain, Addr) -> + case inet:getaddr(Addr, td2fam(Domain)) of {ok, Addr2} -> Addr2; _ when is_list(Addr) -> - case (catch snmp_conf:check_ip(Addr)) of + case (catch snmp_conf:check_ip(Domain, Addr)) of ok -> list_to_tuple(Addr); _ -> @@ -3046,6 +3260,9 @@ normalize_address(Addr) -> Addr end. +td2fam(transportDomainUdpIpv4) -> inet; +td2fam(transportDomainUdpIpv6) -> inet6. + %%---------------------------------------------------------------------- diff --git a/lib/snmp/src/manager/snmpm_internal.hrl b/lib/snmp/src/manager/snmpm_internal.hrl index 5d9b32e3f6..53ad41c6b0 100644 --- a/lib/snmp/src/manager/snmpm_internal.hrl +++ b/lib/snmp/src/manager/snmpm_internal.hrl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 2006-2009. All Rights Reserved. +%% Copyright Ericsson AB 2006-2011. 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 @@ -20,6 +20,11 @@ -ifndef(snmpm_internal). -define(snmpm_internal, true). +-define(DEFAULT_CONTEXT, ""). +-define(SNMPM_EXTRA_INFO_TAG, snmpm_extra_info_tag). +-define(DEFAULT_EXTRA_INFO, {?SNMPM_EXTRA_INFO_TAG}). + + -include_lib("snmp/src/app/snmp_internal.hrl"). -define(snmpm_info(F, A), ?snmp_info("manager", F, A)). diff --git a/lib/snmp/src/manager/snmpm_mpd.erl b/lib/snmp/src/manager/snmpm_mpd.erl index 7712370d28..627838e3d4 100644 --- a/lib/snmp/src/manager/snmpm_mpd.erl +++ b/lib/snmp/src/manager/snmpm_mpd.erl @@ -92,7 +92,7 @@ reset(#state{v3 = V3}) -> %% Purpose: This is the main Message Dispatching function. (see %% section 4.2.1 in rfc2272) %%----------------------------------------------------------------- -process_msg(Msg, TDomain, Addr, Port, State, NoteStore, Logger) -> +process_msg(Msg, Domain, Addr, Port, State, NoteStore, Logger) -> inc(snmpInPkts), @@ -102,18 +102,18 @@ process_msg(Msg, TDomain, Addr, Port, State, NoteStore, Logger) -> #message{version = 'version-1', vsn_hdr = Community, data = Data} when State#state.v1 =:= true -> HS = ?empty_msg_size + length(Community), - process_v1_v2c_msg('version-1', NoteStore, Msg, TDomain, - Addr, Port, + process_v1_v2c_msg('version-1', NoteStore, Msg, + Domain, Addr, Port, Community, Data, HS, Logger); %% Version 2 #message{version = 'version-2', vsn_hdr = Community, data = Data} when State#state.v2c =:= true -> HS = ?empty_msg_size + length(Community), - process_v1_v2c_msg('version-2', NoteStore, Msg, TDomain, - Addr, Port, - Community, Data, HS, Logger); - + (catch process_v1_v2c_msg('version-2', NoteStore, Msg, + Domain, Addr, Port, + Community, Data, HS, Logger)); + %% Version 3 #message{version = 'version-3', vsn_hdr = H, data = Data} when State#state.v3 =:= true -> @@ -148,17 +148,30 @@ process_msg(Msg, TDomain, Addr, Port, State, NoteStore, Logger) -> %%----------------------------------------------------------------- %% Handles a Community based message (v1 or v2c). %%----------------------------------------------------------------- -process_v1_v2c_msg(Vsn, _NoteStore, Msg, snmpUDPDomain, +process_v1_v2c_msg(Vsn, _NoteStore, Msg, Domain, Addr, Port, Community, Data, HS, Log) -> ?vdebug("process_v1_v2c_msg -> entry with" "~n Vsn: ~p" + "~n Domain: ~p" "~n Addr: ~p" "~n Port: ~p" "~n Community: ~p" - "~n HS: ~p", [Vsn, Addr, Port, Community, HS]), + "~n HS: ~p", [Vsn, Domain, Addr, Port, Community, HS]), + {TDomain, TAddress} = + try + begin + TD = snmp_conf:mk_tdomain(Domain), + TA = snmp_conf:mk_taddress(Domain, Addr, Port), + {TD, TA} + end + catch + throw:{error, TReason} -> + throw({discarded, {badarg, Domain, TReason}}) + end, + Max = get_max_message_size(), AgentMax = get_agent_max_message_size(Addr, Port), PduMS = pdu_ms(Max, AgentMax, HS), @@ -170,14 +183,14 @@ process_v1_v2c_msg(Vsn, _NoteStore, Msg, snmpUDPDomain, ?vtrace("process_v1_v2c_msg -> was a pdu", []), Log(Msg), inc_snmp_in(Pdu), - MsgData = {Community, sec_model(Vsn)}, + MsgData = {Community, sec_model(Vsn), TDomain, TAddress}, {ok, Vsn, Pdu, PduMS, MsgData}; Trap when is_record(Trap, trappdu) -> ?vtrace("process_v1_v2c_msg -> was a trap", []), Log(Msg), inc_snmp_in(Trap), - MsgData = {Community, sec_model(Vsn)}, + MsgData = {Community, sec_model(Vsn), TDomain, TAddress}, {ok, Vsn, Trap, PduMS, MsgData}; {'EXIT', Reason} -> @@ -185,11 +198,7 @@ process_v1_v2c_msg(Vsn, _NoteStore, Msg, snmpUDPDomain, "~n Reason: ~p", [Reason]), inc(snmpInASNParseErrs), {discarded, Reason} - end; -process_v1_v2c_msg(_Vsn, _NoteStore, _Msg, TDomain, - _Addr, _Port, - _Comm, _HS, _Data, _Log) -> - {discarded, {badarg, TDomain}}. + end. pdu_ms(MgrMMS, AgentMMS, HS) when AgentMMS < MgrMMS -> AgentMMS - HS; @@ -482,8 +491,8 @@ generate_msg('version-3', NoteStore, Pdu, generate_v3_msg(NoteStore, Pdu, SecModel, SecName, SecLevel, CtxEngineID, CtxName, TargetName, Log); -generate_msg(Vsn, _NoteStore, Pdu, {Community, _SecModel}, Log) -> - generate_v1_v2c_msg(Vsn, Pdu, Community, Log). +generate_msg(Vsn, _NoteStore, Pdu, {Comm, _SecModel}, Log) -> + generate_v1_v2c_msg(Vsn, Pdu, Comm, Log). generate_v3_msg(NoteStore, Pdu, @@ -627,6 +636,8 @@ generate_response_msg('version-3', Pdu, generate_v3_response_msg(Pdu, MsgID, SecModel, SecName, SecLevel, CtxEngineID, CtxName, SecData, Log); generate_response_msg(Vsn, Pdu, {Comm, _SecModel}, Log) -> + generate_v1_v2c_response_msg(Vsn, Pdu, Comm, Log); +generate_response_msg(Vsn, Pdu, {Comm, _SecModel, _TDomain, _TAddress}, Log) -> generate_v1_v2c_response_msg(Vsn, Pdu, Comm, Log). diff --git a/lib/snmp/src/manager/snmpm_net_if.erl b/lib/snmp/src/manager/snmpm_net_if.erl index 07156dacd9..4d6bd9aa33 100644 --- a/lib/snmp/src/manager/snmpm_net_if.erl +++ b/lib/snmp/src/manager/snmpm_net_if.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 2004-2010. All Rights Reserved. +%% Copyright Ericsson AB 2004-2011. 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 @@ -28,7 +28,8 @@ start_link/2, stop/1, send_pdu/6, % Backward compatibillity - send_pdu/7, + send_pdu/7, % Backward compatibillity + send_pdu/8, inform_response/4, @@ -99,18 +100,23 @@ stop(Pid) -> call(Pid, stop). send_pdu(Pid, Pdu, Vsn, MsgData, Addr, Port) -> - send_pdu(Pid, Pdu, Vsn, MsgData, Addr, Port, undefined). + send_pdu(Pid, Pdu, Vsn, MsgData, Addr, Port, ?DEFAULT_EXTRA_INFO). -send_pdu(Pid, Pdu, Vsn, MsgData, Addr, Port, ExtraInfo) +send_pdu(Pid, Pdu, Vsn, MsgData, Addr, Port, ExtraInfo) -> + Domain = snmpm_config:default_transport_domain(), + send_pdu(Pid, Pdu, Vsn, MsgData, Domain, Addr, Port, ExtraInfo). + +send_pdu(Pid, Pdu, Vsn, MsgData, Domain, Addr, Port, ExtraInfo) when is_record(Pdu, pdu) -> ?d("send_pdu -> entry with" "~n Pid: ~p" "~n Pdu: ~p" "~n Vsn: ~p" "~n MsgData: ~p" + "~n Domain: ~p" "~n Addr: ~p" - "~n Port: ~p", [Pid, Pdu, Vsn, MsgData, Addr, Port]), - cast(Pid, {send_pdu, Pdu, Vsn, MsgData, Addr, Port, ExtraInfo}). + "~n Port: ~p", [Pid, Pdu, Vsn, MsgData, Domain, Addr, Port]), + cast(Pid, {send_pdu, Pdu, Vsn, MsgData, Domain, Addr, Port, ExtraInfo}). note_store(Pid, NoteStore) -> call(Pid, {note_store, NoteStore}). @@ -380,14 +386,17 @@ handle_call(Req, From, State) -> %% {noreply, State, Timeout} | %% {stop, Reason, State} (terminate/2 is called) %%-------------------------------------------------------------------- -handle_cast({send_pdu, Pdu, Vsn, MsgData, Addr, Port, _ExtraInfo}, State) -> +handle_cast({send_pdu, Pdu, Vsn, MsgData, Domain, Addr, Port, ExtraInfo}, + State) -> ?vlog("received send_pdu message with" "~n Pdu: ~p" "~n Vsn: ~p" "~n MsgData: ~p" + "~n Domain: ~p" "~n Addr: ~p" - "~n Port: ~p", [Pdu, Vsn, MsgData, Addr, Port]), - maybe_handle_send_pdu(Pdu, Vsn, MsgData, Addr, Port, State), + "~n Port: ~p", [Pdu, Vsn, MsgData, Domain, Addr, Port]), + maybe_process_extra_info(ExtraInfo), + maybe_handle_send_pdu(Pdu, Vsn, MsgData, Domain, Addr, Port, State), {noreply, State}; handle_cast({inform_response, Ref, Addr, Port}, State) -> @@ -544,8 +553,9 @@ handle_recv_msg(Addr, Port, Bytes, mpd_state = MpdState, sock = Sock, log = Log} = State) -> + Domain = snmp_conf:which_domain(Addr), % What the ****... Logger = logger(Log, read, Addr, Port), - case (catch snmpm_mpd:process_msg(Bytes, snmpUDPDomain, Addr, Port, + case (catch snmpm_mpd:process_msg(Bytes, Domain, Addr, Port, MpdState, NoteStore, Logger)) of {ok, Vsn, Pdu, MS, ACM} -> @@ -733,17 +743,17 @@ irgc_stop(Ref) -> (catch erlang:cancel_timer(Ref)). -maybe_handle_send_pdu(Pdu, Vsn, MsgData, Addr, Port, +maybe_handle_send_pdu(Pdu, Vsn, MsgData, Domain, Addr, Port, #state{filter = FilterMod} = State) -> case (catch FilterMod:accept_send_pdu(Addr, Port, pdu_type_of(Pdu))) of false -> inc(netIfPduOutDrops), ok; _ -> - handle_send_pdu(Pdu, Vsn, MsgData, Addr, Port, State) + handle_send_pdu(Pdu, Vsn, MsgData, Domain, Addr, Port, State) end. -handle_send_pdu(Pdu, Vsn, MsgData, Addr, Port, +handle_send_pdu(Pdu, Vsn, MsgData, _Domain, Addr, Port, #state{server = Pid, note_store = NoteStore, sock = Sock, @@ -999,6 +1009,19 @@ pdu_type_of(TrapPdu) when is_record(TrapPdu, trappdu) -> %% ------------------------------------------------------------------- +%% At this point this function is used during testing +maybe_process_extra_info(?DEFAULT_EXTRA_INFO) -> + ok; +maybe_process_extra_info({?SNMPM_EXTRA_INFO_TAG, Fun}) + when is_function(Fun, 0) -> + (catch Fun()), + ok; +maybe_process_extra_info(_ExtraInfo) -> + ok. + + +%% ------------------------------------------------------------------- + t() -> {A,B,C} = erlang:now(), A*1000000000+B*1000+(C div 1000). diff --git a/lib/snmp/src/manager/snmpm_server.erl b/lib/snmp/src/manager/snmpm_server.erl index 1349a64172..484954addb 100644 --- a/lib/snmp/src/manager/snmpm_server.erl +++ b/lib/snmp/src/manager/snmpm_server.erl @@ -32,14 +32,14 @@ register_user/4, register_user_monitor/4, unregister_user/1, - sync_get/4, sync_get/5, sync_get/6, - async_get/4, async_get/5, async_get/6, - sync_get_next/4, sync_get_next/5, sync_get_next/6, - async_get_next/4, async_get_next/5, async_get_next/6, - sync_get_bulk/6, sync_get_bulk/7, sync_get_bulk/8, - async_get_bulk/6, async_get_bulk/7, async_get_bulk/8, - sync_set/4, sync_set/5, sync_set/6, - async_set/4, async_set/5, async_set/6, + sync_get2/4, + async_get2/4, + sync_get_next2/4, + async_get_next2/4, + sync_get_bulk2/6, + async_get_bulk2/6, + sync_set2/4, + async_set2/4, cancel_async_request/2, %% discovery/2, discovery/3, discovery/4, discovery/5, discovery/6, @@ -55,6 +55,20 @@ ]). +%% <BACKWARD-COMPAT> +-export([sync_get/4, sync_get/5, sync_get/6, + async_get/4, async_get/5, async_get/6, + sync_get_next/4, sync_get_next/5, sync_get_next/6, + async_get_next/4, async_get_next/5, async_get_next/6, + sync_get_bulk/6, sync_get_bulk/7, sync_get_bulk/8, + async_get_bulk/6, async_get_bulk/7, async_get_bulk/8, + sync_set/4, sync_set/5, sync_set/6, + async_set/4, async_set/5, async_set/6 + ]). +%% </BACKWARD-COMPAT> + + + %% Internal exports -export([init/1, handle_call/3, handle_cast/2, handle_info/2, code_change/3, terminate/2]). @@ -75,13 +89,39 @@ -define(SERVER, ?MODULE). --define(SYNC_GET_TIMEOUT, 5000). --define(SYNC_SET_TIMEOUT, 5000). --define(DEFAULT_ASYNC_EXPIRE, 5000). --define(EXTRA_INFO, undefined). - --define(SNMP_AGENT_PORT, 161). - +-define(DEFAULT_SYNC_TIMEOUT, timer:seconds(5)). +-define(DEFAULT_SYNC_GET_TIMEOUT, ?DEFAULT_SYNC_TIMEOUT). +-define(DEFAULT_SYNC_GET_NEXT_TIMEOUT, ?DEFAULT_SYNC_TIMEOUT). +-define(DEFAULT_SYNC_GET_BULK_TIMEOUT, ?DEFAULT_SYNC_TIMEOUT). +-define(DEFAULT_SYNC_SET_TIMEOUT, ?DEFAULT_SYNC_TIMEOUT). + +-define(DEFAULT_ASYNC_TIMEOUT, timer:seconds(5)). +-define(DEFAULT_ASYNC_GET_TIMEOUT, ?DEFAULT_ASYNC_TIMEOUT). +-define(DEFAULT_ASYNC_GET_NEXT_TIMEOUT, ?DEFAULT_ASYNC_TIMEOUT). +-define(DEFAULT_ASYNC_GET_BULK_TIMEOUT, ?DEFAULT_ASYNC_TIMEOUT). +-define(DEFAULT_ASYNC_SET_TIMEOUT, ?DEFAULT_ASYNC_TIMEOUT). + +-define(SNMP_AGENT_PORT, 161). + +-define(SYNC_GET_TIMEOUT(SendOpts), + get_opt(timeout, ?DEFAULT_SYNC_GET_TIMEOUT, SendOpts)). +-define(SYNC_GET_NEXT_TIMEOUT(SendOpts), + get_opt(timeout, ?DEFAULT_SYNC_GET_NEXT_TIMEOUT, SendOpts)). +-define(SYNC_GET_BULK_TIMEOUT(SendOpts), + get_opt(timeout, ?DEFAULT_SYNC_GET_BULK_TIMEOUT, SendOpts)). +-define(SYNC_SET_TIMEOUT(SendOpts), + get_opt(timeout, ?DEFAULT_SYNC_SET_TIMEOUT, SendOpts)). + +-define(ASYNC_GET_TIMEOUT(SendOpts), + get_opt(timeout, ?DEFAULT_ASYNC_GET_TIMEOUT, SendOpts)). +-define(ASYNC_GET_NEXT_TIMEOUT(SendOpts), + get_opt(timeout, ?DEFAULT_ASYNC_GET_NEXT_TIMEOUT, SendOpts)). +-define(ASYNC_GET_BULK_TIMEOUT(SendOpts), + get_opt(timeout, ?DEFAULT_ASYNC_GET_BULK_TIMEOUT, SendOpts)). +-define(ASYNC_SET_TIMEOUT(SendOpts), + get_opt(timeout, ?DEFAULT_ASYNC_SET_TIMEOUT, SendOpts)). + +-define(GET_EXTRA(SendOpts), get_opt(extra, ?DEFAULT_EXTRA_INFO, SendOpts)). -ifdef(snmp_debug). -define(GS_START_LINK(Args), @@ -121,7 +161,8 @@ {id, user_id, reg_type, - target, + target, + domain, addr, port, type, @@ -192,142 +233,235 @@ unregister_user(UserId) -> %% -- [sync] get -- -sync_get(UserId, TargetName, CC, Oids) -> - sync_get(UserId, TargetName, CC, Oids, ?SYNC_GET_TIMEOUT). +%% The reason why we have a sync_get2 is to simplify backward +%% compatibillity. -sync_get(UserId, TargetName, CC, Oids, Timeout) -> - sync_get(UserId, TargetName, CC, Oids, Timeout, ?EXTRA_INFO). +%% sync_get2(UserId, TargetName, Oids) -> +%% sync_get2(UserId, TargetName, Oids, []). +sync_get2(UserId, TargetName, Oids, Opts) -> + call({sync_get, self(), UserId, TargetName, Oids, Opts}). -sync_get(UserId, TargetName, CC, Oids, Timeout, ExtraInfo) + +%% <BACKWARD-COMPAT> +sync_get(UserId, TargetName, CtxName, Oids) -> + sync_get(UserId, TargetName, CtxName, Oids, + ?DEFAULT_SYNC_GET_TIMEOUT). + +sync_get(UserId, TargetName, CtxName, Oids, Timeout) -> + sync_get(UserId, TargetName, CtxName, Oids, Timeout, ?DEFAULT_EXTRA_INFO). + +sync_get(UserId, TargetName, CtxName, Oids, Timeout, ExtraInfo) when is_list(TargetName) andalso + is_list(CtxName) andalso is_list(Oids) andalso is_integer(Timeout) -> - call({sync_get, self(), UserId, TargetName, CC, Oids, Timeout, ExtraInfo}). + Opts = [{context, CtxName}, {timeout, Timeout}, {extra, ExtraInfo}], + sync_get2(UserId, TargetName, Oids, Opts). +%% </BACKWARD-COMPAT> + + %% -- [async] get -- -async_get(UserId, TargetName, CC, Oids) -> - async_get(UserId, TargetName, CC, Oids, ?DEFAULT_ASYNC_EXPIRE, ?EXTRA_INFO). +%% async_get2(UserId, TargetName, Oids) -> +%% async_get2(UserId, TargetName, Oids, []). +async_get2(UserId, TargetName, Oids, SendOpts) -> + call({async_get, self(), UserId, TargetName, Oids, SendOpts}). -async_get(UserId, TargetName, CC, Oids, Expire) -> - async_get(UserId, TargetName, CC, Oids, Expire, ?EXTRA_INFO). -async_get(UserId, TargetName, CC, Oids, Expire, ExtraInfo) +%% <BACKWARD-COMPAT> +async_get(UserId, TargetName, CtxName, Oids) -> + async_get(UserId, TargetName, CtxName, Oids, + ?DEFAULT_ASYNC_GET_TIMEOUT, ?DEFAULT_EXTRA_INFO). + +async_get(UserId, TargetName, CtxName, Oids, Expire) -> + async_get(UserId, TargetName, CtxName, Oids, Expire, ?DEFAULT_EXTRA_INFO). + +async_get(UserId, TargetName, CtxName, Oids, Expire, ExtraInfo) when (is_list(TargetName) andalso + is_list(CtxName) andalso is_list(Oids) andalso is_integer(Expire) andalso (Expire >= 0)) -> - call({async_get, self(), UserId, TargetName, CC, Oids, Expire, ExtraInfo}). + SendOpts = [{context, CtxName}, {expire, Expire}, {extra, ExtraInfo}], + async_get2(UserId, TargetName, Oids, SendOpts). +%% </BACKWARD-COMPAT> + + %% -- [sync] get-next -- -sync_get_next(UserId, TargetName, CC, Oids) -> - sync_get_next(UserId, TargetName, CC, Oids, ?SYNC_GET_TIMEOUT, - ?EXTRA_INFO). +%% sync_get_next2(UserId, TargetName, Oids) -> +%% sync_get_next2(UserId, TargetName, Oids, []). +sync_get_next2(UserId, TargetName, Oids, SendOpts) -> + call({sync_get_next, self(), UserId, TargetName, Oids, SendOpts}). -sync_get_next(UserId, TargetName, CC, Oids, Timeout) -> - sync_get_next(UserId, TargetName, CC, Oids, Timeout, ?EXTRA_INFO). -sync_get_next(UserId, TargetName, CC, Oids, Timeout, ExtraInfo) +%% <BACKWARD-COMPAT> +sync_get_next(UserId, TargetName, CtxName, Oids) -> + sync_get_next(UserId, TargetName, CtxName, Oids, + ?DEFAULT_SYNC_GET_TIMEOUT, ?DEFAULT_EXTRA_INFO). + +sync_get_next(UserId, TargetName, CtxName, Oids, Timeout) -> + sync_get_next(UserId, TargetName, CtxName, Oids, Timeout, + ?DEFAULT_EXTRA_INFO). + +sync_get_next(UserId, TargetName, CtxName, Oids, Timeout, ExtraInfo) when is_list(TargetName) andalso + is_list(CtxName) andalso is_list(Oids) andalso is_integer(Timeout) -> - call({sync_get_next, self(), UserId, TargetName, CC, Oids, Timeout, - ExtraInfo}). + SendOpts = [{context, CtxName}, {timeout, Timeout}, {extra, ExtraInfo}], + sync_get_next2(UserId, TargetName, Oids, SendOpts). +%% <BACKWARD-COMPAT> + + %% -- [async] get-next -- -async_get_next(UserId, TargetName, CC, Oids) -> - async_get_next(UserId, TargetName, CC, Oids, - ?DEFAULT_ASYNC_EXPIRE, ?EXTRA_INFO). +%% async_get_next2(UserId, TargetName, Oids) -> +%% async_get_next2(UserId, TargetName, Oids, []). +async_get_next2(UserId, TargetName, Oids, SendOpts) -> + call({async_get_next, self(), UserId, TargetName, Oids, SendOpts}). + -async_get_next(UserId, TargetName, CC, Oids, Expire) -> - async_get_next(UserId, TargetName, CC, Oids, Expire, ?EXTRA_INFO). +async_get_next(UserId, TargetName, CtxName, Oids) -> + async_get_next(UserId, TargetName, CtxName, Oids, + ?DEFAULT_ASYNC_GET_NEXT_TIMEOUT, ?DEFAULT_EXTRA_INFO). -async_get_next(UserId, TargetName, CC, Oids, Expire, ExtraInfo) +async_get_next(UserId, TargetName, CtxName, Oids, Expire) -> + async_get_next(UserId, TargetName, CtxName, Oids, Expire, + ?DEFAULT_EXTRA_INFO). + +async_get_next(UserId, TargetName, CtxName, Oids, Expire, ExtraInfo) when (is_list(TargetName) andalso + is_list(CtxName) andalso is_list(Oids) andalso is_integer(Expire) andalso (Expire >= 0)) -> - call({async_get_next, self(), UserId, TargetName, CC, Oids, - Expire, ExtraInfo}). + SendOpts = [{context, CtxName}, {expire, Expire}, {extra, ExtraInfo}], + async_get_next2(UserId, TargetName, Oids, SendOpts). + + %% -- [sync] get-bulk -- -sync_get_bulk(UserId, TargetName, NonRep, MaxRep, CC, Oids) -> +%% sync_get_bulk2(UserId, TargetName, NonRep, MaxRep, Oids) -> +%% sync_get_bulk2(UserId, TargetName, NonRep, MaxRep, Oids, []). +sync_get_bulk2(UserId, TargetName, NonRep, MaxRep, Oids, SendOpts) -> + %% p("sync_get_bulk2 -> entry with" + %% "~n UserId: ~p" + %% "~n TargetName: ~p" + %% "~n NonRep: ~p" + %% "~n MaxRep: ~p" + %% "~n Oids: ~p" + %% "~n SendOpts: ~p", + %% [UserId, TargetName, NonRep, MaxRep, Oids, SendOpts]), + call({sync_get_bulk, self(), UserId, TargetName, + NonRep, MaxRep, Oids, SendOpts}). + +sync_get_bulk(UserId, TargetName, NonRep, MaxRep, CtxName, Oids) -> sync_get_bulk(UserId, TargetName, - NonRep, MaxRep, CC, Oids, - ?SYNC_GET_TIMEOUT, ?EXTRA_INFO). + NonRep, MaxRep, CtxName, Oids, + ?DEFAULT_SYNC_GET_TIMEOUT, ?DEFAULT_EXTRA_INFO). -sync_get_bulk(UserId, TargetName, NonRep, MaxRep, CC, Oids, Timeout) -> +sync_get_bulk(UserId, TargetName, NonRep, MaxRep, CtxName, Oids, Timeout) -> sync_get_bulk(UserId, TargetName, - NonRep, MaxRep, CC, Oids, - Timeout, ?EXTRA_INFO). + NonRep, MaxRep, CtxName, Oids, + Timeout, ?DEFAULT_EXTRA_INFO). -sync_get_bulk(UserId, TargetName, NonRep, MaxRep, CC, Oids, Timeout, +sync_get_bulk(UserId, TargetName, NonRep, MaxRep, CtxName, Oids, Timeout, ExtraInfo) when is_list(TargetName) andalso is_integer(NonRep) andalso is_integer(MaxRep) andalso + is_list(CtxName) andalso is_list(Oids) andalso is_integer(Timeout) -> - call({sync_get_bulk, self(), UserId, TargetName, - NonRep, MaxRep, CC, Oids, Timeout, ExtraInfo}). + SendOpts = [{context, CtxName}, {timeout, Timeout}, {extra, ExtraInfo}], + sync_get_bulk2(UserId, TargetName, NonRep, MaxRep, Oids, SendOpts). + %% -- [async] get-bulk -- -async_get_bulk(UserId, TargetName, NonRep, MaxRep, CC, Oids) -> +%% async_get_bulk2(UserId, TargetName, NonRep, MaxRep, Oids) -> +%% async_get_bulk2(UserId, TargetName, NonRep, MaxRep, Oids, []). +async_get_bulk2(UserId, TargetName, NonRep, MaxRep, Oids, SendOpts) -> + call({async_get_bulk, self(), UserId, TargetName, NonRep, MaxRep, + Oids, SendOpts}). + + +async_get_bulk(UserId, TargetName, NonRep, MaxRep, CtxName, Oids) -> async_get_bulk(UserId, TargetName, - NonRep, MaxRep, CC, Oids, - ?DEFAULT_ASYNC_EXPIRE, ?EXTRA_INFO). + NonRep, MaxRep, CtxName, Oids, + ?DEFAULT_ASYNC_GET_BULK_TIMEOUT, ?DEFAULT_EXTRA_INFO). -async_get_bulk(UserId, TargetName, NonRep, MaxRep, CC, Oids, Expire) -> +async_get_bulk(UserId, TargetName, NonRep, MaxRep, CtxName, Oids, Expire) -> async_get_bulk(UserId, TargetName, - NonRep, MaxRep, CC, Oids, - Expire, ?EXTRA_INFO). + NonRep, MaxRep, CtxName, Oids, + Expire, ?DEFAULT_EXTRA_INFO). -async_get_bulk(UserId, TargetName, NonRep, MaxRep, CC, Oids, Expire, +async_get_bulk(UserId, TargetName, NonRep, MaxRep, CtxName, Oids, Expire, ExtraInfo) when is_list(TargetName) andalso is_integer(NonRep) andalso is_integer(MaxRep) andalso + is_list(CtxName) andalso is_list(Oids) andalso is_integer(Expire) -> - call({async_get_bulk, self(), UserId, TargetName, - NonRep, MaxRep, CC, Oids, Expire, ExtraInfo}). + SendOpts = [{context, CtxName}, {expire, Expire}, {extra, ExtraInfo}], + async_get_bulk2(UserId, TargetName, NonRep, MaxRep, Oids, SendOpts). + + %% -- [sync] set -- %% VarsAndValues is: {PlainOid, o|s|i, Value} (unknown mibs) | {Oid, Value} -sync_set(UserId, TargetName, CC, VarsAndVals) -> - sync_set(UserId, TargetName, CC, VarsAndVals, - ?SYNC_SET_TIMEOUT, ?EXTRA_INFO). +%% sync_set2(UserId, TargetName, VarsAndVals) -> +%% sync_set2(UserId, TargetName, VarsAndVals, []). +sync_set2(UserId, TargetName, VarsAndVals, SendOpts) -> + call({sync_set, self(), UserId, TargetName, VarsAndVals, SendOpts}). + + +sync_set(UserId, TargetName, CtxName, VarsAndVals) -> + sync_set(UserId, TargetName, CtxName, VarsAndVals, + ?DEFAULT_SYNC_SET_TIMEOUT, ?DEFAULT_EXTRA_INFO). -sync_set(UserId, TargetName, CC, VarsAndVals, Timeout) -> - sync_set(UserId, TargetName, CC, VarsAndVals, - Timeout, ?EXTRA_INFO). +sync_set(UserId, TargetName, CtxName, VarsAndVals, Timeout) -> + sync_set(UserId, TargetName, CtxName, VarsAndVals, + Timeout, ?DEFAULT_EXTRA_INFO). -sync_set(UserId, TargetName, CC, VarsAndVals, Timeout, ExtraInfo) +sync_set(UserId, TargetName, CtxName, VarsAndVals, Timeout, ExtraInfo) when is_list(TargetName) andalso + is_list(CtxName) andalso is_list(VarsAndVals) andalso is_integer(Timeout) -> - call({sync_set, self(), UserId, TargetName, - CC, VarsAndVals, Timeout, ExtraInfo}). + SendOpts = [{context, CtxName}, {timeout, Timeout}, {extra, ExtraInfo}], + sync_set2(UserId, TargetName, VarsAndVals, SendOpts). + + %% -- [async] set -- -async_set(UserId, TargetName, CC, VarsAndVals) -> - async_set(UserId, TargetName, CC, VarsAndVals, - ?DEFAULT_ASYNC_EXPIRE, ?EXTRA_INFO). +%% async_set2(UserId, TargetName, VarsAndVals) -> +%% async_set2(UserId, TargetName, VarsAndVals, []). +async_set2(UserId, TargetName, VarsAndVals, SendOpts) -> + call({async_set, self(), UserId, TargetName, VarsAndVals, SendOpts}). + -async_set(UserId, TargetName, CC, VarsAndVals, Expire) -> - async_set(UserId, TargetName, CC, VarsAndVals, - Expire, ?EXTRA_INFO). +async_set(UserId, TargetName, CtxName, VarsAndVals) -> + async_set(UserId, TargetName, CtxName, VarsAndVals, + ?DEFAULT_ASYNC_SET_TIMEOUT, ?DEFAULT_EXTRA_INFO). -async_set(UserId, TargetName, CC, VarsAndVals, Expire, ExtraInfo) +async_set(UserId, TargetName, CtxName, VarsAndVals, Expire) -> + async_set(UserId, TargetName, CtxName, VarsAndVals, + Expire, ?DEFAULT_EXTRA_INFO). + +async_set(UserId, TargetName, CtxName, VarsAndVals, Expire, ExtraInfo) when (is_list(TargetName) andalso + is_list(CtxName) andalso is_list(VarsAndVals) andalso is_integer(Expire) andalso (Expire >= 0)) -> - call({async_set, self(), UserId, TargetName, - CC, VarsAndVals, Expire, ExtraInfo}). + SendOpts = [{context, CtxName}, {expire, Expire}, {extra, ExtraInfo}], + async_set2(UserId, TargetName, VarsAndVals, SendOpts). cancel_async_request(UserId, ReqId) -> @@ -560,38 +694,93 @@ handle_call({unregister_user, UserId}, _From, State) -> %% We will reply to this request later, when the reply comes in from the %% agent, or when the timeout hits (unless we get an error now). -handle_call({sync_get, Pid, UserId, TargetName, CC, Oids, Timeout, ExtraInfo}, +handle_call({sync_get, Pid, UserId, TargetName, Oids, SendOpts}, From, State) -> - ?vlog("received sync_get [~p] request", [CC]), + ?vlog("[~p,~p] received sync_get request for: " + "~n ~p", [UserId, TargetName, Oids]), case (catch handle_sync_get(Pid, - UserId, TargetName, CC, Oids, + UserId, TargetName, Oids, SendOpts, + From, State)) of + ok -> + {noreply, State}; + Error -> + {reply, Error, State} + end; + +%% <BACKWARD-COMPAT> +%% The only case where this would be called is during code upgrade +handle_call({sync_get, + Pid, UserId, TargetName, CtxName, Oids, Timeout, ExtraInfo}, + From, State) -> + ?vlog("[~p,~p,~p] received sync_get request for: " + "~n ~p", [UserId, TargetName, CtxName, Oids]), + case (catch handle_sync_get(Pid, + UserId, TargetName, CtxName, Oids, Timeout, ExtraInfo, From, State)) of ok -> {noreply, State}; Error -> {reply, Error, State} end; +%% </BACKWARD-COMPAT> -handle_call({sync_get_next, Pid, UserId, TargetName, CC, Oids, Timeout, ExtraInfo}, From, State) -> - ?vlog("received sync_get_next [~p] request", [CC]), +handle_call({sync_get_next, Pid, UserId, TargetName, Oids, SendOpts}, + From, State) -> + ?vlog("[~p,~p] received sync_get_next request for: " + "~n ~p", [UserId, TargetName, SendOpts]), case (catch handle_sync_get_next(Pid, - UserId, TargetName, CC, Oids, + UserId, TargetName, Oids, SendOpts, + From, State)) of + ok -> + {noreply, State}; + Error -> + {reply, Error, State} + end; + + +%% <BACKWARD-COMPAT> +%% The only case where this would be called is during code upgrade +handle_call({sync_get_next, + Pid, UserId, TargetName, CtxName, Oids, Timeout, ExtraInfo}, + From, State) -> + ?vlog("[~p,~p,~p] received sync_get_next request for" + "~n ~p", [UserId, TargetName, CtxName, Oids]), + case (catch handle_sync_get_next(Pid, + UserId, TargetName, CtxName, Oids, Timeout, ExtraInfo, From, State)) of ok -> {noreply, State}; Error -> {reply, Error, State} end; +%% </BACKWARD-COMPAT> %% Check agent version? This op not in v1 +handle_call({sync_get_bulk, + Pid, UserId, TargetName, NonRep, MaxRep, Oids, SendOpts}, + From, State) -> + ?vlog("[~p,~p] received sync_get_bulk request for: " + "~n ~p", [UserId, TargetName, Oids]), + case (catch handle_sync_get_bulk(Pid, + UserId, TargetName, NonRep, MaxRep, Oids, + SendOpts, From, State)) of + ok -> + {noreply, State}; + Error -> + {reply, Error, State} + end; + +%% <BACKWARD-COMPAT> +%% The only case where this would be called is during code upgrade handle_call({sync_get_bulk, Pid, UserId, TargetName, - NonRep, MaxRep, CC, Oids, Timeout, ExtraInfo}, + NonRep, MaxRep, CtxName, Oids, Timeout, ExtraInfo}, From, State) -> - ?vlog("received sync_get_bulk [~p] request", [CC]), + ?vlog("[~p,~p] received sync_get_bulk request for: ~p" + "~n ~p", [UserId, TargetName, CtxName, Oids]), case (catch handle_sync_get_bulk(Pid, - UserId, TargetName, CC, + UserId, TargetName, CtxName, NonRep, MaxRep, Oids, Timeout, ExtraInfo, From, State)) of ok -> @@ -599,59 +788,138 @@ handle_call({sync_get_bulk, Pid, UserId, TargetName, Error -> {reply, Error, State} end; +%% </BACKWARD-COMPAT> + + +handle_call({sync_set, + Pid, UserId, TargetName, VarsAndVals, SendOpts}, + From, State) -> + ?vlog("[~p,~p] received sync_set request for: " + "~n ~p", [UserId, TargetName, VarsAndVals]), + case (catch handle_sync_set(Pid, + UserId, TargetName, VarsAndVals, SendOpts, + From, State)) of + ok -> + {noreply, State}; + Error -> + {reply, Error, State} + end; +%% <BACKWARD-COMPAT> +%% The only case where this would be called is during code upgrade handle_call({sync_set, Pid, UserId, TargetName, - CC, VarsAndVals, Timeout, ExtraInfo}, + CtxName, VarsAndVals, Timeout, ExtraInfo}, From, State) -> - ?vlog("received sync_set [~p] request", [CC]), + ?vlog("[~p,~p,~p] received sync_set request for: " + "~n ~p", [UserId, TargetName, CtxName, VarsAndVals]), case (catch handle_sync_set(Pid, - UserId, TargetName, CC, VarsAndVals, + UserId, TargetName, CtxName, VarsAndVals, Timeout, ExtraInfo, From, State)) of ok -> {noreply, State}; Error -> {reply, Error, State} end; +%% </BACKWARD-COMPAT> +handle_call({async_get, Pid, UserId, TargetName, Oids, SendOpts}, + _From, State) -> + ?vlog("[~p,~p] received async_get request for: " + "~n ~p", [UserId, TargetName, Oids]), + Reply = (catch handle_async_get(Pid, + UserId, TargetName, Oids, SendOpts, + State)), + {reply, Reply, State}; + + +%% <BACKWARD-COMPAT> +%% The only case where this would be called is during code upgrade handle_call({async_get, Pid, UserId, TargetName, - CC, Oids, Expire, ExtraInfo}, + CtxName, Oids, Expire, ExtraInfo}, _From, State) -> - ?vlog("received async_get [~p] request", [CC]), - Reply = (catch handle_async_get(Pid, UserId, TargetName, CC, Oids, + ?vlog("[~p,~p,~p] received async_get request for: " + "~n ~p", [UserId, TargetName, CtxName, Oids]), + Reply = (catch handle_async_get(Pid, UserId, TargetName, CtxName, Oids, Expire, ExtraInfo, State)), {reply, Reply, State}; +%% </BACKWARD-COMPAT> +handle_call({async_get_next, Pid, UserId, TargetName, Oids, SendOpts}, + _From, State) -> + ?vlog("[~p,~p] received async_get_next request for: " + "~n ~p", [UserId, TargetName, Oids]), + Reply = (catch handle_async_get_next(Pid, + UserId, TargetName, Oids, SendOpts, + State)), + {reply, Reply, State}; + + +%% <BACKWARD-COMPAT> +%% The only case where this would be called is during code upgrade handle_call({async_get_next, Pid, UserId, TargetName, - CC, Oids, Expire, ExtraInfo}, + CtxName, Oids, Expire, ExtraInfo}, _From, State) -> - ?vlog("received async_get_next [~p] request", [CC]), - Reply = (catch handle_async_get_next(Pid, UserId, TargetName, CC, + ?vlog("[~p,~p,~p] received async_get_next request for: ", + [UserId, TargetName, CtxName, Oids]), + Reply = (catch handle_async_get_next(Pid, UserId, TargetName, CtxName, Oids, Expire, ExtraInfo, State)), {reply, Reply, State}; +%% </BACKWARD-COMPAT> %% Check agent version? This op not in v1 +handle_call({async_get_bulk, + Pid, UserId, TargetName, NonRep, MaxRep, Oids, SendOpts}, + _From, State) -> + ?vlog("[~p,~p] received async_get_bulk request for: " + "~n ~p", [UserId, TargetName, Oids]), + Reply = (catch handle_async_get_bulk(Pid, + UserId, TargetName, + NonRep, MaxRep, Oids, SendOpts, + State)), + {reply, Reply, State}; + + +%% <BACKWARD-COMPAT> +%% The only case where this would be called is during code upgrade handle_call({async_get_bulk, Pid, UserId, TargetName, - NonRep, MaxRep, CC, Oids, Expire, ExtraInfo}, + NonRep, MaxRep, CtxName, Oids, Expire, ExtraInfo}, _From, State) -> - ?vlog("received async_get_bulk [~p] request", [CC]), + ?vlog("[~p,~p,~p] received async_get_bulk request for: " + "~n ~p", [UserId, TargetName, CtxName, Oids]), Reply = (catch handle_async_get_bulk(Pid, - UserId, TargetName, CC, + UserId, TargetName, CtxName, NonRep, MaxRep, Oids, Expire, ExtraInfo, State)), {reply, Reply, State}; +%% </BACKWARD-COMPAT> +handle_call({async_set, + Pid, UserId, TargetName, VarsAndVals, SendOpts}, + _From, State) -> + ?vlog("[~p,~p] received async_set request for: " + "~n ~p", [UserId, TargetName, VarsAndVals]), + Reply = (catch handle_async_set(Pid, + UserId, TargetName, VarsAndVals, SendOpts, + State)), + {reply, Reply, State}; + + +%% <BACKWARD-COMPAT> +%% The only case where this would be called is during code upgrade handle_call({async_set, Pid, UserId, TargetName, - CC, VarsAndVals, Expire, ExtraInfo}, + CtxName, VarsAndVals, Expire, ExtraInfo}, _From, State) -> - ?vlog("received async_set [~p] request", [CC]), - Reply = (catch handle_async_set(Pid, UserId, TargetName, CC, + ?vlog("[~p,~p,~p] received async_set request for: " + "~n ~p", [UserId, TargetName, CtxName, VarsAndVals]), + Reply = (catch handle_async_set(Pid, UserId, TargetName, CtxName, VarsAndVals, Expire, ExtraInfo, State)), {reply, Reply, State}; +%% </BACKWARD-COMPAT> handle_call({cancel_async_request, UserId, ReqId}, _From, State) -> @@ -888,38 +1156,50 @@ terminate(Reason, #state{gct = GCT}) -> %% %%---------------------------------------------------------------------- -handle_sync_get(Pid, UserId, TargetName, CC, Oids, Timeout, ExtraInfo, +handle_sync_get(Pid, UserId, TargetName, CtxName, Oids, Timeout, ExtraInfo, From, State) -> + SendOpts = + [ + {context, CtxName}, + {timeout, Timeout}, + {extra, ExtraInfo} + ], + handle_sync_get(Pid, UserId, TargetName, Oids, SendOpts, From, State). + +handle_sync_get(Pid, UserId, TargetName, Oids, SendOpts, From, State) -> ?vtrace("handle_sync_get -> entry with" "~n Pid: ~p" "~n UserId: ~p" "~n TargetName: ~p" - "~n CC: ~p" "~n Oids: ~p" - "~n Timeout: ~p" + "~n SendOpts: ~p" "~n From: ~p", - [Pid, UserId, TargetName, CC, Oids, Timeout, From]), - case agent_data(TargetName, CC) of - {ok, RegType, Addr, Port, Vsn, MsgData} -> + [Pid, UserId, TargetName, Oids, SendOpts, From]), + case agent_data(TargetName, SendOpts) of + {ok, RegType, Domain, Addr, Port, Vsn, MsgData} -> ?vtrace("handle_sync_get -> send a ~p message", [Vsn]), - ReqId = send_get_request(Oids, Vsn, MsgData, Addr, Port, - ExtraInfo, State), + Extra = ?GET_EXTRA(SendOpts), + ReqId = send_get_request(Oids, Vsn, MsgData, + Domain, Addr, Port, + Extra, State), ?vdebug("handle_sync_get -> ReqId: ~p", [ReqId]), - Msg = {sync_timeout, ReqId, From}, - Ref = erlang:send_after(Timeout, self(), Msg), - MonRef = erlang:monitor(process, Pid), + Msg = {sync_timeout, ReqId, From}, + Timeout = ?SYNC_GET_TIMEOUT(SendOpts), + Ref = erlang:send_after(Timeout, self(), Msg), + MonRef = erlang:monitor(process, Pid), ?vtrace("handle_sync_get -> MonRef: ~p", [MonRef]), - Req = #request{id = ReqId, - user_id = UserId, - reg_type = RegType, - target = TargetName, - addr = Addr, - port = Port, - type = get, - data = MsgData, - ref = Ref, - mon = MonRef, - from = From}, + Req = #request{id = ReqId, + user_id = UserId, + reg_type = RegType, + target = TargetName, + domain = Domain, + addr = Addr, + port = Port, + type = get, + data = MsgData, + ref = Ref, + mon = MonRef, + from = From}, ets:insert(snmpm_request_table, Req), ok; Error -> @@ -929,39 +1209,51 @@ handle_sync_get(Pid, UserId, TargetName, CC, Oids, Timeout, ExtraInfo, Error end. - -handle_sync_get_next(Pid, UserId, TargetName, CC, Oids, Timeout, +handle_sync_get_next(Pid, UserId, TargetName, CtxName, Oids, Timeout, ExtraInfo, From, State) -> + SendOpts = + [ + {context, CtxName}, + {timeout, Timeout}, + {extra, ExtraInfo} + ], + handle_sync_get_next(Pid, UserId, TargetName, Oids, SendOpts, From, State). + +handle_sync_get_next(Pid, UserId, TargetName, Oids, SendOpts, + From, State) -> ?vtrace("handle_sync_get_next -> entry with" "~n Pid: ~p" "~n UserId: ~p" "~n TargetName: ~p" - "~n CC: ~p" "~n Oids: ~p" - "~n Timeout: ~p" + "~n SendOpts: ~p" "~n From: ~p", - [Pid, UserId, TargetName, CC, Oids, Timeout, From]), - case agent_data(TargetName, CC) of - {ok, RegType, Addr, Port, Vsn, MsgData} -> + [Pid, UserId, TargetName, Oids, SendOpts, From]), + case agent_data(TargetName, SendOpts) of + {ok, RegType, Domain, Addr, Port, Vsn, MsgData} -> ?vtrace("handle_sync_get_next -> send a ~p message", [Vsn]), - ReqId = send_get_next_request(Oids, Vsn, MsgData, - Addr, Port, ExtraInfo, State), + Extra = ?GET_EXTRA(SendOpts), + ReqId = send_get_next_request(Oids, Vsn, MsgData, + Domain, Addr, Port, + Extra, State), ?vdebug("handle_sync_get_next -> ReqId: ~p", [ReqId]), - Msg = {sync_timeout, ReqId, From}, - Ref = erlang:send_after(Timeout, self(), Msg), - MonRef = erlang:monitor(process, Pid), + Msg = {sync_timeout, ReqId, From}, + Timeout = ?SYNC_GET_NEXT_TIMEOUT(SendOpts), + Ref = erlang:send_after(Timeout, self(), Msg), + MonRef = erlang:monitor(process, Pid), ?vtrace("handle_sync_get_next -> MonRef: ~p", [MonRef]), - Req = #request{id = ReqId, - user_id = UserId, - reg_type = RegType, - target = TargetName, - addr = Addr, - port = Port, - type = get_next, - data = MsgData, - ref = Ref, - mon = MonRef, - from = From}, + Req = #request{id = ReqId, + user_id = UserId, + reg_type = RegType, + target = TargetName, + domain = Domain, + addr = Addr, + port = Port, + type = get_next, + data = MsgData, + ref = Ref, + mon = MonRef, + from = From}, ets:insert(snmpm_request_table, Req), ok; @@ -973,42 +1265,55 @@ handle_sync_get_next(Pid, UserId, TargetName, CC, Oids, Timeout, end. -handle_sync_get_bulk(Pid, UserId, TargetName, CC, +handle_sync_get_bulk(Pid, UserId, TargetName, CtxName, NonRep, MaxRep, Oids, Timeout, ExtraInfo, From, State) -> + SendOpts = + [ + {context, CtxName}, + {timeout, Timeout}, + {extra, ExtraInfo} + ], + handle_sync_get_bulk(Pid, UserId, TargetName, NonRep, MaxRep, Oids, + SendOpts, From, State). + +handle_sync_get_bulk(Pid, UserId, TargetName, NonRep, MaxRep, Oids, SendOpts, + From, State) -> ?vtrace("handle_sync_get_bulk -> entry with" "~n Pid: ~p" "~n UserId: ~p" "~n TargetName: ~p" - "~n CC: ~p" "~n NonRep: ~p" "~n MaxRep: ~p" "~n Oids: ~p" - "~n Timeout: ~p" + "~n SendOpts: ~p" "~n From: ~p", - [Pid, UserId, TargetName, CC, NonRep, MaxRep, Oids, - Timeout, From]), - case agent_data(TargetName, CC) of - {ok, RegType, Addr, Port, Vsn, MsgData} -> + [Pid, UserId, TargetName, NonRep, MaxRep, Oids, SendOpts, From]), + case agent_data(TargetName, SendOpts) of + {ok, RegType, Domain, Addr, Port, Vsn, MsgData} -> ?vtrace("handle_sync_get_bulk -> send a ~p message", [Vsn]), - ReqId = send_get_bulk_request(Oids, Vsn, MsgData, Addr, Port, - NonRep, MaxRep, ExtraInfo, State), + Extra = ?GET_EXTRA(SendOpts), + ReqId = send_get_bulk_request(Oids, Vsn, MsgData, + Domain, Addr, Port, + NonRep, MaxRep, Extra, State), ?vdebug("handle_sync_get_bulk -> ReqId: ~p", [ReqId]), - Msg = {sync_timeout, ReqId, From}, - Ref = erlang:send_after(Timeout, self(), Msg), - MonRef = erlang:monitor(process, Pid), + Msg = {sync_timeout, ReqId, From}, + Timeout = ?SYNC_GET_BULK_TIMEOUT(SendOpts), + Ref = erlang:send_after(Timeout, self(), Msg), + MonRef = erlang:monitor(process, Pid), ?vtrace("handle_sync_get_bulk -> MonRef: ~p", [MonRef]), - Req = #request{id = ReqId, - user_id = UserId, - reg_type = RegType, - target = TargetName, - addr = Addr, - port = Port, - type = get_bulk, - data = MsgData, - ref = Ref, - mon = MonRef, - from = From}, + Req = #request{id = ReqId, + user_id = UserId, + reg_type = RegType, + target = TargetName, + domain = Domain, + addr = Addr, + port = Port, + type = get_bulk, + data = MsgData, + ref = Ref, + mon = MonRef, + from = From}, ets:insert(snmpm_request_table, Req), ok; @@ -1020,38 +1325,51 @@ handle_sync_get_bulk(Pid, UserId, TargetName, CC, end. -handle_sync_set(Pid, UserId, TargetName, CC, VarsAndVals, Timeout, +handle_sync_set(Pid, UserId, TargetName, CtxName, VarsAndVals, Timeout, ExtraInfo, From, State) -> + SendOpts = + [ + {context, CtxName}, + {timeout, Timeout}, + {extra, ExtraInfo} + ], + handle_sync_set(Pid, UserId, TargetName, VarsAndVals, SendOpts, + From, State). + +handle_sync_set(Pid, UserId, TargetName, VarsAndVals, SendOpts, From, State) -> ?vtrace("handle_sync_set -> entry with" "~n Pid: ~p" "~n UserId: ~p" "~n TargetName: ~p" - "~n CC: ~p" "~n VarsAndVals: ~p" - "~n Timeout: ~p" + "~n SendOpts: ~p" "~n From: ~p", - [Pid, UserId, TargetName, CC, VarsAndVals, Timeout, From]), - case agent_data(TargetName, CC) of - {ok, RegType, Addr, Port, Vsn, MsgData} -> + [Pid, UserId, TargetName, VarsAndVals, From]), + case agent_data(TargetName, SendOpts) of + {ok, RegType, Domain, Addr, Port, Vsn, MsgData} -> ?vtrace("handle_sync_set -> send a ~p message", [Vsn]), - ReqId = send_set_request(VarsAndVals, Vsn, MsgData, - Addr, Port, ExtraInfo, State), + Extra = ?GET_EXTRA(SendOpts), + ReqId = send_set_request(VarsAndVals, Vsn, MsgData, + Domain, Addr, Port, + Extra, State), ?vdebug("handle_sync_set -> ReqId: ~p", [ReqId]), - Msg = {sync_timeout, ReqId, From}, - Ref = erlang:send_after(Timeout, self(), Msg), - MonRef = erlang:monitor(process, Pid), + Msg = {sync_timeout, ReqId, From}, + Timeout = ?SYNC_SET_TIMEOUT(SendOpts), + Ref = erlang:send_after(Timeout, self(), Msg), + MonRef = erlang:monitor(process, Pid), ?vtrace("handle_sync_set -> MonRef: ~p", [MonRef]), - Req = #request{id = ReqId, - user_id = UserId, - reg_type = RegType, - target = TargetName, - addr = Addr, - port = Port, - type = set, - data = MsgData, - ref = Ref, - mon = MonRef, - from = From}, + Req = #request{id = ReqId, + user_id = UserId, + reg_type = RegType, + target = TargetName, + domain = Domain, + addr = Addr, + port = Port, + type = set, + data = MsgData, + ref = Ref, + mon = MonRef, + from = From}, ets:insert(snmpm_request_table, Req), ok; @@ -1063,26 +1381,38 @@ handle_sync_set(Pid, UserId, TargetName, CC, VarsAndVals, Timeout, end. -handle_async_get(Pid, UserId, TargetName, CC, Oids, Expire, ExtraInfo, +handle_async_get(Pid, UserId, TargetName, CtxName, Oids, Expire, ExtraInfo, State) -> + SendOpts = + [ + {context, CtxName}, + {timeout, Expire}, + {extra, ExtraInfo} + ], + handle_async_get(Pid, UserId, TargetName, Oids, SendOpts, State). + +handle_async_get(Pid, UserId, TargetName, Oids, SendOpts, State) -> ?vtrace("handle_async_get -> entry with" "~n Pid: ~p" "~n UserId: ~p" "~n TargetName: ~p" - "~n CC: ~p" "~n Oids: ~p" - "~n Expire: ~p", - [Pid, UserId, TargetName, CC, Oids, Expire]), - case agent_data(TargetName, CC) of - {ok, RegType, Addr, Port, Vsn, MsgData} -> + "~n SendOpts: ~p", + [Pid, UserId, TargetName, Oids, SendOpts]), + case agent_data(TargetName, SendOpts) of + {ok, RegType, Domain, Addr, Port, Vsn, MsgData} -> ?vtrace("handle_async_get -> send a ~p message", [Vsn]), - ReqId = send_get_request(Oids, Vsn, MsgData, Addr, Port, - ExtraInfo, State), + Extra = ?GET_EXTRA(SendOpts), + ReqId = send_get_request(Oids, Vsn, MsgData, + Domain, Addr, Port, + Extra, State), ?vdebug("handle_async_get -> ReqId: ~p", [ReqId]), + Expire = ?ASYNC_GET_TIMEOUT(SendOpts), Req = #request{id = ReqId, user_id = UserId, reg_type = RegType, target = TargetName, + domain = Domain, addr = Addr, port = Port, type = get, @@ -1101,26 +1431,38 @@ handle_async_get(Pid, UserId, TargetName, CC, Oids, Expire, ExtraInfo, end. -handle_async_get_next(Pid, UserId, TargetName, CC, Oids, Expire, +handle_async_get_next(Pid, UserId, TargetName, CtxName, Oids, Expire, ExtraInfo, State) -> + SendOpts = + [ + {context, CtxName}, + {timeout, Expire}, + {extra, ExtraInfo} + ], + handle_async_get_next(Pid, UserId, TargetName, Oids, SendOpts, State). + +handle_async_get_next(Pid, UserId, TargetName, Oids, SendOpts, State) -> ?vtrace("handle_async_get_next -> entry with" "~n Pid: ~p" "~n UserId: ~p" "~n TargetName: ~p" - "~n CC: ~p" "~n Oids: ~p" - "~n Expire: ~p", - [Pid, UserId, TargetName, CC, Oids, Expire]), - case agent_data(TargetName, CC) of - {ok, RegType, Addr, Port, Vsn, MsgData} -> + "~n SendOpts: ~p", + [Pid, UserId, TargetName, Oids, SendOpts]), + case agent_data(TargetName, SendOpts) of + {ok, RegType, Domain, Addr, Port, Vsn, MsgData} -> ?vtrace("handle_async_get_next -> send a ~p message", [Vsn]), + Extra = ?GET_EXTRA(SendOpts), ReqId = send_get_next_request(Oids, Vsn, MsgData, - Addr, Port, ExtraInfo, State), + Domain, Addr, Port, + Extra, State), ?vdebug("handle_async_get_next -> ReqId: ~p", [ReqId]), + Expire = ?ASYNC_GET_NEXT_TIMEOUT(SendOpts), Req = #request{id = ReqId, user_id = UserId, reg_type = RegType, target = TargetName, + domain = Domain, addr = Addr, port = Port, type = get_next, @@ -1139,29 +1481,45 @@ handle_async_get_next(Pid, UserId, TargetName, CC, Oids, Expire, end. -handle_async_get_bulk(Pid, UserId, TargetName, CC, +handle_async_get_bulk(Pid, UserId, TargetName, CtxName, NonRep, MaxRep, Oids, Expire, ExtraInfo, State) -> + SendOpts = + [ + {context, CtxName}, + {timeout, Expire}, + {extra, ExtraInfo} + ], + handle_async_get_bulk(Pid, + UserId, TargetName, NonRep, MaxRep, Oids, SendOpts, + State). + +handle_async_get_bulk(Pid, + UserId, TargetName, NonRep, MaxRep, Oids, SendOpts, + State) -> ?vtrace("handle_async_get_bulk -> entry with" "~n Pid: ~p" "~n UserId: ~p" "~n TargetName: ~p" - "~n CC: ~p" "~n NonRep: ~p" "~n MaxRep: ~p" "~n Oids: ~p" - "~n Expire: ~p", - [Pid, UserId, TargetName, CC, NonRep, MaxRep, Oids, Expire]), - case agent_data(TargetName, CC) of - {ok, RegType, Addr, Port, Vsn, MsgData} -> + "~n SendOpts: ~p", + [Pid, UserId, TargetName, NonRep, MaxRep, Oids, SendOpts]), + case agent_data(TargetName, SendOpts) of + {ok, RegType, Domain, Addr, Port, Vsn, MsgData} -> ?vtrace("handle_async_get_bulk -> send a ~p message", [Vsn]), - ReqId = send_get_bulk_request(Oids, Vsn, MsgData, Addr, Port, - NonRep, MaxRep, ExtraInfo, State), + Extra = ?GET_EXTRA(SendOpts), + ReqId = send_get_bulk_request(Oids, Vsn, MsgData, + Domain, Addr, Port, + NonRep, MaxRep, Extra, State), ?vdebug("handle_async_get_bulk -> ReqId: ~p", [ReqId]), + Expire = ?ASYNC_GET_BULK_TIMEOUT(SendOpts), Req = #request{id = ReqId, user_id = UserId, reg_type = RegType, target = TargetName, + domain = Domain, addr = Addr, port = Port, type = get_bulk, @@ -1179,26 +1537,38 @@ handle_async_get_bulk(Pid, UserId, TargetName, CC, end. -handle_async_set(Pid, UserId, TargetName, CC, VarsAndVals, Expire, +handle_async_set(Pid, UserId, TargetName, CtxName, VarsAndVals, Expire, ExtraInfo, State) -> + SendOpts = + [ + {context, CtxName}, + {timeout, Expire}, + {extra, ExtraInfo} + ], + handle_async_set(Pid, UserId, TargetName, VarsAndVals, SendOpts, State). + +handle_async_set(Pid, UserId, TargetName, VarsAndVals, SendOpts, State) -> ?vtrace("handle_async_set -> entry with" "~n Pid: ~p" "~n UserId: ~p" "~n TargetName: ~p" - "~n CC: ~p" "~n VarsAndVals: ~p" - "~n Expire: ~p", - [Pid, UserId, TargetName, CC, VarsAndVals, Expire]), - case agent_data(TargetName, CC) of - {ok, RegType, Addr, Port, Vsn, MsgData} -> + "~n SendOpts: ~p", + [Pid, UserId, TargetName, VarsAndVals, SendOpts]), + case agent_data(TargetName, SendOpts) of + {ok, RegType, Domain, Addr, Port, Vsn, MsgData} -> ?vtrace("handle_async_set -> send a ~p message", [Vsn]), + Extra = ?GET_EXTRA(SendOpts), ReqId = send_set_request(VarsAndVals, Vsn, MsgData, - Addr, Port, ExtraInfo, State), + Domain, Addr, Port, + Extra, State), ?vdebug("handle_async_set -> ReqId: ~p", [ReqId]), + Expire = ?ASYNC_SET_TIMEOUT(SendOpts), Req = #request{id = ReqId, user_id = UserId, reg_type = RegType, target = TargetName, + domain = Domain, addr = Addr, port = Port, type = set, @@ -2554,7 +2924,7 @@ do_gc(Key, Now) -> %% %%---------------------------------------------------------------------- -send_get_request(Oids, Vsn, MsgData, Addr, Port, ExtraInfo, +send_get_request(Oids, Vsn, MsgData, Domain, Addr, Port, ExtraInfo, #state{net_if = NetIf, net_if_mod = Mod, mini_mib = MiniMIB}) -> @@ -2565,34 +2935,39 @@ send_get_request(Oids, Vsn, MsgData, Addr, Port, ExtraInfo, "~n Pdu: ~p" "~n Vsn: ~p" "~n MsgData: ~p" + "~n Domain: ~p" "~n Addr: ~p" - "~n Port: ~p", [Mod, NetIf, Pdu, Vsn, MsgData, Addr, Port]), - (catch Mod:send_pdu(NetIf, Pdu, Vsn, MsgData, Addr, Port, ExtraInfo)), + "~n Port: ~p", + [Mod, NetIf, Pdu, Vsn, MsgData, Domain, Addr, Port]), + Res = (catch Mod:send_pdu(NetIf, Pdu, Vsn, MsgData, + Domain, Addr, Port, ExtraInfo)), + ?vtrace("send_get_request -> send result:" + "~n ~p", [Res]), Pdu#pdu.request_id. -send_get_next_request(Oids, Vsn, MsgData, Addr, Port, ExtraInfo, +send_get_next_request(Oids, Vsn, MsgData, Domain, Addr, Port, ExtraInfo, #state{mini_mib = MiniMIB, net_if = NetIf, net_if_mod = Mod}) -> Pdu = make_pdu(get_next, Oids, MiniMIB), - Mod:send_pdu(NetIf, Pdu, Vsn, MsgData, Addr, Port, ExtraInfo), + Mod:send_pdu(NetIf, Pdu, Vsn, MsgData, Domain, Addr, Port, ExtraInfo), Pdu#pdu.request_id. -send_get_bulk_request(Oids, Vsn, MsgData, Addr, Port, +send_get_bulk_request(Oids, Vsn, MsgData, Domain, Addr, Port, NonRep, MaxRep, ExtraInfo, #state{mini_mib = MiniMIB, net_if = NetIf, net_if_mod = Mod}) -> Pdu = make_pdu(bulk, {NonRep, MaxRep, Oids}, MiniMIB), - Mod:send_pdu(NetIf, Pdu, Vsn, MsgData, Addr, Port, ExtraInfo), + Mod:send_pdu(NetIf, Pdu, Vsn, MsgData, Domain, Addr, Port, ExtraInfo), Pdu#pdu.request_id. -send_set_request(VarsAndVals, Vsn, MsgData, Addr, Port, ExtraInfo, +send_set_request(VarsAndVals, Vsn, MsgData, Domain, Addr, Port, ExtraInfo, #state{mini_mib = MiniMIB, net_if = NetIf, net_if_mod = Mod}) -> Pdu = make_pdu(set, VarsAndVals, MiniMIB), - Mod:send_pdu(NetIf, Pdu, Vsn, MsgData, Addr, Port, ExtraInfo), + Mod:send_pdu(NetIf, Pdu, Vsn, MsgData, Domain, Addr, Port, ExtraInfo), Pdu#pdu.request_id. %% send_discovery(Vsn, MsgData, Addr, Port, ExtraInfo, @@ -2787,12 +3162,7 @@ request_id() -> %%---------------------------------------------------------------------- -agent_data(TargetName, {CtxName, Community}) -> - agent_data(TargetName, CtxName, [{community, Community}]); -agent_data(TargetName, CtxName) -> - agent_data(TargetName, CtxName, []). - -agent_data(TargetName, CtxName, Config) -> +agent_data(TargetName, SendOpts) -> case snmpm_config:agent_info(TargetName, all) of {ok, Info} -> Version = agent_data_item(version, Info), @@ -2804,15 +3174,18 @@ agent_data(TargetName, CtxName, Config) -> DefSecLevel = agent_data_item(sec_level, Info), EngineId = agent_data_item(engine_id, Info), + CtxName = agent_data_item(context, + SendOpts, + ?DEFAULT_CONTEXT), SecModel = agent_data_item(sec_model, - Config, + SendOpts, DefSecModel), SecName = agent_data_item(sec_name, - Config, + SendOpts, DefSecName), SecLevel = agent_data_item(sec_level, - Config, + SendOpts, DefSecLevel), {SecModel, SecName, mk_sec_level_flag(SecLevel), @@ -2822,18 +3195,19 @@ agent_data(TargetName, CtxName, Config) -> DefSecModel = agent_data_item(sec_model, Info), Comm = agent_data_item(community, - Config, + SendOpts, DefComm), SecModel = agent_data_item(sec_model, - Config, + SendOpts, DefSecModel), {Comm, SecModel} end, + Domain = agent_data_item(tdomain, Info), Addr = agent_data_item(address, Info), Port = agent_data_item(port, Info), RegType = agent_data_item(reg_type, Info), - {ok, RegType, Addr, Port, version(Version), MsgData}; + {ok, RegType, Domain, Addr, Port, version(Version), MsgData}; Error -> Error end. @@ -2994,6 +3368,12 @@ default_agent_config() -> %%---------------------------------------------------------------------- +get_opt(Key, Default, Opts) -> + proplists:get_value(Key, Opts, Default). + + +%%---------------------------------------------------------------------- + is_started(#state{net_if = _Pid, net_if_mod = _Mod}) -> %% Mod:is_started(Pid) and snmpm_config:is_started(). case snmpm_config:is_started() of diff --git a/lib/snmp/src/manager/snmpm_usm.erl b/lib/snmp/src/manager/snmpm_usm.erl index 8cb3062d4b..497d6d6102 100644 --- a/lib/snmp/src/manager/snmpm_usm.erl +++ b/lib/snmp/src/manager/snmpm_usm.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 2004-2009. All Rights Reserved. +%% Copyright Ericsson AB 2004-2011. 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 @@ -23,6 +23,10 @@ -module(snmpm_usm). +%% Avoid warning for local function error/1 clashing with autoimported BIF. +-compile({no_auto_import,[error/1]}). +%% Avoid warning for local function error/2 clashing with autoimported BIF. +-compile({no_auto_import,[error/2]}). -export([init/0, reset/0, process_incoming_msg/4, generate_outgoing_msg/5]). @@ -472,14 +476,19 @@ set_engine_latest_time(SnmpEngineID, EngineTime) -> %%----------------------------------------------------------------- %% Utility functions %%----------------------------------------------------------------- +-spec error(term()) -> no_return(). error(Reason) -> throw({error, Reason}). +-spec error(term(), term()) -> no_return(). error(Reason, ErrorInfo) -> throw({error, Reason, ErrorInfo}). +-spec error(term(), term(), term()) -> no_return(). error(Variable, Oid, SecName) -> error(Variable, Oid, SecName, []). + +-spec error(term(), term(), term(), [term()]) -> no_return(). error(Variable, Oid, SecName, Opts) -> Val = inc(Variable), ErrorInfo = {#varbind{oid = Oid, |