diff mbox

[net-next] sock_diag: fetch source port from inet_sock

Message ID 1434553150-8750-1-git-send-email-kraig@google.com
State Accepted, archived
Delegated to: David Miller
Headers show

Commit Message

Craig Gallek June 17, 2015, 2:59 p.m. UTC
When an inet_sock is destroyed, its source port (sk_num) is set to
zero as part of the unhash procedure.  In order to supply a source
port as part of the NETLINK_SOCK_DIAG socket destruction broadcasts,
the source port number must be read from inet_sport instead.

Tested: ss -E
Signed-off-by: Craig Gallek <kraig@google.com>
---
 net/ipv4/inet_diag.c | 2 ++
 1 file changed, 2 insertions(+)

Comments

David Miller June 21, 2015, 5:17 p.m. UTC | #1
From: Craig Gallek <kraig@google.com>
Date: Wed, 17 Jun 2015 10:59:10 -0400

> When an inet_sock is destroyed, its source port (sk_num) is set to
> zero as part of the unhash procedure.  In order to supply a source
> port as part of the NETLINK_SOCK_DIAG socket destruction broadcasts,
> the source port number must be read from inet_sport instead.
> 
> Tested: ss -E
> Signed-off-by: Craig Gallek <kraig@google.com>

Applied but it seems very hackish and not very long term maintainable
to do things this way.
--
To unsubscribe from this list: send the line "unsubscribe netdev" in
diff mbox

Patch

diff --git a/net/ipv4/inet_diag.c b/net/ipv4/inet_diag.c
index 21985d8..ba6a80f 100644
--- a/net/ipv4/inet_diag.c
+++ b/net/ipv4/inet_diag.c
@@ -1095,6 +1095,8 @@  int inet_diag_handler_get_info(struct sk_buff *skb, struct sock *sk)
 	r = nlmsg_data(nlh);
 	memset(r, 0, sizeof(*r));
 	inet_diag_msg_common_fill(r, sk);
+	if (sk->sk_type == SOCK_DGRAM || sk->sk_type == SOCK_STREAM)
+		r->id.idiag_sport = inet_sk(sk)->inet_sport;
 	r->idiag_state = sk->sk_state;
 
 	if ((err = nla_put_u8(skb, INET_DIAG_PROTOCOL, sk->sk_protocol))) {