From patchwork Thu Jun 30 08:40:51 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Asias He X-Patchwork-Id: 932192 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 p5U8iM5q029005 for ; Thu, 30 Jun 2011 08:44:23 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1758125Ab1F3IoL (ORCPT ); Thu, 30 Jun 2011 04:44:11 -0400 Received: from mail-iy0-f174.google.com ([209.85.210.174]:59621 "EHLO mail-iy0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1757922Ab1F3IoA (ORCPT ); Thu, 30 Jun 2011 04:44:00 -0400 Received: by mail-iy0-f174.google.com with SMTP id 12so1722525iyb.19 for ; Thu, 30 Jun 2011 01:44:00 -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=zzt3Vtcp087B+C5CM4JiypC2D2UvSCRIDS6pJdT5Vqc=; b=xAgkH05NYgxYD195D1aUneZHQ9idvuzfMr/NTuuiJGyd5/ZirO9cfUtjJdkAMtce96 XB6mPaUtv4RovxOLcc6hMYh1wrL3WpU4d7Km7/he7GOSOnPvlOUcJHMWkkQJIFBpVfQR +Sf2fCeCopijFOPHCUnsfEkSlRDY1Z7iMgj/s= Received: by 10.42.197.199 with SMTP id el7mr1793835icb.237.1309423439863; Thu, 30 Jun 2011 01:43:59 -0700 (PDT) Received: from localhost.localdomain ([219.224.169.130]) by mx.google.com with ESMTPS id d6sm1967338icx.1.2011.06.30.01.43.55 (version=TLSv1/SSLv3 cipher=OTHER); Thu, 30 Jun 2011 01:43:59 -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 03/31] kvm tools: Add IPV4 support for uip Date: Thu, 30 Jun 2011 16:40:51 +0800 Message-Id: <1309423279-3093-4-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:23 +0000 (UTC) - Introduce struct uip_ip to present IP package - Add a helper uip_ip_len() to return totoal length of a IP package - Add a helper uip_ip_hdrlen() to return the IP header length - Currently, uip does not support IP options Drop IP package if IP header length is not 20 bytes which means it contains IP options. Signed-off-by: Asias He --- tools/kvm/Makefile | 1 + tools/kvm/include/kvm/uip.h | 28 ++++++++++++++++++++++++++++ tools/kvm/uip/ipv4.c | 15 +++++++++++++++ 3 files changed, 44 insertions(+), 0 deletions(-) create mode 100644 tools/kvm/uip/ipv4.c diff --git a/tools/kvm/Makefile b/tools/kvm/Makefile index 006218d..7dc5bb2 100644 --- a/tools/kvm/Makefile +++ b/tools/kvm/Makefile @@ -46,6 +46,7 @@ OBJS += disk/raw.o OBJS += ioeventfd.o OBJS += irq.o OBJS += uip/arp.o +OBJS += uip/ipv4.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 c5eb417..e48420d 100644 --- a/tools/kvm/include/kvm/uip.h +++ b/tools/kvm/include/kvm/uip.h @@ -34,6 +34,23 @@ struct uip_arp { u32 dip; } __attribute__((packed)); +struct uip_ip { + struct uip_eth eth; + u8 vhl; + u8 tos; + /* + * len = IP hdr + IP payload + */ + u16 len; + u16 id; + u16 flgfrag; + u8 ttl; + u8 proto; + u16 csum; + u32 sip; + u32 dip; +} __attribute__((packed)); + struct uip_info { struct list_head udp_socket_head; struct list_head tcp_socket_head; @@ -73,6 +90,17 @@ struct uip_tx_arg { int eth_len; }; +static inline u16 uip_ip_hdrlen(struct uip_ip *ip) +{ + return (ip->vhl & 0x0f) * 4; +} + +static inline u16 uip_ip_len(struct uip_ip *ip) +{ + return htons(ip->len); +} + +int uip_tx_do_ipv4(struct uip_tx_arg *arg); 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); diff --git a/tools/kvm/uip/ipv4.c b/tools/kvm/uip/ipv4.c new file mode 100644 index 0000000..da53fec --- /dev/null +++ b/tools/kvm/uip/ipv4.c @@ -0,0 +1,15 @@ +#include "kvm/uip.h" + +int uip_tx_do_ipv4(struct uip_tx_arg *arg) +{ + struct uip_ip *ip; + + ip = (struct uip_ip *)(arg->eth); + + if (uip_ip_hdrlen(ip) != 20) { + pr_warning("IP header length is not 20 bytes"); + return -1; + } + + return 0; +}