sock: Introduce SO_RCVPRIORITY socket option

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 6fd1d51cfa ("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>
Link: https://patch.msgid.link/20241213084457.45120-5-annaemesenyiri@gmail.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
This commit is contained in:
Anna Emese Nyiri 2024-12-13 09:44:57 +01:00 committed by Jakub Kicinski
parent cda7d5abe0
commit e45469e594
9 changed files with 34 additions and 1 deletions

View File

@ -148,6 +148,8 @@
#define SCM_TS_OPT_ID 81 #define SCM_TS_OPT_ID 81
#define SO_RCVPRIORITY 82
#if !defined(__KERNEL__) #if !defined(__KERNEL__)
#if __BITS_PER_LONG == 64 #if __BITS_PER_LONG == 64

View File

@ -159,6 +159,8 @@
#define SCM_TS_OPT_ID 81 #define SCM_TS_OPT_ID 81
#define SO_RCVPRIORITY 82
#if !defined(__KERNEL__) #if !defined(__KERNEL__)
#if __BITS_PER_LONG == 64 #if __BITS_PER_LONG == 64

View File

@ -140,6 +140,8 @@
#define SCM_TS_OPT_ID 0x404C #define SCM_TS_OPT_ID 0x404C
#define SO_RCVPRIORITY 0x404D
#if !defined(__KERNEL__) #if !defined(__KERNEL__)
#if __BITS_PER_LONG == 64 #if __BITS_PER_LONG == 64

View File

@ -141,6 +141,8 @@
#define SCM_TS_OPT_ID 0x005a #define SCM_TS_OPT_ID 0x005a
#define SO_RCVPRIORITY 0x005b
#if !defined(__KERNEL__) #if !defined(__KERNEL__)

View File

@ -953,6 +953,7 @@ enum sock_flags {
SOCK_XDP, /* XDP is attached */ SOCK_XDP, /* XDP is attached */
SOCK_TSTAMP_NEW, /* Indicates 64 bit timestamps always */ SOCK_TSTAMP_NEW, /* Indicates 64 bit timestamps always */
SOCK_RCVMARK, /* Receive SO_MARK ancillary data with packet */ 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)) #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) | \ #define FLAGS_RECV_CMSGS ((1UL << SOCK_RXQ_OVFL) | \
(1UL << SOCK_RCVTSTAMP) | \ (1UL << SOCK_RCVTSTAMP) | \
(1UL << SOCK_RCVMARK)) (1UL << SOCK_RCVMARK) |\
(1UL << SOCK_RCVPRIORITY))
#define TSFLAGS_ANY (SOF_TIMESTAMPING_SOFTWARE | \ #define TSFLAGS_ANY (SOF_TIMESTAMPING_SOFTWARE | \
SOF_TIMESTAMPING_RAW_HARDWARE) SOF_TIMESTAMPING_RAW_HARDWARE)

View File

@ -143,6 +143,8 @@
#define SCM_TS_OPT_ID 81 #define SCM_TS_OPT_ID 81
#define SO_RCVPRIORITY 82
#if !defined(__KERNEL__) #if !defined(__KERNEL__)
#if __BITS_PER_LONG == 64 || (defined(__x86_64__) && defined(__ILP32__)) #if __BITS_PER_LONG == 64 || (defined(__x86_64__) && defined(__ILP32__))

View File

@ -1519,6 +1519,10 @@ int sk_setsockopt(struct sock *sk, int level, int optname,
sock_valbool_flag(sk, SOCK_RCVMARK, valbool); sock_valbool_flag(sk, SOCK_RCVMARK, valbool);
break; break;
case SO_RCVPRIORITY:
sock_valbool_flag(sk, SOCK_RCVPRIORITY, valbool);
break;
case SO_RXQ_OVFL: case SO_RXQ_OVFL:
sock_valbool_flag(sk, SOCK_RXQ_OVFL, valbool); sock_valbool_flag(sk, SOCK_RXQ_OVFL, valbool);
break; break;
@ -1947,6 +1951,10 @@ int sk_getsockopt(struct sock *sk, int level, int optname,
v.val = sock_flag(sk, SOCK_RCVMARK); v.val = sock_flag(sk, SOCK_RCVMARK);
break; break;
case SO_RCVPRIORITY:
v.val = sock_flag(sk, SOCK_RCVPRIORITY);
break;
case SO_RXQ_OVFL: case SO_RXQ_OVFL:
v.val = sock_flag(sk, SOCK_RXQ_OVFL); v.val = sock_flag(sk, SOCK_RXQ_OVFL);
break; break;

View File

@ -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, void __sock_recv_cmsgs(struct msghdr *msg, struct sock *sk,
struct sk_buff *skb) struct sk_buff *skb)
{ {
sock_recv_timestamp(msg, sk, skb); sock_recv_timestamp(msg, sk, skb);
sock_recv_drops(msg, sk, skb); sock_recv_drops(msg, sk, skb);
sock_recv_mark(msg, sk, skb); sock_recv_mark(msg, sk, skb);
sock_recv_priority(msg, sk, skb);
} }
EXPORT_SYMBOL_GPL(__sock_recv_cmsgs); EXPORT_SYMBOL_GPL(__sock_recv_cmsgs);

View File

@ -126,6 +126,8 @@
#define SCM_TS_OPT_ID 78 #define SCM_TS_OPT_ID 78
#define SO_RCVPRIORITY 79
#if !defined(__KERNEL__) #if !defined(__KERNEL__)
#if __BITS_PER_LONG == 64 || (defined(__x86_64__) && defined(__ILP32__)) #if __BITS_PER_LONG == 64 || (defined(__x86_64__) && defined(__ILP32__))