Skip to content

Commit 1ec17db

Browse files
koct9idavem330
authored andcommitted
inet_diag: fix reporting cgroup classid and fallback to priority
Field idiag_ext in struct inet_diag_req_v2 used as bitmap of requested extensions has only 8 bits. Thus extensions starting from DCTCPINFO cannot be requested directly. Some of them included into response unconditionally or hook into some of lower 8 bits. Extension INET_DIAG_CLASS_ID has not way to request from the beginning. This patch bundle it with INET_DIAG_TCLASS (ipv6 tos), fixes space reservation, and documents behavior for other extensions. Also this patch adds fallback to reporting socket priority. This filed is more widely used for traffic classification because ipv4 sockets automatically maps TOS to priority and default qdisc pfifo_fast knows about that. But priority could be changed via setsockopt SO_PRIORITY so INET_DIAG_TOS isn't enough for predicting class. Also cgroup2 obsoletes net_cls classid (it always zero), but we cannot reuse this field for reporting cgroup2 id because it is 64-bit (ino+gen). So, after this patch INET_DIAG_CLASS_ID will report socket priority for most common setup when net_cls isn't set and/or cgroup2 in use. Fixes: 0888e37 ("net: inet: diag: expose sockets cgroup classid") Signed-off-by: Konstantin Khlebnikov <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 4ffcbfa commit 1ec17db

File tree

3 files changed

+21
-6
lines changed

3 files changed

+21
-6
lines changed

include/uapi/linux/inet_diag.h

+11-5
Original file line numberDiff line numberDiff line change
@@ -137,15 +137,21 @@ enum {
137137
INET_DIAG_TCLASS,
138138
INET_DIAG_SKMEMINFO,
139139
INET_DIAG_SHUTDOWN,
140-
INET_DIAG_DCTCPINFO,
141-
INET_DIAG_PROTOCOL, /* response attribute only */
140+
141+
/*
142+
* Next extenstions cannot be requested in struct inet_diag_req_v2:
143+
* its field idiag_ext has only 8 bits.
144+
*/
145+
146+
INET_DIAG_DCTCPINFO, /* request as INET_DIAG_VEGASINFO */
147+
INET_DIAG_PROTOCOL, /* response attribute only */
142148
INET_DIAG_SKV6ONLY,
143149
INET_DIAG_LOCALS,
144150
INET_DIAG_PEERS,
145151
INET_DIAG_PAD,
146-
INET_DIAG_MARK,
147-
INET_DIAG_BBRINFO,
148-
INET_DIAG_CLASS_ID,
152+
INET_DIAG_MARK, /* only with CAP_NET_ADMIN */
153+
INET_DIAG_BBRINFO, /* request as INET_DIAG_VEGASINFO */
154+
INET_DIAG_CLASS_ID, /* request as INET_DIAG_TCLASS */
149155
INET_DIAG_MD5SIG,
150156
__INET_DIAG_MAX,
151157
};

net/ipv4/inet_diag.c

+9-1
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ static size_t inet_sk_attr_size(struct sock *sk,
108108
+ nla_total_size(1) /* INET_DIAG_TOS */
109109
+ nla_total_size(1) /* INET_DIAG_TCLASS */
110110
+ nla_total_size(4) /* INET_DIAG_MARK */
111+
+ nla_total_size(4) /* INET_DIAG_CLASS_ID */
111112
+ nla_total_size(sizeof(struct inet_diag_meminfo))
112113
+ nla_total_size(sizeof(struct inet_diag_msg))
113114
+ nla_total_size(SK_MEMINFO_VARS * sizeof(u32))
@@ -287,12 +288,19 @@ int inet_sk_diag_fill(struct sock *sk, struct inet_connection_sock *icsk,
287288
goto errout;
288289
}
289290

290-
if (ext & (1 << (INET_DIAG_CLASS_ID - 1))) {
291+
if (ext & (1 << (INET_DIAG_CLASS_ID - 1)) ||
292+
ext & (1 << (INET_DIAG_TCLASS - 1))) {
291293
u32 classid = 0;
292294

293295
#ifdef CONFIG_SOCK_CGROUP_DATA
294296
classid = sock_cgroup_classid(&sk->sk_cgrp_data);
295297
#endif
298+
/* Fallback to socket priority if class id isn't set.
299+
* Classful qdiscs use it as direct reference to class.
300+
* For cgroup2 classid is always zero.
301+
*/
302+
if (!classid)
303+
classid = sk->sk_priority;
296304

297305
if (nla_put_u32(skb, INET_DIAG_CLASS_ID, classid))
298306
goto errout;

net/sctp/diag.c

+1
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,7 @@ static size_t inet_assoc_attr_size(struct sctp_association *asoc)
256256
+ nla_total_size(1) /* INET_DIAG_TOS */
257257
+ nla_total_size(1) /* INET_DIAG_TCLASS */
258258
+ nla_total_size(4) /* INET_DIAG_MARK */
259+
+ nla_total_size(4) /* INET_DIAG_CLASS_ID */
259260
+ nla_total_size(addrlen * asoc->peer.transport_count)
260261
+ nla_total_size(addrlen * addrcnt)
261262
+ nla_total_size(sizeof(struct inet_diag_meminfo))

0 commit comments

Comments
 (0)