From patchwork Thu Jun 30 08:40:50 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Asias He X-Patchwork-Id: 932162 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 p5U8iM5n029005 for ; Thu, 30 Jun 2011 08:44:22 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757351Ab1F3IoE (ORCPT ); Thu, 30 Jun 2011 04:44:04 -0400 Received: from mail-iw0-f174.google.com ([209.85.214.174]:43568 "EHLO mail-iw0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751596Ab1F3Inz (ORCPT ); Thu, 30 Jun 2011 04:43:55 -0400 Received: by iwn6 with SMTP id 6so1718423iwn.19 for ; Thu, 30 Jun 2011 01:43:55 -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=gv1BC70MIeJIbC+cbvuHyjnQ0aD6gIx5kLXG0zAM6Us=; b=NuakWB8Vyly7BKUBLe/La1Lo+d5DbOIytgZev78V0mOaj1lc2bg8W1a95g5c8p0SSF lj2ghrBbAAlP2zyfue94bqy04dYB82BRtkYB3biSbczlM0lJ+tkfhGC23q6AMD/YtbWL W+BIG1IMC88eQsDbTGBHRiWJEpTLGXThR49Ts= Received: by 10.42.174.193 with SMTP id w1mr1657754icz.454.1309423435389; Thu, 30 Jun 2011 01:43:55 -0700 (PDT) Received: from localhost.localdomain ([219.224.169.130]) by mx.google.com with ESMTPS id d6sm1967338icx.1.2011.06.30.01.43.51 (version=TLSv1/SSLv3 cipher=OTHER); Thu, 30 Jun 2011 01:43:54 -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 v2 02/31] kvm tools: Add ARP support for uip Date: Thu, 30 Jun 2011 16:40:50 +0800 Message-Id: <1309423279-3093-3-git-send-email-asias.hejun@gmail.com> X-Mailer: git-send-email 1.7.5.4 In-Reply-To: <1309423279-3093-1-git-send-email-asias.hejun@gmail.com> References: <1309423279-3093-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]); Thu, 30 Jun 2011 08:44:22 +0000 (UTC) - Introduce struct uip_arp to present ARP package - uip_tx_do_arp() Clone incoming ARP ethernet frame, if ARP is requesting host IP address, tell guest host MAC address. Signed-off-by: Asias He --- tools/kvm/Makefile | 1 + tools/kvm/include/kvm/uip.h | 15 +++++++++++++++ tools/kvm/uip/arp.c | 30 ++++++++++++++++++++++++++++++ 3 files changed, 46 insertions(+), 0 deletions(-) create mode 100644 tools/kvm/uip/arp.c diff --git a/tools/kvm/Makefile b/tools/kvm/Makefile index 91539de..006218d 100644 --- a/tools/kvm/Makefile +++ b/tools/kvm/Makefile @@ -45,6 +45,7 @@ OBJS += disk/qcow.o OBJS += disk/raw.o OBJS += ioeventfd.o OBJS += irq.o +OBJS += uip/arp.o OBJS += uip/buf.o OBJS += kvm-cmd.o OBJS += kvm-debug.o diff --git a/tools/kvm/include/kvm/uip.h b/tools/kvm/include/kvm/uip.h index 32a5da3..c5eb417 100644 --- a/tools/kvm/include/kvm/uip.h +++ b/tools/kvm/include/kvm/uip.h @@ -21,6 +21,19 @@ struct uip_eth { u16 type; } __attribute__((packed)); +struct uip_arp { + struct uip_eth eth; + u16 hwtype; + u16 proto; + u8 hwlen; + u8 protolen; + u16 op; + struct uip_eth_addr smac; + u32 sip; + struct uip_eth_addr dmac; + u32 dip; +} __attribute__((packed)); + struct uip_info { struct list_head udp_socket_head; struct list_head tcp_socket_head; @@ -60,6 +73,8 @@ struct uip_tx_arg { int eth_len; }; +int uip_tx_do_arp(struct uip_tx_arg *arg); + struct uip_buf *uip_buf_set_used(struct uip_info *info, struct uip_buf *buf); struct uip_buf *uip_buf_set_free(struct uip_info *info, struct uip_buf *buf); struct uip_buf *uip_buf_get_used(struct uip_info *info); diff --git a/tools/kvm/uip/arp.c b/tools/kvm/uip/arp.c new file mode 100644 index 0000000..98423da --- /dev/null +++ b/tools/kvm/uip/arp.c @@ -0,0 +1,30 @@ +#include "kvm/uip.h" + +int uip_tx_do_arp(struct uip_tx_arg *arg) +{ + struct uip_arp *arp, *arp2; + struct uip_info *info; + struct uip_buf *buf; + + info = arg->info; + buf = uip_buf_clone(arg); + + arp = (struct uip_arp *)(arg->eth); + arp2 = (struct uip_arp *)(buf->eth); + + /* + * ARP replay code: 2 + */ + arp2->op = htons(0x2); + arp2->dmac = arp->smac; + arp2->dip = arp->sip; + + if (arp->dip == htonl(info->host_ip)) { + arp2->smac = info->host_mac; + arp2->sip = htonl(info->host_ip); + + uip_buf_set_used(info, buf); + } + + return 0; +}