LogoopenSUSE Build Service > Projects
Sign Up | Log In

View File 0423-snmp-Corrected-agent-ATL-logging-of-outgoing-message.patch of Package erlang (Project home:Ledest:erlang:20)

From f21ba51b85e18feec2f4cd408b51c22d7847f635 Mon Sep 17 00:00:00 2001
From: Micael Karlberg <bmk@erlang.org>
Date: Wed, 5 Sep 2018 18:55:40 +0200
Subject: [PATCH 2/5] [snmp] Corrected (agent) ATL logging of outgoing messages

For some outgoing messages (not response) the following
error(s) has been corrected:
* encrypted: logged incorrectly, should have written the v3-header
  and the scoped pdu, but was actually logged as-is (encrypted),
  making conversion impossible.
* un-encrypted: messages was not logged at all.

OTP-15287 (ERIERL-206)
---
 lib/snmp/src/agent/snmpa_net_if.erl | 109 ++++++++++++++++--------------------
 1 file changed, 47 insertions(+), 62 deletions(-)

diff --git a/lib/snmp/src/agent/snmpa_net_if.erl b/lib/snmp/src/agent/snmpa_net_if.erl
index ecf9498ca9..807491bfcb 100644
--- a/lib/snmp/src/agent/snmpa_net_if.erl
+++ b/lib/snmp/src/agent/snmpa_net_if.erl
@@ -872,7 +869,7 @@ handle_reply_pdu(
 						ACMData, LogF)) of
 	{ok, Packet} ->
 	    ?vinfo("time in agent: ~w mysec", [time_in_agent()]),
-	    try maybe_udp_send(S, Transport, To, Packet)
+	    try maybe_udp_send_wo_log(S, Transport, To, Packet)
 	    catch
 		{Reason, Sz} ->
 		    error_msg("Cannot send message "
@@ -1049,46 +1045,36 @@ do_handle_send_pdu(S, Type, Pdu, Addresses) ->
 	      [Sz, Reason, Pdu])
     end.
 
-do_handle_send_pdu1(
-  #state{transports = Transports} = S,
-  Type, Addresses) ->
+do_handle_send_pdu1(S, Type, Addresses) ->
     lists:foreach(
-      fun ({Domain, Address, Packet}) when is_binary(Packet) ->
-	      ?vdebug(
-		 "[~w] sending packet:~n"
-		 "   size: ~p~n"
-		 "   to:   ~p", [Domain, sz(Packet), Address]),
-	      To = {Domain, Address},
-	      case select_transport_from_domain(Domain, Transports) of
-		  false ->
-		      error_msg(
-			"Can not find transport~n"
-			"   size:   ~p~n"
-			"   to:     ~s",
-			[sz(Packet), format_address(To)]);
-		  Transport ->
-		      maybe_udp_send(S, Transport, To, Packet)
-	      end;
-	  ({Domain, Address, {Packet, LogData}}) when is_binary(Packet) ->
-	      ?vdebug(
-		 "[~w] sending encrypted packet:~n"
-		 "   size: ~p~n"
-		 "   to:   ~p", [Domain, sz(Packet), Address]),
-	      To = {Domain, Address},
-	      case select_transport_from_domain(Domain, Transports) of
-		  false ->
-		      error_msg(
-			"Can not find transport~n"
-			"   size:   ~p~n"
-			"   to:     ~s",
-			[sz(Packet), format_address(To)]);
-		  Transport ->
-		      maybe_udp_send(S, Transport, To, Packet, Type, LogData)
-	      end
+      fun ({Domain, Address, Pkg}) when is_binary(Pkg) ->
+	      do_handle_send_pdu2(S, Type, Domain, Address,
+                                  Pkg, Pkg, "");
+	  ({Domain, Address, {Pkg, LogPkg}}) when is_binary(Pkg) ->
+	      do_handle_send_pdu2(S, Type, Domain, Address,
+                                  Pkg, LogPkg, " encrypted")
       end,
       Addresses).
 
-maybe_udp_send(
+do_handle_send_pdu2(#state{transports = Transports} = S,
+                    Type, Domain, Address, Pkg, LogPkg, EncrStr) ->
+    ?vdebug("[~w] sending~s packet:"
+            "~n   size: ~p"
+            "~n   to:   ~p", [Domain, EncrStr, sz(Pkg), Address]),
+    To = {Domain, Address},
+    case select_transport_from_domain(Domain, Transports) of
+	false ->
+	    error_msg("Can not find transport: "
+                      "~n   size: ~p"
+                      "~n   to:   ~s",
+                      [sz(Pkg), format_address(To)]);
+	Transport ->
+	    maybe_udp_send_w_log(S, Transport, To, Pkg, LogPkg, Type)
+    end.
+
+
+%% This function is used when logging has already been done!
+maybe_udp_send_wo_log(
   #state{filter = FilterMod, transports = Transports},
   #transport{socket = Socket},
   To, Packet) ->
@@ -1118,10 +1104,10 @@ maybe_udp_send(
 	    udp_send(Socket, To, Packet)
     end.
 
-maybe_udp_send(
+maybe_udp_send_w_log(
   #state{log = Log, filter = FilterMod, transports = Transports},
   #transport{socket = Socket},
-  To, Packet, Type, _LogData) ->
+  To, Pkg, LogPkg, Type) ->
     {To_1, To_2} = fix_filter_address(Transports, To),
     case
 	try FilterMod:accept_send(To_1, To_2)
@@ -1143,10 +1129,10 @@ maybe_udp_send(
 		_ ->
 		    error_msg(
 		      "FilterMod:accept_send(~p, ~p) returned: ~p",
-		      [To_1,To_2,Other])
+		      [To_1, To_2, Other])
 	    end,
-	    log(Log, Type, Packet, To),
-	    udp_send(Socket, To, Packet)
+	    log(Log, Type, LogPkg, To),
+	    udp_send(Socket, To, Pkg)
     end.
 
 udp_send(Socket, To, B) ->
-- 
2.16.4