Skip to content

Commit 554e110

Browse files
yaqiangzyanjundeng
authored andcommitted
[ntp] Add support for ntp to listen ipv4/ipv6 address depends on server config (sonic-net#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
1 parent 9b90ee7 commit 554e110

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

files/image_config/ntp/ntp.conf.j2

+11-1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ leapfile /usr/share/zoneinfo/leap-seconds.list
1818
{# Adding NTP servers. We need to know if we have some pools, to set proper
1919
config -#}
2020
{% set ns = namespace(is_pools=false) %}
21+
{% set ip_ver_ns = namespace(ipv4_server=false, ipv6_server=false) %}
2122
{% for server in NTP_SERVER if NTP_SERVER[server].admin_state != 'disabled' -%}
2223
{% set config = NTP_SERVER[server] -%}
2324
{# Server options -#}
@@ -56,6 +57,13 @@ config -#}
5657
restrict {{ resolve_as }} kod limited nomodify noquery
5758
{% endif %}
5859

60+
{% if resolve_as | ipv4 -%}
61+
{% set ip_ver_ns.ipv4_server = true %}
62+
{% elif resolve_as | ipv6 %}
63+
{% set ip_ver_ns.ipv6_server = true %}
64+
{% endif -%}
65+
66+
5967
{% endfor -%}
6068

6169
{% set trusted_keys_arr = [] -%}
@@ -125,9 +133,11 @@ interface listen {{ mgmt_prefix | ip }}
125133
{% endfor %}
126134
{% elif LOOPBACK_INTERFACE %}
127135
{% for (name, prefix) in LOOPBACK_INTERFACE|pfx_filter %}
128-
{% if prefix | ipv4 and name == 'Loopback0' %}
136+
{% if name == 'Loopback0' %}
137+
{% if prefix | ipv4 and ip_ver_ns.ipv4_server or prefix | ipv6 and ip_ver_ns.ipv6_server %}
129138
interface listen {{ prefix | ip }}
130139
{% endif %}
140+
{% endif %}
131141
{% endfor %}
132142
{% else %}
133143
interface listen eth0

0 commit comments

Comments
 (0)