From patchwork Sun Jul 17 08:56:52 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Asias He X-Patchwork-Id: 982922 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter1.kernel.org (8.14.4/8.14.4) with ESMTP id p6H8xN4n023039 for ; Sun, 17 Jul 2011 08:59:23 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753772Ab1GQI7R (ORCPT ); Sun, 17 Jul 2011 04:59:17 -0400 Received: from mail-iy0-f174.google.com ([209.85.210.174]:39735 "EHLO mail-iy0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752130Ab1GQI7N (ORCPT ); Sun, 17 Jul 2011 04:59:13 -0400 Received: by mail-iy0-f174.google.com with SMTP id 12so2303241iyb.19 for ; Sun, 17 Jul 2011 01:59:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references; bh=nKNWkk1VmfJq9TFmtg7Sxb/1UKX1oiw5mKg4MzxdjtA=; b=F4U3Z2dBjFUd3ZH+vj18AdUPgpcVh4niinPbTlqZZxtA6ivzzmAPinv4zd+Zf43avx WTeJKUq5QwhLzdf5TU7ocIJLRrov0C0uzhx9xk4lxsjS1xQb8BAsdF8oSjc4xMW+FGDx H6NHMT6AFm4K01MwtPSb4VTPNv0g8y3RBPsO4= Received: by 10.42.135.194 with SMTP id q2mr5599665ict.63.1310893153433; Sun, 17 Jul 2011 01:59:13 -0700 (PDT) Received: from localhost.localdomain ([219.224.169.130]) by mx.google.com with ESMTPS id us2sm3593680icb.19.2011.07.17.01.59.10 (version=TLSv1/SSLv3 cipher=OTHER); Sun, 17 Jul 2011 01:59:13 -0700 (PDT) From: Asias He To: Pekka Enberg Cc: Cyrill Gorcunov , Ingo Molnar , Sasha Levin , Prasad Joshi , kvm@vger.kernel.org, Asias He Subject: [PATCH 04/16] kvm tools: Add helpers to tell the type of a DHCP message Date: Sun, 17 Jul 2011 16:56:52 +0800 Message-Id: <1310893024-21615-5-git-send-email-asias.hejun@gmail.com> X-Mailer: git-send-email 1.7.5.4 In-Reply-To: <1310893024-21615-1-git-send-email-asias.hejun@gmail.com> References: <1310893024-21615-1-git-send-email-asias.hejun@gmail.com> Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.6 (demeter1.kernel.org [140.211.167.41]); Sun, 17 Jul 2011 08:59:23 +0000 (UTC) If DHCP DISCOVER or DHCP REQUEST is found, reply with DHCP OFFER or DHCP ACK respectively. Signed-off-by: Asias He --- tools/kvm/include/kvm/uip.h | 6 ++++++ tools/kvm/net/uip/dhcp.c | 14 ++++++++++++++ 2 files changed, 20 insertions(+), 0 deletions(-) diff --git a/tools/kvm/include/kvm/uip.h b/tools/kvm/include/kvm/uip.h index 7c84dea..6534c7f 100644 --- a/tools/kvm/include/kvm/uip.h +++ b/tools/kvm/include/kvm/uip.h @@ -38,6 +38,12 @@ #define UIP_DHCP_MAGIC_COOKIE 0x63825363 #define UIP_DHCP_MAGIC_COOKIE_LEN 4 #define UIP_DHCP_OPTION_LEN (UIP_DHCP_VENDOR_SPECIFIC_LEN - UIP_DHCP_MAGIC_COOKIE_LEN) +#define UIP_DHCP_DISCOVER 1 +#define UIP_DHCP_OFFER 2 +#define UIP_DHCP_REQUEST 3 +#define UIP_DHCP_ACK 5 +#define UIP_DHCP_TAG_MSG_TYPE 53 +#define UIP_DHCP_TAG_MSG_TYPE_LEN 1 /* * IP package maxium len == 64 KBytes * IP header == 20 Bytes diff --git a/tools/kvm/net/uip/dhcp.c b/tools/kvm/net/uip/dhcp.c index af0407f..0a6293a 100644 --- a/tools/kvm/net/uip/dhcp.c +++ b/tools/kvm/net/uip/dhcp.c @@ -1,5 +1,19 @@ #include "kvm/uip.h" +static inline bool uip_dhcp_is_discovery(struct uip_dhcp *dhcp) +{ + return (dhcp->option[2] == UIP_DHCP_DISCOVER && + dhcp->option[1] == UIP_DHCP_TAG_MSG_TYPE_LEN && + dhcp->option[0] == UIP_DHCP_TAG_MSG_TYPE); +} + +static inline bool uip_dhcp_is_request(struct uip_dhcp *dhcp) +{ + return (dhcp->option[2] == UIP_DHCP_REQUEST && + dhcp->option[1] == UIP_DHCP_TAG_MSG_TYPE_LEN && + dhcp->option[0] == UIP_DHCP_TAG_MSG_TYPE); +} + bool uip_udp_is_dhcp(struct uip_udp *udp) { struct uip_dhcp *dhcp;