@@ -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
@@ -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);
new file mode 100644
@@ -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;
+}
- 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