[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 07/10] linux-user: Add support for setsockopt() optio
From: |
Laurent Vivier |
Subject: |
[Qemu-devel] [PULL 07/10] linux-user: Add support for setsockopt() options IPV6_<ADD|DROP>_MEMBERSHIP |
Date: |
Thu, 23 May 2019 16:43:33 +0200 |
From: Neng Chen <address@hidden>
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 <address@hidden>
Signed-off-by: Aleksandar Markovic <address@hidden>
Reviewed-by: Laurent Vivier <address@hidden>
Message-Id: <address@hidden>
Signed-off-by: Laurent Vivier <address@hidden>
---
linux-user/syscall.c | 23 +++++++++++++++++++++++
1 file changed, 23 insertions(+)
diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index e5545cbafac7..a0c2bf7db43c 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -1911,6 +1911,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.20.1
- [Qemu-devel] [PULL 00/10] Linux user for 4.1 patches, Laurent Vivier, 2019/05/23
- [Qemu-devel] [PULL 01/10] linux-user: add pseudo /proc/cpuinfo for sparc, Laurent Vivier, 2019/05/23
- [Qemu-devel] [PULL 07/10] linux-user: Add support for setsockopt() options IPV6_<ADD|DROP>_MEMBERSHIP,
Laurent Vivier <=
- [Qemu-devel] [PULL 04/10] linux-user: Add support for SIOCSPGRP ioctl for all targets, Laurent Vivier, 2019/05/23
- [Qemu-devel] [PULL 02/10] linux-user: add pseudo /proc/hardware for m68k, Laurent Vivier, 2019/05/23
- [Qemu-devel] [PULL 09/10] linux-user: Align mmap_find_vma to host page size, Laurent Vivier, 2019/05/23
- [Qemu-devel] [PULL 05/10] linux-user: Add support for SIOC<G|S>IFPFLAGS ioctls for all targets, Laurent Vivier, 2019/05/23
- [Qemu-devel] [PULL 03/10] linux-user: Fix support for SIOCATMARK and SIOCGPGRP ioctls for xtensa, Laurent Vivier, 2019/05/23
- [Qemu-devel] [PULL 08/10] linux-user: Fix shmat emulation by honoring host SHMLBA, Laurent Vivier, 2019/05/23
- [Qemu-devel] [PULL 06/10] linux-user: Sanitize interp_info and, for mips only, init field fp_abi, Laurent Vivier, 2019/05/23
- [Qemu-devel] [PULL 10/10] linux-user: Pass through nanosecond timestamp components for stat syscalls, Laurent Vivier, 2019/05/23
- Re: [Qemu-devel] [PULL 00/10] Linux user for 4.1 patches, no-reply, 2019/05/23