diff options
-rw-r--r-- | lib/snmp/src/agent/snmp_target_mib.erl | 15 | ||||
-rw-r--r-- | lib/snmp/src/manager/snmpm_config.erl | 19 | ||||
-rw-r--r-- | lib/snmp/src/misc/snmp_conf.erl | 16 | ||||
-rw-r--r-- | lib/snmp/src/misc/snmp_config.erl | 4 | ||||
-rw-r--r-- | lib/snmp/test/snmp_agent_test_lib.erl | 7 | ||||
-rw-r--r-- | lib/snmp/test/snmp_conf_test.erl | 6 | ||||
-rw-r--r-- | lib/snmp/test/snmp_manager_config_test.erl | 18 | ||||
-rw-r--r-- | lib/snmp/test/snmp_manager_test.erl | 2 |
8 files changed, 50 insertions, 37 deletions
diff --git a/lib/snmp/src/agent/snmp_target_mib.erl b/lib/snmp/src/agent/snmp_target_mib.erl index cff1e253c3..3bcfd469e6 100644 --- a/lib/snmp/src/agent/snmp_target_mib.erl +++ b/lib/snmp/src/agent/snmp_target_mib.erl @@ -263,7 +263,7 @@ check_target_addr( TagList, Params, EngineId, Mask, MMS]), snmp_conf:check_string(Name,{gt,0}), snmp_conf:check_domain(Domain), - NAddress = snmp_conf:check_address(Domain, Address), + NAddress = check_address(Domain, Address), snmp_conf:check_integer(Timeout, {gte, 0}), snmp_conf:check_integer(RetryCount, {gte,0}), snmp_conf:check_string(TagList), @@ -290,19 +290,20 @@ check_address(Domain, Address) -> case snmp_conf:check_address(Domain, Address) of ok -> Address; - {ok, FixedAddress} -> - FixedAddress + {ok, NAddress} -> + NAddress end. -check_mask(_Domain, []) -> - []; +check_mask(_Domain, [] = Mask) -> + Mask; check_mask(Domain, Mask) -> try check_address(Domain, Mask) catch - {error, {invalid_address, Info}} -> - error({invalid_mask, Info}) + {error, {bad_address, Info}} -> + error({bad_mask, Info}) end. + %%----------------------------------------------------------------- %% TargetParams %% {Name, MPModel, SecurityModel, SecurityName, SecurityLevel} diff --git a/lib/snmp/src/manager/snmpm_config.erl b/lib/snmp/src/manager/snmpm_config.erl index af2262d988..ea962575d5 100644 --- a/lib/snmp/src/manager/snmpm_config.erl +++ b/lib/snmp/src/manager/snmpm_config.erl @@ -1702,7 +1702,10 @@ verify_agent(Conf) -> verify_agent(lists:sort(fun order_agent/2, Conf), []). verify_agent([], VerifiedConf) -> - list:reverse(VerifiedConf); + Ret = lists:reverse(VerifiedConf), + ?vdebug("verify_agent -> returns:~n" + " ~p", [Ret]), + Ret; verify_agent([{_Item, _} = Entry|Conf], VerifiedConf) -> %% verify_invalid(VerifiedConf, [_Item]), % Check for duplicate verify_agent(Conf, VerifiedConf, Entry); @@ -1744,11 +1747,11 @@ verify_agent(Conf, VerifiedConf, {address = Item, Address} = Entry) -> {ok, {NAddress,FakePort}} -> verify_agent(Conf, [{Item, NAddress}|VC]); {ok, _} -> - error({invalid_address, {TDomain, Address}}) + error({bad_address, {TDomain, Address}}) end; verify_agent(Conf, VerifiedConf, {port, Port} = Entry) -> verify_invalid(VerifiedConf, [taddress]), - ok = snmp_conf:check_address(snmpUDPDomain, {{0, 0, 0, 0}, Port}), + _ = snmp_conf:check_address(snmpUDPDomain, {{0, 0, 0, 0}, Port}), verify_agent(Conf, [Entry|VerifiedConf]); verify_agent(Conf, VerifiedConf, {Item, Val} = Entry) -> case verify_agent_entry(Item, Val) of @@ -1846,7 +1849,7 @@ check_user_config({Id, Mod, Data, DefaultAgentConfig} = _User) end; check_user_config({Id, _Mod, _Data, DefaultAgentConfig}) when (Id =/= ?DEFAULT_USER) -> - {error, {bad_default_agent_config, DefaultAgentConfig}}; + error({bad_default_agent_config, DefaultAgentConfig}); check_user_config({Id, _Mod, _Data, _DefaultAgentConfig}) -> error({bad_user_id, Id}); check_user_config(User) -> @@ -2146,7 +2149,7 @@ check_manager_config({engine_id, EngineID}) -> check_manager_config({max_message_size, Max}) -> snmp_conf:check_integer(Max, {gte, 484}); check_manager_config(Conf) -> - {error, {unknown_config, Conf}}. + error({unknown_config, Conf}). check_mandatory_manager_config(Conf) -> @@ -2709,7 +2712,7 @@ handle_register_agent(UserId, TargetName, Config) -> %% dirty crossref stuff ?vtrace("handle_register_agent -> lookup address", []), {ok, Addr} = agent_info(TargetName, address), - ?vtrace("handle_register_agent -> Addr: ~p, lookup Port", + ?vtrace("handle_register_agent -> Addr: ~p, lookup Port", [Addr]), {ok, Port} = agent_info(TargetName, port), ?vtrace("handle_register_agent -> register cross-ref fix", []), @@ -2737,7 +2740,7 @@ 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" + ?vtrace("do_handle_register_agent -> entry with" "~n TargetName: ~p" "~n Item: ~p" "~n Val: ~p" @@ -2746,7 +2749,7 @@ do_handle_register_agent(TargetName, [{Item, Val}|Rest]) -> ok -> do_handle_register_agent(TargetName, Rest); {error, Reason} -> - ?vtrace("handle_register_agent -> failed updating ~p" + ?vtrace("do_handle_register_agent -> failed updating ~p" "~n Item: ~p" "~n Reason: ~p", [Item, Reason]), ets:match_delete(snmpm_agent_table, {TargetName, '_'}), diff --git a/lib/snmp/src/misc/snmp_conf.erl b/lib/snmp/src/misc/snmp_conf.erl index f85f1d3828..3fefe3e8cd 100644 --- a/lib/snmp/src/misc/snmp_conf.erl +++ b/lib/snmp/src/misc/snmp_conf.erl @@ -596,6 +596,8 @@ mk_taddress(?transportDomainUdpIpv6, Address) -> %% mk_taddress(transportDomainUdpIpv4 = Domain, Address) -> case Address of + [] -> % Empty mask + []; {Ip, Port} when tuple_size(Ip) =:= 4, is_integer(Port) -> tuple_to_list(Ip) ++ mk_bytes(Port); _ -> @@ -603,6 +605,8 @@ mk_taddress(transportDomainUdpIpv4 = Domain, Address) -> end; mk_taddress(transportDomainUdpIpv6 = Domain, Address) -> case Address of + [] -> % Empty mask + []; {Ip, Port} when tuple_size(Ip) =:= 8, is_integer(Port) -> tuple_to_list(Ip) ++ mk_bytes(Port); @@ -710,14 +714,14 @@ check_ip(X) -> check_ip(snmpUDPDomain, X) -> check_ip(transportDomainUdpIpv4, X); -check_ip(transportDomainUdpIpv4, X) -> +check_ip(transportDomainUdpIpv4 = Domain, X) -> case X of [A,B,C,D] when ?is_ipv4_addr(A, B, C, D) -> ok; _ -> - error({invalid_ip_address, X}) + error({bad_address, {Domain, X}}) end; -check_ip(transportDomainUdpIpv6, X) -> +check_ip(transportDomainUdpIpv6 = Domain, X) -> case X of [A,B,C,D,E,F,G,H] when ?is_ipv6_addr(A, B, C, D, E, F, G, H) -> @@ -727,7 +731,7 @@ check_ip(transportDomainUdpIpv6, X) -> A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P) -> ok; _ -> - error({invalid_ip_address, X}) + error({bad_address, {Domain, X}}) end; %% check_ip(BadDomain, _X) -> @@ -744,7 +748,7 @@ check_address(Domain, Address, DefaultPort) -> false -> case check_address_ip_port(Domain, Address) of false -> - error({invalid_address, {Domain, Address}}); + error({bad_address, {Domain, Address}}); true -> {ok, Address}; FixedAddress -> @@ -759,7 +763,7 @@ check_address(Domain, Address, DefaultPort) -> check_address(Domain, Address) -> case check_address_ip_port(Domain, Address) of false -> - error({invalid_address, {Domain, Address}}); + error({bad_address, {Domain, Address}}); true -> {ok, Address}; FixedAddress -> diff --git a/lib/snmp/src/misc/snmp_config.erl b/lib/snmp/src/misc/snmp_config.erl index ec6b2ac7e4..12467a1abf 100644 --- a/lib/snmp/src/misc/snmp_config.erl +++ b/lib/snmp/src/misc/snmp_config.erl @@ -2446,7 +2446,9 @@ write_config_file(Dir, FileName, Verify, Write) throw:Error -> Error; T:E -> - {error, {failed_write, Dir, FileName, T, E}} + {error, + {failed_write, Dir, FileName, + {T, E, erlang:get_stacktrace()}}} end. diff --git a/lib/snmp/test/snmp_agent_test_lib.erl b/lib/snmp/test/snmp_agent_test_lib.erl index bfedd7558c..050ae0126d 100644 --- a/lib/snmp/test/snmp_agent_test_lib.erl +++ b/lib/snmp/test/snmp_agent_test_lib.erl @@ -1536,8 +1536,11 @@ rewrite_target_addr_conf(Dir, NewPort) -> end, ?line [TrapAddr|Addrs] = - snmp_conf:read(TAFile, - fun(R) -> rewrite_target_addr_conf_check(R) end), + snmp_conf:read( + TAFile, + fun(R, S) -> + {rewrite_target_addr_conf_check(R),S} + end), ?DBG("rewrite_target_addr_conf -> TrapAddr: ~p",[TrapAddr]), diff --git a/lib/snmp/test/snmp_conf_test.erl b/lib/snmp/test/snmp_conf_test.erl index c4341d8d7e..5c8acb48a5 100644 --- a/lib/snmp/test/snmp_conf_test.erl +++ b/lib/snmp/test/snmp_conf_test.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 2003-2010. All Rights Reserved. +%% Copyright Ericsson AB 2003-2014. 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 @@ -401,7 +401,7 @@ check_taddress(Config) when is_list(Config) -> ok. verify_taddress(Val) -> - case (catch snmp_conf:check_taddress(Val)) of + case (catch snmp_conf:check_taddress(snmpUDPDomain, Val)) of {error, Reason} -> ?FAIL({verify_taddress, Val, Reason}); ok -> @@ -409,7 +409,7 @@ verify_taddress(Val) -> end. verify_not_taddress(Val) -> - case (catch snmp_conf:check_taddress(Val)) of + case (catch snmp_conf:check_taddress(snmpUDPDomain, Val)) of ok -> ?FAIL({verify_taddress, Val}); {error, _Reason} -> diff --git a/lib/snmp/test/snmp_manager_config_test.erl b/lib/snmp/test/snmp_manager_config_test.erl index 7b9924b83c..3cdb2cfcbe 100644 --- a/lib/snmp/test/snmp_manager_config_test.erl +++ b/lib/snmp/test/snmp_manager_config_test.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 2004-2013. All Rights Reserved. +%% Copyright Ericsson AB 2004-2014. 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 @@ -693,7 +693,7 @@ start_with_invalid_manager_conf_file1(Conf) when is_list(Conf) -> "arne_anka", "4001", "500", "\"bmkEngine\""), ?line {error, Reason12} = config_start(Opts), p("start failed (as expected): ~p", [Reason12]), - ?line {failed_check, _, _, 2, {invalid_ip_address, _}} = Reason12, + ?line {failed_check, _, _, 2, {bad_address, _}} = Reason12, await_config_not_running(), %% -- @@ -702,7 +702,7 @@ start_with_invalid_manager_conf_file1(Conf) when is_list(Conf) -> "9999", "4001", "500", "\"bmkEngine\""), ?line {error, Reason13} = config_start(Opts), p("start failed (as expected): ~p", [Reason13]), - ?line {failed_check, _, _, 2, {invalid_ip_address, _}} = Reason13, + ?line {failed_check, _, _, 2, {bad_address, _}} = Reason13, await_config_not_running(), %% -- @@ -1073,7 +1073,7 @@ start_with_invalid_agents_conf_file1(Conf) when is_list(Conf) -> case config_start(Opts) of {error, Reason53} -> p("start failed (as expected): ~p", [Reason53]), - ?line {failed_check, _, _, _, {invalid_ip_address, _}} = Reason53, + ?line {failed_check, _, _, _, {bad_address, _}} = Reason53, await_config_not_running(); OK_53 -> exit({error, {unexpected_success, "53", OK_53}}) @@ -1086,7 +1086,7 @@ start_with_invalid_agents_conf_file1(Conf) when is_list(Conf) -> case config_start(Opts) of {error, Reason54} -> p("start failed (as expected): ~p", [Reason54]), - ?line {failed_check, _, _, _, {invalid_ip_address, _}} = Reason54, + ?line {failed_check, _, _, _, {bad_address, _}} = Reason54, await_config_not_running(); OK_54 -> exit({error, {unexpected_success, "54", OK_54}}) @@ -1098,7 +1098,7 @@ start_with_invalid_agents_conf_file1(Conf) when is_list(Conf) -> write_agents_conf(ConfDir, [Agent55]), ?line {error, Reason55} = config_start(Opts), p("start failed (as expected): ~p", [Reason55]), - ?line {failed_check, _, _, _, {invalid_ip_address, _}} = Reason55, + ?line {failed_check, _, _, _, {bad_address, _}} = Reason55, await_config_not_running(), %% -- @@ -1107,7 +1107,7 @@ start_with_invalid_agents_conf_file1(Conf) when is_list(Conf) -> write_agents_conf(ConfDir, [Agent61]), ?line {error, Reason61} = config_start(Opts), p("start failed (as expected): ~p", [Reason61]), - ?line {failed_check, _, _, _, {invalid_integer, _}} = Reason61, + ?line {failed_check, _, _, _, {bad_address, _}} = Reason61, await_config_not_running(), %% -- @@ -1116,7 +1116,7 @@ start_with_invalid_agents_conf_file1(Conf) when is_list(Conf) -> write_agents_conf(ConfDir, [Agent62]), ?line {error, Reason62} = config_start(Opts), p("start failed (as expected): ~p", [Reason62]), - ?line {failed_check, _, _, _, {invalid_integer, _}} = Reason62, + ?line {failed_check, _, _, _, {bad_address, _}} = Reason62, await_config_not_running(), %% -- @@ -1125,7 +1125,7 @@ start_with_invalid_agents_conf_file1(Conf) when is_list(Conf) -> write_agents_conf(ConfDir, [Agent63]), ?line {error, Reason63} = config_start(Opts), p("start failed (as expected): ~p", [Reason63]), - ?line {failed_check, _, _, _, {invalid_integer, _}} = Reason63, + ?line {failed_check, _, _, _, {bad_address, _}} = Reason63, await_config_not_running(), %% -- diff --git a/lib/snmp/test/snmp_manager_test.erl b/lib/snmp/test/snmp_manager_test.erl index 3a654a2805..90f9ef2026 100644 --- a/lib/snmp/test/snmp_manager_test.erl +++ b/lib/snmp/test/snmp_manager_test.erl @@ -1508,7 +1508,7 @@ register_agent3(Config) when is_list(Config) -> TargetName2 = "agent3", ?line ok = mgr_register_agent(ManagerNode, user_alfa, TargetName2, [{tdomain, transportDomainUdpIpv6}, - {address, LocalHost}, + {address, {0,0,0,0,0,0,0,1}}, {port, 5002}, {engine_id, "agentEngineId-2"}]), TargetName3 = "agent4", |