public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
From: Ferry Huberts <ferry-NbsvJix5b8QAvxtiuMwx3w@public.gmane.org>
To: kvm-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org
Subject: [PATCH] make kvm service script transfer dhclient settings correctly
Date: Sat, 15 Sep 2007 19:09:02 +0200	[thread overview]
Message-ID: <46EC11AE.9090408@hupie.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 3054 bytes --]

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


[-- Attachment #2: patch.diff --]
[-- Type: text/x-patch, Size: 391 bytes --]

--- 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


[-- Attachment #3: Type: text/plain, Size: 228 bytes --]

-------------------------------------------------------------------------
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/

[-- Attachment #4: Type: text/plain, Size: 186 bytes --]

_______________________________________________
kvm-devel mailing list
kvm-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org
https://lists.sourceforge.net/lists/listinfo/kvm-devel

             reply	other threads:[~2007-09-15 17:09 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-09-15 17:09 Ferry Huberts [this message]
     [not found] ` <46EC11AE.9090408-NbsvJix5b8QAvxtiuMwx3w@public.gmane.org>
2007-09-16  9:18   ` [PATCH] make kvm service script transfer dhclient settings correctly Avi Kivity
     [not found]     ` <46ECF4E2.9000203-atKUWr5tajBWk0Htik3J/w@public.gmane.org>
2007-09-16  9:39       ` Ferry Huberts
     [not found]         ` <46ECF9DB.5020208-NbsvJix5b8QAvxtiuMwx3w@public.gmane.org>
2007-09-16  9:52           ` Avi Kivity
     [not found]             ` <46ECFCF8.2020002-atKUWr5tajBWk0Htik3J/w@public.gmane.org>
2007-09-16 18:28               ` Daniel P. Berrange
2007-09-16  9:55           ` Dor Laor

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=46EC11AE.9090408@hupie.com \
    --to=ferry-nbsvjix5b8qavxtiumwx3w@public.gmane.org \
    --cc=kvm-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox