* [Buildroot] [git commit] busybox: udhcpc.script: fix resolv.conf handling with multiple interfaces
@ 2013-06-26 13:20 Peter Korsgaard
2013-06-26 17:13 ` Arnout Vandecappelle
0 siblings, 1 reply; 3+ messages in thread
From: Peter Korsgaard @ 2013-06-26 13:20 UTC (permalink / raw)
To: buildroot
commit: http://git.buildroot.net/buildroot/commit/?id=584f418ec1ae3f0b5e09c10133c82578d78a3e03
branch: http://git.buildroot.net/buildroot/commit/?id=refs/heads/master
When udhcpc is used on multiple network devices at the same time (or a mix
of dhcp and fixed configuration), /etc/resolv.conf should contain the
union of information from all the interfaces.
Currently that's not the case. The udhcpc script simply overwrites
resolv.conf with the information from the specific interface on each dhcp
bound/renew event.
Fix it by tagging lines with the interface they came from when added,
and drop the affected lines on deconfig/renew. As /etc/resolv.conf is
often a symlink to /tmp (and rootfs might be read only), special care
has to be taken when it is updated.
Notice that I'm not really aware of any official documentation requiring
that '#' comments in /etc/resolv.conf must be supported, but atleast
glibc and uClibc do.
Signed-off-by: Peter Korsgaard <jacmet@sunsite.dk>
---
package/busybox/udhcpc.script | 19 ++++++++++++++++---
1 files changed, 16 insertions(+), 3 deletions(-)
diff --git a/package/busybox/udhcpc.script b/package/busybox/udhcpc.script
index f7beb56..43742fb 100755
--- a/package/busybox/udhcpc.script
+++ b/package/busybox/udhcpc.script
@@ -13,6 +13,13 @@ case "$1" in
/sbin/ifconfig $interface up
/sbin/ifconfig $interface 0.0.0.0
+ # drop info from this interface
+ # resolv.conf may be a symlink to /tmp/, so take care
+ TMPFILE=$(mktemp)
+ grep -vE "# $interface\$" $RESOLV_CONF > $TMPFILE
+ cat $TMPFILE > $RESOLV_CONF
+ rm -f $TMPFILE
+
if [ -x /usr/sbin/avahi-autoipd ]; then
/usr/sbin/avahi-autoipd -k $interface
fi
@@ -41,11 +48,17 @@ case "$1" in
done
fi
- echo -n > $RESOLV_CONF
- [ -n "$domain" ] && echo search $domain >> $RESOLV_CONF
+ # drop info from this interface
+ # resolv.conf may be a symlink to /tmp/, so take care
+ TMPFILE=$(mktemp)
+ grep -vE "# $interface\$" $RESOLV_CONF > $TMPFILE
+ cat $TMPFILE > $RESOLV_CONF
+ rm -f $TMPFILE
+
+ [ -n "$domain" ] && echo "search $domain # $interface" >> $RESOLV_CONF
for i in $dns ; do
echo adding dns $i
- echo nameserver $i >> $RESOLV_CONF
+ echo "nameserver $i # $interface" >> $RESOLV_CONF
done
;;
esac
^ permalink raw reply related [flat|nested] 3+ messages in thread
* [Buildroot] [git commit] busybox: udhcpc.script: fix resolv.conf handling with multiple interfaces
2013-06-26 13:20 [Buildroot] [git commit] busybox: udhcpc.script: fix resolv.conf handling with multiple interfaces Peter Korsgaard
@ 2013-06-26 17:13 ` Arnout Vandecappelle
2013-06-26 19:51 ` Peter Korsgaard
0 siblings, 1 reply; 3+ messages in thread
From: Arnout Vandecappelle @ 2013-06-26 17:13 UTC (permalink / raw)
To: buildroot
On 26/06/13 15:20, Peter Korsgaard wrote:
> commit: http://git.buildroot.net/buildroot/commit/?id=584f418ec1ae3f0b5e09c10133c82578d78a3e03
> branch: http://git.buildroot.net/buildroot/commit/?id=refs/heads/master
>
> When udhcpc is used on multiple network devices at the same time (or a mix
> of dhcp and fixed configuration), /etc/resolv.conf should contain the
> union of information from all the interfaces.
>
> Currently that's not the case. The udhcpc script simply overwrites
> resolv.conf with the information from the specific interface on each dhcp
> bound/renew event.
>
> Fix it by tagging lines with the interface they came from when added,
> and drop the affected lines on deconfig/renew. As /etc/resolv.conf is
> often a symlink to /tmp (and rootfs might be read only), special care
> has to be taken when it is updated.
>
> Notice that I'm not really aware of any official documentation requiring
> that '#' comments in /etc/resolv.conf must be supported, but atleast
> glibc and uClibc do.
>
> Signed-off-by: Peter Korsgaard <jacmet@sunsite.dk>
> ---
> package/busybox/udhcpc.script | 19 ++++++++++++++++---
> 1 files changed, 16 insertions(+), 3 deletions(-)
>
> diff --git a/package/busybox/udhcpc.script b/package/busybox/udhcpc.script
> index f7beb56..43742fb 100755
> --- a/package/busybox/udhcpc.script
> +++ b/package/busybox/udhcpc.script
> @@ -13,6 +13,13 @@ case "$1" in
> /sbin/ifconfig $interface up
> /sbin/ifconfig $interface 0.0.0.0
>
> + # drop info from this interface
> + # resolv.conf may be a symlink to /tmp/, so take care
> + TMPFILE=$(mktemp)
> + grep -vE "# $interface\$" $RESOLV_CONF > $TMPFILE
> + cat $TMPFILE > $RESOLV_CONF
Isn't the non-atomicity of this line a potential race condition?
mv -f $TMPFILE $(readlink -f $RESOLV_CONF)
might be a better idea.
Regards,
Arnout
> + rm -f $TMPFILE
> +
> if [ -x /usr/sbin/avahi-autoipd ]; then
> /usr/sbin/avahi-autoipd -k $interface
> fi
> @@ -41,11 +48,17 @@ case "$1" in
> done
> fi
>
> - echo -n > $RESOLV_CONF
> - [ -n "$domain" ] && echo search $domain >> $RESOLV_CONF
> + # drop info from this interface
> + # resolv.conf may be a symlink to /tmp/, so take care
> + TMPFILE=$(mktemp)
> + grep -vE "# $interface\$" $RESOLV_CONF > $TMPFILE
> + cat $TMPFILE > $RESOLV_CONF
> + rm -f $TMPFILE
> +
> + [ -n "$domain" ] && echo "search $domain # $interface" >> $RESOLV_CONF
> for i in $dns ; do
> echo adding dns $i
> - echo nameserver $i >> $RESOLV_CONF
> + echo "nameserver $i # $interface" >> $RESOLV_CONF
> done
> ;;
> esac
> _______________________________________________
> buildroot mailing list
> buildroot at busybox.net
> http://lists.busybox.net/mailman/listinfo/buildroot
>
>
--
Arnout Vandecappelle arnout at mind be
Senior Embedded Software Architect +32-16-286500
Essensium/Mind http://www.mind.be
G.Geenslaan 9, 3001 Leuven, Belgium BE 872 984 063 RPR Leuven
LinkedIn profile: http://www.linkedin.com/in/arnoutvandecappelle
GPG fingerprint: 7CB5 E4CC 6C2E EFD4 6E3D A754 F963 ECAB 2450 2F1F
^ permalink raw reply [flat|nested] 3+ messages in thread
* [Buildroot] [git commit] busybox: udhcpc.script: fix resolv.conf handling with multiple interfaces
2013-06-26 17:13 ` Arnout Vandecappelle
@ 2013-06-26 19:51 ` Peter Korsgaard
0 siblings, 0 replies; 3+ messages in thread
From: Peter Korsgaard @ 2013-06-26 19:51 UTC (permalink / raw)
To: buildroot
>>>>> "Arnout" == Arnout Vandecappelle <arnout@mind.be> writes:
>> diff --git a/package/busybox/udhcpc.script b/package/busybox/udhcpc.script
>> index f7beb56..43742fb 100755
>> --- a/package/busybox/udhcpc.script
>> +++ b/package/busybox/udhcpc.script
>> @@ -13,6 +13,13 @@ case "$1" in
>> /sbin/ifconfig $interface up
>> /sbin/ifconfig $interface 0.0.0.0
>>
>> + # drop info from this interface
>> + # resolv.conf may be a symlink to /tmp/, so take care
>> + TMPFILE=$(mktemp)
>> + grep -vE "# $interface\$" $RESOLV_CONF > $TMPFILE
>> + cat $TMPFILE > $RESOLV_CONF
Arnout> Isn't the non-atomicity of this line a potential race condition?
Possibly, but no worse than what it was before ;)
Arnout> mv -f $TMPFILE $(readlink -f $RESOLV_CONF)
Arnout> might be a better idea.
Yes. Care to send a patch?
--
Bye, Peter Korsgaard
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2013-06-26 19:51 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-06-26 13:20 [Buildroot] [git commit] busybox: udhcpc.script: fix resolv.conf handling with multiple interfaces Peter Korsgaard
2013-06-26 17:13 ` Arnout Vandecappelle
2013-06-26 19:51 ` Peter Korsgaard
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.