Skip to content

Commit

Permalink
fix: Prevented ifup-local from writing duplicate DNS entries (#4674)
Browse files Browse the repository at this point in the history
Signed-off-by: Nicola Timeus <[email protected]>
  • Loading branch information
nicolatimeus authored May 22, 2023
1 parent af967a2 commit daabb0b
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 2 deletions.
29 changes: 28 additions & 1 deletion kura/distrib/src/main/resources/common/ifup-local.debian
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,33 @@ if [ $IFACE == "lo" ] ; then
exit
fi

write_dns() {
if [ -z "$1" ]; then
return
fi

ARG=$(echo "${1}" | xargs)

WRITE_DNS=1

if [ -e /etc/resolv.conf ]; then
while read -r line
do
if [[ "$line" == nameserver* ]]; then
DNS=$(echo "${line#*\ }" | xargs)
if [ "${DNS}" == "${ARG}" ]; then
WRITE_DNS=0
break
fi
fi
done < /etc/resolv.conf
fi

if [ "${WRITE_DNS}" == 1 ]; then
echo "nameserver ${ARG}" >> /etc/resolv.conf
fi
}

DEVICE=$IFACE
FILENAME="/tmp/.kura/coninfo-"$DEVICE
FLAG=0
Expand Down Expand Up @@ -40,7 +67,7 @@ do
DnsInd=`expr $DnsInd + 1`
IFS=' ' read -ra Dns <<< "${line:$ind}"
for i in "${Dns[@]}"; do
echo "nameserver $i" >> /etc/resolv.conf
write_dns "$i"
done
break
fi
Expand Down
29 changes: 28 additions & 1 deletion kura/distrib/src/main/resources/common/ifup-local.raspbian
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,33 @@ if [ $IFACE == "lo" ] ; then
exit
fi

write_dns() {
if [ -z "$1" ]; then
return
fi

ARG=$(echo "${1}" | xargs)

WRITE_DNS=1

if [ -e /etc/resolv.conf ]; then
while read -r line
do
if [[ "$line" == nameserver* ]]; then
DNS=$(echo "${line#*\ }" | xargs)
if [ "${DNS}" == "${ARG}" ]; then
WRITE_DNS=0
break
fi
fi
done < /etc/resolv.conf
fi

if [ "${WRITE_DNS}" == 1 ]; then
echo "nameserver ${ARG}" >> /etc/resolv.conf
fi
}

DEVICE=$IFACE
FILENAME="/tmp/.kura/coninfo-"$DEVICE
FLAG=0
Expand Down Expand Up @@ -40,7 +67,7 @@ do
DnsInd=`expr $DnsInd + 1`
IFS=' ' read -ra Dns <<< "${line:$ind}"
for i in "${Dns[@]}"; do
echo "nameserver $i" >> /etc/resolv.conf
write_dns "$i"
done
break
fi
Expand Down

0 comments on commit daabb0b

Please sign in to comment.