]> git.karo-electronics.de Git - karo-tx-linux.git/commitdiff
kvm tools: Add ARP support for uip
authorAsias He <asias.hejun@gmail.com>
Wed, 29 Jun 2011 08:47:07 +0000 (16:47 +0800)
committerPekka Enberg <penberg@kernel.org>
Thu, 30 Jun 2011 07:41:44 +0000 (10:41 +0300)
- Introduce struct uip_arp to present ARP package
- uip_tx_do_arp()
  Clone incoming ARP ethernet frame, if ARP is requesting
  host IP address, tell guest host MAC address.

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/arp.c [new file with mode: 0644]

index 91539de76234bde1091753d30c17caaede2f6101..006218d736bc4f43d8c92600f83bb7eea8144cd9 100644 (file)
@@ -45,6 +45,7 @@ OBJS  += disk/qcow.o
 OBJS   += disk/raw.o
 OBJS   += ioeventfd.o
 OBJS   += irq.o
+OBJS   += uip/arp.o
 OBJS   += uip/buf.o
 OBJS   += kvm-cmd.o
 OBJS   += kvm-debug.o
index 32a5da365ad56d4221ffea8c1f932b29cc3b3936..c5eb4172206a76987654506ec5297ce55c386a43 100644 (file)
@@ -21,6 +21,19 @@ struct uip_eth {
        u16 type;
 } __attribute__((packed));
 
+struct uip_arp {
+       struct uip_eth eth;
+       u16 hwtype;
+       u16 proto;
+       u8 hwlen;
+       u8 protolen;
+       u16 op;
+       struct uip_eth_addr smac;
+       u32 sip;
+       struct uip_eth_addr dmac;
+       u32 dip;
+} __attribute__((packed));
+
 struct uip_info {
        struct list_head udp_socket_head;
        struct list_head tcp_socket_head;
@@ -60,6 +73,8 @@ struct uip_tx_arg {
        int eth_len;
 };
 
+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);
 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);
diff --git a/tools/kvm/uip/arp.c b/tools/kvm/uip/arp.c
new file mode 100644 (file)
index 0000000..98423da
--- /dev/null
@@ -0,0 +1,30 @@
+#include "kvm/uip.h"
+
+int uip_tx_do_arp(struct uip_tx_arg *arg)
+{
+       struct uip_arp *arp, *arp2;
+       struct uip_info *info;
+       struct uip_buf *buf;
+
+       info = arg->info;
+       buf = uip_buf_clone(arg);
+
+       arp      = (struct uip_arp *)(arg->eth);
+       arp2     = (struct uip_arp *)(buf->eth);
+
+       /*
+        * ARP replay code: 2
+        */
+       arp2->op   = htons(0x2);
+       arp2->dmac = arp->smac;
+       arp2->dip  = arp->sip;
+
+       if (arp->dip == htonl(info->host_ip)) {
+               arp2->smac = info->host_mac;
+               arp2->sip = htonl(info->host_ip);
+
+               uip_buf_set_used(info, buf);
+       }
+
+       return 0;
+}