File 7223-snmp-manager-Use-EngineID-and-Address-when-checkiing.patch of Package erlang

From e223d7cff0e186aa7da0604da3f6c332761c2167 Mon Sep 17 00:00:00 2001
From: Micael Karlberg <bmk@erlang.org>
Date: Thu, 27 Mar 2025 08:54:34 +0100
Subject: [PATCH 3/3] [snmp|manager] Use EngineID *and* Address when checkiing
 if known

ERIERL-1207
---
 lib/snmp/src/manager/snmpm_mpd.erl | 22 ++++++++++++++++------
 1 file changed, 16 insertions(+), 6 deletions(-)

diff --git a/lib/snmp/src/manager/snmpm_mpd.erl b/lib/snmp/src/manager/snmpm_mpd.erl
index ffda751da3..7e50c140fc 100644
--- a/lib/snmp/src/manager/snmpm_mpd.erl
+++ b/lib/snmp/src/manager/snmpm_mpd.erl
@@ -495,8 +495,7 @@ process_v3_msg(NoteStore, Msg, Hdr, Data, Address, Log) ->
 		    %% handle CtxEngineID to ourselves
 		    %% Check that we actually know of an agent with this
 		    %% CtxEngineID and Address
-		    %% case is_known_engine_id(CtxEngineID, Address) of
-                    case is_known_engine_id(CtxEngineID) of
+		    case is_known_engine_id(CtxEngineID, Address) of
 			true ->
 			    ?vtrace("and the agent EngineID (~p) "
 				    "is know to us", [CtxEngineID]),
@@ -1088,10 +1087,21 @@ get_engine_id() ->
 get_agent_engine_id(Name) ->
     snmpm_config:get_agent_engine_id(Name).
 
-%% is_known_engine_id(EngineID, {Addr, Port}) ->
-%%     snmpm_config:is_known_engine_id(EngineID, Addr, Port).
-is_known_engine_id(EngineID) ->
-    snmpm_config:is_known_engine_id(EngineID).
+%% We cannot include 'Port' in this check since agents
+%% can use ephemeral ports (random ports) for traps/notifications.
+is_known_engine_id(EngineID, {Addr, _Port}) ->
+    Agents = snmpm_config:which_agents(engine_id, EngineID),
+    is_known_engine_id2(Agents, Addr).
+
+is_known_engine_id2([], _Addr) ->
+    false;
+is_known_engine_id2([TargetName|Agents], Addr) ->
+    case snmpm_config:agent_info(TargetName, address) of
+        {ok, Addr} ->
+            true;
+        _ ->
+            is_known_engine_id2(Agents, Addr)
+    end.
 
 
 %%-----------------------------------------------------------------
-- 
2.43.0

openSUSE Build Service is sponsored by