linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] net: inet: diag: expose sockets cgroup classid
@ 2017-07-27 18:11 Levin, Alexander (Sasha Levin)
  2017-07-28  3:23 ` Jakub Kicinski
  2017-08-16 20:13 ` Levin, Alexander (Sasha Levin)
  0 siblings, 2 replies; 5+ messages in thread
From: Levin, Alexander (Sasha Levin) @ 2017-07-27 18:11 UTC (permalink / raw)
  To: davem
  Cc: netdev, linux-kernel, xiyou.wangcong, Levin, Alexander (Sasha Levin)

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>
---

Changes in V2:
 - Addressed comments from Cong Wang (use nla_put_u32())

 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..2c2445d4bb58 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_u32(skb, INET_DIAG_CLASS_ID, classid);
+	}
+
 out:
 	nlmsg_end(skb, nlh);
 	return 0;
-- 
2.11.0

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH v2] net: inet: diag: expose sockets cgroup classid
  2017-07-27 18:11 [PATCH v2] net: inet: diag: expose sockets cgroup classid Levin, Alexander (Sasha Levin)
@ 2017-07-28  3:23 ` Jakub Kicinski
  2017-08-16 20:13 ` Levin, Alexander (Sasha Levin)
  1 sibling, 0 replies; 5+ messages in thread
From: Jakub Kicinski @ 2017-07-28  3:23 UTC (permalink / raw)
  To: Levin, Alexander (Sasha Levin)
  Cc: davem, netdev, linux-kernel, xiyou.wangcong

On Thu, 27 Jul 2017 18:11:32 +0000, Levin, Alexander (Sasha Levin)
wrote:
> 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>
> ---
> 
> Changes in V2:
>  - Addressed comments from Cong Wang (use nla_put_u32())
> 
>  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..2c2445d4bb58 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_u32(skb, INET_DIAG_CLASS_ID, classid);

You need to check the return value from nla_put_u32() and goto errout
if it's set.  

Perhaps adding __must_check to the nla_put_*() helpers would be a good
idea.

> +	}
> +
>  out:
>  	nlmsg_end(skb, nlh);
>  	return 0;

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v2] net: inet: diag: expose sockets cgroup classid
  2017-07-27 18:11 [PATCH v2] net: inet: diag: expose sockets cgroup classid Levin, Alexander (Sasha Levin)
  2017-07-28  3:23 ` Jakub Kicinski
@ 2017-08-16 20:13 ` Levin, Alexander (Sasha Levin)
  2017-08-16 20:15   ` Cong Wang
  1 sibling, 1 reply; 5+ messages in thread
From: Levin, Alexander (Sasha Levin) @ 2017-08-16 20:13 UTC (permalink / raw)
  To: davem; +Cc: netdev, linux-kernel, xiyou.wangcong

Ping?

On Thu, Jul 27, 2017 at 02:13:52PM -0400, Sasha Levin wrote:
>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>
>---
>
>Changes in V2:
> - Addressed comments from Cong Wang (use nla_put_u32())
>
> 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..2c2445d4bb58 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_u32(skb, INET_DIAG_CLASS_ID, classid);
>+	}
>+
> out:
> 	nlmsg_end(skb, nlh);
> 	return 0;
>-- 
>2.11.0

-- 

Thanks,
Sasha

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v2] net: inet: diag: expose sockets cgroup classid
  2017-08-16 20:13 ` Levin, Alexander (Sasha Levin)
@ 2017-08-16 20:15   ` Cong Wang
  2017-08-17  0:28     ` Levin, Alexander (Sasha Levin)
  0 siblings, 1 reply; 5+ messages in thread
From: Cong Wang @ 2017-08-16 20:15 UTC (permalink / raw)
  To: Levin, Alexander (Sasha Levin); +Cc: davem, netdev, linux-kernel

On Wed, Aug 16, 2017 at 1:13 PM, Levin, Alexander (Sasha Levin)
<alexander.levin@verizon.com> wrote:
> Ping?

I guess you missed the comment saying you need to check
the return value of nla_put_u32().

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v2] net: inet: diag: expose sockets cgroup classid
  2017-08-16 20:15   ` Cong Wang
@ 2017-08-17  0:28     ` Levin, Alexander (Sasha Levin)
  0 siblings, 0 replies; 5+ messages in thread
From: Levin, Alexander (Sasha Levin) @ 2017-08-17  0:28 UTC (permalink / raw)
  To: Cong Wang; +Cc: davem, netdev, linux-kernel

On Wed, Aug 16, 2017 at 01:15:57PM -0700, Cong Wang wrote:
>On Wed, Aug 16, 2017 at 1:13 PM, Levin, Alexander (Sasha Levin)
><alexander.levin@verizon.com> wrote:
>> Ping?
>
>I guess you missed the comment saying you need to check
>the return value of nla_put_u32().

Indeed I did. Odd, I don't see the mail locally, but I can find it in patchwork.... I'll send a v3.

-- 

Thanks,
Sasha

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2017-08-17  0:29 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-07-27 18:11 [PATCH v2] net: inet: diag: expose sockets cgroup classid Levin, Alexander (Sasha Levin)
2017-07-28  3:23 ` Jakub Kicinski
2017-08-16 20:13 ` Levin, Alexander (Sasha Levin)
2017-08-16 20:15   ` Cong Wang
2017-08-17  0:28     ` Levin, Alexander (Sasha Levin)

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).