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


Groups > linux.kernel > #1698229 > unrolled thread

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

Started by"Levin, Alexander (Sasha Levin)" <alexander.levin@verizon.com>
First post2017-07-27 20:20 +0200
Last post2017-07-28 05:30 +0200
Articles 2 — 2 participants

Back to article view | Back to linux.kernel


Contents

  [PATCH v2] net: inet: diag: expose sockets cgroup classid "Levin, Alexander (Sasha Levin)" <alexander.levin@verizon.com> - 2017-07-27 20:20 +0200
    Re: [PATCH v2] net: inet: diag: expose sockets cgroup classid Jakub Kicinski <kubakici@wp.pl> - 2017-07-28 05:30 +0200

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

From"Levin, Alexander (Sasha Levin)" <alexander.levin@verizon.com>
Date2017-07-27 20:20 +0200
Subject[PATCH v2] net: inet: diag: expose sockets cgroup classid
Message-ID<u7Vy9-12j-3@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>
---

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

[toc] | [next] | [standalone]


#1698439

FromJakub Kicinski <kubakici@wp.pl>
Date2017-07-28 05:30 +0200
Message-ID<u848p-6HH-5@gated-at.bofh.it>
In reply to#1698229
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;

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web