Skip to content

Commit

Permalink
[ntp] Add support for ntp to listen ipv4/ipv6 address depends on serv…
Browse files Browse the repository at this point in the history
…er config (#20227)

Why I did it
Switch cannot connect to NTP server with Loopback ipv6 in Loopback ipv6 only scenario.

Work item tracking
Microsoft ADO (number only): 29415265

How I did it
Add support for ntp to listen ipv4/ipv6 address depends on server config

How to verify it
Run ntp test with new template
  • Loading branch information
yaqiangz authored and mssonicbld committed Sep 20, 2024
1 parent dce23bb commit 35c51eb
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion files/image_config/ntp/ntp.conf.j2
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ leapfile /usr/share/zoneinfo/leap-seconds.list
{# Adding NTP servers. We need to know if we have some pools, to set proper
config -#}
{% set ns = namespace(is_pools=false) %}
{% set ip_ver_ns = namespace(ipv4_server=false, ipv6_server=false) %}
{% for server in NTP_SERVER if NTP_SERVER[server].admin_state != 'disabled' -%}
{% set config = NTP_SERVER[server] -%}
{# Server options -#}
Expand Down Expand Up @@ -56,6 +57,13 @@ config -#}
restrict {{ resolve_as }} kod limited nomodify noquery
{% endif %}

{% if resolve_as | ipv4 -%}
{% set ip_ver_ns.ipv4_server = true %}
{% elif resolve_as | ipv6 %}
{% set ip_ver_ns.ipv6_server = true %}
{% endif -%}


{% endfor -%}

{% set trusted_keys_arr = [] -%}
Expand Down Expand Up @@ -125,9 +133,11 @@ interface listen {{ mgmt_prefix | ip }}
{% endfor %}
{% elif LOOPBACK_INTERFACE %}
{% for (name, prefix) in LOOPBACK_INTERFACE|pfx_filter %}
{% if prefix | ipv4 and name == 'Loopback0' %}
{% if name == 'Loopback0' %}
{% if prefix | ipv4 and ip_ver_ns.ipv4_server or prefix | ipv6 and ip_ver_ns.ipv6_server %}
interface listen {{ prefix | ip }}
{% endif %}
{% endif %}
{% endfor %}
{% else %}
interface listen eth0
Expand Down

0 comments on commit 35c51eb

Please sign in to comment.