From patchwork Fri Aug 24 08:56:01 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Carlo_Marcelo_Arenas_Bel=C3=B3n?= X-Patchwork-Id: 10574917 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 135DF14E1 for ; Fri, 24 Aug 2018 08:57:57 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 807392B4EE for ; Fri, 24 Aug 2018 08:57:56 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 722292B54D; Fri, 24 Aug 2018 08:57:56 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.8 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id ADDC92B4EE for ; Fri, 24 Aug 2018 08:57:55 +0000 (UTC) Received: from localhost ([::1]:40522 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ft7ul-00029k-3b for patchwork-qemu-devel@patchwork.kernel.org; Fri, 24 Aug 2018 04:57:55 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53895) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ft7tx-0001iH-A4 for qemu-devel@nongnu.org; Fri, 24 Aug 2018 04:57:06 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ft7tu-0005Rs-49 for qemu-devel@nongnu.org; Fri, 24 Aug 2018 04:57:05 -0400 Received: from mail-pf1-x442.google.com ([2607:f8b0:4864:20::442]:35150) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1ft7tt-0005RV-RZ for qemu-devel@nongnu.org; Fri, 24 Aug 2018 04:57:02 -0400 Received: by mail-pf1-x442.google.com with SMTP id p12-v6so4241536pfh.2 for ; Fri, 24 Aug 2018 01:57:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=lCoQf8A3ZbvphMn1/UEwcvZuLBNVMvu2w10XwPZC3k4=; b=pYpWgSxBqHYm38oAlwz3xR1FsmkOSqcftsHLWaCklIf8/dqsfb5CqJX8rRzO1MkpPV D+hopV5gYqT+wDSET3Hwc2KclMvGhBNoObUX/OSUoSe07RKJnmh+spCOwMFuyKMPKs1l dvjLP6YhY3+sUJ5BqhqXrg/UDQ+WNQ5nZoyhmitAcrCZ5Xp20qndTXwK68X5Sp87FmNM t34ZJbcG+P5TlT6f7jwL5Qup4sTx9mLdoIpnvVD40O+wi2IhYsFdv0gEe9BcrZhicTKw awaXymMBeg8MFN2GMky2laEcV2Jd7YK/6VXEgykbbcxJROHgS7pjwiDodph3mLk2mLXL DlPQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=lCoQf8A3ZbvphMn1/UEwcvZuLBNVMvu2w10XwPZC3k4=; b=kWFoiOWTYWOFK1Mizwth0YeTLnZ0zvuRYfTxJTl3NmjTupxekDC5bplUmMxEdYulGP luOcHcetH5dHLgsOTFb2zTPNq6ZgrSnXy+BxAJc5SyahJ+XiCgsVQwjmfod/S3wmbWNh NpHW+zBBUjFOA/3jxiAsMASgNrg3IUq4zLj/xfg3Cq+hJy79KEOE8P2NVQWU6jeD4T3f oEqmJI5NtkNWt2m6rtM4K5JpbgeLC2cvwluJ00ADIPaLdligw5LtSh6hvxVbdtivn/Sb H60uTgZgbSPi7arle0GhzqzaYHUtSco/ZsdGcV6R976/FTJEjQQikkSG14EoIRb9wdLc Av+g== X-Gm-Message-State: APzg51AcdYQsZe0rQr6VyUkX22QF5F+3ltijfpkBKWVKOfnM5ZwkQlUk NWsAsTsqQDQjrrigVARadYiXXSqU X-Google-Smtp-Source: ANB0VdYKpUpR8f3O9U5sNZYrA6HR6Ed51dD2si7+Vna7MQ6GEaZwtqcyItd6eny44/Dai3cSUmutpw== X-Received: by 2002:a63:4e25:: with SMTP id c37-v6mr823454pgb.6.1535101020364; Fri, 24 Aug 2018 01:57:00 -0700 (PDT) Received: from localhost.localdomain (c-67-188-192-166.hsd1.ca.comcast.net. [67.188.192.166]) by smtp.gmail.com with ESMTPSA id f13-v6sm7080732pgs.92.2018.08.24.01.56.59 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 24 Aug 2018 01:56:59 -0700 (PDT) From: =?utf-8?q?Carlo_Marcelo_Arenas_Bel=C3=B3n?= To: qemu-devel@nongnu.org Date: Fri, 24 Aug 2018 01:56:01 -0700 Message-Id: <20180824085601.6259-1-carenas@gmail.com> X-Mailer: git-send-email 2.18.0 MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::442 Subject: [Qemu-devel] [PATCH] linux-user: add SO_LINGER to {g,s}etsockopt X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: schwab@suse.de, gang.chen.5i5j@gmail.com, =?utf-8?q?Carlo_Marcelo_Arenas?= =?utf-8?q?_Bel=C3=B3n?= , laurent@vivier.eu Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP Original implementation for setsockopt by Chen Gang[1]; all bugs mine, including removing assignment for optname which hopefully makes the logic easier to follow and moving some variables to make the code more selfcontained. [1] http://patchwork.ozlabs.org/patch/565659/ Signed-off-by: Carlo Marcelo Arenas Belón Co-Authored-By: Chen Gang Reviewed-by: Laurent Vivier --- linux-user/syscall.c | 52 ++++++++++++++++++++++++++++++++++++++- linux-user/syscall_defs.h | 5 ++++ 2 files changed, 56 insertions(+), 1 deletion(-) diff --git a/linux-user/syscall.c b/linux-user/syscall.c index 02fba7606d..43f2839540 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -3290,6 +3290,24 @@ set_timeout: unlock_user (dev_ifname, optval_addr, 0); return ret; } + case TARGET_SO_LINGER: + { + struct linger lg; + struct target_linger *tlg; + + if (optlen != sizeof(struct target_linger)) { + return -TARGET_EINVAL; + } + if (!lock_user_struct(VERIFY_READ, tlg, optval_addr, 1)) { + return -TARGET_EFAULT; + } + __get_user(lg.l_onoff, &tlg->l_onoff); + __get_user(lg.l_linger, &tlg->l_linger); + ret = get_errno(setsockopt(sockfd, SOL_SOCKET, SO_LINGER, + &lg, sizeof(lg))); + unlock_user_struct(tlg, optval_addr, 0); + return ret; + } /* Options with 'int' argument. */ case TARGET_SO_DEBUG: optname = SO_DEBUG; @@ -3381,7 +3399,6 @@ static abi_long do_getsockopt(int sockfd, int level, int optname, level = SOL_SOCKET; switch (optname) { /* These don't just return a single integer */ - case TARGET_SO_LINGER: case TARGET_SO_RCVTIMEO: case TARGET_SO_SNDTIMEO: case TARGET_SO_PEERNAME: @@ -3419,6 +3436,39 @@ static abi_long do_getsockopt(int sockfd, int level, int optname, } break; } + case TARGET_SO_LINGER: + { + struct linger lg; + socklen_t lglen; + struct target_linger *tlg; + + if (get_user_u32(len, optlen)) { + return -TARGET_EFAULT; + } + if (len < 0) { + return -TARGET_EINVAL; + } + + lglen = sizeof(lg); + ret = get_errno(getsockopt(sockfd, level, SO_LINGER, + &lg, &lglen)); + if (ret < 0) { + return ret; + } + if (len > lglen) { + len = lglen; + } + if (!lock_user_struct(VERIFY_WRITE, tlg, optval_addr, 0)) { + return -TARGET_EFAULT; + } + __put_user(lg.l_onoff, &tlg->l_onoff); + __put_user(lg.l_linger, &tlg->l_linger); + unlock_user_struct(tlg, optval_addr, 1); + if (put_user_u32(len, optlen)) { + return -TARGET_EFAULT; + } + break; + } /* 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 40bb60ef4c..18d434d6dc 100644 --- a/linux-user/syscall_defs.h +++ b/linux-user/syscall_defs.h @@ -203,6 +203,11 @@ struct target_ip_mreq_source { uint32_t imr_sourceaddr; }; +struct target_linger { + abi_int l_onoff; /* Linger active */ + abi_int l_linger; /* How long to linger for */ +}; + struct target_timeval { abi_long tv_sec; abi_long tv_usec;