From f12cab5ed3ffeb8a4c34cb874cc05a1cd381ba14 Mon Sep 17 00:00:00 2001 From: Christian Poessinger Date: Mon, 21 May 2018 19:43:00 +0200 Subject: T654: Support IPv6 configuration for SNMP listen address --- interface-definitions/snmp.xml | 8 ++++++++ src/conf_mode/snmp.py | 13 ++++++++++--- 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 @@ IP address to listen for incoming SNMP requests + + ipv4 + IPv4 address to listen for incoming SNMP requests + + + ipv6 + IPv6 address to listen for incoming SNMP requests + 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' } -- cgit v1.2.3