Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1697409 > unrolled thread

[PATCH] net: inet: diag: expose sockets cgroup classid

Started by"Levin, Alexander (Sasha Levin)" <alexander.levin@verizon.com>
First post2017-07-26 19:30 +0200
Last post2017-07-27 01:10 +0200
Articles 3 — 2 participants

Back to article view | Back to linux.kernel


Contents

  [PATCH] net: inet: diag: expose sockets cgroup classid "Levin, Alexander (Sasha Levin)" <alexander.levin@verizon.com> - 2017-07-26 19:30 +0200
    Re: [PATCH] net: inet: diag: expose sockets cgroup classid Cong Wang <xiyou.wangcong@gmail.com> - 2017-07-27 00:10 +0200
      Re: [PATCH] net: inet: diag: expose sockets cgroup classid "Levin, Alexander (Sasha Levin)" <alexander.levin@verizon.com> - 2017-07-27 01:10 +0200

#1697409 — [PATCH] net: inet: diag: expose sockets cgroup classid

From"Levin, Alexander (Sasha Levin)" <alexander.levin@verizon.com>
Date2017-07-26 19:30 +0200
Subject[PATCH] net: inet: diag: expose sockets cgroup classid
Message-ID<u7yie-3eE-9@gated-at.bofh.it>
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>
---
 include/uapi/linux/inet_diag.h |  1 +
 net/ipv4/inet_diag.c           | 10 ++++++++++
 2 files changed, 11 insertions(+)

diff --git a/include/uapi/linux/inet_diag.h b/include/uapi/linux/inet_diag.h
index bbe201047df6..678496897a68 100644
--- a/include/uapi/linux/inet_diag.h
+++ b/include/uapi/linux/inet_diag.h
@@ -142,6 +142,7 @@ enum {
 	INET_DIAG_PAD,
 	INET_DIAG_MARK,
 	INET_DIAG_BBRINFO,
+	INET_DIAG_CLASS_ID,
 	__INET_DIAG_MAX,
 };
 
diff --git a/net/ipv4/inet_diag.c b/net/ipv4/inet_diag.c
index 3828b3a805cd..ffc6dad9780a 100644
--- a/net/ipv4/inet_diag.c
+++ b/net/ipv4/inet_diag.c
@@ -274,6 +274,16 @@ 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
+
+		nla_put(skb, INET_DIAG_CLASS_ID, sizeof(classid), &classid);
+	}
+
 out:
 	nlmsg_end(skb, nlh);
 	return 0;
-- 
2.11.0

[toc] | [next] | [standalone]


#1697591

FromCong Wang <xiyou.wangcong@gmail.com>
Date2017-07-27 00:10 +0200
Message-ID<u7CFc-65z-9@gated-at.bofh.it>
In reply to#1697409
On Wed, Jul 26, 2017 at 10:22 AM, Levin, Alexander (Sasha Levin)
<alexander.levin@verizon.com> wrote:
> +       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 CONFIG_SOCK_CGROUP_DATA is not enabled, should we put 0
or put nothing (that is, skipping this nla_put())?

> +
> +               nla_put(skb, INET_DIAG_CLASS_ID, sizeof(classid), &classid);

nla_put_u32()

Thanks.

[toc] | [prev] | [next] | [standalone]


#1697617

From"Levin, Alexander (Sasha Levin)" <alexander.levin@verizon.com>
Date2017-07-27 01:10 +0200
Message-ID<u7DBg-6H2-13@gated-at.bofh.it>
In reply to#1697591
On Wed, Jul 26, 2017 at 03:01:32PM -0700, Cong Wang wrote:
>On Wed, Jul 26, 2017 at 10:22 AM, Levin, Alexander (Sasha Levin)
><alexander.levin@verizon.com> wrote:
>> +       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 CONFIG_SOCK_CGROUP_DATA is not enabled, should we put 0
>or put nothing (that is, skipping this nla_put())?

My logic was that if CONFIG_SOCK_CGROUP_DATA is disabled, then all sockets have the same default classid ==> 0, rather than having to deal with whether that config is enabled or not.

>> +
>> +               nla_put(skb, INET_DIAG_CLASS_ID, sizeof(classid), &classid);
>
>nla_put_u32()

Will fix, thanks!

-- 

Thanks,
Sasha

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web