From: Laurent Vivier <laurent@vivier.eu>
To: Riku Voipio <riku.voipio@iki.fi>
Cc: qemu-devel@nongnu.org, Laurent Vivier <laurent@vivier.eu>
Subject: [Qemu-devel] [PATCH 2/6] linux-user: Add setsockopt(SO_ATTACH_FILTER)
Date: Fri, 30 Aug 2013 01:46:41 +0200 [thread overview]
Message-ID: <1377820005-3835-3-git-send-email-laurent@vivier.eu> (raw)
In-Reply-To: <1377820005-3835-1-git-send-email-laurent@vivier.eu>
This is needed to be able to run dhclient.
Signed-off-by: Laurent Vivier <laurent@vivier.eu>
---
linux-user/syscall.c | 44 ++++++++++++++++++++++++++++++++++++++++++++
linux-user/syscall_defs.h | 12 ++++++++++++
2 files changed, 56 insertions(+)
diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index b19f712..9acc4f5 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -106,6 +106,7 @@ int __clone2(int (*fn)(void *), void *child_stack_base,
#include <linux/dm-ioctl.h>
#include <linux/reboot.h>
#include <linux/route.h>
+#include <linux/filter.h>
#include "linux_loop.h"
#include "cpu-uname.h"
@@ -1357,6 +1358,49 @@ set_timeout:
case TARGET_SO_SNDTIMEO:
optname = SO_SNDTIMEO;
goto set_timeout;
+ case TARGET_SO_ATTACH_FILTER:
+ {
+ struct target_sock_fprog *tfprog;
+ struct target_sock_filter *tfilter;
+ struct sock_fprog fprog;
+ struct sock_filter *filter;
+ int i;
+
+ if (optlen != sizeof(*tfprog)) {
+ return -TARGET_EINVAL;
+ }
+ if (!lock_user_struct(VERIFY_READ, tfprog, optval_addr, 0)) {
+ return -TARGET_EFAULT;
+ }
+ if (!lock_user_struct(VERIFY_READ, tfilter,
+ tswapal(tfprog->filter), 0)) {
+ unlock_user_struct(tfprog, optval_addr, 1);
+ return -TARGET_EFAULT;
+ }
+
+ fprog.len = tswap16(tfprog->len);
+ filter = malloc(fprog.len * sizeof(*filter));
+ if (filter == NULL) {
+ unlock_user_struct(tfilter, tfprog->filter, 1);
+ unlock_user_struct(tfprog, optval_addr, 1);
+ return -TARGET_ENOMEM;
+ }
+ for (i = 0; i < fprog.len; i++) {
+ filter[i].code = tswap16(tfilter[i].code);
+ filter[i].jt = tfilter[i].jt;
+ filter[i].jf = tfilter[i].jf;
+ filter[i].k = tswap32(tfilter[i].k);
+ }
+ fprog.filter = filter;
+
+ ret = get_errno(setsockopt(sockfd, SOL_SOCKET,
+ SO_ATTACH_FILTER, &fprog, sizeof(fprog)));
+ free(filter);
+
+ unlock_user_struct(tfilter, tfprog->filter, 1);
+ unlock_user_struct(tfprog, optval_addr, 1);
+ return ret;
+ }
/* Options with 'int' argument. */
case TARGET_SO_DEBUG:
optname = SO_DEBUG;
diff --git a/linux-user/syscall_defs.h b/linux-user/syscall_defs.h
index 086fbff..b0630ca 100644
--- a/linux-user/syscall_defs.h
+++ b/linux-user/syscall_defs.h
@@ -119,6 +119,18 @@ struct target_sockaddr {
uint8_t sa_data[14];
};
+struct target_sock_filter {
+ abi_ushort code;
+ uint8_t jt;
+ uint8_t jf;
+ abi_uint k;
+};
+
+struct target_sock_fprog {
+ abi_ushort len;
+ abi_ulong filter;
+};
+
struct target_in_addr {
uint32_t s_addr; /* big endian */
};
--
1.8.1.2
next prev parent reply other threads:[~2013-08-29 23:47 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-08-29 23:46 [Qemu-devel] [PATCH 0/6] linux-user: Misc patches for linux container compatibility Laurent Vivier
2013-08-29 23:46 ` [Qemu-devel] [PATCH 1/6] linux-user: convert /proc/net/route when endianess differs Laurent Vivier
2013-09-06 16:30 ` Peter Maydell
2013-08-29 23:46 ` Laurent Vivier [this message]
2013-09-06 16:30 ` [Qemu-devel] [PATCH 2/6] linux-user: Add setsockopt(SO_ATTACH_FILTER) Peter Maydell
2013-08-29 23:46 ` [Qemu-devel] [PATCH 3/6] linux-user: allow use of TIOCGSID Laurent Vivier
2013-09-06 16:31 ` Peter Maydell
2013-08-29 23:46 ` [Qemu-devel] [PATCH 4/6] linux-user: add some IPV6 commands in setsockop() Laurent Vivier
2013-09-06 16:31 ` Peter Maydell
2013-08-29 23:46 ` [Qemu-devel] [PATCH 5/6] linux-user: add support of binfmt_misc 'O' flag Laurent Vivier
2013-09-06 16:17 ` Peter Maydell
2013-09-06 16:50 ` Laurent Vivier
2013-08-29 23:46 ` [Qemu-devel] [PATCH 6/6] scripts: create a template to use with lxc-create Laurent Vivier
2013-09-06 16:33 ` Peter Maydell
2013-09-06 16:56 ` Laurent Vivier
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=1377820005-3835-3-git-send-email-laurent@vivier.eu \
--to=laurent@vivier.eu \
--cc=qemu-devel@nongnu.org \
--cc=riku.voipio@iki.fi \
/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).