diff mbox

[v2,03/31] kvm tools: Add IPV4 support for uip

Message ID 1309423279-3093-4-git-send-email-asias.hejun@gmail.com (mailing list archive)
State New, archived
Headers show

Commit Message

Asias He June 30, 2011, 8:40 a.m. 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 <asias.hejun@gmail.com>
---
 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 mbox

Patch

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;
+}