summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorChristian Poessinger <christian@poessinger.com>2021-11-17 21:42:26 +0100
committerChristian Poessinger <christian@poessinger.com>2021-11-17 21:42:26 +0100
commitd13b91462487e090b32c0d1ecf9139a2271b4837 (patch)
treea827717326c9acc854f89db0a07c41de0f918b5f /src
parent77eca49bffede005f546b7d9d3660bf2e32c7e8e (diff)
downloadvyos-1x-d13b91462487e090b32c0d1ecf9139a2271b4837.tar.gz
vyos-1x-d13b91462487e090b32c0d1ecf9139a2271b4837.zip
snmp: T3996: fix invalid IPv6 localhost handling when using listen-address
We need to use a temporary variable when validating the tuple if address is used. If not the else branch will always add the tuple to the list of addresses used for listen-address.
Diffstat (limited to 'src')
-rwxr-xr-xsrc/conf_mode/snmp.py19
1 files changed, 12 insertions, 7 deletions
diff --git a/src/conf_mode/snmp.py b/src/conf_mode/snmp.py
index 2a420b193..e1852f2ce 100755
--- a/src/conf_mode/snmp.py
+++ b/src/conf_mode/snmp.py
@@ -20,13 +20,17 @@ from sys import exit
from vyos.config import Config
from vyos.configverify import verify_vrf
-from vyos.snmpv3_hashgen import plaintext_to_md5, plaintext_to_sha1, random
+from vyos.snmpv3_hashgen import plaintext_to_md5
+from vyos.snmpv3_hashgen import plaintext_to_sha1
+from vyos.snmpv3_hashgen import random
from vyos.template import render
from vyos.template import is_ipv4
-from vyos.util import call, chmod_755
+from vyos.util import call
+from vyos.util import chmod_755
from vyos.validate import is_addr_assigned
from vyos.version import get_version_data
-from vyos import ConfigError, airbag
+from vyos import ConfigError
+from vyos import airbag
airbag.enable()
config_file_client = r'/etc/snmp/snmp.conf'
@@ -410,19 +414,20 @@ def verify(snmp):
port = listen[1]
protocol = snmp['protocol']
+ tmp = None
if is_ipv4(addr):
# example: udp:127.0.0.1:161
- listen = f'{protocol}:{addr}:{port}'
+ tmp = f'{protocol}:{addr}:{port}'
elif snmp['ipv6_enabled']:
# example: udp6:[::1]:161
- listen = f'{protocol}6:[{addr}]:{port}'
+ tmp = f'{protocol}6:[{addr}]:{port}'
# We only wan't to configure addresses that exist on the system.
# Hint the user if they don't exist
if is_addr_assigned(addr):
- snmp['listen_on'].append(listen)
+ if tmp: snmp['listen_on'].append(tmp)
else:
- print('WARNING: SNMP listen address {0} not configured!'.format(addr))
+ print(f'WARNING: SNMP listen address {addr} not configured!')
verify_vrf(snmp)