Skip to content

Commit 6e3a401

Browse files
zeildavem330
authored andcommitted
inet_diag: add cgroup id attribute
This patch adds cgroup v2 ID to common inet diag message attributes. Cgroup v2 ID is kernfs ID (ino or ino+gen). This attribute allows filter inet diag output by cgroup ID obtained by name_to_handle_at() syscall. When net_cls or net_prio cgroup is activated this ID is equal to 1 (root cgroup ID) for newly created sockets. Some notes about this ID: 1) gets initialized in socket() syscall 2) incoming socket gets ID from listening socket (not during accept() syscall) 3) not changed when process get moved to another cgroup 4) can point to deleted cgroup (refcounting) v2: - use CONFIG_SOCK_CGROUP_DATA instead if CONFIG_CGROUPS v3: - fix attr size by using nla_total_size_64bit() (Eric Dumazet) - more detailed commit message (Konstantin Khlebnikov) Signed-off-by: Dmitry Yakunin <[email protected]> Reviewed-by: Konstantin Khlebnikov <[email protected]> Acked-By: Tejun Heo <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 8a769c6 commit 6e3a401

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

include/linux/inet_diag.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,11 @@ static inline size_t inet_diag_msg_attrs_size(void)
7171
+ nla_total_size(1) /* INET_DIAG_SKV6ONLY */
7272
#endif
7373
+ nla_total_size(4) /* INET_DIAG_MARK */
74-
+ nla_total_size(4); /* INET_DIAG_CLASS_ID */
74+
+ nla_total_size(4) /* INET_DIAG_CLASS_ID */
75+
#ifdef CONFIG_SOCK_CGROUP_DATA
76+
+ nla_total_size_64bit(sizeof(u64)) /* INET_DIAG_CGROUP_ID */
77+
#endif
78+
;
7579
}
7680
int inet_diag_msg_attrs_fill(struct sock *sk, struct sk_buff *skb,
7781
struct inet_diag_msg *r, int ext,

include/uapi/linux/inet_diag.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ enum {
157157
INET_DIAG_MD5SIG,
158158
INET_DIAG_ULP_INFO,
159159
INET_DIAG_SK_BPF_STORAGES,
160+
INET_DIAG_CGROUP_ID,
160161
__INET_DIAG_MAX,
161162
};
162163

net/ipv4/inet_diag.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,13 @@ int inet_diag_msg_attrs_fill(struct sock *sk, struct sk_buff *skb,
162162
goto errout;
163163
}
164164

165+
#ifdef CONFIG_SOCK_CGROUP_DATA
166+
if (nla_put_u64_64bit(skb, INET_DIAG_CGROUP_ID,
167+
cgroup_id(sock_cgroup_ptr(&sk->sk_cgrp_data)),
168+
INET_DIAG_PAD))
169+
goto errout;
170+
#endif
171+
165172
r->idiag_uid = from_kuid_munged(user_ns, sock_i_uid(sk));
166173
r->idiag_inode = sock_i_ino(sk);
167174

0 commit comments

Comments
 (0)