From patchwork Sun Jul 17 08:56:57 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Asias He X-Patchwork-Id: 982972 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 p6H8xW25023627 for ; Sun, 17 Jul 2011 08:59:33 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754108Ab1GQI7b (ORCPT ); Sun, 17 Jul 2011 04:59:31 -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 S1754101Ab1GQI7a (ORCPT ); Sun, 17 Jul 2011 04:59:30 -0400 Received: by mail-iy0-f174.google.com with SMTP id 12so2303241iyb.19 for ; Sun, 17 Jul 2011 01:59:29 -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=w4W7LSfkzntdFi1MnKRRVZX9Qk+Z/vGExsr38tWxwFE=; b=hxtgM7kkT90vO+Fl3Yi5JCO1XIK1n+3DOtcYd3GxUNmiMLcVWfK644DBcNrSp5cPZn TqnSbq9IGMWVf6qoU1LduLUB30/nKTiCS5mYqbayMkR3Md4cQAkSspDvtO3dAAOLORrv wBs5lIpbdlUOV/JWLhmTk+DwK4lZZTcnc8sBI= Received: by 10.42.115.68 with SMTP id j4mr5453158icq.78.1310893169865; Sun, 17 Jul 2011 01:59:29 -0700 (PDT) Received: from localhost.localdomain ([219.224.169.130]) by mx.google.com with ESMTPS id us2sm3593680icb.19.2011.07.17.01.59.26 (version=TLSv1/SSLv3 cipher=OTHER); Sun, 17 Jul 2011 01:59:29 -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 09/16] kvm tools: Introduce uip_tx_do_ipv4_udp_dhcp() Date: Sun, 17 Jul 2011 16:56:57 +0800 Message-Id: <1310893024-21615-10-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:33 +0000 (UTC) uip_tx_do_ipv4_udp_dhcp() is used to handle DHCP packages from guest. Signed-off-by: Asias He --- tools/kvm/include/kvm/uip.h | 4 ++++ tools/kvm/net/uip/dhcp.c | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 0 deletions(-) diff --git a/tools/kvm/include/kvm/uip.h b/tools/kvm/include/kvm/uip.h index e6b1285..344ec09 100644 --- a/tools/kvm/include/kvm/uip.h +++ b/tools/kvm/include/kvm/uip.h @@ -29,6 +29,8 @@ #define UIP_TCP_FLAG_ACK 16 #define UIP_TCP_FLAG_URG 32 +#define UIP_BOOTP_VENDOR_SPECIFIC_LEN 64 +#define UIP_BOOTP_MAX_PAYLOAD_LEN 300 #define UIP_DHCP_VENDOR_SPECIFIC_LEN 312 #define UIP_DHCP_PORT_SERVER 67 #define UIP_DHCP_PORT_CLIENT 68 @@ -38,6 +40,7 @@ #define UIP_DHCP_MAGIC_COOKIE 0x63825363 #define UIP_DHCP_MAGIC_COOKIE_LEN 4 #define UIP_DHCP_LEASE_TIME 0x00003840 +#define UIP_DHCP_MAX_PAYLOAD_LEN (UIP_BOOTP_MAX_PAYLOAD_LEN - UIP_BOOTP_VENDOR_SPECIFIC_LEN + UIP_DHCP_VENDOR_SPECIFIC_LEN) #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 @@ -328,6 +331,7 @@ int uip_tx(struct iovec *iov, u16 out, struct uip_info *info); int uip_rx(struct iovec *iov, u16 in, struct uip_info *info); int uip_init(struct uip_info *info); +int uip_tx_do_ipv4_udp_dhcp(struct uip_tx_arg *arg); int uip_tx_do_ipv4_icmp(struct uip_tx_arg *arg); int uip_tx_do_ipv4_tcp(struct uip_tx_arg *arg); int uip_tx_do_ipv4_udp(struct uip_tx_arg *arg); diff --git a/tools/kvm/net/uip/dhcp.c b/tools/kvm/net/uip/dhcp.c index 612e024..865b376 100644 --- a/tools/kvm/net/uip/dhcp.c +++ b/tools/kvm/net/uip/dhcp.c @@ -154,3 +154,41 @@ static int uip_dhcp_make_pkg(struct uip_info *info, struct uip_udp_socket *sk, s return 0; } + +int uip_tx_do_ipv4_udp_dhcp(struct uip_tx_arg *arg) +{ + struct uip_udp_socket sk; + struct uip_dhcp *dhcp; + struct uip_info *info; + struct uip_buf *buf; + u8 reply_msg_type; + + dhcp = (struct uip_dhcp *)arg->eth; + + if (uip_dhcp_is_discovery(dhcp)) + reply_msg_type = UIP_DHCP_OFFER; + else if (uip_dhcp_is_request(dhcp)) + reply_msg_type = UIP_DHCP_ACK; + else + return -1; + + buf = uip_buf_clone(arg); + info = arg->info; + + /* + * Cook DHCP pkg + */ + uip_dhcp_make_pkg(info, &sk, buf, reply_msg_type); + + /* + * Cook UDP pkg + */ + uip_udp_make_pkg(info, &sk, buf, NULL, UIP_DHCP_MAX_PAYLOAD_LEN); + + /* + * Send data received from socket to guest + */ + uip_buf_set_used(info, buf); + + return 0; +}