From patchwork Sun Jul 17 08:56:54 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Asias He X-Patchwork-Id: 982942 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 p6H8xQuM023048 for ; Sun, 17 Jul 2011 08:59:26 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753944Ab1GQI7W (ORCPT ); Sun, 17 Jul 2011 04:59:22 -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 S1753731Ab1GQI7U (ORCPT ); Sun, 17 Jul 2011 04:59:20 -0400 Received: by mail-iw0-f174.google.com with SMTP id 6so2294615iwn.19 for ; Sun, 17 Jul 2011 01:59:20 -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=oLm+uPUtD0m0sB0a6MqdOlVkOkTyCuD1ktPxEYL88nU=; b=jLjZ0VvOqLrOPoyhuKVCeiFIR4Md4IjvaI8VUXljgSZmtrIWOPgHRM0D4V6NhOTtO5 WhtH5JK8XFFp5i2FqYPokNqhHusVdIlnwFmTI+op6SV8bsZl1Zu6qJLIynvwl5Z9z97Y u/Ejb9Rlj/ar7k6TeHJd/wPe6nRgVcpzIqQhc= Received: by 10.42.155.200 with SMTP id v8mr5765688icw.130.1310893159967; Sun, 17 Jul 2011 01:59:19 -0700 (PDT) Received: from localhost.localdomain ([219.224.169.130]) by mx.google.com with ESMTPS id us2sm3593680icb.19.2011.07.17.01.59.17 (version=TLSv1/SSLv3 cipher=OTHER); Sun, 17 Jul 2011 01:59:19 -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 06/16] kvm tools: Fill DHCP options with domain name and DNS server IP Date: Sun, 17 Jul 2011 16:56:54 +0800 Message-Id: <1310893024-21615-7-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:26 +0000 (UTC) Domain name and DNS server IP address are filled. Signed-off-by: Asias He --- tools/kvm/include/kvm/uip.h | 4 ++++ tools/kvm/net/uip/dhcp.c | 27 +++++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 0 deletions(-) diff --git a/tools/kvm/include/kvm/uip.h b/tools/kvm/include/kvm/uip.h index e645d3f..2586583 100644 --- a/tools/kvm/include/kvm/uip.h +++ b/tools/kvm/include/kvm/uip.h @@ -46,6 +46,10 @@ #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_DNS_SERVER 6 +#define UIP_DHCP_TAG_DNS_SERVER_LEN 4 +#define UIP_DHCP_TAG_DOMAIN_NAME 15 + /* * 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 9321cdc..79ddd00 100644 --- a/tools/kvm/net/uip/dhcp.c +++ b/tools/kvm/net/uip/dhcp.c @@ -63,3 +63,30 @@ out: fclose(fp); return ret; } + +static int uip_dhcp_fill_option_name_and_server(struct uip_info *info, u8 *opt, int i) +{ + u8 domain_name_len; + u32 *addr; + int n; + + if (info->domain_name) { + domain_name_len = strlen(info->domain_name); + opt[i++] = UIP_DHCP_TAG_DOMAIN_NAME; + opt[i++] = domain_name_len; + memcpy(&opt[i], info->domain_name, domain_name_len); + i += domain_name_len; + } + + for (n = 0; n < UIP_DHCP_MAX_DNS_SERVER_NR; n++) { + if (info->dns_ip[n] == 0) + continue; + opt[i++] = UIP_DHCP_TAG_DNS_SERVER; + opt[i++] = UIP_DHCP_TAG_DNS_SERVER_LEN; + addr = (u32 *)&opt[i]; + *addr = htonl(info->dns_ip[n]); + i += UIP_DHCP_TAG_DNS_SERVER_LEN; + } + + return i; +}