sonic-buildimage/files/image_config/resolv-config/resolv-config.sh
Oleksandr Ivantsiv 475fe27c0b
[dns] Add support for static DNS configuration. (#14549)
- Why I did it
Add support for static DNS configuration. According to sonic-net/SONiC#1262 HLD.

- How I did it
Add a new resolv-config.service that is responsible for transferring configuration from Config DB into /etc/resolv.conf file that is consumed by various subsystems in Linux to resolve domain names into IP addresses.

- How to verify it
Run the image compilation. Each component related to the static DNS feature is covered with the unit tests.
Run sonic-mgmt tests. Static DNS feature will be covered with the system tests.
Install the image and run manual tests.
2023-06-22 19:12:30 +03:00

62 lines
1.6 KiB
Bash
Executable File

#!/bin/bash
WD=/var/run/resolvconf/
CONFIG_DIR=${WD}/interface/
STATIC_CONFIG_FILE=mgmt.static
DYNAMIC_CONFIG_FILE_TEMPLATE=*.dhclient
update_symlink()
{
ln -sf /run/resolvconf/resolv.conf /etc/resolv.conf
}
start()
{
update_symlink
redis-dump -d 4 -k "DNS_NAMESERVER*" -y > /tmp/dns.json
if [[ $? -eq 0 && "$(cat /tmp/dns.json)" != "{}" ]]; then
# Apply static DNS configuration and disable updates
/sbin/resolvconf --disable-updates
pushd ${CONFIG_DIR}
# Backup dynamic configuration to restore it when the static configuration is removed
mv ${DYNAMIC_CONFIG_FILE_TEMPLATE} ${WD} || true
sonic-cfggen -d -t /usr/share/sonic/templates/resolv.conf.j2,${STATIC_CONFIG_FILE}
/sbin/resolvconf --enable-updates
/sbin/resolvconf -u
/sbin/resolvconf --disable-updates
popd
else
# Dynamic DNS configuration. Enable updates. It is expected to receive configuraution for DHCP server
/sbin/resolvconf --disable-updates
pushd ${CONFIG_DIR}
rm -f ${STATIC_CONFIG_FILE}
# Restore dynamic configuration if it exists
mv ${WD}/${DYNAMIC_CONFIG_FILE_TEMPLATE} ${CONFIG_DIR} || true
/sbin/resolvconf --enable-updates
/sbin/resolvconf -u
fi
}
clean-dynamic-conf()
{
rm -f ${WD}/${DYNAMIC_CONFIG_FILE_TEMPLATE}
rm -f ${WD}/postponed-update
}
case $1 in
start)
start
;;
cleanup)
clean-dynamic-conf
;;
*)
echo "Usage: $0 {start|clean-dynamic-conf}"
exit 2
;;
esac