summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Poessinger <christian@poessinger.com>2018-05-21 19:43:00 +0200
committerChristian Poessinger <christian@poessinger.com>2018-06-04 19:19:29 +0200
commitf12cab5ed3ffeb8a4c34cb874cc05a1cd381ba14 (patch)
tree3939c740271c1788948b1ef454315be57ef52dab
parent6ca653e4200f18926a34bb82323931cc71f52e8a (diff)
downloadvyos-1x-f12cab5ed3ffeb8a4c34cb874cc05a1cd381ba14.tar.gz
vyos-1x-f12cab5ed3ffeb8a4c34cb874cc05a1cd381ba14.zip
T654: Support IPv6 configuration for SNMP listen address
-rw-r--r--interface-definitions/snmp.xml8
-rwxr-xr-xsrc/conf_mode/snmp.py13
2 files changed, 18 insertions, 3 deletions
diff --git a/interface-definitions/snmp.xml b/interface-definitions/snmp.xml
index bcd5295ee..698fb34a1 100644
--- a/interface-definitions/snmp.xml
+++ b/interface-definitions/snmp.xml
@@ -77,6 +77,14 @@
<tagNode name="listen-address">
<properties>
<help>IP address to listen for incoming SNMP requests</help>
+ <valueHelp>
+ <format>ipv4</format>
+ <description>IPv4 address to listen for incoming SNMP requests</description>
+ </valueHelp>
+ <valueHelp>
+ <format>ipv6</format>
+ <description>IPv6 address to listen for incoming SNMP requests</description>
+ </valueHelp>
<constraint>
<validator name="ipv4-address"/>
<validator name="ipv6-address"/>
diff --git a/src/conf_mode/snmp.py b/src/conf_mode/snmp.py
index d32a9a343..80f3bee8c 100755
--- a/src/conf_mode/snmp.py
+++ b/src/conf_mode/snmp.py
@@ -20,12 +20,12 @@ import sys
import os
import jinja2
+import vyos.version
+import ipaddress
from vyos.config import Config
from vyos import ConfigError
-import vyos.version
-
config_file_client = r'/etc/snmp/snmp.conf'
config_file_daemon = r'/etc/snmp/snmpd.conf'
@@ -92,7 +92,7 @@ SysDescr {{ description }}
{% endif %}
# Listen
-agentaddress unix:/run/snmpd.socket{% for ip in listen_on %},udp:{{ ip.addr }}:{{ ip.port }}{% endfor %}
+agentaddress unix:/run/snmpd.socket{% for ip in listen_on %},{{ ip.prot }}:{{ ip.addr }}:{{ ip.port }}{% endfor %}
# SNMP communities
@@ -172,8 +172,15 @@ def get_config():
if conf.exists('listen-address'):
for addr in conf.list_nodes('listen-address'):
+ prot = "udp"
+ if ipaddress.ip_address(addr).version == 6:
+ # SNMP configuration file requires brackets on IPv6 addresses
+ addr = "[" + addr + "]"
+ prot = "udp6"
+
listen = {
'addr': addr,
+ 'prot': prot,
'port': '161'
}