etingof / snmpfwd

SNMP Proxy Forwarder
http://snmplabs.com/snmpfwd/
BSD 2-Clause "Simplified" License
67 stars 18 forks source link

Transparent proxy client failing to expand macro #38

Open pshemk opened 5 years ago

pshemk commented 5 years ago

I'm building a transparent proxy setup, where a number of appliances send their traps to snmpfwd, which in turn is supposed to forward them to our NMS, spoofing the source IPs to be those of the appliances (so from NMS perspective they appear to arrive directly from the appliances). I have the actual forwarding working fine, but when I try to apply the transparent proxy configuration from here.

with client.conf setup like this:

peers-group {
  snmp-engine-id: 0x0102030405070809

  snmp-transport-domain: 1.3.6.1.6.1.1.1
  #snmp-bind-address: 0.0.0.0
  snmp-transport-options: transparent-proxy

  # spoof source IP to the IP of the SNMP manager talking to the server part
  snmp-bind-address: ${snmp-peer-address}

  # time out SNMP request in 1 second
  snmp-peer-timeout: 100
  snmp-peer-retries: 0

  snmp-community-name: public
  snmp-security-name: public
  snmp-security-model: 2
  snmp-security-level: 1

  snmp-peer-address: 172.27.196.227:162
  snmp-peer-id: nms-1
}

And server.conf like this:

snmp-credentials-group {
  snmp-transport-domain: 1.3.6.1.6.1.1.100
  snmp-bind-address: 0.0.0.0:1162
  snmp-transport-options: transparent-proxy

  snmp-engine-id: 0x0102030405070809

  snmp-community-name: public
  snmp-security-name: public

  snmp-security-model: 2
  snmp-security-level: 1

  snmp-credentials-id: snmp-credentials
}

after the client process receives a packet from the server and tries to send it - it dies with:

2019-05-03 02:40:29,830 ERROR poll error: Traceback (most recent call last):
; File "/usr/local/lib/python3.6/site-packages/pysnmp/carrier/asyncore/dispatch.py", line 46, in runDispatcher
use_poll=True, map=self.__sockMap, count=1)
; File "/usr/local/lib/python3.6/asyncore.py", line 207, in loop
poll_fun(timeout, map)
; File "/usr/local/lib/python3.6/asyncore.py", line 188, in poll2
readwrite(obj, flags)
; File "/usr/local/lib/python3.6/asyncore.py", line 123, in readwrite
obj.handle_error()
; File "/usr/local/lib/python3.6/asyncore.py", line 110, in readwrite
obj.handle_write_event()
; File "/usr/local/lib/python3.6/asyncore.py", line 442, in handle_write_event
self.handle_write()
; File "/usr/local/lib/python3.6/site-packages/pysnmp/carrier/asyncore/dgram/base.py", line 149, in handle_write
self.socket, outgoingMessage, transportAddress
; File "/usr/local/lib/python3.6/site-packages/pysnmp/carrier/sockmsg.py", line 108, in sendto
addr = ipaddress.ip_address(_to.getLocalAddress()[0])
; File "/usr/local/lib/python3.6/ipaddress.py", line 54, in ip_address
address)
;ValueError: '${snmp-peer-address}' does not appear to be an IPv4 or IPv6 address
caused by <class 'ValueError'>: '${snmp-peer-address}' does not appear to be an IPv4 or IPv6 address

Which makes me believe that the ${snmp-peer-address} macro is not being expanded.

Am I missing something here?

version:

# snmpfwd-client.py --version
SNMP Proxy Forwarder version 0.4.4, written by Ilya Etingof <etingof@gmail.com>
Using foundation libraries: pysnmp 4.4.9, pyasn1 0.4.5.
Python interpreter: 3.6.8 (default, Mar 27 2019, 08:49:59)
[GCC 6.3.0 20170516]
etingof commented 5 years ago

Could you please look up this message in the log? Is it present, does it look as expected?

Secondly, looking into the code, could it be that you actually have to use server-snmp-peer-address option in the configuration? Let me know if it works for you - I will update the example.

pshemk commented 5 years ago

Yes, using server-snmp-peer-address did the trick. Thank you.

etingof commented 5 years ago

Oh, the example appears misleading! Let me fix the documentation...

Let's keep this issue open as a reminder.