From: Anna Emese Nyiri <annaemesenyiri@gmail.com>
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 <annaemesenyiri@gmail.com>
Subject: [PATCH net-next v7 4/4] sock: Introduce SO_RCVPRIORITY socket option
Date: Fri, 13 Dec 2024 09:44:57 +0100 [thread overview]
Message-ID: <20241213084457.45120-5-annaemesenyiri@gmail.com> (raw)
In-Reply-To: <20241213084457.45120-1-annaemesenyiri@gmail.com>
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 <willemb@google.com>
Suggested-by: Ferenc Fejes <fejes@inf.elte.hu>
Signed-off-by: Anna Emese Nyiri <annaemesenyiri@gmail.com>
---
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__))
--
2.43.0
next prev parent reply other threads:[~2024-12-13 8:45 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-12-13 8:44 [PATCH net-next v7 0/4] Add support for SO_PRIORITY cmsg Anna Emese Nyiri
2024-12-13 8:44 ` [PATCH net-next v7 1/4] sock: Introduce sk_set_prio_allowed helper function Anna Emese Nyiri
2024-12-13 8:44 ` [PATCH net-next v7 2/4] sock: support SO_PRIORITY cmsg Anna Emese Nyiri
2024-12-13 8:44 ` [PATCH net-next v7 3/4] selftests: net: test SO_PRIORITY ancillary data with cmsg_sender Anna Emese Nyiri
2024-12-13 8:44 ` Anna Emese Nyiri [this message]
2024-12-17 2:20 ` [PATCH net-next v7 4/4] sock: Introduce SO_RCVPRIORITY socket option Jakub Kicinski
2024-12-18 11:57 ` Anna Nyiri
2024-12-17 2:30 ` [PATCH net-next v7 0/4] Add support for SO_PRIORITY cmsg patchwork-bot+netdevbpf
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=20241213084457.45120-5-annaemesenyiri@gmail.com \
--to=annaemesenyiri@gmail.com \
--cc=James.Bottomley@HansenPartnership.com \
--cc=almasrymina@google.com \
--cc=andreas@gaisler.com \
--cc=arnd@arndb.de \
--cc=asml.silence@gmail.com \
--cc=deller@gmx.de \
--cc=dsahern@kernel.org \
--cc=edumazet@google.com \
--cc=fejes@inf.elte.hu \
--cc=horms@kernel.org \
--cc=idosch@idosch.org \
--cc=kaiyuanz@google.com \
--cc=kerneljasonxing@gmail.com \
--cc=kuba@kernel.org \
--cc=linux-alpha@vger.kernel.org \
--cc=linux-arch@vger.kernel.org \
--cc=linux-can@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=linux-mips@vger.kernel.org \
--cc=linux-parisc@vger.kernel.org \
--cc=mattst88@gmail.com \
--cc=mkl@pengutronix.de \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=richard.henderson@linaro.org \
--cc=shuah@kernel.org \
--cc=socketcan@hartkopp.net \
--cc=sparclinux@vger.kernel.org \
--cc=tsbogend@alpha.franken.de \
--cc=vadim.fedorenko@linux.dev \
--cc=willemb@google.com \
/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