Hi, I succeded in sending the Informs from pre-defined ports. I did not finish my implementation, but I want to discuss my intention and varify it is ok.
Design: ------------ I remind you that I wanted the informs to be send from fixed ports so I can configure my Firewall to open these UDP ports only (for Infrom ACKs). I intened to define a range of fixed ports (say 6070-6072, or probably configurable through the snmpd.conf file), and that for each target (In the SnmpTargetMib, that is configured to receive an Inform) the inform would be sent from a specific port. For example: ------------------- for the first target (which receive an Inform) it will be sent from the 6070 port. for the second target (which receive an Inform) it will be sent from the 6071 port. ... (assuming number of target is restricted to the size of the fixed-port range) The implementation: ------------------------------ Files changed: 1) target.c - Add mechanism for assigning client addresses (via the NETSNMP_DS_LIB_CLIENT_ADDR attribute in the DataStore) for each new target session. 2) snmpUDPDomain.c - Comment out a line which overrides the port in NETSNMP_DS_LIB_CLIENT_ADDR and sets it to zero //client_addr.sin_port = 0; Questions: ----------------- 1) What are the implications of commenting out the mentoioned line from snmpUDPDomain.c ? netsnmp_udp_transport(...) ... if (local) { ... } else { client_socket = netsnmp_ds_get_string(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_CLIENT_ADDR); if (client_socket) { struct sockaddr_in client_addr; netsnmp_sockaddr_in( &client_addr, client_socket, 0); //-------------------------- //client_addr.sin_port = 0; // ---------------------------- bind(t->sock, (struct sockaddr *)&client_addr, sizeof(struct sockaddr)); } 2) Does this solution make sense? does it qualify submitting to the official net-snmp version? Thanks, Erez. -----Original Message----- From: Makavy, Erez (Erez) Sent: Sunday, May 20, 2007 3:00 PM To: 'Dave Shield' Cc: net-snmp-coders@lists.sourceforge.net Subject: RE: Sending Informs with fixed source ports I tried binding to the IP address of eth0. The trap is sent but not from my specified port: tcpdump: ------------ 14:56:52.983519 IP 135.64.102.110.32797 > 135.64.102.136.snmptrap: F=ar U=usr1 [|snmp][|snmp] 14:57:11.876272 IP 135.64.102.110.32797 > 135.64.102.136.snmptrap: F=ar U=usr1 [|snmp][|snmp] 14:57:43.656022 IP 135.64.102.110.32797 > 135.64.102.136.snmptrap: F=ar U=usr1 [|snmp][|snmp] 14:57:49.571344 IP 135.64.102.110.32803 > 135.64.102.136.snmptrap: F=ar U=usr1 [|snmp][|snmp] 14:57:49.696096 IP 135.64.102.110.32803 > 135.64.102.136.snmptrap: F=ar U=usr1 [|snmp][|snmp] 14:57:58.590007 IP 135.64.102.110.32803 > 135.64.102.136.snmptrap: F=ar U=usr1 [|snmp][|snmp] snmpd logging: --------------------- netsnmp_udp: recvfrom fd 6 got 39 bytes (from UDP: [135.64.102.136]:1657) Connection from UDP: [135.64.102.136]:1657 netsnmp_udp_getSecName: no com2sec entries send_notifications: starting: pdu=94a2170, vars=0 target_sessions: looking for: inform target_sessions: for: 0=inform target_sessions: found one: inform netsnmp_udp: open remote UDP: [135.64.102.136]:162:41472 netsnmp_sockaddr_in: addr 0xbfdb9db0, peername "135.64.102.110:6666" netsnmp_sockaddr_in: port number suffix :6666 netsnmp_sockaddr_in: IP address netsnmp_sockaddr_in: return { AF_INET, 135.64.102.110:6666 } netsnmp_udp: Binded to client_socket target_sessions: to: UDP: [135.64.102.136]:162 target_sessions: timeout: 1500 -> 1500000 target_sessions: setting SNMP_FLAG_DONT_PROB for snmp_add, and EIDtarget_sessions: looking for: trap target_sessions: for: 0=trap send_notifications: sent 0 notifications send_notifications: starting: pdu=94a2208, vars=94a24f0 target_sessions: looking for: inform target_sessions: for: 0=inform target_sessions: found one: inform send_notifications: checking filters... send_notifications: no matching profile netsnmp_udp: send 168 bytes from 0x94a3870 to UDP: [135.64.102.136]:162 on fd 7 target_sessions: looking for: trap target_sessions: for: 0=trap send_notifications: sent 1 notifications netsnmp_udp: recvfrom fd 7 got 168 bytes (from UDP: [135.64.102.136]:1658) Any ideas? Thanks, Erez. -----Original Message----- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Dave Shield Sent: Saturday, May 19, 2007 12:41 AM To: Makavy, Erez (Erez) Cc: net-snmp-coders@lists.sourceforge.net Subject: Re: Sending Informs with fixed source ports On 08/05/07, Makavy, Erez (Erez) <[EMAIL PROTECTED]> wrote: > I tried adding this line to target.c:get_target_sessoin(): > > netsnmp_ds_set_string(NETSNMP_DS_LIBRARY_ID, > NETSNMP_DS_LIB_CLIENT_ADDR, "localhost:6666"); > I get an error, you can see in the debug logs: > ---------------------------------------------------- > netsnmp_sockaddr_in: addr 0xbfe7c040, peername "localhost:6666" > netsnmp_sockaddr_in: port number suffix :6666 > netsnmp_sockaddr_in: hostname (resolved okay) > netsnmp_sockaddr_in: return { AF_INET, 127.0.0.1:6666 } : > netsnmp_udp: send 165 bytes from 0x8f52d83 to UDP: > [135.64.102.136]:162 on fd 7 > netsnmp_udp: sendto error, rc -1 (errno 22) > snmpd: send_trap: Failure in sendto (Invalid argument) That probably makes sense. I suspect that there may not be a route from the loopback interface to that IP address. In order to send traffic to that system, you'd have to use a source address that's on the same network as either the destination system, or else a suitable gateway. Using "localhost" as the source won't qualify. Dave ------------------------------------------------------------------------- This SF.net email is sponsored by DB2 Express Download DB2 Express C - the FREE version of DB2 express and take control of your XML. No limits. Just data. Click to get it now. http://sourceforge.net/powerbar/db2/ _______________________________________________ Net-snmp-coders mailing list Net-snmp-coders@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/net-snmp-coders