diff options
Diffstat (limited to 'lib/snmp/src/agent')
-rw-r--r-- | lib/snmp/src/agent/snmp_framework_mib.erl | 51 | ||||
-rw-r--r-- | lib/snmp/src/agent/snmpa_conf.erl | 55 | ||||
-rw-r--r-- | lib/snmp/src/agent/snmpa_net_if.erl | 14 |
3 files changed, 72 insertions, 48 deletions
diff --git a/lib/snmp/src/agent/snmp_framework_mib.erl b/lib/snmp/src/agent/snmp_framework_mib.erl index 51f8c46d19..0b439aa5f1 100644 --- a/lib/snmp/src/agent/snmp_framework_mib.erl +++ b/lib/snmp/src/agent/snmp_framework_mib.erl @@ -41,6 +41,7 @@ -compile({no_auto_import,[error/1]}). -export([init/0, configure/1]). -export([intContextTable/1, intContextTable/3, + intAgentTransportDomain/1, intAgentUDPPort/1, intAgentIpAddress/1, snmpEngineID/1, snmpEngineBoots/1, @@ -128,27 +129,20 @@ read_agent(Dir) -> ?vdebug("read agent config file", []), FileName = "agent.conf", File = filename:join(Dir, FileName), - Agent = + Conf0 = try snmp_conf:read(File, fun order_agent/2, fun check_agent/2) catch throw:{error, Reason} -> error({failed_reading_config_file, Dir, FileName, Reason}) end, - sort_agent(Agent). - - -%%----------------------------------------------------------------- -%% Make sure that each mandatory agent attribute is present, and -%% provide default values for the other non-present attributes. -%%----------------------------------------------------------------- -sort_agent(L) -> - Mand = [{intAgentIpAddress, mandatory}, - {intAgentUDPPort, mandatory}, - {snmpEngineMaxMessageSize, mandatory}, - {snmpEngineID, mandatory}], - {ok, L2} = snmp_conf:check_mandatory(L, Mand), - lists:keysort(1, L2). + Mand = + [{intAgentIpAddress, mandatory}, + {intAgentUDPPort, mandatory}, + {snmpEngineMaxMessageSize, mandatory}, + {snmpEngineID, mandatory}], + {ok, Conf} = snmp_conf:check_mandatory(Conf0, Mand), + Conf. %%----------------------------------------------------------------- @@ -198,14 +192,17 @@ check_context(Context) -> %%----------------------------------------------------------------- check_agent({intAgentTransportDomain, D}, Domain) -> {snmp_conf:check_domain(D), D}; -check_agent({intAgentTransportAddress, Address}, Domain) -> - {snmp_conf:check_address(Domain, Address), Domain}; +check_agent({intAgentIpAddress, Value}, D) -> + Domain = + case D of + undefined -> snmp_target_mib:default_domain(); + _ -> D + end, + {snmp_conf:check_ip(Domain, Value), Domain}; check_agent(Entry, Domain) -> {check_agent(Entry), Domain}. -check_agent({intAgentIpAddress, Value}) -> % Obsoleted - snmp_conf:check_ip(Value); -check_agent({intAgentUDPPort, Value}) -> % Obsoleted +check_agent({intAgentUDPPort, Value}) -> snmp_conf:check_integer(Value); %% This one is kept for backwards compatibility check_agent({intAgentMaxPacketSize, Value}) -> @@ -218,13 +215,14 @@ check_agent(X) -> error({invalid_agent_attribute, X}). %% Ordering function to sort intAgentTransportDomain first -%% hence before intAgentTransportAddress +%% hence before intAgentIpAddress order_agent({Name, _}, {Name, _}) -> true; %% Less than or equal -order_agent(_, {intAgentTransportDomain, _}) -> +order_agent({_, _}, {intAgentTransportDomain, _}) -> false; %% Greater than -order_agent(_, _) -> - true. %% Less than or equal +order_agent({A, _}, {B, _}) -> + A =< B. + maybe_create_table(Name) -> @@ -398,6 +396,11 @@ intAgentUDPPort(Op) -> intAgentIpAddress(Op) -> snmp_generic:variable_func(Op, db(intAgentIpAddress)). +intAgentTransportDomain(Op) -> + snmp_generic:variable_func(Op, db(intAgentTransportDomain)). + + + snmpEngineID(print) -> VarAndValue = [{snmpEngineID, snmpEngineID(get)}], snmpa_mib_lib:print_variables(VarAndValue); diff --git a/lib/snmp/src/agent/snmpa_conf.erl b/lib/snmp/src/agent/snmpa_conf.erl index f055f89880..b05590a504 100644 --- a/lib/snmp/src/agent/snmpa_conf.erl +++ b/lib/snmp/src/agent/snmpa_conf.erl @@ -154,6 +154,8 @@ write_agent_conf(Fd, [H|T]) -> do_write_agent_conf(Fd, H), write_agent_conf(Fd, T). +do_write_agent_conf(Fd, {intAgentTransportDomain = Tag, Val}) -> + io:format(Fd, "{~w, ~w}.~n", [Tag, Val]); do_write_agent_conf(Fd, {intAgentIpAddress = Tag, Val}) -> io:format(Fd, "{~w, ~w}.~n", [Tag, Val]); do_write_agent_conf(Fd, {intAgentUDPPort = Tag, Val} ) -> @@ -566,29 +568,36 @@ write_target_addr_conf(Fd, Conf) -> lists:foreach(Fun, Conf), ok. -do_write_target_addr_conf(Fd, - {Name, - Ip, Udp, - Timeout, RetryCount, TagList, - ParamsName, EngineId, - TMask, MaxMessageSize}) -> - Domain = snmp_target_mib:default_domain(), - do_write_target_addr_conf(Fd, - {Name, - Domain, Ip, Udp, - Timeout, RetryCount, TagList, - ParamsName, EngineId, - TMask, MaxMessageSize}); -do_write_target_addr_conf(Fd, - {Name, - Domain, Ip, Udp, - Timeout, RetryCount, TagList, - ParamsName, EngineId, - TMask, MaxMessageSize}) -> - io:format(Fd, - "{\"~s\", ~w, ~w, ~w, ~w, ~w, \"~s\", \"~s\", \"~s\", ~w, ~w}.~n", - [Name, Domain, Ip, Udp, Timeout, RetryCount, TagList, - ParamsName, EngineId, TMask, MaxMessageSize]); +do_write_target_addr_conf( + Fd, + {Name, Ip, Udp, Timeout, RetryCount, TagList, + ParamsName, EngineId, TMask, MaxMessageSize}) + when is_integer(Udp) -> + Domain = snmp_target_mib:default_domain(), + Address = {Ip, Udp}, + do_write_target_addr_conf( + Fd, + {Name, Domain, Address, Timeout, RetryCount, TagList, + ParamsName, EngineId, TMask, MaxMessageSize}); +do_write_target_addr_conf( + Fd, + {Name, Domain, Address, Timeout, RetryCount, TagList, + ParamsName, EngineId, TMask, MaxMessageSize}) + when is_atom(Domain) -> + io:format( + Fd, + "{\"~s\", ~w, ~w, ~w, ~w, \"~s\", \"~s\", \"~s\", ~w, ~w}.~n", + [Name, Domain, Address, Timeout, RetryCount, TagList, + ParamsName, EngineId, TMask, MaxMessageSize]); +do_write_target_addr_conf( + Fd, + {Name, Domain, Ip, Udp, Timeout, RetryCount, TagList, + ParamsName, EngineId, TMask, MaxMessageSize}) -> + Address = {Ip, Udp}, + do_write_target_addr_conf( + Fd, + {Name, Domain, Address, Timeout, RetryCount, TagList, + ParamsName, EngineId, TMask, MaxMessageSize}); do_write_target_addr_conf(_Fd, Crap) -> error({bad_target_addr_config, Crap}). diff --git a/lib/snmp/src/agent/snmpa_net_if.erl b/lib/snmp/src/agent/snmpa_net_if.erl index 59d88517c9..96211fc5f4 100644 --- a/lib/snmp/src/agent/snmpa_net_if.erl +++ b/lib/snmp/src/agent/snmpa_net_if.erl @@ -112,6 +112,14 @@ get_address() -> {value, IPAddress} = snmp_framework_mib:intAgentIpAddress(get), IPAddress. +get_domain() -> + case snmp_framework_mib:intAgentTransportDomain(get) of + {value, Domain} -> + Domain; + genErr -> + snmpUDPDomain + end. + filter_reset(Pid) -> Pid ! filter_reset. @@ -155,6 +163,8 @@ do_init(Prio, NoteStore, MasterAgent, Parent, Opts) -> ?vlog("starting",[]), %% -- Port and address -- + Domain = get_domain(), + ?vdebug("domain: ~w",[Domain]), UDPPort = get_port(), ?vdebug("port: ~w",[UDPPort]), IPAddress = get_address(), @@ -181,7 +191,9 @@ do_init(Prio, NoteStore, MasterAgent, Parent, Opts) -> IPOpts2 = ip_opt_no_reuse_address(Opts), IPOpts3 = ip_opt_recbuf(Opts), IPOpts4 = ip_opt_sndbuf(Opts), - IPOpts = [binary | IPOpts1 ++ IPOpts2 ++ IPOpts3 ++ IPOpts4], + IPOpts = + [binary, snmp_conf:tdomain_to_family(Domain) + | IPOpts1 ++ IPOpts2 ++ IPOpts3 ++ IPOpts4], ?vdebug("open socket with options: ~w",[IPOpts]), case gen_udp_open(UDPPort, IPOpts) of {ok, Sock} -> |