Skip to content

Commit b3e365b

Browse files
q2venkuba-moo
authored andcommitted
af_unix: Set drop reason in unix_dgram_disconnected().
unix_dgram_disconnected() is called from two places: 1. when a connect()ed socket dis-connect()s or re-connect()s to another socket 2. when sendmsg() fails because the peer socket that the client has connect()ed to has been close()d Then, the client's recv queue is purged to remove all messages from the old peer socket. Let's define a new drop reason for that case. # echo 1 > /sys/kernel/tracing/events/skb/kfree_skb/enable # python3 >>> from socket import * >>> >>> # s1 has a message from s2 >>> s1, s2 = socketpair(AF_UNIX, SOCK_DGRAM) >>> s2.send(b'hello world') >>> >>> # re-connect() drops the message from s2 >>> s3 = socket(AF_UNIX, SOCK_DGRAM) >>> s3.bind('') >>> s1.connect(s3.getsockname()) # cat /sys/kernel/tracing/trace_pipe python3-250 ... kfree_skb: ... location=skb_queue_purge_reason+0xdc/0x110 reason: UNIX_DISCONNECT Signed-off-by: Kuniyuki Iwashima <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent bace4b4 commit b3e365b

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

include/net/dropreason-core.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
FN(SOCKET_CLOSE) \
1010
FN(SOCKET_FILTER) \
1111
FN(SOCKET_RCVBUFF) \
12+
FN(UNIX_DISCONNECT) \
1213
FN(UNIX_SKIP_OOB) \
1314
FN(PKT_TOO_SMALL) \
1415
FN(TCP_CSUM) \
@@ -146,6 +147,12 @@ enum skb_drop_reason {
146147
SKB_DROP_REASON_SOCKET_FILTER,
147148
/** @SKB_DROP_REASON_SOCKET_RCVBUFF: socket receive buff is full */
148149
SKB_DROP_REASON_SOCKET_RCVBUFF,
150+
/**
151+
* @SKB_DROP_REASON_UNIX_DISCONNECT: recv queue is purged when SOCK_DGRAM
152+
* or SOCK_SEQPACKET socket re-connect()s to another socket or notices
153+
* during send() that the peer has been close()d.
154+
*/
155+
SKB_DROP_REASON_UNIX_DISCONNECT,
149156
/**
150157
* @SKB_DROP_REASON_UNIX_SKIP_OOB: Out-Of-Band data is skipped by
151158
* recv() without MSG_OOB so dropped.

net/unix/af_unix.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -622,7 +622,9 @@ static void unix_write_space(struct sock *sk)
622622
static void unix_dgram_disconnected(struct sock *sk, struct sock *other)
623623
{
624624
if (!skb_queue_empty(&sk->sk_receive_queue)) {
625-
skb_queue_purge(&sk->sk_receive_queue);
625+
skb_queue_purge_reason(&sk->sk_receive_queue,
626+
SKB_DROP_REASON_UNIX_DISCONNECT);
627+
626628
wake_up_interruptible_all(&unix_sk(sk)->peer_wait);
627629

628630
/* If one link of bidirectional dgram pipe is disconnected,

0 commit comments

Comments
 (0)