net: inet: diag: expose sockets cgroup classid
authorLevin, Alexander (Sasha Levin) <alexander.levin@one.verizon.com>
Thu, 17 Aug 2017 00:35:11 +0000 (00:35 +0000)
committerDavid S. Miller <davem@davemloft.net>
Fri, 18 Aug 2017 23:10:50 +0000 (16:10 -0700)
This is useful for directly looking up a task based on class id rather than
having to scan through all open file descriptors.

Signed-off-by: Sasha Levin <alexander.levin@verizon.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
include/uapi/linux/inet_diag.h
net/ipv4/inet_diag.c

index bbe201047df6c8cd5e56d8e783d3934163c10d0b..678496897a689e6e6afd694fd5cab236a63d733d 100644 (file)
@@ -142,6 +142,7 @@ enum {
        INET_DIAG_PAD,
        INET_DIAG_MARK,
        INET_DIAG_BBRINFO,
+       INET_DIAG_CLASS_ID,
        __INET_DIAG_MAX,
 };
 
index 3828b3a805cdeae87f4ad9300f35fff048e23691..67325d5832d7f987d69fb216a6178bed9c74da5b 100644 (file)
@@ -274,6 +274,17 @@ int inet_sk_diag_fill(struct sock *sk, struct inet_connection_sock *icsk,
                        goto errout;
        }
 
+       if (ext & (1 << (INET_DIAG_CLASS_ID - 1))) {
+               u32 classid = 0;
+
+#ifdef CONFIG_SOCK_CGROUP_DATA
+               classid = sock_cgroup_classid(&sk->sk_cgrp_data);
+#endif
+
+               if (nla_put_u32(skb, INET_DIAG_CLASS_ID, classid))
+                       goto errout;
+       }
+
 out:
        nlmsg_end(skb, nlh);
        return 0;