Skip to content

Commit

Permalink
net: udp: use kfree_skb_reason() in __udp_queue_rcv_skb()
Browse files Browse the repository at this point in the history
Replace kfree_skb() with kfree_skb_reason() in __udp_queue_rcv_skb().
Following new drop reasons are introduced:

SKB_DROP_REASON_SOCKET_RCVBUFF
SKB_DROP_REASON_PROTO_MEM

Signed-off-by: Menglong Dong <imagedong@tencent.com>
Reviewed-by: David Ahern <dsahern@kernel.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
xmmgithub authored and davem330 committed Feb 7, 2022
1 parent 1379a92 commit 08d4c03
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
5 changes: 5 additions & 0 deletions include/linux/skbuff.h
Expand Up @@ -341,6 +341,11 @@ enum skb_drop_reason {
*/
SKB_DROP_REASON_XFRM_POLICY, /* xfrm policy check failed */
SKB_DROP_REASON_IP_NOPROTO, /* no support for IP protocol */
SKB_DROP_REASON_SOCKET_RCVBUFF, /* socket receive buff is full */
SKB_DROP_REASON_PROTO_MEM, /* proto memory limition, such as
* udp packet drop out of
* udp_memory_allocated.
*/
SKB_DROP_REASON_MAX,
};

Expand Down
2 changes: 2 additions & 0 deletions include/trace/events/skb.h
Expand Up @@ -25,6 +25,8 @@
UNICAST_IN_L2_MULTICAST) \
EM(SKB_DROP_REASON_XFRM_POLICY, XFRM_POLICY) \
EM(SKB_DROP_REASON_IP_NOPROTO, IP_NOPROTO) \
EM(SKB_DROP_REASON_SOCKET_RCVBUFF, SOCKET_RCVBUFF) \
EM(SKB_DROP_REASON_PROTO_MEM, PROTO_MEM) \
EMe(SKB_DROP_REASON_MAX, MAX)

#undef EM
Expand Down
10 changes: 7 additions & 3 deletions net/ipv4/udp.c
Expand Up @@ -2093,16 +2093,20 @@ static int __udp_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
rc = __udp_enqueue_schedule_skb(sk, skb);
if (rc < 0) {
int is_udplite = IS_UDPLITE(sk);
int drop_reason;

/* Note that an ENOMEM error is charged twice */
if (rc == -ENOMEM)
if (rc == -ENOMEM) {
UDP_INC_STATS(sock_net(sk), UDP_MIB_RCVBUFERRORS,
is_udplite);
else
drop_reason = SKB_DROP_REASON_SOCKET_RCVBUFF;
} else {
UDP_INC_STATS(sock_net(sk), UDP_MIB_MEMERRORS,
is_udplite);
drop_reason = SKB_DROP_REASON_PROTO_MEM;
}
UDP_INC_STATS(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
kfree_skb(skb);
kfree_skb_reason(skb, drop_reason);
trace_udp_fail_queue_rcv_skb(rc, sk);
return -1;
}
Expand Down

0 comments on commit 08d4c03

Please sign in to comment.