hc
2024-01-05 071106ecf68c401173c58808b1cf5f68cc50d390
kernel/net/sctp/diag.c
....@@ -1,25 +1,10 @@
1
+// SPDX-License-Identifier: GPL-2.0-or-later
12 /* SCTP kernel implementation
23 * (C) Copyright Red Hat Inc. 2017
34 *
45 * This file is part of the SCTP kernel implementation
56 *
67 * These functions implement sctp diag support.
7
- *
8
- * This SCTP implementation is free software;
9
- * you can redistribute it and/or modify it under the terms of
10
- * the GNU General Public License as published by
11
- * the Free Software Foundation; either version 2, or (at your option)
12
- * any later version.
13
- *
14
- * This SCTP implementation is distributed in the hope that it
15
- * will be useful, but WITHOUT ANY WARRANTY; without even the implied
16
- * ************************
17
- * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
18
- * See the GNU General Public License for more details.
19
- *
20
- * You should have received a copy of the GNU General Public License
21
- * along with GNU CC; see the file COPYING. If not, see
22
- * <http://www.gnu.org/licenses/>.
238 *
249 * Please send any bug reports or fixes you make to the
2510 * email addresched(es):
....@@ -76,10 +61,6 @@
7661 r->idiag_timer = SCTP_EVENT_TIMEOUT_T3_RTX;
7762 r->idiag_retrans = asoc->rtx_data_chunks;
7863 r->idiag_expires = jiffies_to_msecs(t3_rtx->expires - jiffies);
79
- } else {
80
- r->idiag_timer = 0;
81
- r->idiag_retrans = 0;
82
- r->idiag_expires = 0;
8364 }
8465 }
8566
....@@ -159,13 +140,14 @@
159140 r = nlmsg_data(nlh);
160141 BUG_ON(!sk_fullsock(sk));
161142
143
+ r->idiag_timer = 0;
144
+ r->idiag_retrans = 0;
145
+ r->idiag_expires = 0;
162146 if (asoc) {
163147 inet_diag_msg_sctpasoc_fill(r, sk, asoc);
164148 } else {
165149 inet_diag_msg_common_fill(r, sk);
166150 r->idiag_state = sk->sk_state;
167
- r->idiag_timer = 0;
168
- r->idiag_retrans = 0;
169151 }
170152
171153 if (inet_diag_msg_attrs_fill(sk, skb, r, ext, user_ns, net_admin))
....@@ -190,7 +172,7 @@
190172 mem[SK_MEMINFO_FWD_ALLOC] = sk->sk_forward_alloc;
191173 mem[SK_MEMINFO_WMEM_QUEUED] = sk->sk_wmem_queued;
192174 mem[SK_MEMINFO_OPTMEM] = atomic_read(&sk->sk_omem_alloc);
193
- mem[SK_MEMINFO_BACKLOG] = sk->sk_backlog.len;
175
+ mem[SK_MEMINFO_BACKLOG] = READ_ONCE(sk->sk_backlog.len);
194176 mem[SK_MEMINFO_DROPS] = atomic_read(&sk->sk_drops);
195177
196178 if (nla_put(skb, INET_DIAG_SKMEMINFO, sizeof(mem), &mem) < 0)
....@@ -367,11 +349,9 @@
367349 struct sctp_comm_param *commp = p;
368350 struct sock *sk = ep->base.sk;
369351 const struct inet_diag_req_v2 *r = commp->r;
370
- struct sctp_association *assoc =
371
- list_entry(ep->asocs.next, struct sctp_association, asocs);
372352
373353 /* find the ep only once through the transports by this condition */
374
- if (tsp->asoc != assoc)
354
+ if (!list_is_first(&tsp->asoc->asocs, &ep->asocs))
375355 return 0;
376356
377357 if (r->sdiag_family != AF_UNSPEC && sk->sk_family != r->sdiag_family)
....@@ -436,18 +416,19 @@
436416 r->idiag_rqueue = atomic_read(&infox->asoc->rmem_alloc);
437417 r->idiag_wqueue = infox->asoc->sndbuf_used;
438418 } else {
439
- r->idiag_rqueue = sk->sk_ack_backlog;
440
- r->idiag_wqueue = sk->sk_max_ack_backlog;
419
+ r->idiag_rqueue = READ_ONCE(sk->sk_ack_backlog);
420
+ r->idiag_wqueue = READ_ONCE(sk->sk_max_ack_backlog);
441421 }
442422 if (infox->sctpinfo)
443423 sctp_get_sctp_info(sk, infox->asoc, infox->sctpinfo);
444424 }
445425
446
-static int sctp_diag_dump_one(struct sk_buff *in_skb,
447
- const struct nlmsghdr *nlh,
426
+static int sctp_diag_dump_one(struct netlink_callback *cb,
448427 const struct inet_diag_req_v2 *req)
449428 {
429
+ struct sk_buff *in_skb = cb->skb;
450430 struct net *net = sock_net(in_skb->sk);
431
+ const struct nlmsghdr *nlh = cb->nlh;
451432 union sctp_addr laddr, paddr;
452433 struct sctp_comm_param commp = {
453434 .skb = in_skb,
....@@ -481,7 +462,7 @@
481462 }
482463
483464 static void sctp_diag_dump(struct sk_buff *skb, struct netlink_callback *cb,
484
- const struct inet_diag_req_v2 *r, struct nlattr *bc)
465
+ const struct inet_diag_req_v2 *r)
485466 {
486467 u32 idiag_states = r->idiag_states;
487468 struct net *net = sock_net(skb->sk);