From nobody Sat Apr 5 15:09:38 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=kernel.org ARC-Seal: i=1; a=rsa-sha256; t=1737723918; cv=none; d=zohomail.com; s=zohoarc; b=X+nBb87FC2GR9Sr+3yREnpqflmYs5fccO20rRyHkbNBosWPEkPa1aR4+uy0yRRCeTIw2WlGc0T4gNzmNY6lETPp9kaqosEAGPM8Z66xAU3KT3YSzR0bgA4jUuLat67p9NDHo694m/tVLc8EmJSietdMt2cKw+uDjsw9E2JbAykU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1737723918; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=0UrhhDP5Sg7utw1R3CxPPJvWuKMMp8NxFLFpClElQ+o=; b=Yy6xBTbA4pG2pWjfmAMZs/WdbLC9ANmgeHJeZLgz8xXXQg4p1EHEzOVSnOwzD/dNFj7k1MwyNri55TA+BY5AIAqRgb/aoiUn75VTc0HCEtpDdzEAZbk8o0bck145VxIYyEwC8FHiUkKuaSccDgKrxOKaRgnbi9hl4SJi/C504Cw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1737723918689373.16621241389566; Fri, 24 Jan 2025 05:05:18 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tbJLU-0000Uv-Ar; Fri, 24 Jan 2025 08:03:36 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tbJL4-0000Pr-6O for qemu-devel@nongnu.org; Fri, 24 Jan 2025 08:03:14 -0500 Received: from dfw.source.kernel.org ([139.178.84.217]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tbJL2-0007Gt-IZ for qemu-devel@nongnu.org; Fri, 24 Jan 2025 08:03:09 -0500 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 496B45C5A69; Fri, 24 Jan 2025 13:02:25 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id DD5E7C4CEE0; Fri, 24 Jan 2025 13:03:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1737723785; bh=Ovgym6COY+4COyqSeNlwwKYtZTk/Tq2Ej2TcJmZIyic=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=A7PxC7LfDSa/F4FQbgHFx28DZamDkbymKY6YrTpCTCLD2kyO8iOjrnx7T+gebtY1y 1iZTbohzTslYsIWUsXvLiRj87j9L8mUSCXToOdsKG48Mdz9KXG10pZ31BEiWEUkfYR ORTD698Tt8Oem+6ZjPC2z0AxOBMihfD/NYg2NFbsiULjSQWaA58dhWCWx/sY+8ipZZ jxRUTm8tvbrAVFCM2S7jYKrnyy8XanJbnb/YTdHD67SjBMrXvYOyjCIluQE8RGuhug u+z8+q3hPBXxPxHltrWsGF2N5RQZFuZOwIbwFEoC8k0aJmIWcND+zErovZYz1F4QaC N1WAmr1D6x+Pw== From: deller@kernel.org To: Laurent Vivier , Stefan Hajnoczi , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Richard Henderson , qemu-devel@nongnu.org Cc: deller@gmx.de Subject: [PULL v3 4/6] linux-user: netlink: Add emulation of IP_MULTICAST_IF Date: Fri, 24 Jan 2025 14:02:52 +0100 Message-ID: <20250124130254.3134-5-deller@kernel.org> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20250124130254.3134-1-deller@kernel.org> References: <20250124130254.3134-1-deller@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=139.178.84.217; envelope-from=deller@kernel.org; helo=dfw.source.kernel.org X-Spam_score_int: -100 X-Spam_score: -10.1 X-Spam_bar: ---------- X-Spam_report: (-10.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-2.996, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_HI=-5, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @kernel.org) X-ZM-MESSAGEID: 1737723921811019100 Content-Type: text/plain; charset="utf-8" From: Helge Deller Add IP_MULTICAST_IF and share the code with IP_ADD_MEMBERSHIP / IP_DROP_MEM= BERSHIP. Sharing the code makes sense, because the manpage of ip(7) says: IP_MULTICAST_IF (since Linux 1.2) Set the local device for a multicast socket. The argument for setsockopt(2) is an ip_mreqn or (since Linux 3.5) ip_mreq structure similar to IP_ADD_MEMBERSHIP, or an in_addr structure. (The kernel determines which structure is being passed based on the size passed in optlen.) For getsockopt(2), the argument is an in_addr structure. Signed-off-by: Helge Deller Reviewed-by: Laurent Vivier --- linux-user/syscall.c | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/linux-user/syscall.c b/linux-user/syscall.c index df8609b4d8..6ee02383da 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -2130,16 +2130,23 @@ static abi_long do_setsockopt(int sockfd, int level= , int optname, } ret =3D get_errno(setsockopt(sockfd, level, optname, &val, siz= eof(val))); break; + case IP_MULTICAST_IF: case IP_ADD_MEMBERSHIP: case IP_DROP_MEMBERSHIP: { struct ip_mreqn ip_mreq; struct target_ip_mreqn *target_smreqn; + int min_size; =20 QEMU_BUILD_BUG_ON(sizeof(struct ip_mreq) !=3D sizeof(struct target_ip_mreq)); =20 - if (optlen < sizeof (struct target_ip_mreq) || + if (optname =3D=3D IP_MULTICAST_IF) { + min_size =3D sizeof(struct in_addr); + } else { + min_size =3D sizeof(struct target_ip_mreq); + } + if (optlen < min_size || optlen > sizeof (struct target_ip_mreqn)) { return -TARGET_EINVAL; } @@ -2149,13 +2156,14 @@ static abi_long do_setsockopt(int sockfd, int level= , int optname, return -TARGET_EFAULT; } ip_mreq.imr_multiaddr.s_addr =3D target_smreqn->imr_multiaddr.= s_addr; - ip_mreq.imr_address.s_addr =3D target_smreqn->imr_address.s_ad= dr; - if (optlen =3D=3D sizeof(struct target_ip_mreqn)) { - ip_mreq.imr_ifindex =3D tswapal(target_smreqn->imr_ifindex= ); - optlen =3D sizeof(struct ip_mreqn); + if (optlen >=3D sizeof(struct target_ip_mreq)) { + ip_mreq.imr_address.s_addr =3D target_smreqn->imr_address.= s_addr; + if (optlen >=3D sizeof(struct target_ip_mreqn)) { + __put_user(target_smreqn->imr_ifindex, &ip_mreq.imr_if= index); + optlen =3D sizeof(struct ip_mreqn); + } } unlock_user(target_smreqn, optval_addr, 0); - ret =3D get_errno(setsockopt(sockfd, level, optname, &ip_mreq,= optlen)); break; } --=20 2.47.0