Skip to content

Fix to use IPv6 linklocal address as snmp agent address #18350

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

%

  1. Is it a config schema disruptive change?
  2. Do you need to change yang model?
  3. We try hard to prevent minigraph parser behavior change since we will deploy config_db.json directly in production. So backward-compatible config schema change is preferred.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. This is not a config_db schema change
  2. Yang change is already in place
  3. this change is mainly to append %(zone) if the IP address is a link local IP Address, inside the SNMP_AGENT_ADDRESS_CONFIG table which is used here: https://github.com/sonic-net/sonic-buildimage/blob/master/dockers/docker-snmp/snmpd.conf.j2#L29
    We cannot make this change in the template directly, because "zone" refers to the "interface name" to which the respective IP address belongs to, so we need to know what is the interface name while adding the IP address.

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|']"))
Loading