Skip to content

Commit 018eb73

Browse files
Fix to use IPv6 linklocal address as snmp agent address (#3215)
What I did If link local IPv6 address is added as SNMP agent address, it will fail. This PR requires changes in snmpd.conf.j2 template here #18350 How I did it Append scope id to ipv6 link local IP address. How to verify it Able to configure link local ipv6 address as snmp agent address sudo config snmpagentaddress add fe80::a%eth0
1 parent f50587a commit 018eb73

File tree

2 files changed

+33
-2
lines changed

2 files changed

+33
-2
lines changed

config/main.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -3498,7 +3498,10 @@ def add_snmp_agent_address(ctx, agentip, port, vrf):
34983498
"""Add the SNMP agent listening IP:Port%Vrf configuration"""
34993499

35003500
#Construct SNMP_AGENT_ADDRESS_CONFIG table key in the format ip|<port>|<vrf>
3501-
if not clicommon.is_ipaddress(agentip):
3501+
# Link local IP address should be provided along with zone id
3502+
# <link_local_ip>%<zone_id> for ex fe80::1%eth0
3503+
agent_ip_addr = agentip.split('%')[0]
3504+
if not clicommon.is_ipaddress(agent_ip_addr):
35023505
click.echo("Invalid IP address")
35033506
return False
35043507
config_db = ctx.obj['db']
@@ -3508,7 +3511,7 @@ def add_snmp_agent_address(ctx, agentip, port, vrf):
35083511
click.echo("ManagementVRF is Enabled. Provide vrf.")
35093512
return False
35103513
found = 0
3511-
ip = ipaddress.ip_address(agentip)
3514+
ip = ipaddress.ip_address(agent_ip_addr)
35123515
for intf in netifaces.interfaces():
35133516
ipaddresses = netifaces.ifaddresses(intf)
35143517
if ip_family[ip.version] in ipaddresses:

tests/config_snmp_test.py

+28
Original file line numberDiff line numberDiff line change
@@ -877,6 +877,34 @@ def test_config_snmp_community_add_new_community_with_invalid_type_yang_validati
877877
assert result.exit_code != 0
878878
assert 'SNMP community configuration failed' in result.output
879879

880+
@patch('netifaces.interfaces', mock.Mock(return_value=['eth0']))
881+
@patch('netifaces.ifaddresses', mock.Mock(return_value={2:
882+
[{'addr': '10.1.0.32', 'netmask': '255.255.255.0',
883+
'broadcast': '10.1.0.255'}],
884+
10: [{'addr': 'fe80::1%eth0', 'netmask': 'ffff:ffff:ffff:ffff::/64'}]}))
885+
@patch('os.system', mock.Mock(return_value=0))
886+
def test_config_snmpagentaddress_add_linklocal(self):
887+
db = Db()
888+
obj = {'db': db.cfgdb}
889+
runner = CliRunner()
890+
runner.invoke(config.config.commands["snmpagentaddress"].commands["add"], ["fe80::1%eth0"], obj=obj)
891+
assert ('fe80::1%eth0', '', '') in db.cfgdb.get_keys('SNMP_AGENT_ADDRESS_CONFIG')
892+
assert db.cfgdb.get_entry("SNMP_AGENT_ADDRESS_CONFIG", "fe80::1%eth0||") == {}
893+
894+
@patch('netifaces.interfaces', mock.Mock(return_value=['eth0']))
895+
@patch('netifaces.ifaddresses', mock.Mock(return_value={2:
896+
[{'addr': '10.1.0.32', 'netmask': '255.255.255.0',
897+
'broadcast': '10.1.0.255'}],
898+
10: [{'addr': 'fe80::1', 'netmask': 'ffff:ffff:ffff:ffff::/64'}]}))
899+
@patch('os.system', mock.Mock(return_value=0))
900+
def test_config_snmpagentaddress_add_ipv4(self):
901+
db = Db()
902+
obj = {'db': db.cfgdb}
903+
runner = CliRunner()
904+
runner.invoke(config.config.commands["snmpagentaddress"].commands["add"], ["10.1.0.32"], obj=obj)
905+
assert ('10.1.0.32', '', '') in db.cfgdb.get_keys('SNMP_AGENT_ADDRESS_CONFIG')
906+
assert db.cfgdb.get_entry("SNMP_AGENT_ADDRESS_CONFIG", "10.1.0.32||") == {}
907+
880908
@classmethod
881909
def teardown_class(cls):
882910
print("TEARDOWN")

0 commit comments

Comments
 (0)