From 150401fa4c0a393ca496e188eeb08f9ac3844a6a Mon Sep 17 00:00:00 2001 From: Christian Poessinger Date: Sun, 21 Mar 2021 08:24:45 +0100 Subject: ntp: T3416: fix op-mode commands when running inside VRF When NTP is executed inside a VRF context, we also must execute the op-mode commands inside the given VRF. This is a workaround until the op-mode programming library from T3402 is available. (cherry picked from commit f411351baef67740b76e800161fe55f495c4bd92) --- op-mode-definitions/show-ntp.xml.in | 9 ++++----- src/op_mode/show_ntp.sh | 38 +++++++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 5 deletions(-) create mode 100755 src/op_mode/show_ntp.sh diff --git a/op-mode-definitions/show-ntp.xml.in b/op-mode-definitions/show-ntp.xml.in index b7f0acdf8..01f4477d8 100644 --- a/op-mode-definitions/show-ntp.xml.in +++ b/op-mode-definitions/show-ntp.xml.in @@ -6,7 +6,7 @@ Show peer status of NTP daemon - if ps -C ntpd &>/dev/null; then ntpq -n -c peers; else echo NTP daemon disabled; fi + ${vyos_op_scripts_dir}/show_ntp.sh --basic @@ -15,15 +15,14 @@ - /usr/sbin/ntpdate -q "$4" + ${vyos_op_scripts_dir}/show_ntp.sh --server "$4" Show NTP operational summary - if ps -C ntpd &>/dev/null; then ntpq -n -c sysinfo; ntpq -n -c kerninfo; else echo NTP daemon disabled; fi - - + ${vyos_op_scripts_dir}/show_ntp.sh --info + diff --git a/src/op_mode/show_ntp.sh b/src/op_mode/show_ntp.sh new file mode 100755 index 000000000..292a6027f --- /dev/null +++ b/src/op_mode/show_ntp.sh @@ -0,0 +1,38 @@ +#!/bin/sh + +basic=0 +info=0 + +while [[ "$#" -gt 0 ]]; do + case $1 in + --info) info=1 ;; + --basic) basic=1 ;; + --server) server=$2; shift ;; + *) echo "Unknown parameter passed: $1" ;; + esac + shift +done + +if ! ps -C ntpd &>/dev/null; then + echo NTP daemon disabled + exit 1 +fi + +PID=$(pgrep ntpd) +VRF_NAME=$(ip vrf identify ${PID}) + +if [ ! -z ${VRF_NAME} ]; then + VRF_CMD="sudo ip vrf exec ${VRF_NAME}" +fi + +if [ $basic -eq 1 ]; then + $VRF_CMD ntpq -n -c peers +elif [ $info -eq 1 ]; then + echo "=== sysingo ===" + $VRF_CMD ntpq -n -c sysinfo + echo + echo "=== kerninfo ===" + $VRF_CMD ntpq -n -c kerninfo +elif [ ! -z $server ]; then + $VRF_CMD /usr/sbin/ntpdate -q $server +fi -- cgit v1.2.3