Hi list,

I mailed about this earlier (may 7th, 2007) but the issue is still there: the handling surrounding DHCP clients could be a bit improved...

Currently every dhcp client gets killed after which a very basic dhcp client is started for the dst interface, which is not really inline with what the rest of the script does: the settings of the src interface are transferred to the dst interface.

I wrote a new patch to bring the handling of the dhcp client inline with the reset of the script:
- only the dhclient that is running on the src interface gets killed,
- the commandline options of the killed dhcp client get reused for the new dhcp client (running on dst) - when no running dhcp client can be found on the src interface then a basic dhcp client is started.

There is only one assumption in this script: the interface on which the dhcp client is running must be the last argument on the commandline of the dhcp client.

I checked this assumption for Fedora 6 and 7 and it is met.

The patch is against kvm-snapshot-20070914 (since kvm-39 does not allow insertion for me)

Hope this patch is a bit more palatable for you than the previous one :-)

Ferry



--- kvm.org     2007-09-14 19:17:29.000000000 +0200
+++ kvm 2007-09-15 18:46:34.000000000 +0200
@@ -124,15 +124,15 @@
     fi

     if [ $BOOTPROTO = "dhcp" ]; then
+       local dhclientcmd=`getdhclientcmdandkill ${src} ${dst}`
         ifdown ${src} >/dev/null 2>&1 || true
         ip link set ${src} up >/dev/null 2>&1
         bond_link_up ${src}
-        pkill dhclient >/dev/null 2>&1
        for ((i=0;i<3;i++)); do
            pgrep dhclient >/dev/null 2>&1 || i=4     
            sleep 1
        done
-        dhclient ${dst} >/dev/null 2>&1
+       ${dhclientcmd} >/dev/null 2>&1
     else
         get_ip_info ${src}
         ifconfig ${src} 0.0.0.0
@@ -141,6 +141,44 @@
         ip route add default via ${gateway} dev ${dst}
     fi
 }
+
+getdhclientcmdandkill () {
+    local src=$1
+    local dst=$2
+
+    # get pids for all running dhclients
+    local pidlist=`pgrep dhclient`
+
+    # get the commandline of the dhclient that is currently running on ${src}
+    local clientpid=""
+    local newcmdline=""
+    for i in ${pidlist} ; do
+        local cmdline_i=`ps -o args= ${i} | grep -E "[[:space:]]+${src}\$"`
+       if [ -n "${cmdline_i}" ] ; then
+           newcmdline=${cmdline_i}
+           clientpid=${i}
+           break
+       fi
+    done
+
+    if [ -n "${newcmdline}" ] ; then
+       # we found a dhclient running on ${src}: adjust the command line so
+       # that it will run on ${dst}
+       echo "${newcmdline}" | sed -r "s#[[:space:]]+${src}\$# ${dst}#"
+       kill ${clientpid} >/dev/null 2>&1
+    else
+       # we did not find a dhclient running on ${src}
+
+       # see if there is a configfile for the pif and use it when available
+        cffile="/etc/dhclient-${pif}.conf"
+       cfoption=""
+       if [ -r ${cffile} ]; then
+           cfoption="-cf ${cffile}"
+       fi
+       echo "dhclient ${cfoption} ${dst}"
+        pkill dhclient >/dev/null 2>&1
+    fi
+}

 antispoofing () {
     iptables -P FORWARD DROP >/dev/null 2>&1

--- kvm 2007-06-07 17:13:47.000000000 +0200
+++ /etc/init.d/kvm     2007-07-05 21:06:43.000000000 +0200
@@ -132,7 +132,7 @@
            pgrep dhclient >/dev/null 2>&1 || i=4
            sleep 1
        done
-        dhclient ${dst} >/dev/null 2>&1
+        dhclient -cf /etc/dhclient-${pif}.conf ${dst} >/dev/null 2>&1
     else
         get_ip_info ${src}
         ifconfig ${src} 0.0.0.0

-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
kvm-devel mailing list
kvm-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/kvm-devel

Reply via email to