All of lore.kernel.org
 help / color / mirror / Atom feed
From: Aleksandar Markovic <aleksandar.markovic@rt-rk.com>
To: qemu-devel@nongnu.org
Cc: lvivier@redhat.com, thuth@redhat.com, jcmvbkbc@gmail.com,
	arikalo@wavecomp.com, daniel.santos@pobox.com,
	amarkovic@wavecomp.com, nchen@wavecomp.com, philmd@redhat.com,
	aurelien@aurel32.net
Subject: [Qemu-devel] [PATCH v6 4/6] linux-user: Add support for setsockopt() options IPV6_<ADD|DROP>_MEMBERSHIP
Date: Sun, 19 May 2019 18:15:25 +0200	[thread overview]
Message-ID: <1558282527-22183-5-git-send-email-aleksandar.markovic@rt-rk.com> (raw)
In-Reply-To: <1558282527-22183-1-git-send-email-aleksandar.markovic@rt-rk.com>

From: Neng Chen <nchen@wavecomp.com>

Add support for options IPV6_ADD_MEMBERSHIP and IPV6_DROP_MEMPEMBERSHIP
of the syscall setsockopt(). These options control membership in
multicast groups. Their argument is a pointer to a struct ipv6_mreq,
which is in turn defined in IP v6 header netinet/in.h as:

 struct ipv6_mreq {
     /* IPv6 multicast address of group */
     struct  in6_addr  ipv6mr_multiaddr;
     /* local IPv6 address of interface */
     int     ipv6mr_interface;
 };

...whereas its definition in kernel's include/uapi/linux/in6.h is:

 #if __UAPI_DEF_IPV6_MREQ
 struct ipv6_mreq {
     /* IPv6 multicast address of group */
         struct  in6_addr ipv6mr_multiaddr;
     /* local IPv6 address of interface */
     int     ipv6mr_ifindex;
 };
 #endif

The first field of ipv6_mreq has the same name ("ipv6mr_multiaddr")
and type ("in6_addr") in both cases. Moreover, the in6_addr structure
consists of fields that are always big-endian (on host of any endian),
therefore the ipv6_mreq's field ipv6mr_multiaddr doesn't need any
endian conversion.

The second field of ipv6_mreq may, however, depending on the build
environment, have different names. This is the reason why the line
"#if __UAPI_DEF_IPV6_MREQ" is used in this patch - to establish the
right choice for the field name. Also, endian conversion is needed
for this field, since it is of type "int".

Signed-off-by: Neng Chen <nchen@wavecomp.com>
Signed-off-by: Aleksandar Markovic <amarkovic@wavecomp.com>
---
 linux-user/syscall.c | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)

diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index 96cd4bf..acff14d 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -1892,6 +1892,29 @@ static abi_long do_setsockopt(int sockfd, int level, int optname,
                                        &pki, sizeof(pki)));
             break;
         }
+        case IPV6_ADD_MEMBERSHIP:
+        case IPV6_DROP_MEMBERSHIP:
+        {
+            struct ipv6_mreq ipv6mreq;
+
+            if (optlen < sizeof(ipv6mreq)) {
+                return -TARGET_EINVAL;
+            }
+
+            if (copy_from_user(&ipv6mreq, optval_addr, sizeof(ipv6mreq))) {
+                return -TARGET_EFAULT;
+            }
+
+#if __UAPI_DEF_IPV6_MREQ
+            ipv6mreq.ipv6mr_ifindex = tswap32(ipv6mreq.ipv6mr_ifindex);
+#else
+            ipv6mreq.ipv6mr_interface = tswap32(ipv6mreq.ipv6mr_interface);
+#endif /* __UAPI_DEF_IVP6_MREQ */
+
+            ret = get_errno(setsockopt(sockfd, level, optname,
+                                       &ipv6mreq, sizeof(ipv6mreq)));
+            break;
+        }
         default:
             goto unimplemented;
         }
-- 
2.7.4



  parent reply	other threads:[~2019-05-19 16:20 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-05-19 16:15 [Qemu-devel] [PATCH v6 0/6] linux-user: A set of miscellaneous patches Aleksandar Markovic
2019-05-19 16:15 ` [Qemu-devel] [PATCH v6 1/6] linux-user: Fix support for SIOCATMARK and SIOCGPGRP ioctls for xtensa Aleksandar Markovic
2019-05-22  9:11   ` Laurent Vivier
2019-05-19 16:15 ` [Qemu-devel] [PATCH v6 2/6] linux-user: Add support for SIOCSPGRP ioctl for all targets Aleksandar Markovic
2019-05-22  9:12   ` Laurent Vivier
2019-05-19 16:15 ` [Qemu-devel] [PATCH v6 3/6] linux-user: Add support for SIOC<G|S>IFPFLAGS ioctls " Aleksandar Markovic
2019-05-22  9:13   ` Laurent Vivier
2019-05-19 16:15 ` Aleksandar Markovic [this message]
2019-05-22  9:16   ` [Qemu-devel] [PATCH v6 4/6] linux-user: Add support for setsockopt() options IPV6_<ADD|DROP>_MEMBERSHIP Laurent Vivier
2019-05-22  9:18   ` Laurent Vivier
2019-05-19 16:15 ` [Qemu-devel] [PATCH v6 5/6] linux-user: Sanitize interp_info and, for mips only, init field fp_abi Aleksandar Markovic
2019-05-22  9:14   ` Laurent Vivier
2019-05-19 16:15 ` [Qemu-devel] [PATCH v6 6/6] linux-user: Add support for statx() syscall Aleksandar Markovic

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=1558282527-22183-5-git-send-email-aleksandar.markovic@rt-rk.com \
    --to=aleksandar.markovic@rt-rk.com \
    --cc=amarkovic@wavecomp.com \
    --cc=arikalo@wavecomp.com \
    --cc=aurelien@aurel32.net \
    --cc=daniel.santos@pobox.com \
    --cc=jcmvbkbc@gmail.com \
    --cc=lvivier@redhat.com \
    --cc=nchen@wavecomp.com \
    --cc=philmd@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=thuth@redhat.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.