| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-or-later |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * tcp_diag.c Module for monitoring TCP transport protocols sockets. |
|---|
| 3 | 4 | * |
|---|
| 4 | 5 | * Authors: Alexey Kuznetsov, <kuznet@ms2.inr.ac.ru> |
|---|
| 5 | | - * |
|---|
| 6 | | - * This program is free software; you can redistribute it and/or |
|---|
| 7 | | - * modify it under the terms of the GNU General Public License |
|---|
| 8 | | - * as published by the Free Software Foundation; either version |
|---|
| 9 | | - * 2 of the License, or (at your option) any later version. |
|---|
| 10 | 6 | */ |
|---|
| 11 | 7 | |
|---|
| 12 | 8 | #include <linux/module.h> |
|---|
| .. | .. |
|---|
| 25 | 21 | struct tcp_info *info = _info; |
|---|
| 26 | 22 | |
|---|
| 27 | 23 | if (inet_sk_state_load(sk) == TCP_LISTEN) { |
|---|
| 28 | | - r->idiag_rqueue = sk->sk_ack_backlog; |
|---|
| 29 | | - r->idiag_wqueue = sk->sk_max_ack_backlog; |
|---|
| 24 | + r->idiag_rqueue = READ_ONCE(sk->sk_ack_backlog); |
|---|
| 25 | + r->idiag_wqueue = READ_ONCE(sk->sk_max_ack_backlog); |
|---|
| 30 | 26 | } else if (sk->sk_type == SOCK_STREAM) { |
|---|
| 31 | 27 | const struct tcp_sock *tp = tcp_sk(sk); |
|---|
| 32 | 28 | |
|---|
| .. | .. |
|---|
| 86 | 82 | } |
|---|
| 87 | 83 | #endif |
|---|
| 88 | 84 | |
|---|
| 85 | +static int tcp_diag_put_ulp(struct sk_buff *skb, struct sock *sk, |
|---|
| 86 | + const struct tcp_ulp_ops *ulp_ops) |
|---|
| 87 | +{ |
|---|
| 88 | + struct nlattr *nest; |
|---|
| 89 | + int err; |
|---|
| 90 | + |
|---|
| 91 | + nest = nla_nest_start_noflag(skb, INET_DIAG_ULP_INFO); |
|---|
| 92 | + if (!nest) |
|---|
| 93 | + return -EMSGSIZE; |
|---|
| 94 | + |
|---|
| 95 | + err = nla_put_string(skb, INET_ULP_INFO_NAME, ulp_ops->name); |
|---|
| 96 | + if (err) |
|---|
| 97 | + goto nla_failure; |
|---|
| 98 | + |
|---|
| 99 | + if (ulp_ops->get_info) |
|---|
| 100 | + err = ulp_ops->get_info(sk, skb); |
|---|
| 101 | + if (err) |
|---|
| 102 | + goto nla_failure; |
|---|
| 103 | + |
|---|
| 104 | + nla_nest_end(skb, nest); |
|---|
| 105 | + return 0; |
|---|
| 106 | + |
|---|
| 107 | +nla_failure: |
|---|
| 108 | + nla_nest_cancel(skb, nest); |
|---|
| 109 | + return err; |
|---|
| 110 | +} |
|---|
| 111 | + |
|---|
| 89 | 112 | static int tcp_diag_get_aux(struct sock *sk, bool net_admin, |
|---|
| 90 | 113 | struct sk_buff *skb) |
|---|
| 91 | 114 | { |
|---|
| 115 | + struct inet_connection_sock *icsk = inet_csk(sk); |
|---|
| 116 | + int err = 0; |
|---|
| 117 | + |
|---|
| 92 | 118 | #ifdef CONFIG_TCP_MD5SIG |
|---|
| 93 | 119 | if (net_admin) { |
|---|
| 94 | 120 | struct tcp_md5sig_info *md5sig; |
|---|
| 95 | | - int err = 0; |
|---|
| 96 | 121 | |
|---|
| 97 | 122 | rcu_read_lock(); |
|---|
| 98 | 123 | md5sig = rcu_dereference(tcp_sk(sk)->md5sig_info); |
|---|
| .. | .. |
|---|
| 104 | 129 | } |
|---|
| 105 | 130 | #endif |
|---|
| 106 | 131 | |
|---|
| 132 | + if (net_admin) { |
|---|
| 133 | + const struct tcp_ulp_ops *ulp_ops; |
|---|
| 134 | + |
|---|
| 135 | + ulp_ops = icsk->icsk_ulp_ops; |
|---|
| 136 | + if (ulp_ops) |
|---|
| 137 | + err = tcp_diag_put_ulp(skb, sk, ulp_ops); |
|---|
| 138 | + if (err) |
|---|
| 139 | + return err; |
|---|
| 140 | + } |
|---|
| 107 | 141 | return 0; |
|---|
| 108 | 142 | } |
|---|
| 109 | 143 | |
|---|
| 110 | 144 | static size_t tcp_diag_get_aux_size(struct sock *sk, bool net_admin) |
|---|
| 111 | 145 | { |
|---|
| 146 | + struct inet_connection_sock *icsk = inet_csk(sk); |
|---|
| 112 | 147 | size_t size = 0; |
|---|
| 113 | 148 | |
|---|
| 114 | 149 | #ifdef CONFIG_TCP_MD5SIG |
|---|
| .. | .. |
|---|
| 129 | 164 | } |
|---|
| 130 | 165 | #endif |
|---|
| 131 | 166 | |
|---|
| 167 | + if (net_admin && sk_fullsock(sk)) { |
|---|
| 168 | + const struct tcp_ulp_ops *ulp_ops; |
|---|
| 169 | + |
|---|
| 170 | + ulp_ops = icsk->icsk_ulp_ops; |
|---|
| 171 | + if (ulp_ops) { |
|---|
| 172 | + size += nla_total_size(0) + |
|---|
| 173 | + nla_total_size(TCP_ULP_NAME_MAX); |
|---|
| 174 | + if (ulp_ops->get_info_size) |
|---|
| 175 | + size += ulp_ops->get_info_size(sk); |
|---|
| 176 | + } |
|---|
| 177 | + } |
|---|
| 132 | 178 | return size; |
|---|
| 133 | 179 | } |
|---|
| 134 | 180 | |
|---|
| 135 | 181 | static void tcp_diag_dump(struct sk_buff *skb, struct netlink_callback *cb, |
|---|
| 136 | | - const struct inet_diag_req_v2 *r, struct nlattr *bc) |
|---|
| 182 | + const struct inet_diag_req_v2 *r) |
|---|
| 137 | 183 | { |
|---|
| 138 | | - inet_diag_dump_icsk(&tcp_hashinfo, skb, cb, r, bc); |
|---|
| 184 | + inet_diag_dump_icsk(&tcp_hashinfo, skb, cb, r); |
|---|
| 139 | 185 | } |
|---|
| 140 | 186 | |
|---|
| 141 | | -static int tcp_diag_dump_one(struct sk_buff *in_skb, const struct nlmsghdr *nlh, |
|---|
| 187 | +static int tcp_diag_dump_one(struct netlink_callback *cb, |
|---|
| 142 | 188 | const struct inet_diag_req_v2 *req) |
|---|
| 143 | 189 | { |
|---|
| 144 | | - return inet_diag_dump_one_icsk(&tcp_hashinfo, in_skb, nlh, req); |
|---|
| 190 | + return inet_diag_dump_one_icsk(&tcp_hashinfo, cb, req); |
|---|
| 145 | 191 | } |
|---|
| 146 | 192 | |
|---|
| 147 | 193 | #ifdef CONFIG_INET_DIAG_DESTROY |
|---|