@@ -48,6 +48,7 @@ OBJS += irq.o
OBJS += uip/arp.o
OBJS += uip/ipv4.o
OBJS += uip/buf.o
+OBJS += uip/csum.o
OBJS += kvm-cmd.o
OBJS += kvm-debug.o
OBJS += kvm-help.o
@@ -103,6 +103,8 @@ static inline u16 uip_ip_len(struct uip_ip *ip)
int uip_tx_do_ipv4(struct uip_tx_arg *arg);
int uip_tx_do_arp(struct uip_tx_arg *arg);
+u16 uip_csum_ip(struct uip_ip *ip);
+
struct uip_buf *uip_buf_set_used(struct uip_info *info, struct uip_buf *buf);
struct uip_buf *uip_buf_set_free(struct uip_info *info, struct uip_buf *buf);
struct uip_buf *uip_buf_get_used(struct uip_info *info);
new file mode 100644
@@ -0,0 +1,25 @@
+#include "kvm/uip.h"
+
+static u16 uip_csum(u16 csum, u8 *addr, u16 count)
+{
+ long sum = csum;
+
+ while (count > 1) {
+ sum += *(u16 *)addr;
+ addr += 2;
+ count -= 2;
+ }
+
+ if (count > 0)
+ sum += *(unsigned char *)addr;
+
+ while (sum>>16)
+ sum = (sum & 0xffff) + (sum >> 16);
+
+ return ~sum;
+}
+
+u16 uip_csum_ip(struct uip_ip *ip)
+{
+ return uip_csum(0, &ip->vhl, uip_ip_hdrlen(ip));
+}
Other protocal, e.g. TCP, UDP, ICMP, can use uip_csum() to make checsksum as well. Signed-off-by: Asias He <asias.hejun@gmail.com> --- tools/kvm/Makefile | 1 + tools/kvm/include/kvm/uip.h | 2 ++ tools/kvm/uip/csum.c | 25 +++++++++++++++++++++++++ 3 files changed, 28 insertions(+), 0 deletions(-) create mode 100644 tools/kvm/uip/csum.c