qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Laurent Vivier <laurent@vivier.eu>
To: qemu-devel@nongnu.org
Cc: Riku Voipio <riku.voipio@iki.fi>, Laurent Vivier <laurent@vivier.eu>
Subject: [Qemu-devel] [PATCH 1/2] linux-user: Add setsockopt(SO_ATTACH_FILTER)
Date: Mon, 31 Dec 2012 20:37:59 +0100	[thread overview]
Message-ID: <1356982680-12436-2-git-send-email-laurent@vivier.eu> (raw)
In-Reply-To: <1356982680-12436-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      |   34 +++++++++++++++++++++++++++++++++-
 linux-user/syscall_defs.h |   12 ++++++++++++
 2 files changed, 45 insertions(+), 1 deletion(-)

diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index e99adab..000b640 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -98,6 +98,7 @@ int __clone2(int (*fn)(void *), void *child_stack_base,
 #include <linux/fb.h>
 #include <linux/vt.h>
 #include <linux/dm-ioctl.h>
+#include <linux/filter.h>
 #include "linux_loop.h"
 #include "cpu-uname.h"
 
@@ -1491,6 +1492,38 @@ static abi_long do_setsockopt(int sockfd, int level, int optname,
         break;
     case TARGET_SOL_SOCKET:
         switch (optname) {
+        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))
+                    return -TARGET_EFAULT;
+
+                fprog.len = tswap16(tfprog->len);
+                filter = alloca(fprog.len * sizeof(*filter));
+                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)));
+
+                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;
@@ -1548,7 +1581,6 @@ static abi_long do_setsockopt(int sockfd, int level, int optname,
         case TARGET_SO_SNDTIMEO:
 		optname = SO_SNDTIMEO;
 		break;
-            break;
         default:
             goto unimplemented;
         }
diff --git a/linux-user/syscall_defs.h b/linux-user/syscall_defs.h
index d4589e7..501735f 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 {
+    target_ushort code;
+    uint8_t jt;
+    uint8_t jf;
+    target_uint k;
+};
+
+struct target_sock_fprog {
+    target_ushort len;
+    abi_ulong filter;
+};
+
 struct target_in_addr {
     uint32_t s_addr; /* big endian */
 };
-- 
1.7.10.4

  reply	other threads:[~2012-12-31 19:38 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-12-31 19:37 [Qemu-devel] [PATCH 0/2] linux-user: dhclient support Laurent Vivier
2012-12-31 19:37 ` Laurent Vivier [this message]
2012-12-31 20:56   ` [Qemu-devel] [PATCH 1/2] linux-user: Add setsockopt(SO_ATTACH_FILTER) Peter Maydell
2012-12-31 19:38 ` [Qemu-devel] [PATCH 2/2] linux-user: SOCK_PACKET uses network endian to encode protocol in socket() Laurent Vivier
2012-12-31 21:32   ` Peter Maydell
2012-12-31 22:19     ` Laurent Vivier
2013-01-01 15:03       ` Peter Maydell
2013-01-01 17:27         ` Laurent Vivier
2013-01-01 18:37           ` Laurent Vivier
2013-01-01 19:45             ` Peter Maydell
2013-01-01 22:12               ` Laurent Vivier
2013-01-01 22:50                 ` Peter Maydell

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=1356982680-12436-2-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).