Re: Getting listening port number while processing request

Bart Van Assche <[email protected]> Wed, 3 Apr 2024 09:45:54 -0700
Newsgroups gmane.network.net-snmp.devel
Message-ID <[email protected]>
On 4/3/24 02:35, Teus Benschop wrote:
>
> A snmpd was set to listen on 10 ports through multiple entries like 
> “agentaddress tcp:<port>” in the snmpd.conf file.
> It was verified through snmpget that the snmpd listens on all 10 ports.
>
> Function “netsnmp_callback_open” in file 
> snmplib/transports/snmpCallbackDomain.c was patched to write a few 
> debug messages.
>
> It appears that the function “netsnmp_callback_open” is called once.
> It sets the “callback_ss->local_port” to “((netsnmp_callback_info *) 
> callback_tr->data)->callback_num”, which is 1.
> In the handler callback function, the 
> reqinfo->asp->session->local_port is 0 while processing each snmpget.
>
> You wrote "Make sure that session->local_port is set correctly." I 
> studied the code to set this properly, but didn't manage to get the 
> port number set correctly.

I think this is the callchain for registering the ports that the agent 
listens on:

init_master_agent()
   netsnmp_agent_listen_on()
     netsnmp_transport_open_server()
     netsnmp_register_agent_nsap()
       netsnmp_sess_config_transport()
       snmp_add()
         snmp_sess_add_ex()
           transport->f_setup_session()

One possible approach is to implement the .f_setup_session() callback in 
the TCP transport and to make it copy the port information from the 
transport into the session.

Best regards,

Bart.

_______________________________________________
Net-snmp-coders mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/net-snmp-coders