diff options
Diffstat (limited to 'lib/snmp/src')
-rw-r--r-- | lib/snmp/src/agent/snmp_target_mib.erl | 31 | ||||
-rw-r--r-- | lib/snmp/src/agent/snmpa_net_if.erl | 34 | ||||
-rw-r--r-- | lib/snmp/src/misc/snmp_conf.erl | 199 | ||||
-rw-r--r-- | lib/snmp/src/misc/snmp_config.erl | 23 | ||||
-rw-r--r-- | lib/snmp/src/misc/snmp_log.erl | 9 |
5 files changed, 150 insertions, 146 deletions
diff --git a/lib/snmp/src/agent/snmp_target_mib.erl b/lib/snmp/src/agent/snmp_target_mib.erl index 3bcfd469e6..932829e150 100644 --- a/lib/snmp/src/agent/snmp_target_mib.erl +++ b/lib/snmp/src/agent/snmp_target_mib.erl @@ -679,6 +679,20 @@ snmpTargetAddrTable(print) -> FOI = foi(Table), PrintRow = fun(Prefix, Row) -> + TDomain = element(?snmpTargetAddrTDomain, Row), + Domain = + try snmp_conf:tdomain_to_domain(TDomain) + catch + {error, {bad_tdomain, _}} -> + undefined + end, + TAddress = element(?snmpTargetAddrTAddress, Row), + AddrString = + try snmp_conf:mk_addr_string({Domain, TAddress}) + catch + {error, {bad_address, _}} -> + "-" + end, lists:flatten( io_lib:format("~sName: ~p" "~n~sTDomain: ~p (~w)" @@ -693,21 +707,8 @@ snmpTargetAddrTable(print) -> "~n~s[Ext] TMask: ~p" "~n~s[Ext] MMS: ~p", [Prefix, element(?snmpTargetAddrName, Row), - Prefix, element(?snmpTargetAddrTDomain, Row), - case element(?snmpTargetAddrTDomain, Row) of - ?snmpUDPDomain -> snmpUDPDomain; - ?transportDomainUdpIpv4 -> transportDomainUdpIpv4; - ?transportDomainUdpIpv6 -> transportDomainUdpIpv6; - _ -> undefined - end, - Prefix, element(?snmpTargetAddrTAddress, Row), - case element(?snmpTargetAddrTAddress, Row) of - [A,B,C,D,U1,U2] -> - lists:flatten( - io_lib:format("~w.~w.~w.~w:~w", - [A, B, C, D, U1 bsl 8 + U2])); - _ -> "-" - end, + Prefix, TDomain, Domain, + Prefix, TAddress, AddrString, Prefix, element(?snmpTargetAddrTimeout, Row), Prefix, element(?snmpTargetAddrRetryCount, Row), Prefix, element(?snmpTargetAddrTagList, Row), diff --git a/lib/snmp/src/agent/snmpa_net_if.erl b/lib/snmp/src/agent/snmpa_net_if.erl index 2c800db8b6..71bb9cad2e 100644 --- a/lib/snmp/src/agent/snmpa_net_if.erl +++ b/lib/snmp/src/agent/snmpa_net_if.erl @@ -142,9 +142,16 @@ init(Prio, NoteStore, MasterAgent, Parent, Opts) -> try loop(State) catch C:E -> S = erlang:get_stacktrace(), - error_msg( - "loop/1 EXCEPTION ~w:~w~n" - " ~p", [C,E,S]), + Fmt = + "loop/1 EXCEPTION ~w:~w~n" + " ~p", + case C of + exit -> + %% Externally killed, root cause is elsewhere + info_msg(Fmt, [C, E, S]); + _ -> + error_msg(Fmt, [C, E, S]) + end, erlang:raise(C, E, S) end; {error, Reason} -> @@ -287,20 +294,9 @@ log({Log, Types}, _, Packet, Address) -> false -> ok end. -%% log(_, _, _, _, _) -> -%% ok. - -format_address({snmpUDPDomain, {_Ip, Port} = Addr}) when is_integer(Port) -> - format_address(Addr); -format_address({transportDomainUdpIpv4, {Ip, Port}}) -> - format_address("udpIpv4/~s:~w", [inet:ntoa(Ip), Port]); -format_address({transportDomainUdpIpv6, {Ip, Port}}) -> - format_address("udpIpv6/[~s]:~w", [inet:ntoa(Ip), Port]); -format_address({Ip, Port}) when is_integer(Port) -> - format_address("~s:~w", [inet:ntoa(Ip), Port]). -format_address(Format, Args) -> - iolist_to_binary(io_lib:format(Format, Args)). +format_address(Address) -> + iolist_to_binary(snmp_conf:mk_addr_string(Address)). @@ -712,7 +708,6 @@ maybe_handle_reply_pdu( Type, ACMData, To) -> S1 = update_req_counter_outgoing(S, Rid), - %% Addresses = [To], Addresses = [fix_filter_address(Domain, To)], case try @@ -962,7 +957,6 @@ handle_response(Vsn, Pdu, From, S) -> maybe_udp_send( #state{usock = Sock, filter = FilterMod, domain = Domain}, To, Packet) -> - %% {To_1, To_2} = To, {To_1, To_2} = fix_filter_address(Domain, To), case try FilterMod:accept_send(To_1, To_2) @@ -997,7 +991,6 @@ maybe_udp_send( filter = FilterMod, domain = Domain}, To, Packet, Type, _LogData) -> - %% {To_1, To_2} = To, {To_1, To_2} = fix_filter_address(Domain, To), case try FilterMod:accept_send(To_1, To_2) @@ -1358,6 +1351,9 @@ get_bind_to_ip_address(Opts) -> error_msg(F,A) -> ?snmpa_error("NET-IF server: " ++ F, A). +info_msg(F,A) -> + ?snmpa_info("NET-IF server: " ++ F, A). + %% --- user_err(F, A) -> diff --git a/lib/snmp/src/misc/snmp_conf.erl b/lib/snmp/src/misc/snmp_conf.erl index 2d91cb1f55..eb71c55cf4 100644 --- a/lib/snmp/src/misc/snmp_conf.erl +++ b/lib/snmp/src/misc/snmp_conf.erl @@ -40,11 +40,13 @@ all_domains/0, check_domain/1, + domain_to_name/1, all_tdomains/0, check_tdomain/1, mk_tdomain/0, mk_tdomain/1, - tdomain_to_family/1, + tdomain_to_family/1, tdomain_to_domain/1, which_domain/1, + mk_addr_string/1, check_ip/1, check_ip/2, check_port/1, ip_port_to_domaddr/2, @@ -495,9 +497,17 @@ tdomain_to_family(BadDomain) -> %% --------- -%% XXX remove -%% check_taddress(X) -> -%% check_taddress(snmpUDPDomain, X). +tdomain_to_domain(?snmpUDPDomain) -> + snmpUDPDomain; +tdomain_to_domain(?transportDomainUdpIpv4) -> + transportDomainUdpIpv4; +tdomain_to_domain(?transportDomainUdpIpv6) -> + transportDomainUdpIpv6; +tdomain_to_domain(BadTDomain) -> + error({bad_tdomain, BadTDomain}). + + +%% --------- check_taddress(?snmpUDPDomain, X) -> check_taddress(transportDomainUdpIpv4, X); @@ -600,6 +610,42 @@ check_domain(Domain) -> error({unknown_domain, Domain}) end. +domain_to_name(snmpUDPDomain) -> + undefined; +domain_to_name(transportDomainUdpIpv4) -> + udpIpv4; +domain_to_name(transportDomainUdpIpv6) -> + udpIpv6; +domain_to_name(transportDomainUdpIpv4z) -> + udpIpv4z; +domain_to_name(transportDomainUdpIpv6z) -> + udpIpv6z; +domain_to_name(transportDomainTcpIpv4) -> + tcpIpv4; +domain_to_name(transportDomainTcpIpv6) -> + tcpIpv6; +domain_to_name(transportDomainTcpIpv4z) -> + tcpIpv4z; +domain_to_name(transportDomainTcpIpv6z) -> + tcpIpv6z; +domain_to_name(transportDomainSctpIpv4) -> + sctpIpv4; +domain_to_name(transportDomainSctpIpv6) -> + sctpIpv6; +domain_to_name(transportDomainSctpIpv4z) -> + sctpIpv4z; +domain_to_name(transportDomainSctpIpv6z) -> + sctpIpv6z; +domain_to_name(transportDomainLocal) -> + local; +domain_to_name(transportDomainUdpDns) -> + udpDns; +domain_to_name(transportDomainTcpDns) -> + tcpDns; +domain_to_name(transportDomainSctpDns) -> + sctpDns; +domain_to_name(BadDomain) -> + error({bad_domain, BadDomain}). %% --------- @@ -652,77 +698,6 @@ mk_taddress(BadDomain, _) -> error({bad_domain, BadDomain}). - -%% mk_taddress(snmpUDPDomain, Address) -> -%% mk_taddress(transportDomainUdpIpv4, Address); -%% %% mk_taddress(transportDomainUdpIpv4, {Ip, Port}) when is_list(Ip) -> -%% %% Ip ++ mk_bytes(Port); -%% mk_taddress(transportDomainUdpIpv4, {Ip, Port}) -%% when tuple_size(Ip) =:= 4 -> -%% tuple_to_list(Ip) ++ mk_bytes(Port); -%% %% mk_taddress(transportDomainUdpIpv4, IpPort) when is_list(IpPort) -> -%% %% IpPort; % Should be length 6 -%% %% mk_taddress(transportDomainUdpIpv6, {Ip, Port}) when is_list(Ip) -> -%% %% Ip ++ mk_bytes(Port); -%% mk_taddress(transportDomainUdpIpv6, {Ip, Port}) -%% when tuple_size(Ip) == 8 -> -%% tuple_to_list(Ip) ++ mk_bytes(Port); -%% %% mk_taddress(transportDomainUdpIpv6, IpPort) when is_list(IpPort) -> -%% %% case IpPort of -%% %% [A0,A1,A2,A3,A4,A5,A6,A7,P] -> -%% %% [A0,A1,A2,A3,A4,A5,A6,A7] ++ mk_bytes(P); -%% %% [A0,A1,A2,A3,A4,A5,A6,A7,A8,A9,A10,A11,A12,A13,A14,A15,P0,P1] -> -%% %% [mk_word(A0, A1),mk_word(A2, A3), -%% %% mk_word(A4, A5),mk_word(A6, A7), -%% %% mk_word(A8, A9),mk_word(A10, A11), -%% %% mk_word(A12, A13),mk_word(A14, A15),P0,P1]; -%% %% _ -> -%% %% IpPort % Should already be 8 words and 2 bytes hence length 10 -%% %% end; -%% mk_taddress(Domain, []) -> %% Used for empty mask -%% []; -%% mk_taddress(Domain, Address) -> -%% erlang:error(badarg, [Domain,Address]); -%% %% -%% %% These are just for convenience -%% mk_taddress(?snmpUDPDomain, Address) -> -%% mk_taddress(snmpUDPDomain, Address); -%% mk_taddress(?transportDomainUdpIpv4, Address) -> -%% mk_taddress(transportDomainUdpIpv4, Address); -%% mk_taddress(?transportDomainUdpIpv6, Address) -> -%% mk_taddress(transportDomainUdpIpv6, Address); -%% %% Bad domain -%% mk_taddress(BadDomain, _) -> -%% error({bad_domain, BadDomain}). - - - -%% %% XXX remove - -%% mk_taddress(snmpUDPDomain, Ip, Port) -> -%% mk_taddress(transportDomainUdpIpv4, Ip, Port); -%% mk_taddress(transportDomainUdpIpv4, Ip, Port) when is_list(Ip) -> -%% Ip ++ [Port div 256, Port rem 256]; -%% mk_taddress(transportDomainUdpIpv4 = Domain, Ip, Port) when is_tuple(Ip) -> -%% mk_taddress(Domain, tuple_to_list(Ip), Port); -%% mk_taddress(transportDomainUdpIpv6, Ip, Port) when is_list(Ip) -> -%% Ip ++ [Port div 256, Port rem 256]; -%% mk_taddress(transportDomainUdpIpv6 = Domain, Ip, Port) when is_tuple(Ip) -> -%% mk_taddress(Domain, tuple_to_list(Ip), Port); -%% %% -%% %% These are just for convenience -%% mk_taddress(?snmpUDPDomain, Ip, Port) -> -%% mk_taddress(snmpUDPDomain, Ip, Port); -%% mk_taddress(?transportDomainUdpIpv4, Ip, Port) -> -%% mk_taddress(transportDomainUdpIpv4, Ip, Port); -%% mk_taddress(?transportDomainUdpIpv6, Ip, Port) -> -%% mk_taddress(transportDomainUdpIpv6, Ip, Port); -%% %% -%% %% Bad domain -%% mk_taddress(BadDomain, _Ip, _Port) -> -%% error({bad_domain, BadDomain}). - - %% --------- %% XXX remove, when net_if handles one socket per transport domain @@ -747,10 +722,54 @@ which_domain({A0, A1, A2, A3, A4, A5, A6, A7}) %% --------- +mk_addr_string({_IP, Port} = Addr) when is_integer(Port) -> + mk_addr_string({snmpUDPDomain, Addr}); +mk_addr_string({Domain, Addr}) when is_atom(Domain) -> + %% XXX There is only code for IP domains here + case check_address_ip(Domain, Addr) of + false -> + case check_address_ip_port(Domain, Addr) of + false -> + error({bad_address, {Domain, Addr}}); + true -> + {IP, Port} = Addr, + mk_addr_string_ntoa(Domain, IP, Port); + {IP, Port} -> + mk_addr_string_ntoa(Domain, IP, Port) + end; + true -> + mk_addr_string_ntoa(Domain, Addr); + IP -> + mk_addr_string_ntoa(Domain, IP) + end. + + +mk_addr_string_ntoa({_, _, _, _} = IP) -> + inet:ntoa(IP); +mk_addr_string_ntoa(IP) -> + lists:flatten(io_lib:format("[~s]", [inet:ntoa(IP)])). + +mk_addr_string_ntoa(Domain, IP) -> + case domain_to_name(Domain) of + undefined -> + mk_addr_string_ntoa(IP); + Name -> + lists:flatten( + io_lib:format("~w://~s", [Name, mk_addr_string_ntoa(IP)])) + end. + +mk_addr_string_ntoa(Domain, IP, Port) -> + lists:flatten( + io_lib:format( + "~s:~w", [mk_addr_string_ntoa(Domain, IP), Port])). + +%% --------- + check_ip(X) -> check_ip(snmpUDPDomain, X). check_ip(Domain, IP) -> + %% XXX There is only code for IP domains here case check_address_ip(Domain, IP) of false -> error({bad_address, {Domain, IP}}); @@ -760,31 +779,6 @@ check_ip(Domain, IP) -> {ok, FixedIP} end. -%% check_ip(snmpUDPDomain, 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({bad_address, {Domain, X}}) -%% end; -%% 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) -> -%% ok; -%% [A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P] -%% when ?is_ipv6_addr( -%% A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P) -> -%% ok; -%% _ -> -%% error({bad_address, {Domain, X}}) -%% end; -%% %% -%% check_ip(BadDomain, _X) -> -%% error({invalid_domain, BadDomain}). - %% --------- @@ -794,6 +788,7 @@ check_port(Port) -> error({bad_port, Port}). ip_port_to_domaddr(IP, Port) when ?is_word(Port) -> + %% XXX There is only code for IP domains here case check_address_ip(transportDomainUdpIpv4, IP) of false -> case check_address_ip(transportDomainUdpIpv6, IP) of @@ -818,6 +813,8 @@ ip_port_to_domaddr(IP, Port) -> check_address(Domain, Address, DefaultPort) -> %% If Address does not contain Port or contains Port =:= 0 %% create an address containing DefaultPort + %% + %% XXX There is only code for IP domains here case check_address_ip(Domain, Address) of false -> case check_address_ip_port(Domain, Address) of @@ -843,6 +840,8 @@ check_address(Domain, Address, DefaultPort) -> check_address(Domain, Address) -> %% Address has to contain Port + %% + %% XXX There is only code for IP domains here case check_address_ip_port(Domain, Address) of false -> error({bad_address, {Domain, Address}}); diff --git a/lib/snmp/src/misc/snmp_config.erl b/lib/snmp/src/misc/snmp_config.erl index 6d0f14237e..ac2b7b7778 100644 --- a/lib/snmp/src/misc/snmp_config.erl +++ b/lib/snmp/src/misc/snmp_config.erl @@ -1825,18 +1825,23 @@ write_agent_snmp_target_addr_conf( "%%\n\n", Hdr = header() ++ Comment, F = fun(v1 = Vsn, Acc) -> - [{mk_name(Addr, Vsn), Domain, Addr, Timeout, RetryCount, + [{mk_name(Domain, Addr, Vsn), + Domain, Addr, Timeout, RetryCount, "std_trap", mk_param(Vsn), "", [], 2048}| Acc]; (v2 = Vsn, Acc) -> - [{mk_name(Addr, Vsn), Domain, Addr, Timeout, RetryCount, + [{mk_name(Domain, Addr, Vsn), + Domain, Addr, Timeout, RetryCount, "std_trap", mk_param(Vsn), "", [], 2048}, - {lists:flatten(io_lib:format("~s.2",[mk_name(Addr, Vsn)])), + {lists:flatten( + io_lib:format("~s.2",[mk_name(Domain, Addr, Vsn)])), Domain, Addr, Timeout, RetryCount, "std_inform", mk_param(Vsn), "", [], 2048}| Acc]; (v3 = Vsn, Acc) -> - [{mk_name(Addr, Vsn), Domain, Addr, Timeout, RetryCount, + [{mk_name(Domain, Addr, Vsn), + Domain, Addr, Timeout, RetryCount, "std_trap", mk_param(Vsn), "", [], 2048}, - {lists:flatten(io_lib:format("~s.3",[mk_name(Addr, Vsn)])), + {lists:flatten( + io_lib:format("~s.3",[mk_name(Domain, Addr, Vsn)])), Domain, Addr, Timeout, RetryCount, "std_inform", mk_param(Vsn), "mgrEngine", [], 2048}| Acc] end, @@ -1852,10 +1857,10 @@ write_agent_snmp_target_addr_conf( mk_param(Vsn) -> lists:flatten(io_lib:format("target_~w", [Vsn])). -mk_name({[A,B,C,D], _}, Vsn) -> - lists:flatten(io_lib:format("~w.~w.~w.~w ~w", [A,B,C,D,Vsn])); -mk_name(Address, Vsn) -> - lists:flatten(io_lib:format("~w ~w", [Address,Vsn])). +mk_name(Domain, Addr, Vsn) -> + lists:flatten( + io_lib:format( + "~s ~w", [snmp_conf:mk_addr_string({Domain, Addr}), Vsn])). write_agent_target_addr_config(Dir, Hdr, Conf) -> snmpa_conf:write_target_addr_config(Dir, Hdr, Conf). diff --git a/lib/snmp/src/misc/snmp_log.erl b/lib/snmp/src/misc/snmp_log.erl index b3596909cd..a1fd392676 100644 --- a/lib/snmp/src/misc/snmp_log.erl +++ b/lib/snmp/src/misc/snmp_log.erl @@ -867,7 +867,8 @@ f(TimeStamp, SeqNo, %% [ip(Addr), Port, HdrStr, TimeStamp, SeqNo, Vsn, Str]). ipPort2Str(Ip, Port) -> - io_lib:format("~s:~w", [ip(Ip), Port]). + snmp_conf:mk_addr_string({Ip, Port}). + %% io_lib:format("~s:~w", [ip(Ip), Port]). %% Convert a timestamp 2-tupple to a printable string %% @@ -968,8 +969,10 @@ get_type(#pdu{type = Type}) -> Type. -ip({A,B,C,D}) -> - io_lib:format("~w.~w.~w.~w", [A,B,C,D]). +ip(Domain, Addr) -> + snmp_conf:mk_addr_string(Domain, Addr). +%% ip({A,B,C,D}) -> +%% io_lib:format("~w.~w.~w.~w", [A,B,C,D]). |