From: SourceForge.net <no...@so...> - 2009-04-09 01:39:52
|
Patches item #2709705, was opened at 2009-03-24 10:56 Message generated for change (Comment added) made by fhew You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=312694&aid=2709705&group_id=12694 Please note that this message will contain a full copy of the comment thread, including the initial issue submission, for this request, not just the latest update. Category: None Group: None Status: Pending Resolution: Accepted Priority: 5 Private: No Submitted By: fhew (fhew) Assigned to: Thomas Anders (tanders) Summary: [PATCH] providing src/target IP address in Perl based agents Initial Comment: This patch provides the ability to get access to the target (and source) IP address in Perl based agents, Although not ideal this patch has been tested on Fedora 8 with v5.6.1 against Net-SNMP v5.4.2.1 Design discussion/limitations: In my custom Perl based agents, I needed to provide the ability to the agent to be able to discriminate between get/set requests coming into different IP addresses that may be assigned to a single machine. (ie. a Network simulator). Although Net-SNMP provides a 'session' structure that is available to agents, the following fields do not appear to be populated: peername, remote_port, localname, local_port. I have to assume that these fields are only (currently) used for out-going sessions and not in-coming session (that I need). Therefore to minimize my patches, I have provided this patch to the NetSNMP-agent-5.0401 code to provide this information under the limited scenario of IP v4 UDP only (the only scenario have have tested). To accomplish this, I access the 'opaque' data called 'transport_data' as in reqinfo->asp->pdu->transport_data Unfortunately, by the time the Net-SNMP code executes the Perl agent, the transport identification, and hence the ability to decode this 'transport_data' is no longer available. (This is why I simply assume it is currently an IPv4 structure.) The correct and better answer would be to: a) enhance Net-SNMP to fill in the peername, remote_port, localname, local_port fields b) provide access to the 'session' structure and its fields in the NetSNMP::agent Since I needed a solution with a minimal amount of effort (upstream changes), I opted for this supplied patch. Note: this patch includes source and documentation changes. ---------------------------------------------------------------------- Comment By: fhew (fhew) Date: 2009-04-08 21:39 Message: w.r.t. the two warning... I got so many warnings when I compiled the latest distribution that I didn't notice the new warnings I introduced. Then can be resolved by changing the two statements identified from: rarg = newSVpv((unsigned char *) ..... to: rarg = newSVpv((const char *) ..... ---------------------------------------------------------------------- Comment By: Thomas Anders (tanders) Date: 2009-04-08 19:25 Message: As for transport-independent options, you may want to consider the approach used in perl/TrapReceiver/TrapReceiver.xs:perl_trapd_handler() that fills "receivedfrom". ---------------------------------------------------------------------- Comment By: Thomas Anders (tanders) Date: 2009-04-08 19:18 Message: Functions renamed and comments added in r17478 and r17479. The XS code triggers a few warnings: agent.xs: In function ‘XS_NetSNMP__agent__netsnmp_agent_request_info_getSourceIp’: agent.xs:1078: warning: pointer targets in passing argument 2 of ‘Perl_newSVpv’ differ in signedness agent.xs: In function ‘XS_NetSNMP__agent__netsnmp_agent_request_info_getDestIp’: agent.xs:1099: warning: pointer targets in passing argument 2 of ‘Perl_newSVpv’ differ in signedness @fhew: would you be willing to look into them? ---------------------------------------------------------------------- Comment By: fhew (fhew) Date: 2009-04-08 17:33 Message: 1/ Regarding subroutine names: Requestor/Target vrs src/dst... Yes, alternate names could be used, but these where what I chose (and documented). I felt that since my motivation/use of this facility was to write a simulator where the Perl application was the 'destination', but yet the subroutine returns the 'intended' target of the request, the name getTargetIp' was more indicative. And hence the converse of 'target' could be 'requestor'. 2/ There is POD. The file 'agent.pm' contains both the changes to the code as well as changes to the pod. ---------------------------------------------------------------------- Comment By: Thomas Anders (tanders) Date: 2009-04-08 11:25 Message: I'm not sure I like the names of the new subroutines (getRequestorIp and getTargetIp). Wouldn't source (src) and destination (d[e]st) be more appropriate than requestor and target? Also, shouldn't there be some minimal POD for these routines? ---------------------------------------------------------------------- Comment By: Dave Shield (dts12) Date: 2009-04-08 10:24 Message: SVN revision 17467 ---------------------------------------------------------------------- Comment By: Dave Shield (dts12) Date: 2009-04-08 10:24 Message: Thanks for the patch! It has been applied to the current development code, and will appear in the next major release of the Net-SNMP package. ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=312694&aid=2709705&group_id=12694 |