[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20241113-tcp-md5-diag-prep-v2-3-00a2a7feb1fa@gmail.com>
Date: Wed, 13 Nov 2024 18:46:42 +0000
From: Dmitry Safonov via B4 Relay <devnull+0x7f454c46.gmail.com@...nel.org>
To: "David S. Miller" <davem@...emloft.net>,
Eric Dumazet <edumazet@...gle.com>, Jakub Kicinski <kuba@...nel.org>,
Paolo Abeni <pabeni@...hat.com>, Simon Horman <horms@...nel.org>,
David Ahern <dsahern@...nel.org>, Ivan Delalande <colona@...sta.com>,
Matthieu Baerts <matttbe@...nel.org>, Mat Martineau <martineau@...nel.org>,
Geliang Tang <geliang@...nel.org>, Boris Pismenny <borisp@...dia.com>,
John Fastabend <john.fastabend@...il.com>,
Davide Caratti <dcaratti@...hat.com>, Kuniyuki Iwashima <kuniyu@...zon.com>
Cc: netdev@...r.kernel.org, linux-kernel@...r.kernel.org,
mptcp@...ts.linux.dev, Dmitry Safonov <0x7f454c46@...il.com>
Subject: [PATCH net v2 3/5] net/diag: Pre-allocate optional info only if
requested
From: Dmitry Safonov <0x7f454c46@...il.com>
Those INET_DIAG_* flags from req->idiag_ext are provided by the
userspace, so they are not going to change during one socket dump.
This is going to save just nits and bits for typical netlink reply,
which I'm going to utilise in the very next patch by always allocating
tls_get_info_size().
It's possible to save even some more by checking the request in
inet_diag_msg_attrs_size(), but that's being on very stingy side.
Signed-off-by: Dmitry Safonov <0x7f454c46@...il.com>
---
net/ipv4/inet_diag.c | 29 ++++++++++++++++++-----------
1 file changed, 18 insertions(+), 11 deletions(-)
diff --git a/net/ipv4/inet_diag.c b/net/ipv4/inet_diag.c
index ca9a7e61d8d7de80cb234c45c41d6357fde50c11..2dd173a73bd1e2657957e5e4ecb70401cc85dfda 100644
--- a/net/ipv4/inet_diag.c
+++ b/net/ipv4/inet_diag.c
@@ -102,24 +102,31 @@ static size_t inet_sk_attr_size(struct sock *sk,
bool net_admin)
{
const struct inet_diag_handler *handler;
- size_t aux = 0;
+ int ext = req->idiag_ext;
+ size_t ret = 0;
rcu_read_lock();
handler = rcu_dereference(inet_diag_table[req->sdiag_protocol]);
DEBUG_NET_WARN_ON_ONCE(!handler);
if (handler && handler->idiag_get_aux_size)
- aux = handler->idiag_get_aux_size(sk, net_admin);
+ ret += handler->idiag_get_aux_size(sk, net_admin);
rcu_read_unlock();
- return nla_total_size(sizeof(struct tcp_info))
- + nla_total_size(sizeof(struct inet_diag_msg))
- + inet_diag_msg_attrs_size()
- + nla_total_size(sizeof(struct inet_diag_meminfo))
- + nla_total_size(SK_MEMINFO_VARS * sizeof(u32))
- + nla_total_size(TCP_CA_NAME_MAX)
- + nla_total_size(sizeof(struct tcpvegas_info))
- + aux
- + 64;
+ ret += nla_total_size(sizeof(struct tcp_info))
+ + nla_total_size(sizeof(struct inet_diag_msg))
+ + inet_diag_msg_attrs_size()
+ + 64;
+
+ if (ext & (1 << (INET_DIAG_MEMINFO - 1)))
+ ret += nla_total_size(sizeof(struct inet_diag_meminfo));
+ if (ext & (1 << (INET_DIAG_SKMEMINFO - 1)))
+ ret += nla_total_size(SK_MEMINFO_VARS * sizeof(u32));
+ if (ext & (1 << (INET_DIAG_CONG - 1)))
+ ret += nla_total_size(TCP_CA_NAME_MAX);
+ if (ext & (1 << (INET_DIAG_VEGASINFO - 1)))
+ ret += nla_total_size(sizeof(struct tcpvegas_info));
+
+ return ret;
}
int inet_diag_msg_attrs_fill(struct sock *sk, struct sk_buff *skb,
--
2.42.2
Powered by blists - more mailing lists