Received: by 2002:a05:7412:b995:b0:f9:9502:5bb8 with SMTP id it21csp475883rdb; Thu, 21 Dec 2023 15:23:33 -0800 (PST) X-Google-Smtp-Source: AGHT+IGKxO3pI3ozTgHF/YMnC88D3F4bFxDg2GDgrIRtyUNWL8lyOzs+3D1MJ1TwJUAhs2kDcYVN X-Received: by 2002:a05:6512:32b5:b0:50e:515b:56e4 with SMTP id q21-20020a05651232b500b0050e515b56e4mr119605lfe.19.1703201013710; Thu, 21 Dec 2023 15:23:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703201013; cv=none; d=google.com; s=arc-20160816; b=unEv88UuGDw5KKouMXCcrxslPF1pto3UIRfpMUluw+436y9uEIOKY6Abkeg1Zml1cN Oc9RhmBatxqY/CKDIBazqRkT1ipVOvnIiqNlLASxmtZyd/Nc9KMafUFo9+Bp9XK+lyaU mvuAfX+l2ffJvandveu2dCp2AWXRW7jVYYgQD1mANIVdgKJm1Z39t13vvoRjrAgQ1Vku xMvHZVGMYPxF2K5cwURRRmLddrf0JQ6aeonxLLjfqVbCdtyKImSbbk7E9FKT904THNcs JsMyRfW+GL6ZUdg5uJrNtdCAOEGdsT10FYshwc4g9DgbXtV0GkQ1umAPHx9zF1JiPGvy wsDw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from:dkim-signature; bh=Ti5eomPIZbnykEiRIHFWHoRdnkVM3Lii6pCaOjMdzxI=; fh=CNdCXcis1qEy0dhrRydWElqfG7ZnVggvzbMXdQego1U=; b=nB4cjuutS24Q0hdLraEmzM80Do/fwYjg1VdkNMVEQjlMmduDP97JVszBgSHyWgBI7T xWE4R1YxXIH6TYoKeQCaIOp12gBgm/tOCylOODsZV1hsF6NTfQBTnxDTBbDLCLXGmMGv tbSfc9CQH7rpGN8XrCOGAWrUS+pydhUk2OvETCSQtw4mrTf+GZaLnedJhOtMcsOJTkja Li0UoDYyVJa7yVptu+gt9wCi3ZkQQBOrrwekw0L/BJzb1aeEJsTMgLZokjuLPGQGoMvc uQ/zvgYBhEBASXYHtw8wlnUUhSAAIQXasLPlSPJkVbP9KsOmh3fg2305jbun6c3UFVkN WxsA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@tu-berlin.de header.s=dkim-tub header.b=L2gO5BZF; spf=pass (google.com: domain of linux-kernel+bounces-9175-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-9175-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=tu-berlin.de Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id m27-20020a50931b000000b0055414a0298bsi1154089eda.0.2023.12.21.15.23.33 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Dec 2023 15:23:33 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-9175-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@tu-berlin.de header.s=dkim-tub header.b=L2gO5BZF; spf=pass (google.com: domain of linux-kernel+bounces-9175-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-9175-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=tu-berlin.de Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 71AA21F23989 for ; Thu, 21 Dec 2023 23:23:33 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 5A2167996F; Thu, 21 Dec 2023 23:19:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=tu-berlin.de header.i=@tu-berlin.de header.b="L2gO5BZF" X-Original-To: linux-kernel@vger.kernel.org Received: from mailrelay.tu-berlin.de (mailrelay.tu-berlin.de [130.149.7.70]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5913E7995F; Thu, 21 Dec 2023 23:19:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=mailbox.tu-berlin.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=campus.tu-berlin.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tu-berlin.de; l=1833; s=dkim-tub; t=1703200787; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=Ti5eomPIZbnykEiRIHFWHoRdnkVM3Lii6pCaOjMdzxI=; b=L2gO5BZF/pQ8Nx6bOGFAyVa79pauEyOKNK1HfHIfviPLnJFR80/4eyCD b0vaArE4+7GDSuNHxERPVBWOs3UnArBZG1Vqwmc7Dd6BkOsqCkzdOpB2Y U451QFFETkJK1rkn1NZnhCQo3PRwkBiX9NakQpdWksjcZDgqK3yJytl1p c=; X-CSE-ConnectionGUID: THVcGfoHSOaMWzOeFXAlZw== X-CSE-MsgGUID: uvaIDAWJQ+yjFuvgSaLsfw== X-IronPort-AV: E=Sophos;i="6.04,294,1695679200"; d="scan'208";a="14652823" Received: from mail.tu-berlin.de ([141.23.12.141]) by mailrelay.tu-berlin.de with ESMTP; 22 Dec 2023 00:19:44 +0100 From: =?UTF-8?q?J=C3=B6rn-Thorben=20Hinz?= To: , CC: =?UTF-8?q?J=C3=B6rn-Thorben=20Hinz?= , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Willem de Bruijn , Deepa Dinamani Subject: [PATCH net] net: Implement missing getsockopt(SO_TIMESTAMPING_NEW) Date: Fri, 22 Dec 2023 00:19:01 +0100 Message-ID: <20231221231901.67003-1-jthinz@mailbox.tu-berlin.de> X-Mailer: git-send-email 2.39.2 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8bit Commit 9718475e6908 ("socket: Add SO_TIMESTAMPING_NEW") added the new socket option SO_TIMESTAMPING_NEW. Setting the option is handled in sk_setsockopt(), querying it was not handled in sk_getsockopt(), though. Following remarks on an earlier submission of this patch, keep the old behavior of getsockopt(SO_TIMESTAMPING_OLD) which returns the active flags even if they actually have been set through SO_TIMESTAMPING_NEW. The new getsockopt(SO_TIMESTAMPING_NEW) is stricter, returning flags only if they have been set through the same option. Fixes: 9718475e6908 ("socket: Add SO_TIMESTAMPING_NEW") Link: https://lore.kernel.org/lkml/20230703175048.151683-1-jthinz@mailbox.tu-berlin.de/ Link: https://lore.kernel.org/netdev/0d7cddc9-03fa-43db-a579-14f3e822615b@app.fastmail.com/ Signed-off-by: Jörn-Thorben Hinz --- net/core/sock.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/net/core/sock.c b/net/core/sock.c index fef349dd72fa..51d52859e942 100644 --- a/net/core/sock.c +++ b/net/core/sock.c @@ -1711,9 +1711,16 @@ int sk_getsockopt(struct sock *sk, int level, int optname, break; case SO_TIMESTAMPING_OLD: + case SO_TIMESTAMPING_NEW: lv = sizeof(v.timestamping); - v.timestamping.flags = READ_ONCE(sk->sk_tsflags); - v.timestamping.bind_phc = READ_ONCE(sk->sk_bind_phc); + /* For the later-added case SO_TIMESTAMPING_NEW: Be strict about only + * returning the flags when they were set through the same option. + * Don't change the beviour for the old case SO_TIMESTAMPING_OLD. + */ + if (optname == SO_TIMESTAMPING_OLD || sock_flag(sk, SOCK_TSTAMP_NEW)) { + v.timestamping.flags = READ_ONCE(sk->sk_tsflags); + v.timestamping.bind_phc = READ_ONCE(sk->sk_bind_phc); + } break; case SO_RCVTIMEO_OLD: -- 2.39.2