Re: Duplicate Traps being sent from a Sub Agent: unhandled PDU in logs

Larry Hayes <[email protected]>
Newsgroups gmane.network.net-snmp.user
Message-ID <CAG3KfNb+UG36GU474rWH3O8Z4-EA7M0F=H7dwVQneN-HLdUTsA@mail.gmail.com>
I tracked this down to probably being a multiple thread issue.
The mail loop which calls the API: agent_check_and_process() is in the main
process.
The call to sendTrap2 is in a thread.

What I see is the sendTrap2 logic is making the request to the snmpd, and
before it can put the request on the isp->requests list
the response is coming back into the main process loop and being process,
but since the isp->requests has not been updated, it becomes an un handled
PDU.
The sendTrap2 logic adds it to the isp->requests list and the request
eventually times out and a second trap is sent, which works correctly
because it is sent
withing the main loop.

So I had to get the sending of the Trap to the main loop of the process.
Which required not calling agent_check_and_process(), but writing my own
select statement and processing the snmp socket FDs in it and opening a
listening socket which the trap thread could
send a message to generate a trap, on the main loop processing.

Hope this helps others, that might run into the same issue.

Larry


On Thu, Mar 15, 2018 at 4:42 PM Larry Hayes <[email protected]> wrote:

> OS: Linux
> Net-snmp version: 5.7.3
>
> I have written a sub agent using the net-snmp library.
> This sub agent opens a web socket(uWs) to a web socket server and receives
> events.
> It takes the events and maps them to traps and calls the net-snmp library
> functions
> to forward the traps to snmpd, which forwards them out port 162.
> # snmpd -Lsd udp:0.0.0.0
> # subAgent  -Dsess_process_packet -d
>
> snmpd   < -- > subAgent  < -- > custom process
>
> Everything was going well until I did a popen() call from my subAgent to
> get the IP of the machine I am running on.
>
> (Maybe a coincidence) but now about 95% of the time, I get duplicate traps
> coming out of the net-snmp library of the subAgent.  If I do  not do the
> popen() then no duplicates are seen.
>
> When I trun on some debugging in the library, I see unhandled PDU, then a
> resend print.
> This seems to be causing the duplicated traps.
>
> Any Idea why the popen() would interfere with the library apis?
> The popen() and library calls are done by a thread of my subAgent.
>
>
>  sess_process_packet: received message id#0 reqid#2035863312 len 28
> {"method":"alertNtfn","params":{"code":1,"alertId":84,"state":"event","name":"CTRLR:1","type":"Configuration
> Update","severity":"info","description":"Configuration
> Update","modIndex":84,"delIndex":0}}
> Coinfiguration Update
> +++++++++++++++++++ popen(): ifconfig eth0 | grep 'inet addr:' | cut -d:
> -f2 | awk '{ print $1}'
> *sess_process_packet: sending message id#290792091 reqid#2035863313 len
> 212*
>
> Sending 212 bytes to Local IPC: /var/agentx/master
> 0000: 01 0C 00 00  53 00 00 00  00 00 00 00  11 CF 58 79
> ....S.........Xy
> 0016: C0 00 00 00  43 00 00 00  04 02 00 00  01 00 00 00
> ....C...........
> 0032: 01 00 00 00  03 00 00 00  00 00 00 00  41 7B 17 00
> ............A{..
> 0048: 06 00 00 00  06 06 00 00  03 00 00 00  01 00 00 00
> ................
> 0064: 01 00 00 00  04 00 00 00  01 00 00 00  00 00 00 00
> ................
> 0080: 05 04 01 00  01 00 00 00  4E 2A 00 00  01 00 00 00
> ........N*......
> 0096: 00 00 00 00  22 00 00 00  04 00 00 00  05 04 00 00
> ...."...........
> 0112: 01 00 00 00  4E 2A 00 00  02 00 00 00  0F 00 00 00
> ....N*..........
> 0128: 00 00 00 00  00 00 00 00  04 00 00 00  05 04 00 00
> ................
> 0144: 01 00 00 00  4E 2A 00 00  02 00 00 00  10 00 00 00
> ....N*..........
> 0160: 00 00 00 00  00 00 00 00  04 00 00 00  05 04 00 00
> ................
> 0176: 01 00 00 00  4E 2A 00 00  02 00 00 00  11 00 00 00
> ....N*..........
> 0192: 00 00 00 00  0C 00 00 00  31 30 2E 32  30 2E 31 39
> ........10.20.19
> 0208: 2E 31 38 0A                                           .18.
>
> sess_process_packet: session 0x88bd048 fd 8 pkt 0x88ea0a0 length 220
>
> Received 220 byte packet from Local IPC: abstract
> 0000: 01 12 00 00  53 00 00 00  00 00 00 00  11 CF 58 79
> ....S.........Xy
> 0016: C8 00 00 00  43 7B 17 00  00 00 00 00  43 00 00 00
> ....C{......C...
> 0032: 04 02 00 00  01 00 00 00  01 00 00 00  03 00 00 00
> ................
> 0048: 00 00 00 00  41 7B 17 00  06 00 00 00  06 06 00 00
> ....A{..........
> 0064: 03 00 00 00  01 00 00 00  01 00 00 00  04 00 00 00
> ................
> 0080: 01 00 00 00  00 00 00 00  05 04 01 00  01 00 00 00
> ................
> 0096: 4E 2A 00 00  01 00 00 00  00 00 00 00  22 00 00 00
> N*.........."...
> 0112: 04 00 00 00  05 04 00 00  01 00 00 00  4E 2A 00 00
> ............N*..
> 0128: 02 00 00 00  0F 00 00 00  00 00 00 00  00 00 00 00
> ................
> 0144: 04 00 00 00  05 04 00 00  01 00 00 00  4E 2A 00 00
> ............N*..
> 0160: 02 00 00 00  10 00 00 00  00 00 00 00  00 00 00 00
> ................
> 0176: 04 00 00 00  05 04 00 00  01 00 00 00  4E 2A 00 00
> ............N*..
> 0192: 02 00 00 00  11 00 00 00  00 00 00 00  0C 00 00 00
> ................
> 0208: 31 30 2E 32  30 2E 31 39  2E 31 38 0A                 10.20.19.18.
>
>
>
>
>
> *sess_process_packet: received message id#0 reqid#2035863313 len
> 220sess_process_packet: unhandled PDUsess_process_packet: resending message
> id#290792092 reqid#2035863313 rp_reqid#2035863313 rp_msgid#290792092 len
> 212*
> Sending 212 bytes to Local IPC: /var/agentx/master
> 0000: 01 0C 00 00  53 00 00 00  00 00 00 00  11 CF 58 79
> ....S.........Xy
> 0016: C0 00 00 00  43 00 00 00  04 02 00 00  01 00 00 00
> ....C...........
> 0032: 01 00 00 00  03 00 00 00  00 00 00 00  41 7B 17 00
> ............A{..
> 0048: 06 00 00 00  06 06 00 00  03 00 00 00  01 00 00 00
> ................
> 0064: 01 00 00 00  04 00 00 00  01 00 00 00  00 00 00 00
> ................
> 0080: 05 04 01 00  01 00 00 00  4E 2A 00 00  01 00 00 00
> ........N*......
> 0096: 00 00 00 00  22 00 00 00  04 00 00 00  05 04 00 00
> ...."...........
> 0112: 01 00 00 00  4E 2A 00 00  02 00 00 00  0F 00 00 00
> ....N*..........
> 0128: 00 00 00 00  00 00 00 00  04 00 00 00  05 04 00 00
> ................
> 0144: 01 00 00 00  4E 2A 00 00  02 00 00 00  10 00 00 00
> ....N*..........
> 0160: 00 00 00 00  00 00 00 00  04 00 00 00  05 04 00 00
> ................
> 0176: 01 00 00 00  4E 2A 00 00  02 00 00 00  11 00 00 00
> ....N*..........
> 0192: 00 00 00 00  0C 00 00 00  31 30 2E 32  30 2E 31 39
> ........10.20.19
> 0208: 2E 31 38 0A                                           .18.
>
> sess_process_packet: sending message id#290792093 reqid#2035863314 len 20
>
> Sending 20 bytes to Local IPC: /var/agentx/master
> 0000: 01 0D 00 00  53 00 00 00  00 00 00 00  12 CF 58 79
> ....S.........Xy
> 0016: 00 00 00 00                                           ....
>
>

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot

_______________________________________________
Net-snmp-users mailing list
[email protected]
Please see the following page to unsubscribe or change other options:
https://lists.sourceforge.net/lists/listinfo/net-snmp-users
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.