inet_diag: change inet_diag_bc_sk() first argument
We want to have access to the inet_diag_dump_data structure in the following patch. This patch removes duplication in callers. Signed-off-by: Eric Dumazet <edumazet@google.com> Reviewed-by: Kuniyuki Iwashima <kuniyu@google.com> Link: https://patch.msgid.link/20250828102738.2065992-5-edumazet@google.com Signed-off-by: Jakub Kicinski <kuba@kernel.org>
This commit is contained in:
parent
4fd84a0aaf
commit
9529320ad6
|
|
@ -46,7 +46,7 @@ int inet_sk_diag_fill(struct sock *sk, struct inet_connection_sock *icsk,
|
|||
const struct inet_diag_req_v2 *req,
|
||||
u16 nlmsg_flags, bool net_admin);
|
||||
|
||||
int inet_diag_bc_sk(const struct nlattr *_bc, struct sock *sk);
|
||||
int inet_diag_bc_sk(const struct inet_diag_dump_data *cb_data, struct sock *sk);
|
||||
|
||||
void inet_diag_msg_common_fill(struct inet_diag_msg *r, struct sock *sk);
|
||||
|
||||
|
|
|
|||
|
|
@ -591,8 +591,9 @@ static void entry_fill_addrs(struct inet_diag_entry *entry,
|
|||
}
|
||||
}
|
||||
|
||||
int inet_diag_bc_sk(const struct nlattr *bc, struct sock *sk)
|
||||
int inet_diag_bc_sk(const struct inet_diag_dump_data *cb_data, struct sock *sk)
|
||||
{
|
||||
const struct nlattr *bc = cb_data->inet_diag_nla_bc;
|
||||
const struct inet_sock *inet = inet_sk(sk);
|
||||
struct inet_diag_entry entry;
|
||||
|
||||
|
|
|
|||
|
|
@ -126,9 +126,9 @@ static int raw_diag_dump_one(struct netlink_callback *cb,
|
|||
static int sk_diag_dump(struct sock *sk, struct sk_buff *skb,
|
||||
struct netlink_callback *cb,
|
||||
const struct inet_diag_req_v2 *r,
|
||||
struct nlattr *bc, bool net_admin)
|
||||
bool net_admin)
|
||||
{
|
||||
if (!inet_diag_bc_sk(bc, sk))
|
||||
if (!inet_diag_bc_sk(cb->data, sk))
|
||||
return 0;
|
||||
|
||||
return inet_sk_diag_fill(sk, NULL, skb, cb, r, NLM_F_MULTI, net_admin);
|
||||
|
|
@ -140,17 +140,13 @@ static void raw_diag_dump(struct sk_buff *skb, struct netlink_callback *cb,
|
|||
bool net_admin = netlink_net_capable(cb->skb, CAP_NET_ADMIN);
|
||||
struct raw_hashinfo *hashinfo = raw_get_hashinfo(r);
|
||||
struct net *net = sock_net(skb->sk);
|
||||
struct inet_diag_dump_data *cb_data;
|
||||
int num, s_num, slot, s_slot;
|
||||
struct hlist_head *hlist;
|
||||
struct sock *sk = NULL;
|
||||
struct nlattr *bc;
|
||||
|
||||
if (IS_ERR(hashinfo))
|
||||
return;
|
||||
|
||||
cb_data = cb->data;
|
||||
bc = cb_data->inet_diag_nla_bc;
|
||||
s_slot = cb->args[0];
|
||||
num = s_num = cb->args[1];
|
||||
|
||||
|
|
@ -174,7 +170,7 @@ static void raw_diag_dump(struct sk_buff *skb, struct netlink_callback *cb,
|
|||
if (r->id.idiag_dport != inet->inet_dport &&
|
||||
r->id.idiag_dport)
|
||||
goto next;
|
||||
if (sk_diag_dump(sk, skb, cb, r, bc, net_admin) < 0)
|
||||
if (sk_diag_dump(sk, skb, cb, r, net_admin) < 0)
|
||||
goto out_unlock;
|
||||
next:
|
||||
num++;
|
||||
|
|
|
|||
|
|
@ -320,11 +320,9 @@ static void tcp_diag_dump(struct sk_buff *skb, struct netlink_callback *cb,
|
|||
u32 idiag_states = r->idiag_states;
|
||||
struct inet_hashinfo *hashinfo;
|
||||
int i, num, s_i, s_num;
|
||||
struct nlattr *bc;
|
||||
struct sock *sk;
|
||||
|
||||
hashinfo = net->ipv4.tcp_death_row.hashinfo;
|
||||
bc = cb_data->inet_diag_nla_bc;
|
||||
if (idiag_states & TCPF_SYN_RECV)
|
||||
idiag_states |= TCPF_NEW_SYN_RECV;
|
||||
s_i = cb->args[1];
|
||||
|
|
@ -365,7 +363,7 @@ static void tcp_diag_dump(struct sk_buff *skb, struct netlink_callback *cb,
|
|||
r->id.idiag_sport)
|
||||
goto next_listen;
|
||||
|
||||
if (!inet_diag_bc_sk(bc, sk))
|
||||
if (!inet_diag_bc_sk(cb_data, sk))
|
||||
goto next_listen;
|
||||
|
||||
if (inet_sk_diag_fill(sk, inet_csk(sk), skb,
|
||||
|
|
@ -432,7 +430,7 @@ resume_bind_walk:
|
|||
r->sdiag_family != sk->sk_family)
|
||||
goto next_bind;
|
||||
|
||||
if (!inet_diag_bc_sk(bc, sk))
|
||||
if (!inet_diag_bc_sk(cb_data, sk))
|
||||
goto next_bind;
|
||||
|
||||
sock_hold(sk);
|
||||
|
|
@ -519,7 +517,7 @@ next_chunk:
|
|||
goto next_normal;
|
||||
twsk_build_assert();
|
||||
|
||||
if (!inet_diag_bc_sk(bc, sk))
|
||||
if (!inet_diag_bc_sk(cb_data, sk))
|
||||
goto next_normal;
|
||||
|
||||
if (!refcount_inc_not_zero(&sk->sk_refcnt))
|
||||
|
|
|
|||
|
|
@ -16,9 +16,9 @@
|
|||
static int sk_diag_dump(struct sock *sk, struct sk_buff *skb,
|
||||
struct netlink_callback *cb,
|
||||
const struct inet_diag_req_v2 *req,
|
||||
struct nlattr *bc, bool net_admin)
|
||||
bool net_admin)
|
||||
{
|
||||
if (!inet_diag_bc_sk(bc, sk))
|
||||
if (!inet_diag_bc_sk(cb->data, sk))
|
||||
return 0;
|
||||
|
||||
return inet_sk_diag_fill(sk, NULL, skb, cb, req, NLM_F_MULTI,
|
||||
|
|
@ -92,12 +92,8 @@ static void udp_dump(struct udp_table *table, struct sk_buff *skb,
|
|||
{
|
||||
bool net_admin = netlink_net_capable(cb->skb, CAP_NET_ADMIN);
|
||||
struct net *net = sock_net(skb->sk);
|
||||
struct inet_diag_dump_data *cb_data;
|
||||
int num, s_num, slot, s_slot;
|
||||
struct nlattr *bc;
|
||||
|
||||
cb_data = cb->data;
|
||||
bc = cb_data->inet_diag_nla_bc;
|
||||
s_slot = cb->args[0];
|
||||
num = s_num = cb->args[1];
|
||||
|
||||
|
|
@ -130,7 +126,7 @@ static void udp_dump(struct udp_table *table, struct sk_buff *skb,
|
|||
r->id.idiag_dport)
|
||||
goto next;
|
||||
|
||||
if (sk_diag_dump(sk, skb, cb, r, bc, net_admin) < 0) {
|
||||
if (sk_diag_dump(sk, skb, cb, r, net_admin) < 0) {
|
||||
spin_unlock_bh(&hslot->lock);
|
||||
goto done;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,9 +15,9 @@
|
|||
static int sk_diag_dump(struct sock *sk, struct sk_buff *skb,
|
||||
struct netlink_callback *cb,
|
||||
const struct inet_diag_req_v2 *req,
|
||||
struct nlattr *bc, bool net_admin)
|
||||
bool net_admin)
|
||||
{
|
||||
if (!inet_diag_bc_sk(bc, sk))
|
||||
if (!inet_diag_bc_sk(cb->data, sk))
|
||||
return 0;
|
||||
|
||||
return inet_sk_diag_fill(sk, inet_csk(sk), skb, cb, req, NLM_F_MULTI,
|
||||
|
|
@ -76,9 +76,7 @@ static void mptcp_diag_dump_listeners(struct sk_buff *skb, struct netlink_callba
|
|||
const struct inet_diag_req_v2 *r,
|
||||
bool net_admin)
|
||||
{
|
||||
struct inet_diag_dump_data *cb_data = cb->data;
|
||||
struct mptcp_diag_ctx *diag_ctx = (void *)cb->ctx;
|
||||
struct nlattr *bc = cb_data->inet_diag_nla_bc;
|
||||
struct net *net = sock_net(skb->sk);
|
||||
struct inet_hashinfo *hinfo;
|
||||
int i;
|
||||
|
|
@ -121,7 +119,7 @@ static void mptcp_diag_dump_listeners(struct sk_buff *skb, struct netlink_callba
|
|||
if (!refcount_inc_not_zero(&sk->sk_refcnt))
|
||||
goto next_listen;
|
||||
|
||||
ret = sk_diag_dump(sk, skb, cb, r, bc, net_admin);
|
||||
ret = sk_diag_dump(sk, skb, cb, r, net_admin);
|
||||
|
||||
sock_put(sk);
|
||||
|
||||
|
|
@ -154,15 +152,10 @@ static void mptcp_diag_dump(struct sk_buff *skb, struct netlink_callback *cb,
|
|||
bool net_admin = netlink_net_capable(cb->skb, CAP_NET_ADMIN);
|
||||
struct mptcp_diag_ctx *diag_ctx = (void *)cb->ctx;
|
||||
struct net *net = sock_net(skb->sk);
|
||||
struct inet_diag_dump_data *cb_data;
|
||||
struct mptcp_sock *msk;
|
||||
struct nlattr *bc;
|
||||
|
||||
BUILD_BUG_ON(sizeof(cb->ctx) < sizeof(*diag_ctx));
|
||||
|
||||
cb_data = cb->data;
|
||||
bc = cb_data->inet_diag_nla_bc;
|
||||
|
||||
while ((msk = mptcp_token_iter_next(net, &diag_ctx->s_slot,
|
||||
&diag_ctx->s_num)) != NULL) {
|
||||
struct inet_sock *inet = (struct inet_sock *)msk;
|
||||
|
|
@ -181,7 +174,7 @@ static void mptcp_diag_dump(struct sk_buff *skb, struct netlink_callback *cb,
|
|||
r->id.idiag_dport)
|
||||
goto next;
|
||||
|
||||
ret = sk_diag_dump(sk, skb, cb, r, bc, net_admin);
|
||||
ret = sk_diag_dump(sk, skb, cb, r, net_admin);
|
||||
next:
|
||||
sock_put(sk);
|
||||
if (ret < 0) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue