net: sock: introduce sock_queue_rcv_skb_reason()
authorMenglong Dong <imagedong@tencent.com>
Thu, 7 Apr 2022 06:20:49 +0000 (14:20 +0800)
committerDavid S. Miller <davem@davemloft.net>
Mon, 11 Apr 2022 09:38:37 +0000 (10:38 +0100)
In order to report the reasons of skb drops in 'sock_queue_rcv_skb()',
introduce the function 'sock_queue_rcv_skb_reason()'.

As the return value of 'sock_queue_rcv_skb()' is used as the error code,
we can't make it as drop reason and have to pass extra output argument.
'sock_queue_rcv_skb()' is used in many places, so we can't change it
directly.

Introduce the new function 'sock_queue_rcv_skb_reason()' and make
'sock_queue_rcv_skb()' an inline call to it.

Reviewed-by: Hao Peng <flyingpeng@tencent.com>
Reviewed-by: Jiang Biao <benbjiang@tencent.com>
Signed-off-by: Menglong Dong <imagedong@tencent.com>
Reviewed-by: David Ahern <dsahern@kernel.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
include/net/sock.h
net/core/sock.c

index c4b91fc19b9cad34f1343098617109cf36eafbb3..1a988e605f0992ecb020876150a0fb129940e157 100644 (file)
@@ -2392,7 +2392,14 @@ int __sk_queue_drop_skb(struct sock *sk, struct sk_buff_head *sk_queue,
                        void (*destructor)(struct sock *sk,
                                           struct sk_buff *skb));
 int __sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb);
-int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb);
+
+int sock_queue_rcv_skb_reason(struct sock *sk, struct sk_buff *skb,
+                             enum skb_drop_reason *reason);
+
+static inline int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
+{
+       return sock_queue_rcv_skb_reason(sk, skb, NULL);
+}
 
 int sock_queue_err_skb(struct sock *sk, struct sk_buff *skb);
 struct sk_buff *sock_dequeue_err_skb(struct sock *sk);
index 7000403eaeb260ff2affa4be24496c07bd04790a..05e0cfa064b6e98786a795297ec2914c029e2486 100644 (file)
@@ -505,17 +505,35 @@ int __sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
 }
 EXPORT_SYMBOL(__sock_queue_rcv_skb);
 
-int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
+int sock_queue_rcv_skb_reason(struct sock *sk, struct sk_buff *skb,
+                             enum skb_drop_reason *reason)
 {
+       enum skb_drop_reason drop_reason;
        int err;
 
        err = sk_filter(sk, skb);
-       if (err)
-               return err;
-
-       return __sock_queue_rcv_skb(sk, skb);
+       if (err) {
+               drop_reason = SKB_DROP_REASON_SOCKET_FILTER;
+               goto out;
+       }
+       err = __sock_queue_rcv_skb(sk, skb);
+       switch (err) {
+       case -ENOMEM:
+               drop_reason = SKB_DROP_REASON_SOCKET_RCVBUFF;
+               break;
+       case -ENOBUFS:
+               drop_reason = SKB_DROP_REASON_PROTO_MEM;
+               break;
+       default:
+               drop_reason = SKB_NOT_DROPPED_YET;
+               break;
+       }
+out:
+       if (reason)
+               *reason = drop_reason;
+       return err;
 }
-EXPORT_SYMBOL(sock_queue_rcv_skb);
+EXPORT_SYMBOL(sock_queue_rcv_skb_reason);
 
 int __sk_receive_skb(struct sock *sk, struct sk_buff *skb,
                     const int nested, unsigned int trim_cap, bool refcounted)