Skip to content

Commit

Permalink
[Static DNS] Optimize DNS configuration update during interface-confi…
Browse files Browse the repository at this point in the history
…g service restart (sonic-net#19583)

#### Why I did it
The `resolvconfig` service updates the DNS configuration in the host OS and each running Docker container when a configuration change is detected. The DNS configuration update during the shutdown of the management interface is redundant, as the management interface is going down temporarily and, when it is back online, the DNS configuration will remain the same. The update of the DNS configuration adds a couple of seconds (depending on the CPU) to the interface-config service restart time when the management interface uses a dynamic IP address. This can affect the fast boot. To optimize the flow and execute the service restart faster, the update should be skipped.

#### How I did it
Do not run DNS configuration update during the shutdown of the management interface.

#### How to verify it
Measure the execution time of the `service interfaces-config restart` command on the device with the static IP address configuration on the management interface and compare it to the execution time of the same command with the dynamic IP address. The difference should be insignificant.
  • Loading branch information
oleksandrivantsiv authored and matiAlfaro committed Aug 21, 2024
1 parent a69296a commit 1ecbe56
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
21 changes: 21 additions & 0 deletions files/image_config/interfaces/interfaces-config.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/bin/bash
resolvconf_updates=true

function wait_networking_service_done() {
local -i _WDOG_CNT="1"
Expand All @@ -23,6 +24,24 @@ function wait_networking_service_done() {
systemctl kill networking 2>&1
}

function resolvconf_updates_disable() {
resolvconf --updates-are-enabled
if [[ $? -ne 0 ]]; then
resolvconf_updates=false
fi
resolvconf --disable-updates
}

function resolvconf_updates_restore() {
if [[ $resolvconf_updates == true ]]; then
resolvconf --enable-updates
fi
}

# Do not run DNS configuration update during the shutdowning of the management interface.
# This operation is redundant as there will be an update after the start of the interface.
resolvconf_updates_disable

if [[ $(ifquery --running eth0) ]]; then
wait_networking_service_done
ifdown --force eth0
Expand Down Expand Up @@ -61,6 +80,8 @@ for intf_pid in $(ls -1 /var/run/dhclient*.Ethernet*.pid 2> /dev/null); do
done

/usr/bin/resolv-config.sh cleanup
# Restore DNS configuration update to the previous state.
resolvconf_updates_restore

# Read sysctl conf files again
sysctl -p /etc/sysctl.d/90-dhcp6-systcl.conf
Expand Down
7 changes: 6 additions & 1 deletion files/image_config/resolv-config/update-containers
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
#!/bin/bash

for container in $(docker ps -a --format=" {{ .ID }}"); do
networking_status=$(systemctl is-active networking.service 2>/dev/null)
if [[ $networking_status != "active" ]]; then
exit 0
fi

for container in $(docker ps -q); do
docker cp -L /etc/resolv.conf ${container}:/_resolv.conf
docker exec -t ${container} bash -c "cat /_resolv.conf > /etc/resolv.conf"
docker exec -t ${container} bash -c "rm /_resolv.conf"
Expand Down

0 comments on commit 1ecbe56

Please sign in to comment.