Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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>

authored by

Eric Dumazet and committed by
Jakub Kicinski
9529320a 4fd84a0a

+16 -32
+1 -1
include/linux/inet_diag.h
··· 46 46 const struct inet_diag_req_v2 *req, 47 47 u16 nlmsg_flags, bool net_admin); 48 48 49 - int inet_diag_bc_sk(const struct nlattr *_bc, struct sock *sk); 49 + int inet_diag_bc_sk(const struct inet_diag_dump_data *cb_data, struct sock *sk); 50 50 51 51 void inet_diag_msg_common_fill(struct inet_diag_msg *r, struct sock *sk); 52 52
+2 -1
net/ipv4/inet_diag.c
··· 591 591 } 592 592 } 593 593 594 - int inet_diag_bc_sk(const struct nlattr *bc, struct sock *sk) 594 + int inet_diag_bc_sk(const struct inet_diag_dump_data *cb_data, struct sock *sk) 595 595 { 596 + const struct nlattr *bc = cb_data->inet_diag_nla_bc; 596 597 const struct inet_sock *inet = inet_sk(sk); 597 598 struct inet_diag_entry entry; 598 599
+3 -7
net/ipv4/raw_diag.c
··· 126 126 static int sk_diag_dump(struct sock *sk, struct sk_buff *skb, 127 127 struct netlink_callback *cb, 128 128 const struct inet_diag_req_v2 *r, 129 - struct nlattr *bc, bool net_admin) 129 + bool net_admin) 130 130 { 131 - if (!inet_diag_bc_sk(bc, sk)) 131 + if (!inet_diag_bc_sk(cb->data, sk)) 132 132 return 0; 133 133 134 134 return inet_sk_diag_fill(sk, NULL, skb, cb, r, NLM_F_MULTI, net_admin); ··· 140 140 bool net_admin = netlink_net_capable(cb->skb, CAP_NET_ADMIN); 141 141 struct raw_hashinfo *hashinfo = raw_get_hashinfo(r); 142 142 struct net *net = sock_net(skb->sk); 143 - struct inet_diag_dump_data *cb_data; 144 143 int num, s_num, slot, s_slot; 145 144 struct hlist_head *hlist; 146 145 struct sock *sk = NULL; 147 - struct nlattr *bc; 148 146 149 147 if (IS_ERR(hashinfo)) 150 148 return; 151 149 152 - cb_data = cb->data; 153 - bc = cb_data->inet_diag_nla_bc; 154 150 s_slot = cb->args[0]; 155 151 num = s_num = cb->args[1]; 156 152 ··· 170 174 if (r->id.idiag_dport != inet->inet_dport && 171 175 r->id.idiag_dport) 172 176 goto next; 173 - if (sk_diag_dump(sk, skb, cb, r, bc, net_admin) < 0) 177 + if (sk_diag_dump(sk, skb, cb, r, net_admin) < 0) 174 178 goto out_unlock; 175 179 next: 176 180 num++;
+3 -5
net/ipv4/tcp_diag.c
··· 320 320 u32 idiag_states = r->idiag_states; 321 321 struct inet_hashinfo *hashinfo; 322 322 int i, num, s_i, s_num; 323 - struct nlattr *bc; 324 323 struct sock *sk; 325 324 326 325 hashinfo = net->ipv4.tcp_death_row.hashinfo; 327 - bc = cb_data->inet_diag_nla_bc; 328 326 if (idiag_states & TCPF_SYN_RECV) 329 327 idiag_states |= TCPF_NEW_SYN_RECV; 330 328 s_i = cb->args[1]; ··· 363 365 r->id.idiag_sport) 364 366 goto next_listen; 365 367 366 - if (!inet_diag_bc_sk(bc, sk)) 368 + if (!inet_diag_bc_sk(cb_data, sk)) 367 369 goto next_listen; 368 370 369 371 if (inet_sk_diag_fill(sk, inet_csk(sk), skb, ··· 430 432 r->sdiag_family != sk->sk_family) 431 433 goto next_bind; 432 434 433 - if (!inet_diag_bc_sk(bc, sk)) 435 + if (!inet_diag_bc_sk(cb_data, sk)) 434 436 goto next_bind; 435 437 436 438 sock_hold(sk); ··· 517 519 goto next_normal; 518 520 twsk_build_assert(); 519 521 520 - if (!inet_diag_bc_sk(bc, sk)) 522 + if (!inet_diag_bc_sk(cb_data, sk)) 521 523 goto next_normal; 522 524 523 525 if (!refcount_inc_not_zero(&sk->sk_refcnt))
+3 -7
net/ipv4/udp_diag.c
··· 16 16 static int sk_diag_dump(struct sock *sk, struct sk_buff *skb, 17 17 struct netlink_callback *cb, 18 18 const struct inet_diag_req_v2 *req, 19 - struct nlattr *bc, bool net_admin) 19 + bool net_admin) 20 20 { 21 - if (!inet_diag_bc_sk(bc, sk)) 21 + if (!inet_diag_bc_sk(cb->data, sk)) 22 22 return 0; 23 23 24 24 return inet_sk_diag_fill(sk, NULL, skb, cb, req, NLM_F_MULTI, ··· 92 92 { 93 93 bool net_admin = netlink_net_capable(cb->skb, CAP_NET_ADMIN); 94 94 struct net *net = sock_net(skb->sk); 95 - struct inet_diag_dump_data *cb_data; 96 95 int num, s_num, slot, s_slot; 97 - struct nlattr *bc; 98 96 99 - cb_data = cb->data; 100 - bc = cb_data->inet_diag_nla_bc; 101 97 s_slot = cb->args[0]; 102 98 num = s_num = cb->args[1]; 103 99 ··· 126 130 r->id.idiag_dport) 127 131 goto next; 128 132 129 - if (sk_diag_dump(sk, skb, cb, r, bc, net_admin) < 0) { 133 + if (sk_diag_dump(sk, skb, cb, r, net_admin) < 0) { 130 134 spin_unlock_bh(&hslot->lock); 131 135 goto done; 132 136 }
+4 -11
net/mptcp/mptcp_diag.c
··· 15 15 static int sk_diag_dump(struct sock *sk, struct sk_buff *skb, 16 16 struct netlink_callback *cb, 17 17 const struct inet_diag_req_v2 *req, 18 - struct nlattr *bc, bool net_admin) 18 + bool net_admin) 19 19 { 20 - if (!inet_diag_bc_sk(bc, sk)) 20 + if (!inet_diag_bc_sk(cb->data, sk)) 21 21 return 0; 22 22 23 23 return inet_sk_diag_fill(sk, inet_csk(sk), skb, cb, req, NLM_F_MULTI, ··· 76 76 const struct inet_diag_req_v2 *r, 77 77 bool net_admin) 78 78 { 79 - struct inet_diag_dump_data *cb_data = cb->data; 80 79 struct mptcp_diag_ctx *diag_ctx = (void *)cb->ctx; 81 - struct nlattr *bc = cb_data->inet_diag_nla_bc; 82 80 struct net *net = sock_net(skb->sk); 83 81 struct inet_hashinfo *hinfo; 84 82 int i; ··· 119 121 if (!refcount_inc_not_zero(&sk->sk_refcnt)) 120 122 goto next_listen; 121 123 122 - ret = sk_diag_dump(sk, skb, cb, r, bc, net_admin); 124 + ret = sk_diag_dump(sk, skb, cb, r, net_admin); 123 125 124 126 sock_put(sk); 125 127 ··· 152 154 bool net_admin = netlink_net_capable(cb->skb, CAP_NET_ADMIN); 153 155 struct mptcp_diag_ctx *diag_ctx = (void *)cb->ctx; 154 156 struct net *net = sock_net(skb->sk); 155 - struct inet_diag_dump_data *cb_data; 156 157 struct mptcp_sock *msk; 157 - struct nlattr *bc; 158 158 159 159 BUILD_BUG_ON(sizeof(cb->ctx) < sizeof(*diag_ctx)); 160 - 161 - cb_data = cb->data; 162 - bc = cb_data->inet_diag_nla_bc; 163 160 164 161 while ((msk = mptcp_token_iter_next(net, &diag_ctx->s_slot, 165 162 &diag_ctx->s_num)) != NULL) { ··· 174 181 r->id.idiag_dport) 175 182 goto next; 176 183 177 - ret = sk_diag_dump(sk, skb, cb, r, bc, net_admin); 184 + ret = sk_diag_dump(sk, skb, cb, r, net_admin); 178 185 next: 179 186 sock_put(sk); 180 187 if (ret < 0) {