All of lore.kernel.org
 help / color / mirror / Atom feed
From: Samuel Thibault <samuel.thibault@ens-lyon.org>
To: qemu-devel@nongnu.org
Cc: Stefan Hajnoczi <stefanha@gmail.com>,
	Jan Kiszka <jan.kiszka@siemens.com>,
	Samuel Thibault <samuel.thibault@ens-lyon.org>,
	Guillaume Subiron <maethor@subiron.org>
Subject: [Qemu-devel] [PATCH 02/18] slirp: Generalizing and neutralizing code before adding IPv6 stuff
Date: Mon, 31 Mar 2014 00:22:53 +0200	[thread overview]
Message-ID: <1396218189-14422-3-git-send-email-samuel.thibault@ens-lyon.org> (raw)
In-Reply-To: <1396218189-14422-1-git-send-email-samuel.thibault@ens-lyon.org>

Basically, this patch replaces "arp" by "resolution" every time "arp"
means "mac resolution" and not specifically ARP.

Some indentation problems are solved in functions that will be modified
in the next patches (ip_input…).

In if_encap, a switch is added to prepare for the IPv6 case. Some code
is factorized.

Some #define ETH_* are moved upper in slirp.h to make them accessible to
other slirp/*.h

Signed-off-by: Guillaume Subiron <maethor@subiron.org>
Signed-off-by: Samuel Thibault <samuel.thibault@ens-lyon.org>
---
 slirp/if.c    |  2 +-
 slirp/mbuf.c  |  2 +-
 slirp/mbuf.h  |  2 +-
 slirp/slirp.c | 24 ++++++++++++++++++++----
 slirp/slirp.h | 12 ++++++------
 5 files changed, 29 insertions(+), 13 deletions(-)

diff --git a/slirp/if.c b/slirp/if.c
index fb7acf8..e36b9cb 100644
--- a/slirp/if.c
+++ b/slirp/if.c
@@ -193,7 +193,7 @@ void if_start(Slirp *slirp)
 
         /* Try to send packet unless it already expired */
         if (ifm->expiration_date >= now && !if_encap(slirp, ifm)) {
-            /* Packet is delayed due to pending ARP resolution */
+            /* Packet is delayed due to pending ARP or NDP resolution */
             continue;
         }
 
diff --git a/slirp/mbuf.c b/slirp/mbuf.c
index 4fefb04..92c429e 100644
--- a/slirp/mbuf.c
+++ b/slirp/mbuf.c
@@ -91,7 +91,7 @@ m_get(Slirp *slirp)
 	m->m_len = 0;
         m->m_nextpkt = NULL;
         m->m_prevpkt = NULL;
-        m->arp_requested = false;
+        m->resolution_requested = false;
         m->expiration_date = (uint64_t)-1;
 end_error:
 	DEBUG_ARG("m = %lx", (long )m);
diff --git a/slirp/mbuf.h b/slirp/mbuf.h
index b144f1c..38fedf4 100644
--- a/slirp/mbuf.h
+++ b/slirp/mbuf.h
@@ -79,7 +79,7 @@ struct mbuf {
 	int	m_len;			/* Amount of data in this mbuf */
 
 	Slirp *slirp;
-	bool	arp_requested;
+	bool	resolution_requested;
 	uint64_t expiration_date;
 	/* start of dynamic buffer area, must be last element */
 	union {
diff --git a/slirp/slirp.c b/slirp/slirp.c
index bad8dad..676c86d 100644
--- a/slirp/slirp.c
+++ b/slirp/slirp.c
@@ -778,12 +778,14 @@ int if_encap(Slirp *slirp, struct mbuf *ifm)
         return 1;
     }
 
+    switch (iph->ip_v) {
+    case IPVERSION:
     if (!arp_table_search(slirp, iph->ip_dst.s_addr, ethaddr)) {
         uint8_t arp_req[ETH_HLEN + sizeof(struct arphdr)];
         struct ethhdr *reh = (struct ethhdr *)arp_req;
         struct arphdr *rah = (struct arphdr *)(arp_req + ETH_HLEN);
 
-        if (!ifm->arp_requested) {
+        if (!ifm->resolution_requested) {
             /* If the client addr is not known, send an ARP request */
             memset(reh->h_dest, 0xff, ETH_ALEN);
             memcpy(reh->h_source, special_ethaddr, ETH_ALEN - 4);
@@ -809,22 +811,36 @@ int if_encap(Slirp *slirp, struct mbuf *ifm)
             rah->ar_tip = iph->ip_dst.s_addr;
             slirp->client_ipaddr = iph->ip_dst;
             slirp_output(slirp->opaque, arp_req, sizeof(arp_req));
-            ifm->arp_requested = true;
+            ifm->resolution_requested = true;
 
             /* Expire request and drop outgoing packet after 1 second */
             ifm->expiration_date = qemu_clock_get_ns(QEMU_CLOCK_REALTIME) + 1000000000ULL;
         }
         return 0;
     } else {
-        memcpy(eh->h_dest, ethaddr, ETH_ALEN);
         memcpy(eh->h_source, special_ethaddr, ETH_ALEN - 4);
         /* XXX: not correct */
         memcpy(&eh->h_source[2], &slirp->vhost_addr, 4);
         eh->h_proto = htons(ETH_P_IP);
+        break;
+    }
+
+    default:
+        /* Do not assert while we don't manage IP6VERSION */
+        /* assert(0); */
+        break;
+    }
+
+        memcpy(eh->h_dest, ethaddr, ETH_ALEN);
+        DEBUG_ARGS((dfd, " src = %02x:%02x:%02x:%02x:%02x:%02x\n",
+                    eh->h_source[0], eh->h_source[1], eh->h_source[2],
+                    eh->h_source[3], eh->h_source[4], eh->h_source[5]));
+        DEBUG_ARGS((dfd, " dst = %02x:%02x:%02x:%02x:%02x:%02x\n",
+                    eh->h_dest[0], eh->h_dest[1], eh->h_dest[2],
+                    eh->h_dest[3], eh->h_dest[4], eh->h_dest[5]));
         memcpy(buf + sizeof(struct ethhdr), ifm->m_data, ifm->m_len);
         slirp_output(slirp->opaque, buf, ifm->m_len + ETH_HLEN);
         return 1;
-    }
 }
 
 /* Drop host forwarding rule, return 0 if found. */
diff --git a/slirp/slirp.h b/slirp/slirp.h
index e4a1bd4..cd9f2d0 100644
--- a/slirp/slirp.h
+++ b/slirp/slirp.h
@@ -136,6 +136,12 @@ void free(void *ptr);
 #include "qemu/queue.h"
 #include "qemu/sockets.h"
 
+#define ETH_ALEN 6
+#define ETH_HLEN 14
+
+#define ETH_P_IP  0x0800        /* Internet Protocol packet  */
+#define ETH_P_ARP 0x0806        /* Address Resolution packet */
+
 #include "libslirp.h"
 #include "ip.h"
 #include "tcp.h"
@@ -158,12 +164,6 @@ void free(void *ptr);
 #include "bootp.h"
 #include "tftp.h"
 
-#define ETH_ALEN 6
-#define ETH_HLEN 14
-
-#define ETH_P_IP  0x0800        /* Internet Protocol packet  */
-#define ETH_P_ARP 0x0806        /* Address Resolution packet */
-
 #define ARPOP_REQUEST 1         /* ARP request */
 #define ARPOP_REPLY   2         /* ARP reply   */
 
-- 
1.9.0

  parent reply	other threads:[~2014-03-30 22:23 UTC|newest]

Thread overview: 49+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-03-30 22:22 [Qemu-devel] [PATCHv4 00/18] slirp: Adding IPv6 support to Qemu -net user mode Samuel Thibault
2014-03-30 22:22 ` [Qemu-devel] [PATCH 01/18] slirp: goto bad in udp_input if sosendto fails Samuel Thibault
2014-05-07 22:15   ` [Qemu-devel] [PATCH, DoS] slirp (arp): do not special-case bogus IP addresses Samuel Thibault
2014-05-08  6:10     ` Edgar E. Iglesias
2014-05-08  6:50       ` Samuel Thibault
2014-05-08  6:59         ` Edgar E. Iglesias
2014-05-13 22:15           ` Samuel Thibault
2014-05-14  0:30             ` Edgar E. Iglesias
2014-05-14  0:44               ` Samuel Thibault
2014-05-14  0:54                 ` Edgar E. Iglesias
2014-05-14  1:11                   ` Samuel Thibault
2014-05-14  1:13     ` [Qemu-devel] [PATCHv2, " Samuel Thibault
2014-05-14  1:22       ` Edgar E. Iglesias
     [not found]         ` <20140527231002.GB3396@toto>
2014-06-12  5:48           ` Jan Kiszka
2014-06-09  0:01       ` Edgar E. Iglesias
2014-03-30 22:22 ` Samuel Thibault [this message]
2014-03-30 22:22 ` [Qemu-devel] [PATCH 03/18] slirp: Reindent after refactoring Samuel Thibault
2014-03-30 22:22 ` [Qemu-devel] [PATCH 04/18] slirp: Make Socket structure IPv6 compatible Samuel Thibault
2014-03-30 22:22 ` [Qemu-devel] [PATCH 05/18] slirp: Factorizing address translation Samuel Thibault
2014-03-30 22:22 ` [Qemu-devel] [PATCH 06/18] slirp: Factorizing and cleaning solookup() Samuel Thibault
2014-03-30 22:22 ` [Qemu-devel] [PATCH 07/18] slirp: Make udp_attach IPv6 compatible Samuel Thibault
2014-03-30 22:22 ` [Qemu-devel] [PATCH 08/18] slirp: Adding family argument to tcp_fconnect() Samuel Thibault
2014-03-30 22:23 ` [Qemu-devel] [PATCH 09/18] qemu/timer.h : Adding function to second scale Samuel Thibault
2014-03-30 22:23 ` [Qemu-devel] [PATCH 10/18] slirp: Adding IPv6, ICMPv6 Echo and NDP autoconfiguration Samuel Thibault
2014-03-30 22:23 ` [Qemu-devel] [PATCH 11/18] slirp: Adding ICMPv6 error sending Samuel Thibault
2014-03-30 22:23 ` [Qemu-devel] [PATCH 12/18] slirp: Adding IPv6 UDP support Samuel Thibault
2014-03-30 22:23 ` [Qemu-devel] [PATCH 13/18] slirp: Factorizing tcpiphdr structure with an union Samuel Thibault
2014-03-30 22:23 ` [Qemu-devel] [PATCH 14/18] slirp: Generalizing and neutralizing various TCP functions before adding IPv6 stuff Samuel Thibault
2014-03-30 22:23 ` [Qemu-devel] [PATCH 15/18] slirp: Reindent after refactoring Samuel Thibault
2014-03-30 22:23 ` [Qemu-devel] [PATCH 16/18] slirp: Handle IPv6 in TCP functions Samuel Thibault
2014-03-30 22:23 ` [Qemu-devel] [PATCH 17/18] slirp: Adding IPv6 address for DNS relay Samuel Thibault
2014-03-30 22:23 ` [Qemu-devel] [PATCH 18/18] qapi-schema, qemu-options & slirp: Adding Qemu options for IPv6 addresses Samuel Thibault
2015-07-28 22:57 [Qemu-devel] [PATCHv4 00/18] slirp: Adding IPv6 support to Qemu -net user mode Samuel Thibault
2015-07-28 22:57 ` [Qemu-devel] [PATCH 01/18] slirp: goto bad in udp_input if sosendto fails Samuel Thibault
2015-07-28 22:57   ` [Qemu-devel] [PATCH 02/18] slirp: Generalizing and neutralizing code before adding IPv6 stuff Samuel Thibault
2015-12-11  0:15 [Qemu-devel] [PATCHv5 00/18] slirp: Adding IPv6 support to Qemu -net user mode Samuel Thibault
2015-12-11  0:15 ` [Qemu-devel] [PATCH 01/18] slirp: goto bad in udp_input if sosendto fails Samuel Thibault
2015-12-11  0:15   ` [Qemu-devel] [PATCH 02/18] slirp: Generalizing and neutralizing code before adding IPv6 stuff Samuel Thibault
2015-12-11 13:38     ` Thomas Huth
2015-12-11 13:43       ` Thomas Huth
2015-12-11 13:47         ` Samuel Thibault
2015-12-11 13:52           ` Thomas Huth
2015-12-11 13:49         ` Thomas Huth
2015-12-11 14:01           ` Samuel Thibault
2015-12-11 14:32             ` Thomas Huth
2015-12-11 14:55               ` Samuel Thibault
2015-12-11 15:09                 ` Thomas Huth
2015-12-11 15:40                   ` Laszlo Ersek
2015-12-11 15:41                     ` Samuel Thibault
2015-12-11 16:17                     ` Eric Blake
2015-12-11 18:01                       ` Laszlo Ersek
2015-12-11 13:45       ` Samuel Thibault
2015-12-11 20:10       ` Samuel Thibault

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1396218189-14422-3-git-send-email-samuel.thibault@ens-lyon.org \
    --to=samuel.thibault@ens-lyon.org \
    --cc=jan.kiszka@siemens.com \
    --cc=maethor@subiron.org \
    --cc=qemu-devel@nongnu.org \
    --cc=stefanha@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.