From mboxrd@z Thu Jan 1 00:00:00 1970 From: Amos Kong Subject: [Autotest PATCH] virt: Only update macaddr cache when capture dhcp ACK packet Date: Thu, 29 Sep 2011 17:57:19 +0800 Message-ID: <20110929095719.20712.71205.stgit@t> Mime-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Cc: jasowang@redhat.com, kvm@vger.kernel.org To: lmr@redhat.com Return-path: Received: from mx1.redhat.com ([209.132.183.28]:32115 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752030Ab1I2J4J (ORCPT ); Thu, 29 Sep 2011 05:56:09 -0400 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id p8T9u9SC019151 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Thu, 29 Sep 2011 05:56:09 -0400 Sender: kvm-owner@vger.kernel.org List-ID: Currently, tcpdump can capture both dhcp Offer and ACK packets, macaddr cache will be updated in those to condition, dhcp Offer packet doesn't mean the IP is already allocated to dhcp client. Signed-off-by: Amos Kong --- client/virt/virt_env_process.py | 10 ++++++++-- 1 files changed, 8 insertions(+), 2 deletions(-) diff --git a/client/virt/virt_env_process.py b/client/virt/virt_env_process.py index 51c7e8a..a7621bb 100644 --- a/client/virt/virt_env_process.py +++ b/client/virt/virt_env_process.py @@ -403,14 +403,20 @@ def _update_address_cache(address_cache, line): address_cache["last_seen"] = matches[0] if re.search("Client.Ethernet.Address", line, re.IGNORECASE): matches = re.findall(r"\w*:\w*:\w*:\w*:\w*:\w*", line) - if matches and address_cache.get("last_seen"): - mac_address = matches[0].lower() + if matches: + address_cache["last_mac"] = matches[0] + if re.search("DHCP-Message", line, re.IGNORECASE): + matches = re.findall(r"ACK", line) + if matches and address_cache.get("last_seen") and address_cache.get( + "last_mac"): + mac_address = address_cache.get("last_mac").lower() if time.time() - address_cache.get("time_%s" % mac_address, 0) > 5: logging.debug("(address cache) Adding cache entry: %s ---> %s", mac_address, address_cache.get("last_seen")) address_cache[mac_address] = address_cache.get("last_seen") address_cache["time_%s" % mac_address] = time.time() del address_cache["last_seen"] + del address_cache["last_mac"] def _take_screendumps(test, params, env):