make kvm service script transfer dhclient settings correctly
PATCH 1/1 make kvm service script transfer dhclient settings correctly
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 renamed from kvm.org +40 -2
@@ -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
etc/init.d/kvm 2007-07-05 21:06:43.000000000 +0200 renamed from kvm 2007-06-07 17:13:47.000000000 +0200 +1 -1
@@ -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 [email protected]
https://lists.sourceforge.net/lists/listinfo/kvm-devel
A message that is not in the archive (sent off-list or not yet received): [email protected]
Quoted 22 lines · Ferry Huberts
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.
Quoted 7 lines
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 :-)
I really recommend against using the kvm initscript... it is fragile is broken. On Fedora, you can use the standard initscripts (well, they are fragile and broken too, but they are more complete than the kvm initscript):
[avi@blast ~]$ cat /etc/sysconfig/network-scripts/ifcfg-sw0 DEVICE=sw0
BOOTPROTO=dhcp
HWADDR=00:0F:EA:6E:1E:F0
ONBOOT=yes
TYPE=Bridge
DHCP_HOSTNAME=blast
[avi@blast ~]$ cat /etc/sysconfig/network-scripts/ifcfg-eth0 DEVICE=eth0
BRIDGE=sw0
HWADDR=00:0F:EA:6E:1E:F0
ONBOOT=yes
TYPE=Ethernet
This setup starts dhcp directly on the bridge, without the need to move things around. See especially the 'TYPE=Bridge' and 'BRIDGE=sw0' statements.
Is there a reason to use the kvm initscript instead of this?
Signature · 7 lines
error compiling committee.c: too many arguments to function ------------------------------------------------------------------------- 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/
A message that is not in the archive (sent off-list or not yet received): 46ECF4E2.9000203-atKUWr5tajBWk0Htik3J/[email protected]
Quoted 54 lines · Avi Kivity
Quoted 22 lines · Ferry Huberts
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.
Quoted 8 lines
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 :-)
I really recommend against using the kvm initscript... it is fragile is broken. On Fedora, you can use the standard initscripts (well, they are fragile and broken too, but they are more complete than the kvm initscript):
[avi@blast ~]$ cat
/etc/sysconfig/network-scripts/ifcfg-sw0DEVICE=sw0
BOOTPROTO=dhcp
HWADDR=00:0F:EA:6E:1E:F0
ONBOOT=yes
TYPE=Bridge
DHCP_HOSTNAME=blast[avi@blast ~]$ cat
/etc/sysconfig/network-scripts/ifcfg-eth0DEVICE=eth0
BRIDGE=sw0
HWADDR=00:0F:EA:6E:1E:F0
ONBOOT=yes
TYPE=Ethernet
Quoted 6 lines
This setup starts dhcp directly on the bridge, without the need to move things around. See especially the 'TYPE=Bridge' and 'BRIDGE=sw0' statements.
Is there a reason to use the kvm initscript instead of this?
no, just thought that since it's included in the kvm distribution I'd use it. Seemed a logical conclusion that this one would be the recommended way to do it. I'll just as happy convert to the distribution scripts now. But maybe it's a good idea then to remove the script and replace it with a text file on how to setup the config files. If you don't remove the script maybe the patch can go in? At least it makes the script more robust than it is.
You seem to use the same MAC address for both your interfaces Avi. Is this on purpose?
Ferry
-------------------------------------------------------------------------
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/
A message that is not in the archive (sent off-list or not yet received): [email protected]
Quoted 61 lines · Ferry Huberts
Quoted 54 lines · Avi Kivity
Quoted 22 lines · Ferry Huberts
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.
Quoted 8 lines
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 :-)
I really recommend against using the kvm initscript... it is fragile is broken. On Fedora, you can use the standard initscripts (well, they are fragile and broken too, but they are more complete than the kvm initscript):
[avi@blast ~]$ cat
/etc/sysconfig/network-scripts/ifcfg-sw0DEVICE=sw0
BOOTPROTO=dhcp
HWADDR=00:0F:EA:6E:1E:F0
ONBOOT=yes
TYPE=Bridge
DHCP_HOSTNAME=blast[avi@blast ~]$ cat
/etc/sysconfig/network-scripts/ifcfg-eth0DEVICE=eth0
BRIDGE=sw0
HWADDR=00:0F:EA:6E:1E:F0
ONBOOT=yes
TYPE=EthernetQuoted 6 lines
This setup starts dhcp directly on the bridge, without the need to move things around. See especially the 'TYPE=Bridge' and 'BRIDGE=sw0' statements.
Is there a reason to use the kvm initscript instead of this?
Quoted 8 lines
no, just thought that since it's included in the kvm distribution I'd use it. Seemed a logical conclusion that this one would be the recommended way to do it. I'll just as happy convert to the distribution scripts now. But maybe it's a good idea then to remove the script and replace it with a text file on how to setup the config files. If you don't remove the script maybe the patch can go in? At least it makes the script more robust than it is.
I'll remove the script unless anyone sees an objection?
Quoted 2 lines
You seem to use the same MAC address for both your interfaces Avi. Is this on purpose?
Not really. I just added lines until it worked. But I think it makes sense -- you need the mac address for eth0 so it can detect the card, and you need one for the switch, and since the real card won't use its address this is a good choice.
Signature · 7 lines
error compiling committee.c: too many arguments to function ------------------------------------------------------------------------- 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/
A message that is not in the archive (sent off-list or not yet received): 46ECFCF8.2020002-atKUWr5tajBWk0Htik3J/[email protected]
Quoted 9 lines · Avi Kivity
Quoted 8 lines · Ferry Huberts
Quoted 7 lines · Avi Kivity
Ferry Huberts wrote:
I really recommend against using the kvm initscript... it is fragile is broken. On Fedora, you can use the standard initscripts (well, they are fragile and broken too, but they are more complete than the kvm initscript):
I entirely agree with your recommendation against using the kvm initscript. We don't include in the Fedora KVM rpms, and the equivalent script shipped with Xen has inflicted untold misery & bug report chaos. Using the distro specific initscripts for setting up bridges is a much more predictable and reliable approach.
Quoted 17 lines
Quoted 17 lines
Quoted 17 lines
[avi@blast ~]$ cat
/etc/sysconfig/network-scripts/ifcfg-sw0DEVICE=sw0
BOOTPROTO=dhcp
HWADDR=00:0F:EA:6E:1E:F0
ONBOOT=yes
TYPE=Bridge
DHCP_HOSTNAME=blast[avi@blast ~]$ cat
/etc/sysconfig/network-scripts/ifcfg-eth0DEVICE=eth0
BRIDGE=sw0
HWADDR=00:0F:EA:6E:1E:F0
ONBOOT=yes
TYPE=Ethernet
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
This setup starts dhcp directly on the bridge, without the need to move things around. See especially the 'TYPE=Bridge' and 'BRIDGE=sw0' statements.
This is similar to the way we document bridge setup in Fedora, although for the sake of consistent nomenculture with Xen, we have peth0 being the physical device & eth0 being the bridge device. Either way its just naming, the end result is functionally the same.
Libvirt also provides a 'virtual network' which is an isolated bridge device, connected to the physical devices using NAT as our 'out of the box' connectivity.
There's a short blog post with recommendations for KVM networking on Fedora
http://watzmann.net/blog/index.php/2007/04/27/networking_with_kvm_and_libvirt
Quoted 1 line
I'll remove the script unless anyone sees an objection?
Gets my vote.
Regards,
Dan.
Signature · 9 lines
|=- Red Hat, Engineering, Emerging Technologies, Boston. +1 978 392 2496 -=| |=- Perl modules: http://search.cpan.org/~danberr/ -=| |=- Projects: http://freshmeat.net/~danielpb/ -=| |=- GnuPG: 7D3B9505 F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 -=| ------------------------------------------------------------------------- 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/
Quoted 39 lines · Ferry Huberts
Quoted 23 lines · Avi Kivity
I really recommend against using the kvm initscript... it is fragile is broken. On Fedora, you can use the standard initscripts (well, they are fragile and broken too, but they are more complete than the kvm initscript):
[avi@blast ~]$ cat
/etc/sysconfig/network-scripts/ifcfg-sw0DEVICE=sw0
BOOTPROTO=dhcp
HWADDR=00:0F:EA:6E:1E:F0
ONBOOT=yes
TYPE=Bridge
DHCP_HOSTNAME=blast[avi@blast ~]$ cat
/etc/sysconfig/network-scripts/ifcfg-eth0DEVICE=eth0
BRIDGE=sw0
HWADDR=00:0F:EA:6E:1E:F0
ONBOOT=yes
TYPE=EthernetQuoted 6 lines
This setup starts dhcp directly on the bridge, without the need to move things around. See especially the 'TYPE=Bridge' and 'BRIDGE=sw0' statements.
Is there a reason to use the kvm initscript instead of this?
no, just thought that since it's included in the kvm distribution I'd use it. Seemed a logical conclusion that this one would be the recommended way to do it. I'll just as happy convert to the distribution scripts now. But maybe it's a good idea then to remove the script and replace it with a text file on how to setup the config files. If you don't remove the script maybe the patch can go in? At least it makes the script more robust than it is.
Quoted 5 lines
You seem to use the same MAC address for both your interfaces Avi. Is this on purpose?
Ferry
Actually the propose was to have a script that can handle both creation of a bridge and bonding together. Last time I checked I couldn't add a bridge over bonding.
It's also nice to have a distribution agnostic script but I agree that we should drop it since the its better to use distribution tools instead.
-------------------------------------------------------------------------
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 [email protected]
https://lists.sourceforge.net/lists/listinfo/kvm-devel