From patchwork Sun Jul 17 08:56:51 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Asias He X-Patchwork-Id: 982912 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter2.kernel.org (8.14.4/8.14.4) with ESMTP id p6H8xISB023321 for ; Sun, 17 Jul 2011 08:59:19 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753552Ab1GQI7M (ORCPT ); Sun, 17 Jul 2011 04:59:12 -0400 Received: from mail-iw0-f174.google.com ([209.85.214.174]:63499 "EHLO mail-iw0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752890Ab1GQI7K (ORCPT ); Sun, 17 Jul 2011 04:59:10 -0400 Received: by mail-iw0-f174.google.com with SMTP id 6so2294615iwn.19 for ; Sun, 17 Jul 2011 01:59:10 -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=HIbLZ0YPJX5yT8pqtS/FsGv3MlTGhSuMBGn9GETp1I4=; b=LR5dxLL5QVr+XZdSo86ZHuu2NIwxugq2KbkGSCF/+qlFJMNVI6ncKg6ZENSkfPi/3z RHxSlh+2FXgUINiJxTzy7khyP2xhllmJ/sYSgVWe0m6yD34ulwYVaxzqCOGO5IKHAB70 5E0FTQkvxH5YC+TTUKA9nbooNlb2RvEr5zMZM= Received: by 10.43.47.1 with SMTP id uq1mr6006609icb.134.1310893150205; Sun, 17 Jul 2011 01:59:10 -0700 (PDT) Received: from localhost.localdomain ([219.224.169.130]) by mx.google.com with ESMTPS id us2sm3593680icb.19.2011.07.17.01.59.07 (version=TLSv1/SSLv3 cipher=OTHER); Sun, 17 Jul 2011 01:59:09 -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 03/16] kvm tools: Add helper to tell if a UDP package is a DHCP package Date: Sun, 17 Jul 2011 16:56:51 +0800 Message-Id: <1310893024-21615-4-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 (demeter2.kernel.org [140.211.167.43]); Sun, 17 Jul 2011 08:59:19 +0000 (UTC) This patch checks: - sport and dport - magic cookie to detemine whether a UDP package is a DHCP package. Signed-off-by: Asias He --- tools/kvm/Makefile | 1 + tools/kvm/include/kvm/uip.h | 4 ++++ tools/kvm/net/uip/dhcp.c | 17 +++++++++++++++++ 3 files changed, 22 insertions(+), 0 deletions(-) create mode 100644 tools/kvm/net/uip/dhcp.c diff --git a/tools/kvm/Makefile b/tools/kvm/Makefile index 5d04377..b5c5516 100644 --- a/tools/kvm/Makefile +++ b/tools/kvm/Makefile @@ -61,6 +61,7 @@ OBJS += net/uip/tcp.o OBJS += net/uip/udp.o OBJS += net/uip/buf.o OBJS += net/uip/csum.o +OBJS += net/uip/dhcp.o OBJS += kvm-cmd.o OBJS += mptable.o OBJS += rbtree.o diff --git a/tools/kvm/include/kvm/uip.h b/tools/kvm/include/kvm/uip.h index c414267..7c84dea 100644 --- a/tools/kvm/include/kvm/uip.h +++ b/tools/kvm/include/kvm/uip.h @@ -30,9 +30,12 @@ #define UIP_TCP_FLAG_URG 32 #define UIP_DHCP_VENDOR_SPECIFIC_LEN 312 +#define UIP_DHCP_PORT_SERVER 67 +#define UIP_DHCP_PORT_CLIENT 68 #define UIP_DHCP_MACPAD_LEN 10 #define UIP_DHCP_HOSTNAME_LEN 64 #define UIP_DHCP_FILENAME_LEN 128 +#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) /* @@ -317,4 +320,5 @@ struct uip_buf *uip_buf_get_free(struct uip_info *info); struct uip_buf *uip_buf_clone(struct uip_tx_arg *arg); int uip_udp_make_pkg(struct uip_info *info, struct uip_udp_socket *sk, struct uip_buf *buf, u8 *payload, int payload_len); +bool uip_udp_is_dhcp(struct uip_udp *udp); #endif /* KVM__UIP_H */ diff --git a/tools/kvm/net/uip/dhcp.c b/tools/kvm/net/uip/dhcp.c new file mode 100644 index 0000000..af0407f --- /dev/null +++ b/tools/kvm/net/uip/dhcp.c @@ -0,0 +1,17 @@ +#include "kvm/uip.h" + +bool uip_udp_is_dhcp(struct uip_udp *udp) +{ + struct uip_dhcp *dhcp; + + if (ntohs(udp->sport) != UIP_DHCP_PORT_CLIENT || + ntohs(udp->dport) != UIP_DHCP_PORT_SERVER) + return false; + + dhcp = (struct uip_dhcp *)udp; + + if (ntohl(dhcp->magic_cookie) != UIP_DHCP_MAGIC_COOKIE) + return false; + + return true; +}