[Qemu-devel] [PATCH 02/16] slirp: Generalizing and neutralizing code before adding IPv6 stuff

2014-02-11 Thread Samuel Thibault
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 maet...@subiron.org
Signed-off-by: Samuel Thibault samuel.thiba...@ens-lyon.org
---
 slirp/if.c|   2 +-
 slirp/mbuf.c  |   2 +-
 slirp/mbuf.h  |   2 +-
 slirp/slirp.c | 107 ++
 slirp/slirp.h |  12 +++
 5 files changed, 71 insertions(+), 54 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;
-   boolarp_requested;
+   boolresolution_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..bfc4832 100644
--- a/slirp/slirp.c
+++ b/slirp/slirp.c
@@ -778,53 +778,70 @@ int if_encap(Slirp *slirp, struct mbuf *ifm)
 return 1;
 }
 
-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 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);
-memcpy(reh-h_source[2], slirp-vhost_addr, 4);
-reh-h_proto = htons(ETH_P_ARP);
-rah-ar_hrd = htons(1);
-rah-ar_pro = htons(ETH_P_IP);
-rah-ar_hln = ETH_ALEN;
-rah-ar_pln = 4;
-rah-ar_op = htons(ARPOP_REQUEST);
-
-/* source hw addr */
-memcpy(rah-ar_sha, special_ethaddr, ETH_ALEN - 4);
-memcpy(rah-ar_sha[2], slirp-vhost_addr, 4);
-
-/* source IP */
-rah-ar_sip = slirp-vhost_addr.s_addr;
-
-/* target hw addr (none) */
-memset(rah-ar_tha, 0, ETH_ALEN);
-
-/* target IP */
-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;
-
-/* Expire request and drop outgoing packet after 1 second */
-ifm-expiration_date = qemu_clock_get_ns(QEMU_CLOCK_REALTIME) + 
10ULL;
+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-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);
+memcpy(reh-h_source[2], slirp-vhost_addr, 4);
+reh-h_proto = htons(ETH_P_ARP);
+rah-ar_hrd = htons(1);
+rah-ar_pro = htons(ETH_P_IP);
+rah-ar_hln = ETH_ALEN;
+rah-ar_pln = 4;
+rah-ar_op = htons(ARPOP_REQUEST);
+
+/* source hw addr */
+memcpy(rah-ar_sha, special_ethaddr, ETH_ALEN - 4);
+memcpy(rah-ar_sha[2], slirp-vhost_addr, 4);
+
+/* source IP */
+rah-ar_sip = slirp-vhost_addr.s_addr;
+
+/* target hw addr (none) */
+memset(rah-ar_tha, 0, ETH_ALEN);
+
+/* target IP */
+   

[Qemu-devel] [PATCH 02/16] slirp: Generalizing and neutralizing code before adding IPv6 stuff

2013-11-17 Thread Samuel Thibault
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 maet...@subiron.org
Signed-off-by: Samuel Thibault samuel.thiba...@ens-lyon.org
---
 slirp/if.c|   2 +-
 slirp/mbuf.c  |   2 +-
 slirp/mbuf.h  |   2 +-
 slirp/slirp.c | 107 ++
 slirp/slirp.h |  12 +++
 5 files changed, 71 insertions(+), 54 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;
-   boolarp_requested;
+   boolresolution_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..bfc4832 100644
--- a/slirp/slirp.c
+++ b/slirp/slirp.c
@@ -778,53 +778,70 @@ int if_encap(Slirp *slirp, struct mbuf *ifm)
 return 1;
 }
 
-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 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);
-memcpy(reh-h_source[2], slirp-vhost_addr, 4);
-reh-h_proto = htons(ETH_P_ARP);
-rah-ar_hrd = htons(1);
-rah-ar_pro = htons(ETH_P_IP);
-rah-ar_hln = ETH_ALEN;
-rah-ar_pln = 4;
-rah-ar_op = htons(ARPOP_REQUEST);
-
-/* source hw addr */
-memcpy(rah-ar_sha, special_ethaddr, ETH_ALEN - 4);
-memcpy(rah-ar_sha[2], slirp-vhost_addr, 4);
-
-/* source IP */
-rah-ar_sip = slirp-vhost_addr.s_addr;
-
-/* target hw addr (none) */
-memset(rah-ar_tha, 0, ETH_ALEN);
-
-/* target IP */
-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;
-
-/* Expire request and drop outgoing packet after 1 second */
-ifm-expiration_date = qemu_clock_get_ns(QEMU_CLOCK_REALTIME) + 
10ULL;
+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-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);
+memcpy(reh-h_source[2], slirp-vhost_addr, 4);
+reh-h_proto = htons(ETH_P_ARP);
+rah-ar_hrd = htons(1);
+rah-ar_pro = htons(ETH_P_IP);
+rah-ar_hln = ETH_ALEN;
+rah-ar_pln = 4;
+rah-ar_op = htons(ARPOP_REQUEST);
+
+/* source hw addr */
+memcpy(rah-ar_sha, special_ethaddr, ETH_ALEN - 4);
+memcpy(rah-ar_sha[2], slirp-vhost_addr, 4);
+
+/* source IP */
+rah-ar_sip = slirp-vhost_addr.s_addr;
+
+/* target hw addr (none) */
+memset(rah-ar_tha, 0, ETH_ALEN);
+
+/* target IP */
+   

[Qemu-devel] [PATCH 02/16] slirp: Generalizing and neutralizing code before adding IPv6 stuff

2013-10-20 Thread Samuel Thibault
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 maet...@subiron.org
Signed-off-by: Samuel Thibault samuel.thiba...@ens-lyon.org
---
 slirp/if.c|   2 +-
 slirp/mbuf.c  |   2 +-
 slirp/mbuf.h  |   2 +-
 slirp/slirp.c | 107 ++
 slirp/slirp.h |  12 +++
 5 files changed, 71 insertions(+), 54 deletions(-)

diff --git a/slirp/if.c b/slirp/if.c
index 87ca8a5..c138ff4 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;
-   boolarp_requested;
+   boolresolution_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..bfc4832 100644
--- a/slirp/slirp.c
+++ b/slirp/slirp.c
@@ -778,53 +778,70 @@ int if_encap(Slirp *slirp, struct mbuf *ifm)
 return 1;
 }
 
-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 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);
-memcpy(reh-h_source[2], slirp-vhost_addr, 4);
-reh-h_proto = htons(ETH_P_ARP);
-rah-ar_hrd = htons(1);
-rah-ar_pro = htons(ETH_P_IP);
-rah-ar_hln = ETH_ALEN;
-rah-ar_pln = 4;
-rah-ar_op = htons(ARPOP_REQUEST);
-
-/* source hw addr */
-memcpy(rah-ar_sha, special_ethaddr, ETH_ALEN - 4);
-memcpy(rah-ar_sha[2], slirp-vhost_addr, 4);
-
-/* source IP */
-rah-ar_sip = slirp-vhost_addr.s_addr;
-
-/* target hw addr (none) */
-memset(rah-ar_tha, 0, ETH_ALEN);
-
-/* target IP */
-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;
-
-/* Expire request and drop outgoing packet after 1 second */
-ifm-expiration_date = qemu_clock_get_ns(QEMU_CLOCK_REALTIME) + 
10ULL;
+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-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);
+memcpy(reh-h_source[2], slirp-vhost_addr, 4);
+reh-h_proto = htons(ETH_P_ARP);
+rah-ar_hrd = htons(1);
+rah-ar_pro = htons(ETH_P_IP);
+rah-ar_hln = ETH_ALEN;
+rah-ar_pln = 4;
+rah-ar_op = htons(ARPOP_REQUEST);
+
+/* source hw addr */
+memcpy(rah-ar_sha, special_ethaddr, ETH_ALEN - 4);
+memcpy(rah-ar_sha[2], slirp-vhost_addr, 4);
+
+/* source IP */
+rah-ar_sip = slirp-vhost_addr.s_addr;
+
+/* target hw addr (none) */
+memset(rah-ar_tha, 0, ETH_ALEN);
+
+/* target IP */
+