From patchwork Fri Dec 13 08:44:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anna Nyiri X-Patchwork-Id: 13906663 Received: from mail-wm1-f53.google.com (mail-wm1-f53.google.com [209.85.128.53]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DCA3B136352; Fri, 13 Dec 2024 08:45:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.53 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734079537; cv=none; b=tU62evSHLwoHiI+CG5DPUKXYVNLMSEOPGnnn70odcIwaUUKvo4KTi1wYb6LknsUjWTUnNotT0jGA1+oplShol8fW5UywTA05r6D9VhI/aLsdNGhItERXIp/PX8HFAjuyi9W+ld+oRJC0QJURgk5bqH383btsVV/I0cUp4h38LxE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734079537; c=relaxed/simple; bh=QPh03QEa0M8YEQs8GzmP3qJH+OhK905FKbbXXrN+B+8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=NBsnThSavGXF+JzJi+RYh49hM9nr/huRJEZMrlk/C4QroaCTBpN5c4Ajsq4WRuKT8ADpHhMYVW7L30cxchRD2d5LgP6kX6cUqNIGZamD1CSTG0Xu/+m4cJu90RCEIJWdE7N/dwyQuNym+1czgQcARbCvOwORwGQK1jOM8ZpUK64= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=Fn1YkPgK; arc=none smtp.client-ip=209.85.128.53 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Fn1YkPgK" Received: by mail-wm1-f53.google.com with SMTP id 5b1f17b1804b1-43624b2d453so17629575e9.2; Fri, 13 Dec 2024 00:45:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1734079534; x=1734684334; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=fNATByMEO9e+OmkVFZzCHZ/xIGul3/7QVkpEK0lUick=; b=Fn1YkPgKusuosBcJOodl6OC90L+FFLcNbOKzxlpn+j+yLF80MqrLWZ1hnDROlvEtd7 MHLUBkGDqx4y7av4ilIgcbz2ZpER240NXWGW6PMQd8UciwKQoAvP58h9u21nGvtg00VF gX9lBmgPIUwPmie8VHT8Yw3LJB+krke/E9KS+r/o6idLMj08jRcQCOvstsnvB+zOTRyA uXFMFxxrdrambJleSXutTBxJlfWa6wecpYY+LJHPyzFQdHhTMRGbzqoCB2XmDQPhnusK Uftklqtm9e07BLFMZVN/YFtNewt/Y/u1M87XXeg2V4fSW9xVfoXpyQ89q/iV7ddeqadX eigg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734079534; x=1734684334; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=fNATByMEO9e+OmkVFZzCHZ/xIGul3/7QVkpEK0lUick=; b=X2V8k3A5TFMNZaDEXy1Qqg0t0uSbUOGdNuSAnNgcuiF3OdKOjjNTAtdkhi/gsV91uJ AyL8dXsDw1nXeciAL7pgcYsKlvmzLvetLhVoIoXzGblLCjQb/vGi1fxwFRVBz2+oF0AT hcKwU066NuEvyRk9dlf5AH6GerPuihTs041iKaD76NPluhEwSSlJKQf/pSvTvfOTw4/F tHGV4TyHT+IMM8yE77RURwrevXqcbBbm5HWvOyxrAJTXL4M8apL4j3dvYwwnz3EYCd3G jHBmvdOF9zIZtLt+G3p7jRzCXDvsvRdfZo09k+4FPD28MGibxShkLB7I2kqufVDqj290 TYbQ== X-Forwarded-Encrypted: i=1; AJvYcCUT/rzT3pgDgWm3/IMV8UcRNdWVvdOWo5RCUgeQ9ToovqIB7grLLsvLVmwL/l1aBk88GersKgpcCE/y@vger.kernel.org, AJvYcCUiiJktmN6xFlaDnsJZfgRs5dn+dNc6HxWPRAm5zzwD3XcYxYEHQBSsV85hqDnzQSy8oXVOnFBblhDxgw==@vger.kernel.org, AJvYcCV7X9ZVGA4uFFZeYSEw3kJX7BD/38B/koyiUlcUyba0BXX0Aj8/PVbTNMpiN7sGCESs0XGMvdIb8yIzsA==@vger.kernel.org, AJvYcCWFV6jJy0XVooUb0lTF4qJG2CL9K8pUeivdjxdkVDdBIJLAFOoxbOqXJwxgptkrfieoe6OGJcfXvm7gNw==@vger.kernel.org, AJvYcCWU76FNv5/+AW88cI6D/S2WwKELAHW3EWqxK9mY1daPvMoAmUboEJzW2zVOCtoGwL4BBV+XJ6IBMaJ3XVhu@vger.kernel.org, AJvYcCWuiPr8n56WfJm4/RGU+qhfe+sekrSuiw9z4piFNmA43d4x6SADpG7rim/BonxJa31I9i6O/mD1UnCAuw==@vger.kernel.org, AJvYcCXXo09cmB0YzVrKPnWY6siqAiLsLOOSjCc7LmBL+55GxEyyfjLLYNq39dYHOeQtVH4BHIVXyusAKj3AfeaSbZ5r@vger.kernel.org X-Gm-Message-State: AOJu0YzXc7qD4giSI8Wrvq0Xb9uuKaUiAUFMW8tntsUEynsjG7pJ2Aox TO4v6XLNlSGPXfh8TTTlzt1t19pPiToFR83EIsYIVxg0kLNpTCWBl9zjTzGjL1k= X-Gm-Gg: ASbGnct5G/CsntuXApx4scJfBAXswjHvDCFUUqm5ZLvEqNwhan8jkXuniOimu0szTwT D3Fo9dbIdeMtIseH6Xdv32yjfGyv7LNgQ3toutBgJRREVZBYRyafE3+mZ0dzp9xqadxyImgOuwY NdjVOeP8U6KlhdgBtg6odVeTvOdTfSWFjHFWxX4xYUZQe4SV6lD2HDkAQg8PMnlBnHCtDjxoAcH ZXFCIEk1TtqrRRpnHadrKyrsO5vpXG0B0LZ5X40jN7l/Q/lYS0/brhUKl1byYcsaNGgZiTA4wZ1 yaVEJC/AUTDJvvGqVTFjNG0NE98NozFHEOmJ1JBNH8C8QQQQWNR/nIvxNd0yBf4= X-Google-Smtp-Source: AGHT+IGvZ46F4y7GsgwRtao3zQ76bY3tw4SGo8pyxYF9lkLcVpC0qsmeBDijswvA1DK5T7GpHdGkkA== X-Received: by 2002:a05:600c:3b9c:b0:434:f739:7cd9 with SMTP id 5b1f17b1804b1-4362aa362e5mr14019765e9.9.1734079533683; Fri, 13 Dec 2024 00:45:33 -0800 (PST) Received: from localhost.localdomain (20014C4E1E9B09007B50BC12F2E5C1B6.dsl.pool.telekom.hu. [2001:4c4e:1e9b:900:7b50:bc12:f2e5:c1b6]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4362559eaf6sm42487645e9.20.2024.12.13.00.45.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Dec 2024 00:45:33 -0800 (PST) From: Anna Emese Nyiri To: netdev@vger.kernel.org Cc: fejes@inf.elte.hu, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, willemb@google.com, idosch@idosch.org, horms@kernel.org, dsahern@kernel.org, linux-can@vger.kernel.org, socketcan@hartkopp.net, mkl@pengutronix.de, linux-kselftest@vger.kernel.org, shuah@kernel.org, tsbogend@alpha.franken.de, kaiyuanz@google.com, James.Bottomley@HansenPartnership.com, richard.henderson@linaro.org, arnd@arndb.de, almasrymina@google.com, asml.silence@gmail.com, linux-mips@vger.kernel.org, andreas@gaisler.com, mattst88@gmail.com, kerneljasonxing@gmail.com, sparclinux@vger.kernel.org, linux-alpha@vger.kernel.org, linux-arch@vger.kernel.org, deller@gmx.de, vadim.fedorenko@linux.dev, linux-parisc@vger.kernel.org, Anna Emese Nyiri Subject: [PATCH net-next v7 1/4] sock: Introduce sk_set_prio_allowed helper function Date: Fri, 13 Dec 2024 09:44:54 +0100 Message-ID: <20241213084457.45120-2-annaemesenyiri@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241213084457.45120-1-annaemesenyiri@gmail.com> References: <20241213084457.45120-1-annaemesenyiri@gmail.com> Precedence: bulk X-Mailing-List: linux-mips@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Simplify priority setting permissions with the 'sk_set_prio_allowed' function, centralizing the validation logic. This change is made in anticipation of a second caller in a following patch. No functional changes. Reviewed-by: Willem de Bruijn Reviewed-by: Eric Dumazet Suggested-by: Willem de Bruijn Signed-off-by: Anna Emese Nyiri --- net/core/sock.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/net/core/sock.c b/net/core/sock.c index 74729d20cd00..9016f984d44e 100644 --- a/net/core/sock.c +++ b/net/core/sock.c @@ -454,6 +454,13 @@ static int sock_set_timeout(long *timeo_p, sockptr_t optval, int optlen, return 0; } +static bool sk_set_prio_allowed(const struct sock *sk, int val) +{ + return ((val >= TC_PRIO_BESTEFFORT && val <= TC_PRIO_INTERACTIVE) || + sockopt_ns_capable(sock_net(sk)->user_ns, CAP_NET_RAW) || + sockopt_ns_capable(sock_net(sk)->user_ns, CAP_NET_ADMIN)); +} + static bool sock_needs_netstamp(const struct sock *sk) { switch (sk->sk_family) { @@ -1193,9 +1200,7 @@ int sk_setsockopt(struct sock *sk, int level, int optname, /* handle options which do not require locking the socket. */ switch (optname) { case SO_PRIORITY: - if ((val >= 0 && val <= 6) || - sockopt_ns_capable(sock_net(sk)->user_ns, CAP_NET_RAW) || - sockopt_ns_capable(sock_net(sk)->user_ns, CAP_NET_ADMIN)) { + if (sk_set_prio_allowed(sk, val)) { sock_set_priority(sk, val); return 0; } From patchwork Fri Dec 13 08:44:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anna Nyiri X-Patchwork-Id: 13906664 Received: from mail-wm1-f41.google.com (mail-wm1-f41.google.com [209.85.128.41]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 855251AC882; Fri, 13 Dec 2024 08:45:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.41 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734079540; cv=none; b=b2pDTtb2+WDmvuJAT9a1OeINmHhuXrxJYIW76PuTokM/TtbMipNyf30re9Zhu5dfLWJE6dRO8BjRcB3OWsqcEZtNJP0TQyOjyZopJl5JiATrbf9SmdNJbaC8ymfto7xv9Ty0THliarQbSh+7BpzAUx2/oCkd3nYK9mqDQbiFnco= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734079540; c=relaxed/simple; bh=Sl6GRW5iCPIpRgCJflqImLWJSqpqskSMz6hDhNcVQ00=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=EZ0VPHuji10+7V/LEgH/Cf9wctUeaYLjqdV+IbnW9ZwkcSi5wWAkNy2PAWiB9BgPBYWGkNnKTzhqux9PflRuBDOJRb+w6w6EoBfeFr5k+lGKSbbdvdR61hqFlHEfymGiZ4CciV/iSr1IK5+AwUAB6YkGHGkPCmnK9O26nUTMBFU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=BQKHfPy+; arc=none smtp.client-ip=209.85.128.41 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="BQKHfPy+" Received: by mail-wm1-f41.google.com with SMTP id 5b1f17b1804b1-4361fe642ddso15025725e9.2; Fri, 13 Dec 2024 00:45:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1734079536; x=1734684336; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=OhdEgZMIttJrwhWdkX71iUAWJ6QOVvPMGJLsgMmFF/o=; b=BQKHfPy+GW+LnDix0qN+fre5kdd3kJU1mylCPXvG3Kr17BJWVHRu4OUVWBYcroyfaB U/fIar7ipjzsgVI6PYvoIlVcwmcbG3cNoq39LvBOKyWgTnkyppIMgrCMI2uvScCCUXZO ZeDRw2gF/4nDW+NokRnNSqpDudhZWe+qpvALMgmAWRC24GpR10mBMWYViD1btaZLAirl qurF9/NKZfGR/c6nNe8JzjOyx9toaLo5qYoyKAa+VaeZQr9zlDD8U4vWwLvmSQlBsEtx MHL3p2KmO8ACN5IwweE1z2gH/wcXAwmWBrgpzkxTE8pi5GllDg5UgBhyff9lYeqY3KeW qH2A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734079536; x=1734684336; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=OhdEgZMIttJrwhWdkX71iUAWJ6QOVvPMGJLsgMmFF/o=; b=ojJfTOQ8Y5aeunR3dD0NSOyHIUc2/MlvddZryJJXNtjAQAwioTjE+vNwEA+HFxBuuZ XAzF21iDmZQuIdgT9AQT9Te5o5jEVjhnzyODFWf1mXOQ0VxqD2MclIKf4Jbb01fFahgO 2Aa4AN0ow+StICRkOV80gLadnpzXkTtlGmwFS0V1HLIdYTIIfjWzIM5DfIqrP9ldedhN Dazoj4YkmlDt0Tds+RFxGjaS5DCB01xaQB8zG8UV6CdJbq6gx7l0Ow2L+kjLPPPT4idV FTldL0CC5FT0sbIPuLosDEZ4pLoar8ms1YVEz69SZ9QdIQ7HJxWwKnAYHZHiLbgvounG q0hw== X-Forwarded-Encrypted: i=1; AJvYcCUBEPi+vf5YJgdQOiQvEfLXCWMrMbA4w6g1b/+e8OODzDdkN2NFitfuCrznyuZ9M3HbzbHjBGBNgPgAHf33ggyh@vger.kernel.org, AJvYcCUaDc39m1RjL8cS+Wa5Lz/qKMB0pRJ6oMrwekDK4Nc1bItVPIGbLZzGlTeWi/U4m/C5T1N1u6GteQximw==@vger.kernel.org, AJvYcCVqUx77kuZS0cge9xeV4k+YLkmxMb+ixi6xt/tQuoAGxmDDGd0AYUJe47zR4PNNdtVj/L6lMBZSK+11iA==@vger.kernel.org, AJvYcCWJ7wLy8dbFi0xaBzTbJv6NrY2dZHAXNGRqQnkDZnlmw21gC5vI13r0J3pEqrYfcf8G5GMuVWT9WuKbOA==@vger.kernel.org, AJvYcCWRR71SRuypNg/Sqs1KVouMpELPMwRM0yUtnv4zwZmaAyAxZwEQt1XD4tX27YakLAP2eqH8/haagWpQFSr2@vger.kernel.org, AJvYcCWWX3QncdtUXDr/m6gyW8VuvAmOEES/rpI5ev8eh0xezgxF7cf9i65NosEOMdEzCfui5FuUmU3rO2qWHQ==@vger.kernel.org, AJvYcCWhS352pYYlAwPC1sYx4AbSXw9joPBy9ehRAQ8Ih64EAzeflMOn30lpksw3cyLHGv4YTy4K7w1j+MKl@vger.kernel.org X-Gm-Message-State: AOJu0Yw+aVCa86cJYcKQj0COgGO4/2dov9+bMFEBQCSezE21IFQM9QuB c+X2/bQKnd9TUqZplgdTz240vT9i9pRk1xNZJn07b28vYVzd+hR3xfk8MZ9rt9Y= X-Gm-Gg: ASbGncv3dHJbz0hh1PzBRcLQWnNEFPDkHEjkkb81Lld/tv6y4sla1lUdEBfN9Yl/SNB FPTapMVbjPxCm/yEmQxLzzm2ONYmYJaLNJQM8D/LTpzm42NWUqfS9VdLhkmYMwRlip2zd7BQk9k inGt536KbxSlYlPht2obdHveJPZl/3FlHJDHWkWOGw+YeQN/66dluv94F5N1wvtXNHe/18KpkGD OmVBS00tfmOQfEVshuj1tFSmZzVopHpF9UtJ7uJO7GrkW25CRjmJgu+itFBkQNQPa0HGjiOKZxV i2bQs34WpI075wUMnj7TTq13Hur3r86FHkSJzXYDful7lpnW32F8JIbattfXKv8= X-Google-Smtp-Source: AGHT+IGLCdYQdP51TjZUz59Ci9JhyjH2voEmX8kN0lUpbIanwox00zNpnNj0ALsCdgrFCv+aQlzKew== X-Received: by 2002:a05:600c:350c:b0:434:f297:8e78 with SMTP id 5b1f17b1804b1-4362aa15448mr12172655e9.7.1734079536375; Fri, 13 Dec 2024 00:45:36 -0800 (PST) Received: from localhost.localdomain (20014C4E1E9B09007B50BC12F2E5C1B6.dsl.pool.telekom.hu. [2001:4c4e:1e9b:900:7b50:bc12:f2e5:c1b6]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4362559eaf6sm42487645e9.20.2024.12.13.00.45.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Dec 2024 00:45:35 -0800 (PST) From: Anna Emese Nyiri To: netdev@vger.kernel.org Cc: fejes@inf.elte.hu, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, willemb@google.com, idosch@idosch.org, horms@kernel.org, dsahern@kernel.org, linux-can@vger.kernel.org, socketcan@hartkopp.net, mkl@pengutronix.de, linux-kselftest@vger.kernel.org, shuah@kernel.org, tsbogend@alpha.franken.de, kaiyuanz@google.com, James.Bottomley@HansenPartnership.com, richard.henderson@linaro.org, arnd@arndb.de, almasrymina@google.com, asml.silence@gmail.com, linux-mips@vger.kernel.org, andreas@gaisler.com, mattst88@gmail.com, kerneljasonxing@gmail.com, sparclinux@vger.kernel.org, linux-alpha@vger.kernel.org, linux-arch@vger.kernel.org, deller@gmx.de, vadim.fedorenko@linux.dev, linux-parisc@vger.kernel.org, Anna Emese Nyiri Subject: [PATCH net-next v7 2/4] sock: support SO_PRIORITY cmsg Date: Fri, 13 Dec 2024 09:44:55 +0100 Message-ID: <20241213084457.45120-3-annaemesenyiri@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241213084457.45120-1-annaemesenyiri@gmail.com> References: <20241213084457.45120-1-annaemesenyiri@gmail.com> Precedence: bulk X-Mailing-List: linux-mips@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 The Linux socket API currently allows setting SO_PRIORITY at the socket level, applying a uniform priority to all packets sent through that socket. The exception to this is IP_TOS, when the priority value is calculated during the handling of ancillary data, as implemented in commit ("ipv4: IP_TOS and IP_TTL can be specified as ancillary data"). However, this is a computed value, and there is currently no mechanism to set a custom priority via control messages prior to this patch. According to this patch, if SO_PRIORITY is specified as ancillary data, the packet is sent with the priority value set through sockc->priority, overriding the socket-level values set via the traditional setsockopt() method. This is analogous to the existing support for SO_MARK, as implemented in commit ("ip: support SO_MARK cmsg"). If both cmsg SO_PRIORITY and IP_TOS are passed, then the one that takes precedence is the last one in the cmsg list. This patch has the side effect that raw_send_hdrinc now interprets cmsg IP_TOS. Reviewed-by: Willem de Bruijn Suggested-by: Ferenc Fejes Signed-off-by: Anna Emese Nyiri --- include/net/inet_sock.h | 2 +- include/net/ip.h | 2 +- include/net/sock.h | 4 +++- net/can/raw.c | 2 +- net/core/sock.c | 7 +++++++ net/ipv4/ip_output.c | 4 ++-- net/ipv4/ip_sockglue.c | 2 +- net/ipv4/raw.c | 2 +- net/ipv6/ip6_output.c | 3 ++- net/ipv6/ping.c | 1 + net/ipv6/raw.c | 3 ++- net/ipv6/udp.c | 1 + net/packet/af_packet.c | 2 +- 13 files changed, 24 insertions(+), 11 deletions(-) diff --git a/include/net/inet_sock.h b/include/net/inet_sock.h index 56d8bc5593d3..3ccbad881d74 100644 --- a/include/net/inet_sock.h +++ b/include/net/inet_sock.h @@ -172,7 +172,7 @@ struct inet_cork { u8 tx_flags; __u8 ttl; __s16 tos; - char priority; + u32 priority; __u16 gso_size; u32 ts_opt_id; u64 transmit_time; diff --git a/include/net/ip.h b/include/net/ip.h index 0e548c1f2a0e..9f5e33e371fc 100644 --- a/include/net/ip.h +++ b/include/net/ip.h @@ -81,7 +81,6 @@ struct ipcm_cookie { __u8 protocol; __u8 ttl; __s16 tos; - char priority; __u16 gso_size; }; @@ -96,6 +95,7 @@ static inline void ipcm_init_sk(struct ipcm_cookie *ipcm, ipcm_init(ipcm); ipcm->sockc.mark = READ_ONCE(inet->sk.sk_mark); + ipcm->sockc.priority = READ_ONCE(inet->sk.sk_priority); ipcm->sockc.tsflags = READ_ONCE(inet->sk.sk_tsflags); ipcm->oif = READ_ONCE(inet->sk.sk_bound_dev_if); ipcm->addr = inet->inet_saddr; diff --git a/include/net/sock.h b/include/net/sock.h index 7464e9f9f47c..316a34d6c48b 100644 --- a/include/net/sock.h +++ b/include/net/sock.h @@ -1814,13 +1814,15 @@ struct sockcm_cookie { u32 mark; u32 tsflags; u32 ts_opt_id; + u32 priority; }; static inline void sockcm_init(struct sockcm_cookie *sockc, const struct sock *sk) { *sockc = (struct sockcm_cookie) { - .tsflags = READ_ONCE(sk->sk_tsflags) + .tsflags = READ_ONCE(sk->sk_tsflags), + .priority = READ_ONCE(sk->sk_priority), }; } diff --git a/net/can/raw.c b/net/can/raw.c index 255c0a8f39d6..46e8ed9d64da 100644 --- a/net/can/raw.c +++ b/net/can/raw.c @@ -962,7 +962,7 @@ static int raw_sendmsg(struct socket *sock, struct msghdr *msg, size_t size) } skb->dev = dev; - skb->priority = READ_ONCE(sk->sk_priority); + skb->priority = sockc.priority; skb->mark = READ_ONCE(sk->sk_mark); skb->tstamp = sockc.transmit_time; diff --git a/net/core/sock.c b/net/core/sock.c index 9016f984d44e..a3d9941c1d32 100644 --- a/net/core/sock.c +++ b/net/core/sock.c @@ -2947,6 +2947,13 @@ int __sock_cmsg_send(struct sock *sk, struct cmsghdr *cmsg, case SCM_RIGHTS: case SCM_CREDENTIALS: break; + case SO_PRIORITY: + if (cmsg->cmsg_len != CMSG_LEN(sizeof(u32))) + return -EINVAL; + if (!sk_set_prio_allowed(sk, *(u32 *)CMSG_DATA(cmsg))) + return -EPERM; + sockc->priority = *(u32 *)CMSG_DATA(cmsg); + break; default: return -EINVAL; } diff --git a/net/ipv4/ip_output.c b/net/ipv4/ip_output.c index a59204a8d850..f45a083f2c13 100644 --- a/net/ipv4/ip_output.c +++ b/net/ipv4/ip_output.c @@ -1333,7 +1333,7 @@ static int ip_setup_cork(struct sock *sk, struct inet_cork *cork, cork->ttl = ipc->ttl; cork->tos = ipc->tos; cork->mark = ipc->sockc.mark; - cork->priority = ipc->priority; + cork->priority = ipc->sockc.priority; cork->transmit_time = ipc->sockc.transmit_time; cork->tx_flags = 0; sock_tx_timestamp(sk, &ipc->sockc, &cork->tx_flags); @@ -1470,7 +1470,7 @@ struct sk_buff *__ip_make_skb(struct sock *sk, ip_options_build(skb, opt, cork->addr, rt); } - skb->priority = (cork->tos != -1) ? cork->priority: READ_ONCE(sk->sk_priority); + skb->priority = cork->priority; skb->mark = cork->mark; if (sk_is_tcp(sk)) skb_set_delivery_time(skb, cork->transmit_time, SKB_CLOCK_MONOTONIC); diff --git a/net/ipv4/ip_sockglue.c b/net/ipv4/ip_sockglue.c index cf377377b52d..f6a03b418dde 100644 --- a/net/ipv4/ip_sockglue.c +++ b/net/ipv4/ip_sockglue.c @@ -315,7 +315,7 @@ int ip_cmsg_send(struct sock *sk, struct msghdr *msg, struct ipcm_cookie *ipc, if (val < 0 || val > 255) return -EINVAL; ipc->tos = val; - ipc->priority = rt_tos2priority(ipc->tos); + ipc->sockc.priority = rt_tos2priority(ipc->tos); break; case IP_PROTOCOL: if (cmsg->cmsg_len != CMSG_LEN(sizeof(int))) diff --git a/net/ipv4/raw.c b/net/ipv4/raw.c index 0e9e01967ec9..4304a68d1db0 100644 --- a/net/ipv4/raw.c +++ b/net/ipv4/raw.c @@ -358,7 +358,7 @@ static int raw_send_hdrinc(struct sock *sk, struct flowi4 *fl4, skb_reserve(skb, hlen); skb->protocol = htons(ETH_P_IP); - skb->priority = READ_ONCE(sk->sk_priority); + skb->priority = sockc->priority; skb->mark = sockc->mark; skb_set_delivery_type_by_clockid(skb, sockc->transmit_time, sk->sk_clockid); skb_dst_set(skb, &rt->dst); diff --git a/net/ipv6/ip6_output.c b/net/ipv6/ip6_output.c index 3d672dea9f56..993106876604 100644 --- a/net/ipv6/ip6_output.c +++ b/net/ipv6/ip6_output.c @@ -1401,6 +1401,7 @@ static int ip6_setup_cork(struct sock *sk, struct inet_cork_full *cork, cork->base.gso_size = ipc6->gso_size; cork->base.tx_flags = 0; cork->base.mark = ipc6->sockc.mark; + cork->base.priority = ipc6->sockc.priority; sock_tx_timestamp(sk, &ipc6->sockc, &cork->base.tx_flags); if (ipc6->sockc.tsflags & SOCKCM_FLAG_TS_OPT_ID) { cork->base.flags |= IPCORK_TS_OPT_ID; @@ -1942,7 +1943,7 @@ struct sk_buff *__ip6_make_skb(struct sock *sk, hdr->saddr = fl6->saddr; hdr->daddr = *final_dst; - skb->priority = READ_ONCE(sk->sk_priority); + skb->priority = cork->base.priority; skb->mark = cork->base.mark; if (sk_is_tcp(sk)) skb_set_delivery_time(skb, cork->base.transmit_time, SKB_CLOCK_MONOTONIC); diff --git a/net/ipv6/ping.c b/net/ipv6/ping.c index 88b3fcacd4f9..46b8adf6e7f8 100644 --- a/net/ipv6/ping.c +++ b/net/ipv6/ping.c @@ -119,6 +119,7 @@ static int ping_v6_sendmsg(struct sock *sk, struct msghdr *msg, size_t len) return -EINVAL; ipcm6_init_sk(&ipc6, sk); + ipc6.sockc.priority = READ_ONCE(sk->sk_priority); ipc6.sockc.tsflags = READ_ONCE(sk->sk_tsflags); ipc6.sockc.mark = READ_ONCE(sk->sk_mark); diff --git a/net/ipv6/raw.c b/net/ipv6/raw.c index 8476a3944a88..a45aba090aa4 100644 --- a/net/ipv6/raw.c +++ b/net/ipv6/raw.c @@ -619,7 +619,7 @@ static int rawv6_send_hdrinc(struct sock *sk, struct msghdr *msg, int length, skb_reserve(skb, hlen); skb->protocol = htons(ETH_P_IPV6); - skb->priority = READ_ONCE(sk->sk_priority); + skb->priority = sockc->priority; skb->mark = sockc->mark; skb_set_delivery_type_by_clockid(skb, sockc->transmit_time, sk->sk_clockid); @@ -780,6 +780,7 @@ static int rawv6_sendmsg(struct sock *sk, struct msghdr *msg, size_t len) ipcm6_init(&ipc6); ipc6.sockc.tsflags = READ_ONCE(sk->sk_tsflags); ipc6.sockc.mark = fl6.flowi6_mark; + ipc6.sockc.priority = READ_ONCE(sk->sk_priority); if (sin6) { if (addr_len < SIN6_LEN_RFC2133) diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c index d766fd798ecf..7c14c449804c 100644 --- a/net/ipv6/udp.c +++ b/net/ipv6/udp.c @@ -1448,6 +1448,7 @@ int udpv6_sendmsg(struct sock *sk, struct msghdr *msg, size_t len) ipc6.gso_size = READ_ONCE(up->gso_size); ipc6.sockc.tsflags = READ_ONCE(sk->sk_tsflags); ipc6.sockc.mark = READ_ONCE(sk->sk_mark); + ipc6.sockc.priority = READ_ONCE(sk->sk_priority); /* destination address check */ if (sin6) { diff --git a/net/packet/af_packet.c b/net/packet/af_packet.c index 886c0dd47b66..f8d87d622699 100644 --- a/net/packet/af_packet.c +++ b/net/packet/af_packet.c @@ -3126,7 +3126,7 @@ static int packet_snd(struct socket *sock, struct msghdr *msg, size_t len) skb->protocol = proto; skb->dev = dev; - skb->priority = READ_ONCE(sk->sk_priority); + skb->priority = sockc.priority; skb->mark = sockc.mark; skb_set_delivery_type_by_clockid(skb, sockc.transmit_time, sk->sk_clockid); From patchwork Fri Dec 13 08:44:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anna Nyiri X-Patchwork-Id: 13906665 Received: from mail-wm1-f52.google.com (mail-wm1-f52.google.com [209.85.128.52]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AD2D91ADFF6; Fri, 13 Dec 2024 08:45:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.52 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734079543; cv=none; b=eMheDkOcV4K5TGlpRnRI6Y7KiPaZHHZ+6/5wVuSiWfAQ6tRe3EeK47DynggZmpz9FNAnhHELJkPC/Vzh8kHLc3S6X2+QEB7ELFyOBDf0QkeYUCsTcDnL5yBUAeZLoViPBdwzrw6Adq5W3broe7m1pjgQymITpYH1xEKCW7CxHAk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734079543; c=relaxed/simple; bh=gEXrtWbvKXbc5DAvlMeORK670b/NaKAd2vGNsP6Rfu4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=H7kZjdqI93CkXgCpbOXW6o3Cc1JcQK+0oHP18prE37K8DYeo5rx1MU4vbob6VckhkwF7MxP3zab8UgnSX8+XEOBsgeVRZxQ8y6WxhP4omfHLXxaHnhP2tBgHc6PHLccVxW2CgNl95+Ets+WMFGGpF91leE9V3AICFnpihX5rGbk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=Ei487U02; arc=none smtp.client-ip=209.85.128.52 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Ei487U02" Received: by mail-wm1-f52.google.com with SMTP id 5b1f17b1804b1-4361e89b6daso10139315e9.3; Fri, 13 Dec 2024 00:45:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1734079539; x=1734684339; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=UAQPjCfF8R79FFcgAR1MpcWgrbDYC2HDbd/YFnzgQSI=; b=Ei487U02MMkvJZ9sDN8Rr8bfV7yRw0HjBCnCxfqa/v1geENc4PiTVAzQ1kMpNo6WLE qPl0RV2cgPUDvynJvFj8gZ1dycOLa2EKyE0tdtW5tqdndavyHolup443hXkb8cV5apB+ IRjRCBRAFdrVhDskcLMNcdr9bGLaY94pYW/BPdOXgFEK7eU0MLaxqfdiQVWVEsQYsJ71 XA1G8qsXXOjy9PBTEgPI/MAxU2o2ZU/ydHB+P1Hfh5bEWixR9iTeRopDiqlDruDUwDsi wufZbhYqiSd14I24YiiJ5Q3i/ovo0kj31VSAwuqz0JZfmQgqnvjP8CKDnxWrb7+TbieW bclA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734079539; x=1734684339; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=UAQPjCfF8R79FFcgAR1MpcWgrbDYC2HDbd/YFnzgQSI=; b=hiYyz9i2ljY74Cr4dVwjmHi1uhcNczTP0rqXyS+BxJgvJcRMMNOYkee3CXslXKZdmT fFa3/JvGl9YKlF+W7BBiFuh8EXKz6CO9+Fv9CAqXxMqcHbH3TDu2OLtvace7J2ncmU9a QaLGfOyrIaXqTxQYUm229hoK9mWPGyLFHbID9DmVCBi++t4BCZzbVJIsSr7YZBF79nQ/ JH2zth6GNQjMGSSLaIUyJzyVI711Ru17zIPtoFrPWXZvhia1sDCnBKiSdxUcBRw/AUNz a03qn0wy/UJBZ4ypWNznBKAFFKSFFzwxXoaivdTjqpAbqqYo0yogIBebovmGLdu7Wq03 hOTw== X-Forwarded-Encrypted: i=1; AJvYcCUETsQumaocsCWHTZGq4Bhogi8zMceJhdUlGj/up+lZqXBl8w/kqM6vfG5HtmKdXF3QAMd47o8PmCzx+wbtL1sB@vger.kernel.org, AJvYcCUa7pL3QMjKFZci2iO7+5PYUwxQmpQP8I4RhIxrwcWJxsyqYuLop+Vr9ohftKwU5x0Bsk1979d6rrt3fA==@vger.kernel.org, AJvYcCVN+Muhuh1sV3/vMHo8LxThXsOd4HrxsXGtFVPT/hMw9pcC/t7GVN5/AotbAgOJVmEP+10iz/K/LFL7aHul@vger.kernel.org, AJvYcCVPY4qImGhw5xWYK6C+eQOeQ8bHc3auUQgZ0eBRHc9eZbBw5+7VMSxkxf8zwsOeQdRZz8S82iU7Lkr6@vger.kernel.org, AJvYcCVXq511xWwHcxLD7uRtO0xUUhHkWXAj8A5fQ3ewt1EujVhvUBDtyAQ/D15XO483lQH1NymfUUK/1kjGvg==@vger.kernel.org, AJvYcCWJ7kIC1ITlGLUolbjCf8mzDMqvvZ774E3P1jy+nL5JfkeoJcet919qIMriSurJWYYOX2LkG+qnL/PFBg==@vger.kernel.org, AJvYcCX3NmbfkfDQoafic/kehwypX4gcqNpLDcXk3y/MmFGGO4++/9D6GRIOSay41UyoGmNR41f2XXgutb/mLg==@vger.kernel.org X-Gm-Message-State: AOJu0YwphQF/j5IdovGi3aR4Tvl0Egu5tXjnRgWnC6Zic+fKyvt/0KtZ yQevfpZKAIr6jQ6yP38n/3fyC6j5DWg4sNdAKcfp6o45HKZW7Wtu2f3zgE48eBE= X-Gm-Gg: ASbGncsMlkSDrmsgvYvTZ4T00JiTBo1pl++uHud7lI2knaGTkldgbPCISgx5B4+d1/Y VgbuiGrlsWe/tIoCwGg68EqOall/Mp0BQ7uqt4KAW8m0OaGd/4Qs6H8AKyz4/dPVqo60lr9m8po InzdJ6tPfLtvfkQm1VpgD+pl+gnm8x69ubiVfKS/w7NmDVwl1Jj16tTnIJczLSKKx8QaJ4LJWa0 Zo3E5zEdE+TbW4iJRJ3BLt/4wqJvwbs1IILLPSS6mnfs0VA4++QrWZt25hC/5DjnRv8vfSkJn5v K0p0HbwWUlhIYlJ8f2p4SVBpWG/pRypNOpy9xbxAq5O5iXIuSQuYPuGycNoZXHM= X-Google-Smtp-Source: AGHT+IHEs3Cei5msjsPGizCRnMmoZL2dPAJpkHiPIRNVrae9gJi3SXbE3DRfQs3hVdWLib2Sivoeyg== X-Received: by 2002:a05:600c:1c07:b0:434:a10f:c3 with SMTP id 5b1f17b1804b1-4362aa2dea3mr13831005e9.9.1734079538652; Fri, 13 Dec 2024 00:45:38 -0800 (PST) Received: from localhost.localdomain (20014C4E1E9B09007B50BC12F2E5C1B6.dsl.pool.telekom.hu. [2001:4c4e:1e9b:900:7b50:bc12:f2e5:c1b6]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4362559eaf6sm42487645e9.20.2024.12.13.00.45.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Dec 2024 00:45:37 -0800 (PST) From: Anna Emese Nyiri To: netdev@vger.kernel.org Cc: fejes@inf.elte.hu, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, willemb@google.com, idosch@idosch.org, horms@kernel.org, dsahern@kernel.org, linux-can@vger.kernel.org, socketcan@hartkopp.net, mkl@pengutronix.de, linux-kselftest@vger.kernel.org, shuah@kernel.org, tsbogend@alpha.franken.de, kaiyuanz@google.com, James.Bottomley@HansenPartnership.com, richard.henderson@linaro.org, arnd@arndb.de, almasrymina@google.com, asml.silence@gmail.com, linux-mips@vger.kernel.org, andreas@gaisler.com, mattst88@gmail.com, kerneljasonxing@gmail.com, sparclinux@vger.kernel.org, linux-alpha@vger.kernel.org, linux-arch@vger.kernel.org, deller@gmx.de, vadim.fedorenko@linux.dev, linux-parisc@vger.kernel.org, Anna Emese Nyiri , Ido Schimmel Subject: [PATCH net-next v7 3/4] selftests: net: test SO_PRIORITY ancillary data with cmsg_sender Date: Fri, 13 Dec 2024 09:44:56 +0100 Message-ID: <20241213084457.45120-4-annaemesenyiri@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241213084457.45120-1-annaemesenyiri@gmail.com> References: <20241213084457.45120-1-annaemesenyiri@gmail.com> Precedence: bulk X-Mailing-List: linux-mips@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Extend cmsg_sender.c with a new option '-Q' to send SO_PRIORITY ancillary data. cmsg_so_priority.sh script added to validate SO_PRIORITY behavior by creating VLAN device with egress QoS mapping and testing packet priorities using flower filters. Verify that packets with different priorities are correctly matched and counted by filters for multiple protocols and IP versions. Reviewed-by: Willem de Bruijn Acked-by: Willem de Bruijn Reviewed-by: Ido Schimmel Tested-by: Ido Schimmel Suggested-by: Ido Schimmel Signed-off-by: Anna Emese Nyiri --- tools/testing/selftests/net/Makefile | 1 + tools/testing/selftests/net/cmsg_sender.c | 11 +- .../testing/selftests/net/cmsg_so_priority.sh | 151 ++++++++++++++++++ 3 files changed, 162 insertions(+), 1 deletion(-) create mode 100755 tools/testing/selftests/net/cmsg_so_priority.sh diff --git a/tools/testing/selftests/net/Makefile b/tools/testing/selftests/net/Makefile index cb2fc601de66..f09bd96cc978 100644 --- a/tools/testing/selftests/net/Makefile +++ b/tools/testing/selftests/net/Makefile @@ -32,6 +32,7 @@ TEST_PROGS += ioam6.sh TEST_PROGS += gro.sh TEST_PROGS += gre_gso.sh TEST_PROGS += cmsg_so_mark.sh +TEST_PROGS += cmsg_so_priority.sh TEST_PROGS += cmsg_time.sh cmsg_ipv6.sh TEST_PROGS += netns-name.sh TEST_PROGS += nl_netdev.py diff --git a/tools/testing/selftests/net/cmsg_sender.c b/tools/testing/selftests/net/cmsg_sender.c index 876c2db02a63..bc314382e4e1 100644 --- a/tools/testing/selftests/net/cmsg_sender.c +++ b/tools/testing/selftests/net/cmsg_sender.c @@ -59,6 +59,7 @@ struct options { unsigned int proto; } sock; struct option_cmsg_u32 mark; + struct option_cmsg_u32 priority; struct { bool ena; unsigned int delay; @@ -97,6 +98,8 @@ static void __attribute__((noreturn)) cs_usage(const char *bin) "\n" "\t\t-m val Set SO_MARK with given value\n" "\t\t-M val Set SO_MARK via setsockopt\n" + "\t\t-P val Set SO_PRIORITY via setsockopt\n" + "\t\t-Q val Set SO_PRIORITY via cmsg\n" "\t\t-d val Set SO_TXTIME with given delay (usec)\n" "\t\t-t Enable time stamp reporting\n" "\t\t-f val Set don't fragment via cmsg\n" @@ -115,7 +118,7 @@ static void cs_parse_args(int argc, char *argv[]) { int o; - while ((o = getopt(argc, argv, "46sS:p:P:m:M:n:d:tf:F:c:C:l:L:H:")) != -1) { + while ((o = getopt(argc, argv, "46sS:p:P:m:M:n:d:tf:F:c:C:l:L:H:Q:")) != -1) { switch (o) { case 's': opt.silent_send = true; @@ -148,6 +151,10 @@ static void cs_parse_args(int argc, char *argv[]) opt.mark.ena = true; opt.mark.val = atoi(optarg); break; + case 'Q': + opt.priority.ena = true; + opt.priority.val = atoi(optarg); + break; case 'M': opt.sockopt.mark = atoi(optarg); break; @@ -252,6 +259,8 @@ cs_write_cmsg(int fd, struct msghdr *msg, char *cbuf, size_t cbuf_sz) ca_write_cmsg_u32(cbuf, cbuf_sz, &cmsg_len, SOL_SOCKET, SO_MARK, &opt.mark); + ca_write_cmsg_u32(cbuf, cbuf_sz, &cmsg_len, + SOL_SOCKET, SO_PRIORITY, &opt.priority); ca_write_cmsg_u32(cbuf, cbuf_sz, &cmsg_len, SOL_IPV6, IPV6_DONTFRAG, &opt.v6.dontfrag); ca_write_cmsg_u32(cbuf, cbuf_sz, &cmsg_len, diff --git a/tools/testing/selftests/net/cmsg_so_priority.sh b/tools/testing/selftests/net/cmsg_so_priority.sh new file mode 100755 index 000000000000..35dde2c5b67f --- /dev/null +++ b/tools/testing/selftests/net/cmsg_so_priority.sh @@ -0,0 +1,151 @@ +#!/bin/bash +# SPDX-License-Identifier: GPL-2.0 + +source lib.sh + +readonly KSFT_SKIP=4 + +IP4=192.0.2.1/24 +TGT4=192.0.2.2 +TGT4_RAW=192.0.2.3 +IP6=2001:db8::1/64 +TGT6=2001:db8::2 +TGT6_RAW=2001:db8::3 +PORT=1234 +TOTAL_TESTS=0 +FAILED_TESTS=0 + +if ! command -v jq &> /dev/null; then + echo "SKIP cmsg_so_priroity.sh test: jq is not installed." >&2 + exit "$KSFT_SKIP" +fi + +check_result() { + ((TOTAL_TESTS++)) + if [ "$1" -ne 0 ]; then + ((FAILED_TESTS++)) + fi +} + +cleanup() +{ + cleanup_ns $NS +} + +trap cleanup EXIT + +setup_ns NS + +create_filter() { + local handle=$1 + local vlan_prio=$2 + local ip_type=$3 + local proto=$4 + local dst_ip=$5 + local ip_proto + + if [[ "$proto" == "u" ]]; then + ip_proto="udp" + elif [[ "$ip_type" == "ipv4" && "$proto" == "i" ]]; then + ip_proto="icmp" + elif [[ "$ip_type" == "ipv6" && "$proto" == "i" ]]; then + ip_proto="icmpv6" + fi + + tc -n $NS filter add dev dummy1 \ + egress pref 1 handle "$handle" proto 802.1q \ + flower vlan_prio "$vlan_prio" vlan_ethtype "$ip_type" \ + dst_ip "$dst_ip" ${ip_proto:+ip_proto $ip_proto} \ + action pass +} + +ip -n $NS link set dev lo up +ip -n $NS link add name dummy1 up type dummy + +ip -n $NS link add link dummy1 name dummy1.10 up type vlan id 10 \ + egress-qos-map 0:0 1:1 2:2 3:3 4:4 5:5 6:6 7:7 + +ip -n $NS address add $IP4 dev dummy1.10 +ip -n $NS address add $IP6 dev dummy1.10 nodad + +ip netns exec $NS sysctl -wq net.ipv4.ping_group_range='0 2147483647' + +ip -n $NS neigh add $TGT4 lladdr 00:11:22:33:44:55 nud permanent \ + dev dummy1.10 +ip -n $NS neigh add $TGT6 lladdr 00:11:22:33:44:55 nud permanent \ + dev dummy1.10 +ip -n $NS neigh add $TGT4_RAW lladdr 00:11:22:33:44:66 nud permanent \ + dev dummy1.10 +ip -n $NS neigh add $TGT6_RAW lladdr 00:11:22:33:44:66 nud permanent \ + dev dummy1.10 + +tc -n $NS qdisc add dev dummy1 clsact + +FILTER_COUNTER=10 + +for i in 4 6; do + for proto in u i r; do + echo "Test IPV$i, prot: $proto" + for priority in {0..7}; do + if [[ $i == 4 && $proto == "r" ]]; then + TGT=$TGT4_RAW + elif [[ $i == 6 && $proto == "r" ]]; then + TGT=$TGT6_RAW + elif [ $i == 4 ]; then + TGT=$TGT4 + else + TGT=$TGT6 + fi + + handle="${FILTER_COUNTER}${priority}" + + create_filter $handle $priority ipv$i $proto $TGT + + pkts=$(tc -n $NS -j -s filter show dev dummy1 egress \ + | jq ".[] | select(.options.handle == ${handle}) | \ + .options.actions[0].stats.packets") + + if [[ $pkts == 0 ]]; then + check_result 0 + else + echo "prio $priority: expected 0, got $pkts" + check_result 1 + fi + + ip netns exec $NS ./cmsg_sender -$i -Q $priority \ + -p $proto $TGT $PORT + + pkts=$(tc -n $NS -j -s filter show dev dummy1 egress \ + | jq ".[] | select(.options.handle == ${handle}) | \ + .options.actions[0].stats.packets") + if [[ $pkts == 1 ]]; then + check_result 0 + else + echo "prio $priority -Q: expected 1, got $pkts" + check_result 1 + fi + + ip netns exec $NS ./cmsg_sender -$i -P $priority \ + -p $proto $TGT $PORT + + pkts=$(tc -n $NS -j -s filter show dev dummy1 egress \ + | jq ".[] | select(.options.handle == ${handle}) | \ + .options.actions[0].stats.packets") + if [[ $pkts == 2 ]]; then + check_result 0 + else + echo "prio $priority -P: expected 2, got $pkts" + check_result 1 + fi + done + FILTER_COUNTER=$((FILTER_COUNTER + 10)) + done +done + +if [ $FAILED_TESTS -ne 0 ]; then + echo "FAIL - $FAILED_TESTS/$TOTAL_TESTS tests failed" + exit 1 +else + echo "OK - All $TOTAL_TESTS tests passed" + exit 0 +fi From patchwork Fri Dec 13 08:44:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anna Nyiri X-Patchwork-Id: 13906666 Received: from mail-wm1-f51.google.com (mail-wm1-f51.google.com [209.85.128.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8307F1AF0AE; Fri, 13 Dec 2024 08:45:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734079546; cv=none; b=r9qlGafH8zFHgRMROJbH4t+mIW8Z51SSJz8gdCXJE1B2YxwKhJ1bnLLZYXMDupR6CwqYiZ0pyxx3B61togQUWyChTF2BBK8cJtGD+xPTtdWUvWFdOfR9gazvJD1X+jHUdIzxZP0z4DltJfjMFU8p1DzQXFNsYo0ss/gzzQlqGLk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734079546; c=relaxed/simple; bh=bKHfseLrLFam+t0l4K7cSgf5MpnHwyP6kMNZLJ8EnQU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=NxgQfHkBYSEg54wvmEkJpwXTK1yL766YFqdo/5GWsRokc4TB+3L9Di8L9SWs6IgRbphAjp18RuTIo00i1WZemZiMnVcLtvTxlkDBOb8tXP2L9eSF7Sy4jQUD7ZfomJkxo2qi0zskV9UzzUNYD28yQnJTJBEB+gZIenT0VnyaJlo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=ejl8/pF7; arc=none smtp.client-ip=209.85.128.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="ejl8/pF7" Received: by mail-wm1-f51.google.com with SMTP id 5b1f17b1804b1-436281c8a38so7570525e9.3; Fri, 13 Dec 2024 00:45:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1734079542; x=1734684342; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=1Wy+YHf2E614t23hlQRqaAuPuP0RfmetGDSjCxDtFm8=; b=ejl8/pF7Gegjk72RzgxkSdBbtaM+1Wp6tEXVdZfD9Ma/LEGNOrdClQ9BgiSrqx6ztU OeKL1JMSg8HbY1My3RICis7ltJZxCMdt1CzEz8EcMtfxnGeJshA6EECYHtZgkD4D9AFw tNrYtPKCXu+Keva43VDFYE1w0aWra2qSigf3+BhBL/NGTiUIi84hMxroznBLJSxS4WLK laNdJ55nB9rdU1qm3uzBYDnJMAa47nP0LUYH5IGDb5RqVcHwYOKTS+0F66x6RjQI6LA/ zHzdJDAq+0s/ckhYVbRnxW2AIJrMrYlLBAn4j2JqQfzbb44cHiui3u/fcncIb3UpvJ6l nrMA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734079542; x=1734684342; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=1Wy+YHf2E614t23hlQRqaAuPuP0RfmetGDSjCxDtFm8=; b=HLGU6Z6TRNIDKcVd4JF2bXaQJBmCmlRwV61BLdff2GROfKAryA/ocilwtv9EL1E+y1 LtdXLECGI4/6twXbX9NATYB8LWO2bOqF0ox6cIXk7p1YWVJbnCC6N3vlGyNk2p4LI2uh Bk1BNc7FFOcbs1isJlo+mqeu/gX4kUvvzFV1TaEeRZ9rQr5upEosOAS5bHOoZuEJ9O73 PyUh5F7kk8R6Vn4t+cB5CpDVn8QrJt7zcU0wWlmrvexni4tc/L5sR4jbHMtV0nJHyck5 twH9+OCuqSK7EyDlbMAyzDftvc9x5GUIyJaQ3fSt4J0bHrYAGHfbstuGzzhQksfBXxpo VdOw== X-Forwarded-Encrypted: i=1; AJvYcCUJ+fCzbpm3xlsmZGIYvmaAdGVgvQRj7iQvtJz+0E+MHDOb2/dElixqq1pw9qY2t1khiBJzf8O2se6smR1T@vger.kernel.org, AJvYcCUT45oj2kTrxIIm7jCUG7AL5ZuHBqoL5ozOaLn5bDloNFAnCSlqPJs/K60tvkbr0n4EpSfKE2Md5QNcjg==@vger.kernel.org, AJvYcCUd0vPpirqF/JTNBIBMcNsPsSKVMoMruN2/HUZHai6bsB4TYgyJZlms+K7mo5aFItv0ZIX0dkUXLqPD@vger.kernel.org, AJvYcCUxTKUU9Zp6hTjSvelblLMBmEe5o3paBlQrRfxyzdTUEo3UeztdostNXHJQl7Es9TFQjPZHHmlnjKGReA==@vger.kernel.org, AJvYcCVCVBIED9z/68mpHuoA4p60a+y+dzsQM8wW43AX7HwfqqDYvhrS9w0VQcLKO4SeBnpG0QJcDIQ2faNFOw==@vger.kernel.org, AJvYcCXctg1UrifCnXGu49FEmzeEcQlZBeccoB3EeQm68znGHGZnvOUEXDLt0fKsEpBeOH58QkC4yl1caXPNorURMms6@vger.kernel.org, AJvYcCXejwd42gPiB+joTt6OEZpPk7gAGFgz/AhbZE8Y+lobvxUFK9O84TN81W2J/GIxovUBj+nH6HdB7MOfiQ==@vger.kernel.org X-Gm-Message-State: AOJu0YxZH4dUM3sjb0/M54wvw1HqlPWW+nVvw7MCc/dh29Kc+aLeyDp3 0Ty9mgnrmc897Rhz8RRnC5HF+DMt4Ng5xOV/+McTyT+bJpzzQEBpwrxZ/oorIio= X-Gm-Gg: ASbGncs8398qdHKWr4sL6A8KOPfvVYqo+uSAOcPfdx36req4obmLFIQpsMCpzoIftXU P/L8s5WPURqSkWM61Zln5IlP7dBncCH3d6o56i3menxHUMigvbV/xtopAU8hD5GbnucOvIj3Ns3 nO+mthzegGPbxr0eYSjnkcmFuaYZaKwwzVuRVI2ypGGOtn8iqFJS+BCTIC+buNepwq/4zUoiU79 1Z3LaeQpZvG+edm8BM82STObWgZbMyxiSKP8sLOzvkyKeApPeeFjjs2GZ9rEtTpJOTbkHpZpj7G sSp1U4okno3Yv5QcUIwsdk5nGkuRT/QIciQ709sIraqRUkWNMEJOBZLcdU3sYvQ= X-Google-Smtp-Source: AGHT+IGTU+lhc2lWa5575ClokcDUoOVQuXcljdePkNZ8VtH/nBtJO1u/jxwEfj0Q47P8NpjHVdg9Xw== X-Received: by 2002:a05:600c:a10:b0:434:a59c:43c6 with SMTP id 5b1f17b1804b1-4362aaa4c0cmr10082605e9.26.1734079542232; Fri, 13 Dec 2024 00:45:42 -0800 (PST) Received: from localhost.localdomain (20014C4E1E9B09007B50BC12F2E5C1B6.dsl.pool.telekom.hu. [2001:4c4e:1e9b:900:7b50:bc12:f2e5:c1b6]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4362559eaf6sm42487645e9.20.2024.12.13.00.45.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Dec 2024 00:45:41 -0800 (PST) From: Anna Emese Nyiri To: netdev@vger.kernel.org Cc: fejes@inf.elte.hu, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, willemb@google.com, idosch@idosch.org, horms@kernel.org, dsahern@kernel.org, linux-can@vger.kernel.org, socketcan@hartkopp.net, mkl@pengutronix.de, linux-kselftest@vger.kernel.org, shuah@kernel.org, tsbogend@alpha.franken.de, kaiyuanz@google.com, James.Bottomley@HansenPartnership.com, richard.henderson@linaro.org, arnd@arndb.de, almasrymina@google.com, asml.silence@gmail.com, linux-mips@vger.kernel.org, andreas@gaisler.com, mattst88@gmail.com, kerneljasonxing@gmail.com, sparclinux@vger.kernel.org, linux-alpha@vger.kernel.org, linux-arch@vger.kernel.org, deller@gmx.de, vadim.fedorenko@linux.dev, linux-parisc@vger.kernel.org, Anna Emese Nyiri Subject: [PATCH net-next v7 4/4] sock: Introduce SO_RCVPRIORITY socket option Date: Fri, 13 Dec 2024 09:44:57 +0100 Message-ID: <20241213084457.45120-5-annaemesenyiri@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241213084457.45120-1-annaemesenyiri@gmail.com> References: <20241213084457.45120-1-annaemesenyiri@gmail.com> Precedence: bulk X-Mailing-List: linux-mips@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Add new socket option, SO_RCVPRIORITY, to include SO_PRIORITY in the ancillary data returned by recvmsg(). This is analogous to the existing support for SO_RCVMARK, as implemented in commit <6fd1d51cfa253> ("net: SO_RCVMARK socket option for SO_MARK with recvmsg()"). Reviewed-by: Willem de Bruijn Suggested-by: Ferenc Fejes Signed-off-by: Anna Emese Nyiri --- arch/alpha/include/uapi/asm/socket.h | 2 ++ arch/mips/include/uapi/asm/socket.h | 2 ++ arch/parisc/include/uapi/asm/socket.h | 2 ++ arch/sparc/include/uapi/asm/socket.h | 2 ++ include/net/sock.h | 4 +++- include/uapi/asm-generic/socket.h | 2 ++ net/core/sock.c | 8 ++++++++ net/socket.c | 11 +++++++++++ tools/include/uapi/asm-generic/socket.h | 2 ++ 9 files changed, 34 insertions(+), 1 deletion(-) diff --git a/arch/alpha/include/uapi/asm/socket.h b/arch/alpha/include/uapi/asm/socket.h index 302507bf9b5d..3df5f2dd4c0f 100644 --- a/arch/alpha/include/uapi/asm/socket.h +++ b/arch/alpha/include/uapi/asm/socket.h @@ -148,6 +148,8 @@ #define SCM_TS_OPT_ID 81 +#define SO_RCVPRIORITY 82 + #if !defined(__KERNEL__) #if __BITS_PER_LONG == 64 diff --git a/arch/mips/include/uapi/asm/socket.h b/arch/mips/include/uapi/asm/socket.h index d118d4731580..22fa8f19924a 100644 --- a/arch/mips/include/uapi/asm/socket.h +++ b/arch/mips/include/uapi/asm/socket.h @@ -159,6 +159,8 @@ #define SCM_TS_OPT_ID 81 +#define SO_RCVPRIORITY 82 + #if !defined(__KERNEL__) #if __BITS_PER_LONG == 64 diff --git a/arch/parisc/include/uapi/asm/socket.h b/arch/parisc/include/uapi/asm/socket.h index d268d69bfcd2..aa9cd4b951fe 100644 --- a/arch/parisc/include/uapi/asm/socket.h +++ b/arch/parisc/include/uapi/asm/socket.h @@ -140,6 +140,8 @@ #define SCM_TS_OPT_ID 0x404C +#define SO_RCVPRIORITY 0x404D + #if !defined(__KERNEL__) #if __BITS_PER_LONG == 64 diff --git a/arch/sparc/include/uapi/asm/socket.h b/arch/sparc/include/uapi/asm/socket.h index 113cd9f353e3..5b464a568664 100644 --- a/arch/sparc/include/uapi/asm/socket.h +++ b/arch/sparc/include/uapi/asm/socket.h @@ -141,6 +141,8 @@ #define SCM_TS_OPT_ID 0x005a +#define SO_RCVPRIORITY 0x005b + #if !defined(__KERNEL__) diff --git a/include/net/sock.h b/include/net/sock.h index 316a34d6c48b..d4bdd3286e03 100644 --- a/include/net/sock.h +++ b/include/net/sock.h @@ -953,6 +953,7 @@ enum sock_flags { SOCK_XDP, /* XDP is attached */ SOCK_TSTAMP_NEW, /* Indicates 64 bit timestamps always */ SOCK_RCVMARK, /* Receive SO_MARK ancillary data with packet */ + SOCK_RCVPRIORITY, /* Receive SO_PRIORITY ancillary data with packet */ }; #define SK_FLAGS_TIMESTAMP ((1UL << SOCK_TIMESTAMP) | (1UL << SOCK_TIMESTAMPING_RX_SOFTWARE)) @@ -2660,7 +2661,8 @@ static inline void sock_recv_cmsgs(struct msghdr *msg, struct sock *sk, { #define FLAGS_RECV_CMSGS ((1UL << SOCK_RXQ_OVFL) | \ (1UL << SOCK_RCVTSTAMP) | \ - (1UL << SOCK_RCVMARK)) + (1UL << SOCK_RCVMARK) |\ + (1UL << SOCK_RCVPRIORITY)) #define TSFLAGS_ANY (SOF_TIMESTAMPING_SOFTWARE | \ SOF_TIMESTAMPING_RAW_HARDWARE) diff --git a/include/uapi/asm-generic/socket.h b/include/uapi/asm-generic/socket.h index deacfd6dd197..aa5016ff3d91 100644 --- a/include/uapi/asm-generic/socket.h +++ b/include/uapi/asm-generic/socket.h @@ -143,6 +143,8 @@ #define SCM_TS_OPT_ID 81 +#define SO_RCVPRIORITY 82 + #if !defined(__KERNEL__) #if __BITS_PER_LONG == 64 || (defined(__x86_64__) && defined(__ILP32__)) diff --git a/net/core/sock.c b/net/core/sock.c index a3d9941c1d32..f9f4d976141e 100644 --- a/net/core/sock.c +++ b/net/core/sock.c @@ -1518,6 +1518,10 @@ int sk_setsockopt(struct sock *sk, int level, int optname, case SO_RCVMARK: sock_valbool_flag(sk, SOCK_RCVMARK, valbool); break; + + case SO_RCVPRIORITY: + sock_valbool_flag(sk, SOCK_RCVPRIORITY, valbool); + break; case SO_RXQ_OVFL: sock_valbool_flag(sk, SOCK_RXQ_OVFL, valbool); @@ -1947,6 +1951,10 @@ int sk_getsockopt(struct sock *sk, int level, int optname, v.val = sock_flag(sk, SOCK_RCVMARK); break; + case SO_RCVPRIORITY: + v.val = sock_flag(sk, SOCK_RCVPRIORITY); + break; + case SO_RXQ_OVFL: v.val = sock_flag(sk, SOCK_RXQ_OVFL); break; diff --git a/net/socket.c b/net/socket.c index 9a117248f18f..79d08b734f7c 100644 --- a/net/socket.c +++ b/net/socket.c @@ -1008,12 +1008,23 @@ static void sock_recv_mark(struct msghdr *msg, struct sock *sk, } } +static void sock_recv_priority(struct msghdr *msg, struct sock *sk, + struct sk_buff *skb) +{ + if (sock_flag(sk, SOCK_RCVPRIORITY) && skb) { + __u32 priority = skb->priority; + + put_cmsg(msg, SOL_SOCKET, SO_PRIORITY, sizeof(__u32), &priority); + } +} + void __sock_recv_cmsgs(struct msghdr *msg, struct sock *sk, struct sk_buff *skb) { sock_recv_timestamp(msg, sk, skb); sock_recv_drops(msg, sk, skb); sock_recv_mark(msg, sk, skb); + sock_recv_priority(msg, sk, skb); } EXPORT_SYMBOL_GPL(__sock_recv_cmsgs); diff --git a/tools/include/uapi/asm-generic/socket.h b/tools/include/uapi/asm-generic/socket.h index 281df9139d2b..ffff554a5230 100644 --- a/tools/include/uapi/asm-generic/socket.h +++ b/tools/include/uapi/asm-generic/socket.h @@ -126,6 +126,8 @@ #define SCM_TS_OPT_ID 78 +#define SO_RCVPRIORITY 79 + #if !defined(__KERNEL__) #if __BITS_PER_LONG == 64 || (defined(__x86_64__) && defined(__ILP32__))