From 6f17bcbeb3a18ac84e9c5e707a1cb45dfb6c1d9a Mon Sep 17 00:00:00 2001 From: Asias He Date: Wed, 29 Jun 2011 16:47:08 +0800 Subject: [PATCH] kvm tools: Add IPV4 support for uip - 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 Signed-off-by: Pekka Enberg --- tools/kvm/Makefile | 1 + tools/kvm/include/kvm/uip.h | 28 ++++++++++++++++++++++++++++ tools/kvm/uip/ipv4.c | 15 +++++++++++++++ 3 files changed, 44 insertions(+) create mode 100644 tools/kvm/uip/ipv4.c diff --git a/tools/kvm/Makefile b/tools/kvm/Makefile index 006218d736bc..7dc5bb2ebe32 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 c5eb4172206a..e48420d8ec1d 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 000000000000..da53fecdec6b --- /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; +} -- 2.39.5