From 3a208379d41f7d11409a1b41600412274ae908c3 Mon Sep 17 00:00:00 2001 From: Vitaly Kuznetsov Date: Tue, 12 Nov 2024 15:30:44 +0100 Subject: [PATCH 2/2] Use NetworkManager information to report DNS settings RH-Author: Vitaly Kuznetsov RH-MergeRequest: 11: Use NetworkManager information to report DNS/DHCP settings RH-Jira: RHEL-65434 RH-Acked-by: Emanuele Giuseppe Esposito RH-Acked-by: Miroslav Rezanina RH-Commit: [2/2] 369721a80574f03e708cc2bd8129e69dd12281d6 (vkuznets/hyperv-daemons) Getting DNS information our of /etc/resolv.conf is not entirely correct as per-NIC settings may differ. NetworkManager information is more precise. Note, KVP daemon need to pass NIC name to the script to make it work. Signed-off-by: Vitaly Kuznetsov --- hv_get_dns_info.sh | 20 ++++++++++++-------- hv_kvp_daemon.c | 2 +- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/hv_get_dns_info.sh b/hv_get_dns_info.sh index 058c17b..973b1be 100644 --- a/hv_get_dns_info.sh +++ b/hv_get_dns_info.sh @@ -1,13 +1,17 @@ #!/bin/bash # This example script parses /etc/resolv.conf to retrive DNS information. -# In the interest of keeping the KVP daemon code free of distro specific -# information; the kvp daemon code invokes this external script to gather -# DNS information. # This script is expected to print the nameserver values to stdout. -# Each Distro is expected to implement this script in a distro specific -# fashion. For instance on Distros that ship with Network Manager enabled, -# this script can be based on the Network Manager APIs for retrieving DNS -# entries. +# RHEL specific implementation, use NetworkManager information. -cat /etc/resolv.conf 2>/dev/null | awk '/^nameserver/ { print $2 }' +[ ! -z "$1" ] || exit 1 + +nmcon=$(nmcli -g GENERAL.CONNECTION device show "$1" 2>/dev/null) + +if [ -z "$nmcon" ]; then +exit 0 +fi + +nmcli -g IP4.DNS -e no connection show "$nmcon" 2>/dev/null | sed 's, | ,\n,g' + +nmcli -g IP6.DNS -e no connection show "$nmcon" 2>/dev/null | sed 's, | ,\n,g' diff --git a/hv_kvp_daemon.c b/hv_kvp_daemon.c index ae57bf6..931eb53 100644 --- a/hv_kvp_daemon.c +++ b/hv_kvp_daemon.c @@ -725,7 +725,7 @@ static void kvp_get_ipconfig_info(char *if_name, * . */ - sprintf(cmd, KVP_SCRIPTS_PATH "%s", "hv_get_dns_info"); + sprintf(cmd, KVP_SCRIPTS_PATH "%s %s", "hv_get_dns_info", if_name); /* * Execute the command to gather DNS info. -- 2.39.3