public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
From: Asias He <asias.hejun@gmail.com>
To: Pekka Enberg <penberg@kernel.org>
Cc: Cyrill Gorcunov <gorcunov@gmail.com>, Ingo Molnar <mingo@elte.hu>,
	Sasha Levin <levinsasha928@gmail.com>,
	Prasad Joshi <prasadjoshi124@gmail.com>,
	kvm@vger.kernel.org, Asias He <asias.hejun@gmail.com>
Subject: [PATCH 07/16] kvm tools: Fill all DHCP options
Date: Sun, 17 Jul 2011 16:56:55 +0800	[thread overview]
Message-ID: <1310893024-21615-8-git-send-email-asias.hejun@gmail.com> (raw)
In-Reply-To: <1310893024-21615-1-git-send-email-asias.hejun@gmail.com>

The following DHCP options are filled.

   - MSG_TYPE

   - SERVER_ID

   - LEASE_TIME

   - SUBMASK

   - ROUTER

   - DNS_SERVER

   - DOMAIN_NAME

Signed-off-by: Asias He <asias.hejun@gmail.com>
---
 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;
+}
-- 
1.7.5.4


  parent reply	other threads:[~2011-07-17  8:59 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-07-17  8:56 [PATCH 00/16] Implement DHCP support for user mode network Asias He
2011-07-17  8:56 ` [PATCH 01/16] kvm tools: Introduce uip_udp_make_pkg() Asias He
2011-07-17  8:56 ` [PATCH 02/16] kvm tools: Introduce struct uip_dhcp Asias He
2011-07-17  8:56 ` [PATCH 03/16] kvm tools: Add helper to tell if a UDP package is a DHCP package Asias He
2011-07-17  8:56 ` [PATCH 04/16] kvm tools: Add helpers to tell the type of a DHCP message Asias He
2011-07-17  8:56 ` [PATCH 05/16] kvm tools: Get domain name and nameserver from host Asias He
2011-07-17  9:36   ` Sasha Levin
2011-07-18  4:48     ` Asias He
2011-07-18  8:27       ` Pekka Enberg
2011-07-17  8:56 ` [PATCH 06/16] kvm tools: Fill DHCP options with domain name and DNS server IP Asias He
2011-07-17  8:56 ` Asias He [this message]
2011-07-17  8:56 ` [PATCH 08/16] kvm tools: Introduce uip_dhcp_make_pkg() Asias He
2011-07-17  8:56 ` [PATCH 09/16] kvm tools: Introduce uip_tx_do_ipv4_udp_dhcp() Asias He
2011-07-17  8:56 ` [PATCH 10/16] kvm tools: Get DNS information from host in uip_init() Asias He
2011-07-17  8:56 ` [PATCH 11/16] kvm tools: Handle DHCP package in gernal UDP processing path Asias He
2011-07-17  8:57 ` [PATCH 12/16] kvm tools: Introduce --guest-ip option Asias He
2011-07-17  8:57 ` [PATCH 13/16] kvm tools: Introduce --host-mac option Asias He
2011-07-17  8:57 ` [PATCH 14/16] kvm tools: Rename --host-ip-addr to --host-ip Asias He
2011-07-17  8:57 ` [PATCH 15/16] kvm tools: Initialize MAC address for virtio net properly Asias He
2011-07-17  8:57 ` [PATCH 16/16] kvm tools: Initialize MAC and IP address for uip properly Asias He
2011-07-18 10:20 ` [PATCH 00/16] Implement DHCP support for user mode network Pekka Enberg

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1310893024-21615-8-git-send-email-asias.hejun@gmail.com \
    --to=asias.hejun@gmail.com \
    --cc=gorcunov@gmail.com \
    --cc=kvm@vger.kernel.org \
    --cc=levinsasha928@gmail.com \
    --cc=mingo@elte.hu \
    --cc=penberg@kernel.org \
    --cc=prasadjoshi124@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox