Skip to content

Commit

Permalink
[snmpd]: Fix to use IPv6 linklocal address as snmp agent address (#18350
Browse files Browse the repository at this point in the history
)

Why I did it

1. fix [snmp] Snmpd fails to start when mgmt or Loopback interface is configured with Link local IPv6 address #16001
2. fix Timeout error while fetching response using snmpget #17807

#17045 modified minigraph parser to use management and loopback IPs to support SNMP query over IPv6. With this fix, if mgmt or loopback IP contains link local IP, that will not work as link local IP has to be appended with scope id associating the IP address to a specific interface. This PR change is to ensure that snmp works with link local IPv6 address.

How I did it
Modify minigraph parser to append the Ip address with % scope id if snmp agent address being used is link local IP address.
Modify snmpd.conf.j2 to take this change while checking if an IP address is ipv4 or ipv6.

How to verify it
Verified by configuring link local ipv6 address.
Last login: Wed Mar 13 01:45:09 2024 from 10.1.84.57
admin@<>:~$ sudo netstat -tulnp | grep 161
...
udp6 0 0 fe80::f6ee:31ff:fe9:161 :::* 70355/snmpd

Signed-off-by: Suvarna Meenakshi <sumeenak@microsoft.com>
  • Loading branch information
SuvarnaMeenakshi authored May 12, 2024
1 parent 4f4a5d0 commit a0ff20e
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 8 deletions.
2 changes: 1 addition & 1 deletion dockers/docker-snmp/snmpd.conf.j2
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
# Listen on managment and loopback0 ips for single asic platform
#
{% macro protocol(ip_addr) %}
{%- if ip_addr|ipv6 -%}
{%- if ip_addr.split('%')[0]|ipv6 -%}
{{ 'udp6' }}
{%- else -%}
{{ 'udp' }}
Expand Down
13 changes: 7 additions & 6 deletions src/sonic-config-engine/minigraph.py
Original file line number Diff line number Diff line change
Expand Up @@ -1762,12 +1762,13 @@ def parse_xml(filename, platform=None, port_config_file=None, asic_name=None, hw
if not is_multi_asic() and asic_name is None:
results['SNMP_AGENT_ADDRESS_CONFIG'] = {}
port = '161'
for mgmt_intf in mgmt_intf.keys():
snmp_key = mgmt_intf[1].split('/')[0] + '|' + port + '|'
results['SNMP_AGENT_ADDRESS_CONFIG'][snmp_key] = {}
# Add Loopback IP as agent address for single asic
for loip in lo_intfs.keys():
snmp_key = loip[1].split('/')[0] + '|' + port + '|'
for intf in list(mgmt_intf.keys()) + list(lo_intfs.keys()):
ip_addr = ipaddress.ip_address(UNICODE_TYPE(intf[1].split('/')[0]))
if ip_addr.version == 6 and ip_addr.is_link_local:
agent_addr = str(ip_addr) + '%' + intf[0]
else:
agent_addr = str(ip_addr)
snmp_key = agent_addr + '|' + port + '|'
results['SNMP_AGENT_ADDRESS_CONFIG'][snmp_key] = {}
else:
results['SNMP_AGENT_ADDRESS_CONFIG'] = {}
Expand Down
8 changes: 8 additions & 0 deletions src/sonic-config-engine/tests/sample_graph.xml
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,14 @@
</a:Prefix>
<a:PrefixStr>192.168.200.15/24</a:PrefixStr>
</a:ManagementIPInterface>
<a:ManagementIPInterface>
<Name>ManagementIPv6</Name>
<AttachTo>Management0</AttachTo>
<a:Prefix xmlns:b="Microsoft.Search.Autopilot.NetMux">
<b:IPPrefix>fe80::1/64</b:IPPrefix>
</a:Prefix>
<a:PrefixStr>fe80::1/64</a:PrefixStr>
</a:ManagementIPInterface>
</ManagementIPInterfaces>
<MplsInterfaces/>
<MplsTeInterfaces/>
Expand Down
2 changes: 1 addition & 1 deletion src/sonic-config-engine/tests/test_cfggen.py
Original file line number Diff line number Diff line change
Expand Up @@ -1150,4 +1150,4 @@ def testsnmp_agent_address_config(self):
output = self.run_script(argument)
self.assertEqual(
utils.liststr_to_dict(output.strip()),
utils.liststr_to_dict("['192.168.200.15|161|', '100.0.0.6|161|', '100.0.0.7|161|']"))
utils.liststr_to_dict("['192.168.200.15|161|', '100.0.0.6|161|', '100.0.0.7|161|', 'fe80::1%Management0|161|']"))

0 comments on commit a0ff20e

Please sign in to comment.