* Provide guest dhclient with a pristine config file. This obsoletes the
authorUrban Wallasch <urban.wallasch@freenet.de>
Tue, 23 Apr 2019 14:45:44 +0000 (16:45 +0200)
committerUrban Wallasch <urban.wallasch@freenet.de>
Tue, 23 Apr 2019 14:45:44 +0000 (16:45 +0200)
  hack to remove any remnant /etc/resolv.conf.dhclient-new.XXXX files.
* Cleaned out To-Do list.

nns.sh

diff --git a/nns.sh b/nns.sh
index 9059cbb931539320867a091c75b885d9d7bf5990..31d9444e5aa1726972505bcc25f614f0bbe6f52a 100755 (executable)
--- a/nns.sh
+++ b/nns.sh
@@ -5,18 +5,6 @@
 # the host (default) network namespace.
 #
 
-######################################################################
-# To-Do:
-# ------
-#
-# * Find a nice way to keep dhclient when run within a network namespace
-#   from littering the system with /etc/resolv.conf.dhclient-new.XXXX
-#   files while attempting to overwrite /etc/resolv.conf.
-#   Current workaround is to indiscriminately remove such files.
-#   Cf: https://stackoverflow.com/questions/38102481/how-can-dhclient-be-made-namespace-aware )
-#
-#####
-
 ######################################################################
 # Default configuration; can be overridden by passing the name
 # of a shell script fragment containing appropriate variable
@@ -235,9 +223,9 @@ start_nns() {
     # up this and the lo interface:
     $IP link set $VETH_GUEST netns $1
     if [ -z "$GUEST_ADDR" ] ; then
+        # Provide the guest dhclient with its own empty configuration file:
+        /bin/mkdir -p /etc/netns/$1/dhcp/ && /bin/touch /etc/netns/$1/dhcp/dhcp.conf
         $IP netns exec $1 $DHCLIENT -pf "$RUNDIR/dhclient.$VETH_GUEST.pid" -v $VETH_GUEST
-        # Remove dhclients useless remains:
-        rm /etc/resolv.conf.dhclient-new.*
     else
         $IP netns exec $1 $IP addr add $GUEST_ADDR/$GUEST_PLEN broadcast $GUEST_BCAST dev $VETH_GUEST
         $IP netns exec $1 $IP link set dev $VETH_GUEST up
@@ -291,7 +279,9 @@ stop_nns() {
     $IP link del $VETH_HOST 2> /dev/null
     $IP netns del $1
 
-    # Cleanup namespace DNS configuration:
+    # Cleanup namespace DHCP and DNS configuration:
+    /bin/rm /etc/netns/$1/dhcp/dhcp.conf
+    /bin/rmdir /etc/netns/$1/dhcp/
     /bin/rm /etc/netns/$1/resolv.conf
     /bin/rmdir /etc/netns/$1