qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Philippe Mathieu-Daudé" <philmd@redhat.com>
To: Samuel Thibault <samuel.thibault@gnu.org>,
	Chris Heinze <c.heinze@precibake.com>
Cc: "Marc-André Lureau" <marcandre.lureau@redhat.com>, qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] slirp, incoming packets get truncated
Date: Mon, 9 Sep 2019 12:51:23 +0200	[thread overview]
Message-ID: <47bad7a1-8fae-b464-7c74-b458d02a6174@redhat.com> (raw)
In-Reply-To: <20190907232924.a2maha6jyf7u6xbb@function>

Hi Samuel,

On 9/8/19 1:29 AM, Samuel Thibault wrote:
>
> Now, with MTU set to 9000, the packets just don't go at all. Could you
> try the attached patch? The lowest layer of slirp was indeed limited to
> 1600-byte frames for no good reason. With this and the virtio driver, I
> could exchange 9000-byte packets.
> 
> Samuel
> 
> diff --git a/src/slirp.c b/src/slirp.c
> index b0194cb..3fd6f68 100644
> --- a/src/slirp.c
> +++ b/src/slirp.c
> @@ -890,20 +890,22 @@ static int if_encap6(Slirp *slirp, struct mbuf
*ifm, struct ethhdr *eh,
>   */
>  int if_encap(Slirp *slirp, struct mbuf *ifm)
>  {
> -    uint8_t buf[1600];
> -    struct ethhdr *eh = (struct ethhdr *)buf;
> +    uint8_t *buf;
> +    struct ethhdr *eh;
>      uint8_t ethaddr[ETH_ALEN];
>      const struct ip *iph = (const struct ip *)ifm->m_data;
>      int ret;
>
> -    if (ifm->m_len + ETH_HLEN > sizeof(buf)) {
> -        return 1;
> -    }
> +    buf = g_malloc(ifm->m_len + ETH_HLEN);

Since g_malloc() aborts on failure, you want g_try_malloc() here.

> +    if (!buf)
> +        return 0;
> +    eh = (struct ethhdr *)buf;
>
>      switch (iph->ip_v) {
>      case IPVERSION:
>          ret = if_encap4(slirp, ifm, eh, ethaddr);
>          if (ret < 2) {
> +            g_free(buf);
>              return ret;
>          }
>          break;
> @@ -911,6 +913,7 @@ int if_encap(Slirp *slirp, struct mbuf *ifm)
>      case IP6VERSION:
>          ret = if_encap6(slirp, ifm, eh, ethaddr);
>          if (ret < 2) {
> +            g_free(buf);
>              return ret;
>          }
>          break;
> @@ -929,6 +932,7 @@ int if_encap(Slirp *slirp, struct mbuf *ifm)
>                eh->h_dest[5]);
>      memcpy(buf + sizeof(struct ethhdr), ifm->m_data, ifm->m_len);
>      slirp_send_packet_all(slirp, buf, ifm->m_len + ETH_HLEN);
> +    g_free(buf);
>      return 1;
>  }

Eventually easier to review using less exit points, i.e.:

-- >8 --
@@ -903,16 +903,10 @@ int if_encap(Slirp *slirp, struct mbuf *ifm)
     switch (iph->ip_v) {
     case IPVERSION:
         ret = if_encap4(slirp, ifm, eh, ethaddr);
-        if (ret < 2) {
-            return ret;
-        }
         break;

     case IP6VERSION:
         ret = if_encap6(slirp, ifm, eh, ethaddr);
-        if (ret < 2) {
-            return ret;
-        }
         break;

     default:
@@ -920,16 +914,21 @@ int if_encap(Slirp *slirp, struct mbuf *ifm)
         break;
     }

-    memcpy(eh->h_dest, ethaddr, ETH_ALEN);
-    DEBUG_ARG("src = %02x:%02x:%02x:%02x:%02x:%02x", 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_ARG("dst = %02x:%02x:%02x:%02x:%02x:%02x", 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_send_packet_all(slirp, buf, ifm->m_len + ETH_HLEN);
-    return 1;
+    if (ret >= 2) {
+        memcpy(eh->h_dest, ethaddr, ETH_ALEN);
+        DEBUG_ARG("src = %02x:%02x:%02x:%02x:%02x:%02x", 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_ARG("dst = %02x:%02x:%02x:%02x:%02x:%02x", 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_send_packet_all(slirp, buf, ifm->m_len + ETH_HLEN);
+        ret = 1;
+    }
+
+    g_free(buf);
+    return ret;
 }
---

Anyhow, if you plan to properly (with your S-o-b) commit your patch to
the libslirp repository, using g_try_malloc() you can add:

Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>

Regards,

Phil.


  parent reply	other threads:[~2019-09-09 10:54 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-09-03 15:02 [Qemu-devel] slirp, incoming packets get truncated Chris Heinze
2019-09-06  9:59 ` Samuel Thibault
2019-09-06 10:54   ` Chris Heinze
2019-09-06 11:14     ` Samuel Thibault
2019-09-07 23:29 ` Samuel Thibault
2019-09-09 10:35   ` Chris Heinze
2019-09-09 10:51   ` Philippe Mathieu-Daudé [this message]
2019-09-09 10:59     ` 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=47bad7a1-8fae-b464-7c74-b458d02a6174@redhat.com \
    --to=philmd@redhat.com \
    --cc=c.heinze@precibake.com \
    --cc=marcandre.lureau@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=samuel.thibault@gnu.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).