From patchwork Sun Jul 17 08:56:55 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Asias He X-Patchwork-Id: 982952 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 p6H8xUB1023062 for ; Sun, 17 Jul 2011 08:59:30 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753975Ab1GQI70 (ORCPT ); Sun, 17 Jul 2011 04:59:26 -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 S1753731Ab1GQI7X (ORCPT ); Sun, 17 Jul 2011 04:59:23 -0400 Received: by mail-iy0-f174.google.com with SMTP id 12so2303241iyb.19 for ; Sun, 17 Jul 2011 01:59:23 -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=FWUmzPipbMmSIT8dAAZjMfFvJfVOMrU9LSyTsvJvcCs=; b=Jz6D3LM4FcJA2qaOAEGcsmtUkV81aYszVHfiOfWlFmRDStMgq/NKcQgaS9AJ9f76ZR s2CmAyGwZ07Uq/W38Gqg82gSLlOOl5/M9W+lLT8DKkFhLiwmHBjRDXjxTAGJ2+2cbiQp 92nWq7O+5I59XXbGw3AbjUXZksbAkdRO7aHX0= Received: by 10.43.44.6 with SMTP id ue6mr5979777icb.469.1310893163193; Sun, 17 Jul 2011 01:59:23 -0700 (PDT) Received: from localhost.localdomain ([219.224.169.130]) by mx.google.com with ESMTPS id us2sm3593680icb.19.2011.07.17.01.59.20 (version=TLSv1/SSLv3 cipher=OTHER); Sun, 17 Jul 2011 01:59:22 -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 07/16] kvm tools: Fill all DHCP options Date: Sun, 17 Jul 2011 16:56:55 +0800 Message-Id: <1310893024-21615-8-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:30 +0000 (UTC) The following DHCP options are filled. - MSG_TYPE - SERVER_ID - LEASE_TIME - SUBMASK - ROUTER - DNS_SERVER - DOMAIN_NAME Signed-off-by: Asias He --- tools/kvm/include/kvm/uip.h | 12 ++++++++++++ tools/kvm/net/uip/dhcp.c | 42 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+), 0 deletions(-) diff --git a/tools/kvm/include/kvm/uip.h b/tools/kvm/include/kvm/uip.h index 2586583..e6b1285 100644 --- a/tools/kvm/include/kvm/uip.h +++ b/tools/kvm/include/kvm/uip.h @@ -37,6 +37,7 @@ #define UIP_DHCP_FILENAME_LEN 128 #define UIP_DHCP_MAGIC_COOKIE 0x63825363 #define UIP_DHCP_MAGIC_COOKIE_LEN 4 +#define UIP_DHCP_LEASE_TIME 0x00003840 #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 @@ -46,9 +47,18 @@ #define UIP_DHCP_MAX_DOMAIN_NAME_LEN 256 #define UIP_DHCP_TAG_MSG_TYPE 53 #define UIP_DHCP_TAG_MSG_TYPE_LEN 1 +#define UIP_DHCP_TAG_SERVER_ID 54 +#define UIP_DHCP_TAG_SERVER_ID_LEN 4 +#define UIP_DHCP_TAG_LEASE_TIME 51 +#define UIP_DHCP_TAG_LEASE_TIME_LEN 4 +#define UIP_DHCP_TAG_SUBMASK 1 +#define UIP_DHCP_TAG_SUBMASK_LEN 4 +#define UIP_DHCP_TAG_ROUTER 3 +#define UIP_DHCP_TAG_ROUTER_LEN 4 #define UIP_DHCP_TAG_DNS_SERVER 6 #define UIP_DHCP_TAG_DNS_SERVER_LEN 4 #define UIP_DHCP_TAG_DOMAIN_NAME 15 +#define UIP_DHCP_TAG_END 255 /* * IP package maxium len == 64 KBytes @@ -183,6 +193,8 @@ struct uip_info { int udp_epollfd; int buf_free_nr; int buf_used_nr; + u32 guest_ip; + u32 guest_netmask; u32 host_ip; u32 dns_ip[UIP_DHCP_MAX_DNS_SERVER_NR]; char *domain_name; diff --git a/tools/kvm/net/uip/dhcp.c b/tools/kvm/net/uip/dhcp.c index 79ddd00..42e354c 100644 --- a/tools/kvm/net/uip/dhcp.c +++ b/tools/kvm/net/uip/dhcp.c @@ -90,3 +90,45 @@ static int uip_dhcp_fill_option_name_and_server(struct uip_info *info, u8 *opt, return i; } +static int uip_dhcp_fill_option(struct uip_info *info, struct uip_dhcp *dhcp, int reply_msg_type) +{ + int i = 0; + u32 *addr; + u8 *opt; + + opt = dhcp->option; + + opt[i++] = UIP_DHCP_TAG_MSG_TYPE; + opt[i++] = UIP_DHCP_TAG_MSG_TYPE_LEN; + opt[i++] = reply_msg_type; + + opt[i++] = UIP_DHCP_TAG_SERVER_ID; + opt[i++] = UIP_DHCP_TAG_SERVER_ID_LEN; + addr = (u32 *)&opt[i]; + *addr = htonl(info->host_ip); + i += UIP_DHCP_TAG_SERVER_ID_LEN; + + opt[i++] = UIP_DHCP_TAG_LEASE_TIME; + opt[i++] = UIP_DHCP_TAG_LEASE_TIME_LEN; + addr = (u32 *)&opt[i]; + *addr = htonl(UIP_DHCP_LEASE_TIME); + i += UIP_DHCP_TAG_LEASE_TIME_LEN; + + opt[i++] = UIP_DHCP_TAG_SUBMASK; + opt[i++] = UIP_DHCP_TAG_SUBMASK_LEN; + addr = (u32 *)&opt[i]; + *addr = htonl(info->guest_netmask); + i += UIP_DHCP_TAG_SUBMASK_LEN; + + opt[i++] = UIP_DHCP_TAG_ROUTER; + opt[i++] = UIP_DHCP_TAG_ROUTER_LEN; + addr = (u32 *)&opt[i]; + *addr = htonl(info->host_ip); + i += UIP_DHCP_TAG_ROUTER_LEN; + + i = uip_dhcp_fill_option_name_and_server(info, opt, i); + + opt[i++] = UIP_DHCP_TAG_END; + + return 0; +}