summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Poessinger <christian@poessinger.com>2021-03-21 08:24:45 +0100
committerChristian Poessinger <christian@poessinger.com>2021-03-21 08:24:45 +0100
commitf411351baef67740b76e800161fe55f495c4bd92 (patch)
tree1a965d69b49c39752faed31015c3a054e53af1e3
parentb7386d3d3c98bb1894a8ceea56e880ae1c83c27a (diff)
downloadvyos-1x-f411351baef67740b76e800161fe55f495c4bd92.tar.gz
vyos-1x-f411351baef67740b76e800161fe55f495c4bd92.zip
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.
-rw-r--r--op-mode-definitions/show-ntp.xml.in9
-rwxr-xr-xsrc/op_mode/show_ntp.sh39
2 files changed, 43 insertions, 5 deletions
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 @@
<properties>
<help>Show peer status of NTP daemon</help>
</properties>
- <command>if ps -C ntpd &amp;&gt;/dev/null; then ntpq -n -c peers; else echo NTP daemon disabled; fi</command>
+ <command>${vyos_op_scripts_dir}/show_ntp.sh --basic</command>
<children>
<tagNode name="server">
<properties>
@@ -15,15 +15,14 @@
<script>${vyos_completion_dir}/list_ntp_servers.sh</script>
</completionHelp>
</properties>
- <command>/usr/sbin/ntpdate -q "$4"</command>
+ <command>${vyos_op_scripts_dir}/show_ntp.sh --server "$4"</command>
</tagNode>
<node name="info">
<properties>
<help>Show NTP operational summary</help>
</properties>
- <command>if ps -C ntpd &amp;&gt;/dev/null; then ntpq -n -c sysinfo; ntpq -n -c kerninfo; else echo NTP daemon disabled; fi</command>
- </node>
-
+ <command>${vyos_op_scripts_dir}/show_ntp.sh --info</command>
+ </node>
</children>
</node>
</children>
diff --git a/src/op_mode/show_ntp.sh b/src/op_mode/show_ntp.sh
new file mode 100755
index 000000000..e9dd6c5c9
--- /dev/null
+++ b/src/op_mode/show_ntp.sh
@@ -0,0 +1,39 @@
+#!/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
+