Skip to content
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

[SNMP][IPv6]: Fix SNMP IPv6 reachability issue in certain scenarios #15487

Merged
merged 12 commits into from
Jul 12, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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
28 changes: 27 additions & 1 deletion dockers/docker-snmp/snmpd.conf.j2
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,38 @@
# AGENT BEHAVIOUR
#

# Listen for connections on all ip addresses, including eth0, ipv4 lo
# Listen for connections on ip addresses based on configuration
#
# if SNMP_AGENT_ADDRESS_CONFIG is present
# use SNMP_AGENT_ADDRESS_CONFIG
# elif either MGMT_INTERFACE or LOOPBACK_INTERFACE
# use management and loopback ip addresses
# use docker0 ipv4 and ipv6 address
# else if none of the above config is present
# listen on any IP
Copy link
Collaborator

@qiluo-msft qiluo-msft Jun 19, 2023

Choose a reason for hiding this comment

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

The logic is complex.
how about minigraph.py just generated correct SNMP_AGENT_ADDRESS_CONFIG?

  1. single-asic: bind to mgmt and lo
  2. multi-asic: bind to mgmt and docker0 #Closed

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think docker0 IP is not part of user config, you can use template here.

However, mgmt IP, lo IP are from user config, it is natural to add them into ConfigDB SNMP_AGENT_ADDRESS_CONFIG table.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I see the challenge of determine single/multi-asic in minigraph.py. So it is okay to keep complex code here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have modified the snmpd.conf.j2 template to use management and loopback IP for single asic platform.
With this, we could backport to previous branches to ensure that we could use ipv6 .

Next step is to:

  1. If the change to modify to use bridge network for snmp docker is merged in, we could add NAT rule for single asic platform similar to multi-asic platform.
  2. After that change, will update minigraph parser to update SNMP_AGENT_ADDRESS_CONFIG table with management IP and docker0 IP for both single and multi-asic platform that way minigraph parser need not have the logic to differentiate between single and multi-asic platform.
  3. Remove the changes in snmpd.conf.j2 and directly use SNMP_AGENT_ADDRESS_CONFIG which will be updated by minigraph parser.


{% if SNMP_AGENT_ADDRESS_CONFIG %}
{% for (agentip, port, vrf) in SNMP_AGENT_ADDRESS_CONFIG %}
agentAddress {{ agentip }}{% if port %}:{{ port }}{% endif %}{% if vrf %}%{{ vrf }}{% endif %}{{ "" }}
{% endfor %}
{% elif MGMT_INTERFACE is defined or LOOPBACK_INTERFACE is defined%}
{% if MGMT_INTERFACE is defined %}
{% for if, ip in MGMT_INTERFACE %}
agentAddress {{ ip.split('/')[0] }}
{% endfor %}
{% endif %}
{% if LOOPBACK_INTERFACE is defined and loopback0_exists %}
{% for lo in LOOPBACK_INTERFACE %}
{% if lo | length == 2 %}
agentAddress {{ lo[1].split('/')[0] }}
{% endif %}
{% endfor %}
{% endif %}
# Listen on docker0 IP address to support multi-asic platform
{% if docker0_v4 and docker0_v6 %}
agentAddress {{ docker0_v4 }}
agentAddress {{ docker0_v6 }}
{% endif %}
{% else %}
agentAddress udp:161
agentAddress udp6:161
Expand Down
11 changes: 11 additions & 0 deletions dockers/docker-snmp/start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,22 @@ mkdir -p /etc/ssw /etc/snmp
# Parse snmp.yml and insert the data in Config DB
/usr/bin/snmp_yml_to_configdb.py

DOCKER0_V4=$(ip -4 addr show docker0 | grep -oP '(?<=inet\s)\d+(\.\d+){3}')
Copy link
Collaborator

@qiluo-msft qiluo-msft Jun 23, 2023

Choose a reason for hiding this comment

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

docker0

More secure container will bring better isolation between host and container. There is no access to docker0 insider container in future.

You may consider passing env var while docker create. #Closed

DOCKER0_V6=$(ip -6 addr show docker0 scope global | grep -oP '(?<=inet6\s)[0-9a-fA-F:]+')
# Loopback0 interface will not exist on multi-asic device
if ip link show Loopback0 >/dev/null 2>&1; then
LOOPBACK0_EXITS=true
fi

ADD_PARAM=$(printf '%s {"docker0_v4":"%s","docker0_v6":"%s","loopback0_exists":"%s"}' \
"-a" "$DOCKER0_V4" "$DOCKER0_V6" "$LOOPBACK0_EXITS")

SONIC_CFGGEN_ARGS=" \
-d \
-y /etc/sonic/sonic_version.yml \
-t /usr/share/sonic/templates/sysDescription.j2,/etc/ssw/sysDescription \
-t /usr/share/sonic/templates/snmpd.conf.j2,/etc/snmp/snmpd.conf \
$ADD_PARAM \
"

sonic-cfggen $SONIC_CFGGEN_ARGS
Expand Down