inet_diag: add cgroup id attribute
Subsystems (4)
PATCH v2 1/1 inet_diag: add cgroup id attribute
This patch adds cgroup v2 id to common inet diag message attributes. This allows investigate sockets on per cgroup basis when net_cls/net_prio cgroup not used.
--- include/linux/inet_diag.h | 6 +++++- include/uapi/linux/inet_diag.h | 1 + net/ipv4/inet_diag.c | 7 +++++++ 3 files changed, 13 insertions(+), 1 deletion(-)
include/linux/inet_diag.h +5 -1
@@ -66,7 +66,11 @@ static inline size_t inet_diag_msg_attrs_size(void) + nla_total_size(1) /* INET_DIAG_SKV6ONLY */ #endif + nla_total_size(4) /* INET_DIAG_MARK */ - +nla_total_size (4 );/* INET_DIAG_CLASS_ID */ + + nla_total_size(4) /* INET_DIAG_CLASS_ID */ +#ifdef CONFIG_SOCK_CGROUP_DATA + + nla_total_size(8) /* INET_DIAG_CGROUP_ID */ +#endif + ; } int inet_diag_msg_attrs_fill(struct sock *sk, struct sk_buff *skb, struct inet_diag_msg *r, int ext,
include/uapi/linux/inet_diag.h +1 -0
@@ -154,6 +154,7 @@ enum {INET_DIAG_CLASS_ID ,/* request as INET_DIAG_TCLASS */ INET_DIAG_MD5SIG ,INET_DIAG_ULP_INFO , +INET_DIAG_CGROUP_ID , __INET_DIAG_MAX, };
net/ipv4/inet_diag.c +7 -0
@@ -161,6 +161,13 @@ int inet_diag_msg_attrs_fill(struct sock *sk, struct sk_buff *skb, goto errout; } +#ifdef CONFIG_SOCK_CGROUP_DATA +if (nla_put_u64_64bit (skb,INET_DIAG_CGROUP_ID , +cgroup_id (sock_cgroup_ptr (&sk->sk_cgrp_data)), +INET_DIAG_PAD )) + goto errout; +#endif + r->idiag_uid =from_kuid_munged (user_ns,sock_i_uid (sk)); r->idiag_inode =sock_i_ino (sk);
Signature · 1 line
2.7.4
Quoted 3 lines · Dmitry Yakunin
This patch adds cgroup v2 id to common inet diag message attributes. This allows investigate sockets on per cgroup basis when net_cls/net_prio cgroup not used.
After second thought:
Option CONFIG_SOCK_CGROUP_DATA are not directly enabled in config. It's selected by CONFIG_CGROUP_BPF or legacy CGROUP_NET_CLASSID/PRIO.
So, it would be more clear to put this code under ifdef CONFIG_CGROUP_BPF. Because it exposes cgroup2 id and has nothing to do with legacy cgroups.
+CC [email protected] and [email protected]
Quoted 57 lines
Signed-off-by Dmitry Yakunin <[email protected]>Reviewed-by Konstantin Khlebnikov <[email protected]>--- include/linux/inet_diag.h | 6 +++++- include/uapi/linux/inet_diag.h | 1 + net/ipv4/inet_diag.c | 7 +++++++ 3 files changed, 13 insertions(+), 1 deletion(-)include/linux/inet_diag.h +5
-1@@ -66,7 +66,11 @@ static inline size_t inet_diag_msg_attrs_size(void) + nla_total_size(1) /* INET_DIAG_SKV6ONLY */ #endif + nla_total_size(4) /* INET_DIAG_MARK */ - +nla_total_size (4 );/* INET_DIAG_CLASS_ID */ + + nla_total_size(4) /* INET_DIAG_CLASS_ID */ +#ifdef CONFIG_SOCK_CGROUP_DATA + + nla_total_size(8) /* INET_DIAG_CGROUP_ID */ +#endif + ; } int inet_diag_msg_attrs_fill(struct sock *sk, struct sk_buff *skb, struct inet_diag_msg *r, int ext,include/uapi/linux/inet_diag.h +1
-0@@ -154,6 +154,7 @@ enum {INET_DIAG_CLASS_ID ,/* request as INET_DIAG_TCLASS */ INET_DIAG_MD5SIG ,INET_DIAG_ULP_INFO , +INET_DIAG_CGROUP_ID , __INET_DIAG_MAX, };net/ipv4/inet_diag.c +7
-0@@ -161,6 +161,13 @@ int inet_diag_msg_attrs_fill(struct sock *sk, struct sk_buff *skb, goto errout; } +#ifdef CONFIG_SOCK_CGROUP_DATA +if (nla_put_u64_64bit (skb,INET_DIAG_CGROUP_ID , +cgroup_id (sock_cgroup_ptr (&sk->sk_cgrp_data)), +INET_DIAG_PAD )) + goto errout; +#endif + r->idiag_uid =from_kuid_munged (user_ns,sock_i_uid (sk)); r->idiag_inode =sock_i_ino (sk);
Quoted 17 lines · Dmitry Yakunin
This patch adds cgroup v2 id to common inet diag message attributes. This allows investigate sockets on per cgroup basis when net_cls/net_prio cgroup not used.
Signed-off-by Dmitry Yakunin <[email protected]>Reviewed-by Konstantin Khlebnikov <[email protected]>--- include/linux/inet_diag.h | 6 +++++- include/uapi/linux/inet_diag.h | 1 + net/ipv4/inet_diag.c | 7 +++++++ 3 files changed, 13 insertions(+), 1 deletion(-)include/linux/inet_diag.h +0
-0
include/linux/inet_diag.h static inline size_t inet_diag_msg_attrs_size(void) · line 71
Quoted 7 lines
include/linux/inet_diag.h +3
-1@@ -66,7 +66,11 @@ static inline size_t inet_diag_msg_attrs_size(void) +nla_total_size (1 )/* INET_DIAG_SKV6ONLY */ #endif +nla_total_size (4 )/* INET_DIAG_MARK */ - +nla_total_size (4 );/* INET_DIAG_CLASS_ID */ + + nla_total_size(4) /* INET_DIAG_CLASS_ID */ +#ifdef CONFIG_SOCK_CGROUP_DATA + +nla_total_size (8 )/* INET_DIAG_CGROUP_ID */
nla_total_size_64bit(sizeof(u64))
Quoted 36 lines
include/linux/inet_diag.h +2
-0+#endif + ; } int inet_diag_msg_attrs_fill(struct sock *sk, struct sk_buff *skb, struct inet_diag_msg *r, int ext,include/uapi/linux/inet_diag.h +1
-0@@ -154,6 +154,7 @@ enum {INET_DIAG_CLASS_ID ,/* request as INET_DIAG_TCLASS */ INET_DIAG_MD5SIG ,INET_DIAG_ULP_INFO , +INET_DIAG_CGROUP_ID , __INET_DIAG_MAX, };net/ipv4/inet_diag.c +7
-0@@ -161,6 +161,13 @@ int inet_diag_msg_attrs_fill(struct sock *sk, struct sk_buff *skb, goto errout; } +#ifdef CONFIG_SOCK_CGROUP_DATA +if (nla_put_u64_64bit (skb,INET_DIAG_CGROUP_ID , +cgroup_id (sock_cgroup_ptr (&sk->sk_cgrp_data)), +INET_DIAG_PAD )) + goto errout; +#endif + r->idiag_uid =from_kuid_munged (user_ns,sock_i_uid (sk)); r->idiag_inode =sock_i_ino (sk);