Blame SOURCES/chrony-nm-dispatcher-dhcp.patch

f77576
commit 5bd13c8d593a74ad168057efe94dd2b3aeeffe14
f77576
Author: Miroslav Lichvar <mlichvar@redhat.com>
f77576
Date:   Mon Feb 7 13:27:25 2022 +0100
f77576
f77576
    examples: support DHCPv6 NTP servers in NM dispatcher script
f77576
    
f77576
    Latest NetworkManager code provides NTP servers from the DHCPv6 NTP
f77576
    option (RFC 5908) in the DHCP6_DHCP6_NTP_SERVERS variable to dispatcher
f77576
    scripts.
f77576
    
f77576
    Check for invalid characters (which can come from the FQDN suboption)
f77576
    and include the servers in the interface-specific sources file.
f77576
f77576
diff --git a/examples/chrony.nm-dispatcher.dhcp b/examples/chrony.nm-dispatcher.dhcp
f77576
index 6ea4c370..4454f037 100644
f77576
--- a/examples/chrony.nm-dispatcher.dhcp
f77576
+++ b/examples/chrony.nm-dispatcher.dhcp
f77576
@@ -1,8 +1,7 @@
f77576
 #!/bin/sh
f77576
 # This is a NetworkManager dispatcher script for chronyd to update
f77576
-# its NTP sources passed from DHCP options. Note that this script is
f77576
-# specific to NetworkManager-dispatcher due to use of the
f77576
-# DHCP4_NTP_SERVERS environment variable.
f77576
+# its NTP sources with servers from DHCP options passed by NetworkManager
f77576
+# in the DHCP4_NTP_SERVERS and DHCP6_DHCP6_NTP_SERVERS environment variables.
f77576
 
f77576
 export LC_ALL=C
f77576
 
f77576
@@ -10,17 +9,19 @@ interface=$1
f77576
 action=$2
f77576
 
f77576
 chronyc=/usr/bin/chronyc
f77576
-default_server_options=iburst
f77576
+server_options=iburst
f77576
 server_dir=/var/run/chrony-dhcp
f77576
 
f77576
 dhcp_server_file=$server_dir/$interface.sources
f77576
-# DHCP4_NTP_SERVERS is passed from DHCP options by NetworkManager.
f77576
-nm_dhcp_servers=$DHCP4_NTP_SERVERS
f77576
+dhcp_ntp_servers="$DHCP4_NTP_SERVERS $DHCP6_DHCP6_NTP_SERVERS"
f77576
 
f77576
 add_servers_from_dhcp() {
f77576
     rm -f "$dhcp_server_file"
f77576
-    for server in $nm_dhcp_servers; do
f77576
-        echo "server $server $default_server_options" >> "$dhcp_server_file"
f77576
+    for server in $dhcp_ntp_servers; do
f77576
+        # Check for invalid characters (from the DHCPv6 NTP FQDN suboption)
f77576
+        printf '%s\n' "$server" | grep -E -q '^[-A-Za-z0-9:.]{1,255}$' || continue
f77576
+
f77576
+        printf 'server %s %s\n' "$server" "$server_options" >> "$dhcp_server_file"
f77576
     done
f77576
     $chronyc reload sources > /dev/null 2>&1 || :
f77576
 }
f77576
@@ -34,10 +35,11 @@ clear_servers_from_dhcp() {
f77576
 
f77576
 mkdir -p $server_dir
f77576
 
f77576
-if [ "$action" = "up" ] || [ "$action" = "dhcp4-change" ]; then
f77576
-    add_servers_from_dhcp
f77576
-elif [ "$action" = "down" ]; then
f77576
-    clear_servers_from_dhcp
f77576
-fi
f77576
+case "$action" in
f77576
+    up|dhcp4-change|dhcp6-change)
f77576
+        add_servers_from_dhcp;;
f77576
+    down)
f77576
+        clear_servers_from_dhcp;;
f77576
+esac
f77576
 
f77576
 exit 0
f77576
f77576
commit e55f174bd3a7ae82fb24afd43443d0b55d5536cf
f77576
Author: Miroslav Lichvar <mlichvar@redhat.com>
f77576
Date:   Mon Feb 7 13:27:48 2022 +0100
f77576
f77576
    examples: handle more actions in NM dispatcher script
f77576
    
f77576
    Run the chronyc onoffline command also when the connectivity-change
f77576
    and dhcp6-change actions are reported by the NetworkManager dispatcher.
f77576
    
f77576
    The latter should not be necessary, but there currently doesn't seem to
f77576
    be any action for IPv6 becoming routable after duplicate address
f77576
    detection, so at least in networks using DHCPv6, IPv6 NTP servers should
f77576
    not be stuck in the offline state from a previously reported action.
f77576
f77576
diff --git a/examples/chrony.nm-dispatcher.onoffline b/examples/chrony.nm-dispatcher.onoffline
f77576
index 34cfa0db..01e6fdb1 100644
f77576
--- a/examples/chrony.nm-dispatcher.onoffline
f77576
+++ b/examples/chrony.nm-dispatcher.onoffline
f77576
@@ -7,8 +7,18 @@ export LC_ALL=C
f77576
 
f77576
 chronyc=/usr/bin/chronyc
f77576
 
f77576
-# For NetworkManager consider only up/down events
f77576
-[ $# -ge 2 ] && [ "$2" != "up" ] && [ "$2" != "down" ] && exit 0
f77576
+# For NetworkManager consider only selected events
f77576
+if [ $# -ge 2 ]; then
f77576
+    case "$2" in
f77576
+        up|down|connectivity-change)
f77576
+            ;;
f77576
+        dhcp6-change)
f77576
+            # No other action is reported for routable IPv6
f77576
+            ;;
f77576
+        *)
f77576
+            exit 0;;
f77576
+    esac
f77576
+fi
f77576
 
f77576
 # Note: for networkd-dispatcher routable.d ~= on and off.d ~= off
f77576
 
f77576
commit fca8966adaaf8376536af86ba2afe02501463588
f77576
Author: Miroslav Lichvar <mlichvar@redhat.com>
f77576
Date:   Wed Mar 23 15:17:03 2022 +0100
f77576
f77576
    examples: replace grep command in NM dispatcher script
f77576
    
f77576
    Some grep implementations detect binary data and return success without
f77576
    matching whole line. This might be an issue for the DHCPv6 NTP FQDN
f77576
    check. The GNU grep in the C locale seems to check only for the NUL
f77576
    character, which cannot be passed in an environment variable, but other
f77576
    implementations might behave differently and there doesn't seem to be a
f77576
    portable way to force matching the whole line.
f77576
    
f77576
    Instead of the grep command, check for invalid characters by comparing
f77576
    the length of the input passed through "tr -d -c".
f77576
f77576
diff --git a/examples/chrony.nm-dispatcher.dhcp b/examples/chrony.nm-dispatcher.dhcp
f77576
index 4454f037..547ce83f 100644
f77576
--- a/examples/chrony.nm-dispatcher.dhcp
f77576
+++ b/examples/chrony.nm-dispatcher.dhcp
f77576
@@ -19,7 +19,11 @@ add_servers_from_dhcp() {
f77576
     rm -f "$dhcp_server_file"
f77576
     for server in $dhcp_ntp_servers; do
f77576
         # Check for invalid characters (from the DHCPv6 NTP FQDN suboption)
f77576
-        printf '%s\n' "$server" | grep -E -q '^[-A-Za-z0-9:.]{1,255}$' || continue
f77576
+        len1=$(printf '%s' "$server" | wc -c)
f77576
+        len2=$(printf '%s' "$server" | tr -d -c 'A-Za-z0-9:.-' | wc -c)
f77576
+        if [ "$len1" -ne "$len2" ] || [ "$len2" -lt 1 ] || [ "$len2" -gt 255 ]; then
f77576
+          continue
f77576
+        fi
f77576
 
f77576
         printf 'server %s %s\n' "$server" "$server_options" >> "$dhcp_server_file"
f77576
     done
d45484
From: Robert Fairley <rfairley@redhat.com>
d45484
Date: Wed, 17 Jun 2020 10:14:19 -0400
d45484
Subject: [PATCH] examples/nm-dispatcher.dhcp: use sysconfig
d45484
d45484
Use the PEERNTP and NTPSERVERARGS environment variables from
d45484
/etc/sysconfig/network{-scripts}.
d45484
d45484
Co-Authored-By: Christian Glombek <cglombek@redhat.com>
d45484
d45484
diff --git a/examples/chrony.nm-dispatcher.dhcp b/examples/chrony.nm-dispatcher.dhcp
d45484
index 6ea4c37..a6ad35a 100644
d45484
--- a/examples/chrony.nm-dispatcher.dhcp
d45484
+++ b/examples/chrony.nm-dispatcher.dhcp
f77576
@@ -8,15 +8,23 @@ export LC_ALL=C
f77576
 interface=$1
f77576
 action=$2
d45484
 
f77576
+[ -f /etc/sysconfig/network ] && . /etc/sysconfig/network
f77576
+[ -f /etc/sysconfig/network-scripts/ifcfg-"${interface}" ] && \
f77576
+    . /etc/sysconfig/network-scripts/ifcfg-"${interface}"
f77576
+
d45484
 chronyc=/usr/bin/chronyc
f77576
-server_options=iburst
d45484
-server_dir=/var/run/chrony-dhcp
f77576
+server_options=${NTPSERVERARGS:-iburst}
d45484
+server_dir=/run/chrony-dhcp
d45484
 
d45484
 dhcp_server_file=$server_dir/$interface.sources
f77576
 dhcp_ntp_servers="$DHCP4_NTP_SERVERS $DHCP6_DHCP6_NTP_SERVERS"
d45484
 
d45484
 add_servers_from_dhcp() {
d45484
     rm -f "$dhcp_server_file"
d45484
+
d45484
+    # Don't add NTP servers if PEERNTP=no specified; return early.
d45484
+    [ "$PEERNTP" = "no" ] && return
d45484
+
f77576
     for server in $dhcp_ntp_servers; do
f77576
         # Check for invalid characters (from the DHCPv6 NTP FQDN suboption)
f77576
         len1=$(printf '%s' "$server" | wc -c)