qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Lionel Landwerlin <lionel.landwerlin@openwide.fr>
To: qemu-devel@nongnu.org
Subject: [Qemu-devel] [PATCH] linux-user: Added IP_ADD_MEMBERSHIP/IP_DROP_MEMBERSHIP flags to setsockopt
Date: Sat, 25 Apr 2009 23:30:19 +0200	[thread overview]
Message-ID: <1240695019.21332.1.camel@coalu.atr> (raw)

linux-user: Added IP_ADD_MEMBERSHIP/IP_DROP_MEMBERSHIP flags to setsockopt

Signed-off-by: Lionel Landwerlin <lionel.landwerlin@openwide.fr>
---
 linux-user/syscall.c      |   30 ++++++++++++++++++++++++++++++
 linux-user/syscall_defs.h |   15 +++++++++++++++
 2 files changed, 45 insertions(+), 0 deletions(-)

diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index 0bc9902..42f1089 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -944,6 +944,24 @@ static abi_long do_select(int n,
     return ret;
 }
 
+static inline abi_long target_to_host_ip_mreq(struct ip_mreqn *mreqn,
+                                              abi_ulong target_addr,
+                                              socklen_t len)
+{
+    struct target_ip_mreqn *target_smreqn;
+
+    target_smreqn = lock_user(VERIFY_READ, target_addr, len, 1);
+    if (!target_smreqn)
+        return -TARGET_EFAULT;
+    mreqn->imr_multiaddr.s_addr = target_smreqn->imr_multiaddr.s_addr;
+    mreqn->imr_address.s_addr = target_smreqn->imr_address.s_addr;
+    if (len == sizeof(struct target_ip_mreqn))
+        mreqn->imr_ifindex = tswapl(target_smreqn->imr_ifindex);
+    unlock_user(target_smreqn, target_addr, 0);
+
+    return 0;
+}
+
 static inline abi_long target_to_host_sockaddr(struct sockaddr *addr,
                                                abi_ulong target_addr,
                                                socklen_t len)
@@ -1119,6 +1137,7 @@ static abi_long do_setsockopt(int sockfd, int level, int optname,
 {
     abi_long ret;
     int val;
+    struct ip_mreqn *ip_mreq;
 
     switch(level) {
     case SOL_TCP:
@@ -1157,6 +1176,17 @@ static abi_long do_setsockopt(int sockfd, int level, int optname,
             }
             ret = get_errno(setsockopt(sockfd, level, optname, &val, sizeof(val)));
             break;
+        case IP_ADD_MEMBERSHIP:
+        case IP_DROP_MEMBERSHIP:
+            if (optlen < sizeof (struct target_ip_mreq) ||
+                optlen > sizeof (struct target_ip_mreqn))
+                return -TARGET_EINVAL;
+
+            ip_mreq = (struct ip_mreqn *) alloca(optlen);
+            target_to_host_ip_mreq(ip_mreq, optval_addr, optlen);
+            ret = get_errno(setsockopt(sockfd, level, optname, ip_mreq, optlen));
+            break;
+
         default:
             goto unimplemented;
         }
diff --git a/linux-user/syscall_defs.h b/linux-user/syscall_defs.h
index 7f0b0df..3284710 100644
--- a/linux-user/syscall_defs.h
+++ b/linux-user/syscall_defs.h
@@ -104,6 +104,21 @@ struct target_sockaddr {
     uint8_t sa_data[14];
 };
 
+struct target_in_addr {
+    uint32_t s_addr; /* big endian */
+};
+
+struct target_ip_mreq {
+    struct target_in_addr imr_multiaddr;
+    struct target_in_addr imr_address;
+};
+
+struct target_ip_mreqn {
+    struct target_in_addr imr_multiaddr;
+    struct target_in_addr imr_address;
+    abi_long imr_ifindex;
+};
+
 struct target_timeval {
     abi_long tv_sec;
     abi_long tv_usec;
-- 
1.6.2.4


-- 
Lionel Landwerlin <lionel.landwerlin@openwide.fr>

             reply	other threads:[~2009-04-25 21:30 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-04-25 21:30 Lionel Landwerlin [this message]
2009-04-27 17:21 ` [Qemu-devel] [PATCH] linux-user: Added IP_ADD_MEMBERSHIP/IP_DROP_MEMBERSHIP flags to setsockopt Nathan Froyd
2009-04-27 18:05   ` Lionel Landwerlin
2009-04-29 18:00     ` Riku Voipio
2009-04-29 20:35       ` Jamie Lokier
2009-04-29 20:43         ` Riku Voipio
2009-04-29 21:00           ` Jamie Lokier
2009-04-29 21:41             ` Riku Voipio
2009-04-30  2:41               ` Jamie Lokier
2009-04-29 23:08         ` Lionel Landwerlin

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=1240695019.21332.1.camel@coalu.atr \
    --to=lionel.landwerlin@openwide.fr \
    --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).