From: Markus Armbruster <armbru@redhat.com>
To: Faisal Al-Humaimidi <falhumai96@gmail.com>
Cc: Jason Wang <jasowang@redhat.com>, qemu-devel@nongnu.org
Subject: Re: QEMU Sockets Networking Backend Multicast Networking Fix
Date: Sat, 15 Feb 2020 11:39:16 +0100 [thread overview]
Message-ID: <87mu9knnhn.fsf@dusky.pond.sub.org> (raw)
In-Reply-To: <CAMx8kb2aJ2OOHx6GG9qmXOoSXdQrzQ9+fsK=JR7pM-bJA4QOzg@mail.gmail.com> (Faisal Al-Humaimidi's message of "Fri, 14 Feb 2020 10:51:17 -0800")
Jason, please have a look.
Faisal Al-Humaimidi <falhumai96@gmail.com> writes:
> Hello QEMU developers,
>
> I have noticed a bug in the `mcast` option of the `socket` networking
> backend, where I simply cannot join a multicast group (tested in Windows 10
> with QEMU 4.2.0 release). I have found a fix to the problem. The problem
> was mainly due to the fact that QEMU was binding to the multicast address,
> and not the local address or the default INADDR_ANY (0.0.0.0) if no local
> address is used.
>
> Here's the patch text (as well as attached with this email), that outlines
> my fix:
>
> ```
> diff -uarN qemu-4.2.0.original/net/socket.c qemu-4.2.0.modified/net/socket.c
> --- qemu-4.2.0.original/net/socket.c 2019-12-12 10:20:48.000000000 -0800
> +++ qemu-4.2.0.modified/net/socket.c 2020-02-14 10:30:16.395973453 -0800
> @@ -253,6 +253,15 @@
> goto fail;
> }
>
> + /* Preserve the multicast address, and bind to a non-multicast group
> (e.g. a
> + * local address).
> + */
> + struct in_addr group_addr = mcastaddr->sin_addr;
> + if (localaddr) {
> + mcastaddr->sin_addr = *localaddr;
> + } else {
> + mcastaddr->sin_addr.s_addr = htonl(INADDR_ANY);
> + }
> ret = bind(fd, (struct sockaddr *)mcastaddr, sizeof(*mcastaddr));
> if (ret < 0) {
> error_setg_errno(errp, errno, "can't bind ip=%s to socket",
> @@ -260,7 +269,10 @@
> goto fail;
> }
>
> - /* Add host to multicast group */
> + /* Restore the multicast address. */
> + mcastaddr->sin_addr = group_addr;
> +
> + /* Add host to multicast group. */
> imr.imr_multiaddr = mcastaddr->sin_addr;
> if (localaddr) {
> imr.imr_interface = *localaddr;
> @@ -277,7 +289,7 @@
> goto fail;
> }
>
> - /* Force mcast msgs to loopback (eg. several QEMUs in same host */
> + /* Force mcast msgs to loopback (eg. several QEMUs in same host). */
> loop = 1;
> ret = qemu_setsockopt(fd, IPPROTO_IP, IP_MULTICAST_LOOP,
> &loop, sizeof(loop));
> @@ -287,7 +299,7 @@
> goto fail;
> }
>
> - /* If a bind address is given, only send packets from that address */
> + /* If a bind address is given, only send packets from that address. */
> if (localaddr != NULL) {
> ret = qemu_setsockopt(fd, IPPROTO_IP, IP_MULTICAST_IF,
> localaddr, sizeof(*localaddr));
> ```
>
> Regards,
> Faisal Al-Humaimidi
next prev parent reply other threads:[~2020-02-15 10:39 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-02-14 18:51 QEMU Sockets Networking Backend Multicast Networking Fix Faisal Al-Humaimidi
2020-02-15 10:39 ` Markus Armbruster [this message]
2020-02-17 9:53 ` Jason Wang
2020-02-17 10:05 ` Faisal Al-Humaimidi
2020-02-19 5:22 ` Jason Wang
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=87mu9knnhn.fsf@dusky.pond.sub.org \
--to=armbru@redhat.com \
--cc=falhumai96@gmail.com \
--cc=jasowang@redhat.com \
--cc=qemu-devel@nongnu.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).