]> git.karo-electronics.de Git - karo-tx-linux.git/commitdiff
kvm tools: Add IPV4 support for uip
authorAsias He <asias.hejun@gmail.com>
Wed, 29 Jun 2011 08:47:08 +0000 (16:47 +0800)
committerPekka Enberg <penberg@kernel.org>
Thu, 30 Jun 2011 07:41:49 +0000 (10:41 +0300)
- 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>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
tools/kvm/Makefile
tools/kvm/include/kvm/uip.h
tools/kvm/uip/ipv4.c [new file with mode: 0644]

index 006218d736bc4f43d8c92600f83bb7eea8144cd9..7dc5bb2ebe320f1122815bf85a08d804da285f9e 100644 (file)
@@ -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
index c5eb4172206a76987654506ec5297ce55c386a43..e48420d8ec1d9f54df09904dc366f2c67d2680a5 100644 (file)
@@ -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 (file)
index 0000000..da53fec
--- /dev/null
@@ -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;
+}