diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/snmp/src/manager/snmpm_conf.erl | 13 | ||||
-rw-r--r-- | lib/snmp/src/manager/snmpm_config.erl | 28 | ||||
-rw-r--r-- | lib/snmp/src/manager/snmpm_mpd.erl | 22 | ||||
-rw-r--r-- | lib/snmp/src/manager/snmpm_net_if.erl | 271 | ||||
-rw-r--r-- | lib/snmp/src/manager/snmpm_net_if_filter.erl | 16 | ||||
-rw-r--r-- | lib/snmp/src/manager/snmpm_server.erl | 362 | ||||
-rw-r--r-- | lib/snmp/src/misc/snmp_conf.erl | 2 | ||||
-rw-r--r-- | lib/snmp/src/misc/snmp_config.erl | 17 | ||||
-rw-r--r-- | lib/snmp/test/snmp_manager_test.erl | 105 |
9 files changed, 481 insertions, 355 deletions
diff --git a/lib/snmp/src/manager/snmpm_conf.erl b/lib/snmp/src/manager/snmpm_conf.erl index d2f9ba9c26..ed4cfd749e 100644 --- a/lib/snmp/src/manager/snmpm_conf.erl +++ b/lib/snmp/src/manager/snmpm_conf.erl @@ -110,14 +110,15 @@ write_manager_conf(Fd, [H|T]) -> do_write_manager_conf(Fd, H), write_manager_conf(Fd, T). -do_write_manager_conf(Fd, {address = Tag, Val}) -> +do_write_manager_conf(Fd, {Tag, Val}) + when Tag =:= domain; + Tag =:= address; + Tag =:= port; + Tag =:= max_message_size -> io:format(Fd, "{~w, ~w}.~n", [Tag, Val]); -do_write_manager_conf(Fd, {port = Tag, Val} ) -> - io:format(Fd, "{~w, ~w}.~n", [Tag, Val]); -do_write_manager_conf(Fd, {engine_id = Tag, Val} ) -> +do_write_manager_conf(Fd, {Tag, Val}) + when Tag =:= engine_id -> io:format(Fd, "{~w, \"~s\"}.~n", [Tag, Val]); -do_write_manager_conf(Fd, {max_message_size = Tag, Val} ) -> - io:format(Fd, "{~w, ~w}.~n", [Tag, Val]); do_write_manager_conf(_Fd, Crap) -> error({bad_manager_config, Crap}). diff --git a/lib/snmp/src/manager/snmpm_config.erl b/lib/snmp/src/manager/snmpm_config.erl index b3500d7293..5ebd3a0662 100644 --- a/lib/snmp/src/manager/snmpm_config.erl +++ b/lib/snmp/src/manager/snmpm_config.erl @@ -2297,9 +2297,33 @@ read_manager_config_file(Dir) -> %% If the address is not possible to determine %% that way, then we give up... verify_mandatory(Conf, [port,engine_id,max_message_size]), - ensure_config(default_manager_config(), Conf). - + default_manager_config(Conf). +default_manager_config(Conf) -> + %% Ensure address of right family + case lists:keyfind(address, 1, Conf) of + false -> + Domain = + case lists:keyfind(domain, 1, Conf) of + false -> + default_transport_domain(); + {_, D} -> + D + end, + Family = snmp_conf:tdomain_to_family(Domain), + {ok, HostName} = inet:gethostname(), + case inet:getaddr(HostName, Family) of + {ok, Address} -> + [{address, Address} | Conf]; + {error, _Reason} -> + ?d("default_manager_config -> " + "failed getting ~w address for ~s:~n" + " _Reason: ~p", [Family, HostName, _Reason]), + Conf + end; + _ -> + Conf + end. default_manager_config() -> {ok, HostName} = inet:gethostname(), diff --git a/lib/snmp/src/manager/snmpm_mpd.erl b/lib/snmp/src/manager/snmpm_mpd.erl index 27f0336bc1..521c496adb 100644 --- a/lib/snmp/src/manager/snmpm_mpd.erl +++ b/lib/snmp/src/manager/snmpm_mpd.erl @@ -92,10 +92,10 @@ reset(#state{v3 = V3}) -> %% Purpose: This is the main Message Dispatching function. (see %% section 4.2.1 in rfc2272) %%----------------------------------------------------------------- -process_msg(Msg, Domain, Addr, Port, State, NoteStore, Logger) -> - process_msg(Msg, Domain, {Addr, Port}, State, NoteStore, Logger). +process_msg(Msg, Domain, Ip, Port, State, NoteStore, Logger) -> + process_msg(Msg, Domain, {Ip, Port}, State, NoteStore, Logger). -process_msg(Msg, Domain, Address, State, NoteStore, Logger) -> +process_msg(Msg, Domain, Addr, State, NoteStore, Logger) -> inc(snmpInPkts), case (catch snmp_pdus:dec_message_only(binary_to_list(Msg))) of @@ -105,7 +105,7 @@ process_msg(Msg, Domain, Address, State, NoteStore, Logger) -> when State#state.v1 =:= true -> HS = ?empty_msg_size + length(Community), process_v1_v2c_msg( - 'version-1', NoteStore, Msg, Domain, Address, + 'version-1', NoteStore, Msg, Domain, Addr, Community, Data, HS, Logger); %% Version 2 @@ -113,7 +113,7 @@ process_msg(Msg, Domain, Address, State, NoteStore, Logger) -> when State#state.v2c =:= true -> HS = ?empty_msg_size + length(Community), process_v1_v2c_msg( - 'version-2', NoteStore, Msg, Domain, Address, + 'version-2', NoteStore, Msg, Domain, Addr, Community, Data, HS, Logger); %% Version 3 @@ -124,7 +124,7 @@ process_msg(Msg, Domain, Address, State, NoteStore, Logger) -> "~n msgFlags: ~p" "~n msgSecModel: ~p", [H#v3_hdr.msgID,H#v3_hdr.msgFlags,H#v3_hdr.msgSecurityModel]), - process_v3_msg(NoteStore, Msg, H, Data, Address, Logger); + process_v3_msg(NoteStore, Msg, H, Data, Addr, Logger); %% Crap {'EXIT', {bad_version, Vsn}} -> @@ -151,26 +151,26 @@ process_msg(Msg, Domain, Address, State, NoteStore, Logger) -> %% Handles a Community based message (v1 or v2c). %%----------------------------------------------------------------- process_v1_v2c_msg( - Vsn, _NoteStore, Msg, Domain, Address, Community, Data, HS, Log) -> + Vsn, _NoteStore, Msg, Domain, Addr, Community, Data, HS, Log) -> ?vdebug("process_v1_v2c_msg -> entry with" "~n Vsn: ~p" "~n Domain: ~p" - "~n Address: ~p" + "~n Addr: ~p" "~n Community: ~p" - "~n HS: ~p", [Vsn, Domain, Address, Community, HS]), + "~n HS: ~p", [Vsn, Domain, Addr, Community, HS]), {TDomain, TAddress} = try {snmp_conf:mk_tdomain(Domain), - snmp_conf:mk_taddress(Domain, Address)} + snmp_conf:mk_taddress(Domain, Addr)} catch throw:{error, TReason} -> throw({discarded, {badarg, Domain, TReason}}) end, Max = get_max_message_size(), - AgentMax = get_agent_max_message_size(Address), + AgentMax = get_agent_max_message_size(Addr), PduMS = pdu_ms(Max, AgentMax, HS), ?vtrace("process_v1_v2c_msg -> PduMS: ~p", [PduMS]), diff --git a/lib/snmp/src/manager/snmpm_net_if.erl b/lib/snmp/src/manager/snmpm_net_if.erl index d7f17e0b7f..860b0b83dd 100644 --- a/lib/snmp/src/manager/snmpm_net_if.erl +++ b/lib/snmp/src/manager/snmpm_net_if.erl @@ -55,11 +55,12 @@ %% -define(VMODULE,"NET_IF"). -include("snmp_verbosity.hrl"). --record(state, +-record(state, { server, note_store, - sock, + domain, + sock, mpd_state, log, irb = auto, % auto | {user, integer()} @@ -99,22 +100,22 @@ start_link(Server, NoteStore) -> stop(Pid) -> call(Pid, stop). -send_pdu(Pid, Pdu, Vsn, MsgData, DomainIp, AddrPort) -> - send_pdu(Pid, Pdu, Vsn, MsgData, DomainIp, AddrPort, ?DEFAULT_EXTRA_INFO). +send_pdu(Pid, Pdu, Vsn, MsgData, Domain_or_Ip, Addr_or_Port) -> + send_pdu( + Pid, Pdu, Vsn, MsgData, Domain_or_Ip, Addr_or_Port, ?DEFAULT_EXTRA_INFO). -send_pdu(Pid, Pdu, Vsn, MsgData, Domain, Address, ExtraInfo) - when is_record(Pdu, pdu), is_atom(Domain) -> +send_pdu(Pid, Pdu, Vsn, MsgData, Domain_or_Ip, Addr_or_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" - " Address: ~p", [Pid, Pdu, Vsn, MsgData, Domain, Address]), - cast(Pid, {send_pdu, Pdu, Vsn, MsgData, Domain, Address, ExtraInfo}); -send_pdu(Pid, Pdu, Vsn, MsgData, Ip, Port, ExtraInfo) -> - Domain = snmpm_config:default_transport_domain(), - send_pdu(Pid, Pdu, Vsn, MsgData, Domain, {Ip, Port}, ExtraInfo). + " Pid: ~p~n" + " Pdu: ~p~n" + " Vsn: ~p~n" + " MsgData: ~p~n" + " Domain/IP: ~p~n" + " Addr/Port: ~p", + [Pid, Pdu, Vsn, MsgData, Domain_or_Ip, Addr_or_Port]), + {Domain, Addr} = address(Domain_or_Ip, Addr_or_Port), + cast(Pid, {send_pdu, Pdu, Vsn, MsgData, Domain, Addr, ExtraInfo}). send_pdu(Pid, Pdu, Vsn, MsgData, Domain, Ip, Port, ExtraInfo) -> send_pdu(Pid, Pdu, Vsn, MsgData, Domain, {Ip, Port}, ExtraInfo). @@ -122,8 +123,9 @@ send_pdu(Pid, Pdu, Vsn, MsgData, Domain, Ip, Port, ExtraInfo) -> note_store(Pid, NoteStore) -> call(Pid, {note_store, NoteStore}). -inform_response(Pid, Ref, Domain, Address) -> - cast(Pid, {inform_response, Ref, Domain, Address}). +inform_response(Pid, Ref, Domain_or_Ip, Addr_or_Port) -> + {Domain, Addr} = address(Domain_or_Ip, Addr_or_Port), + cast(Pid, {inform_response, Ref, Domain, Addr}). info(Pid) -> call(Pid, info). @@ -200,7 +202,14 @@ do_init(Server, NoteStore) -> BindTo = get_opt(Opts, bind_to, false), NoReuse = get_opt(Opts, no_reuse, false), {ok, Port} = snmpm_config:system_info(port), - {ok, Sock} = do_open_port(Port, SndBuf, RecBuf, BindTo, NoReuse), + Domain = + case snmpm_config:system_info(domain) of + {ok, D} -> + D; + _ -> + snmpm_config:default_transport_domain() + end, + {ok, Sock} = do_open_port(Port, SndBuf, RecBuf, Domain, BindTo, NoReuse), %% Flow control -- FilterOpts = get_opt(Opts, filter, []), @@ -218,6 +227,7 @@ do_init(Server, NoteStore) -> State = #state{server = Server, note_store = NoteStore, mpd_state = MpdState, + domain = Domain, sock = Sock, log = Log, irb = IRB, @@ -228,18 +238,23 @@ do_init(Server, NoteStore) -> %% Open port -do_open_port(Port, SendSz, RecvSz, BindTo, NoReuse) -> - ?vtrace("do_open_port -> entry with" - "~n Port: ~p" - "~n SendSz: ~p" - "~n RecvSz: ~p" - "~n BindTo: ~p" - "~n NoReuse: ~p", [Port, SendSz, RecvSz, BindTo, NoReuse]), +do_open_port(Port, SendSz, RecvSz, Domain, BindTo, NoReuse) -> + ?vtrace("do_open_port -> entry with~n" + " Port: ~p~n" + " SendSz: ~p~n" + " RecvSz: ~p~n" + " Domain: ~p~n" + " BindTo: ~p~n" + " NoReuse: ~p", + [Port, SendSz, RecvSz, Domain, BindTo, NoReuse]), IpOpts1 = bind_to(BindTo), IpOpts2 = no_reuse(NoReuse), IpOpts3 = recbuf(RecvSz), IpOpts4 = sndbuf(SendSz), - IpOpts = [binary | IpOpts1 ++ IpOpts2 ++ IpOpts3 ++ IpOpts4], + IpOpts = + [binary, + snmp_conf:tdomain_to_family(Domain) | + IpOpts1 ++ IpOpts2 ++ IpOpts3 ++ IpOpts4], OpenRes = case init:get_argument(snmpm_fd) of {ok, [[FdStr]]} -> @@ -387,24 +402,24 @@ handle_call(Req, From, State) -> %% {noreply, State, Timeout} | %% {stop, Reason, State} (terminate/2 is called) %%-------------------------------------------------------------------- -handle_cast({send_pdu, Pdu, Vsn, MsgData, Domain, Address, ExtraInfo}, +handle_cast({send_pdu, Pdu, Vsn, MsgData, Domain, Addr, ExtraInfo}, State) -> ?vlog("received send_pdu message with~n" " Pdu: ~p~n" " Vsn: ~p~n" " MsgData: ~p~n" " Domain: ~p~n" - " Address: ~p", [Pdu, Vsn, MsgData, Domain, Address]), + " Addr : ~p", [Pdu, Vsn, MsgData, Domain, Addr]), maybe_process_extra_info(ExtraInfo), - maybe_handle_send_pdu(Pdu, Vsn, MsgData, Domain, Address, State), + maybe_handle_send_pdu(Pdu, Vsn, MsgData, Domain, Addr, State), {noreply, State}; -handle_cast({inform_response, Ref, Domain, Address}, State) -> +handle_cast({inform_response, Ref, Domain, Addr}, State) -> ?vlog("received inform_response message with~n" - " Ref: ~p~n" - " Domain: ~p~n" - " Address: ~p", [Ref, Domain, Address]), - handle_inform_response(Ref, Domain, Address, State), + " Ref: ~p~n" + " Domain: ~p~n" + " Addr: ~p", [Ref, Domain, Addr]), + handle_inform_response(Ref, Domain, Addr, State), {noreply, State}; handle_cast(filter_reset, State) -> @@ -423,9 +438,10 @@ handle_cast(Msg, State) -> %% {noreply, State, Timeout} | %% {stop, Reason, State} (terminate/2 is called) %%-------------------------------------------------------------------- -handle_info({udp, Sock, Ip, Port, Bytes}, #state{sock = Sock} = State) -> +handle_info( + {udp, Sock, Ip, Port, Bytes}, + #state{sock = Sock, domain = Domain} = State) -> ?vlog("received ~w bytes from ~p:~p [~w]", [size(Bytes), Ip, Port, Sock]), - Domain = snmpm_config:default_transport_domain(), maybe_handle_recv_msg(Domain, {Ip, Port}, Bytes, State), {noreply, State}; @@ -533,48 +549,49 @@ code_change(_Vsn, State, _Extra) -> %%%------------------------------------------------------------------- maybe_handle_recv_msg( - Domain, Address, Bytes, #state{filter = FilterMod} = State) -> - case (catch FilterMod:accept_recv(Domain, Address)) of + Domain, Addr, Bytes, + #state{filter = FilterMod, domain = ManagerDomain} = State) -> + {Arg1, Arg2} = fix_filter_address(ManagerDomain, {Domain, Addr}), + case (catch FilterMod:accept_recv(Arg1, Arg2)) of false -> %% Drop the received packet inc(netIfMsgInDrops), ok; _ -> - handle_recv_msg(Domain, Address, Bytes, State) + handle_recv_msg(Domain, Addr, Bytes, State) end. -handle_recv_msg(Domain, Address, Bytes, #state{server = Pid}) +handle_recv_msg(Domain, Addr, Bytes, #state{server = Pid}) when is_binary(Bytes) andalso (size(Bytes) =:= 0) -> - Pid ! {snmp_error, {empty_message, Domain, Address}, Domain, Address}, + Pid ! {snmp_error, {empty_message, Domain, Addr}, Domain, Addr}, ok; handle_recv_msg( - Domain, Address, Bytes, + Domain, Addr, Bytes, #state{server = Pid, note_store = NoteStore, mpd_state = MpdState, - sock = Sock, log = Log} = State) -> - Logger = logger(Log, read, Domain, Address), - case (catch snmpm_mpd:process_msg(Bytes, Domain, Address, + Logger = logger(Log, read, Domain, Addr), + case (catch snmpm_mpd:process_msg(Bytes, Domain, Addr, MpdState, NoteStore, Logger)) of {ok, Vsn, Pdu, MS, ACM} -> - maybe_handle_recv_pdu(Domain, Address, Vsn, Pdu, MS, ACM, + maybe_handle_recv_pdu(Domain, Addr, Vsn, Pdu, MS, ACM, Logger, State); {discarded, Reason, Report} -> ?vdebug("discarded: ~p", [Reason]), ErrorInfo = {failed_processing_message, Reason}, - Pid ! {snmp_error, ErrorInfo, Domain, Address}, - maybe_udp_send(State#state.filter, Sock, Domain, Address, Report), + Pid ! {snmp_error, ErrorInfo, Domain, Addr}, + maybe_udp_send(Domain, Addr, Report, State), ok; {discarded, Reason} -> ?vdebug("discarded: ~p", [Reason]), ErrorInfo = {failed_processing_message, Reason}, - Pid ! {snmp_error, ErrorInfo, Domain, Address}, + Pid ! {snmp_error, ErrorInfo, Domain, Addr}, ok; Error -> @@ -585,92 +602,93 @@ handle_recv_msg( maybe_handle_recv_pdu( - Domain, Address, Vsn, #pdu{type = Type} = Pdu, PduMS, ACM, Logger, - #state{filter = FilterMod} = State) -> - case (catch FilterMod:accept_recv_pdu(Domain, Address, Type)) of + Domain, Addr, Vsn, #pdu{type = Type} = Pdu, PduMS, ACM, Logger, + #state{filter = FilterMod, domain = ManagerDomain} = State) -> + {Arg1, Arg2} = fix_filter_address(ManagerDomain, {Domain, Addr}), + case (catch FilterMod:accept_recv_pdu(Arg1, Arg2, Type)) of false -> inc(netIfPduInDrops), ok; _ -> handle_recv_pdu( - Domain, Address, Vsn, Pdu, PduMS, ACM, Logger, State) + Domain, Addr, Vsn, Pdu, PduMS, ACM, Logger, State) end; maybe_handle_recv_pdu( - Domain, Address, Vsn, Trap, PduMS, ACM, Logger, - #state{filter = FilterMod} = State) + Domain, Addr, Vsn, Trap, PduMS, ACM, Logger, + #state{filter = FilterMod, domain = ManagerDomain} = State) when is_record(Trap, trappdu) -> - case (catch FilterMod:accept_recv_pdu(Domain, Address, trappdu)) of + {Arg1, Arg2} = fix_filter_address(ManagerDomain, {Domain, Addr}), + case (catch FilterMod:accept_recv_pdu(Arg1, Arg2, trappdu)) of false -> inc(netIfPduInDrops), ok; _ -> handle_recv_pdu( - Domain, Address, Vsn, Trap, PduMS, ACM, Logger, State) + Domain, Addr, Vsn, Trap, PduMS, ACM, Logger, State) end; maybe_handle_recv_pdu( - Domain, Address, Vsn, Pdu, PduMS, ACM, Logger, State) -> - handle_recv_pdu(Domain, Address, Vsn, Pdu, PduMS, ACM, Logger, State). + Domain, Addr, Vsn, Pdu, PduMS, ACM, Logger, State) -> + handle_recv_pdu(Domain, Addr, Vsn, Pdu, PduMS, ACM, Logger, State). handle_recv_pdu( - Domain, Address, Vsn, + Domain, Addr, Vsn, #pdu{type = 'inform-request'} = Pdu, _PduMS, ACM, Logger, #state{server = Pid, irb = IRB} = State) -> handle_inform_request( - IRB, Pid, Vsn, Pdu, ACM, Domain, Address, Logger, State); + IRB, Pid, Vsn, Pdu, ACM, Domain, Addr, Logger, State); handle_recv_pdu( - Domain, Address, _Vsn, + Domain, Addr, _Vsn, #pdu{type = report} = Pdu, _PduMS, ok, _Logger, #state{server = Pid} = _State) -> ?vtrace("received report - ok", []), - Pid ! {snmp_report, {ok, Pdu}, Domain, Address}; + Pid ! {snmp_report, {ok, Pdu}, Domain, Addr}; handle_recv_pdu( - Domain, Address, _Vsn, + Domain, Addr, _Vsn, #pdu{type = report} = Pdu, _PduMS, {error, ReqId, Reason}, _Logger, #state{server = Pid} = _State) -> ?vtrace("received report - error", []), - Pid ! {snmp_report, {error, ReqId, Reason, Pdu}, Domain, Address}; + Pid ! {snmp_report, {error, ReqId, Reason, Pdu}, Domain, Addr}; handle_recv_pdu( - Domain, Address, _Vsn, + Domain, Addr, _Vsn, #pdu{type = 'snmpv2-trap'} = Pdu, _PduMS, _ACM, _Logger, #state{server = Pid} = _State) -> ?vtrace("received snmpv2-trap", []), - Pid ! {snmp_trap, Pdu, Domain, Address}; + Pid ! {snmp_trap, Pdu, Domain, Addr}; handle_recv_pdu( - Domain, Address, _Vsn, Trap, _PduMS, _ACM, _Logger, + Domain, Addr, _Vsn, Trap, _PduMS, _ACM, _Logger, #state{server = Pid} = _State) when is_record(Trap, trappdu) -> ?vtrace("received trappdu", []), - Pid ! {snmp_trap, Trap, Domain, Address}; + Pid ! {snmp_trap, Trap, Domain, Addr}; handle_recv_pdu( - Domain, Address, _Vsn, Pdu, _PduMS, _ACM, _Logger, + Domain, Addr, _Vsn, Pdu, _PduMS, _ACM, _Logger, #state{server = Pid} = _State) when is_record(Pdu, pdu) -> ?vtrace("received pdu", []), - Pid ! {snmp_pdu, Pdu, Domain, Address}; + Pid ! {snmp_pdu, Pdu, Domain, Addr}; handle_recv_pdu( - _Domain, _Address, _Vsn, Pdu, _PduMS, ACM, _Logger, _State) -> + _Domain, _Addr, _Vsn, Pdu, _PduMS, ACM, _Logger, _State) -> ?vlog("received unexpected pdu: " "~n Pdu: ~p" "~n ACM: ~p", [Pdu, ACM]). handle_inform_request( - auto, Pid, Vsn, Pdu, ACM, Domain, Address, Logger, State) -> + auto, Pid, Vsn, Pdu, ACM, Domain, Addr, Logger, State) -> ?vtrace("received inform-request (true)", []), - Pid ! {snmp_inform, ignore, Pdu, Domain, Address}, + Pid ! {snmp_inform, ignore, Pdu, Domain, Addr}, RePdu = make_response_pdu(Pdu), - maybe_send_inform_response( - RePdu, Vsn, ACM, Domain, Address, Logger, State); + maybe_send_inform_response(RePdu, Vsn, ACM, Domain, Addr, Logger, State); handle_inform_request( {user, To}, Pid, Vsn, #pdu{request_id = ReqId} = Pdu, - ACM, Domain, Address, _Logger, _State) -> + ACM, Domain, Addr, _Logger, _State) -> ?vtrace("received inform-request (false)", []), - Pid ! {snmp_inform, ReqId, Pdu, Domain, Address}, + Pid ! {snmp_inform, ReqId, Pdu, Domain, Addr}, %% Before we go any further, we need to check that we have not %% already received this message (possible resend). - Key = {ReqId, Domain, Address}, + Key = {ReqId, Domain, Addr}, case ets:lookup(snmpm_inform_request_table, Key) of [_] -> %% OK, we already know about this. We assume this @@ -684,26 +702,28 @@ handle_inform_request( ets:insert(snmpm_inform_request_table, Rec) end. -handle_inform_response(Ref, Domain, Address, State) -> - Key = {Ref, Domain, Address}, +handle_inform_response(Ref, Domain, Addr, State) -> + Key = {Ref, Domain, Addr}, case ets:lookup(snmpm_inform_request_table, Key) of [{Key, _, {Vsn, ACM, RePdu}}] -> - Logger = logger(State#state.log, read, Domain, Address), + Logger = logger(State#state.log, read, Domain, Addr), ets:delete(snmpm_inform_request_table, Key), - maybe_send_inform_response(RePdu, Vsn, ACM, Domain, Address, - Logger, State); + maybe_send_inform_response( + RePdu, Vsn, ACM, Domain, Addr, Logger, State); [] -> %% Already acknowledged, or the user was to slow to reply... ok end, ok. -maybe_send_inform_response(RePdu, Vsn, ACM, Domain, Address, Logger, - #state{server = Pid, - sock = Sock, - filter = FilterMod}) -> +maybe_send_inform_response( + RePdu, Vsn, ACM, Domain, Addr, Logger, + #state{server = Pid, + filter = FilterMod, + domain = ManagerDomain} = State) -> + {Arg1, Arg2} = fix_filter_address(ManagerDomain, {Domain, Addr}), case (catch FilterMod:accept_send_pdu( - Domain, Address, pdu_type_of(RePdu))) + Arg1, Arg2, pdu_type_of(RePdu))) of false -> inc(netIfPduOutDrops), @@ -711,13 +731,13 @@ maybe_send_inform_response(RePdu, Vsn, ACM, Domain, Address, Logger, _ -> case snmpm_mpd:generate_response_msg(Vsn, RePdu, ACM, Logger) of {ok, Msg} -> - maybe_udp_send(FilterMod, Sock, Domain, Address, Msg); + maybe_udp_send(Domain, Addr, Msg, State); {discarded, Reason} -> ?vlog("failed generating response message:" "~n Reason: ~p", [Reason]), ReqId = RePdu#pdu.request_id, ErrorInfo = {failed_generating_response, {RePdu, Reason}}, - Pid ! {snmp_error, ReqId, ErrorInfo, Domain, Address}, + Pid ! {snmp_error, ReqId, ErrorInfo, Domain, Addr}, ok end end. @@ -752,28 +772,29 @@ irgc_stop(Ref) -> (catch erlang:cancel_timer(Ref)). -maybe_handle_send_pdu(Pdu, Vsn, MsgData, Domain, Address, - #state{filter = FilterMod} = State) -> - case (catch FilterMod:accept_send_pdu(Domain, Address, pdu_type_of(Pdu))) of +maybe_handle_send_pdu( + Pdu, Vsn, MsgData, Domain, Addr, + #state{filter = FilterMod, domain = ManagerDomain} = State) -> + {Arg1, Arg2} = fix_filter_address(ManagerDomain, {Domain, Addr}), + case (catch FilterMod:accept_send_pdu(Arg1, Arg2, pdu_type_of(Pdu))) of false -> inc(netIfPduOutDrops), ok; _ -> - handle_send_pdu(Pdu, Vsn, MsgData, Domain, Address, State) + handle_send_pdu(Pdu, Vsn, MsgData, Domain, Addr, State) end. -handle_send_pdu(Pdu, Vsn, MsgData, Domain, Address, - #state{server = Pid, - note_store = NoteStore, - sock = Sock, - log = Log, - filter = FilterMod}) -> - Logger = logger(Log, write, Domain, Address), - case (catch snmpm_mpd:generate_msg(Vsn, NoteStore, - Pdu, MsgData, Logger)) of +handle_send_pdu( + Pdu, Vsn, MsgData, Domain, Addr, + #state{server = Pid, + note_store = NoteStore, + log = Log} = State) -> + Logger = logger(Log, write, Domain, Addr), + case (catch snmpm_mpd:generate_msg( + Vsn, NoteStore, Pdu, MsgData, Logger)) of {ok, Msg} -> ?vtrace("handle_send_pdu -> message generated", []), - maybe_udp_send(FilterMod, Sock, Domain, Address, Msg); + maybe_udp_send(Domain, Addr, Msg, State); {discarded, Reason} -> ?vlog("PDU not sent: " "~n PDU: ~p" @@ -783,12 +804,18 @@ handle_send_pdu(Pdu, Vsn, MsgData, Domain, Address, end. -maybe_udp_send(FilterMod, Sock, Domain, {Ip, Port} = Address, Msg) -> - case (catch FilterMod:accept_send(Domain, Address)) of +maybe_udp_send( + Domain, Addr, Msg, + #state{sock = Sock, filter = FilterMod, domain = ManagerDomain}) -> + {Arg1, Arg2} = fix_filter_address(ManagerDomain, {Domain, Addr}), + case (catch FilterMod:accept_send(Arg1, Arg2)) of false -> inc(netIfMsgOutDrops), ok; _ -> + %% XXX There should be some kind of lookup of socket + %% from transport domain here + {Ip, Port} = Addr, udp_send(Sock, Ip, Port, Msg) end. @@ -998,6 +1025,26 @@ handle_set_log_type(State, _NewType) -> {State, {error, not_enabled}}. +%% If the manager uses legacy snmpUDPDomain e.g has not set +%% {domain, _}, then make sure snmpm_network_interface_filter +%% gets legacy arguments to not break backwards compatibility. +%% +fix_filter_address(snmpUDPDomain, {Domain, Addr}) + when Domain =:= snmpUDPDomain; + Domain =:= transportDomainUdpIpv4 -> + Addr; +fix_filter_address(_ManagerDomain, {Domain, _} = Address) + when is_atom(Domain) -> + Address; +fix_filter_address(snmpUDPDomain, {_, Port} = Addr) + when is_integer(Port) -> + Addr. + +address(Domain, Addr) when is_atom(Domain) -> + {Domain, Addr}; +address(Ip, Port) when is_integer(Port) -> + {snmpm_config:default_transport_domain(), {Ip, Port}}. + %% ------------------------------------------------------------------- make_response_pdu(#pdu{request_id = ReqId, varbinds = Vbs}) -> @@ -1038,15 +1085,17 @@ t() -> %% ------------------------------------------------------------------- -logger(undefined, _Type, _Domain, _Address) -> +logger(undefined, _Type, _Domain, _Addr) -> fun(_) -> ok end; -logger({Log, Types}, Type, Domain, Address) -> +logger({Log, Types}, Type, Domain, Addr) -> case lists:member(Type, Types) of true -> + AddrString = + iolist_to_binary(snmp_conf:mk_addr_string({Domain, Addr})), fun(Msg) -> - snmp_log:log(Log, Msg, Domain, Address) + snmp_log:log(Log, Msg, AddrString) end; false -> fun(_) -> diff --git a/lib/snmp/src/manager/snmpm_net_if_filter.erl b/lib/snmp/src/manager/snmpm_net_if_filter.erl index 54b87a772a..d96ae5c145 100644 --- a/lib/snmp/src/manager/snmpm_net_if_filter.erl +++ b/lib/snmp/src/manager/snmpm_net_if_filter.erl @@ -30,10 +30,10 @@ accept_recv(Domain, _Address) when is_atom(Domain) -> " Domain: ~p~n" " Address: ~p", [Domain, _Address]), true; -accept_recv(_Addr, _Port) -> +accept_recv(_Addr, Port) when is_integer(Port) -> ?d("accept_recv -> entry with~n" " Addr: ~p~n" - " Port: ~p", [_Addr, _Port]), + " Port: ~p", [_Addr, Port]), true. accept_send(Domain, _Address) when is_atom(Domain) -> @@ -41,10 +41,10 @@ accept_send(Domain, _Address) when is_atom(Domain) -> " Domain: ~p~n" " Address: ~p", [Domain, _Address]), true; -accept_send(_Addr, _Port) -> +accept_send(_Addr, Port) when is_integer(Port) -> ?d("accept_send -> entry with~n" " Addr: ~p~n" - " Port: ~p", [_Addr, _Port]), + " Port: ~p", [_Addr, Port]), true. accept_recv_pdu(Domain, _Address, _PduType) when is_atom(Domain) -> @@ -53,11 +53,11 @@ accept_recv_pdu(Domain, _Address, _PduType) when is_atom(Domain) -> " Address: ~p~n" " PduType: ~p", [Domain, _Address, _PduType]), true; -accept_recv_pdu(_Addr, _Port, _PduType) -> +accept_recv_pdu(_Addr, Port, _PduType) when is_integer(Port) -> ?d("accept_recv_pdu -> entry with~n" " Addr: ~p~n" " Port: ~p~n" - " PduType: ~p", [_Addr, _Port, _PduType]), + " PduType: ~p", [_Addr, Port, _PduType]), true. accept_send_pdu(Domain, _Address, _PduType) when is_atom(Domain) -> @@ -66,10 +66,10 @@ accept_send_pdu(Domain, _Address, _PduType) when is_atom(Domain) -> " Address: ~p~n" " PduType: ~p", [Domain, _Address, _PduType]), true; -accept_send_pdu(_Addr, _Port, _PduType) -> +accept_send_pdu(_Addr, Port, _PduType) when is_integer(Port) -> ?d("accept_send_pdu -> entry with~n" " Addr: ~p~n" " Port: ~p~n" - " PduType: ~p", [_Addr, _Port, _PduType]), + " PduType: ~p", [_Addr, Port, _PduType]), true. diff --git a/lib/snmp/src/manager/snmpm_server.erl b/lib/snmp/src/manager/snmpm_server.erl index b3389ef96c..ece5dad082 100644 --- a/lib/snmp/src/manager/snmpm_server.erl +++ b/lib/snmp/src/manager/snmpm_server.erl @@ -1032,14 +1032,14 @@ handle_info({snmp_error, Pdu, Reason}, State) -> handle_snmp_error(Pdu, Reason, State), {noreply, State}; -handle_info({snmp_error, Reason, Domain, Address}, State) -> +handle_info({snmp_error, Reason, Domain, Addr}, State) -> ?vlog("received snmp_error message", []), - handle_snmp_error(Domain, Address, -1, Reason, State), + handle_snmp_error(Domain, Addr, -1, Reason, State), {noreply, State}; -handle_info({snmp_error, ReqId, Reason, Domain, Address}, State) -> +handle_info({snmp_error, ReqId, Reason, Domain, Addr}, State) -> ?vlog("received snmp_error message", []), - handle_snmp_error(Domain, Address, ReqId, Reason, State), + handle_snmp_error(Domain, Addr, ReqId, Reason, State), {noreply, State}; %% handle_info({snmp_error, ReqId, Pdu, Reason, Addr, Port}, State) -> @@ -1048,30 +1048,30 @@ handle_info({snmp_error, ReqId, Reason, Domain, Address}, State) -> %% {noreply, State}; -handle_info({snmp_pdu, Pdu, Domain, Address}, State) -> +handle_info({snmp_pdu, Pdu, Domain, Addr}, State) -> ?vlog("received snmp_pdu message", []), - handle_snmp_pdu(Pdu, Domain, Address, State), + handle_snmp_pdu(Pdu, Domain, Addr, State), {noreply, State}; -handle_info({snmp_trap, Trap, Domain, Address}, State) -> +handle_info({snmp_trap, Trap, Domain, Addr}, State) -> ?vlog("received snmp_trap message", []), - handle_snmp_trap(Trap, Domain, Address, State), + handle_snmp_trap(Trap, Domain, Addr, State), {noreply, State}; -handle_info({snmp_inform, Ref, Pdu, Domain, Address}, State) -> +handle_info({snmp_inform, Ref, Pdu, Domain, Addr}, State) -> ?vlog("received snmp_inform message", []), - handle_snmp_inform(Ref, Pdu, Domain, Address, State), + handle_snmp_inform(Ref, Pdu, Domain, Addr, State), {noreply, State}; -handle_info({snmp_report, {ok, Pdu}, Domain, Address}, State) -> - handle_snmp_report(Pdu, Domain, Address, State), +handle_info({snmp_report, {ok, Pdu}, Domain, Addr}, State) -> + handle_snmp_report(Pdu, Domain, Addr, State), {noreply, State}; -handle_info({snmp_report, {error, ReqId, Info, Pdu}, Domain, Address}, State) -> - handle_snmp_report(ReqId, Pdu, Info, Domain, Address, State), +handle_info({snmp_report, {error, ReqId, Info, Pdu}, Domain, Addr}, State) -> + handle_snmp_report(ReqId, Pdu, Info, Domain, Addr, State), {noreply, State}; @@ -1175,11 +1175,11 @@ handle_sync_get(Pid, UserId, TargetName, Oids, SendOpts, From, State) -> "~n From: ~p", [Pid, UserId, TargetName, Oids, SendOpts, From]), case agent_data(TargetName, SendOpts) of - {ok, RegType, Domain, Address, Vsn, MsgData} -> + {ok, RegType, Domain, Addr, Vsn, MsgData} -> ?vtrace("handle_sync_get -> send a ~p message", [Vsn]), Extra = ?GET_EXTRA(SendOpts), ReqId = send_get_request(Oids, Vsn, MsgData, - Domain, Address, + Domain, Addr, Extra, State), ?vdebug("handle_sync_get -> ReqId: ~p", [ReqId]), Msg = {sync_timeout, ReqId, From}, @@ -1192,7 +1192,7 @@ handle_sync_get(Pid, UserId, TargetName, Oids, SendOpts, From, State) -> reg_type = RegType, target = TargetName, domain = Domain, - address = Address, + address = Addr, type = get, data = MsgData, ref = Ref, @@ -1228,11 +1228,11 @@ handle_sync_get_next(Pid, UserId, TargetName, Oids, SendOpts, "~n From: ~p", [Pid, UserId, TargetName, Oids, SendOpts, From]), case agent_data(TargetName, SendOpts) of - {ok, RegType, Domain, Address, Vsn, MsgData} -> + {ok, RegType, Domain, Addr, Vsn, MsgData} -> ?vtrace("handle_sync_get_next -> send a ~p message", [Vsn]), Extra = ?GET_EXTRA(SendOpts), ReqId = send_get_next_request(Oids, Vsn, MsgData, - Domain, Address, + Domain, Addr, Extra, State), ?vdebug("handle_sync_get_next -> ReqId: ~p", [ReqId]), Msg = {sync_timeout, ReqId, From}, @@ -1245,7 +1245,7 @@ handle_sync_get_next(Pid, UserId, TargetName, Oids, SendOpts, reg_type = RegType, target = TargetName, domain = Domain, - address = Address, + address = Addr, type = get_next, data = MsgData, ref = Ref, @@ -1287,11 +1287,11 @@ handle_sync_get_bulk(Pid, UserId, TargetName, NonRep, MaxRep, Oids, SendOpts, "~n From: ~p", [Pid, UserId, TargetName, NonRep, MaxRep, Oids, SendOpts, From]), case agent_data(TargetName, SendOpts) of - {ok, RegType, Domain, Address, Vsn, MsgData} -> + {ok, RegType, Domain, Addr, Vsn, MsgData} -> ?vtrace("handle_sync_get_bulk -> send a ~p message", [Vsn]), Extra = ?GET_EXTRA(SendOpts), ReqId = send_get_bulk_request(Oids, Vsn, MsgData, - Domain, Address, + Domain, Addr, NonRep, MaxRep, Extra, State), ?vdebug("handle_sync_get_bulk -> ReqId: ~p", [ReqId]), Msg = {sync_timeout, ReqId, From}, @@ -1304,7 +1304,7 @@ handle_sync_get_bulk(Pid, UserId, TargetName, NonRep, MaxRep, Oids, SendOpts, reg_type = RegType, target = TargetName, domain = Domain, - address = Address, + address = Addr, type = get_bulk, data = MsgData, ref = Ref, @@ -1342,11 +1342,11 @@ handle_sync_set(Pid, UserId, TargetName, VarsAndVals, SendOpts, From, State) -> "~n From: ~p", [Pid, UserId, TargetName, VarsAndVals, From]), case agent_data(TargetName, SendOpts) of - {ok, RegType, Domain, Address, Vsn, MsgData} -> + {ok, RegType, Domain, Addr, Vsn, MsgData} -> ?vtrace("handle_sync_set -> send a ~p message", [Vsn]), Extra = ?GET_EXTRA(SendOpts), ReqId = send_set_request(VarsAndVals, Vsn, MsgData, - Domain, Address, + Domain, Addr, Extra, State), ?vdebug("handle_sync_set -> ReqId: ~p", [ReqId]), Msg = {sync_timeout, ReqId, From}, @@ -1359,7 +1359,7 @@ handle_sync_set(Pid, UserId, TargetName, VarsAndVals, SendOpts, From, State) -> reg_type = RegType, target = TargetName, domain = Domain, - address = Address, + address = Addr, type = set, data = MsgData, ref = Ref, @@ -1395,11 +1395,11 @@ handle_async_get(Pid, UserId, TargetName, Oids, SendOpts, State) -> "~n SendOpts: ~p", [Pid, UserId, TargetName, Oids, SendOpts]), case agent_data(TargetName, SendOpts) of - {ok, RegType, Domain, Address, Vsn, MsgData} -> + {ok, RegType, Domain, Addr, Vsn, MsgData} -> ?vtrace("handle_async_get -> send a ~p message", [Vsn]), Extra = ?GET_EXTRA(SendOpts), ReqId = send_get_request(Oids, Vsn, MsgData, - Domain, Address, + Domain, Addr, Extra, State), ?vdebug("handle_async_get -> ReqId: ~p", [ReqId]), Expire = ?ASYNC_GET_TIMEOUT(SendOpts), @@ -1408,7 +1408,7 @@ handle_async_get(Pid, UserId, TargetName, Oids, SendOpts, State) -> reg_type = RegType, target = TargetName, domain = Domain, - address = Address, + address = Addr, type = get, data = MsgData, expire = t() + Expire}, @@ -1444,11 +1444,11 @@ handle_async_get_next(Pid, UserId, TargetName, Oids, SendOpts, State) -> "~n SendOpts: ~p", [Pid, UserId, TargetName, Oids, SendOpts]), case agent_data(TargetName, SendOpts) of - {ok, RegType, Domain, Address, Vsn, MsgData} -> + {ok, RegType, Domain, Addr, Vsn, MsgData} -> ?vtrace("handle_async_get_next -> send a ~p message", [Vsn]), Extra = ?GET_EXTRA(SendOpts), ReqId = send_get_next_request(Oids, Vsn, MsgData, - Domain, Address, + Domain, Addr, Extra, State), ?vdebug("handle_async_get_next -> ReqId: ~p", [ReqId]), Expire = ?ASYNC_GET_NEXT_TIMEOUT(SendOpts), @@ -1457,7 +1457,7 @@ handle_async_get_next(Pid, UserId, TargetName, Oids, SendOpts, State) -> reg_type = RegType, target = TargetName, domain = Domain, - address = Address, + address = Addr, type = get_next, data = MsgData, expire = t() + Expire}, @@ -1500,11 +1500,11 @@ handle_async_get_bulk(Pid, "~n SendOpts: ~p", [Pid, UserId, TargetName, NonRep, MaxRep, Oids, SendOpts]), case agent_data(TargetName, SendOpts) of - {ok, RegType, Domain, Address, Vsn, MsgData} -> + {ok, RegType, Domain, Addr, Vsn, MsgData} -> ?vtrace("handle_async_get_bulk -> send a ~p message", [Vsn]), Extra = ?GET_EXTRA(SendOpts), ReqId = send_get_bulk_request(Oids, Vsn, MsgData, - Domain, Address, + Domain, Addr, NonRep, MaxRep, Extra, State), ?vdebug("handle_async_get_bulk -> ReqId: ~p", [ReqId]), Expire = ?ASYNC_GET_BULK_TIMEOUT(SendOpts), @@ -1513,7 +1513,7 @@ handle_async_get_bulk(Pid, reg_type = RegType, target = TargetName, domain = Domain, - address = Address, + address = Addr, type = get_bulk, data = MsgData, expire = t() + Expire}, @@ -1548,11 +1548,11 @@ handle_async_set(Pid, UserId, TargetName, VarsAndVals, SendOpts, State) -> "~n SendOpts: ~p", [Pid, UserId, TargetName, VarsAndVals, SendOpts]), case agent_data(TargetName, SendOpts) of - {ok, RegType, Domain, Address, Vsn, MsgData} -> + {ok, RegType, Domain, Addr, Vsn, MsgData} -> ?vtrace("handle_async_set -> send a ~p message", [Vsn]), Extra = ?GET_EXTRA(SendOpts), ReqId = send_set_request(VarsAndVals, Vsn, MsgData, - Domain, Address, + Domain, Addr, Extra, State), ?vdebug("handle_async_set -> ReqId: ~p", [ReqId]), Expire = ?ASYNC_SET_TIMEOUT(SendOpts), @@ -1561,7 +1561,7 @@ handle_async_set(Pid, UserId, TargetName, VarsAndVals, SendOpts, State) -> reg_type = RegType, target = TargetName, domain = Domain, - address = Address, + address = Addr, type = set, data = MsgData, expire = t() + Expire}, @@ -1799,15 +1799,15 @@ handle_snmp_error(CrapError, Reason, _State) -> "~n~p~n~p", [CrapError, Reason]), ok. -handle_snmp_error(Domain, Address, ReqId, Reason, State) -> +handle_snmp_error(Domain, Addr, ReqId, Reason, State) -> ?vtrace("handle_snmp_error -> entry with~n" " Domain: ~p~n" - " Address: ~p~n" + " Addr: ~p~n" " ReqId: ~p~n" - " Reason: ~p", [Domain, Address, ReqId, Reason]), + " Reason: ~p", [Domain, Addr, ReqId, Reason]), - case snmpm_config:get_agent_user_id(Domain, Address) of + case snmpm_config:get_agent_user_id(Domain, Addr) of {ok, UserId} -> case snmpm_config:user_info(UserId) of {ok, UserMod, UserData} -> @@ -1822,7 +1822,7 @@ handle_snmp_error(Domain, Address, ReqId, Reason, State) -> error_msg("failed retreiving the default user " "info handling snmp error " "<~p,~p>: ~n~w~n~w", - [Domain, Address, ReqId, Reason]) + [Domain, Addr, ReqId, Reason]) end end; _Error -> @@ -1834,7 +1834,7 @@ handle_snmp_error(Domain, Address, ReqId, Reason, State) -> error_msg("failed retreiving the default user " "info handling snmp error " "<~p,~p>: ~n~w~n~w", - [Domain, Address, ReqId, Reason]) + [Domain, Addr, ReqId, Reason]) end end. @@ -1858,12 +1858,12 @@ handle_error(_UserId, Mod, Reason, ReqId, Data, _State) -> handle_snmp_pdu(#pdu{type = 'get-response', request_id = ReqId} = Pdu, - Domain, Address, State) -> + Domain, Addr, State) -> ?vtrace("handle_snmp_pdu(get-response) -> entry with~n" " Domain: ~p~n" - " Address: ~p~n" - " Pdu: ~p", [Domain, Address, Pdu]), + " Addr: ~p~n" + " Pdu: ~p", [Domain, Addr, Pdu]), case ets:lookup(snmpm_request_table, ReqId) of @@ -1895,7 +1895,7 @@ handle_snmp_pdu(#pdu{type = 'get-response', request_id = ReqId} = Pdu, {ok, UserMod, UserData} -> handle_pdu( UserId, UserMod, - RegType, Target, Domain, Address, + RegType, Target, Domain, Addr, ReqId, SnmpResponse, UserData, State), maybe_delete(Disco, ReqId); _Error -> @@ -1906,14 +1906,14 @@ handle_snmp_pdu(#pdu{type = 'get-response', request_id = ReqId} = Pdu, {ok, DefUserId, DefMod, DefData} -> handle_pdu( DefUserId, DefMod, - RegType, Target, Domain, Address, + RegType, Target, Domain, Addr, ReqId, SnmpResponse, DefData, State), maybe_delete(Disco, ReqId); Error -> error_msg("failed retreiving the default user " "info handling pdu from " "~p <~p,~p>: ~n~w~n~w", - [Target, Domain, Address, Error, Pdu]) + [Target, Domain, Addr, Error, Pdu]) end end; @@ -1967,7 +1967,7 @@ handle_snmp_pdu(#pdu{type = 'get-response', request_id = ReqId} = Pdu, varbinds = Varbinds} = Pdu, Varbinds2 = fix_vbs_BITS(Varbinds), SnmpInfo = {EStatus, EIndex, Varbinds2}, - case snmpm_config:get_agent_user_id(Domain, Address) of + case snmpm_config:get_agent_user_id(Domain, Addr) of {ok, UserId} -> %% A very late reply or a reply to a request %% that has been cancelled. @@ -1992,7 +1992,7 @@ handle_snmp_pdu(#pdu{type = 'get-response', request_id = ReqId} = Pdu, "user info handling (old) " "pdu from " "<~p,~p>: ~n~w~n~w", - [Domain, Address, Error, Pdu]) + [Domain, Addr, Error, Pdu]) end end; @@ -2011,7 +2011,7 @@ handle_snmp_pdu(#pdu{type = 'get-response', request_id = ReqId} = Pdu, {ok, DefUserId, DefMod, DefData} -> handle_agent( DefUserId, DefMod, - Domain, Address, + Domain, Addr, pdu, ignore, SnmpInfo, DefData, State); Error -> @@ -2019,19 +2019,19 @@ handle_snmp_pdu(#pdu{type = 'get-response', request_id = ReqId} = Pdu, "info handling (old) pdu when no user " "found from " "<~p,~p>: ~n~w~n~w", - [Domain, Address, Error, Pdu]) + [Domain, Addr, Error, Pdu]) end end end; -handle_snmp_pdu(CrapPdu, Domain, Address, _State) -> +handle_snmp_pdu(CrapPdu, Domain, Addr, _State) -> error_msg("received crap (snmp) Pdu from ~w:~w =>" - "~p", [Domain, Address, CrapPdu]), + "~p", [Domain, Addr, CrapPdu]), ok. handle_pdu( - _UserId, Mod, target_name = _RegType, TargetName, _Domain, _Address, + _UserId, Mod, target_name = _RegType, TargetName, _Domain, _Addr, ReqId, SnmpResponse, Data, _State) -> ?vtrace("handle_pdu(target_name) -> entry when" "~n Mod: ~p", [Mod]), @@ -2049,37 +2049,37 @@ handle_pdu( handle_callback(F), ok; handle_pdu( - _UserId, Mod, addr_port = _RegType, _TargetName, _Domain, Address, + _UserId, Mod, addr_port = _RegType, _TargetName, _Domain, Addr, ReqId, SnmpResponse, Data, _State) -> ?vtrace("handle_pdu(addr_port) -> entry when" "~n Mod: ~p", [Mod]), F = fun() -> - {Ip, Port} = Address, + {Ip, Port} = Addr, (catch Mod:handle_pdu(Ip, Port, ReqId, SnmpResponse, Data)) end, handle_callback(F), ok. -handle_agent(UserId, Mod, Domain, Address, Type, Ref, SnmpInfo, Data, State) -> +handle_agent(UserId, Mod, Domain, Addr, Type, Ref, SnmpInfo, Data, State) -> ?vtrace("handle_agent -> entry when" "~n UserId: ~p" "~n Type: ~p" "~n Mod: ~p", [UserId, Type, Mod]), F = fun() -> - do_handle_agent(UserId, Mod, Domain, Address, + do_handle_agent(UserId, Mod, Domain, Addr, Type, Ref, SnmpInfo, Data, State) end, handle_callback(F), ok. do_handle_agent(DefUserId, DefMod, - Domain, Address, + Domain, Addr, Type, Ref, SnmpInfo, DefData, State) -> ?vdebug("do_handle_agent -> entry when" "~n DefUserId: ~p", [DefUserId]), - try DefMod:handle_agent(Domain, Address, Type, SnmpInfo, DefData) of + try DefMod:handle_agent(Domain, Addr, Type, SnmpInfo, DefData) of {register, UserId2, TargetName, Config} -> ?vtrace("do_handle_agent -> register: " "~n UserId2: ~p" @@ -2088,7 +2088,7 @@ do_handle_agent(DefUserId, DefMod, [UserId2, TargetName, Config]), Config2 = ensure_present( - [{tdomain, Domain}, {taddress, Address}], Config), + [{tdomain, Domain}, {taddress, Addr}], Config), Config3 = [{reg_type, target_name} | Config2], case snmpm_config:register_agent(UserId2, TargetName, Config3) of @@ -2098,7 +2098,7 @@ do_handle_agent(DefUserId, DefMod, error_msg("failed registering agent - " "handling agent " "~p <~p,~p>: ~n~w", - [TargetName, Domain, Address, Reason]), + [TargetName, Domain, Addr, Reason]), ok end; @@ -2107,23 +2107,23 @@ do_handle_agent(DefUserId, DefMod, ok; InvalidResult -> - CallbackArgs = [Domain, Address, Type, SnmpInfo, DefData], + CallbackArgs = [Domain, Addr, Type, SnmpInfo, DefData], handle_invalid_result(handle_agent, CallbackArgs, InvalidResult) catch error:{undef, _} when Type =:= pdu -> %% Maybe, still on the old API ?vdebug("do_handle_agent -> maybe still on the old api", []), - {Ip, Port} = Address, + {Ip, Port} = Addr, case (catch DefMod:handle_agent(Ip, Port, SnmpInfo, DefData)) of {register, UserId2, Config} -> ?vtrace("do_handle_agent -> register: " "~n UserId2: ~p" "~n Config: ~p", [UserId2, Config]), - TargetName = mk_target_name(Domain, Address, Config), + TargetName = mk_target_name(Domain, Addr, Config), Config2 = ensure_present( - [{tdomain, Domain}, {taddress, Address}], Config), + [{tdomain, Domain}, {taddress, Addr}], Config), Config3 = [{reg_type, addr_port} | Config2], case snmpm_config:register_agent( UserId2, TargetName, Config3) of @@ -2133,7 +2133,7 @@ do_handle_agent(DefUserId, DefMod, error_msg("failed registering agent - " "handling agent " "~p <~p,~p>: ~n~w", - [TargetName, Domain, Address, Reason]), + [TargetName, Domain, Addr, Reason]), ok end; {register, UserId2, TargetName, Config} -> @@ -2144,7 +2144,7 @@ do_handle_agent(DefUserId, DefMod, [UserId2, TargetName, Config]), Config2 = ensure_present( - [{tdomain, Domain}, {taddress, Address}], Config), + [{tdomain, Domain}, {taddress, Addr}], Config), Config3 = [{reg_type, target_name} | Config2], case snmpm_config:register_agent( UserId2, TargetName, Config3) of @@ -2154,7 +2154,7 @@ do_handle_agent(DefUserId, DefMod, error_msg("failed registering agent - " "handling agent " "~p <~p,~p>: ~n~w", - [TargetName, Domain, Address, Reason]), + [TargetName, Domain, Addr, Reason]), ok end; _Ignore -> @@ -2172,38 +2172,38 @@ do_handle_agent(DefUserId, DefMod, %% Backward compatibillity crap RegType = target_name, - Target = mk_target_name(Domain, Address, default_agent_config()), + Target = mk_target_name(Domain, Addr, default_agent_config()), case Type of report -> SnmpInform = SnmpInfo, handle_report( DefUserId, DefMod, - RegType, Target, Domain, Address, + RegType, Target, Domain, Addr, SnmpInform, DefData, State); inform -> SnmpInform = SnmpInfo, handle_inform( DefUserId, DefMod, Ref, - RegType, Target, Domain, Address, + RegType, Target, Domain, Addr, SnmpInform, DefData, State); trap -> SnmpTrapInfo = SnmpInfo, handle_trap( DefUserId, DefMod, - RegType, Target, Domain, Address, + RegType, Target, Domain, Addr, SnmpTrapInfo, DefData, State); _ -> error_msg( "failed delivering ~w info to default user - " "regarding agent " - "<~p,~p>: ~n~w", [Type, Domain, Address, SnmpInfo]) + "<~p,~p>: ~n~w", [Type, Domain, Addr, SnmpInfo]) end; T:E -> - CallbackArgs = [Domain, Address, Type, SnmpInfo, DefData], + CallbackArgs = [Domain, Addr, Type, SnmpInfo, DefData], handle_invalid_result(handle_agent, CallbackArgs, T, E) end. @@ -2226,45 +2226,45 @@ handle_snmp_trap( generic_trap = Generic, specific_trap = Spec, time_stamp = Timestamp, - varbinds = Varbinds} = Trap, Domain, Address, State) -> + varbinds = Varbinds} = Trap, Domain, Addr, State) -> ?vtrace("handle_snmp_trap [trappdu] -> entry with~n" " Domain: ~p~n" - " Address: ~p~n" - " Trap: ~p", [Domain, Address, Trap]), + " Addr: ~p~n" + " Trap: ~p", [Domain, Addr, Trap]), Varbinds2 = fix_vbs_BITS(Varbinds), SnmpTrapInfo = {Enteprise, Generic, Spec, Timestamp, Varbinds2}, - do_handle_snmp_trap(SnmpTrapInfo, Domain, Address, State); + do_handle_snmp_trap(SnmpTrapInfo, Domain, Addr, State); handle_snmp_trap(#pdu{error_status = EStatus, error_index = EIndex, varbinds = Varbinds} = Trap, - Domain, Address, State) -> + Domain, Addr, State) -> ?vtrace("handle_snmp_trap [pdu] -> entry with~n" " Domain: ~p~n" - " Address: ~p~n" - " Trap: ~p", [Domain, Address, Trap]), + " Addr: ~p~n" + " Trap: ~p", [Domain, Addr, Trap]), Varbinds2 = fix_vbs_BITS(Varbinds), SnmpTrapInfo = {EStatus, EIndex, Varbinds2}, - do_handle_snmp_trap(SnmpTrapInfo, Domain, Address, State); + do_handle_snmp_trap(SnmpTrapInfo, Domain, Addr, State); -handle_snmp_trap(CrapTrap, Domain, Address, _State) -> +handle_snmp_trap(CrapTrap, Domain, Addr, _State) -> error_msg("received crap (snmp) trap from ~w:~w =>" - "~p", [Domain, Address, CrapTrap]), + "~p", [Domain, Addr, CrapTrap]), ok. -do_handle_snmp_trap(SnmpTrapInfo, Domain, Address, State) -> - case snmpm_config:get_agent_user_info(Domain, Address) of +do_handle_snmp_trap(SnmpTrapInfo, Domain, Addr, State) -> + case snmpm_config:get_agent_user_info(Domain, Addr) of {ok, UserId, Target, RegType} -> ?vtrace("handle_snmp_trap -> found user: ~p", [UserId]), case snmpm_config:user_info(UserId) of {ok, Mod, Data} -> handle_trap( UserId, Mod, - RegType, Target, Domain, Address, + RegType, Target, Domain, Addr, SnmpTrapInfo, Data, State); Error1 -> @@ -2279,7 +2279,7 @@ do_handle_snmp_trap(SnmpTrapInfo, Domain, Address, State) -> {ok, DefUserId, DefMod, DefData} -> handle_agent( DefUserId, DefMod, - Domain, Address, + Domain, Addr, trap, ignore, SnmpTrapInfo, DefData, State); Error2 -> @@ -2287,7 +2287,7 @@ do_handle_snmp_trap(SnmpTrapInfo, Domain, Address, State) -> "failed retreiving the default " "user info handling report from " "~p <~p,~p>: ~n~w~n~w", - [Target, Domain, Address, + [Target, Domain, Addr, Error2, SnmpTrapInfo]) end; Error3 -> @@ -2299,7 +2299,7 @@ do_handle_snmp_trap(SnmpTrapInfo, Domain, Address, State) -> "user ~p, handling trap: " "~n Error: ~w" "~n Trap info: ~w", - [Target, Domain, Address, UserId, + [Target, Domain, Addr, UserId, Error3, SnmpTrapInfo]) end end; @@ -2307,12 +2307,12 @@ do_handle_snmp_trap(SnmpTrapInfo, Domain, Address, State) -> Error4 -> %% Unknown agent, pass it on to the default user ?vlog("[trap] failed retreiving user id for agent <~p,~p>: " - "~n ~p", [Domain, Address, Error4]), + "~n ~p", [Domain, Addr, Error4]), case snmpm_config:user_info() of {ok, DefUserId, DefMod, DefData} -> handle_agent( DefUserId, DefMod, - Domain, Address, + Domain, Addr, trap, ignore, SnmpTrapInfo, DefData, State); Error5 -> @@ -2320,21 +2320,21 @@ do_handle_snmp_trap(SnmpTrapInfo, Domain, Address, State) -> "failed retreiving " "the default user info handling trap from " "<~p,~p>: ~n~w~n~w", - [Domain, Address, Error5, SnmpTrapInfo]) + [Domain, Addr, Error5, SnmpTrapInfo]) end end, ok. handle_trap( - UserId, Mod, RegType, Target, Domain, Address, SnmpTrapInfo, Data, State) -> + UserId, Mod, RegType, Target, Domain, Addr, SnmpTrapInfo, Data, State) -> ?vtrace("handle_trap -> entry with" "~n UserId: ~p" "~n Mod: ~p", [UserId, Mod]), F = fun() -> do_handle_trap( UserId, Mod, - RegType, Target, Domain, Address, + RegType, Target, Domain, Addr, SnmpTrapInfo, Data, State) end, handle_callback(F), @@ -2342,7 +2342,7 @@ handle_trap( do_handle_trap( - UserId, Mod, RegType, Target, Domain, Address, SnmpTrapInfo, Data, _State) -> + UserId, Mod, RegType, Target, Domain, Addr, SnmpTrapInfo, Data, _State) -> ?vdebug("do_handle_trap -> entry with" "~n UserId: ~p", [UserId]), {HandleTrap, CallbackArgs} = @@ -2351,7 +2351,7 @@ do_handle_trap( {fun() -> Mod:handle_trap(Target, SnmpTrapInfo, Data) end, [Target, SnmpTrapInfo, Data]}; addr_port -> - {Ip, Port} = Address, + {Ip, Port} = Addr, {fun() -> Mod:handle_trap(Ip, Port, SnmpTrapInfo, Data) end, [Ip, Port, SnmpTrapInfo, Data]} end, @@ -2361,10 +2361,10 @@ do_handle_trap( ?vtrace("do_handle_trap -> register: " "~n UserId2: ~p" "~n Config: ~p", [UserId2, Config]), - Target2 = mk_target_name(Domain, Address, Config), + Target2 = mk_target_name(Domain, Addr, Config), Config2 = [{reg_type, target_name}, - {tdomain, Domain}, {taddress, Address} | Config], + {tdomain, Domain}, {taddress, Addr} | Config], case snmpm_config:register_agent(UserId2, Target2, Config2) of ok -> ok; @@ -2372,7 +2372,7 @@ do_handle_trap( error_msg("failed registering agent " "handling trap " "<~p,~p>: ~n~w", - [Domain, Address, Reason]), + [Domain, Addr, Reason]), ok end; {register, UserId2, Target2, Config} -> @@ -2390,19 +2390,19 @@ do_handle_trap( error_msg("failed registering agent " "handling trap " "~p <~p,~p>: ~n~w", - [Target2, Domain, Address, Reason]), + [Target2, Domain, Addr, Reason]), reply end; unregister -> ?vtrace("do_handle_trap -> unregister", []), - case snmpm_config:unregister_agent(UserId, Domain, Address) of + case snmpm_config:unregister_agent(UserId, Domain, Addr) of ok -> ok; {error, Reason} -> error_msg("failed unregistering agent " "handling trap " "<~p,~p>: ~n~w", - [Domain, Address, Reason]), + [Domain, Addr, Reason]), ok end; ignore -> @@ -2423,16 +2423,16 @@ handle_snmp_inform( Ref, #pdu{error_status = EStatus, error_index = EIndex, - varbinds = Varbinds} = Pdu, Domain, Address, State) -> + varbinds = Varbinds} = Pdu, Domain, Addr, State) -> ?vtrace("handle_snmp_inform -> entry with~n" " Domain: ~p~n" - " Address: ~p~n" - " Pdu: ~p", [Domain, Address, Pdu]), + " Addr: ~p~n" + " Pdu: ~p", [Domain, Addr, Pdu]), Varbinds2 = fix_vbs_BITS(Varbinds), SnmpInform = {EStatus, EIndex, Varbinds2}, - case snmpm_config:get_agent_user_info(Domain, Address) of + case snmpm_config:get_agent_user_info(Domain, Addr) of {ok, UserId, Target, RegType} -> case snmpm_config:user_info(UserId) of {ok, Mod, Data} -> @@ -2441,7 +2441,7 @@ handle_snmp_inform( "~n Mod: ~p", [UserId, Mod]), handle_inform( UserId, Mod, Ref, - RegType, Target, Domain, Address, + RegType, Target, Domain, Addr, SnmpInform, Data, State); Error1 -> %% User no longer exists, unregister agent @@ -2455,14 +2455,14 @@ handle_snmp_inform( {ok, DefUserId, DefMod, DefData} -> handle_agent( DefUserId, DefMod, - Domain, Address, + Domain, Addr, inform, Ref, SnmpInform, DefData, State); Error2 -> error_msg("failed retreiving the default " "user info handling inform from " "~p <~p,~p>: ~n~w~n~w", - [Target, Domain, Address, + [Target, Domain, Addr, Error2, Pdu]) end; Error3 -> @@ -2473,7 +2473,7 @@ handle_snmp_inform( "user ~p, handling inform: " "~n Error: ~w" "~n Pdu: ~w", - [Target, Domain, Address, UserId, + [Target, Domain, Addr, UserId, Error3, Pdu]) end end; @@ -2481,38 +2481,38 @@ handle_snmp_inform( Error4 -> %% Unknown agent, pass it on to the default user ?vlog("[inform] failed retreiving user id for agent <~p,~p>: " - "~n ~p", [Domain, Address, Error4]), + "~n ~p", [Domain, Addr, Error4]), case snmpm_config:user_info() of {ok, DefUserId, DefMod, DefData} -> handle_agent( DefUserId, DefMod, - Domain, Address, + Domain, Addr, inform, Ref, SnmpInform, DefData, State); Error5 -> error_msg("failed retreiving " "the default user info handling inform from " "<~p,~p>: ~n~w~n~w", - [Domain, Address, Error5, Pdu]) + [Domain, Addr, Error5, Pdu]) end end, ok; -handle_snmp_inform(_Ref, CrapInform, Domain, Address, _State) -> +handle_snmp_inform(_Ref, CrapInform, Domain, Addr, _State) -> error_msg("received crap (snmp) inform from ~w:~w =>" - "~p", [Domain, Address, CrapInform]), + "~p", [Domain, Addr, CrapInform]), ok. handle_inform( UserId, Mod, Ref, - RegType, Target, Domain, Address, SnmpInform, Data, State) -> + RegType, Target, Domain, Addr, SnmpInform, Data, State) -> ?vtrace("handle_inform -> entry with" "~n UserId: ~p" "~n Mod: ~p", [UserId, Mod]), F = fun() -> do_handle_inform( UserId, Mod, Ref, - RegType, Target, Domain, Address, SnmpInform, + RegType, Target, Domain, Addr, SnmpInform, Data, State) end, handle_callback(F), @@ -2520,7 +2520,7 @@ handle_inform( do_handle_inform( UserId, Mod, Ref, - RegType, Target, Domain, Address, SnmpInform, Data, State) -> + RegType, Target, Domain, Addr, SnmpInform, Data, State) -> ?vdebug("do_handle_inform -> entry with" "~n UserId: ~p", [UserId]), {HandleInform, CallbackArgs} = @@ -2529,7 +2529,7 @@ do_handle_inform( {fun() -> Mod:handle_inform(Target, SnmpInform, Data) end, [Target, SnmpInform, Data]}; addr_port -> - {Ip, Port} = Address, + {Ip, Port} = Addr, {fun() -> Mod:handle_inform(Ip, Port, SnmpInform, Data) end, [Ip, Port, SnmpInform, Data]} end, @@ -2542,11 +2542,11 @@ do_handle_inform( "~n Config: ~p", [UserId2, Config]), %% The only user which would do this is the %% default user - Target2 = mk_target_name(Domain, Address, Config), + Target2 = mk_target_name(Domain, Addr, Config), Config2 = [{reg_type, target_name} | ensure_present( - [{tdomain, Domain}, {taddress, Address}], Config)], + [{tdomain, Domain}, {taddress, Addr}], Config)], case snmpm_config:register_agent(UserId2, Target2, Config2) of ok -> reply; @@ -2554,7 +2554,7 @@ do_handle_inform( error_msg("failed registering agent " "handling inform " "~p <~p,~p>: ~n~w", - [Target2, Domain, Address, Reason]), + [Target2, Domain, Addr, Reason]), reply end; @@ -2573,21 +2573,21 @@ do_handle_inform( error_msg("failed registering agent " "handling inform " "~p <~p,~p>: ~n~w", - [Target2, Domain, Address, Reason]), + [Target2, Domain, Addr, Reason]), reply end; unregister -> ?vtrace("do_handle_inform -> unregister", []), case snmpm_config:unregister_agent( - UserId, Domain, Address) of + UserId, Domain, Addr) of ok -> reply; {error, Reason} -> error_msg("failed unregistering agent " "handling inform " "<~p,~p>: ~n~w", - [Domain, Address, Reason]), + [Domain, Addr, Reason]), reply end; @@ -2610,34 +2610,34 @@ do_handle_inform( reply end, - handle_inform_response(Rep, Ref, Domain, Address, State), + handle_inform_response(Rep, Ref, Domain, Addr, State), ok. -handle_inform_response(_, ignore, _Domain, _Address, _State) -> +handle_inform_response(_, ignore, _Domain, _Addr, _State) -> ignore; -handle_inform_response(no_reply, _Ref, _Domain, _Address, _State) -> +handle_inform_response(no_reply, _Ref, _Domain, _Addr, _State) -> no_reply; handle_inform_response( - _, Ref, Domain, Address, + _, Ref, Domain, Addr, #state{net_if = Pid, net_if_mod = Mod}) -> ?vdebug("handle_inform -> response", []), - (catch Mod:inform_response(Pid, Ref, Domain, Address)). + (catch Mod:inform_response(Pid, Ref, Domain, Addr)). handle_snmp_report( #pdu{error_status = EStatus, error_index = EIndex, varbinds = Varbinds} = Pdu, - Domain, Address, State) -> + Domain, Addr, State) -> ?vtrace("handle_snmp_report -> entry with~n" " Domain: ~p~n" - " Address: ~p~n" - " Pdu: ~p", [Domain, Address, Pdu]), + " Addr: ~p~n" + " Pdu: ~p", [Domain, Addr, Pdu]), Varbinds2 = fix_vbs_BITS(Varbinds), SnmpReport = {EStatus, EIndex, Varbinds2}, - case snmpm_config:get_agent_user_info(Domain, Address) of + case snmpm_config:get_agent_user_info(Domain, Addr) of {ok, UserId, Target, RegType} -> case snmpm_config:user_info(UserId) of {ok, Mod, Data} -> @@ -2647,7 +2647,7 @@ handle_snmp_report( "~n ~p" "~n ~p", [UserId, Mod, Target, SnmpReport]), handle_report(UserId, Mod, - RegType, Target, Domain, Address, + RegType, Target, Domain, Addr, SnmpReport, Data, State); Error1 -> %% User no longer exists, unregister agent @@ -2660,7 +2660,7 @@ handle_snmp_report( case snmpm_config:user_info() of {ok, DefUserId, DefMod, DefData} -> handle_agent(DefUserId, DefMod, - Domain, Address, + Domain, Addr, report, ignore, SnmpReport, DefData, State); @@ -2668,7 +2668,7 @@ handle_snmp_report( error_msg("failed retreiving the default " "user info handling report from " "~p <~p,~p>: ~n~w~n~w", - [Target, Domain, Address, + [Target, Domain, Addr, Error2, Pdu]) end; Error3 -> @@ -2679,7 +2679,7 @@ handle_snmp_report( "user ~p, handling report: " "~n Error: ~w" "~n Report: ~w", - [Target, Domain, Address, UserId, + [Target, Domain, Addr, UserId, Error3, Pdu]) end end; @@ -2687,25 +2687,25 @@ handle_snmp_report( Error4 -> %% Unknown agent, pass it on to the default user ?vlog("[report] failed retreiving user id for agent <~p,~p>: " - "~n ~p", [Domain, Address, Error4]), + "~n ~p", [Domain, Addr, Error4]), case snmpm_config:user_info() of {ok, DefUserId, DefMod, DefData} -> handle_agent(DefUserId, DefMod, - Domain, Address, + Domain, Addr, report, ignore, SnmpReport, DefData, State); Error5 -> error_msg("failed retreiving " "the default user info handling report from " "<~p,~p>: ~n~w~n~w", - [Domain, Address, Error5, Pdu]) + [Domain, Addr, Error5, Pdu]) end end, ok; -handle_snmp_report(CrapReport, Domain, Address, _State) -> +handle_snmp_report(CrapReport, Domain, Addr, _State) -> error_msg("received crap (snmp) report from ~w:~w =>" - "~p", [Domain, Address, CrapReport]), + "~p", [Domain, Addr, CrapReport]), ok. %% This could be from a failed get-request, so we might have a user @@ -2719,14 +2719,14 @@ handle_snmp_report( error_index = EIndex, varbinds = Varbinds} = Pdu, {ReportReason, Info} = Rep, - Domain, Address, State) when is_integer(ReqId) -> + Domain, Addr, State) when is_integer(ReqId) -> ?vtrace("handle_snmp_report -> entry with~n" " Domain: ~p~n" - " Address: ~p~n" + " Addr: ~p~n" " ReqId: ~p~n" " Rep: ~p~n" - " Pdu: ~p", [Domain, Address, ReqId, Rep, Pdu]), + " Pdu: ~p", [Domain, Addr, ReqId, Rep, Pdu]), Varbinds2 = fix_vbs_BITS(Varbinds), SnmpReport = {EStatus, EIndex, Varbinds2}, @@ -2771,7 +2771,7 @@ handle_snmp_report( %% Either not a sync request or no such request. Either %% way, this is error info, so handle it as such. - case snmpm_config:get_agent_user_id(Domain, Address) of + case snmpm_config:get_agent_user_id(Domain, Addr) of {ok, UserId} -> case snmpm_config:user_info(UserId) of {ok, Mod, Data} -> @@ -2795,7 +2795,7 @@ handle_snmp_report( "default user " "info handling report from " "<~p,~p>: ~n~w~n~w~n~w", - [Domain, Address, Error, + [Domain, Addr, Error, ReqId, Reason]) end end; @@ -2803,7 +2803,7 @@ handle_snmp_report( %% Unknown agent, pass it on to the default user ?vlog("[report] failed retreiving user id for " "agent <~p,~p>: " - "~n ~p", [Domain, Address, Error]), + "~n ~p", [Domain, Addr, Error]), case snmpm_config:user_info() of {ok, DefUserId, DefMod, DefData} -> handle_error(DefUserId, DefMod, Reason, ReqId, @@ -2813,35 +2813,35 @@ handle_snmp_report( "the default user info handling " "report from " "<~p,~p>: ~n~w~n~w~n~w", - [Domain, Address, Error, ReqId, Reason]) + [Domain, Addr, Error, ReqId, Reason]) end end end, ok; -handle_snmp_report(CrapReqId, CrapReport, CrapInfo, Domain, Address, _State) -> +handle_snmp_report(CrapReqId, CrapReport, CrapInfo, Domain, Addr, _State) -> error_msg( "received crap (snmp) report from ~w:~w =>" "~n~p~n~p~n~p", - [Domain, Address, CrapReqId, CrapReport, CrapInfo]), + [Domain, Addr, CrapReqId, CrapReport, CrapInfo]), ok. -handle_report(UserId, Mod, RegType, Target, Domain, Address, +handle_report(UserId, Mod, RegType, Target, Domain, Addr, SnmpReport, Data, State) -> ?vtrace("handle_report -> entry with" "~n UserId: ~p" "~n Mod: ~p", [UserId, Mod]), F = fun() -> do_handle_report( - UserId, Mod, RegType, Target, Domain, Address, + UserId, Mod, RegType, Target, Domain, Addr, SnmpReport, Data, State) end, handle_callback(F), ok. do_handle_report( - UserId, Mod, RegType, Target, Domain, Address, + UserId, Mod, RegType, Target, Domain, Addr, SnmpReport, Data, _State) -> ?vdebug("do_handle_report -> entry with" "~n UserId: ~p", [UserId]), @@ -2851,7 +2851,7 @@ do_handle_report( {fun() -> Mod:handle_report(Target, SnmpReport, Data) end, [Target, SnmpReport, Data]}; addr_port -> - {Ip, Port} = Address, + {Ip, Port} = Addr, {fun() -> Mod:handle_report(Ip, Port, SnmpReport, Data) end, [Ip, Port, SnmpReport, Data]} end, @@ -2863,10 +2863,10 @@ do_handle_report( "~n Config: ~p", [UserId2, Config]), %% The only user which would do this is the %% default user - Target2 = mk_target_name(Domain, Address, Config), + Target2 = mk_target_name(Domain, Addr, Config), Config2 = [{reg_type, target_name}, - {tdomain, Domain}, {taddress, Address} | Config], + {tdomain, Domain}, {taddress, Addr} | Config], case snmpm_config:register_agent(UserId2, Target2, Config2) of ok -> ok; @@ -2874,7 +2874,7 @@ do_handle_report( error_msg("failed registering agent " "handling report " "<~p,~p>: ~n~w", - [Domain, Address, Reason]), + [Domain, Addr, Reason]), ok end; @@ -2893,20 +2893,20 @@ do_handle_report( error_msg("failed registering agent " "handling report " "~p <~p,~p>: ~n~w", - [Target2, Domain, Address, Reason]), + [Target2, Domain, Addr, Reason]), reply end; unregister -> ?vtrace("do_handle_trap -> unregister", []), - case snmpm_config:unregister_agent(UserId, Domain, Address) of + case snmpm_config:unregister_agent(UserId, Domain, Addr) of ok -> ok; {error, Reason} -> error_msg("failed unregistering agent " "handling report " "<~p,~p>: ~n~w", - [Domain, Address, Reason]), + [Domain, Addr, Reason]), ok end; @@ -3044,7 +3044,7 @@ do_gc(Key, Now) -> %% %%---------------------------------------------------------------------- -send_get_request(Oids, Vsn, MsgData, Domain, Address, ExtraInfo, +send_get_request(Oids, Vsn, MsgData, Domain, Addr, ExtraInfo, #state{net_if = NetIf, net_if_mod = Mod, mini_mib = MiniMIB}) -> @@ -3056,37 +3056,37 @@ send_get_request(Oids, Vsn, MsgData, Domain, Address, ExtraInfo, " Vsn: ~p~n" " MsgData: ~p~n" " Domain: ~p~n" - " Address: ~p~n", - [Mod, NetIf, Pdu, Vsn, MsgData, Domain, Address]), + " Addr: ~p", + [Mod, NetIf, Pdu, Vsn, MsgData, Domain, Addr]), Res = (catch Mod:send_pdu(NetIf, Pdu, Vsn, MsgData, - Domain, Address, ExtraInfo)), + Domain, Addr, ExtraInfo)), ?vtrace("send_get_request -> send result:" "~n ~p", [Res]), Pdu#pdu.request_id. -send_get_next_request(Oids, Vsn, MsgData, Domain, Address, ExtraInfo, +send_get_next_request(Oids, Vsn, MsgData, Domain, Addr, 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, Domain, Address, ExtraInfo), + Mod:send_pdu(NetIf, Pdu, Vsn, MsgData, Domain, Addr, ExtraInfo), Pdu#pdu.request_id. -send_get_bulk_request(Oids, Vsn, MsgData, Domain, Address, +send_get_bulk_request(Oids, Vsn, MsgData, Domain, Addr, 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, Domain, Address, ExtraInfo), + Mod:send_pdu(NetIf, Pdu, Vsn, MsgData, Domain, Addr, ExtraInfo), Pdu#pdu.request_id. -send_set_request(VarsAndVals, Vsn, MsgData, Domain, Address, ExtraInfo, +send_set_request(VarsAndVals, Vsn, MsgData, Domain, Addr, 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, Domain, Address, ExtraInfo), + Mod:send_pdu(NetIf, Pdu, Vsn, MsgData, Domain, Addr, ExtraInfo), Pdu#pdu.request_id. %% send_discovery(Vsn, MsgData, Addr, Port, ExtraInfo, @@ -3322,9 +3322,9 @@ agent_data(TargetName, SendOpts) -> {Comm, SecModel} end, Domain = agent_data_item(tdomain, TargetName), - Address = agent_data_item(taddress, TargetName), + Addr = agent_data_item(taddress, TargetName), RegType = agent_data_item(reg_type, TargetName), - {ok, RegType, Domain, Address, version(Version), MsgData}; + {ok, RegType, Domain, Addr, version(Version), MsgData}; Error -> Error end. @@ -3471,8 +3471,8 @@ t() -> {A,B,C} = erlang:now(), A*1000000000+B*1000+(C div 1000). -mk_target_name(Domain, Address, Config) -> - snmpm_config:mk_target_name(Domain, Address, Config). +mk_target_name(Domain, Addr, Config) -> + snmpm_config:mk_target_name(Domain, Addr, Config). default_agent_config() -> case snmpm_config:agent_info() of diff --git a/lib/snmp/src/misc/snmp_conf.erl b/lib/snmp/src/misc/snmp_conf.erl index ea4686c91a..82cbf42e35 100644 --- a/lib/snmp/src/misc/snmp_conf.erl +++ b/lib/snmp/src/misc/snmp_conf.erl @@ -508,6 +508,8 @@ tdomain_to_family(transportDomainUdpIpv4) -> inet; tdomain_to_family(transportDomainUdpIpv6) -> inet6; +tdomain_to_family(?snmpUDPDomain) -> + inet; tdomain_to_family(?transportDomainUdpIpv4) -> inet; tdomain_to_family(?transportDomainUdpIpv6) -> diff --git a/lib/snmp/src/misc/snmp_config.erl b/lib/snmp/src/misc/snmp_config.erl index 68d4aee97d..38e248c326 100644 --- a/lib/snmp/src/misc/snmp_config.erl +++ b/lib/snmp/src/misc/snmp_config.erl @@ -2107,10 +2107,19 @@ write_manager_snmp_conf(Dir, IP, Port, MMS, EngineID) -> "%% {max_message_size, 484}.\n" "%%\n\n", Hdr = header() ++ Comment, - Conf = [{port, Port}, - {address, IP}, - {engine_id, EngineID}, - {max_message_size, MMS}], + Conf = + case Port of + {Addr, P} when is_integer(P), is_atom(IP) -> + Domain = IP, + [{domain, Domain}, + {port, P}, + {address, Addr}]; + _ when is_integer(Port) -> + [{port, Port}, + {address, IP}] + end ++ + [{engine_id, EngineID}, + {max_message_size, MMS}], write_manager_config(Dir, Hdr, Conf). write_manager_config(Dir, Hdr, Conf) -> diff --git a/lib/snmp/test/snmp_manager_test.erl b/lib/snmp/test/snmp_manager_test.erl index 3e152e6ad4..685c4dc9be 100644 --- a/lib/snmp/test/snmp_manager_test.erl +++ b/lib/snmp/test/snmp_manager_test.erl @@ -244,6 +244,7 @@ init_per_testcase2(Case, Config) -> Family = proplists:get_value(ipfamily, Config, inet), Conf = [{watchdog, ?WD_START(?MINS(5))}, + {ipfamily, Family}, {ip, ?LOCALHOST(Family)}, {case_top_dir, CaseTopDir}, {agent_dir, AgTopDir}, @@ -413,7 +414,8 @@ all() -> {group, event_tests_mt}, discovery, {group, tickets}, - {group, ipv6} + {group, ipv6}, + {group, ipv6_mt} ]. groups() -> @@ -549,13 +551,18 @@ groups() -> otp8395_1 ] }, - {ipv6, [], + {ipv6, [], + [ + simple_sync_get3, + inform1 + ] + }, + {ipv6_mt, [], [ simple_sync_get3, inform1 ] } - ]. @@ -567,6 +574,8 @@ init_per_group(event_tests_mt = GroupName, Config) -> snmp_test_lib:init_group_top_dir( GroupName, [{manager_net_if_module, snmpm_net_if_mt} | Config]); +init_per_group(ipv6_mt, Config) -> + init_per_group(ipv6, [{manager_net_if_module, snmpm_net_if_mt} | Config]); init_per_group(ipv6 = GroupName, Config) -> case ct:require(ipv6_hosts) of ok -> @@ -5767,12 +5776,24 @@ fin_mgr_user(Conf) -> init_mgr_user_data1(Conf) -> Node = ?config(manager_node, Conf), TargetName = ?config(manager_agent_target_name, Conf), - Addr = ?config(ip, Conf), + IpFamily = ?config(ipfamily, Conf), + Ip = ?config(ip, Conf), Port = ?AGENT_PORT, - ?line ok = mgr_user_register_agent(Node, TargetName, - [{address, Addr}, - {port, Port}, - {engine_id, "agentEngine"}]), + ?line ok = + case IpFamily of + inet -> + mgr_user_register_agent( + Node, TargetName, + [{address, Ip}, + {port, Port}, + {engine_id, "agentEngine"}]); + inet6 -> + mgr_user_register_agent( + Node, TargetName, + [{tdomain, transportDomainUdpIpv6}, + {taddress, {Ip, Port}}, + {engine_id, "agentEngine"}]) + end, _Agents = mgr_user_which_own_agents(Node), ?DBG("Own agents: ~p", [_Agents]), @@ -5797,12 +5818,24 @@ init_mgr_user_data2(Conf) -> "~n Conf: ~p", [Conf]), Node = ?config(manager_node, Conf), TargetName = ?config(manager_agent_target_name, Conf), - Addr = ?config(ip, Conf), + IpFamily = ?config(ipfamily, Conf), + Ip = ?config(ip, Conf), Port = ?AGENT_PORT, - ?line ok = mgr_user_register_agent(Node, TargetName, - [{address, Addr}, - {port, Port}, - {engine_id, "agentEngine"}]), + ?line ok = + case IpFamily of + inet -> + mgr_user_register_agent( + Node, TargetName, + [{address, Ip}, + {port, Port}, + {engine_id, "agentEngine"}]); + inet6 -> + mgr_user_register_agent( + Node, TargetName, + [{tdomain, transportDomainUdpIpv6}, + {taddress, {Ip, Port}}, + {engine_id, "agentEngine"}]) + end, _Agents = mgr_user_which_own_agents(Node), ?DBG("Own agents: ~p", [_Agents]), @@ -6199,10 +6232,16 @@ await_stopped(Node, N) -> write_manager_config(Config) -> Dir = ?config(manager_conf_dir, Config), - Ip = ?config(ip, Config), - Addr = tuple_to_list(Ip), - snmp_config:write_manager_snmp_files(Dir, Addr, ?MGR_PORT, - ?MGR_MMS, ?MGR_ENGINE_ID, [], [], []). + Ip = tuple_to_list(?config(ip, Config)), + {Addr, Port} = + case ?config(ipfamily, Config) of + inet -> + {Ip, ?MGR_PORT}; + inet6 -> + {transportDomainUdpIpv6, {Ip, ?MGR_PORT}} + end, + snmp_config:write_manager_snmp_files( + Dir, Addr, Port, ?MGR_MMS, ?MGR_ENGINE_ID, [], [], []). write_manager_conf(Dir) -> Port = "5000", @@ -6231,25 +6270,27 @@ write_manager_conf(Dir, Str) -> write_agent_config(Vsns, Conf) -> Dir = ?config(agent_conf_dir, Conf), - Ip = ?config(ip, Conf), - ?line Addr = tuple_to_list(Ip), - ?line ok = write_agent_config_files(Dir, Vsns, Addr), + ?line Ip = tuple_to_list(?config(ip, Conf)), + ?line Domain = + case ?config(ipfamily, Conf) of + inet -> + snmpUDPDomain; + inet6 -> + transportDomainUdpIpv6 + end, + ?line ok = write_agent_config_files(Dir, Vsns, Domain, Ip), ?line ok = update_agent_usm(Vsns, Dir), ?line ok = update_agent_community(Vsns, Dir), ?line ok = update_agent_vacm(Vsns, Dir), - ?line ok = write_agent_target_addr_conf(Dir, Addr, Vsns), + ?line ok = write_agent_target_addr_conf(Dir, Domain, Ip, Vsns), ?line ok = write_agent_target_params_conf(Dir, Vsns), ?line ok = write_agent_notify_conf(Dir), ok. -write_agent_config_files(Dir, Vsns, Addr) -> - snmp_config:write_agent_snmp_files(Dir, Vsns, - Addr, ?MGR_PORT, - Addr, ?AGENT_PORT, - "mgr-test", "trap", - none, "", - ?AGENT_ENGINE_ID, - ?AGENT_MMS). +write_agent_config_files(Dir, Vsns, Domain, Ip) -> + snmp_config:write_agent_snmp_files( + Dir, Vsns, Domain, {Ip, ?MGR_PORT}, {Ip, ?AGENT_PORT}, "mgr-test", + trap, none, "", ?AGENT_ENGINE_ID, ?AGENT_MMS). update_agent_usm(Vsns, Dir) -> case lists:member(v3, Vsns) of @@ -6317,9 +6358,9 @@ update_agent_vacm(_Vsns, Dir) -> excluded, null}], snmp_config:update_agent_vacm_config(Dir, Conf). -write_agent_target_addr_conf(Dir, Addr, Vsns) -> - snmp_config:write_agent_snmp_target_addr_conf(Dir, Addr, ?MGR_PORT, - 300, 3, Vsns). +write_agent_target_addr_conf(Dir, Domain, Ip, Vsns) -> + snmp_config:write_agent_snmp_target_addr_conf( + Dir, Domain, {Ip, ?MGR_PORT}, 300, 3, Vsns). write_agent_target_params_conf(Dir, Vsns) -> F = fun(v1) -> {"target_v1", v1, v1, "all-rights", noAuthNoPriv}; |