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

[NTP] 🐞 Fix config template to init default parameters #18736

Merged
merged 1 commit into from
May 15, 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
22 changes: 9 additions & 13 deletions files/image_config/ntp/ntp.conf.j2
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ 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) %}
{% for server in NTP_SERVER if NTP_SERVER[server].admin_state != 'disabled' and
NTP_SERVER[server].resolve_as and
NTP_SERVER[server].association_type -%}
{% for server in NTP_SERVER if NTP_SERVER[server].admin_state != 'disabled' -%}
{% set config = NTP_SERVER[server] -%}
{# Server options -#}
{% set soptions = '' -%}
{# Server access control options -#}
{% set aoptions = '' -%}

{# Define defaults if not defined -#}
{% set association_type = config.association_type | d('server') -%}
{% set resolve_as = config.resolve_as | d(server) -%}

{# Authentication key -#}
{% if global.authentication == 'enabled' -%}
Expand All @@ -47,17 +47,13 @@ config -#}
{# Check if there are any pool configured. BTW it doesn't matter what was
configured as "resolve_as" for pools. If they were configured with FQDN they
must remain like that -#}
{% set config_as = config.resolve_as -%}
{% if config.association_type == 'pool' -%}
{% set ns.is_pools = true -%}
{% set config_as = server -%}
{% else -%}
{% set aoptions = aoptions ~ ' nopeer' -%}
{% if association_type == 'pool' -%}
{% set resolve_as = server -%}
{% endif -%}

{{ config.association_type }} {{ config_as }}{{ soptions }}
{{ association_type }} {{ resolve_as }}{{ soptions }}
{% if global.server_role == 'disabled' %}
restrict {{ config_as }} kod limited nomodify notrap noquery{{ aoptions }}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you please clarify why notrap and aoptions are removed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

nopeer and notrap is not supported by ntp-sec anymore. You can check its reference here: https://docs.ntpsec.org/latest/accopt.html
aoptions was used to add nopeer based on condition (if server is not a pool), but now it is not needed anymore.

Copy link
Collaborator

Choose a reason for hiding this comment

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

@fastiuk Then we may need to raise a separate PR for 202311 as 202311 doesn't use bookworm. @saiarcot895 FYI

restrict {{ resolve_as }} kod limited nomodify noquery
{% endif %}

{% endfor -%}
Expand Down
4 changes: 2 additions & 2 deletions src/sonic-config-engine/tests/sample_output/py3/ntp.conf
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ driftfile /var/lib/ntpsec/ntp.drift
leapfile /usr/share/zoneinfo/leap-seconds.list

server 10.20.30.50 key 42 iburst version 3
restrict 10.20.30.50 kod limited nomodify notrap noquery nopeer
restrict 10.20.30.50 kod limited nomodify noquery

pool pool.ntp.org iburst version 3
restrict pool.ntp.org kod limited nomodify notrap noquery
restrict pool.ntp.org kod limited nomodify noquery


keys /etc/ntpsec/ntp.keys
Expand Down
Loading